Professional Documents
Culture Documents
18 Semihostng
18 Semihostng
T.O.M.A.S Team
Goal of this part 2
• With Cortex-M based MCUs, the bottom level of the C library contains a special
BKPT instruction. The execution of this is trapped by the debug tools which
determine what operation is being requested - in the case of a printf, for
example, this will effectively be a "write character to stdout". The debug tools
will then read the character from the memory of the target board - and display it
in the console window within the IDE.
• Semihosting also provides support for a number of other I/O operations. For
example it provides the ability for scanf to read its input from the IDE console. It
also allows file operations, such that fopen can open a file on your PC's hard
drive, and fscanf can then be used to read from that file.
Semihosting example
5
In linker settings for the project please add: -specs=rdimon.specs –lc –lrdimon
Semihosting example
8
In debug configuration:
• Add “monitor arm semihosting enable”
• Compile and run the code
• Look on console in SW4STM32
Semihosting – important remark
9
• When you have linked with the semihosting library, your application will no longer work standalone - it
will only work when connected to the debugger.
• Semihosting operations cause the CPU to drop into "debug state", which means that for the duration
of the data transfer between the target and the host PC no code (including interrupts) will get
executed on the target. Thus if you application uses interrupts, then it is normally advisable to avoid
the use of semihosting whilst interrupts are active. If you still need to use printf, then you can retarget
the bottom level of the C library to use an alternative communication channel, such as a UART or
SWO.
www.st.com/mcu