cancel
Showing results for 
Search instead for 
Did you mean: 

Help using SWD and NRST as GPIO safely - STM32G031

NGD
Associate II

Hi, so I've chosen to use STM32G031J6M6 8-pin version for an audio level meter project to get me started. I'm using pin 1 as the adc input, 2 and 3 are 3v3 and gnd, obviously. I was hoping to use the remaining 5 pins as GPIO outputs attached to LEDs for the level display. I'm using the DISCO board to program.

I'm pretty sure I bricked one of my chips already though, I think because I assigned the NRST (pin4) as well as the SWDIO and SWDCLK (pins 7 and 😎 as GPIO outs and I guess then that there was no way to hold the chip in reset and program or debug it? The only other thing I did before it was unresponsive was to probe some of the board traces with my multimeter in diode/continuity mode.

I'm trying to be careful not to break another chip so I wanted to be sure before assigning those pins.​

Is there a way I can use all these pins as GPIO output but not lock myself out of programing / debugging the chip? I read something about maybe adding a delay before the pins are assigned? Would this be as simple as placing a HAL_Delay(1000) towards the top of the main function in main.c? I'm using the CubeIDE and it's auto code generation functionality to assign the pins. I am still fairly new to this level of MCU programming having come from using Arduino so I might need baby steps.

Thanks.

11 REPLIES 11
NGD
Associate II

Thanks for the response. So I guess I'd have to add this delay in 'int main(void)' right?

The generated code goes: HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_ADC1_Init(); MX_TIM16_Init(); HAL_TIM_Base_Start_IT(&htim16); then into the while loop.

From what you have said I'm guessing that the HAL_Delay(5000); should be added after SystemClock_Config() but before MX_GPIO_Init(). Is this correct?

Yeah I discovered yesterday to use the NRST pin I'd have to use STM32CubeProgrammer to set the User Option Byte so I can use that as GPIO. Attempting to use it before doing that (ie. setting it to GPIO output and attaching an LED through a current limiting resistor) just seemed to keep the chip in a reset state.

So to reiterate, If I am to set the NRST user option byte so that it is a GPIO output and I am also to set the SWDIO and SWDCLK pins as GPIO outputs I am likely to lock myself out of reprogramming or debugging the chip unless I prepare it before hand with this 5 to 10s delay which will give me a window of opportunity to access the chip from power on before it reassigns the pins.

Am I talking sense? Thanks again.

Hello,

I tried to do as you say and the problem was solved. I had some chips stuck. Thanks for your help.

Best regards.

Roberto