• AVR Freaks

Hot!Generic SPI Flash and enhanced SPI Driver

Super Member
  • Total Posts : 729
  • Reward points : 0
  • Joined: 2008/12/04 06:44:21
  • Location: Cincinnati, OH
  • Status: offline
2016/07/15 09:02:09 (permalink)
5 (1)

Generic SPI Flash and enhanced SPI Driver

At this point I figured that I would simply share the generic SPI Flash Driver that I implemented. The SPI libraries have been slightly altered to make it so that the SPI Flash Driver and other SPI peripherals, regardless of clock mode, could operate nicely on the same bus. It's (SPI driver) only been tested in 8 bit mode, as I don't have the hardware to test it out in 16/32 bit mode. I have some basic hooks in the SPI Flash Driver to bolt into the MPFS file system, but since that library is blocking I haven't done much with it. You'll also get an EraseWrite function and support for byte, AAI, and page write modes. At a minimum, it can serve as a starting point for those of you interested in writing your own drivers. Please let me know if you run into issues with it, as I'd like to be able to correct my own code base.
I have attached zipped up folders for the spi and spi flash drivers. The spi driver folder should be unpacked to C:\microchip\harmony\v1_08\framework\driver and the generic_spi_flash driver to C:\microchip\harmony\v1_08\framework\driver\spi_flash. The config/drv_flash.hconfig file should have the following line added to it:
source "$HARMONY_VERSION_PATH/framework/driver/spi_flash/generic_spi_flash/config/drv_generic_spi_flash.hconfig"
I've also attached the system_definitions.h.ftl, system_config.h.ftl, and system_tasks_rtos.c.ftl files so that you can see what needs to be added in order to get the generic spi flash driver bolted into the mhc. Those files are located here: C:\microchip\harmony\v1_08\utilities\mhc\templates\app\system_config.
I believe that is all that you need. It will take up more memory due to the EraseWrite functionality, but it's fairly easy to get rid of it. The reason is that with EraseWrite is that you'll need to read 4k sectors first (requires a buffer like the nvm library), erase the sector, and then write back the contents. It can be a lengthy operation if you only want to write a few bytes, but it will be necessary if you want to bolt serial flash drivers into the file system. If you need to add your own SPI flash chips to this, simply add the appropriate definitions to drv_generic_spi_flash_local.h and the appropriate code to drv_generic_spi_flash.c.

1 Reply Related Threads

    Super Member
    • Total Posts : 191
    • Reward points : 0
    • Joined: 2008/03/24 04:10:00
    • Location: Russia, Nsk
    • Status: offline
    Re: Generic SPI Flash and enhanced SPI Driver 2019/08/02 01:40:08 (permalink)
    Thank you, now I can write 1kb of FLASH in 10ms instead of 10sec!

    Let's telegram! t.me/microchip_forum
    Jump to:
    © 2019 APG vNext Commercial Version 4.5