Flash Programming Examples

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Flash Programming Examples

9,081 Views
mjcoury
Contributor I
Are there any GOOD examples of programming flash. I have found the document in the GT60UG that has an example but its pretty confusing and not much help.


Thanks
Labels (1)
0 Kudos
10 Replies

820 Views
Technoman64
Contributor III
0 Kudos

820 Views
Andik
Contributor I
I made mistake

STA FCDIV ;flash clk freq divider setup ((fosc)/200000)-1

should be

STA FCDIV ;flash clk freq divider setup ((fbus)/200000)-1

and the FCDIV should be recalculated.

Ah, those clocks...

Message Edited by Andik on 2006-07-19 04:00 AM

0 Kudos

820 Views
mjcoury
Contributor I
Is it reccomended to do all of this in ASM verses C?
0 Kudos

820 Views
irob
Contributor V
With all the fine examples here on the boards, I did mine in C.
0 Kudos

820 Views
mjcoury
Contributor I
These posts are great help all.... last question for the moment.... if this is written in C how exactly to load the registers and push data onto the stack in C code? or is that no possible?



Thanks


MC
0 Kudos

820 Views
irob
Contributor V
I'm just running my flash writing code from RAM instead of the stack. Seems to work well enough for my needs.
Have you seen this post? It's a great tech note with sample code on copying a function from flash to RAM and then running the function from RAM.
0 Kudos

820 Views
mjcoury
Contributor I
Ahh glorious - i will check this out post haste...
0 Kudos

820 Views
Andik
Contributor I
Hope, the FCLKDIV is right...

;initialisation for RG60 @ 8MHz
LDA #19
STA FCDIV ;flash clk freq divider setup ((fosc)/200000)-1
LDA #$30
STA FSTAT ;clear errors
LDA #$F8
STA FPROT ;unprotect

;subroutine for program HCS08 byte,
;input data and address on stack

PROG:
PSHA ;save data
PSHX ;save Lo(addr)
PSHH ;save Hi(addr)
LDHX #FSTAT
FCBEF:
LDA ,X
AND #$80 ;FCBEF bit
BEQ FCBEF ;wait until command buffer empty
PULH
PULX
PULA
STA ,X ;write desired data to desired address
AIX #1

PSHX
PSHH
LDHX #FCMD
LDA #$25 ;BURST_PGM command code
STA ,X ;write PGM command
LDHX #FSTAT
LDA #$80 ;FCBEF bit
STA ,X ;start command execution
PULH
PULX

RTS


Andik
0 Kudos

820 Views
mjcoury
Contributor I
Thanks for the example!


Now how do you reserve memory in codewarrior on the MCU so that you don't overwrite the program?? I want to reserve the ~60K space from $182C - $FFBD? for fonts and other bitmaps... I am not running PE as this is the evolution of a example program from freescale.


Thanks


Mike
0 Kudos

820 Views
irob
Contributor V

mjcoury wrote:
how do you reserve memory in codewarrior on the MCU so that you don't overwrite the program?? I want to reserve the ~60K space from $182C - $FFBD?



Mike, put this in your .prm file which is in Project Settings \ Linker CW folder. Place it inside the SEGMENTS section:

YOUR_MEMORY = READ_ONLY 0x182C TO 0xFFBD

Then place this inside the PLACEMENT section:

YOUR_MEMORY_SPACE INTO YOUR_MEMORY;

Then in your .c file, put this in front of the routines that are to be located there:

#pragma CODE_SEG YOUR_MEMORY_SPACE

Hope that helps.
0 Kudos