DAVE TIP of the day: Semihosting in DAVEv4

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Not applicable
Semihosting is a mechanism for ARM targets to communicate input/output requests from application code to a host computer running a debugger. For example, you can use this mechanism to enable functions in the C library, such as printf() and scanf(), to use the screen and keyboard of the host instead of having a screen and keyboard on the target system.

In DAVEv4, you can enable semihosting using the following steps. An example for semihosting on XMC1300 is provided in this tip. 🙂

1. Configure the Tool settings:
- Toolbar: Select “Project  Active Project Settings” to launch the Settings Dialog.
- Settings Dialog: Select “C/C++ Build  Settings” and click on the “Tool Settings” Tab.
- Linker Settings: Select “ARM-GCC C Linker  Miscellaneous  Other Flags:” , enter “-specs=rdimon.specs -specs=nosys.specs”
- Preprocessor Settings: Select “ARM-GCC Assembler  Preprocessor  Defined symbols (-D):” , add “__SKIP_LIBC_INIT_ARRAY”

2. In the folder Libraries/Newlib, replace syscalls.c by _sbrk.c

3. In your application, add the following lines to initialize the monitor handles for semihosting. Add “printf” statements in your code for semihosting.

extern void initialise_monitor_handles(void);

int main(void)
{
initialise_monitor_handles();


// Example printf statements for semihosting
printf("XMClib printf using semihosting \n");


4. Compile and start a debug session. In the debugger settings you need to activate semihosting.

5. To see the output, in the debugger perspective, you need to activate the Semihosting and SWV in the Console view.
0 Likes
14 Replies
Dirk
Employee
Employee
Hi Daryl,

it's working thanks,
but in your description is a small error. There is a missing "underline" at __SKIP.
- Preprocessor Settings: Select “ARM-GCC Assembler  Preprocessor  Defined symbols (-D):” , add “_SKIP_LIBC_INIT_ARRAY”


Another question. Why u must replace the c file? as if i compare the file its nearly the same, just reduced of some functions. Which functions have to be deleted to activate that function`?

Regards
Dirk
0 Likes
Not applicable
HI Dirk,

Thanks for pointing it out. I have edited the post. 🙂

For STEP2/replacing the file, the syscall.c file does not support the output functions in semihosting correctly. Therefore, for now, we have to replace the file.
In the next DAVE update, the syscall.c file will be updated and STEP2 will not be needed.

Regards,
Daryl



Regards,
Daryl
0 Likes
Not applicable
in order to use XMC_DEBUG() isn't it necessary to #define XMC_DEBUG_ENABLE ?

Anyway, I followed the steps, the project compiles put it seems that printf() is not working.
I can't see any output. Whether in step mode or running the example.
Using a simple project for an XMC1404
0 Likes
elm0
Employee
Employee
Are you looking at the right console?

1651.attach

A mistake I made first was to define the symbol "__SKIP_LIBC_INIT_ARRAY" in the ARM-GCC C Compiler preprocessor settings, and not in the ARM-GCC Assembler preprocessor settings as it should be.

To use the XMC_DEBUG() function, it is necessary to #define XMC_DEBUG_ENABLE, but not in the main.c, but e.g. in the xmc_common.h
0 Likes
elm0
Employee
Employee
Did someone try semihosting input? For me, it doesn't work ... or maybe I don't know how to send something. Simply typing in the console and pressing enter seems not to work.
0 Likes
lock attach
Attachments are accessible only for community members.
Not applicable
[Updated for DAVE 4.2.4]

Semihosting is a mechanism for ARM targets to communicate input/output requests from application code to a host computer running a debugger. For example, you can use this mechanism to enable functions in the C library, such as printf() and scanf(), to use the screen and keyboard of the host instead of having a screen and keyboard on the target system.

In DAVEv4, you can enable semihosting using the following steps. An example for semihosting on XMC1300 is provided in this tip.

1. Configure the Tool settings:
- Toolbar: Select “Project  Active Project Settings” to launch the Settings Dialog.
- Settings Dialog: Select “C/C++ Build  Settings” and click on the “Tool Settings” Tab.
- Linker Settings: Select “ARM-GCC C Linker  Miscellaneous  Other Flags:” , enter “-specs=rdimon.specs”

2. In your application, add the following lines to initialize the monitor handles for semihosting. Add “printf” statements in your code for semihosting.

extern void initialise_monitor_handles(void);

int main(void)
{
initialise_monitor_handles();


// Example printf statements for semihosting
printf("XMClib printf using semihosting \n");


3. Compile and start a debug session. In the debugger settings you need to activate semihosting.

4. To see the output, in the debugger perspective, you need to activate the Semihosting and SWV in the Console view.
0 Likes
User11706
Level 2
Level 2
I am unable to make it work on Hexagon board XMC4500 and Dave 4.3.2
2514.attach
2517.attach
2515.attach

Here is a simplified source code (from "Blinky" example) :


#include //Declarations from DAVE Code Generation (includes SFR declaration)
#include

#include "GPIO.h"
#include "board.h"

extern void initialise_monitor_handles(void);

volatile unsigned long timingdelay, adc_result;

void ADC0_Init(void);
void Delay100US (unsigned long time);


/*Main function*/
int main(void)
{
initialise_monitor_handles();
/* Setup the system */
SysTick_Config(12000); // Systick every 0.1 ms = 100us

/* Configure P3.9 (LED) */
// P3.9 is used as GPIO for LED indication. Macros can be find in GPIO.h
Control_P3_9(OUTPUT_PP_GP, STRONG);

printf("Welcome into Blink45\n");

/* Infinite loop */
while (1)
{
Delay100US (0x0FFF);
Toggle(P3_9); // toggle P3.9 (toggle LED) using GPIO.h macros

printf("Welcome into Blink45\n");
}

Does not seem to do the job :
2516.attach
What am I doing wrong ?
Thanks for any clue...

Jorge
0 Likes

I hope this is helpful, I just recorded this by following the steps in this thread. 

https://www.youtube.com/watch?v=-iDKpxj51pI

0 Likes
User12537
Level 1
Level 1
Hello together 🙂

printf is working well and will help me very much. Would be nice to have the same for sending data to uC.
I have tried scanf, gehtchar,... But it doesn't work.
Here is an example:

char buff[1];

if (fgets(buff, sizeof(buff), stdin) != NULL ) {
printf("yes 🙂 \n");
}


What am I doing wrong? Any ideas? Would be very happy if someone could help me.
Regards, Dirk
0 Likes
User17265
Level 1
Level 1
Hi.
I did the steps 1 to 3 above, and the linker fails.

make: *** [EP6V43_relax.elf] Error 1
makefile:72: recipe for target 'EP6V43_relax.elf' failed

There are no other messages to help understand what is missing.


I am with an XMC4300 with Ethercat and a software a bit more complex than the example. But it runs perfectly on the Relax kit when I don't try semihosting.

Thans in advance for your help.
Olivier
0 Likes
User18406
Level 1
Level 1
Same issue with DAVE 4.4.2
0 Likes
User20504
Level 1
Level 1
Hi there

I have issues sending messags to the debug window. I tried using XMC_debug and as well the solution using semihosting.
However, both are not working (at all). I an able to compile but there no messages arrive at the window.

Is there meanwhile an new solution available?
I am using XMC4300 with dave 4.4.2

Thank you!
Regards
Roman
0 Likes
mleisner
Level 1
Level 1
25 sign-ins 10 sign-ins 5 sign-ins

Where is initialise_monitor_handles() defined?

I'm using Dave 4.5 with an xmc4800.   I'm just baffled how to get stdio working through the j-link debugger

Are there current/complete instructions someplace?

Marty

0 Likes
Anis399
Level 1
Level 1
First like received First reply posted Welcome!

I hope this is helpful, I just recorded this by following the steps in this thread. 

https://www.youtube.com/watch?v=-iDKpxj51pI

0 Likes