Flash Driver

Flash is a re-programmable memory that retains program and data storage even with the power off.

The user can write or read several bytes from any valid address in a flash.

Summary of the API's Functional Features

The API provides functions to:
  • Initialize and deinitialize the driver and associated hardware

  • Writing/Reading bytes

  • Locking/Unlocking/Erasing pages

  • Get page size and total pages information

  • Notifications about errors or being ready for a new command

Summary of Configuration Options

Depend on device, few flash parameters can be configured in START.

Driver Implementation Description

As to the erase/lock/unlock command, the input parameter of an address should be a byte address aligned with the page start, otherwise, the command will fail to be executed. At the meantime, the number of pages that can be locked or unlocked at once depends on the region size of the flash. The user can get the real number from the function return value, which can be different for the different devices.

Example of Usage

The following shows a simple example of using the Flash. The Flash driver must have been initialized by flash_init. This initialization will configure the operation of the hardware Flash instance.

The example writes one page size of data into flash and read it back.

          static uint8_t src_data[128];
          static uint8_t chk_data[128];
          /**
           * Example of using FLASH_0 to read and write buffer.
           */
          void FLASH_0_example(void)
          {
              uint32_t page_size;
              uint16_t i;
              /* Init source data */
              page_size = flash_get_page_size(&FLASH_0);
              for (i = 0; i < page_size; i++) {
                  src_data[i] = i;
              }
              /* Write data to flash */
              flash_write(&FLASH_0, 0x3200, src_data, page_size);
              /* Read data from flash */
              flash_read(&FLASH_0, 0x3200, chk_data, page_size);
          }
        

Dependencies

  • Non-Volatile Memory (NVM) peripheral and clocks