cancel
Showing results for 
Search instead for 
Did you mean: 

how to programm a L432KC with an external STLink

MSimo.1
Associate II

Hey, iam working with a STM32 L432KC with an ST-Link onboard.

Iam am planning to create a PCB with the same chip and iam wondering how i could programm/debug it.

I read through the Instructions and i think SWD is the right thing for me.

I have a STM L452RE-P laying around. This is Board with a "ST-Link-Section" witch you can break off the PCB. (so you break the PCB in two parts and have the ST-Link part and the microcontroller part )

How can i programm/debug my L432KC with that ST-Link part off the L52RE-P?

ive found the SWD clock and data pins on the ST-Link part but i dont know where to connect them to the L432. Pin PA14/13 (SWCLK/SWDIO) are not routed to any pins of the PCB

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions

3.3V supply and GND are needed for your board to work.

For a ST-LINK debug connection

  • GND, SWCLK, and SWDIO are minimum
  • reset (NRST) is optional and useful, see below
  • SWO is optional and maybe useful. SWO is a fast tracing output which can be used for printf tracing (logging) similar to a VCP_TX but using a different protocol and needing a SWO capable debugger/logger
  • VCP_RX and VCP_TX is a useful serial console interface which can be used for printf tracing (logging) as well as for user IO as you like. It can be routed to any USART on your PCB and is not closely related to SWD, just happens to show up on the same USB. Shows up as a COM port on the host PC.

> What about a reset ? i thought, the debugger has to tell the MCU ro reset ? (after flashing)

A MCU reset can also be triggered by some magic SWDIO+SWDCK commands. But this is "soft" and works only when the SWD interface is available, i.e. SWD pins are not reconfigured and MCU not in certain low-power modes. The NRST can give it a "hard" reset anytime, which is more powerful.

Take a look at the broken-off of your Nucleo-64-p board (User manual UM2206). It has GND, SWCLK, SWDIO, NRST, SWO on pin 2-6 of CN3 and VCP_RX and VCP_TX on the connector nearby. You cannot fail if you make those signals available on your board.

CN3 Pin 1 marked VDD_TARGET is a special case. It is an input to SWD for detecting the target (debuggee) VDD voltage which can be evaluated by the debugger. High-end debug probes can use that pin for IO level conversion, galvanic decoupling etc.. Think of it as a 1-channel digital voltmeter input. Maybe useful to connect too, especially to detect low battery... scenarios.

Beware: some low-cost ST-LINK debug clones have a 3.3V pin which acts as an output to power the target, this is not the standard, do not connect.

STM AN4989 Application note "STM32 microcontroller debug toolbox has valuable info on debugging, SWO etc..

View solution in original post

13 REPLIES 13
KnarfB
Principal III

> Pin PA14/13 (SWCLK/SWDIO) are not routed to any pins of the PCB

On your PCB? They are routed on the Nucleo board, see UM1956 User manual STM32 Nucleo-32 board.

And, yes its possible to use the external broken-off ST-LINK for programming your L432KC. There was a recent discussion here: https://community.st.com/0D73W000000UT47

AN4555 Application note "Getting started with STM32L4 Series and STM32L4+ Series hardware development" is a good read if you plan to design your own board. There are many optional things to consider depending on your application (SWO, BOOT0, NRST pins, low-power, battery, RTC, clocking, ...).

Here is an open minimal STM32F0 board project: https://vivonomicon.com/2018/05/05/your-own-hardware-designing-an-stm32-development-board/

MSimo.1
Associate II

thank you! that giude will help me later.

I cant find anything about the SWD connector in um1956 .. I assume its the 5 holes in the PCB next to the usb connector ?

Page 32/37 tells me it exists, but i dont know wich pin is wich?

iam already sorry for asking that but i cant find a pinout of that connector:|

could you give me a hint?

ive seen the VCP_TX/RX pins there ... can I connect them to the broken off ST-Link as a uart?

Iam sending debug messages per uart to a virtual COM port of my host PC.. would be awesome to proceed with that.

KnarfB
Principal III

The Nucleo-32 board has two MCUs on it: the ST-LINK connected to USB on the bottom side and the user programmable MCU on the top side.

The "5 holes in the PCB" are connector CN2 on sheet 3 of 3 in the schematics. This is the programming port for the ST-LINK itself during board production and testing.

The user programmable MCU's SWD is connected to the ST-LINK on the board, thats what I ment by "routed". Those are the 4 signals in the top right corner above CN2 of sheet 3. The naming is somehow inconsistent, see sheet 1 for a top level view. You cannot separate the ST-LINK interface on a Nucleo-32 board unless you are heavily soldering and "hacking" the board.

> How can i programm/debug my L432KC with that ST-Link part off the L52RE-P?

The L432KC MCU or the Nucleo board? The Nucleo board comes with its own ST-LINK, no need for hardware changes/additions. For the L432KC MCU, use (==route on your PCB) the SWD interface if possible with optional pins (NRST, SWO) see AN4555. If you want a standard SWD capable connector, look at the available ST-LINK modules for a standard pinout. If you want to roll your own debug connector you may add the virtual com port pins ... as you like.

Here is some minimal breadboard with another chip (STM32F031F4) one an adapter board. The first two pins top left are the SWD interface, the next two used as UART. The LED blinks SOS - there is room for improvements.

0693W000003QMTnQAO.png

MSimo.1
Associate II

thank you!

iam powering my board external with 3.3V. the datasheet of the Nucelo board told me to remove SB14 and SB9. This disconnects the Reset line of the ST-Link and the 3.3v regulator from the MCU. That means that i can no longer use the ST-Link onboard.

i thought, i could connect this broken off ST-Link to my L432KC and programm/debug/ use uart this way?

where do i have to connect it ?

the L452 (where i broke the ST-Link off) has its SWD data and clock routet to the pin header, so that you can connect a jumper wire between the two parts..

Iam sorry, that i described it unclear!

I want to design my own PCB without a ST-Link onboard. This pcb will also be powered by 3.3V.

I just wanted to test how i can programm the controller on that PCB later on.. (with the SWD Interface)

Don't use the NUCLEO-32 for it's ST-LINK

The CN2 header is diagrammed in the schematic, it is for programming the F103 device with the ST-LINK firmware

The headers on the NUCLEO-64 allow you to connect to external devices provided you have disconnected the local target.

The header design is somewhat arbitrary, others use the older 20-pin ARM JTAG, or 10-pin SWD connector. While some use the Tag-Connect footprint.

The balance here is ease / cheapness of the debugging, vs testing / programming in a production.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
KnarfB
Principal III

> That means that i can no longer use the ST-Link onboard.

Why? The on-board ST-LINK is independently powered from USB. NRST is not needed for debugging as long as you leave the SWD pins of the MCU in SWD configuration.

UM1956 says " In this case [external 3.3V power supply]the ST-LINK is not powered, thus programming and debugging features are not available. When the board is powered by +3V3 (CN4 pin 14), the solder bridge SB14 and SB9 (NRST) must be off."

> as long as you leave the SWD pins of the MCU in SWD configuration.

where can i configure this?

> UM1956 says

I read it differently: "... ST-LINK is not powered [by that external 3.3V power supply]..."

Must admit that I haven't tried it out but thats what the schematics tell me: U4 powers ST-LINK from USB (U5V) and U3 powers the target MCU unless you open SB14. SB9 must be opened because if ST_LINK is not powered it would keep NRST low and the target MCU would stay in reset.

>> as long as you leave the SWD pins of the MCU in SWD configuration

> where can i configure this?

The SWD interface is always available immediately after reset, thats also the reason why the debug interface can trigger NRST causing a reset.

But your program might override that. Main reasons for overriding are: you are low in pin count and need those pins for something else, or you want to obscure the debug interface a little from hackers.

See also the Reference Manual "SWJ-DP pin assignment"

If you use STM32CubeIDE the configuration is done in the IO config file (.ioc) editor. Check that System Core SYS Debug Serial Wire is enabled.

MSimo.1
Associate II

alright.

  • I enabled Debug Serial Wirte in the .ioc FIle
  • I connected SWDIO, SWCLK, GND and VDD from the ST-Link(broken off) to the SWD Connector of the Nucleo Board.. According to the schematic
  • i connected NReset from the ST-Link board (pin5) to NRST of the Nucleo board (CN3 Pin3)
  • I removed the 2 Jumpers (CN2) from the ST-Link
    • JP 3 = on ; JP 4 = on ; JP1 = OFF
  • Removed solder bridges SB9 and SB14 from the nucleo board
  • the ST-Link is powered though USB
  • the Nucleo Board is powered through 3.3V.

the LED of the ST-Link is green(not blinking) and my host-PC shows its usb mass storage

If i click on the debug icon in CubeIDE it shows me a device not found error..

Target no device found

Error in initializing ST-LINK device.

Reason: No device found on target.

Any suggestions?