2019-10-09 03:28 AM
I am using MDK5 (5.22) with STM32CubeMX (4.26.1). I generate blank project within CubeMX for STM32L471ZGTx (144pin MCU). Clock configuration uses internal HSI and LSI and it's set to 16MHz. For testing purposes I configured clocks so all other clocks are 16MHz (SYSCLK, APB1, Timers, Cortex etc...)
Under SYS menu I enable TRACE asynchronous SW to use SW for programming and SWO for retargeting printf.
I generate project and open it in MDK5 then under RTE editor I set up Compiler->I/O and select all options to ITM. So retargeting of printf goes to ITM.
Under options for target I enable TRACE - ITM channel 0.
Then I try to use printf in my main function
int main(void)
{
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
printf("Hello world\n");
...
But I get stuck on that command. If I press Stop code execution it points to file retarget_io.c to line 99. Obviously I am stuck within that while-loop:
I can get anywhere with this... so far I tried different clock configurations, I checked for HW failure and there is solid connection to pin PB3 (SWO). I checked my ULINK2 programmer and tried with others... same problem.
I use same method for other projects with other MCU families which supports SWO and it works except with this one. I tried same approach on discovery board with STM32L475 and it works.
Any help/ideas would be much appreciated!
Thank you!
2019-10-09 03:36 AM
I normally check Privilege Port 0..7
2019-10-09 03:42 AM
I forgot to mention this but I also tried checking privilege for Port 0..7 and it's same.
2019-10-09 03:46 AM
Using SWO on several L4 series parts here, not got a L471 to try.
2019-10-09 04:01 AM
It's quite straight forward how to enable and use SWO therfore it's strange to me because I have experiences with other MCUs and it's not problem at all except with this one.
2019-10-10 12:11 AM
For your information... I found out that problem was in Keil Ulink2 programmer. I have two of them and with both I have same problem, then I borrowed Segger's J-link and I connected it to my HW and ITM and printf works now without a problem. I guess I will use J-link with this project. Thanks for your contribution.
2019-10-10 01:53 AM
Additionaly I found out that if I try to debug first with J-link then I switch to ulink2 printf starts working with ulink (until next hardware reset). I guess that J-link puts MCU's registers in different startup states comparing to Ulink2. So what I did I made screen capture of registers when using JLink and registers when using Ulink2... and I found differences in DBGMCU registers. Then I forced those register values to same as with JLink and printf works. (see attached image for differences)
I think I will make a configuration ini file for debug mode which will setup those registers on startup when using Ulink2.
2019-10-10 02:53 AM
My ini file looks like this below:
// Manually enable debugging in DBGMCU module (DBG_SLEEP, DBG_STOP, DBG_STANDBY, TRACE_IOEN, TRACE_MODE)
_WWORD(0xE0042004, 0x27) // CR register of DBGMCU
// Enable fields in freeze register APB1FZR1
_WDWORD(0xE0042008, 0x1800) // APB1FZR1 register of DBGMCU