ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
Loading...
Searching...
No Matches
cfg_flash_wb.c File Reference

cfg_store flash backend for the STM32WB55, safe with the BLE stack running on the CPU2 (AN5289, "Flash memory management"). More...

#include "cfg_store.h"
#include "main.h"
#include "cmsis_os2.h"
#include "hw_conf.h"
#include <string.h>
Include dependency graph for cfg_flash_wb.c:

Go to the source code of this file.

Macros

#define CFG_PAGE0_ADDR   0x0807E000u
 
#define CFG_PAGE_SIZE   0x1000u
 

Enumerations

enum  op_t { OP_ERASE , OP_PROGRAM }
 

Functions

const void * cfg_flash_page (int page)
 memory-mapped page
 
static int single_op (op_t op, uint32_t addr, uint64_t dw)
 
int cfg_flash_write (int page, const void *data, uint32_t len)
 erase + program; 0 = ok
 

Variables

volatile uint8_t g_cpu2_ready
 

Detailed Description

cfg_store flash backend for the STM32WB55, safe with the BLE stack running on the CPU2 (AN5289, "Flash memory management").

Pages: the last two 4 KB pages of the CPU1 application area, 0x0807E000 and 0x0807F000. The linker script keeps them out of FLASH (STM32WB55RGVX_FLASH.ld: FLASH LENGTH = 504K).

Every erase and every double-word program is one "single flash operation":

  1. take HSEM CFG_HW_FLASH_SEMID (flash controller shared by the 2 cores);
  2. with interrupts off, start the operation only if the CPU2 does not hold CFG_HW_BLOCK_FLASH_REQ_BY_CPU2_SEMID (radio timing-critical window); otherwise retry 1 ms later;
  3. release the HSEM. The CPU2 is told about the erase (SHCI_C2_FLASH_EraseActivity) and to use semaphore 7 (SHCI_C2_SetFlashActivityControl), only once the wireless stack is running (ble_tlm_svc_init() marks it).

Called only by the AppTask, only while disarmed: a page erase stalls the CPU1 for ~22 ms (the IMU FIFO absorbs it, the IWDG window is 500 ms).

Definition in file cfg_flash_wb.c.

Macro Definition Documentation

◆ CFG_PAGE0_ADDR

#define CFG_PAGE0_ADDR   0x0807E000u

Definition at line 36 of file cfg_flash_wb.c.

◆ CFG_PAGE_SIZE

#define CFG_PAGE_SIZE   0x1000u

Definition at line 37 of file cfg_flash_wb.c.

Enumeration Type Documentation

◆ op_t

enum op_t
Enumerator
OP_ERASE 
OP_PROGRAM 

Definition at line 47 of file cfg_flash_wb.c.

Function Documentation

◆ cfg_flash_page()

const void * cfg_flash_page ( int  page)

memory-mapped page

Definition at line 41 of file cfg_flash_wb.c.

References CFG_PAGE0_ADDR, CFG_PAGE_SIZE, and CFG_PAGES.

Referenced by cfg_flash_write(), cfg_load(), cfg_save(), and latest_page().

Here is the caller graph for this function:

◆ single_op()

static int single_op ( op_t  op,
uint32_t  addr,
uint64_t  dw 
)
static

Definition at line 49 of file cfg_flash_wb.c.

References addr(), OP_ERASE, and st().

Referenced by cfg_flash_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cfg_flash_write()

int cfg_flash_write ( int  page,
const void *  data,
uint32_t  len 
)

erase + program; 0 = ok

Definition at line 79 of file cfg_flash_wb.c.

References cfg_flash_page(), CFG_PAGE_SIZE, CFG_PAGES, g_cpu2_ready, off, OP_ERASE, OP_PROGRAM, and single_op().

Referenced by cfg_save().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ g_cpu2_ready

volatile uint8_t g_cpu2_ready

Definition at line 39 of file cfg_flash_wb.c.

Referenced by cfg_flash_write().