testflash.fs 899 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. start-microcode testflash
  2. : off d# 0 swap c! ;
  3. : on d# 1 swap c! ;
  4. : spi-sel FLASH_SSEL off ;
  5. : spi-unsel FLASH_SSEL on ;
  6. : spi-cold spi-unsel FLASH_SCK off ;
  7. : spi-1bit ( u -- u ) \ single bit via SPI
  8. d# 2 *
  9. dup swab FLASH_MOSI c! \ write MSB to MOSI
  10. FLASH_SCK on \ raise clock
  11. FLASH_MISO c@ or \ read MISO into LSB
  12. FLASH_SCK off ; \ drop clock
  13. : spi-xfer ( u -- u )
  14. spi-1bit
  15. spi-1bit
  16. spi-1bit
  17. spi-1bit
  18. spi-1bit
  19. spi-1bit
  20. spi-1bit
  21. spi-1bit ;
  22. \ See Atmel AT45DB021D datasheet:
  23. \ http://www.atmel.com/dyn/resources/prod_documents/doc3638.pdf
  24. : main
  25. spi-cold
  26. spi-sel
  27. h# d7 spi-xfer \ flash read status command
  28. spi-xfer \ send junk, receive status
  29. spi-unsel
  30. COMM+0 c! \ write status to COMM+0
  31. begin again
  32. ;
  33. end-microcode