Author Topic: Help with 'Flashing' STM32F1xx Series  (Read 2034 times)

0 Members and 1 Guest are viewing this topic.

Offline fmashockieTopic starter

  • Regular Contributor
  • *
  • Posts: 241
  • Country: us
Help with 'Flashing' STM32F1xx Series
« on: September 02, 2023, 07:06:32 pm »
Hi everyone! I'm relatively new to the blog, but have been a fan of EEVBlog YT channel for a long time! Anyway, I was hoping to get some help/info regarding flashing a STM32F1xx series microcontroller.  This micro is currently employed in an APC UPS BR1500G I am trying to fix.  I have a thread going on this repair in the 'Repair' forum (https://www.eevblog.com/forum/repair/repair-help-for-apc-ups-br1500g-f06-error/).  But basically, I've come to the conclusion there's a good chance that one of the GPIO pins on the original micro has gone bad.  So I would like to replace it with a new micro, but I've never flashed one before.

I did some research and it seems like there is a lot of resources for programming the STM32 micro family.  I started by reading the ST Application Note 2606 (https://www.st.com/resource/en/application_note/an2606-stm32-microcontroller-system-memory-boot-mode-stmicroelectronics.pdf).  I found out how to put the STM32F1 into bootloader function and how to interface with it.  It appears for the STM32F1, the bootloader supports USART.  So I bought a FTDI USB to UART cable (datasheet here https://ftdichip.com/wp-content/uploads/2020/08/DS_C232HD_UART_CABLE.pdf).  Then I was going to use the free software on ST's website called STM32CubeMX (info here https://www.st.com/en/development-tools/stm32cubemx.html) to enable the bootloader function and flash the micro.

This will be my first attempt at doing something like this.  I was hoping someone could tell me if I am on the right track?  If not, what am I missing?? Also, can I connect the micro to this adapter cable while it is still in-circuit on the original PCB? Do I have to remove it for any reason??   

I would greatly appreciate any help/info anyone has to offer.  Thanks in advance!!
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5914
  • Country: es
Re: Help with 'Flashing' STM32F1xx Series
« Reply #1 on: September 02, 2023, 07:26:02 pm »
To enable the bootloader you must pull BOOT0 pin to VDD.
Then power it on, or trigger a reset by pulling nRST low for a moment.
Now it'll be in bootloader mode.

You don't need all the CUBE crap, you can use this:
https://www.st.com/en/development-tools/flasher-stm32.html

Check AN2606, page 75:
https://www.st.com/resource/en/application_note/an2606-stm32-microcontroller-system-memory-boot-mode-stmicroelectronics.pdf


Connection goes like this:

Adapter             STM32
   TX                   PA10 (31)
   RX                   PA9 (30)


Check the pinout in the datasheet:
https://www.st.com/resource/en/datasheet/stm32f103c8.pdf
« Last Edit: September 13, 2023, 06:09:30 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: fmashockie

Offline fmashockieTopic starter

  • Regular Contributor
  • *
  • Posts: 241
  • Country: us
Re: Help with 'Flashing' STM32F1xx Series
« Reply #2 on: September 02, 2023, 09:08:56 pm »
Thank you David! And I can do all this with the micro still in-circuit on the original board? I shouldn't have to desolder it?
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5914
  • Country: es
Re: Help with 'Flashing' STM32F1xx Series
« Reply #3 on: September 02, 2023, 10:03:27 pm »
Not really unless the programming pins are used for something else.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: fmashockie

Offline fmashockieTopic starter

  • Regular Contributor
  • *
  • Posts: 241
  • Country: us
Re: Help with 'Flashing' STM32F1xx Series
« Reply #4 on: September 13, 2023, 05:30:25 am »
Hey everyone - I was hoping to get some additional help on trying to flash this STM102C8 (datasheet attached) micro that controls an APC UPS BR1500G I am trying to repair.  I've ran into some trouble connecting to the micro via STMCubeProgrammer.

I am using a FTDI UART to USB cable (datasheet attached) and the STMCubeProgrammer software.  I installed the drivers for the FTDI cable as well from their website.  I also got a LQFP48 adapter board in case I had to remove the chip from circuit to flash it. 

I read the ST application note 2606 to get info on the bootloader function for this chip.  Here's how I set it up:
-Connected the VCC 3.3V (red) wire from the FTDI cable to VDD on micro
-Connected ground (black) wire from FTDI cable to VSS on micro
-tied BOOT0 (pin 44) on micro high (3.3V)
-tied BOOT1 (pin 20) on micro low (gnd)
-Connected the TXD (orange) wire from FTDI cable to PA9/USART1_TX (pin 30) on micro
-Connected the RXD (yellow) wire from FTDI calbe to PA10/USART1_RX (pin 31) on micro
-I selected 'UART' in STMCube software and checked to ensure serial configs matched (see photo attached).

Of course, once I was finished connecting everything, I tried to connect and an error message popped up saying 'Error activating device - check bootloader and serial configs and reset'.  I double checked everything and powered cycled my setup and tried again - same result.  I tried tying the NRST pin low to see if that would reset it, but that still gave me the same error. I tried connecting to the micro both in-circuit and out of circuit.

It should be noted that the reason I am trying to flash this chip in the first place is because I suspect it has some faulty GPIO pins.  Pin 27 (PB14) is shorted to VDD.  And PB13 (pin 26) is not working at all.  These pins are responsible for the AVR function of the UPS.  But otherwise the unit works fine.  So I assumed I would still be able to interface with it to flash it.

I was hoping you guys could take a look at my set-up to make sure I'm not missing anything (I've attached photos as well).  Any help would be greatly appreciated!  Also, if the micro is read-protected by the manufacturer, would this explain the error message I am getting?

Thanks!
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5914
  • Country: es
Re: Help with 'Flashing' STM32F1xx Series
« Reply #5 on: September 13, 2023, 12:54:30 pm »
-Connected the TXD (orange) wire from FTDI cable to PA9/USART1_TX (pin 30) on micro
-Connected the RXD (yellow) wire from FTDI calbe to PA10/USART1_RX (pin 31) on micro

Probably you have TX/RX backwards.
Connection goes like this:
Adapter             STM32
   TX                   PA10 (31)
   RX                   PA9 (30)
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline DELTA67

  • Regular Contributor
  • *
  • Posts: 57
  • Country: fr
Re: Help with 'Flashing' STM32F1xx Series
« Reply #6 on: September 13, 2023, 05:15:20 pm »
Have you arrived to flash your STM fmashockie?
With STM32F103C8 I use the method that DavidAlpha has described very well in his 1st reply .
Simply be sure that TX/RX are connected backwards.

TX (adapter) ====> RX (STM32)
RX (adapter) ====> TX (STM32).

I use default parameters in STM32_flasher tool, only need to choose the right COM port of your adapter.
 

Offline fmashockieTopic starter

  • Regular Contributor
  • *
  • Posts: 241
  • Country: us
Re: Help with 'Flashing' STM32F1xx Series
« Reply #7 on: September 14, 2023, 04:26:15 am »
Thanks for everyone's reply!

So I did indeed have the TXD and RXD wires reversed.  I also lowered the baud rate (115200 is the max according to application notes) and set parity to even.  After I fixed all that, I was able to get the original micro connected to the STMCubeProgrammer software no problem!  It appeared to read all the flash memory successfully.  So I extracted the flash memory and saved it to my PC.  I then desoldered the original chip from the LQFP48 adapter board and soldered in a brand new micro.  I made all the connections, configured the bootloader, and connected to the chip.  I downloaded the flash memory I saved from the original chip onto the new micro.  I verified the files were exactly the same.  Then I desoldered the new chip from the adapter board and soldered it onto the UPS PCB.  I powered it up and..... nothing happened...  :palm:

I verified the display was getting power.  It definitely appears that the new micro was not programmed properly.  I then connected the new micro to the STMCubeProgrammer again (thank god it worked in-circuit because I did not feel like desoldering it again!) to verify the flash memory was there and it is. 

Is there something else that I am missing as far as programming the chip?  Some crucial step perhaps? The only thing that seems out of the ordinary (maybe?) is that a few of the address lines in the flash memory have all zeros (see photo attached).  But that is how the flash memory from the original micro read as well.  Sorry, if I am not giving enough info - this is my first time attempting this.  But any help you can provide would be greatly appreciated! I can't thank everyone enough so far!! Also, here's a video below summarizing where I'm at so far.  Thanks again!!

 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5914
  • Country: es
Re: Help with 'Flashing' STM32F1xx Series
« Reply #8 on: September 14, 2023, 05:19:02 am »
Did you set size 0x20000 when reading the old one?
If you left it to 0x400, definitely didn't read the entire flash.
The final bin file should be 128KB, by the looks of it, it's 1KB instead!

All those 0s belong to nvic isr table.
Lots are unimplemented in the Cortex-M3 core, others might not be used by the program, so not really suspicious.
« Last Edit: September 14, 2023, 05:25:42 am by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: fmashockie

Offline darkspr1te

  • Frequent Contributor
  • **
  • Posts: 290
  • Country: zm
Re: Help with 'Flashing' STM32F1xx Series
« Reply #9 on: September 14, 2023, 05:25:12 am »
I agree with David, if you left it at 0x400 for the read side then you got only 1k of 64k so the jump instruction 0x8000edd wont happen , i normally put 0xfffff in the size box when reading or use stflash read all function.


*edit* if your board has a connector J40 next too a couple of caps then check to see if pins PA13/PA14 goto that point as that looks like a programming header to me so you might just have to reflow the "old chip" to your header board and leave the new chip in place and program.


see
https://i.ebayimg.com/images/g/MIgAAOSwIRNkEJYA/s-l1600.png
https://i.ebayimg.com/images/g/k9EAAOSwwW1kEH7R/s-l1600.png


darkspr1te

« Last Edit: September 14, 2023, 05:33:24 am by darkspr1te »
 
The following users thanked this post: fmashockie

Offline fchk

  • Regular Contributor
  • *
  • Posts: 245
  • Country: de
Re: Help with 'Flashing' STM32F1xx Series
« Reply #10 on: September 14, 2023, 06:26:36 am »
I read the ST application note 2606 to get info on the bootloader function for this chip.  Here's how I set it up:
[...]

Here is the datasheet:
https://www.st.com/resource/en/datasheet/stm32f102c8.pdf

Look at section 5.1.6 "Power supply scheme".
The capacitors shown there are required for proper operation, and they need to be within a few mm of the corresponding pin pair. Distance is critical here. PCB traces are not a zero ohm connection but act as capacitors, inductors and resistors. So using a generic adapter board is not the brightest idea.

fchk
 
The following users thanked this post: fmashockie

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5914
  • Country: es
Re: Help with 'Flashing' STM32F1xx Series
« Reply #11 on: September 14, 2023, 06:49:05 am »
Anyways a stm32 pin going bad would be very rare.
There're hundreds of parts there: Resistors, transistors, logic ICs...
Maybe it's not a bad relay, but a bad part in the signal path that checks the actuation of xyz part.

Also the board listed few posts earlier is just $20: https://www.ebay.com/itm/364182438674
« Last Edit: September 14, 2023, 07:09:14 am by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: fmashockie

Offline uer166

  • Frequent Contributor
  • **
  • Posts: 893
  • Country: us
Re: Help with 'Flashing' STM32F1xx Series
« Reply #12 on: September 14, 2023, 07:07:04 am »
Anyways a stm32 pin going bad would be very rare.

I've seen that specific parts' analog pin fail (and only analog), so all ADC readings are zero out of a specific pin, but otherwise fully functional. Weird shit happens..
 
The following users thanked this post: DavidAlfa

Offline fmashockieTopic starter

  • Regular Contributor
  • *
  • Posts: 241
  • Country: us
Re: Help with 'Flashing' STM32F1xx Series
« Reply #13 on: September 14, 2023, 02:23:48 pm »
Did you set size 0x20000 when reading the old one?
If you left it to 0x400, definitely didn't read the entire flash.
The final bin file should be 128KB, by the looks of it, it's 1KB instead!

All those 0s belong to nvic isr table.
Lots are unimplemented in the Cortex-M3 core, others might not be used by the program, so not really suspicious.

Thank you so much DavidAlfa.  I responded to you in my other thread in the repair section.  But I'm pretty sure I understand what you mean by read size! I will give it another try. 

I agree with David, if you left it at 0x400 for the read side then you got only 1k of 64k so the jump instruction 0x8000edd wont happen , i normally put 0xfffff in the size box when reading or use stflash read all function.


*edit* if your board has a connector J40 next too a couple of caps then check to see if pins PA13/PA14 goto that point as that looks like a programming header to me so you might just have to reflow the "old chip" to your header board and leave the new chip in place and program.

Thanks! This is what I will plan to do today.  I will check that connector on the original PCB.  This STM32F102 micro's bootloader function only suggests connection via UART in the ST 2606 application note.  So I only know how to connect using the TXD and RXD pins (pin 30, pin 31).  When you say programming headers, would that mean interfacing with the micro a different way? Excuse my ignorance, again this is brand new stuff for me.

I read the ST application note 2606 to get info on the bootloader function for this chip.  Here's how I set it up:
[...]
Look at section 5.1.6 "Power supply scheme".
The capacitors shown there are required for proper operation, and they need to be within a few mm of the corresponding pin pair. Distance is critical here. PCB traces are not a zero ohm connection but act as capacitors, inductors and resistors. So using a generic adapter board is not the brightest idea.

Wow I didn't even consider that.  I hope I didn't do any damage to the new and old chips by attaching it to a generic adapter board like this.  Do you have recommendations for boards to do this with?  I guess I found that I can connect to the micro in-circuit (i.e. the original UPS PCB) anyway.  I only removed it because I was having trouble connecting to it at first and thought that was the problem  :palm:

Anyways a stm32 pin going bad would be very rare.
There're hundreds of parts there: Resistors, transistors, logic ICs...
Maybe it's not a bad relay, but a bad part in the signal path that checks the actuation of xyz part.

Also the board listed few posts earlier is just $20: https://www.ebay.com/itm/364182438674

Thank you again DavidAlfa.  But I have definitely narrowed down the issue to the micro.  I have traced the signal paths to relays in question.  Both PB14 and PB13 connect to their own internally biased NPN transistor and a zener diode before the buck and boost relays, respectively.  These components are fine.  There's nothing else in the chain that could be causing this.  Also, I removed the original micro and as I said, VDD and PB14 are shorted together - that definitely should not be.  Thank you for providing a link to a new board.  But my interest in getting this to work is to learn new skills (like this for example!) and repair it myself.  Not just replace the entire board.  What is the fun in that!?  :-DD

 

Offline fmashockieTopic starter

  • Regular Contributor
  • *
  • Posts: 241
  • Country: us
Re: Help with 'Flashing' STM32F1xx Series
« Reply #14 on: September 15, 2023, 05:55:33 am »
Update - Changing the read size to 0x20000 worked!! Was able to flash the micro successfully - thanks everyone!
 

Offline fmashockieTopic starter

  • Regular Contributor
  • *
  • Posts: 241
  • Country: us
Re: Help with 'Flashing' STM32F1xx Series
« Reply #15 on: September 15, 2023, 02:30:02 pm »
Consider yourself extremely lucky, it's very rare they didn't set the readout protection  ;)
Is it working now?

Yes I know! That was what I was afraid of.  Also, I haven't had too many repair experiences where the micro is the problem, and it is not completely destroyed/damaged due to overvoltage.  So the fact that I could still extract the flash memory from it and fix it really made for a rewarding repair experience!  It is working great now (I updated the repair forum post for this UPS as well)!  Thank you so much for your input DavidAlfa - couldn't have fixed it without your help!!

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf