Mark Butcher

Incircuit FLASH programming - M5223X

Discussion created by Mark Butcher on May 11, 2006
Latest reply on Nov 7, 2007 by None None
Hi
 
I am having a bad time trying to program the FLASH on the M52235EVB from the application!!!!!!!

I am moving from the MC9S12NE64 which is almost identical and so I expected the code to work with a few small modifications.
 
Before letting the code run, I walked through with the BDM and tried the command manually. This is the sequence (which is indeed very simple and works fine on the NE64 using BDM - register names are the only modification).
1. Set CFMCLKD to 0x4f - it reads back 0xcf showing that it has been written to.
2. Write a long word to a FLASH location - say 0x20000
3. Write the command in CFMCMD - say 20 to program a long word
4. Write 0x80 to CFMUSTAT (to start the command - writing the '1' resets CBEIF).
I read back immediatly 0xc0 - indicating ready for command and no errors.
 
The problem is that it doesn't program, erase or do anything (with various commands attempted). Also when I intentionally do comething incorrectly, or cancel by writing 0x00 to CFMUSTAT there are never error error bits set as would be expected.
 
My only explanation is that there is some additional initialisation required which I have not yet found as my impression is that the commands are presently being totally ignored.
The result is the same whether I step through code performing this sequence or when I write the bytes manually using the BDM.
 
I then tried with the dBUG in the EVB. Using the inbuilt flash commands I managed to erase a block so the device is fine. I wanted to see how it had left the registers but this was not possible since I couldn't get a memory read of the registers to work - the reason being that reads default to half word reads, which cause a bus error in this peripheral area. When I tried a byte read (md b 401d0002, according to the documentation) it just gave me a memory dump from address 0 (like a serial upload because it never stopped and I had to reset the board), suggesting also a problem with the dBUG on the new EVB.
 
So I have a few questions:
- When setting CFMCLKD is the value correct for a 25MHz quarz and 60MHz PLL operation. I am not sure which clock is actually used for the calculation and so am using the faster to avoid destroying something if wrong - I would have loved to see what the dBUG programs but I just can't read the register - it is very frustrating....
- Does anyone know what is missing in the above sequence which is causing it not to work?

- After studying the data sheet I was convinced that the granuality of the FLASH is 8k (the smallest block which can be individually erased) but dBUG told me it is 2k and it really is so from the test results. I think that this point is missing in the data sheet.
By the way, I saw previous FLASH programming questions and looked at the dBUG code for the 5213 but the programing routine is defined as an array of constant data (I assume assembler code to be copied to RAM) so I didn't learn much there. 
 
I would be very grateful if someone could help since this is a very annoying problem, especially as I never had any trouble programming the HCS FLASH, which seems to be basically identical....
 
Regards
 
Mark Butcher
www.mjbc.ch
 

Outcomes