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 4656667686970717273747576777879If 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().
**
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
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- TI Audio Pre-Processing System Reference Design for Speech-Based Applications
- Playing with Zynq Serial 14 - Using GIT for Project Backup and Version Management 6
- Selection of solid state relays
- TWS earphones product display
- 【Silicon Labs Development Kit Review】+Data Collection
- How to evaluate MCU performance parameters? From which perspectives?
- Renesas CPK-RA6M4 Development Board Review ---- CAN
- There is a sound when the flyback power supply is turned off. Is it a problem with the circuit or the transformer? How to fix it?
- FAQ_How to quickly confirm the power consumption in different modes of S2-LP
- Last week: 100 sets of Pingtouge RISC-V development kits are waiting for you, share and win a 100 yuan red envelope