Branches don't work after erasing flash in simulator!

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

Branches don't work after erasing flash in simulator!

2,745 Views
alexd
Contributor I
Hi everyone,

I am writing an embedded application for the MC9S08SH8. I want to use one page of FLASH memory for non-volatile storage of user settings. I have allocated a 512-byte constant block starting at E030 (the beginning of a FLASH page). However, when I erase this page of FLASH in the simulator, the MCU suddenly ignores all branches, breezing past them and executing data.

The instruction summary says this about BRA:

BRA rel -- Branch Always (if I = 1)

I have tried turning I on, off, off and on, on and off, but whatever I do, branches don't work after erasing FLASH.

I am using the FlashErase1 routine from page 60 of the HCS08 Family Reference Manual. Any input would be much appreciated.

Alex Dowad
Labels (1)
Tags (1)
0 Kudos
6 Replies

544 Views
Lundin
Senior Contributor IV
I suspect this is because you can't execute code from the flash while writing/erasing to the flash. The solution in that case is to execute the erase code from internal eeprom or RAM.
0 Kudos

544 Views
bigmac
Specialist III
Hello Alex,

For the 'SH8 device, you will need to run part of the erase code (and also programming code) from RAM.  This is because, when the erase process commences, an internal charge pump applies high voltage to the flash array.  Whilst this occurs, flash memory is unreadable.

Using the search engine below, you should find numerous code examples for S08 devices within this forum.  Some of the methods use a fixed block for the RAM based code, whereas the other possibility is to load the function code to the stack, and run it from there.

Regards,
Mac

0 Kudos

544 Views
alexd
Contributor I
Thanks, but the thing is that I *am* executing out of RAM. I am using the routine given on page 60 of the HCS08 Family Manual. This routine loads the critical code from FLASH onto the stack and then uses a JSR to run it from off the stack.

Alex Dowad
0 Kudos

544 Views
alexd
Contributor I
Still haven't found any way around this problem. I suspect that the CodeWarrior MCU simulator is buggy (but I would be happy to be proved wrong).

Alex Dowad
0 Kudos

544 Views
bigmac
Specialist III
Hello Alex,

You seem to be implying that you are using full chip simulation, rather than the real hardware.  Is this the case?  My understanding is that flash erase and write processes are not simulated.

However, I cannot see why branch instructions should be ignored under this circumstance.

Regards,
Mac

0 Kudos

544 Views
alexd
Contributor I
OK, then that answers my question. It's unfortunate, because it means I can't test my code for saving/retrieving user settings in the simulator. Thanks for your help!

Alex
0 Kudos