Bootstrap code.

benbaker7

Well-known member
As I understand it, program code is stored in rom, as is data memory. As rom is eeprom, it is not lost at power off.
My question is, where is the bootstrap code stored? If it were in rom, then it would be overwritten with a new program - which it isn't. I can only surmise that the bs code is protected - but of course it seems that it can be deleted by erasing the chip in total.
So I'm a little perplexed. Despite reading pt1 p52 and the FAQ's, I cannot see any definitive answer to my question. Help please.
Ben Baker
 
On a majority of the PICAXE chips, the firmware ("Bootstrap code") is located in Flash memory ... Flash memory is *also* where your application code is stored.

As it's the firmware itself that receives the download and stores it in Flash, it is responsible for not overwriting any of it's own code.

The *only* way you can damage the PICAXE firmware is to erase it using an ICSP programmer such as the PICKIT. Erasing the firmware reverts the PIC chip to a raw PIC device which you can program with MPLABX .... but the PICAXE firmware will be lost, and the chip will no longer receive PICAXE downloads.
 
I hope I'm not appearing to be argumentative - I have done some programming with pickit2,mplab and 12f508, such that when I've done a bulk erase, all locations revert to hex fff. So what confuses me is that when an erase occurs during overwrite by the new program, all eeprom is used for the program. The only conclusion I can draw from this, is that the chip(s) used by the picaxe system have a separate area where firmware is placed, other than eeprom.
 
Hi,

The 12F508 is Not a "Base PIC" chip, the 08M2+ uses a 12F1840, which has both Data EEPROM (256 bytes) and Program Flash (4k "words") Memory (which actually have different endurance ratings of 100k and 10k write-cycles respectively). If you erase both of those, I'm fairly sure you WILL lose the PICaxe interpreter (of which some is the Bootstrap Code). But PICaxe might not use those regions "as intended" by Microchip. Although the 08M2 has 256 bytes of "Data EEPROM", if you actually use some of those bytes (in a specific program), they are Borrowed or Stolen from the (PICaxe's) available "Program Memory", which reduces from 2048 bytes to 1792 bytes !

Cheers, Alan.
 
I hope I'm not appearing to be argumentative - I have done some programming with pickit2,mplab and 12f508, such that when I've done a bulk erase, all locations revert to hex fff. So what confuses me is that when an erase occurs during overwrite by the new program, all eeprom is used for the program. The only conclusion I can draw from this, is that the chip(s) used by the picaxe system have a separate area where firmware is placed, other than eeprom.
Yes, a bulk erase will erase the FLASH (where the PICAXE firmware along with any user code is stored). However, when you're uploading programs to the PICAXE via the PICAXE Editor, the editor is uploading via the PICAXE firmware on the chip, there is no "Bulk erase" taking place ... the PICAXE firmware takes the program given to it, and stores it in the "user code" space of flash for execution.

With a PICKIT, you can *easily* erase a PICAXE chip ... this will revert it to it's base PIC model ... for instance: I"ve erased a PICAXE 20x2... which essentially turned that into a PIC14FK22 chip ... so I use it as a PIC chip now.

You can't read / copy the PICAXE firmware ... so if you erase a chip, it's no longer a PICAXE, and can't be made back into a PICAXE.
 
So if I'm reading you correctly, the pocsxe code is written to data memory by rev-ed and is code protected. User programs are written to eeprom and are unprotected. Am I on the right track?
 
So if I'm reading you correctly, the pocsxe code is written to data memory by rev-ed and is code protected. User programs are written to eeprom and are unprotected. Am I on the right track?
Close.

The PICAXE firmware ("Interpreter") code is stored on the PIC's Flash memory (By Rev-Ed).

The PICAXE firmware will take a user code download and store it on Flash memory as well ... (PIC's can write to their own flash) and if necessary, user code can be stored in the EEPROM as well. (If the Flash space runs out).

The Flash is read-protected ... so you will not be able to retrieve the PICAXE firmware, nor the user code.
 
So if I'm reading you correctly, the pocsxe code is written to data memory by rev-ed and is code protected. User programs are written to eeprom and are unprotected. Am I on the right track?
Generally speaking, EEPROM is usually only used for storing non-volatile data. In some PICAXE models, they can use EEPROM for 'overflow' program storage, once FLASH memory has been exhausted. The (very old) 08Ms and 14Ms used to store their use code in EEPROM but that was around 15 years ago.

As background, the code you write is stored in FLASH as instruction "tokens". The PICAXE firmware (that you cant access) unpacks these tokens and interprets them before executing their requirements. That is why PICAXE chips execute code quite slowly when compared to the more usual microcontrollers.
 
User programs are written to eeprom and are unprotected. Am I on the right track?
Both the flash and the EEPROM can be protected on the PIC chips.

I've never tried to read the EEPROM but this Microchip document Advanced Code Security Features in 8-bit PIC Microcontrollers states that EEPROM can be protected, like flash, and reading protected EEPROM will return all zeros:
"The CPD Configuration bit protects the entire data EEPROM memory space from external read and write operations. When CPD = 0, external read and write operations of the data EEPROM memory are inhibited, and a read will return all zeros."

You can configure the EEPROM protection so that it only applies to external access, e.g. reading it using a programmer like the pickit2, and it allows internal program running on the chip can read and write to the EEPROM.

The document above also describes "Impact of Bulk Erase Operation" as "Completely erases the memory" in the flash, eeprom, configuration bits and user id memory sections.

So if I'm reading you correctly, the pocsxe code is written to data memory by rev-ed and is code protected. User programs are written to eeprom
Older microchip PIC chips, like the PIC12F683 used for the PICAXE 08M, did not provide the commands to allow the program that was running from flash to modify the contents of flash so when you downloaded the user program the PICAXE firmware running from the flash on the chip could only write the user program to the EEPROM.

The 08M/PIC12F683 chip has 2048 bytes of flash and 256 bytes of EEPROM.
The PICAXE firmware is stored in the 2048 bytes of flash and both the user program and the PICAXE BASIC DATA/TABLE data are stored in the 256 bytes of EEPROM.
So the 08M specs are:
  • For the user program "Memory Capacity (bytes)" = 256 and "Max. Memory Capacity (lines)" = 220. i.e. the user program could use all the EEPROM space.
  • For the DATA/TABLE data "Data EEPROM (bytes)" = 256-P, which means 256 bytes minus the size of the user program. i.e. the bigger the user program the smaller the amount memory available for DATA/TABLE data in the user program.

Newer Microchip PIC chips , like the PIC12F1840 used for the PICAXE 08M2, added commands that allowed the running program to modify the contents of flash.
The 08M2/PIC12F1840 chip has 4096 bytes of flash and 256 bytes of EEPROM.
and the 08M2 specs are:
  • For the user program "Memory Capacity (bytes)" = 2048 and "Max. Memory Capacity (lines)" = 1800. As the chip only has 256 bytes of EEPROM the user program can only be stored in the flash not used by the PICAXE firmware and this is made possible by the commands that allow the running program to modify the contents of flash.
  • For the DATA/TABLE data "Data EEPROM (bytes)" = 256. Now that the user program is being stored in flash, all the EEPROM memory can be used for DATA/TABLE data.
NOTE #1: The manual #1 states that on the 08M2 chip the DATA/TABLE memory is shared with the user program, which conflicts with the contents of the "PICAXE-M2 Information" document that was published when the 08M2 chip was released, so the specific info about the 08M2 above might be wrong.
When I check using PE 6.2.0.0 what I think Alleycat described in post #4 I get a different result:
08M2 EEPROM Example.JPG

However, that detail doesn't matter as the 08M2 example I give above is intended to describe the general difference between the older chips where the user program was stored in EEPROM and those new chips where the user program is being stored in flash.

NOTE #2: The manual #1 also describes that "On X1 and X2 parts 256 bytes of the program memory can also be ‘reserved’ as a lookup table" for the TABLE/READTABLE commands.
 
Last edited:
Hi,
When I check using PE 6.2.0.0 what I think Alleycat described in post #4 I get a different result:
It's not as simple as that. :giggle:

I recall encountering the issue with PE5, but PE6 gets it wrong as well. The 08M2 EPROM is shared with the Program Memory in reverse order. So if you allocate EPROM Address Bytes 0 - 4, then the 08M2 Program size is actually limited to 2043 bytes. To check this, I loaded a program of just under 1900 bytes. It was happy if I added Data bytes from Address 0, but anything over about 150 and it reports that the memory is already in use. Note how it reports that the last byte is in error, but several of the others are as well.
08M2DataMemoryOverlay.png
Generally, the limiting factors on the larger chips now appears to be the Program Editor as much as the Base PIC chips. With PE6, the other M2s now can have a second Program "Slot" (bank) and another 512 Bytes of (Read Only) Table Memory. Also, certain types of Program compile to a smaller size with PE6 compared with PE5, I believe because they found an alternative area to store the Subroutine Address Table List.

Cheers, Alan.
 
Back
Top