Skip to content

Commit f15f9df

Browse files
str4t0mcfriedt
authored andcommitted
flash: stm32: fix g0 error flags and move ifdef-ery to header
In STM32G0 HAL FLASH_FLAG_xxx defines don't follow the pattern of other Series to simply redefine the FLASH_SR_xxx Msk. Instead an ID for the SR reg and the position of the Error flag are defined. As a result error checking in flash_stm32_check_status was not working until this fix on stm32g0 series. In order to avoid complexity in the driver, the ifdef-ery of the flags was moved to the header file. Other series except g0 use FLASH_FLAG_xxx defines, because those are valid for both cores in dual core(wl) and in secure/non-secure targets(l5,u5). FLASH_STM32_SR_ERRORS mask is introduced to check for any active error in the SR. The flags for SIZERR, MISERR, FASTERR are newly introduced. the latter two are only required once fast programming is used, which is not yet the case for any series. The FLASH_SR_OPTVERR flag (option validity flag) is also present in the SR, but is not added. Also ecc errors are generally not checked, but these are in a different register. Signed-off-by: Thomas Stranger <[email protected]>
1 parent 519f5ff commit f15f9df

File tree

2 files changed

+103
-26
lines changed

2 files changed

+103
-26
lines changed

drivers/flash/flash_stm32.c

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,33 +78,11 @@ static inline void _flash_stm32_sem_give(const struct device *dev)
7878
#if !defined(CONFIG_SOC_SERIES_STM32WBX)
7979
static int flash_stm32_check_status(const struct device *dev)
8080
{
81-
uint32_t const error =
82-
#if defined(FLASH_FLAG_PGAERR)
83-
FLASH_FLAG_PGAERR |
84-
#endif
85-
#if defined(FLASH_FLAG_RDERR)
86-
FLASH_FLAG_RDERR |
87-
#endif
88-
#if defined(FLASH_FLAG_PGPERR)
89-
FLASH_FLAG_PGPERR |
90-
#endif
91-
#if defined(FLASH_FLAG_PGSERR)
92-
FLASH_FLAG_PGSERR |
93-
#endif
94-
#if defined(FLASH_FLAG_OPERR)
95-
FLASH_FLAG_OPERR |
96-
#endif
97-
#if defined(FLASH_FLAG_PROGERR)
98-
FLASH_FLAG_PROGERR |
99-
#endif
100-
#if defined(FLASH_FLAG_PGERR)
101-
FLASH_FLAG_PGERR |
102-
#endif
103-
FLASH_FLAG_WRPERR;
10481

105-
if (FLASH_STM32_REGS(dev)->FLASH_STM32_SR & error) {
106-
LOG_DBG("Status: 0x%08x",
107-
FLASH_STM32_REGS(dev)->FLASH_STM32_SR & error);
82+
if (FLASH_STM32_REGS(dev)->FLASH_STM32_SR & FLASH_STM32_SR_ERRORS) {
83+
LOG_DBG("Status: 0x%08lx",
84+
FLASH_STM32_REGS(dev)->FLASH_STM32_SR &
85+
FLASH_STM32_SR_ERRORS);
10886
return -EIO;
10987
}
11088

drivers/flash/flash_stm32.h

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,105 @@ struct flash_stm32_priv {
5959
#define FLASH_STM32_SR_BUSY (FLASH_FLAG_BSY)
6060
#endif
6161

62+
#if defined(CONFIG_SOC_SERIES_STM32G0X)
63+
/* STM32G0 HAL FLASH_FLAG_x don't represent bit-masks, need FLASH_SR_x instead */
64+
#define FLASH_STM32_SR_OPERR FLASH_SR_OPERR
65+
#define FLASH_STM32_SR_PGERR 0
66+
#define FLASH_STM32_SR_PROGERR FLASH_SR_PROGERR
67+
#define FLASH_STM32_SR_WRPERR FLASH_SR_WRPERR
68+
#define FLASH_STM32_SR_PGAERR FLASH_SR_PGAERR
69+
#define FLASH_STM32_SR_SIZERR FLASH_SR_SIZERR
70+
#define FLASH_STM32_SR_PGSERR FLASH_SR_PGSERR
71+
#define FLASH_STM32_SR_MISERR FLASH_SR_MISERR
72+
#define FLASH_STM32_SR_FASTERR FLASH_SR_FASTERR
73+
#if defined(FLASH_SR_RDERR)
74+
#define FLASH_STM32_SR_RDERR FLASH_SR_RDERR
75+
#else
76+
#define FLASH_STM32_SR_RDERR 0
77+
#endif
78+
#define FLASH_STM32_SR_PGPERR 0
79+
80+
#else /* !defined(CONFIG_SOC_SERIES_STM32G0X) */
81+
#if defined(FLASH_FLAG_OPERR)
82+
#define FLASH_STM32_SR_OPERR FLASH_FLAG_OPERR
83+
#else
84+
#define FLASH_STM32_SR_OPERR 0
85+
#endif
86+
87+
#if defined(FLASH_FLAG_PGERR)
88+
#define FLASH_STM32_SR_PGERR FLASH_FLAG_PGERR
89+
#else
90+
#define FLASH_STM32_SR_PGERR 0
91+
#endif
92+
93+
#if defined(FLASH_FLAG_PROGERR)
94+
#define FLASH_STM32_SR_PROGERR FLASH_FLAG_PROGERR
95+
#else
96+
#define FLASH_STM32_SR_PROGERR 0
97+
#endif
98+
99+
#if defined(FLASH_FLAG_WRPERR)
100+
#define FLASH_STM32_SR_WRPERR FLASH_FLAG_WRPERR
101+
#else
102+
#define FLASH_STM32_SR_WRPERR 0
103+
#endif
104+
105+
#if defined(FLASH_FLAG_PGAERR)
106+
#define FLASH_STM32_SR_PGAERR FLASH_FLAG_PGAERR
107+
#else
108+
#define FLASH_STM32_SR_PGAERR 0
109+
#endif
110+
111+
#if defined(FLASH_FLAG_SIZERR)
112+
#define FLASH_STM32_SR_SIZERR FLASH_FLAG_SIZERR
113+
#else
114+
#define FLASH_STM32_SR_SIZERR 0
115+
#endif
116+
117+
#if defined(FLASH_FLAG_PGSERR)
118+
#define FLASH_STM32_SR_PGSERR FLASH_FLAG_PGSERR
119+
#else
120+
#define FLASH_STM32_SR_PGSERR 0
121+
#endif
122+
123+
#if defined(FLASH_FLAG_MISERR)
124+
#define FLASH_STM32_SR_MISERR FLASH_FLAG_MISERR
125+
#else
126+
#define FLASH_STM32_SR_MISERR 0
127+
#endif
128+
129+
#if defined(FLASH_FLAG_FASTERR)
130+
#define FLASH_STM32_SR_FASTERR FLASH_FLAG_FASTERR
131+
#else
132+
#define FLASH_STM32_SR_FASTERR 0
133+
#endif
134+
135+
#if defined(FLASH_FLAG_RDERR)
136+
#define FLASH_STM32_SR_RDERR FLASH_FLAG_RDERR
137+
#else
138+
#define FLASH_STM32_SR_RDERR 0
139+
#endif
140+
141+
#if defined(FLASH_FLAG_PGPERR)
142+
#define FLASH_STM32_SR_PGPERR FLASH_FLAG_PGPERR
143+
#else
144+
#define FLASH_STM32_SR_PGPERR 0
145+
#endif
146+
147+
#endif /* !defined(CONFIG_SOC_SERIES_STM32G0X) */
148+
149+
#define FLASH_STM32_SR_ERRORS (FLASH_STM32_SR_OPERR | \
150+
FLASH_STM32_SR_PGERR | \
151+
FLASH_STM32_SR_PROGERR | \
152+
FLASH_STM32_SR_WRPERR | \
153+
FLASH_STM32_SR_PGAERR | \
154+
FLASH_STM32_SR_SIZERR | \
155+
FLASH_STM32_SR_PGSERR | \
156+
FLASH_STM32_SR_MISERR | \
157+
FLASH_STM32_SR_FASTERR | \
158+
FLASH_STM32_SR_RDERR | \
159+
FLASH_STM32_SR_PGPERR)
160+
62161

63162
#ifdef CONFIG_FLASH_PAGE_LAYOUT
64163
static inline bool flash_stm32_range_exists(const struct device *dev,

0 commit comments

Comments
 (0)