WikiTI has oodles of information about controlling the Flash (as far as protection goes, for example) but I can't find any information on how it's actually written to.
I've heard of the AND-ing of bits and clearing of whole pages (or sectors?) but can't find anything out there... I tried treating the pages as RAM, but that simply didn't work.
Does anyone have any info on this, or could point me in the direction of some?
[TI Hardware] Flash ROM
Moderator: MaxCoderz Staff
-
- MCF Legend
- Posts: 1601
- Joined: Mon 20 Dec, 2004 8:45 am
- Location: Budapest, Absurdistan
- Contact:
I’m not sure where to find the datasheet for the flash chip now, but I think it’s even easier to look at some source code:
http://svn.revsoft.org/wabbitemu/source ... re/83phw.c
Check out the flashwrite83p function. Note that you need to unprotect the flash before you can send write commands to it, and that’s the nastier part.
http://svn.revsoft.org/wabbitemu/source ... re/83phw.c
Check out the flashwrite83p function. Note that you need to unprotect the flash before you can send write commands to it, and that’s the nastier part.
- Jim e
- Calc King
- Posts: 2457
- Joined: Sun 26 Dec, 2004 5:27 am
- Location: SXIOPO = Infinite lives for both players
- Contact:
There's PDFs to it as well.
http://docs.revsoft.org/TI_HW/83P/flash.pdf
http://docs.revsoft.org/
I also keep a lot of general info there for all sorts of things.
But here's a slightly cleaner version of that code Cobb pointed to.
Note that theres also a status read that you have to deal with. For erasing and programming the flash chip is not instant. So ti-os does a status read to see if its done. Thats just reading from any place in the flash. If it returns with bit 7 set, its done. Bit 5 indicates an error. When the status read returns a DONE it kicks out of programming or erasing mode and goes back to normal. Since you probably aren't going to emulate the delay in programming, all you need to do is return FF on the first read from the flash after programming.
EDIT:
I should also point out that I'm a bit liberal when it comes to where commands are sent. The flash chip requires writing to 16bit addresses $AAAA or $5555, but I just allow $XAAA and $X555. So for actual flash writing you have to change the page.
http://docs.revsoft.org/TI_HW/83P/flash.pdf
http://docs.revsoft.org/
I also keep a lot of general info there for all sorts of things.
But here's a slightly cleaner version of that code Cobb pointed to.
Code: Select all
typedef struct {
unsigned char *addr; //Pointer to offset of memory.(already paged)
int page; //Current 16kb page
int ram; //This is on the ram chip(also effect write method for flash)
} bank_state_t;
typedef struct {
unsigned char * flash; //Pointer to flash memory
unsigned char * ram; //Pointer to ram
int flash_size;
int flash_pages;
int ram_size;
int ram_pages;
int step; // These are for flash programming
unsigned char cmd; // step tells what cycle of the command you are on,
bank_state_t banks[5]; //Current state of each bank
// structure 5 is used to preserve the 4th in boot map
int boot_mapped; //Special mapping used in boot that rotates location of pages
int unlocked; //Whether flash is writeable or not.
int ver;
} memory_context_t, memc;
void flashwrite83p(unsigned short addr, unsigned char data) {
int bank = (addr>>14)&0x03;
switch( mem->step ) {
case 0:
if (((addr&0xFFF)==0xAAA)&&(data==0xAA)) {
mem->step++;
}
break;
case 1:
if (((addr&0xFFF)==0x555)&&(data==0x55)) {
mem->step++;
} else mem->step=0;
break;
case 2:
if ((addr&0xFFF)==0xAAA) {
if (data==0xA0) { //Program
mem->step++;
} else if (data==0x80) { //Erase
mem->step++;
} else mem->step=0;
} else mem->step=0;
break;
case 3:
if (mem->cmd==0xA0) {//Write data
mem->banks[bank].addr[addr&0x3fff]&=data;//AND logic
mem->step=0;
} else if (((addr&0xFFF)==0xAAA)&&(data==0xAA)) {
mem->step++;
} else if (data==0xF0) mem->step=0;
break;
case 4:
if (((addr&0xFFF)==0x555)&&(data==0x55)) {
mem->step++;
} else if (data==0xF0) mem->step=0;
break;
case 5:
if (((addr&0xFFF)==0xAAA)&&(data==0x10)) {
//Erase entire chip, except boot page
memset(mem->flash,0xFF,(mem->flash_size-0x4000));
} else if (data==0x30) {//Erase certain sectors
int spage = (mem->banks[bank].page<<1)+((addr>>13)&0x01);
if (spage<56) {
memset(mem->flash+((spage&0xF8)<<13),0xFF,0x10000);
} else if (spage<60) {
memset(mem->flash+0x70000,0xFF,0x8000);
} else if (spage<61) {
memset(mem->flash+0x78000,0xFF,0x2000);
} else if (spage<62) {
memset(mem->flash+0x7A000,0xFF,0x2000);
} else if (spage<64) {
//Can't erase the boot page.
//memset(mem->flash+0x7C000,0xFF,0x4000);
}
} else if (data==0xF0) mem->step=0;
break;
default:
mem->step=0;
break;
}
mem->cmd=data;
}
EDIT:
I should also point out that I'm a bit liberal when it comes to where commands are sent. The flash chip requires writing to 16bit addresses $AAAA or $5555, but I just allow $XAAA and $X555. So for actual flash writing you have to change the page.
Last edited by Jim e on Mon 29 Oct, 2007 3:50 pm, edited 1 time in total.
- benryves
- Maxcoderz Staff
- Posts: 3089
- Joined: Thu 16 Dec, 2004 10:06 pm
- Location: Croydon, England
- Contact:
Ah, thanks, that was exactly what I was after.Jim e wrote:There's PDFs to it as well.
http://docs.revsoft.org/TI_HW/83P/flash.pdf
http://docs.revsoft.org/
I also keep a lot of general info there for all sorts of things.
...and the plain English translation of a datasheet is always handy, so thank you for that too.Note that theres also a status read that you have to deal with. For erasing and programming the flash chip is not instant. So ti-os does a status read to see if its done. Thats just reading from any place in the flash. If it returns with bit 7 set, its done. Bit 5 indicates an error. When the status read returns a DONE it kicks out of programming or erasing mode and goes back to normal. Since you probably aren't going to emulate the delay in programming, all you need to do is return FF on the first read from the flash after programming.