From 8a15cec6bf99f59065879a14895fb8af8a8a53e7 Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Wed, 17 Dec 2014 15:22:15 +0000 Subject: [PATCH] stm32: f4: flash: support extended sector ranges F42xx and F43xx have extended sector ranges. Reported-by: H2OBrain@irc --- include/libopencm3/stm32/common/flash_common_f24.h | 14 ++------------ lib/stm32/common/flash_common_f24.c | 8 ++++---- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/include/libopencm3/stm32/common/flash_common_f24.h b/include/libopencm3/stm32/common/flash_common_f24.h index f4495b8c..79b1d248 100644 --- a/include/libopencm3/stm32/common/flash_common_f24.h +++ b/include/libopencm3/stm32/common/flash_common_f24.h @@ -74,18 +74,8 @@ #define FLASH_CR_MER (1 << 2) #define FLASH_CR_SER (1 << 1) #define FLASH_CR_PG (1 << 0) -#define FLASH_CR_SECTOR_0 (0x00 << 3) -#define FLASH_CR_SECTOR_1 (0x01 << 3) -#define FLASH_CR_SECTOR_2 (0x02 << 3) -#define FLASH_CR_SECTOR_3 (0x03 << 3) -#define FLASH_CR_SECTOR_4 (0x04 << 3) -#define FLASH_CR_SECTOR_5 (0x05 << 3) -#define FLASH_CR_SECTOR_6 (0x06 << 3) -#define FLASH_CR_SECTOR_7 (0x07 << 3) -#define FLASH_CR_SECTOR_8 (0x08 << 3) -#define FLASH_CR_SECTOR_9 (0x09 << 3) -#define FLASH_CR_SECTOR_10 (0x0a << 3) -#define FLASH_CR_SECTOR_11 (0x0b << 3) +#define FLASH_CR_SNB_SHIFT 3 +#define FLASH_CR_SNB_MASK 0x1f #define FLASH_CR_PROGRAM_X8 (0x00 << 8) #define FLASH_CR_PROGRAM_X16 (0x01 << 8) #define FLASH_CR_PROGRAM_X32 (0x02 << 8) diff --git a/lib/stm32/common/flash_common_f24.c b/lib/stm32/common/flash_common_f24.c index 03883fb7..29f2b9e1 100644 --- a/lib/stm32/common/flash_common_f24.c +++ b/lib/stm32/common/flash_common_f24.c @@ -351,7 +351,7 @@ first be fully erased before attempting to program it. See the reference manual or the FLASH programming manual for details. -@param[in] uint32_t sector (0 - 11). +@param[in] uint32_t sector (0 - 11 for some parts, 0-23 on others) @param program_size: 0 (8-bit), 1 (16-bit), 2 (32-bit), 3 (64-bit) */ @@ -360,14 +360,14 @@ void flash_erase_sector(uint8_t sector, uint32_t program_size) flash_wait_for_last_operation(); flash_set_program_size(program_size); - FLASH_CR &= ~(0xF << 3); - FLASH_CR |= (sector << 3) & 0x78; + FLASH_CR &= ~(FLASH_CR_SNB_MASK << FLASH_CR_SNB_SHIFT); + FLASH_CR |= (sector & FLASH_CR_SNB_MASK) << FLASH_CR_SNB_SHIFT; FLASH_CR |= FLASH_CR_SER; FLASH_CR |= FLASH_CR_STRT; flash_wait_for_last_operation(); FLASH_CR &= ~FLASH_CR_SER; - FLASH_CR &= ~(0xF << 3); + FLASH_CR &= ~(FLASH_CR_SNB_MASK << FLASH_CR_SNB_SHIFT); } /*---------------------------------------------------------------------------*/