March 11, 2025

STM32F429 Discovery Kit - Git to the rescue

I got everything into a huge mess working on clocks. Now I would like to use git to go back in time before I got everything tangled up. In large part this is why I use git, though I virtually never do this.

One rule when you get in a mess is to not do anything in a hurry. What I am going to do is to clone the Hydra project from Github, build from that, and see where it gets me. I build for the black pill and it does not run at all.

I cloned into a separate directory (which I call "Mess") with the intent of keeping it separate from my actual working directory (which has recent work and uncommited changes). So now I have two copies of Hydra. I will leave my current work entirely alone and just try to get some historic code working again.

The copy I just cloned has the entire git history. It is a world unto itself. This means that I can now move back in time. I have done this before (doing checkouts for specific date/times) and have found that getting things back to the most recent state after such is tricky. This is why we are doing this in a separate copy I can throw away. We can see our commit history via:

git log
git log --pretty=oneline
The second form is more condensed, but the first is easier to grasp. I use this to pick out a has to give to git, then:
git checkout commit-hash
This article explains a lot of this, along with what it calls "detached head status", which is what has tripped me up before and is what I am taking pains to avoid: So, I pick a commit from 2 days ago, get the hash from "git log" and then:
git checkout fa218763648cffb1a8ba05714169a53f32c70656
error: Your local changes to the following files would be overwritten by checkout:
	Makefile
I use "git status" to discover the Makefile is the issue (and it told me that). Yes I did modify it. I do "git commit -a", then repeat the checkout command.

Now it works. It gives me a long explanatory warning about being in detached HEAD status. It even tells me:

HEAD is now at fa21876 Enable HS core for USB for F429
Which is indeed what I wanted and confirms that the hash I selected from the log really was the right one.

Get something to run

I try building this code for the F411 and that does not work. I drop that (put it on the list for later). I build the code for the F429 board and try running it on the F411. That does not work either, which is sort of surprising, but figuring that out is another total sidetrack, so we move on. I flash the code onto the F429 discovery board, and it runs, printing messages at 115200 baud. This is good. I have something that runs and talks to the serial port and I can work from there.

Now to remind myself of things I have been doing, I use this command:

diff -qr . ../Hydra | grep differ
Files ./event.c and ../Hydra/event.c differ
Files ./gpio_411.c and ../Hydra/gpio_411.c differ
Files ./hydra.h and ../Hydra/hydra.h differ
Files ./init.c and ../Hydra/init.c differ
Files ./led.c and ../Hydra/led.c differ
Files ./main.c and ../Hydra/main.c differ
Files ./Makefile and ../Hydra/Makefile differ
Files ./rcc_411.c and ../Hydra/rcc_411.c differ
Files ./serial.c and ../Hydra/serial.c differ
The above results have been trimmed to just show me recent work that was restricted to the top level directory. I begin evaluating changes and copying the files one by one from Hydra (the directory with the latest work).
Files ./hydra.h and ../Hydra/hydra.h differ -- OK (enum)
Files ./init.c and ../Hydra/init.c differ -- OK simple message
Files ./main.c and ../Hydra/main.c differ -- OK - blink test
Files ./event.c and ../Hydra/event.c differ -- OK - delay_ms
Files ./led.c and ../Hydra/led.c differ -- OK - red/green
Files ./gpio_411.c and ../Hydra/gpio_411.c differ -- OK
Files ./serial.c and ../Hydra/serial.c differ -- disco baud rate

Files ./Makefile and ../Hydra/Makefile differ
Files ./rcc_411.c and ../Hydra/rcc_411.c differ
I got the two LED on the disco board blinking. This was just a matter of enabling clocks for all these GPIO in rcc_411.c I put this fix into the Hydra main directory.

The current serial.c depends on rcc_411.c to inform it properly of the pclk2 bus clock speed, this is fixed in rcc_411.c

So now, all the differences are in rcc_411.c. The Makefile has big revisions, but should be OK.

The final story

I replace rcc_411.c in the Hydra directory with the file from "Mess" and I can rebuild and run from the latest code. So I can abandon this "Mess" clone with its detached HEAD and continue work in the latest branch.
Some important things to do: The F411 build works fine, runs with the correct baud rate, and blinks an LED. It does blink much faster than on the "disco", but that is because of the 8 Mhz crystal (when we expect a 25 Mhz crystal).

For the MCO clocks, I need to add some code from the new rcc code. I did this, and tried a few things, but it isn't working. I was going to use this to help debug the PLL code in rcc_411.c, but I worked it out without such.

Now that I have the F429 running at 168 Mhz, I need to retest the F411, which should run at 96 Mhz, then clean up rcc_411.c

Finally I can delete my clone with the detached HEAD. And I did!


Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org