2017-06-15 09:22 AM
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
2017-06-15 11:05 AM
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;