Skip to content

Commit c387fca

Browse files
niedzwiecki-dawidkartben
authored andcommitted
drivers: flash: stm32h7: fix compilation errors
There were some compilation errors caused by unused functions. Add proper #ifdef statements not to include unused functions. Signed-off-by: Dawid Niedzwiecki <[email protected]>
1 parent e3538a3 commit c387fca

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

drivers/flash/flash_stm32h7x.c

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ struct flash_stm32_sector_t {
6767
volatile uint32_t *sr;
6868
};
6969

70-
static __unused int commit_optb(const struct device *dev)
70+
#if defined(CONFIG_FLASH_STM32_READOUT_PROTECTION) || defined(CONFIG_FLASH_STM32_WRITE_PROTECT)
71+
72+
static int commit_optb(const struct device *dev)
7173
{
7274
FLASH_TypeDef *regs = FLASH_STM32_REGS(dev);
7375
int64_t timeout_time = k_uptime_get() + STM32H7_FLASH_OPT_TIMEOUT_MS;
@@ -87,8 +89,8 @@ static __unused int commit_optb(const struct device *dev)
8789
}
8890

8991
/* Returns negative value on error, 0 if a change was not need, 1 if a change has been made. */
90-
static __unused int write_opt(const struct device *dev, uint32_t mask, uint32_t value,
91-
uintptr_t cur, bool commit)
92+
static int write_opt(const struct device *dev, uint32_t mask, uint32_t value, uintptr_t cur,
93+
bool commit)
9294
{
9395
FLASH_TypeDef *regs = FLASH_STM32_REGS(dev);
9496
/* PRG register always follows CUR register. */
@@ -124,34 +126,17 @@ static __unused int write_opt(const struct device *dev, uint32_t mask, uint32_t
124126
return 1;
125127
}
126128

127-
static __unused int write_optsr(const struct device *dev, uint32_t mask, uint32_t value)
129+
#endif /* CONFIG_FLASH_STM32_WRITE_PROTECT || CONFIG_FLASH_STM32_READOUT_PROTECTION */
130+
131+
#if defined(CONFIG_FLASH_STM32_READOUT_PROTECTION)
132+
static int write_optsr(const struct device *dev, uint32_t mask, uint32_t value)
128133
{
129134
FLASH_TypeDef *regs = FLASH_STM32_REGS(dev);
130135
uintptr_t cur = (uintptr_t)regs + offsetof(FLASH_TypeDef, OPTSR_CUR);
131136

132137
return write_opt(dev, mask, value, cur, true);
133138
}
134139

135-
static __unused int write_optwp(const struct device *dev, uint32_t mask, uint32_t value,
136-
uint32_t bank)
137-
{
138-
FLASH_TypeDef *regs = FLASH_STM32_REGS(dev);
139-
uintptr_t cur = (uintptr_t)regs + offsetof(FLASH_TypeDef, WPSN_CUR1);
140-
141-
if (bank >= NUMBER_OF_BANKS) {
142-
return -EINVAL;
143-
}
144-
145-
#ifdef DUAL_BANK
146-
if (bank == 1) {
147-
cur = (uintptr_t)regs + offsetof(FLASH_TypeDef, WPSN_CUR2);
148-
}
149-
#endif /* DUAL_BANK */
150-
151-
return write_opt(dev, mask, value, cur, false);
152-
}
153-
154-
#if defined(CONFIG_FLASH_STM32_READOUT_PROTECTION)
155140
uint8_t flash_stm32_get_rdp_level(const struct device *dev)
156141
{
157142
FLASH_TypeDef *regs = FLASH_STM32_REGS(dev);
@@ -170,6 +155,24 @@ void flash_stm32_set_rdp_level(const struct device *dev, uint8_t level)
170155
#define WP_MSK FLASH_WPSN_WRPSN_Msk
171156
#define WP_POS FLASH_WPSN_WRPSN_Pos
172157

158+
static int write_optwp(const struct device *dev, uint32_t mask, uint32_t value, uint32_t bank)
159+
{
160+
FLASH_TypeDef *regs = FLASH_STM32_REGS(dev);
161+
uintptr_t cur = (uintptr_t)regs + offsetof(FLASH_TypeDef, WPSN_CUR1);
162+
163+
if (bank >= NUMBER_OF_BANKS) {
164+
return -EINVAL;
165+
}
166+
167+
#ifdef DUAL_BANK
168+
if (bank == 1) {
169+
cur = (uintptr_t)regs + offsetof(FLASH_TypeDef, WPSN_CUR2);
170+
}
171+
#endif /* DUAL_BANK */
172+
173+
return write_opt(dev, mask, value, cur, false);
174+
}
175+
173176
int flash_stm32_update_wp_sectors(const struct device *dev, uint64_t changed_sectors,
174177
uint64_t protected_sectors)
175178
{

0 commit comments

Comments
 (0)