2025-05-05 1:27 PM
I made a custom board using a C091KCT6. I assumed I would be able to figure out a way to display data in real time using printf. Unfortunately, I did not make provision to expose PA2 and PA3 (or indeed any pins other than the ones used by my board). PA2 is in any case in use as SPI1 MOSI. So I have pretty much accepted that I need to make a new custom board, and I am keen to ensure that I will be able to use printf this time!
I believe that two good solutions are to buy the STLINKV3-SET and either a) re-design the board to expose the PA2 / PA3 UART to that ST-LINK or b) re-design the board with an MCU that has a SWO pin and expose that to the STLINK-V3.
I would like two kinds of help, please: if I do not need to buy a new debugger or re-design the board, it would be great to hear how I can use printf with the setup I have, or avoid one of i) buying a new debugger and ii) re-designing the board.
If I do need to buy a new de-bugger and re-design the board, it would be great to have confirmation that both a) and b) above are options for me.
I have seven ST-LINK options available to me, one standalone and 6 dev kits:
Board | ST-LINK type |
Nucleo-C092RC | ST-LINK/V2EC |
STM32VLDISCOVERY | ST_LINK/V1 |
STM32F407G-DISC1 | ST-LINK/V2-A |
Nucleo-H753ZI | STLINK-V3E |
Nucleo-C031C6 | ST-LINK/V2-1 |
STM32F4-DISCOVERY | ST-LINK/V2-A |
NA | standalone ST-LINK V2 |
I believe that none of these options is suitable (I would love it if someone can persuade me I'm wrong, of course). The promising ones are the V2-1 and V3E ST-LINKs, but in order to use these I would need either i) to expose the SWO pin of the C091KCT6, or ii) connect PA2 & PA3 on the C091KCT6 to the ST-LINK/V2-1 or ST-LINK/V3E.
Option i) doesn't work because, I think, there is no SWO pin on the C091KCT6.
Option ii) doesn't work because, I think, there is no provision for connecting UART pins to the ST-LINKs ON THE BOARDS from a custom board, only from the MCU on the dev kit board.
If I get the STLINKV3-SET, then I can either connect PA2 & PA3 of the C091KCT6 to it (and do my SPI stuff elsewhere on the chip) or replace the C091KCT6 with a chip that has a SWO pin. (I am not concerned about BoM cost, this is a low volume project. But I am concerned about the cost of buying a J-link :) ).
I think I need printf specifically - I am driving a mechanical oscillator close to its resonant frequency, so I need the whole system to run without interruption in order to be able to assess how well the control system is functioning. So breakpoints are great, but the oscillation will die each time I halt execution.
Thanks for reading, apologies for the newbie questions and the long post!
Solved! Go to Solution.
2025-05-06 6:42 AM
@chisatholm wrote:J-LINK V2 ... J-Link 3.
You mean ST-Link ?
@chisatholm wrote:I'll then redesign the board slightly to bring out USART1 to a 14 pin Tag Connect !
You have a spare pin (6) on your 6-pin Tag Connect - why not use that for UART TX ... ?
2025-05-06 7:02 AM
I did mean ST-link not j-link, good spot!!
Also a good spot that I have a spare pin. I somehow had the fixed idea that I have to have the pair of connections, both RX & TX. But all I need is for my board to send info out to the world, I do not need to talk TO it, just listen. So thanks for shattering that misconception.
However, even if I get UART TX to the Tag Connect, I don't think my ST-link V2 knows what to do with it, does it?
If I get the ST-link 3, I think that doesn't know what to do with the six pin receptacle.
So either way, I need the 14 pin plug of nails, or, I suppose, I could hack something together to get the UART TX to a ST-link 3.
If I'm missing something, please LMK :)
2025-05-06 7:19 AM
@chisatholm wrote:However, even if I get UART TX to the Tag Connect, I don't think my ST-link V2 knows what to do with it, does it?:)
Indeed, it doesn't.
But you said you already have a separate UART-to-USB bridge?
@chisatholm wrote:If I get the ST-link 3, I think that doesn't know what to do with the six pin receptacle.:)
The ST-Link knows nothing about any receptacle - you have to arrange the appropriate connections.
2025-05-06 7:39 AM
Thanks for your reply Andrew Neil - appreciate it.
Are you suggesting I flash the C091 using the Tag connect cable from the ST Link V2, then disconnect that cable from the ST Link and connect it to the UART-USB bridge to extract data while the code is running?
I guess that saves me getting the new ST Link v3 and 14 pin tag connect cable, at the price of more faff for each change of code.
[Someone's going to suggest a mux/demux arrangement now :) ]
When I said the STLink 3 doesn't know what to do with the 6 pin receptacle, I meant that there isn't physically a way to plug it in, let alone having the right connection in the right place. But yes, take the point, thank you!
2025-05-06 8:07 AM
@chisatholm wrote:Are you suggesting I flash the C091 using the Tag connect cable from the ST Link V2, then disconnect that cable from the ST Link and connect it to the UART-USB bridge to extract data while the code is running?
Not really.
Just wire your TagConnect so that pins 1-5 go to the ST-Link, and pin 6 goes to the USB-to-UART
2025-05-06 11:53 AM - edited 2025-05-06 12:02 PM
> 14 pin Tag Connect
Wow! that's an overkill. 10 pins is enough. Tag-connect cables are expensive and more pins/holes mean more wasted space on the board. Even 6 pins is enough if you need only the TX line of the UART. If you want the printf to UART be independent from the debugger.
As @Tesla DeLorean wrote, SWDIO and SWCLK pins of STM32C031 can be re-purposed as UART TX and RX. In this case the existing 6-pin connector can be left as is, just the cable should be re-wired to a FTDI or other TTL to USB adapter, or to UART pins of the same ST-LINK v3 MINIE. Indeed a lot of options to consider.
2025-05-07 12:29 AM
Thanks everyone for your replies. I chose to respond to Pavel A., but the thanks is to all of you who chipped in and helped me get to a solution that works for me.
Out of fear of not getting the De Lorean "SWDIO and SWCLK pins of STM32C031 can be re-purposed as UART TX and RX" solution to work, I'm going to do a mix of things that have been suggested. For right now, I soldered a wire onto PA9 on the existing board to use as USART1_TX into the TDI bridge, which is working great.
I'll then make another iteration of the board with a two pin 0.1" header bringing out GND and PA9 /USART1_TX, which I can use for debugging and then remove before installation if need be.
This appeals to me because it's clean, I'm not hacking anything, I don't have to buy any cables/STinkls, it gives me an excuse to resolve the niggly 'why did I put that THERE?' issues on the current PCB and all the connections are reliable / reasonably robust / I don't have to remember where the eg yellow cable goes if it pings out of something.
In slower time, I'll try to work out the De Lorean solution - it would clearly be great to know how to get two pin flavours from one pin for other applications.
Thanks again, greatly appreciated!!