Abo
So I guess my question should change from "uploading user code (the .bin file)" to "writing self contained STM32F".
Yes, exactly.
My understanding is that the normal flashing procedure with Maple IDE is
1. USART bootloader flashes the Maple bootloader, a self-contain program via USART (run in python)
2. Maple bootloader flashes the user program, not a self-contain program via USB (run with dfu-util).
Yes.
The combine bootloader.bin file + user code.bin file + some work by the Maple IDE (or dfu-util), create a self-contain firmware.
Sort of yes. The bootloader.bin is permanently on the board, and creates the environment for the uploaded user code.bin.
I guess the goal I need to achieve would be
1. USART bootloader flashes the user program, a self-contain program via USART (run in python)
Yes, with a broken USB that is exactly what you need. There are several other USART uploaders that run on the host PC. I think I saw a list at PyMite or an associated web site.
From the look of the python code, it feels like I can upload a .bin file to any memory location I want.
Not quite. There has to be values for the reset vector, which is, by default at 0x00000000. Combinations of the BOOT pins will give three options for its location (See RM0008, section 3.4 "Boot configuration"). There are a few other vectors which should be initialised. Once that is set up, yes, the program can be anywhere in valid flash or RAM.
Would it be possible to modify the wirish.c init() function so that the compiled .bin file become a self-contained STM32 program?
Where is wirish.c? I thought that had been changed. Do you mean boards.cpp?
I am working through the same question.
Essentially
- interrupt vectors need to be set up in the NVIC vector table,
- reset handler (and preferably a default handler for faults and interrupts)
Then execution of the reset handler runs (or calls) code for:
- initialised variables need to be initialised (by copying from a segment in flash)
- uninitialised variables need to be zero'd
- system and peripheral clocks, flash and NVIC
- static class initialisers,
- systick timer, and other peripherals
I am 98% certain there is startup code (cs3) that comes with CodeSourcery lite that covers the first 4 steps. That source isn't included in the Maple distribution, and it might be that the license doesn't allow LeafLabs to include it.
Depending on what you need to do, for example if USB is not needed, then the cs3 code might be everything.
ST Micro also supply all the code needed for setup. It is a bit ugly, mostly in assembler, which is not necessary. Cortex-M3 functions can be called with nothing more than a stack pointer set, and a starting address.
(full disclosure: I am not a member of LeafLabs staff.)