STM32 semi-host mode

Publisher:HappyExplorerLatest update time:2017-09-08 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

When programming in Keil, you will often encounter the warning of __use_no_semihosting_swi, which means you have entered the semihost mode. 
In embedded programming, you cannot avoid using functions such as printf, fopen, fclose, etc. However, because there is no underlying implementation of these functions in the embedded program, the device will enter the software interrupt BAEB when it is running. At this time, the declaration of __use_no_semihosting_swi is needed to make the program stop at this interrupt when encountering these file operation functions. The specific operation is as follows. Add the following program to your project:

#pragma import(__use_no_semihosting_swi) #pragma import(_main_redirection) const char __stdin_name[150];  
const char __stdout_name[150];  
const char __stderr_name[150];  
typedef int FILEHANDLE;  

//Rewrite the standard library function. When printf, fopen, fclose and other file operation functions are running, they will call your rewritten function. These rewritten functions are just a few simple examples, and not all file operation functions are rewritten void _sys_exit(int status)  
{  
    while(1);  
}  
FILEHANDLE _sys_open(const char *name, int openmode)  
{  
    return 0;  
}  

int _sys_close(FILEHANDLE fh)  
{  
    return 0;  
}  

int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)  
{  
    return 0;  
}  

int _sys_read(FILEHANDLE fh, unsigned char*buf, unsigned len, int mode)  
{  
    return 0;  
}  

int _sys_istty(FILEHANDLE fh)  
{  
    return 0;  
}  

int _sys_seek(FILEHANDLE fh, long pos)  
{  
    return 0;  
}  

int _sys_ensure(FILEHANDLE fh)  
{  
    return 0;  
}  

long _sys_flen(FILEHANDLE fh)  
{  
    return 0;  
}  

int _sys_tmpnam(char *name, int fileno, unsigned maxlength)  
{  
    return 0;  
}  

void _ttywrch(int ch)  
{  
}
time_t time(time_t *t)  
{  
    return 0;  
}  
int remove(const char *filename)  
{  
    return 0;  
}  

char *_sys_command_string(char *cmd, int len)  
{  
    return 0;  
}  

clock_t clock(void)  
{  
    return 0;  
} 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636 4656667686970717273747576777879

If the following compilation error occurs: Error: L6915E: Library reports error: __use_no_semihosting_swi was requested, but _ttywrch was referenced, you only need to rewrite the _ttywrch function. You
can refer to the previous article 
to enable semihost mode on MDK - SWO line is required (in other words, JTAG wiring is required)

When the target board is separated from the emulator (jlink/ulink) and runs independently, the semihost mode cannot be used

pragma import(__use_no_semihosting_swi)

This statement can turn off the semihost mode. Just add it to any C file.

Also, when programming with Keil, you may encounter...\OBJ\USART.axf: Error: L6915E: Library reports error: __use_no_semihosting was requested, but _ttywrch was referenced. 
This roughly means that the semihost mode is turned off, but the function __ttywrch is required. At this time, you need to rewrite the function. Of course, when other functions are required, you can refer to the above functions for writing. Just put them in any .c source file. 
**About microlib 
microlib is an alternative library to the default C library. It is used for deeply embedded applications that must run in a very small amount of memory. These applications do not run in the operating system. microlib does not try to be a standard ISO C library. 
microlib is highly optimized to make the code very small. It has fewer functions than the default C library and does not have some ISO C features at all. Some library functions also run slower, for example, memcpy(). 
**


Keywords:STM32 Reference address:STM32 semi-host mode

Previous article:Using DMA+USART3 to transfer data on STM32
Next article:STM32 interrupt priority grouping concept

Recommended ReadingLatest update time:2024-11-16 21:47

Application of printf function in STM32 compiler keil
First, please check "UseMicroLIB" in "Target"- "Code Generation" of MDK (keil) project properties. Add Printf to your program 1,#include 2. Add #ifdef __GNUC__ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #else #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif PUTCHAR_PROTOTYPE { USART_S
[Microcontroller]
STM32 USART serial port DMA receiving and sending source code detailed explanation
Hardware platform: STM32F103ZET6;  Development environment: KEIL 4; Let's talk about the application communication mode first. The working mode of the serial terminal is similar to that of the DWIN screen. The terminal passively accepts the instructions sent by the MCU, and the terminal will occasionally actively send
[Microcontroller]
Analysis of WM_REDRAW.c source code of transplanting ucGUI on STM32
1. Transplantation of wm_redraw.c     In my previous note, I talked about how to port ucGUI to STM32 to develop bare-metal programs. In this note, I will analyze the porting and source code of wm_redraw.c. First, open the ported ucGUI project file, and then copy the functions in the WM_Redraw.c file in the ucGUI\Sampl
[Microcontroller]
STM32 learning: timer time calculation
Assuming the system clock is 72Mhz, TIM1 is derived from PCLK2 (72MHz), and TIM2-7 are derived from PCLK1 The key is to set the clock pre-division number and the value of the automatic reload register cycle /*An update event occurs every 1 second (entering the interrupt service routine). RCC- CFGR |= (uint32_t)RCC_CFG
[Microcontroller]
STM32 learning record 13 ucosII transplantation
There are already many documents explaining how to migrate and set up projects. Here we will only explain the files that need to be modified and the reasons for the modifications. 1: os_cpu.h  We need to modify this file:  1) void OS_CPU_PendSVHandler(void) needs to be replaced with void PendSV_Handler(void) Gen
[Microcontroller]
STM32 learning different FLASH chip startup file selection rules
The FLASH size of F103ZET6 is 512K, so select startup_stm32f10x_hd.s The FLASH size of F103C8T6 is 64K, so select startup_stm32f10x_md.s Things to note when transplanting From ZET6 to C8T6, changes are required 1. Startup File 2. C++XU tab 3、
[Microcontroller]
STM32 learning different FLASH chip startup file selection rules
Portable flight parameter data unloader based on μC/OS-II
With the widespread application and continuous enhancement of embedded systems, the requirements for the human-machine interface in the system are getting higher and higher. Therefore, the addition of graphical user interfaces in embedded systems has been widely used. In order to give full play to the functions and per
[Microcontroller]
Portable flight parameter data unloader based on μC/OS-II
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号