cancel
Showing results for 
Search instead for 
Did you mean: 

writing your own in application programming

matthiasjunge9
Associate II
Posted on July 28, 2008 at 08:12

writing your own in application programming

3 REPLIES 3
matthiasjunge9
Associate II
Posted on May 17, 2011 at 12:40

Hi,

I have the STM32F103 with 128 KByte flash. I have downloaded a new firmware binary data at flash address 0x8010000, while my program is still running at 0x8000000. Now I want to copy the program from 0x8010000 to 0x8000000. Do do this I have to have a copyfunction running in RAM. In my program this function is defined: void bootcode(void) {...}. I want to copy this code into a RAM array unsigned char bootram[0x400] and execute the code there. As I understand the ROM can only be read out 32 bit wise and I do get a Hard Fault if the function adress of bootcode is not a multiple of 4 byte. Is this correct? The _align macro only works on variables so how to force the Keil compiler to align the function to a 32 bit even address. For example according to the map file the function bootcode lies at adress 0x080014df. Now if I copy the data from the last lower matching adress 0x080014dc then all the codebytes from bootcode are in bootram, how can this be??? Also if I jump to the adress of bootram via function pointer I get a hard fault:

bootAppFuncAddr = (bootAppFunc) (bootram);

bootAppFuncAddr();

According to an early thread I should jump to the next address bootram+1 but again I get a hard fault. Is is debugger related or something else?

matt

[ This message was edited by: matthias.junge on 25-07-2008 12:10 ]

ivanov-i
Associate II
Posted on May 17, 2011 at 12:40

Hi Matt,

You can not do it in the way you described at least because the bootcode() function is compiled and linkend in the Flash address space. Normaly, besides the function code there are also constants, which are accessed by a relative addressing from the program counter and if you just copy the code to RAM this addressing will fail.

There are compiler extensions, which you can use to inform the linker to put the function in the RAM. For IAR it is __ramfunc, for example:

__ramfunc void bootcode (void)

The code for the bootcode() function is filled up automaticaly in the RAM during the initialization of the static variables at the startup. Then you can call bootcode() as any other function.

However, be carefull - don't exit the function by a normal return. If you replace the code in the Flash then the return address could point to an uncorrect place. The best case is to perform a software reset of the chip at exit.

Regards,

Ivan

matthiasjunge9
Associate II
Posted on May 17, 2011 at 12:40

I finally got it to work, it is quite tricky because of the 32-bit offsets but you can make your own reprogramming that way!

matt