pondělí 13. srpna 2012

Working with the FLASH memory


As the title suggests, I have spent some time during the past week experimenting with the FLASH memory. On LPC13XX micros the memory is divided into eight sectors of 4 kB. Each of these is divided into eight pages of 256 bytes and these are in turn divided into eight 16 byte words.
When working with the FLASH memory there are some restrictions that have to be kept in mind:
  1. The data have to be written into the memory in pages. That means that the size of the data has to be one page and the start address has to be a page boundary.
  2. When erasing the memory it is possible only to erase whole sectors.
  3. A page can be re-written at most sixteen times before it has to be erased (In combination with the previous restriction this means that the whole sector containing the page has to be erased).
Based on these restrictions, I and mr. Svoboda have drafted a specification for six new Elvis commands which are to be used for programming the FLASH memory.
The device's firmware and the tolpc program will be extended to implement these new commands.

The new FLASH programming commands

The FLASH programming works in the following way (in simplified terms): The micro contains a page-sized buffer and receives messages containing 16 bytes (one word) of data which are then written into the buffer. Once full, the whole buffer can then be written into the memory by sending another message containing the desired page address. The complete description of the programming messages can be found in the Elvis protocol specification, but I will give a brief rundown here as well:
  1. Reset
  2. Command to reset the micro. It does not really have anything to do with programming the FLASH memory, but it will be needed in the future to implement the boot-loader.
  3. EraseCommands the micro to erase a range of sectors specified in the data part of the message.
  4. LoadSends 16 bytes of data to be loaded into the buffer. Also contains an offset to specify where exactly to put the data into the buffer.
  5. WriteContains a page address where the data from the buffer should be written.
  6. Check-sumAfter receiving this command, the micro will compute a check-sum over all of the data contained in the page specified in the message. Then it will send in back to the master computer. The check-sum can be compared with the correct value to see if the data have been written into the memory without any errors. The CRC algorithm used is the same as for the Elvis messages. LPC13XX contains a hardware signature generator, which allows for the same functionality, but after some deliberation we have decided not to use it.

More work

Besides experimenting with the FLASH I have been working on creating a basic boot-loader. The way it is intended to work is that the program will be stored in FLASH, but right after reset it will copy itself into RAM and run from there; Allowing it to rewrite itself in the FLASH and run a new version of itself after reset. To accomplish this I have written a new linker script file and rewrote crt0.S, the file containing the code which runs right after reset. I thought I had them right but, unfortunately, it does not work, so it looks like I will probably have to take a look at some Cortex M3 debugging documentation and find out what is wrong.
I will let you know how that went next week.

Žádné komentáře:

Okomentovat