Skip to main content
Associate III
December 29, 2024
Question

Programming pins in the STM32G031J6M6 microcontroller

Hello to all developers!)

I am interested in the following question: is it possible to use the pins of the STM32G031J6M6 microcontroller first for programming (SWCLK, SWDIO), and then for another functionality, for example for UART?

Maybe there is some separate programming mode and a separate functional mode? Or for example, do I need to use Reset to perform programming? I know that the PIC10 microcontroller uses the same pins for programming and performing functions.

I would be grateful for the answer!!!1.png

This topic has been closed for replies.

7 replies

Tesla DeLorean
Guru
December 30, 2024

It's going to get ugly.

If you don't commit a pin the NRST, you'll either need to power cycle the part, or facilitate it reseting via some user interface or user interaction via your UART

I might suggest putting an idle loop in Reset_Handler to burn a few hundred thousand cycles to allow time for the debugger to probe/connect out of power-up/reset before you get to main() and reconfigure the SWDIO/SWCLK to alternate functionality or different bond-out pin usage.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Associate III
December 30, 2024

Sorry, I don't fully understand what you're saying.

 

Tesla DeLorean
Guru
December 30, 2024

Which part?

That the interaction of the debug probe needs the pins to be in/available for SWDIO/SWCLK? That there is quite a significant time window needed from the part starting to you reconfiguring the pin usage/function in order to wrestle control? That gets more complicated if it can't control the process via "Connect Under Reset" where it would normally try to reset and then try to initiate the debug sequence?

Perhaps start by forumlating and communicating how you plan to use the very limited pin count.

You'd need to have SWDIO/SWCLK to be usable in a manner that doesn't conflict with other board function whilst the debugger is connected.

Some reason the smaller UFQFPN28 couldn't be used?

https://www.st.com/resource/en/datasheet/stm32g031j6.pdf

 

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
TDK
December 31, 2024

> is it possible to use the pins of the STM32G031J6M6 microcontroller first for programming (SWCLK, SWDIO), and then for another functionality, for example for UART?

Yes, this is possible. However, if the pins are defined as UART you will be unable to connect over SWD. This also means debugging with SWD will not be possible. Ensure you are able to enter the bootloader or recover the chip in some other manner. Inserting a 1sec delay on startup before re-assigning the pins can work, if you are quick with connecting.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Associate III
January 2, 2025

The option with a delay at the beginning of the program sounds good.
Is it possible to perform the first firmware via the SWD interface, and then when the pins are marked for UART, flash via the UART interface?

TDK
January 2, 2025

> Is it possible to perform the first firmware via the SWD interface then when the pins are marked for UART, flash via the UART interface?

You'll have to get into the bootloader if you want to use the UART interfaces supported by the bootloader. There is no way to run the bootloader for 1 second, then fall back to running the application if nothing responds.

"If you feel a post has answered your question, please click ""Accept as Solution""."