a few questions on flash programming

OP #1173881
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.
OP #1173882
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.
#1173883
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

A question of your own? This thread is over 18 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.