Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: FLASHD_SetGPNVM(2) and NVIC_SystemReset()
PostPosted: Sat Jul 02, 2011 12:16 pm 
Offline

Joined: Sat Jul 02, 2011 11:42 am
Posts: 4
Dear All,

I'm new in the Forum and I'm working on a SAM3U4E micro controller.

In my architecture I need to set Flash0 or Flash1 and (soft) restart the micro controller at run time.

When the code is executed in Flash 1 I can easily switch to Flash 0 and (soft) restart the micro controller using the following commands:

FLASHD_ClearGPNVM(2);
NVIC_SystemReset();

But when the code is executed in Flash 0 and I want to switch to Flash 1 and (soft) restart the micro through the sequence

FLASHD_SetGPNVM(2);
NVIC_SystemReset();

the micro get stuck in the FLASHD_SetGPNVM function and does not restart.

At this point, if I power the micro off and on, it restart from Flash 1. So the SetGPNVM has worked but the micro got stuck in the FLASHD_ClearGPNVM function.

The big surprise is that when I use the JTAG to debug the code, everything is working fine.

Do you have any suggestion to debug/solve this problem?

Thank you since now for your support.

KR,

Antonio


Top
 Profile  
 
 Post subject: Re: FLASHD_SetGPNVM(2) and NVIC_SystemReset()
PostPosted: Sun Jul 03, 2011 11:20 am 
Offline

Joined: Thu Dec 02, 2004 2:28 pm
Posts: 454
hello,
make sure that the fuinction FLASHD_SetGPNVM() is running out of sram.

regards
gerhard


Top
 Profile  
 
 Post subject: Re: FLASHD_SetGPNVM(2) and NVIC_SystemReset()
PostPosted: Sun Jul 03, 2011 12:13 pm 
Offline

Joined: Sat Jul 02, 2011 11:42 am
Posts: 4
[quote="gerhardf"]hello,
make sure that the fuinction FLASHD_SetGPNVM() is running out of sram.

regards
gerhard[/quote]

Dear Gerhard,

First of all thank you for your answer.

I do not have external SRAM and all the code should be running in the flash (see the scatter file below).

I also noted that I cannot write in the same FLASH region where the code is running. I'm not sure if the problem is connected.


Load_region 0x80000 0x20000
{
; Flash 128K
Vector_region 0x80000
{
board_cstartup_keil.o (vectors, +FIRST)
.ANY (+RO)
}
Fixed_region +0
{

.ANY (+RO)
}
; SRAM0 52K
Relocate_region 0x20000100 (0xD000-0x100)
{
.ANY (+RW +ZI)
}

; ; Configure Stack and Heap
; ARM_LIB_HEAP 0x2000C000-0x800 EMPTY 0xF00
ARM_LIB_HEAP 0x20007000 EMPTY 0x5000
{
}

ARM_LIB_STACK 0x2000CFFC EMPTY -0x800
{
}
}


Top
 Profile  
 
 Post subject: Re: FLASHD_SetGPNVM(2) and NVIC_SystemReset()
PostPosted: Sun Jul 03, 2011 12:36 pm 
Offline

Joined: Sat Jul 02, 2011 11:42 am
Posts: 4
Dear Gherard,

Even if the scatter file was OK I've seen in the eefc.c source code this line:

__attribute__ ((section (".ramfunc")))

After commenting it, it seems to work fine!

Thank you again for your support.

KR,

Antonio


Top
 Profile  
 
 Post subject: Re: FLASHD_SetGPNVM(2) and NVIC_SystemReset()
PostPosted: Sun Jul 03, 2011 8:48 pm 
Offline

Joined: Thu Dec 02, 2004 2:28 pm
Posts: 454
hello antonio,
the line "__attribute__ ((section (".ramfunc")))" tells the linker and the startup-code to copy this function into internal sram.
regards
gerhard


Top
 Profile  
 
 Post subject: Re: FLASHD_SetGPNVM(2) and NVIC_SystemReset()
PostPosted: Sun Jul 03, 2011 9:43 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
>>I also noted that I cannot write in the same FLASH region where the code is running.

This is in fact very usual with the way flash memory planes are implemented. The writes/erases typically take micro or milli seconds to perform. In order for the processor to appear to keep running, you would need to stall the processor. The STM32 does this, but the resulting stall effectively breaks the ability to service peripherals in a timely manner. ie the serial port will have overruns and data loss.

The value read from flash during the write is typically a status, not the data you actually want, from the address your writing, or any other cells for that matter.

The trick is to place the code you want to run while the flash is writing in SRAM (internal, external, whatever). This would need to include interrupt code.


Top
 Profile  
 
 Post subject: Re: FLASHD_SetGPNVM(2) and NVIC_SystemReset()
PostPosted: Mon Jul 04, 2011 8:48 am 
Offline

Joined: Sat Jul 02, 2011 11:42 am
Posts: 4
Thank you everybody for your precious support!

Regards,

Anthony


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: