I am needing an assembly bootloaders for these two chips. I can write my own but if it has already been done that would be greatly appreciated. I have seen some mention in the "Files" section but I can not locate that either. Thank you, AllanO
Try this link:
Then click on application notes at the left. There are several downloader app notes there, and some of them have software archives.
---Tom
Thanks I will try them.
Allan
INCLUDE 'mc9s12xdp512.inc'.....FCLKDIVVal: equ 19 ; value for the FCLKDIV register. (4MHz oscillator)..... ldab #FCLKDIVVal ; value for the Flash clock divider register. stab FCLKDIV.....ProgFBlock: ldab DataBytes,pcr ; get the block size. lsrb ; divide the byte count by 2 since we program a word at a time. pshb ; allocate the local (NumWords,sp). ldx PPAGEWAddr,pcr ; get the PPAGE window Flash address. leay SRecData,pcr ; point to the received S-Record data.ProgLoop: ldd 2,y+ ; get a word from the buffer. std 2,x+ ; latch the address & data into the Flash program/erase buffers. ldab #PROG ; get the program command. stab FCMD ; write it to the command register. ldab #mFSTAT_CBEIF ; start the command by writing a 1 to CBEIF. stab FSTAT nop nop nop nop ldab FSTAT ; check to see if there was a problem executing the command. bitb #mFSTAT_PVIOL+mFSTAT_ACCERR ; if either the PVIOL or ACCERR bit is set, bne Return ; return. brclr FSTAT,#mFSTAT_CBEIF,* ; wait here till the command buffer is empty. dec NumWords,sp ; any more words to program— bne ProgLoop ; yes. continue until done. brclr FSTAT,#mFSTAT_CCIF,* ; no. wait until all commands complete.; ldab DataBytes,pcr ; get the block size. lsrb ; divide the byte count by 2 since we verify a word at a time. stab NumWords,sp ldx PPAGEWAddr,pcr ; get the PPAGE window Flash address. leay SRecData,pcr ; point to the received S-Record data.VerfLoop: ldd 2,y+ ; get a word from the buffer. cpd 2,x+ ; same as the word in Flash– bne Return ; no. return w/ an error (!= condition). dec NumWords,sp ; yes. done comparing all words˜ bne VerfLoop ; no. compare some more.;Return: pulb ; deallocate the local. rts ; return.
Thanks Imajeff, but I have checked the erratas, and my chipset (0L15Y) does not include anything about programming Flash.
Here is the disassembled listing of the (not working version of the) program loop (almost identical to the AN2153). I did read somewhere on the forum a note about a delay before the CBEIF-bit is cleared, so I did put in the NOPs, but they did not help.
a00FAFA E6FA 02D7 ProgFBlock: ldab DataBytes,pcra00FAFE 54 lsrba00FAFF 37 pshba00FB00 EEFA 02D2 ldx PPAGEWAddr,pcra00FB04 19FA 02D3 leay SRecData,pcra00FB08 EC71 ProgLoop: ldd 2,y+a00FB0A 6C31 std 2,x+a00FB0C C620 ldab #PROGa00FB0E 7B01 06 stab FCMDa00FB11 C680 ldab #mFSTAT_CBEIFa00FB13 7B01 05 stab FSTATa00FB16 A7 nopa00FB17 A7 nopa00FB18 A7 nopa00FB19 A7 nopa00FB1A F601 05 ldab FSTATa00FB1D C530 bitb #mFSTAT_PVIOL+mFSTAT_ACCERRa00FB1F 2627 bne Returna00FB21 1F01 0580 brclr FSTAT,#mFSTAT_CBEIF,* 00FB25 FB a00FB26 6380 dec NumWords,spa00FB28 26DE bne ProgLoopa00FB2A 1F01 0540 brclr FSTAT,#mFSTAT_CCIF,* 00FB2E FB ;a00FB2F E6FA 02A2 ldab DataBytes,pcra00FB33 54 lsrba00FB34 6B80 stab NumWords,spa00FB36 EEFA 029C ldx PPAGEWAddr,pcra00FB3A 19FA 029D leay SRecData,pcra00FB3E EC71 VerfLoop: ldd 2,y+a00FB40 AC31 cpd 2,x+a00FB42 2604 bne Returna00FB44 6380 dec NumWords,spa00FB46 26F6 bne VerfLoop ;a00FB48 33 Return: pulba00FB49 3D rts
When I change the program so that the loop checks the CCIF-bit instead of the CBEIF, it works fine, but as this it leaves every second or every third word unprogrammed.
Note! The program is moved to RAM before executing, so the addresses in the listing will acutally be above 2000 instead of F800.
This is not so critical anymore, because I have a working version, but it would be interesting to know why the CBEIF-approach doesn't work.
I got it working myself by changing the prog_loop to directly check the CCIF-bit instead of the CBEIF-bit:
Code:
bitb #mFSTAT_PVIOL+mFSTAT_ACCERR ; if either the PVIOL or ACCERR bit is set, bne Return ; return. brclr FSTAT,#mFSTAT_CCIF,* ; wait here until all commands complete. dec NumWords,sp ; any more words to program— bne ProgLoop ; yes. continue until done.; ldab DataBytes,pcr ; get the block size.
Can somebody explain why the code checking the CBEIF-bit did not work, but this does?
Message Edited by imajeff on 05-16-200608:24 AM
Hey Sten,
I used AN 2720 to program and erase flash. It has a few functions in it that let you initialize the flash module, program a flash word, and erase a flash sector (including the function that copies the flash code that needs to run out of RAM). You'll need to make some changes though, because of the way the S12X handles global address aceess (theres a thread I started about this earlier that explains the difference). Once you get those function working, writing an application that reads an S-Record file through SCI is pretty straight forward.
I hope that helps...
- Michael
(Alban linked AppNote)
Message Edited by Alban on 04-26-2006 11:40 AM
Message Edited by Alban on 04-26-2006 11:41 AM