Project

General

Profile

jnz4 Forth F-RAM driver

Added by linuxpeppe about 1 month ago

Hi,
there are a lot of intersting things in Jeelabs.org page and this forum.
That's is my less than a contribute but just experience for sharing.
I soldered a Cypress FM25CL64 F-RAM chip on HyTiny Extender and i write an ugly Forth driver.
It's a very cool mem. No pagination, no delay. Moreover High-endurance 100 trillion (10
14) read/writes. I did it thinking to counter datalogger applications.
Take a look to http://www.cypress.com/file/41676/download

If anyone is interested in writing a driver this is a useless photo and some code.

\ already included in tex/board.fs
PA15 constant SMEM.SEL  \ SPI flash memory CS usef for F-RAM
SMEM.SEL ssel ! \ change definition in spi.fs for Slave Select

spi-init

\ F-RAM DRIVER

$06 constant FR:WREN \ set write enable latch
$05 constant FR:RDSR \ read status register
$04 constant FR:WRDI \ write disable
$03 constant FR:READ \ read memory data
$02 constant FR:WRITE \ write memory data
$01 constant FR:WRSR  \ write status register

: frmem-cmd ( cmd -- )  +spi >spi ;
: frmem-rdsr ( -- rdsr ) +spi FR:RDSR >spi spi> -spi . ;
: frmem-wren ( -- ) FR:WREN frmem-cmd -spi ; \ set write enable latch
: frmem-read8 ( addr -- c )
  dup $FF and swap 8 rshift $FF and \ address 13 bit in two byte conversion (MSB first)
  FR:READ frmem-cmd >spi >spi spi> -spi . ;

: frmem-read32 ( addr -- u )
    dup $FF and swap 8 rshift $FF and \ address 13 bit in two byte conversion (MSB first)
    FR:READ frmem-cmd >spi >spi
    0  4 0 do 8 lshift spi> or loop -spi . ;

: frmem-write8 ( addr c -- )
  frmem-wren
  swap dup
  $FF and swap 8 rshift $FF and \ address 13 bit in two byte conversion (MSB first)
  FR:WRITE frmem-cmd >spi >spi >spi -spi ;

: frmem-write32 ( addr u -- )
    dup $FF and swap 3 0 do 8 rshift dup $FF and swap loop drop \ prepare stack to transmit MSB at first
    4 pick
    dup $FF and swap 8 rshift $FF and \ address 13 bit in two byte conversion (MSB first)
    frmem-wren
    FR:WRITE frmem-cmd >spi >spi \ write address
    4 0 do >spi loop -spi
    drop ;


Replies (1)

RE: jnz4 Forth F-RAM driver - Added by jcw about 1 month ago

Very nice - thanks for sharing!

Interesting chip - I see they're available in sizes from 512 to 512K bytes, and there's even a DIP-8 version.

    (1-1/1)