How to use overlays and libflash in the same application

  • version

    1.1.1

  • scope

    Example.

    This code is provided as example code for a user to base their code on.

  • description

    How to use overlays and libflash in the same application

  • boards

    Unless otherwise specified, this example runs on the SliceKIT Core Board, but can easily be run on any XMOS device by using a different XN file.

When the flash overlay runtime is initialized it takes ownership of the xCORE ports used to access the SPI flash device. This prevents them being used for any other purpose (e.g. reading and writing data using libflash).

If necessary an application can ask the flash overlay runtime to transfer ownership of SPI ports back to the application:

fl_SPIPorts * movable spi_ports = overlay_flash_claim_ports();

If the overlay runtime is in the middle of loading an overlay the call to overlay_flash_claim_ports will block until it has finished loading the overlay.

Once the application has ownership of the SPI ports it can use them to read and write data from the flash using libflash:

fl_connect(*spi_ports);
// Access flash here...
fl_disconnect();

While the application has ownership of the ports a call to function in an overlay that is not loaded will block. Call overlay_flash_return_ports to give ownership of the ports back to the overlay runtime:

overlay_flash_return_ports(move(spi_ports));