More progress…I basically removed all the existing Spark Core USB driver code and pulled in the code from “STM32F105/7, STM32F2 and STM32F4 USB on-the-go Host and device library (UM1021)”. They have a USB DFU example that was extremely similar to the Spark Core bootloader so I was able to get it working based on that example.
Since the STM32F4’s FLASH management is different than the F1 (it goes by sectors, not pages), I reworked the memory mapping a bit to line up with the STM32F4’s sectors. My memory map for the F4 is as follows:
0x08000000 Bootloader (32K max - Sectors 0 and 1)
0x08008000 System Flags (16K max - Sector 2)
0x0800C000 Firmware (976K max Sectors 3-11)
I was able to create a separate “Blinky” binary and flashed it to 0x0800C000. After doing things like relocating the vector table and updating the linker script, I was able to force the bootloader to load my Blinky app. If I let the bootloader enter DFU mode, it DOES show up as a device in my “dmesg” output. I haven’t done much testing with dfu-util with it yet.
I did some commenting out of the Spark RGB led code since the STM32F4 Discovery doesn’t have a RGB LED. I changed the code to use the on board LEDs for indications. I’ll probably end up with a RGB LED in my final design, I see it’s kind of handy.
I need to verify that my STM32F4 Discovery is working properly with the external flash chip over SPI. That is one of my next tasks. Then I need to work on porting the main firmware over. Luckily, I think the further I get away from the hardware in the code, the less modifications there will need to be. Stay tuned for updates.
My bootloader repo: https://github.com/lanteau/bootloader