cancel
Showing results for 
Search instead for 
Did you mean: 

In App programing for STM32L476 Remaping Vector table

bm23
Associate II
Posted on October 31, 2016 at 16:46

Hi,

I want STM32L476 to jump to User program located at 0x80004000 if button is not pressed. Please check the flow chart as below; 

1. I would like to know how can I remap the Vector table to RAM?

2. What RAM address to use for Remaping Vector table and why?

3. User program which will be stored at 0x8004000; need to have any specific build process to generate .hex/.bin files? i.e. is ther any configuration of Start address or initial clock to define before copile and build?

Thanks

regards 

#vector-table #in-app-programming
11 REPLIES 11
Posted on October 31, 2016 at 17:00

The address for the APP image and vector table would be 0x08004000. This is frequently set up in SystemInit()

SCB->VTOR = 0x08004000;

This is a topic area that's been covered here many times, review perhaps older posts, and the IAP examples furnished by ST.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
bm23
Associate II
Posted on October 31, 2016 at 17:10

Hi Clive,

Thank you for the responce;

I have read several post including yours ( about M0 does not have this VTOR register etc..) however,

it is not clear that in which app (boot load or user app) I need to do the remapping?

For Coretx M3/M4 processor there is no need to use RAM for Remaping vector table?

The flash can be used directly for remaping vector table?

the user app image(.hex/.bin) which will be flashed by IAP needs to be compile for 0x8004000 address or for 0x8000000 ?

Please share some knowledge...

Thanks

Posted on October 31, 2016 at 17:29

On an M0 you'd need to use the base of RAM (0x20000000) cause that's the only thing other than 0x08000000 that is mappable at zero.

The M3/M4 need a suitably aligned memory, depending of the vector table size, that can be programmed into SCB->VTOR. On the F4, and likely the L4, this would need to be a 512-byte boundary. 0x08004000 fits this. You can set the address at a suitable time, most effectively BEFORE you generate interrupts or faults that would need the table to be in the correct spot. ie don't leave random crap running as you hand control from loader to application.

You'd need to link the code for operation at the 0x08004000 base address, the addresses IN the vector table are ABSOLUTE so you can't have them point to some other random base addresses, it would need to match the addresses you've fixated in the image.

Review M3/M4 Technical Reference Manuals, or Joesph Yiu treatment of such.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
bm23
Associate II
Posted on October 31, 2016 at 17:49

Hi clive,

thanks

I've noticed the code check for value of :20008000 in Application start address(i.e. 0x8004000).

Why is this value required? 

The image being comipled does not have 20008000 instead 20000740 or other value.

What is significance of 20008000 value?

/* Test if user code is programmed starting from address ''APPLICATION_ADDRESS'' */

if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000)

Posted on October 31, 2016 at 19:23

It is not checking that it is 0x20008000, it is looking at the Initial Stack Pointer (SP) Entry in the Vector Table, and confirming it points to RAM. It is a crude test, one could write a better version.

If it were 0xFFFFFFFF for example, it would be invalid, and suggest it is an erased flash memory

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
bm23
Associate II
Posted on November 01, 2016 at 12:41

Hi,

I have attached all my codes; please review.

Two programs Program A and B;

Prog A is the Application Image

Prog B suppost be bootload program

Prog A has Memory address assigned to

0x08004000 in

system_stm32l4xx.c file, However

not sure if it assigned

correctly!

After

reset, when Button is

Pressed MCU goes in

Prog B (at 0x08000 000)and toggles LED at

1s

However when button is

not pressed, MCU doesn't seems to be running program from 0x0800400

SP shows 0x200000410

PC shows 0x0800049C (shouldn't it be 0x08004000 ?)

Please check the

debug log in attachments.

Anything I'm missing here?

________________

Attachments :

Debug_of_PB_to_PA.PNG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0nG&d=%2Fa%2F0X0000000bil%2FZ.I46FFt.UBJjl1rWi_3Ro9V0c53imRNkkpGykrNSGI&asPdf=false

Flow.PNG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I17o&d=%2Fa%2F0X0000000bim%2FghNX8TealJdgkna.WFiQkqsWMhKvRnSu38vCY1ni2zk&asPdf=false

PA_at_08004000.PNG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0tP&d=%2Fa%2F0X0000000bik%2FOJ8AbQaXDTtmVWZ0KXzllOdQImAAi7yZmAlpzAl9.TI&asPdf=false

PB_at_08000000.PNG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I16c&d=%2Fa%2F0X0000000bij%2FzKhDm3bDGFjuVhygD15N8TXtgeRKj3kkaDEaUvbfrF4&asPdf=false

Program_A.txt : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I17j&d=%2Fa%2F0X0000000bih%2FQd_dofcvOyH9qW_5oN.g8BGnNAArmg6YSYecS8.wXec&asPdf=false

Program_A_system_stm32l4xx.txt : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I17L&d=%2Fa%2F0X0000000bif%2FIrAtfHBVYNouYNYMHxXkamQUY9yTpszFjaEqDvplmII&asPdf=false

Program_B.txt : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I17e&d=%2Fa%2F0X0000000big%2FlunrsCvjGjzQVk2mreu4VF8hdw5.6wtthdt_fL.aYtE&asPdf=false
Posted on November 01, 2016 at 13:50

It would seem apparent that you are not building/linking the code for 0x08004000, you would need to address that in the Target pane, or the scatter file the linker is using.

The address of the PC will not be 0x08004000, but an address above that. The vector table is not executable code.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
bm23
Associate II
Posted on November 02, 2016 at 10:14

Hi Clive,

Could you please explain in-app-process in steps?

I'm assuming that;

Prog B (bootloader) starts at 0x0800 0000 does HAL_init and Clock configuration

then runs some user code(check for button press and then blinking LED at 1 sec in my case)

if button not pressed it will Jump the application to

0x0800 4000

now here is the catch;

When it says Jump to0x0800 4000..what happens actually?

PC will have value0x0800 4000 ? or it will just remap0x0800 4000 to 0x0800 0000?

and what about SP ?

How can i

Debugto see if it is actually Jumping to 0x0800 4000 successfully or not?

I'm using

Keiland ST

CubeMxwith

HALlibraries.

How can I figure out if the problem is with

.Bin Image of the prog Aor with the code of

Prog B?

I'm attaching .Bin of Prog A for reference.

Is it possible for you to check if it is copied properly to run from address 0x0800 4000?

Thanks

________________

Attachments :

PA.bin : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I163&d=%2Fa%2F0X0000000bii%2F7s5ssgQIP0bM7ydotcorCYj10hyVIkcMQYf2tDCGFZ0&asPdf=false
bm23
Associate II
Posted on November 02, 2016 at 10:37

FYI,

Prog A

 has Memory address assigned to 

0x08004000

 in 

system_stm32l4xx.c 

file using 

#define VECT_TAB_OFFSET  0x4000

SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET;

If you see the

http://i63.tinypic.com/s3giaa.png

;

http://i63.tinypic.com/s3giaa.png

After the line:

__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);

the Value of SP changes from 0x2000 0410 to 0x2000 0408

 

0x2000 0408 is the value of mem address 

0x08004000

 

and the of Prog A while 0x2000 0410 is value of mem address 0x0800 0000 i.e. Prog B.

Does that mean the Program jups to  0x0800 4000 but is not running the code properly?

Please shed some light....