No announcement yet.

Using SD for generic NV memory

  • Filter
  • Time
  • Show
Clear All
new posts

  • Using SD for generic NV memory

    Can the SD card be used for generic reads and writes, regardless of address?

    I just want to write a few user settings to the SD card, and retrieve them on startup. I will not be using the card in a PC, nor will I be using the file_ class functions.

    I've tried the media_WriteWord(), and media_ReadWord(), but what I write isn't persistent after a startup.

    Are there address spaces that should be used? Ones that should be avoided? Can areas used by the FAT be written over with media_WriteWord, and if so, would a subsequent media_Init() then fail?

  • #2
    Did you do media_Flush() after your writes?

    If you are using FAT services you will need to make sure you don't write anywhere in the FAT partition, you can use RMPET to find the location of the FAT partition.

    If you don't have any space after the FAT partition to store RAW data then you can use RMPET to shrink the FAT partition.


    • #3
      I'm not using FAT services at all. RMPET shows "No valid MBR or Partition Table Found"

      Is the media_Flush required after media_WriteWord and media_WriteByte? The DIABLO16 manual says its required after a Sector write - which I took to mean media_WrSector()


      • #4
        So you can write it 'anywhere'

        It doesn't say after a sector write, at least in my manual, it says "After writing any data to a sector". Bytes and words are 'buffered' so you need to do a flush to get them written. This might occur automatically if there is other uSD access afterwards, but a flush ensures it is written.

        A write sector doesn't need a flush as the buffer is filled by definition and hence automatically flushed


        • #5
          If I do several sequential media_WriteWord() calls, will a single media_Flush() suffice?


          P.S. Thanks for the quick replies!


          • #6
            If you do enough to fill a sector (and that could be caused by starting part way through a sector), then the sector will be flushed when filled.

            So a single flush at the end of a series of writes will always suffice


            • #7
              If you do enough to fill a sector (and that could be caused by starting part way through a sector),
              This confuses me. I thought that attempting to write to the middle of a sector, will automatically put the data at the beginning of the sector.

              Which kind of leads to my next question of why the media_SetAdd() function accepts an absolute memory location, instead of just the sector number.

              The Diablo16 Internal Functions document says:
              An attempt to use the media_SetAdd(...) function will result in the lower 9 bits being interpreted as zero.
              I kind of confirmed this by setting the address to (0,0), writing 2 words, setting the address to (0,32), and writing 1 word. The contents of the second word would end up at (0,0), overwriting the data from the first write, and all remaining bytes in the sector being 0xFF.

              Or am I totally wrong on this?


              • #8
                Ahh, no the manual is probably right. I expect setAdd is only useful for reading non sector aligned data