logo elektroda
logo elektroda
X
logo elektroda

Title: STM32 Serial Wire Viewer & Output, ST-LINK: Beginner Questions on SWO, SWCLK & Reset

vp32 4788 17
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18330556
    vp32
    Level 11  
    Hi
    I turned around pretty hard. I am asking for your understanding because I am just starting with STM32, or at least I have been trying for some time.
    I'm not jumping into deep water, I'm just interested in the topic.
    I realize that these are obvious things to you, but I don't have an ARM mentor (it's a pity) and sometimes I connect contradictory things reading the internet.

    1. What exactly is Serial Wire Viewer and Serial Wire Output?
    I mean exactly SWO is the pin dedicated to this?
    does it activate somehow?
    In that case, how does the uC know what to send to this output?
    Is this data related to the clock somehow, SWCLK?

    2. I use ST-Link. I came across such Connect Under Reset setting. What does it give me? How to take advantage of it? Does it mean the reset button has to be pressed? Why in cubeMX you can programmatically set two pins to work with SWD?
  • ADVERTISEMENT
  • Helpful post
    #2 18330651
    Sareph
    Level 24  
    vp32 wrote:
    1. What exactly is Serial Wire Viewer and Serial Wire Output?
    It's kind of a one-way serial port to put whatever information you see fit on it. http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0314h/Chdcicdb.html

    vp32 wrote:
    I mean exactly SWO is the pin dedicated to this?
    Of course.

    vp32 wrote:
    does it activate somehow?
    Yes.

    vp32 wrote:
    In that case, how does the uC know what to send to this output?
    Like all CPUs, it will do what you ask it to do, so if you enable trace and give it data, it will send whatever you want there. http://blog.atollic.com/cortex-m-debugging-pr...on-to-a-debugger-console-using-swv/itm-part-1


    vp32 wrote:
    Is this data related to the clock somehow, SWCLK?
    NO.

    vp32 wrote:
    2. I use ST-Link. I came across such Connect Under Reset setting. What does it give me? How to take advantage of it? Does it mean the reset button has to be pressed?
    If you turn off the SWD in the program, this connection during the reset gives you access to the SWD interface. And yes, you can hold the reset, but if you don't have a Chinese clone, the programmer will do it for you.

    vp32 wrote:
    Why in cubeMX you can programmatically set two pins to work with SWD?
    Probably because SWD has two signals.
  • #3 18330935
    BlueDraco
    MCUs specialist
    vp32 wrote:
    2. I use ST-Link. I came across such Connect Under Reset setting. What does it give me? How to take advantage of it? Does it mean the reset button has to be pressed?


    On the contrary. This option means that ST-Link will try to reset the CPU by whatever method it can when attempting to connect. In some uCs the connection fails without it (e.g. often in the F4 series). If you programmed the SWD by mistake and you don't have the RESET line connected to the ST-Link, you can press the RESET button while connecting and it will work without this option, because in this case you reset the uC, not the ST-Link.
  • ADVERTISEMENT
  • #4 18330977
    vp32
    Level 11  
    I read a little, there is light at the end of the tunnel.
    Isn't it a coincidence that after a hundred pins for SWD work are set in CubeMX so that the Debugger can be used during normal operation, otherwise they are ordinary GIPO? And maybe that's why it's connect under reset?
    I also read that SWO also needs SWD. And now I don't understand SWD is two-pin and what about SWO, does it not connect together and actually three lines are needed?
    Also tell me if SWO is activated in the ARM program or is it only activated in the program like Atolic? Because since it is a regular PB3 port, it can be used for other purposes.
    P.S. why there is no ST-LINK programmer selection in Sytem Workbench. No underlined tab? Title: STM32 Serial Wire Viewer & Output, ST-LINK: Beginner Questions on SWO, SWCLK & Reset

    PS> now I've read that SWO is independent of SWD and can also work with JTAG, so what activates SDO?
  • #5 18331006
    Sareph
    Level 24  
    vp32 wrote:
    I also read that SWO also needs SWD. And now I don't understand SWD is two-pin and what about SWO, does it not connect together and actually three lines are needed?
    SWD as such is two-pin, "SWD + async trace" is three-pin. So if you want to use ITM then you need 3 lines.

    vp32 wrote:
    Also tell me if SWO is activated in the ARM program or is it only activated in the program like Atolic? Because since it is a regular PB3 port, it can be used for other purposes.
    You can initialize the ITM in the program code on the MCU, the debugger can do it for you. If you're not using it as an SWO, then yes - it can be used as a GPIO.

    And basically you can use trace/ITM even without SWD/JTAG but then *probably* only in synchronous mode.
  • ADVERTISEMENT
  • #6 18334507
    vp32
    Level 11  
    Can you help me?
    I don't understand why I can't connect to uC using ST-LINK.
    SWD pins PA13 and PA14 are free, I don't have them occupied. In Cube they are set as SWDIO and SWCLK. Supposedly, this setting does nothing other than not assigning pins to other purposes.
    In TrueStudio, there is always an error after trying to establish communication
    Error in initializing ST-LINK device.

    When I run ST-Link Utility, it does not connect either, but after pressing RESET, it manages to establish communication with the board.

    What's the deal with Connect Under Reset, why can't I connect via Debbuger in TrueStudio?
  • ADVERTISEMENT
  • #7 18334582
    Sareph
    Level 24  
    vp32 wrote:
    SWD pins PA13 and PA14 are free, I don't have them occupied. In Cube they are set as SWDIO and SWCLK. Supposedly, this setting does nothing other than not assigning pins to other purposes.
    Well, it depends, in F1, for example, the default setting is full JTAG. In F0, SWD is enabled by default, but...

    vp32 wrote:
    What's the deal with Connect Under Reset, why can't I connect via Debbuger in TrueStudio?
    ... it would turn out that you turned off the SWD, most likely in GPIO by changing the pin functions in port A.
  • #8 18334653
    vp32
    Level 11  
    Ok, how to fix it?, The chip is STM32F103C8Tx
    So it comes out that JTAG is the default, but I read that if there is JTAG, SWD switches when trying to establish a connection. or not?

    Tell me what is this Connect Under Reset, why did they separate it specifically?
  • #9 18334678
    Sareph
    Level 24  
    vp32 wrote:
    The chip is STM32F103C8Tx

    A, then not in port A, because there DP is configured in AFIO->MAPR

    vp32 wrote:
    So it comes out that JTAG is the default, but I read that if there is JTAG, SWD switches when trying to establish a connection. or not?
    I haven't actually checked, somehow I always have the SWD "manually" selected.

    vp32 wrote:
    Tell me what is this Connect Under Reset, why did they separate it specifically?
    That is why. Because you might want to connect a debugger while the program is running too, like if it crashes, to see what's going on. Or maybe there is a situation like you have, that for some reason the SWD is turned off (or it will stop working because you set the clocks wrong or you do not connect AVCC) and somehow you have to get to the system.

    Check if:

    [syntax=C]AFIO->MAPR = (0b010
  • #10 18334938
    vp32
    Level 11  
    Title: STM32 Serial Wire Viewer & Output, ST-LINK: Beginner Questions on SWO, SWCLK & Reset No changes unfortunately :-(
    Sareph wrote:
    A, then not in port A, because there DP is configured in AFIO->MAPR

    I don't understand what you mean, if not on A then on what.
    I took PA13 and PA14 from CubeMX. See drawing.

    Sareph wrote:
    I haven't actually checked, somehow I always have the SWD "manually" selected.

    Manually, i.e. by typing in that instruction you posted?

    And if Under Reset is what special initialization is it? Couldn't you write in the note that if you don't want to connect, then cut RESET? I can't figure out the intention of this "special mode".
  • #11 18334959
    Sareph
    Level 24  
    vp32 wrote:
    Title: STM32 Serial Wire Viewer & Output, ST-LINK: Beginner Questions on SWO, SWCLK & Reset No changes unfortunately :-(

    Your Cube configuration indicates that you have SWD *disabled*. Go under device SYS, there enable debug on SWD or async trace if you want SWO. Merely marking the pins here does not give you anything. (Orange - pony reserved but device is not turned on).

    vp32 wrote:
    I don't understand what you mean, if not on A then on what.
    On A, but no. :D Because in older STMs, if you want to switch SWD configurations, you change it in AFIO, and if debug is turned on, these pins are "force" intended for debug and you can change their functions in port A (GPIO) and it won't help you anyway.

    vp32 wrote:
    Manually, i.e. by typing in that instruction you posted?
    Yes. At the same time, it will also switch all remapped pins to default ones. Well, that's just for the test.

    vp32 wrote:
    And if Under Reset is what special initialization is it? Couldn't you write in the note that if you don't want to connect, then cut RESET? I can't figure out the intention of this "special mode".
    Reset "presses" the programmer for you, unless you have a Chinese clone, then no, because they do not have a hardware reset and you have to do it manually.
  • #12 18335112
    vp32
    Level 11  
    Sareph wrote:
    On A, but no. :D Because in older STMs, if you want to switch SWD configurations, you change it in AFIO, and if debug is turned on, these pins are "force" intended for debug and you can change their functions in port A (GPIO) and it won't do you any good.

    You got me so confused I have no idea what you're talking about :(
    Correct me if I misunderstand you. I connect the programmer to these Pins PA13 and 14.
    Bits 26:24 SWJ_CFG[2]: Serial wire JTAG configuration
    These bits are write-only (when read, the value is undefined). They are used to configure the
    SWJ and trace alternate function I/Os. The SWJ (Serial Wire JTAG) supports JTAG or SWD
    access to the Cortex debug port. The default state after reset is SWJ ON without trace. This
    allows JTAG or SW mode to be enabled by sending a specific sequence on the JTMS /
    JTCK pin.
    000: Full SWJ (JTAG-DP + SW-DP): Reset State
    001: Full SWJ (JTAG-DP + SW-DP) but without NJTRST
    010: JTAG-DP Disabled and SW-DP Enabled
    100: JTAG-DP Disabled and SW-DP Disabled
    Other combinations: no effect


    If the value 000, 001, or 010 is written there (in these bits 24:26), these PA13 and PA14 will always be on JATG SWD. And it doesn't matter what he writes to the GPIO port because it doesn't matter then. So for these PA13 and 14 to do anything, those 24:26 bits must be 100? Yes?
    You write in older and newer, how and which, how do I know which is old and which is new?

    But reset isn't meant to be pressed all the time? because if I hold it all the time it doesn't work? or so?

    Now try with SYS, pony turned green

    Added after 7 [minutes]:

    But this setting in SYS SWD gives the same effect as your instruction because according to CubeMX it gives: Title: STM32 Serial Wire Viewer & Output, ST-LINK: Beginner Questions on SWO, SWCLK & Reset
  • #13 18335216
    Sareph
    Level 24  
    vp32 wrote:
    If the value 000, 001, or 010 is written there (in these bits 24:26), these PA13 and PA14 will always be on JATG SWD.
    Well, when JTAG is on, it's not only them, but roughly yes.

    vp32 wrote:
    And it doesn't matter what he writes to the GPIO port because it doesn't matter then. So for these PA13 and 14 to do anything, those 24:26 bits must be 100? Yes?
    Yes.

    vp32 wrote:
    You write in older and newer, how and which, how do I know which is old and which is new?
    From the documentation, the "newer" ones don't have AFIO. And they have other GPIO registers.

    vp32 wrote:
    But reset isn't meant to be pressed all the time? because if I hold it all the time it doesn't work? or so?
    If you have properly configured and connected SWD, then you shouldn't have to hold the reset (unless something with the program goes very wrong).

    vp32 wrote:
    But this setting in SYS SWD has the same effect as your instruction
    Because it's roughly a different way to accomplish the same thing (if you prefer to use Cube). Well, "my instruction" changes the pin remapping settings of other devices, if they are set, Cube does not.
  • #14 18342282
    vp32
    Level 11  
    Okay, something happened after changing SYS to SW Debug.
    But that gave me another question. Because setting this SW Debug causes the function to be called

    Code: C / C++
    Log in, to see the code


    Which registers AFIO->MAPR 0b010 at [26:24]
    If I don't set SW Debug it will be entered into these registers

    Code: C / C++
    Log in, to see the code



    So they will be ordinary GPIO

    But why, after all the initialization done by CubeIDE, I type it manually

    [syntax=c]AFIO->MAPR =(0b010
  • #15 18344562
    vp32
    Level 11  
    P.S. thanks for the help :-(
  • #16 18345255
    excray
    Level 41  
    And what does your ST-Link look like? Sareph already mentioned that "Connect under reset" doesn't work in Chinese versions.
  • #17 18359329
    vp32
    Level 11  
    It's a typical quinol.
    I rather meant the principle of operation of this Connect Under Reset and not whether my programmer works. are these instructions sent when the connection is established, or is it just a matter of giving an additional reset signal and if so, for how long?
  • #18 18359367
    Sareph
    Level 24  
    vp32 wrote:
    is it just a matter of giving an additional reset signal and if so, for how long?
    You download the reset to ground, the programmer initiates what it needs in the CPU during this reset, you release the reset (or the programmer does it) and the SWD is restored, so you can program.

Topic summary

The discussion revolves around the STM32 microcontroller's Serial Wire Viewer (SWV) and Serial Wire Output (SWO) functionalities, particularly for beginners. Key points include the nature of SWO as a one-way serial port for data output, its activation through program code, and its relationship with SWD (Serial Wire Debug) and SWCLK (Serial Wire Clock). The "Connect Under Reset" feature of the ST-Link programmer is explained as a method to reset the microcontroller to establish a connection, especially useful for certain STM32 models like the F4 series. The conversation also touches on the configuration of SWD pins in CubeMX, the necessity of proper initialization for SWD and SWO, and the distinction between SWD and JTAG modes. Issues with connecting to the microcontroller and troubleshooting steps are discussed, emphasizing the importance of correct pin assignments and settings in the firmware.
Summary generated by the language model.
ADVERTISEMENT