2017-10-19 01:46 AM
I am working on the project with STM32F030R8T6. So far I have bootloader and main application with memory space allocated. My problem is that currently I am jumping between main and bootleader using address of reset handler and I need to somehow let BL know if it is startup or jump from main. I have been trying to allocate 4 bytes to store this information in memory and access using the address, but it seems that value at the address get reset after jump. My question is — what would be the best approach to have some flag between BL and Main application ?
Note: this post was migrated and contained many threaded conversations, some content may be missing.2017-10-19 03:08 AM
I have been trying to allocate 4 bytes to store this information in memory and access using the address, but it seems that value at the address get reset after jump.
Most probably in the startup code, that runs from reset vector to main.
You can modify the startup (assembler code) or the linker map t not initialize certain areas, but that depends on the toolchain.
I guess you speak about a custom BL, not the system BL in ROM.
2017-10-19 03:25 AM
Shrink the RAM size slightly in the linker script or scatter file so you can use the last 4 or 16 bytes, or whatever you need to pass state information between the two.
2017-10-25 02:34 AM
Ok, I have left last 4 bytes of RAM out of both linker scripts, but it seems that this value still get reset when jumping. There is no power cycle reset, so I am not sure why this behavior exists.
In linker script I just do
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 8K - 4
And then I use address
0x20000000 + 8K - 4 to store 32 bit int, it seems I am successful but after the jump it gets reset even if this 4 byte area is not allocated in any linker script and should not be touched by reset handlers.
2017-10-25 02:42 AM
Debugging ?
I would set a data breakpoint at your reserved location.
Depending on your IDE, single-step might only be possible in instruction/assembler mode, since the application is started the BL.
2017-10-25 02:55 AM
Look at the startup code you are using, from where does it acquire the constants used for the clear loop.
JW
2017-10-25 07:31 AM
Don't know how you access, but the Linker and startup code shouldn't mess with things. Check where GNU is placing the stack. If 0x20002000 then move to 0x20001FFC, it will then predecrement that before use.
Then
uint32_t *myvar = (uint32_t *)0x20001FFC;
printf('%08X\n', *myvar);
2017-10-26 06:54 AM
Ok, here is my linker scripts..
BL:
{FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 20K /* 64K total, 20k boot, 44k main program */RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 8K - 4 }Main application:
{
FLASH (rx) : ORIGIN = (0x08000000+20K), LENGTH = (64K-20K-4)VTRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0xc0 /* First part of RAM is reserved to the vector table */RAM (xrw) : ORIGIN = 0x200000C0, LENGTH = 8K - 0xc0 - 4}Also, in mu linker scripts I have values set:
__flags = 0x20000000 + 8K - 4;
From source code:
&sharpdefine
FLAGS
((
uint32_t
)
&
__flags)
extern
uint32_t
__flags;
dbg_printf
(
'Flag addr: %x
\n
'
, FLAGS);
volatile
int32_t
*
ptr
=
(
int32_t
*
) FLAGS;
dbg_printf
(
'flags: %d
\n
'
,
*
ptr);
*
ptr
=
1
;
volatile
int32_t
*
ptr2
=
(
int32_t
*
) FLAGS;
dbg_printf
(
'flags2: %d
\n
'
,
*
ptr2);
Flag addr prints the address you said:
0x20001FFC
flags print some random value whitch is alwasy the same on startup.
flags2 print 1
Now when I jump, I read from very same address and it is again some random value which is very similar to random value from before but different.
2017-10-26 07:08 AM
I repeat,
Look at the startup code
As Clive said, that includes stack definition.
JW
2017-10-26 07:20 AM
Isn't stack defined at the compile time ?