1 #include "Driver_Flash.h"
2 #include "cmsis_os2.h" // ARM::CMSIS:RTOS2:Keil RTX5
4 /* Flash driver instance */
5 extern ARM_DRIVER_FLASH Driver_Flash0;
6 static ARM_DRIVER_FLASH * flashDev = &Driver_Flash0;
8 /* CMSIS-RTOS2 Thread Id */
9 osThreadId_t Flash_Thread_Id;
11 /* Flash signal event */
12 void Flash_Callback(uint32_t event)
14 if (event & ARM_FLASH_EVENT_READY) {
15 /* The read/program/erase operation is completed */
16 osThreadFlagsSet(Flash_Thread_Id, 1U);
18 if (event & ARM_FLASH_EVENT_ERROR) {
19 /* The read/program/erase operation is completed with errors */
20 /* Call debugger or replace with custom error handling */
25 /* CMSIS-RTOS2 Thread */
26 void Flash_Thread (void *argument)
28 /* Query drivers capabilities */
29 const ARM_FLASH_CAPABILITIES capabilities = flashDev->GetCapabilities();
31 /* Initialize Flash device */
32 if (capabilities.event_ready) {
33 flashDev->Initialize (&Flash_Callback);
35 flashDev->Initialize (NULL);
38 /* Power-on Flash device */
39 flashDev->PowerControl (ARM_POWER_FULL);
41 /* Read data taking data_width into account */
43 flashDev->ReadData (0x1000U, buf, sizeof(buf)>>capabilities.data_width);
45 /* Wait operation to be completed */
46 if (capabilities.event_ready) {
47 osThreadFlagsWait (1U, osFlagsWaitAny, 100U);
52 /* Switch off gracefully */
53 flashDev->PowerControl (ARM_POWER_OFF);
54 flashDev->Uninitialize ();