Cannot reboot after switching banks (SAM3SD8)

Discussion around product based on ARM Cortex M3 core.
This forum will be discontinued soon.

Moderators: nferre, ncollot

liorbaz
Posts: 3
Joined: Mon Jun 20, 2016 3:50 pm

Cannot reboot after switching banks (SAM3SD8)

Mon Jun 20, 2016 4:01 pm

Hello,

When I wish to upgrade a firmware image, I use bank switching, and then attempt to reboot.
I first write the new image to the new bank, and then set GPNVM 2 (At this point I see that memory and variables gets "crazy" using the debugger view - probably the effect of the memory remapping).

Now I am trying to reboot using:
AIRCR=(AIRCR&VECTKEY_MASK)|VECTKEY|SYSRESETREQ

Which translates to
(*(uint32_t*)0xe000ed0cUL)=((*(uint32_t*)0xe000ed0cUL)&0x05fa0000UL)|0x05fa0000UL|(1<<2))

And it doesn't reboot - only external reset helps.

Few pointers:
1. This reboot macro usually works perfectly, just not after the bank switching.
2. After external reset takes place, the new FW boots OK.
3. I am using SAM3SD8.

Help, please....:(

Thanks!
Lior.
tsvoipio
Posts: 54
Joined: Wed Aug 19, 2015 9:44 pm

Re: Cannot reboot after switching banks (SAM3SD8)

Tue Jun 21, 2016 2:54 pm

Your vector key mask is suspect. To pick the key field, you need 0xffff0000 and for dropping it , you need 0x0000ffff.
liorbaz
Posts: 3
Joined: Mon Jun 20, 2016 3:50 pm

Re: Cannot reboot after switching banks (SAM3SD8)

Wed Jun 22, 2016 3:57 pm

Hey tsvoipio, thanks for your reply!

However, can you please elaborate?
VECTKEY_MASK is defined as (0x0000ffffUL)

How would you use it to call a reset?

Also, I would like to emphasis again two more things:
1. This reboot macro usually works perfectly, just not after the bank switching.
2. Immediately after I set GPNVM 2 (for switching banks), I see the in debugger view that memory and variables, call stack etc., gets "crazy".
I suspect that once I switch banks, I can't continue to execute since the code flow is lost, thus I am not actually performing the reset macro...
tsvoipio
Posts: 54
Joined: Wed Aug 19, 2015 9:44 pm

Re: Cannot reboot after switching banks (SAM3SD8)

Wed Jun 22, 2016 7:00 pm

In your message the mask value was different - a misprint?

You may need to copy to RAM the code to set GPNVM and reset the processor. The code has to be linked to be runnable in RAM, so the bank switching does not interfere.

If you're using GCC, you can put the functions to a special memory section and tell the linker that the section belongs to initialized RAM (.data). The normal ARM call does not branch far enough, so you have to access the functions with indirect calls or declare them with longcall attribute. For details, see the GCC manual.
liorbaz
Posts: 3
Joined: Mon Jun 20, 2016 3:50 pm

Re: Cannot reboot after switching banks (SAM3SD8)

Thu Jun 23, 2016 3:55 pm

tsvoipio wrote:In your message the mask value was different - a misprint?
Yes, sorry. It's ((*(uint32_t*)0xe000ed0cUL)=((*(uint32_t*)0xe000ed0cUL)&(0x0000ffffUL))|(0x05fa0000UL)|(1<<2))
tsvoipio wrote:You may need to copy to RAM the code to set GPNVM and reset the processor. The code has to be linked to be runnable in RAM, so the bank switching does not interfere. If you're using GCC, you can put the functions to a special memory section and tell the linker that the section belongs to initialized RAM (.data). The normal ARM call does not branch far enough, so you have to access the functions with indirect calls or declare them with longcall attribute. For details, see the GCC manual.
I think I do that. Here is the function declaration (which I use for other flash commands as well):
/* invoke function in RAM */
void sam3s_flash_cmd_ramfunc(uint16_t arg, uint8_t cmd) __attribute__ ((section(".data")));
BTW - one of my team members reported that it sometimes works (inconsistently), however - only when the JTAG debugger is disconnected.

Any other ideas...?

Thanks!
Lior.

Return to “SAM3 Cortex-M3 MCU”

Who is online

Users browsing this forum: No registered users and 4 guests