2
\$\begingroup\$

I am an STM32 newcomer. I recently got an STM32F429 Discovery dev board which I have been playing around with. Currently I'm trying to figure out how to use the debugging functions of this M4 Cortex, specifically the SWV ones.

I used STM32CubeMX standalone to generate a project for Atollic TrueStudio and then modified the main.c files infinite loop as follows to blink an LED on and off every 2 seconds and to printf a message to the console.

  while (1)
  {
     HAL_GPIO_TogglePin(GPIOG,GPIO_PIN_13);
     HAL_Delay(2000);
     printf("hello");
  }

When I run debug it programs the board perfectly. I see the LED blink on and off. I followed the steps in this article which explains how to setup printf redirect to the console by generating a syscalls.c file and making some changes to the int _write function in that file. I am however struggling to get this to work. When I step through my code and get to that printf("hello") line it just skips over it like it doesn't exist and there is nothing printed to the SWV console.

Below is a picture of my debug settings and the modified version of int _write which resides in my syscalls.c file.

int _write(int32_t file, uint8_t *ptr, int32_t len)
{
   int i=0;
     for(i=0 ; i<len ; i++)
       ITM_SendChar((*ptr++));
     return len;

   errno = ENOSYS;
   return -1;
}

Is it possible I've missed something in the setup when using CubeMX? I followed Atollics recommended setup for printf redirect exactly but nothing shows up in the SWV console.

Debug settings

\$\endgroup\$
  • 1
    \$\begingroup\$ For anyone having a similar issue. I ended up solving the problem by soldering SB9, solder bridge 9, on the bottom of the board. Also update the board firmware and make 100% sure that your clock speed is correct in the debug settings. \$\endgroup\$ – Blargian Feb 19 at 11:48
2
\$\begingroup\$

Although Blargian already gave his answer as a comment, I thought I should formally answer in case anyone has the same problem.


I will refer to the document "STM32F429ZI Discovery Kit User Manual" (search for "en.DM00093903" or "UM1670") as "the user manual" in the below paragraphs.

In section 6.13 of the user manual, it indicates that solder bridge "SB9" controls the SWO (Serial Wire Out). By default, SWO is disconnected! This means you can't get any output back from the device for any of the SWV features.

To apply this fix, apply judicious solder to SB9, as indicated in Figure 4. of the user manual. It is located on the bottom side of the board (the side without the LCD), near the SWD connector.

If you apply this fix, note that PB3 will be connected to SWO, so you can't use PB3 anymore.


I think using an external ST-LINK/V2 debugger would also work (see section 6.3.5 of the user manual).

Also as Blargian mentioned, the clock speed must match the actual speed the microcontroller is running at.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.