4. Analyzing The Demonstration Example
This section analyzes an application example which demonstrates using the NVMS adapters. The example is based on the freertos_retarget sample code found in the SDK. It adds an additional freeRTOS task which is responsible for various NVMS operations and enables the wake-up timer for handling external events.
4.1. Application Structure
The very first time the
prvFLASH_Tasktask is executed, the NVMS adapters are initialized as well as an NVMS write operation is performed. In specific, the task attempts to write 1024 bytes of data in the
NVMS_LOG_PARTFLASH partition, starting from the relative address zero.
The key goal of this demonstration is for the device to perform a few NVMS operations following an event. For demonstration purposes, the button K1 on the Pro Devkit has been configured as a wake-up input pin. For more detailed information on how to configure and set a pin for handling external events, read the External Interruption tutorial. At each external event, produced at every K1 button press, a dedicated callback function named
wkup_cb()is triggered. In this function, a freeRTOS signal named
signal_FLASHis sent towards the
prvFLASH_Taskapplication task to unblock its execution.
This application task calls the
FLASH_reader()routine which attempts to read a chunk of 64 bytes from the
NVMS_LOG_PARTFLASH partition, starting from the relative address zero (given the Flash model used this corresponds to the physical address 0x200000). Following a successful read operation, the read data is printed on the serial console and the pointer that points to the current location in the aforementioned partition entry is incremented so that it points to the right next chunk of 64 bytes. Otherwise, a debugging message indicating the failure of the current NVMS operation is printed on the console.
It is essential for the system to enter the idle mode, that is, all the application tasks are either blocked or suspended. By default, the Background Options mechanism is enabled allowing the execution of NVMS related operations only when the system is idle.