Skip to content

Commit 79fa066

Browse files
dgarskedanielinux
authored andcommitted
Fix for the STM32 internal flash erase page selection mask (some variants have larger sizes)
1 parent c02c273 commit 79fa066

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

hal/stm32c0.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@
9595
#define FLASH_CR_PG (1 << 0) /* RM0490 - 3.7.5 - FLASH_CR */
9696
#define FLASH_CR_SEC_PROT (1 << 28) /* RM0490 - 3.7.5 - FLASH_CR */
9797

98-
#define FLASH_CR_PNB_SHIFT 3 /* RM0490 - 3.7.5 - FLASH_CR - PNB bits 8:3 */
99-
#define FLASH_CR_PNB_MASK 0x3f /* RM0490 - 3.7.5 - FLASH_CR - PNB bits 8:3 - 6 bits */
98+
#define FLASH_CR_PNB_SHIFT 3 /* RM0490 - 4.7.5 - FLASH_CR - PNB bits 9:3 */
99+
#define FLASH_CR_PNB_MASK 0x7f /* RM0490 - 4.7.5 - FLASH_CR - PNB bits 9:3 - 7 bits */
100100

101101
#define FLASH_SECR_SEC_SIZE_POS (0U)
102102
#define FLASH_SECR_SEC_SIZE_MASK (0xFF)

hal/stm32g0.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787
#define FLASH_CR_PG (1 << 0) /* RM0444 - 3.7.5 - FLASH_CR */
8888
#define FLASH_CR_SEC_PROT (1 << 28) /* RM0444 - 3.7.5 - FLASH_CR */
8989

90-
#define FLASH_CR_PNB_SHIFT 3 /* RM0444 - 3.7.5 - FLASH_CR - PNB bits 8:3 */
91-
#define FLASH_CR_PNB_MASK 0x3f /* RM0444 - 3.7.5 - FLASH_CR - PNB bits 8:3 - 6 bits */
90+
#define FLASH_CR_PNB_SHIFT 3 /* RM0444 - 3.7.5 - FLASH_CR - PNB bits 9:3 */
91+
#define FLASH_CR_PNB_MASK 0x7f /* RM0444 - 3.7.5 - FLASH_CR - PNB bits 9:3 - 7 bits */
9292

9393
#define FLASH_SECR_SEC_SIZE_POS (0U)
9494
#define FLASH_SECR_SEC_SIZE_MASK (0xFF)

hal/stm32h5.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@
302302
#define FLASH_CR_BER (1 << 3)
303303
#define FLASH_CR_FW (1 << 4)
304304
#define FLASH_CR_STRT (1 << 5)
305+
/* Page number selection:
306+
* Up to 31 pages: H523/33xx
307+
* Up to 127 pages: All others
308+
*/
305309
#define FLASH_CR_PNB_SHIFT 6
306310
#define FLASH_CR_PNB_MASK 0x7F
307311
#define FLASH_CR_MER (1 << 15)

hal/stm32l5.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
#define FLASH_CR_PER (1 << 1)
204204
#define FLASH_CR_MER1 (1 << 2)
205205
#define FLASH_CR_PNB_SHIFT 3
206-
#define FLASH_CR_PNB_MASK 0x7F
206+
#define FLASH_CR_PNB_MASK 0x7F /* up to 127 pages */
207207
#define FLASH_CR_BKER (1 << 11)
208208
#define FLASH_CR_MER2 (1 << 15)
209209
#define FLASH_CR_STRT (1 << 16)

hal/stm32u5.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,13 @@
209209
#define FLASH_CR_PG (1 << 0)
210210
#define FLASH_CR_PER (1 << 1)
211211
#define FLASH_CR_MER1 (1 << 2)
212+
/* Page number selection:
213+
* Up to 31 pages: U535/U545
214+
* Up to 127 pages: U575/U585
215+
* Up to 255 pages: U59x/5Ax/5Fx/5Gx
216+
*/
212217
#define FLASH_CR_PNB_SHIFT 3
213-
#define FLASH_CR_PNB_MASK 0x7F
218+
#define FLASH_CR_PNB_MASK 0xFF /* support up to 255 pages */
214219
#define FLASH_CR_BKER (1 << 11)
215220
#define FLASH_CR_MER2 (1 << 15)
216221
#define FLASH_CR_STRT (1 << 16)

0 commit comments

Comments
 (0)