Select Git revision
stm32-bootloader.txt
-
Signed-off-by:
Terraneo Federico <fede.tft@miosix.org>
Signed-off-by:
Terraneo Federico <fede.tft@miosix.org>
stm32-bootloader.txt 3.62 KiB
Bootloader for stm3210e-eval
----------------------------
This bootloader allows to load code to external RAM, for easy development
without wearing out the STM32's FLASH which is only rated 10000 write cycles.
Ofcourse, it is not suitable for release code, since at every reboot the loaded
code gets lost. Please also note that running code from external RAM will be
~10 times slower than internal FLASH, but for code development and debugging
it is fine.
This bootloader contains code to forward interrupts @ 0x6800000 which is the
start of the external RAM.
Installation on PC
------------------
You'll need gcc (and g++), CMake and the boost libraries installed.
Windows build was not tested but should work. Linux and Mac OSX were tested.
run these commands with a shell opened in the
miosix/_tools/booltloaders/stm32/pc_loader/pc_loader
directory
mkdir build
cd build
cmake ..
make
cp pc_loader ..
Installation on microcontroller
-------------------------------
Use your preferred method of loading code to the STM32, such as
serial bootloader or JTAG. Do not use the ST USB bootloader since it
reserves some space in the FLASH for the ST USB bootloader itself.
This Miosix bootloader is not PIC (position independent code) so loading
it at another address will fail.
Loading code using the bootloader in external RAM
-------------------------------------------------
1) Make sure Miosix is configured to run from the STM32'e external RAM:
in miosix/config/Makefile.inc options:
OPT_BOARD := stm32f103ze_stm3210e-eval
LINKER_SCRIPT := $(LINKER_SCRIPT_PATH)stm32_512k+64k_all_in_xram.ld
XRAM := -D__ENABLE_XRAM -D__CODE_IN_XRAM
should be uncommented (no # at the start of the line)
2) Build Miosix as usual with
make
3) Connect the USART1 of the STM32 board with a serial cable to the PC
the expected device name for the serial port is /dev/ttyUSB0,
if not modify the line
PROGRAM_CMDLINE := miosix/_tools/bootloaders/pc_loader/pc_loader \
/dev/ttyUSB0 main.bin
in miosix/config/Makefile.inc
4) then do a
make program
The bootloader should send data to the board, and run the binary.
Debugging code with Openocd in external RAM
-------------------------------------------
The bootloader should be loaded to the STM32's FLASH memeory to forward
interrupts @ 0x6800000, or Miosix will fail at the first interrupt.
Then run openocd in a shell:
sudo openocd -f miosix/arch/cortexM3_stm32f1/stm32f103ze_stm3210e-eval/stm32f10x_eval.cfg
and in another shell type:
arm-eabi-gdb main.elf
target remote :3333
monitor soft_reset_halt
load
c
After typing c miosix will start running. You can set breakpoints with
"break" and see variables with "print". For a more in-depth tutorial see
a gdb guide.
Running code without bootloader, from internal FLASH
----------------------------------------------------
This is essential for release builds, and for other STM32 based boards that
lack external RAM. By running the code from FLASH it will run at full
processor speed (~10 times faster than from internal RAM) and code will
not be erased by powercycling.
To do so configure Miosix's linker script for internal FLASH:
In miosix/config/Makefile.inc
select:
OPT_BOARD := stm32f103ze_stm3210e-eval
LINKER_SCRIPT := $(LINKER_SCRIPT_PATH)stm32_512k+64k_rom.ld
and comment out these two lines:
# XRAM := -D__ENABLE_XRAM
# XRAM := -D__ENABLE_XRAM -D__CODE_IN_XRAM
Then use your preferred method of loading code to the STM32, such as
serial bootloader or JTAG. Do not use the ST USB bootloader since it
reserves some space in the FLASH for the ST USB bootloader itself.
This Miosix kernel is not PIC (position independent code) so loading
it at another address will fail.