Today, I tried to flash the firmware for my STM32 board on my Mac. It was a bit of a headache, but I finally figured it out. So, I decided to write down the steps I took to save others from the same struggle.
First off, I needed a way to flash the STM32 chip. I heard about the STM32CubeProgrammer, and people said it worked on macOS, but I was a bit skeptical. It was a mess to get it working. After some digging, I found a tool called stm32flash. It’s a simple command-line tool, and it seemed like just what I needed.
I downloaded the latest version of stm32flash. I was a bit confused at first, but I managed to compile it from the source code. I opened the terminal, went to the folder where I saved stm32flash, and ran the build commands. It took a few minutes, but finally, I had the stm32flash executable ready.
Next, I connected my STM32 board to my Mac using a USB-to-serial adapter. I made sure the BOOT0 pin was pulled high to put the chip in bootloader mode. It’s like a secret handshake to tell the chip to listen for new instructions.
With the board connected, I opened the terminal again. I used the following command:
stm32flash -w <*> -v -g 0x0 /dev/*-<your_serial_port>
I replaced <*>
with the path to my firmware file and <your_serial_port>
with the actual serial port of my adapter. I had to do some trial and error to find the right port, but eventually, I figured it out. The -w
option tells stm32flash to write the firmware, -v
is for verify, and -g 0x0
tells it to run the code after flashing. There is also the option -b to select the bit rate. It didn’t worked the first time but after a few tries it finally worked.
I hit enter, and to my relief, the flashing process started! I saw some messages in the terminal indicating that the firmware was being written to the chip. It took a while, but finally, I saw a success message. I was pretty happy at this point, let me tell you.
After the flashing was done, I reset the board by pulling the BOOT0 pin low and pressing the reset button. I tried out the new firmware, and it worked perfectly! It was such a relief to see everything working as expected.
So, that’s how I managed to flash my STM32 firmware on my Mac using stm32flash. It was a bit of a journey, but I’m glad I persevered. Hopefully, this little write-up will help someone else out there who’s facing the same challenge. But also I found out there’s also another solution which is called System WorkBench, it is an Eclipse based IDE, I didn’t try this one. Keep on tinkering, folks!