cancel
Showing results for 
Search instead for 
Did you mean: 

Self programming STM32

DiBosco
Senior II
Posted on December 09, 2010 at 02:55

Self programming STM32

15 REPLIES 15
DiBosco
Senior II
Posted on May 17, 2011 at 14:17

Thanks, Andrew. I assume you're talking about the interrupt vector table? I don't think I'll need any interrupts at all.

What I'm still not clear on is that with the AVR if the fuse is set, you always go to the bootloader section first which then sends you to ''normal'' code space if the external stimulus is there. Am I right in thinking it's the BOOT0 line which sends you to this bootloader space? If not, you jump to the standard program? Is there something to setup to tell which addresses to go to depending on the state of the BOOT0 line?
Posted on May 17, 2011 at 14:17

''I assume you're talking about the interrupt vector table?''

 

 

I'm talking about The Vector Table: there is only one table for all vectors - including the start vector, the interrupt vectors, exception vectors, etc...

''Am I right in thinking it's the BOOT0 line which sends you to this bootloader''

The BOOT pin can send you to ST's internal bootloader in ROM; otherwise, the start vector is fetched from the 1st entry in the vector table.

When you write your own custom bootloader - as we're discussing here, and as illustrated in AN2557 - that has to be the destination of the start vector.

 

As far as the CPU is concerned, your custom bootloader is just a ''standard'' application.

Posted on May 17, 2011 at 14:17

''There is an application note describing this''

 

It is the AN2557 mentioned above!
mrost9
Associate II
Posted on May 17, 2011 at 14:17

Like Neil just said, your boot loader is just a standard appplication.

The binaries created contain the vector table, there's no need to care for anything.

If compiled for flash, these vector tables are aligned to the flash start address.

You can use any size of bootloader you want, just make sure your ''real'' application starts anywhere on a flash sector boundary.

When you offset your application, to e.g. 0x08008000 (that's what I did, my bootloader got quite big ;-)), you will have to do multiple things:

- correct the vector table addresses

- jump from bootloader-application to ''real'' application

- tell the processor to use the new vector table.

There is an application note describing this, but I can't find it.

1) vector table offset:

I changed my linker script to use the new base address.

It depends on your toolchain how you do that, as I'm using Winarm, I had to align

stm32_flash.ld, to align the line

  FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 256K

to

  FLASH (rx) : ORIGIN = 0x8008000, LENGTH = 224K

2) jump to application code:

You bootloader needs to call the application. This is simple:

    { /* Jump to user application */

        JumpAddress = *(vu32*) (ApplicationAddress + 4);

        Jump_To_Application = (pFunction) JumpAddress;

        /* Initialize user application's Stack Pointer */

        Jump_To_Application();

    }

So, your setting a function's address to the address of your application +4 (the first 32bit-value is the stack pointer, followed by the reset vector), and call that function.

3) align for the new vector table:

    NVIC_SetVectorTable(NVIC_VectTab_FLASH, FIRMWAREBASEADDRESS);

That's all that is needed to jump from one application to another one.

You can do whatever you want to the flash sectors that are not used by the currently running code, e.g. erase and reprogram the bootloader from your application and vice versa.

mrost9
Associate II
Posted on May 17, 2011 at 14:17

Whoops. I searched for that, but on a quick glance AN2557 seemed to me like an example for another update tool. But you're right, and the example code to AN2557 should explain everything to do (as it contains the code above).

The example is a bit complex due to the interaction and stuff, but with the above pointers it should be easier to find the important parts.

glory_man
Associate II
Posted on December 30, 2011 at 08:13

I have bootloader - which programming application via CAN.

Application starts successfully from main function (after reset or power-on). But when I try to start application after flash programming from CAN-interrupt handler - application doesn't started.

How can I start application from interrupt handler?