STM32G030K6T6TR problem re-programming - Page 1
Forum section: electronics / general

author: amwales
author_rank: Regular Contributor
timestamp: January 22, 2025, 11:09:59 am
content: I am have been having limited success with an STM32G030K6T6TR, I purchased the part from lcsc and am confident that its not a clone.I started out with a STM32CubeIDE 1.16.1 thinking that getting a LED blinky would be trivial using the tools provided by ST.I created a new project selecting the appropriate chip from the pinout & configuration panel I double clicked PA0 and set it to GPIO_Output.I then generated the code and made the following changes to the while loop inside main.The while loop inside mainCode:/* Infinite loop *//* USER CODE BEGIN WHILE */while (1){HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_0);HAL_Delay(500);/* USER CODE END WHILE *//* USER CODE BEGIN 3 */}/* USER CODE END 3 */I built the target it compiled with All good so far, I got the following output.Code:arm-none-eabi-size simpletest1.elfarm-none-eabi-objdump -h -S simpletest1.elf > "simpletest1.list"textdatabssdechexfilename525212157268361ab4simpletest1.elfFinished building: default.size.stdoutFinished building: simpletest1.list10:40:35 Build Finished. 0 errors, 0 warnings. (took 924ms)I was hoping I could program my chip from the IDE but after a fruitless search for a program or download button in the IDE I instead downloaded and install the STM32CubeProgrammer.I had the chip installed in a breadboard, using a breadboarded ch340k and running at 3.3v powered externally I connected to the ch340k to the USART2_RX pin 10 PA3 and USART2_TX pin 9 PA2 ( I added a 1.8k resistor pullup on the RX pin ).The STM32G030K6T6TR was connected to 3.3v/VDD pin 4 and GND/VSS pin 5.I added an LED to PA0 pin 7.Connecting this up to a USB cable on my PC the COM port appeared as I expected.Using the STM32CubeProgrammer I selected the UART and clicked connect ( NOT change any of the default settings ).unfortunately I did not collect the output, but it all looked good to me.I then browsed for the file simpletest1.elf that was generated from the IDE and clicked on the download button.At this point I cannot remember if I had added a jumper to the boot0 pin but since I was able to connect through the programmer I knew I was inside the bootloader.I then pressed removed and reapplied power to the chip and the LED started blinking, success.From this point on I have not been able to reprogram the chip.I am beginning to believe that somehow the chip has been configured as read protected?Things I have triedcombinations of pulling the boot0 pin low and high along with resetting the chip, then attempting to reconnect via the uart.changing all the wires on the breadboard after find out some where steel.using a cloned j-link to attempt to program with that while in reset, not in reset.using j-link commander to connectconnected the nrst/pin 6 on the chip to the reset output on the j-linkusing the j-link stm32 unlockerwhatever I do when I re-apply power the led starts blinking again.I have a genuine j-link edu that I have never used but haven't tried that yet as I don't have a header for the teeny-tiny pins.The more I read online the more I am convinced I have activated the chips read protection mechanism, I assume that the default setting within the IDE/Programmer would not have been set to do this.Ideas?

author: elektryk
author_rank: Regular Contributor
timestamp: January 22, 2025, 11:26:19 am
content: QuoteUnfortunately default setting in Cube IDE is SWD disabled, but it shouldn't prevent you from using bootloader.

author: amwales
author_rank: Regular Contributor
timestamp: January 22, 2025, 02:52:07 pm
content: Ok, I think I found the issue, it looks like the default for a virgin STM32G030 ( empty flash ) is to boot from the boot loader.The production value of the option byte is set such thatnBoot0 = nBoot1 = nBOOT_SEL = 1 and empty flashDuring programming of the virgin device you must set the nBOOT_SEL = 0 or it will no longer enter the bootloader,regardless of the value of Boot0 pin. I guess this must be done through OB in the STM32CubeProgrammer, what a palava.Explained by Peter BENSCH inhttps://community.st.com/t5/stm32-mcus-embedded-software/stm32g030-does-not-enter-bootloader-when-boot0-is-3-3v-what-is/td-p/222450He also referenceshttps://www.st.com/resource/en/application_note/cd00167594.pdfhttps://www.st.com/resource/en/reference_manual/dm00463896.pdfStill trying to understand why it cannot be programmed with SWD while held in reset, maybe its my j-link?I'll solder another chip onto a breakout and breadboard but this time I'll look at the option byte.Maybe I should buy a genuine st-link?Maybe try the j-link edu....

author: voltsandjolts
author_rank: Unknown
timestamp: January 22, 2025, 04:26:08 pm
content: Quote from: amwales on January 22, 2025, 02:52:07 pmHeld in reset? Trying to program it while reset is asserted the whole time?

author: amwales
author_rank: Regular Contributor
timestamp: January 22, 2025, 04:38:41 pm
content: https://www.eevblog.com/forum/microcontrollers/stm32-programming-with-st-link-problem/@rolo mentions it here in reply #2 "Try setting the programmer options to "connect under reset". Then press reset on the target controller, keep it pressed while klicking on connect in the programmertool, release reset on controller. Programmer should connect to the controller now."

author: amwales
author_rank: Regular Contributor
timestamp: January 22, 2025, 06:44:52 pm
content: So I tried the genuine j-link edu, looks like the j-link clone was the culprit.Connecting via SWD I was able to set nBOOT_SEL = 0 which causes the boot0 pin to work.I was then able to start the booloader and use the UART to connect to the device,So, to reiterate, if you are working with an STM32G030 device the default factory behaviour is to start the bootloader because the flash is empty.As soon as you flash it, if you did not set nBOOT_SEL = 0 it will NOT start the bootloader again regardless of the state of the boot0 pin.You can recover the boot0 pin behaviour using SWD and a j-link and most likely an st-link (I didn't try).

author: DavidAlfa
author_rank: Super Contributor
timestamp: January 26, 2025, 04:01:40 am
content: Just use the jlink to program it.Click on the green "play" button, "Run as...", "stm32...".In the opening window set Jlink as your programmer and you'll be done!