37 #include <libopencm3/stm32/flash.h>
38 #include <libopencm3/stm32/crc.h>
39 #include <libopencm3/stm32/dbgmcu.h>
57 #define FLASH_SIZE_ MMIO16(0x1FFFF7E0)
58 #elif defined(STM32F4)
59 #define FLASH_SIZE_ MMIO16(0x1FFF7A22)
62 #define FLASH_BEGIN 0x08000000
72 CRC_CR = CRC_CR_RESET;
76 for (i = 0; i < (size & ~3); i += 4) {
77 CRC_DR = (*(
uint8_t *)(ptr + i)) |
78 (*(
uint8_t *)(ptr + i + 1)) << 8 |
79 (*(
uint8_t *)(ptr + i + 2)) << 16 |
80 (*(
uint8_t *)(ptr + i + 3)) << 24;
84 for (i = 0; i < (size & ~3); i += 4) {
95 CRC_DR = (*(
uint8_t *)(ptr + i)) |
96 (*(
uint8_t *)(ptr + i + 1)) << 8;
99 CRC_DR = (*(
uint8_t *)(ptr + i)) |
100 (*(
uint8_t *)(ptr + i + 1)) << 8 |
101 (*(
uint8_t *)(ptr + i + 2)) << 16;
144 default: {
return -1;}
147 #elif defined(STM32F4)
151 device_id = DBGMCU_IDCODE & DBGMCU_IDCODE_DEV_ID_MASK;
195 #error Unknown device
201 #elif defined(STM32F4)
220 flash_erase_page(flash->
addr);
221 #elif defined(STM32F4)
222 flash_erase_sector(flash->
page_nr, FLASH_CR_PROGRAM_X32);
227 for (i = 0; i < flash->
page_size; i += 4) {
228 if ((*(
uint32_t *)(flash->
addr + i)) != 0xFFFFFFFF) {
return -1; }
248 for (i = 0; i < (size & ~1); i += 2) {
249 flash_program_half_word(flash->
addr + i,
265 (
uint16_t)((chksum >> 16) & 0xFFFF));
269 for (i = 0; i < size; i++) {
282 if ((size > flash_info.
page_size -
FSIZ) || (size == 0)) {
return -2; }
297 if ((size > flash.
page_size -
FSIZ) || (size == 0)) {
return -2; }
307 for (i = 0; i < size; i++) {
int32_t persistent_write(void *ptr, uint32_t size)
int32_t persistent_read(void *ptr, uint32_t size)
int32_t persistent_clear(void)
Persistent settings interface.
static uint32_t pflash_checksum(uint32_t ptr, uint32_t size)
static int32_t pflash_program_bytes(struct FlashInfo *flash, uint32_t src, uint32_t size, uint32_t chksum)
static int32_t flash_detect(struct FlashInfo *flash)
static int32_t pflash_erase(struct FlashInfo *flash)
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.