Hi
Does someone have the code (prefer assembly code)
for flashing data to a byte or block of flash in a JM60 ?
I dont need anything fancy, just code that runs in RAM with interrupts disabled
(I have looked at the USB bootloader samples, but the flash code is hidden in a library...)
I am using this in a JM60 project, its an adaptation to the Mini-RAM routines posted in this forum.
const unsigned char ROM_PGM[7] = { 0xf7, // sta ,X FSTAT 0x44, // lsra - delay and convert to FCCF bit0xf5, // Bit X ,fstat0xf5, // Bit X ,fstat0x27,0xfd, // BEQ *-10x81 // RTS}; volatile unsigned char PGM[7] = { 0xf7, // sta ,X FSTAT 0x44, // lsra - delay and convert to FCCF bit0xf5, // Bit X ,fstat0xf5, // Bit X ,fstat0x27,0xfd, // BEQ *-10x81 // RTS}; void InitFlashRoutine(void) // match number of bytes above. { PGM[0] = ROM_PGM[0]; PGM[1] = ROM_PGM[1]; PGM[2] = ROM_PGM[2]; PGM[3] = ROM_PGM[3]; PGM[4] = ROM_PGM[4]; PGM[5] = ROM_PGM[5]; PGM[6] = ROM_PGM[6]; }byte FlashErasePage(word page) { asm { TPA ; Get status to A PSHA ; Save current status SEI ; Disable interrupts LDA #0x30 STA FSTAT ; Clear FACCERR & FPVIOL flags LDHX page STA ,X ; Save the data LDA #$40 ; Erase command STA FCMD LDA #FSTAT_FCBEF_MASK LDHX @FSTAT JSR PGM PULA ; Restore previous status TAP } return (FSTAT & 0x30); }byte FlashProgramByte(word address, byte data) { asm{ TPA PSHA ; Save current status SEI ; Disable interrupts LDA #0x30 STA FSTAT ; Clear FACCERR & FPVIOL flags LDHX address LDA data STA ,X ; Save the data LDA #$20 ; Burn command STA FCMD LDA #FSTAT_FCBEF_MASK LDHX @FSTAT JSR PGM PULA ; Restore previous status TAP } return (FSTAT & 0x30); }
Thanks Bob & Peg
I have enough to go on with now. I need to alter one or more bytes in a block,
so will copy the flash block to Ram, modify the ram bytes & flash it back to Flash
using the block flash command.
One would think FS would have demo code of these commonly required tasks available....
In my opinion, there is a lot of demo code that FS should have published.
You may want to consider using 2 blocks. Copy block A to RAM, change the bytes you want, then erase and program block B. Then you can work out a recovery plan in case of a reset in the middle of the operation.
Bob
Yes its always a good idea to have a recovery plan!
Hello Don,
This should get you started. Should still work with JM apart from any paging type issues .