Skip to main content
Graduate II
June 25, 2024
Solved

Use Serial Wire Viewer on Cube Programmer for STM32 F405 Feather

  • June 25, 2024
  • 5 replies
  • 5045 views
I want to read the serial output from the STM32 F405 Feather using the SWV on Cube Programmer, but I do not receive Serial output from the board. I am running the .hex file from this Arduino sketch on the board:

 

#include <SWOStream.h>
SWOStream s(2000000, SWO_Async, 0, false); //swoEnable = false

void setup() {
 delay(150);
}

void loop() {
 s.print("Serial is alive!");
 delay(500);
}

 

I have searched through the board documentation over and over and I can't find what clock frequency to use in my program and in the SWV terminal on Cube Programmer, so if anyone could point me in the right direction, it would be appreciated!
    This topic has been closed for replies.
    Best answer by BarryWhit

    That looks just like the cheap chinese ones. I know because I had one and to avoid the risk of damaging it during  modding, I just spent a few bucks and got a better quality one which just worked.  Are you sure you bought that from ST?

     

    https://www.eevblog.com/forum/microcontrollers/quick-hack-to-get-swo-on-st-link-clones/

     

    5 replies

    Graduate II
    June 25, 2024

    It needs to know the speed your MCU is clocking and the speed the SWCLK is clocking.

    Here it's assuming 2 MHz, going to depend on the settings you have in STM32 Cube Programmer

    vs13Author
    Graduate II
    June 26, 2024

    @Tesla DeLorean wrote:

    It needs to know the speed your MCU is clocking and the speed the SWCLK is clocking.

    Here it's assuming 2 MHz, going to depend on the settings you have in STM32 Cube Programmer


    There is a clock speed of 168 MHz printed on the board that I've just changed the code and my settings to use, but I'm still not getting the output that I expect. I've attached my settings.

    Super User
    June 25, 2024

    @vs13 To see SWO output you don't need any sketches etc. The debugger or CubeProgrammer will set up the SWO automatically. All it needs to know is the SystemCoreClock value. Just provide it the value, call ITM_SendChar (or redirect printf to SWO) and enjoy.

     

    vs13Author
    Graduate II
    June 26, 2024

    @Pavel A. wrote:

    All it needs to know is the SystemCoreClock value. Just provide it the value, call ITM_SendChar (or redirect printf to SWO) and enjoy.

     


    I can't find the SystemCoreClock value of this board anywhere in its documentation. Do you know where I could look for it?

    Graduate II
    June 26, 2024

    It should be a variable in your system all the same, but the SWOStream implementation has it as a default parameter in any case

    https://github.com/koendv/SerialWireOutput/blob/master/SWOStream.h#L29

    Typically the Debug Pod sets the baud rate knowing the connection speed it has with the device, and the MCU clock it's dividing down to meet that.

    Graduate II
    June 26, 2024

    Just to be sure : 

    1. Are you using an ST-LINK (or clone) which provides an external SWO pin? the most common cheap chinese knock-off ones do not, unless you physicall mod them (cut a trace, run a jumper wire from the chip to the connector).

    2. If your ST-LINK support the SWO pin, did you connect the SWO pin on your board to the appropriate pin on your ST-LINK? The SWO ping is not needed for debug/programming, but SWO is required for using the SWV facilities in CubeIDE.

    vs13Author
    Graduate II
    June 26, 2024

    @BarryWhit wrote:

    Just to be sure : 

    1. Are you using an ST-LINK (or clone) which supports SWO, the most common cheap chinese knock-off ones do not support SWO out of the box, unless you install some jumper wires.

    2. Did you connect the SWO pin on your board to the appropriate pin on your ST-LINK? This is a third optional debug pin, needed specifically for SWV.


    I've attached a picture of my ST-Link. It should be genuine as I bought it through ST's website, but I don't see a SWO pin on the ST-Link or my STM32F405. 

    BarryWhitAnswer
    Graduate II
    June 26, 2024

    That looks just like the cheap chinese ones. I know because I had one and to avoid the risk of damaging it during  modding, I just spent a few bucks and got a better quality one which just worked.  Are you sure you bought that from ST?

     

    https://www.eevblog.com/forum/microcontrollers/quick-hack-to-get-swo-on-st-link-clones/

     

    Graduate II
    June 26, 2024

    The SWO pin isn't routed to the external connector on these clones, AFAIK there's no way around a bodge to get it working. 

     

    If you attempt the mod, be very careful. The PCB inside the clone can change from seller to seller and over time. An EEVblog post from 10 years ago might contain information that does not apply to your board so make sure you're not blindly following but actually understand what you're trying to do. Or, buy a better ST-LINK (original or clone).

    vs13Author
    Graduate II
    June 26, 2024

    @BarryWhit wrote:

    The SWO pin isn't routed to the external connector on these clones, AFAIK there's no way around a bodge to get it working. 

    If you attempt the mode, be very careful. Clones are uncharted territory, and the board may change from seller to seller and over time. An EEVblog post from 10 years ago may contain information that does not apply to your board so make sure you're not blindly following but actually understand what you're trying to to. Or, buy a better ST-LINK (original or clone).


    Sigh, that's a good point. I'll just try to order a new one and make sure it's not a clone, thanks for all of your help!

    Graduate II
    June 30, 2024

    @vs13 , see this thread for identical situation and high-res photos of mod (may or may not be same board as yours), if you're thinking of doing it.