cancel
Showing results for 
Search instead for 
Did you mean: 

Check under debug mode for ARM semihosting

ctc.ctc
Associate II
Posted on June 15, 2017 at 18:22

I'm study cortex-m4 for semihost and use stm32f429-discovery board. I have a trouble with that semihost can not work when board is standalone(without in debug mode), So, I hope to use judge debug status before printf(), like

if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) \ ==CoreDebug_DHCSR_C_DEBUGEN_Msk) { printf('THIS IS SEMIHOST\n'); }

In normal situation, it will be like my expect, in debug mode, I can see semihiost log, in standalone, nothing pending. But in one situation, when I just burn the code into flash (using openocd or texane stlink with stlink hardware in linux). The first time it run, the bit of debug mode

(CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk)
keep being 1. I thought it should not be in debug mode, even I press reset hardware button on the board, it still keep 1, and the program will pending in printf().

After I plug out the power and then plug again, the debug mode bit will back to 0, and it work correctly now, Is this trouble can be solved? or I use wrong openocd command? Thanks.

openocd command I use:

openocd -f interface/stlink-v2.cfg -f target/stm32f4x_stlink.cfg \ -c 'init' \ -c 'reset init' \ -c 'flash write_image erase ***.bin 0x8000000' \ -c 'reset run' \ -c 'shutdown'

#stm32f4 #debug #semihost
1 REPLY 1
Posted on June 15, 2017 at 20:05

There's not much protection from debug tools that leave the system registers in indeterminate states

This is the test I use, but it was designed to work for systems started with no debugger attached.

static int Debug_ITMDebug = 0;

volatile unsigned int *ITM_TER = (volatile unsigned int *)0xE0000E00;

volatile unsigned int *SCB_DHCSR = (volatile unsigned int *)0xE000EDF0;

if ((*SCB_DHCSR & 1) && (*ITM_TER & 1)) // Enabled?

Debug_ITMDebug = 1;
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..