Skip to main content
Associate
October 24, 2023
Solved

STM32 Bootloader firmware write over uart

Hi everybody,

I'm working on a project where I have a pi cm4 connected to a STM32 (during testing we're using a STM32G07 dev board, but production will be using an STM32G03 chip). I've been asked to write a program to allow the cm4 to update the firmware via the uart. I've managed to get the program to reliably access the bootloader and run get, getv, getid, and readmem (for the flash memory). However when I try to run the write memory command it appears to run successfully, but when I read the memory address I just wrote to it returns the original value. I'm fairly certain that the write protection has already been disabled (checked using STM32CubeProgrammer), but I decided to try and run the write unprotect command just encase, but the chip seem to just hang after running the command.

I'm a recent graduate, and this is my first job, so I'm fairly uncertain as to what I'm doing, so it's very possible I'm missing something important. Thanks for any assistance and patients.

This topic has been closed for replies.
jbreaperBest answer
Associate
October 25, 2023

I've managed to solve me issue, it was two things;

  1. I was neglecting to erase the areas of memory I was going to write too (I had tested this at one point but that leads into point 2).
  2. I had been using the "erase" command (0x43), when in I should of been using the "Extended Erase" command (0x44).

Thanks @TDK and @Tesla DeLorean,

I'm going to throw myself into the ocean now

9 replies

TDK
October 24, 2023

Flash needs to be erased before being written. Are you doing that? It should be all 0xFF before writing.

"If you feel a post has answered your question, please click ""Accept as Solution""."
jbreaperAuthor
Associate
October 24, 2023

I tried to run a global erase and it gave me a NACK back. I'm away from the test rig for the rest of today but I'll try and get full interaction tomorrow if it's needed.

(knew I would forget to put something in the post)

TDK
October 24, 2023

Are you writing the entire flash word (64 bits, aligned)? Less will not work.

It might be helpful to post a log of bytes sent and bytes received in the following transactions:

  • read an address
  • write to that address
  • read that address again
"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Guru
October 24, 2023

Not really a hospital..

Can't say I've tried the G0. Tried others with AN3155 described protocol, and L0 with the MRK WAN1300 board in more recent times.

I guess you could tap the RX/TX and watch the interaction as performed by STM32 Cube Programmer.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
jbreaperAuthor
Associate
October 25, 2023

I wasn't properly aware that Cube had this option. This help me tremendously, turned out I was using the wrong erase function, I've got everything working now.

jbreaperAuthorBest answer
Associate
October 25, 2023

I've managed to solve me issue, it was two things;

  1. I was neglecting to erase the areas of memory I was going to write too (I had tested this at one point but that leads into point 2).
  2. I had been using the "erase" command (0x43), when in I should of been using the "Extended Erase" command (0x44).

Thanks @TDK and @Tesla DeLorean,

I'm going to throw myself into the ocean now