Is is possible with the 8051 architecture to copy a program or function into XRAM and execute it? Or do the separate code/data address spaces prevent this? What I'm trying to do is to write a boot loader that can put the loader routine into flash, so that the flash chip the boot loader resides in can be erased and re-written. The plan is NOT to update the boot loader portion of the flash, but the application portion. The flash chip we're using doesn't allow you to execute out of the flash if any portion of the flash is being programmed. We're using the Philips 87C51MB2 chip, which is an MX part. Thanks, Ed
Well, all you have to do is to create a certain chip select logic. As a default, the FLASH will be accessed with PSEN (thus, it is in the code segment). For boot loading, you could access part of the ram as code segement with PSEN. Probably you might need some external ram for the boot loader too. the flash should be in the x-data segment while boot loading. It shoudl be accessed with /RD and /WR. You can switch between both modes using an I/O pin. In default, it is HIGH. So when this pin is high, the memory is accessed in normal mode (/RD and /WR access the RAM, /PSEN accesses the FLASH). For boat loading, this I/O Pin is tied to LOW. In this case, the part of the RAM that contains the boot loader is accessed with /PSEN. The RAM being used by the boot laoding routine accessed with /WR and /RD. Also the FLASH is accessed by /WR and /RD. There is a memory overlap. This doesn't matter much, since there should be some part of the FLASH that cannot be modified. Maybe it could contain the code of the bootloader being copied to the RAM. Programming the software that is suitable for being upload is a bit tricky, but not really hard. Assuming the FLASH cannot be modified in the first KB, you have to have a secondary interrupt table. Just modify the startup.a51 that every interrupt from the normal interrupt table jumps to the secondary interrupt table in the part of the FLASH that can be modified. Now you can easily create that secondary interrupt table, by telling the compiler/linker a different offset for the interrzpt table. You should also be able to do "seemless" switching of the boot laoder and the main program. That is possible with the startup.a51 routine too. Just do the set/reset of the I/O-pin mentioned before in a certain place and then jump to the normal entry point at 0000.
Thanks for your ideas - I'll talk with my hardware engineer when he gets back.
Take a look at the following example program: http://www.keil.com/download/docs/8051_vonneumann.zip.asp Jon