Author Topic: [z80] Writing to flash  (Read 13832 times)

0 Members and 1 Guest are viewing this topic.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
[z80] Writing to flash
« on: March 23, 2013, 06:56:50 am »
Hi guys,

I'm working on a file system for cmdOS, and I want every files to be in archive to allow user programs to use a maximal amount of free RAM. I planned to handle it this way :
  • A 3-bytes pointer on a VAT at a static address in RAM consisting of a 2-bytes address (low byte then high byte) and a page number.
  • At the location pointed to by this pointer and in the given flash page, the start of the VAT.
  • After this location, each and every file whose structure will be discussed later.
The problem is : I don't know how to write to flash. I know how to swap pages using ports 6 and 7, but I also know that you can't just write to the corresponding areas like that.

How can I, say, write a byte to a flash page ?

Note that I don't have any built-in routine for that. I'm NOT using the TI-OS nor any library, and I don't want to. I just want to understand how to do that and then being able to implement it.
« Last Edit: March 23, 2013, 06:57:52 am by Matrefeytontias »

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: [z80] Writing to flash
« Reply #1 on: March 23, 2013, 08:33:24 am »
I think there's some boot code stuff but IDK how to use it. :s

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: [z80] Writing to flash
« Reply #2 on: March 23, 2013, 08:43:51 am »
How can I, say, write a byte to a flash page ?
That is not a good idea. The flash can't bear an infinite number of writes. That number is high (10000 or something) so in "normal conditions of use", you don't reach it, but if you plan on writing byte per byte, or even 10 bytes per 10 bytes, as long as you use it often, you have more chance of having a flash wear.

Also, sorry not to actually answer the question (:P), I think that you should ask thepenguin or DrDnar or Runer or other people like that about unlocking flash.
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: [z80] Writing to flash
« Reply #3 on: March 23, 2013, 08:48:13 am »
What wears out Flash memories is erasing sectors / blocks / full chip, not writing to sectors / blocks :)

The OS and boot code contain BCALLs to those effects. They're certainly documented, and besides, the datasheet of the Flash memory chip could enable you finding them more easily.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [z80] Writing to flash
« Reply #4 on: March 23, 2013, 09:18:23 am »
Well, if you can only erase sectors, how can you save datas into them ? O.O

And btw I won't be able to understand a code which does something I don't know anything about.
« Last Edit: March 23, 2013, 09:18:33 am by Matrefeytontias »

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: [z80] Writing to flash
« Reply #5 on: March 23, 2013, 09:30:23 am »
In case anybody missed it, Matrefeytontias is working on building an OS, so he won't have some tools (but it should be easier). I think this page might be useful.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [z80] Writing to flash
« Reply #6 on: March 23, 2013, 09:32:39 am »
How could I have missed that, I read every page of Ti-83+:OS on WikiTi O.O (well, I thought)

Thanks a lot, that'll help me :D

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [z80] Writing to flash
« Reply #7 on: March 23, 2013, 09:34:34 am »
Hmm if you write to flash, be very careful to not accidentally write to the wrong page. If you accidentally erase the certificate, you're screwed.

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: [z80] Writing to flash
« Reply #8 on: March 23, 2013, 09:37:09 am »
Yup, the raw commands are in the datasheet, which is why I suggested him to read the datasheet and then find the corresponding routines in TI's boot code :)
But if it's documented in WikiTI, even better.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [z80] Writing to flash
« Reply #9 on: March 23, 2013, 09:47:12 am »
I'll go with the page Xeda112358 gave me, and then I'll see if I can do something with it :)

By the way, Hayleia said that writing a byte to flash wasn't a good practice, but the said page gives an entire writeFlashByte routine .. what are your thoughts on that ?

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: [z80] Writing to flash
« Reply #10 on: March 23, 2013, 10:02:42 am »
Writing more than one byte is just a matter of embedding the code for writing a byte into a loop. As I wrote above, what wears out the Flash memory is erasing it, not writing to it.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [z80] Writing to flash
« Reply #11 on: March 23, 2013, 10:04:53 am »
Erasing a sector is what the TI-OS does when Defragmenting after an app deletion right ?

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: [z80] Writing to flash
« Reply #12 on: March 23, 2013, 10:09:50 am »
Yup, erasing a sector is necessary so that you can write again arbitrary data to it. When writing to Flash memory (both NOR and NAND), the write operation is effectively an AND operation: it can only turn bits from 1 (default state after erasing) to 0. Only erasing makes it possible to turn bits from 0 to 1, but erasing is a slow, bulk operation performed over large blocks (sectors).
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [z80] Writing to flash
« Reply #13 on: March 23, 2013, 10:11:37 am »
But then if I want to write a single 1 bit to a sector I need to erase it first !? *.*

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: [z80] Writing to flash
« Reply #14 on: March 23, 2013, 10:15:06 am »
Only if you want to overwrite it. If you have erased the sector (a chunk of 4 flash pages), you can write to all of the bytes. That is why the OS needs to garbage collect. When you unarchive to edit, then rearchive, it gets written back to a different place instead of overwriting the whole sector just to replace the data.