www.mikrocontroller.net

Mikrocontroller.net Forum WinARM / Yagarto / ARM-GCC > a few questions on flash programming

Posted by Roman Mashak (romez777)
on 31.05.2008 15:46
Hello,

MCU: at91sam7s64
toolchain: Yagarto(gcc 4.2.2)

1) I'm studying the flash handling reference source code by Atmel and
found
that in most functions doing flash operations (erase, write, lock) this
code snippet exists:

//* set the Flash controller base address
AT91PS_MC ptMC = AT91C_BASE_MC;
...
//* Write the Set Lock Bit command
ptMC->MC_FCR = AT91C_MC_CORRECT_KEY | AT91C_MC_FCMD_LOCK |
(AT91C_MC_PAGEN & (Flash_Lock_Page << 8) ) ;

Why can't we simply do:
AT91C_BASE_MC->MC_FCR = AT91C_MC_CORRECT_KEY | AT91C_MC_FCMD_LOCK |
(AT91C_MC_PAGEN & (Flash_Lock_Page << 8) ) ;

Is there any special point in declaring that extra pointer and address
to the fields of structure in such a way, or it's simply a coding style?

2) am I right that read access to the flash is permitted when
Lock/Unlock
command is performed? So __ramfunc function attribute is not needed in
this case?

3) I don't quite understand how FMCN field of MC_FMR register is
calculated.
In Atmel examples:

AT91C_BASE_MC->MC_FMR = ((AT91C_MC_FMCN) & (72 << 16)) |
AT91C_MC_FWS_1FWS;

Well, I understand how they choose wait state, but what does 72 mean,
provided
that master clock is 47923200 Hz?

Moreover, for lock bits handling they program this field in another way:

AT91C_BASE_MC->MC_FMR = ((AT91C_MC_FMCN) & (48 << 16)) |
AT91C_MC_FWS_1FWS

Why is it so? Why can't we use the same amoount of cycles for both
operations?

Thanks.
Posted by Roman Mashak (romez777)
on 02.06.2008 15:05
Roman Mashak wrote:
> 2) am I right that read access to the flash is permitted when
> Lock/Unlock
> command is performed? So __ramfunc function attribute is not needed in
> this case?

I figured out with this point, but others are still unclear. especially 
with FMCN calculations. Datasheet is not very eloquent about it. I hope 
somebody can shed some light on it.
Posted by Jim Kaz (ancaritha)
on 02.06.2008 16:40
Roman Mashak wrote:
> Roman Mashak wrote:
>> 2) am I right that read access to the flash is permitted when
>> Lock/Unlock
>> command is performed? So __ramfunc function attribute is not needed in
>> this case?
> 
> I figured out with this point, but others are still unclear. especially 
> with FMCN calculations. Datasheet is not very eloquent about it. I hope 
> somebody can shed some light on it.

I honestly don't remember what all the other things you said actually 
mean/if they are required, but I know for our project we just left them 
the same and everything worked out fine :)

And yea, that ramfunc is definitely needed :)