Shop OBEX P1 Docs P2 Docs Learn Events
Work in Progress - Winbond Flash / Microchip SRAM driver + FemtoBasic — Parallax Forums

Work in Progress - Winbond Flash / Microchip SRAM driver + FemtoBasic

Mike GreenMike Green Posts: 23,101
edited 2009-10-21 16:27 in Propeller 1
For those interested in experimenting, here's my current working copy of FemtoBasic modified for use with TriBlade#1 and a 2MB Winbond
flash memory chip.

There's a subset VT100 terminal emulator included and tested low level support for a 2MB to 8MB Winbond flash memory chip.
You can erase 4K blocks (FERASE) and read (FREAD) data and write (FWRITE) small amounts of data to flash. The DUMP statement
works with flash as well.

There's the ability to create, open, and delete files and read and write data to files, but this is not tested yet. Once this works, the SAVE,
LOAD, FILES, and COPY statements will be implemented for flash so they look and work much like for an SD card. Have a look at the
"Winbond Driver".

Note that the source is set up for a 6MHz crystal. You can change that and recompile. It's also set up for a VGA display. I've included the
half-height 40 x 30 TV text driver modified to be able to substitute for the VGA driver including the VT100 support. I haven't tested it yet,
but it compiles and looks like it should work.


6 May 09: Corrected error in FWRITE
7 May 09: Corrected error in findFile. Added code for SAVE, LOAD, FILES ... tested & seem to work.
7 May 09: v4.005 - Corrected error in eraseFile and DELETE
9 May 09: v4.008 - Corrected errors in eraseFile, FILES, DELETE, COPY. Sped up some operations.
10 May 09: V4.009 - Corrected errors in readFile and writeFile. Now files >4K work properly.


At this point, everything flash related appears to work except the SPIN statement to load and execute Spin programs.

The Winbond Driver is designed to not use a central directory. This slows things down, but helps reduce the number of times a 4K sector has to be erased or written. Because of the way flash memory is implemented, once you write to a portion of the file, you can't write again to that portion until that 4K block is erased. The Winbond Driver is intended to provide for sequential files where you write sequentially to the file, then read the file sequentially one or more times. Next step is to finish the PASM routines so the SPIN statement will work and the whole Winbond Driver will run faster.

Post Edited (Mike Green) : 7/4/2009 5:03:53 AM GMT
«1

Comments

  • Dr_AculaDr_Acula Posts: 5,484
    edited 2009-05-06 07:59
    So many things happening so quickly!

    Right, I've been jolted out of my stupor, and am off to the shed to solder up a triblade.

    Re femtobasic, sooner or later any program seems to grow bigger than the available memory. One way around that is Shell and Chain, to pass control to another program. Does femtobasic have these commands? (I must do some more research, it sounds intriguing).
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-06 12:40
    FemtoBasic has the ability to load and run new Basic programs either from EEPROM or an SD card. Look at the descriptions of the LOAD and RUN statements. It doesn't preserve the values of variables when you do a RUN, but you can write values to EEPROM or an SD card file and reload them in the "overlay". If there's a file "AUTOEXEC.BAS" on the SD card, FemtoBasic will do a LOAD "AUTOEXEC.BAS":RUN when it starts up.

    FemtoBasic also has the ability to run a new Spin/PASM program using the SPIN statement. Parallax used FemtoBasic for a kiosk for Propeller demo programs that would let you choose a demo from a menu, then execute it. The demo would do a reboot when it finished, restarting FemtoBasic.
  • CassLanCassLan Posts: 586
    edited 2009-05-06 13:24
    Now I have to get a Tri-Blade [noparse]:)[/noparse]
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-06 13:30
    I just posted a correction. I'll continue to post corrected versions to the first message on this thread along with a date and what's corrected.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-07 05:28
    Exciting ... LOAD and SAVE seem to work. OPEN R and OPEN W seem to work and FILE / FILE = seem to work as well as READ, WRITE and FILES. I've not tested these other than on small files (< 4096 bytes). There are also long pauses (500-1000ms) as some of the file lookups go through lots of unused sectors one at a time. I'm trying to avoid having a central directory since that would have to be erased and rewritten every time it's changed. I may have to do something anyway since lookups and space allocation are slow.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-09 23:43
    At this point, everything seems to work except the SPIN statement, so you can save and load Basic programs, read and write sequential data files, copy 32K EEPROM pages to and from flash files, list the files on the flash. You just can't execute Spin programs stored on flash memory yet.
  • Ole Man EarlOle Man Earl Posts: 262
    edited 2009-05-09 23:46
    Great work Mike. I am a fan of yours.
  • Mike HuseltonMike Huselton Posts: 746
    edited 2009-05-10 08:54
    I also admire Mike's professional approach, clarity of thought and patience exhibited in his replies to a full spectrum of users, both neophytes and experts.

    I want to become more like Mike when I grow up wink.gif . I am sure Mike's patients appreciate his approach as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    JMH
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-25 19:02
    Here's a later version of the Winbond driver. It's now been moved to a Demo Board since I was unable to get the loader to work on the TriBlade Prop #1. I think the problem has to do with cog I/O pin conflicts between the Winbond loader and the I2C loader cogs and I plan to eventually get back to it, but I wanted to do some specific things with the Winbond flash.

    This driver also supports the Microchip 23K256 32K byte SRAM. It allows for up to 2 SRAM chips for a total of 64K. The included version of FemtoBasic is used for development and testing of this driver and has statements for low level access to the flash memory and SRAM. You can save Basic programs to the flash and can use the COPY and SPIN statements to handle Spin programs the same way you'd use an SD card. The only limitation is that you can't replace (overwrite) a file. You have to delete it first, then recreate it. This is a limitation of the flash memory, something the SD card internal controller takes care of.
    Added a comment to FemtoBasic.spin describing the connections for the Flash and SRAM memories.
    Corrected use of "dev" in Winbond_Driver.spin. Not allowed under Propeller Tool 1.2.6. Works with BradC's BST.
    I think I've really corrected it this time. Sorry.

    Post Edited (Mike Green) : 5/26/2009 2:54:16 PM GMT
  • Mike HuseltonMike Huselton Posts: 746
    edited 2009-05-25 19:25
    Thank you! I have 23K256 chips and I was going to have write the driver myself. Again, thank you!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    JMH
  • Mike HuseltonMike Huselton Posts: 746
    edited 2009-05-25 19:41
    Mike, how difficult do you think it would be to add FRAM support to the driver?

    My sample devices include:

    • FM24L256-G
      FM24C512-G
      FM25V10
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    JMH
  • Mike HuseltonMike Huselton Posts: 746
    edited 2009-05-25 19:59
    Compile Error: Block Designator Must Be In The First Column
    Module: WinBond Driver
    Routine: PRI sendRecv(dev, sD, rCt, rA) | i, m ' Send and possibly receive
    ..................................^^^ Error cursor at dev

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    JMH
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-25 21:30
    James,
    There's some kind of new error in the Propeller Tool 1.2.6 with the use of "dev". It compiles fine with BradC's compiler. Try replacing the 3 uses of "dev" with "d" and recompiling. It should work.

    All 3 FRAM devices you mentioned are I2C devices as I recall and they should work fine with the existing I2C drivers as direct replacements for ordinary EEPROM. Some of them are 5V-only devices and you'd need some kind of voltage interface (3.3V to 5V for SCL and SDA). Usually just a 1K series resistor will work.
  • BradCBradC Posts: 2,601
    edited 2009-05-25 21:33
    Mike Green said...
    James,
    There's some kind of new error in the Propeller Tool 1.2.6 with the use of "dev". It compiles fine with BradC's compiler. Try replacing the 3 uses of "dev" with "d" and recompiling. It should work.

    Now _that_ is interesting. Sounds like the compiler is being updated and they are adding a new block type to it.. time to get out the disassembler again [noparse];)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "VOOM"?!? Mate, this bird wouldn't "voom" if you put four million volts through it! 'E's bleedin' demised!
  • jazzedjazzed Posts: 11,803
    edited 2009-05-25 21:36
    The "dev" thing is also in version 1.1 ..... I just ran into it this morning. OBJ dev[noparse][[/noparse]1] : "somedevice" gave me an error: "Block designator must be in the first column."

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • BradCBradC Posts: 2,601
    edited 2009-05-25 21:38
    jazzed said...
    The "dev" thing is also in version 1.1 ..... I just ran into it this morning. OBJ dev[noparse][[/noparse] 1][noparse][[/noparse] 2] : "somedevice" gave me an error: "Block designator must be in the first column."

    Oh, in which case I won't bother. Perhaps its a reserved word we did not know about.

    I guess I should make it a reserved word in my compiler to save the incompatibility. Is it documented anywhere?

    <edit>
    Nyaaaahaaa.. further investigation shows it to be used in constructs similar to this
    DEV ARCHIVE "FILENAME"
    DEV PRECOMPILE "FILENAME"

    I was wondering what those two directives were.. now I need to see if they are actually hooked up in the compiler or just remnants. My gut feeling is they provide some sort of interface between the compiler and the IDE. In any case, I won't hijack Mikes thread any further [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "VOOM"?!? Mate, this bird wouldn't "voom" if you put four million volts through it! 'E's bleedin' demised!

    Post Edited (BradC) : 5/25/2009 9:54:15 PM GMT
  • jazzedjazzed Posts: 11,803
    edited 2009-05-25 21:44
    Friggin' tags [noparse]:)[/noparse] OBJ dev[noparse][[/noparse] 1] : "somedevice" ....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • Mike HuseltonMike Huselton Posts: 746
    edited 2009-05-26 14:16
    Mike,
    Mike Green said...
    Corrected use of "dev" in Winbond_Driver.spin. Not allowed under Propeller Tool 1.2.6. Works with BradC's BST.

    This correction does not appear in my freshly downloaded version. Still uses "dev".

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    JMH
  • BradCBradC Posts: 2,601
    edited 2009-05-26 14:21
    James Michael Huselton said...

    This correction does not appear in my freshly downloaded version. Still uses "dev".

    Change all the instances of "dev" to something else. Dev is a reserved word (a block) in the Parallax compiler.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "VOOM"?!? Mate, this bird wouldn't "voom" if you put four million volts through it! 'E's bleedin' demised!
  • Mike HuseltonMike Huselton Posts: 746
    edited 2009-05-26 14:29
    BradC,

    I have done so yesterday. This was meant to inform Mike that he still needs to change the source for the unsuspecting.
    He states that he corrected this, but the code remains the same.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    JMH
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-28 05:30
    There are some minor changes / fixes to the VGA driver and Winbond driver here and some additional comments in the Winbond driver.
  • Mike HuseltonMike Huselton Posts: 746
    edited 2009-05-28 09:41
    Mike,

    Thanks for the updated code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    JMH
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-04 04:41
    Attached is a new version of the Winbond flash / Microchip sram driver written in assembly. It's drop-in compatible with the Spin-only version which is also included and quite a bit faster which is to be expected.

    Next step is to modify "createFile" so it will erase any existing copy of the specified file. This will make it work more like an SD card.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-04 05:04
    Here's the next version that erases an existing file on a createFile.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-04 18:56
    The Winbond Flash / Microchip SRAM Driver has been posted to the Object Exchange. Further updates will be posted directly there.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-04 21:17
    The Winbond version of FemtoBasic for a VGA display has been posted in the ObEx along with the I/O driver and a minor error has been corrected in the driver.
  • Mike HuseltonMike Huselton Posts: 746
    edited 2009-07-05 15:42
    What is the purpose of ouroboros and ouroboros1 in the your software architecture?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    JMH
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-16 16:17
    Ouroboros and ouroboros1 are left-overs from a project to make a Basic to LMM compiler for the Propeller. I forgot to delete them from the archive for the Winbond/SRAM driver. They're not in the Object Exchange version of the driver.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2009-10-21 16:27
    I'm trying to use Winbond chip W25X16A.· I've written a small demo object with hopes of understanding Mike Green's Winbond driver.

    The size of the chip is read correctly but I can't write to the chip (either that or I can't read from the chip).· Here's the code.
    {{  WinbondDemo1a.spin
      Attempt at a demo program for Michael Green's
      Winbond flash driver.
             Vdd(+3.3V)           Vdd(+3.3V)
               &#61463;                    &#61463;
              &#9484;&#9515;      W25X16A      &#9484;&#9547;&#9472;&#9488;
              &#61628;&#61628;                   &#61628;&#61628; &#9474;       
              &#9474;&#9474; &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;&#9474;&#9474; &#9474; 0.1µF        
        P0 &#61609;&#9472;&#9472;&#9532;&#9532;&#9472;&#9508;1 /CS    Vcc   8&#9500;&#9532;&#9532;&#9472;&#9531;&#9472;&#9472;&#61611;&#9472;&#9472;&#9472;&#9472; Vss
        P3 &#61615;&#9472;&#9472;&#9532;&#9531;&#9472;&#9508;2 DO     /Hold 7&#9500;&#9496;&#9474;
              &#9492;&#9472;&#9472;&#9508;3 /WP    CLK   6&#9500;&#9472;&#9532;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#61610; P1
              &#9484;&#9472;&#9472;&#9508;4 GND    DIO   5&#9500;&#9472;&#9531;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#61620; P2    
              &#61464;  &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;  
             Vss
                 Pullup resisters are 10K
                                                   
     }}
    con
     
       _clkmode  = xtal1 + pll16x
       _xinfreq  = 5_000_000
       _CS = 0
       _Clk = 1
       _DIO = 2
       _DO = 3
       _DebugBaud = 9600
    OBJ
      Debug : "FullDuplexSerialPlus"
      Win : "Winbond_Driver"
       
    VAR
       long location
       byte buffer[noparse][[/noparse]128]
    PUB Main | localTemp
      Debug.Start(31, 30, 0, _DebugBaud)
      location := @buffer[noparse][[/noparse]0]
      localTemp := win.start(_CS, _Clk, _DIO, _DO, -1, -1)
      Debug.str(string(13, "Starting Winbond driver returned = "))
      Debug.dec(localTemp)
      
      localTemp := flashSize
      Debug.str(string(13, "flashSize = "))
      Debug.dec(localTemp)
      eraseData($8000)
      repeat localTemp from 0 to 127
        buffer[noparse][[/noparse]localTemp] := localTemp
      Debug.str(string(13, "buffer filled with squential numbers = "))
      repeat localTemp from 0 to 127
        Debug.hex(buffer[noparse][[/noparse]localTemp], 2)
        Debug.str(string(", "))
       
      Debug.str(string(13, "Write buffer to flash memory.  Then erase buffer from prop memory."))
      writeData($8000, location, 128)
      waitcnt(clkfreq / 10 + cnt)
      byteFill(@buffer, 0, 128)
      Debug.str(string(13, "cleared buffer = "))
      repeat localTemp from 0 to 127
        Debug.hex(buffer[noparse][[/noparse]localTemp], 2)
        Debug.str(string(", "))
       
      Debug.str(string(13, "Restore buffer from flash memory.  Buffer = "))
      readData($8000,location,128)
      waitcnt(clkfreq / 10 + cnt)
      repeat localTemp from 0 to 127
        Debug.hex(buffer[noparse][[/noparse]localTemp], 2)
        Debug.str(string(", "))
      
      repeat
    pub winStop
       return win.stop
    pub flashSize                     ' Return the size of the flash memory in bytes
      return win.flashSize
    pub readData(a,d,c)               ' Read a block of data from Flash
      return win.readData(a,d,c)
    pub writeData(a,d,c)              ' Write a block of data to erased Flash
      return win.writeData(a,d,c)
    pub eraseData(a)                  ' Erase a block of data
      return win.eraseData(a)
     
    

    The DO, /WP, DIO, and /Hold pins all have 10K pullup resistors.

    What am I doing wrong?

    I don't post often but I'm a fequent reading of this forum.· Most of my questions have already been asked and answered here.· Thanks for all of your help.

    Duane Degn
Sign In or Register to comment.