Bank Switching and Native Flash Programming
I think I got my bank switching stuff working. In fact, it worked right out of the box–no debugging necessary. Which is a little worrisome. But, I added some menu items for programming flash and writing RAM and bank switching is working as expected.
But, then I ran into a problem…. To put the flash chip into the modes for programming and/or erasing, I need to write to 2aaa and 5555 in specific sequences. But those addresses are from the flash chip’s point of view–after any bank switching. It’s obvious now, but it didn’t occur to me before.
That means, I need the lowest 32K of flash to live in 32k of addressable memory for that brief time. And once in that mode, I can’t touch the flash except for whatever programming/erasing I need to do.
Since my bank granularity is 16k, this is a bit of a problem. It’s going to take a little creativity.
Bit 15 doesn’t matter. But bit 14 does. So when I write to 2aaa, it has to be a to bank where bit 14 is 0. And when I write 5555, it has to be to a bank where bit 14 is 1. Right now, the flash code just writes 2aaa and 5555, but actually, I’m going to need to ensure than either 1) 2 banks are loaded in and the flash programmer has the appropriate addresses that map to post-bank switch of 2aaa and 5555 or 2) that the banks are switched between the writes to 2aaa, 5555, and whatever the user wants to write.
Obviously the first one is easier.
Basically, the steps I need to follow are these:
- copy the flash programming code into a RAM bank
- swap that RAM bank into bank 0 and run from there
- swap the flash banks 00 and 01 into banks 1 and 2
- activate the flash mode with 2aaa+4000 and 5555+4000. These map to 2aaa and 5555
- swap the flash bank to be programmed into bank 1
- perform the write that will program or erase