Skip to main content
Nix Wayne
Associate III
October 9, 2019
Question

Serial wire output on STM32L471ZGTx is not working - it hangs

  • October 9, 2019
  • 6 replies
  • 3251 views

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...)

0690X00000ApLaHQAV.png

Under SYS menu I enable TRACE asynchronous SW to use SW for programming and SWO for retargeting printf.

0690X00000ApLaMQAV.png

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.

0690X00000ApLalQAF.png

Under options for target I enable TRACE - ITM channel 0.

0690X00000ApLaqQAF.pngThen 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:

0690X00000ApLc8QAF.png

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!

This topic has been closed for replies.

6 replies

Tesla DeLorean
Guru
October 9, 2019

I normally check Privilege Port 0..7

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Nix Wayne
Nix WayneAuthor
Associate III
October 9, 2019

I forgot to mention this but I also tried checking privilege for Port 0..7 and it's same.

Tesla DeLorean
Guru
October 9, 2019

Using SWO on several L4 series parts here, not got a L471 to try.​

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Nix Wayne
Nix WayneAuthor
Associate III
October 9, 2019

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.

Nix Wayne
Nix WayneAuthor
Associate III
October 10, 2019

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.

Nix Wayne
Nix WayneAuthor
Associate III
October 10, 2019

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)

0690X00000ApOdYQAV.png

I think I will make a configuration ini file for debug mode which will setup those registers on startup when using Ulink2.

Nix Wayne
Nix WayneAuthor
Associate III
October 10, 2019

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