EmbDev.net

Forum: ARM programming with GCC/GNU tools a few questions on flash programming


Author: Roman Mashak (romez777)
Posted on:

Rate this post
0 useful
not useful
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.

Author: Roman Mashak (romez777)
Posted on:

Rate this post
0 useful
not useful
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.

Author: Jim Kaz (ancaritha)
Posted on:

Rate this post
0 useful
not useful
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 :)

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.