Skip to main content
Visitor II
January 16, 2020
Solved

How do I modify an stm32f439vitx system workbench stm32 project for use with a bootloader.

  • January 16, 2020
  • 2 replies
  • 3922 views

I have an existing stm32f439vitx custom board project which works fine when flashed at address 0x08000000 which I now need to make runnable from an existing bootloader expecting the program to have been flashed at address 0x8008000.

Is it enough to change the linker script ROM origin and length?

    This topic has been closed for replies.
    Best answer by berendi

    Try with this in the linker file

    /* Sections */
    SECTIONS
    {
     /* The startup code into ROM memory */
     .isr_vector :
     {
     . = ALIGN(4);
     KEEP(*(.isr_vector)) /* Startup code */
     . = 0x200; /* apparently this should be relative to the section start */
     KEEP(*(.mystartup)) /* The reset handler code where the bootloader is expecting it */
     . = ALIGN(4);
     } >ROM
     /* The program code and other data into ROM memory */
     .text :
     {
     . = ALIGN(4);
     *(.text) /* .text sections (code) */
     *(.text*) /* .text* sections (code) */

    2 replies

    Visitor II
    January 16, 2020

    Find the line (usually in system_stm32f4xx.c) where SCB->VTOR is assigned to, and change it to the new base address. If the bootloader has left any interrupts enabled, disable them before changing SCB->VTOR.

    The bootloader and the application must agree on the state of all peripherals.

    DCarr.1Author
    Visitor II
    January 16, 2020

    Brilliant!

    I shall give that a try, thanks.

    DCarr.1Author
    Visitor II
    January 21, 2020

    So I gave it a try and it didn't work, no doubt due to a failure on my part.

    I've traced through the bootloader source and - after tinkering with various peripherals for its own purposes - it executes this function :

    void JumpToApp(void)
    {
     DisableInterrupts();
     NVIC_VTOR = 0x8000;
     asm {
     MOVW R0, #65532
     MOVT R0, #8192
     MOV SP, R0
     
     MOVW R0, #0x8201
     MOVT R0, #0
     BLX R0
     }
    }/* end JumpToApp() */

    Which means basically nothing to me :(

    The application binary file itself is copied to flash starting at address 0x08008000 although it's not completely impossible that some checksums and so on have been inserted at the start of the file before the start of the linker.

    Visitor II
    January 21, 2020

    This inline assember block assumes that the stack pointer should be set to 0x2000FFFC, meaning the static data segment is either much smaller than 64K, or it begins at the 64K mark (0x20001000). Moreover, it assumes that the reset handler function is at 0x08008200.

    This bootloader is for a specific system with an unusual memory layout. Are you sure that it's for the STM32F4 series?

    A generic bootloader should rather load the stack pointer and the reset address from the vector table, at 0x08008000 and 0x08008004 in your case.

    What kind of compiler is it? The syntax looks like Keil, but does Keil work with system workbench?

    DCarr.1Author
    Visitor II
    January 21, 2020

    The bootloader is for a custom board, but I'm as sure as I can be that it's a standard stm32f439vitx without anything really special going on in terms of memory or anything else; the programs I build in system workbench for stm32f439vitx work fine when I flash them directly using an ST-link at a base address of 0x08000000

    The bootloader and legacy app which I'm replacing are built in the "mikroelectronica" environment: I'm using system work bench for the replacement app and would have a hard time justifying a new bootloader.

    Do you think there could be a fundamental incompatibility here?