Skip to content

Commit ecc9fee

Browse files
committed
drivers: flash: max32: Disable interrupts before accessing flash
Disable interrupts during flash operations to prevent unintended jumps. Interrupts are now disabled before read, erase, and write operations to avoid accidental jumps to other flash sections while working on a specific section. Signed-off-by: Tahsin Mutlugun <Tahsin.Mutlugun@analog.com>
1 parent f862069 commit ecc9fee

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

drivers/flash/flash_max32.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,35 @@ static inline void max32_sem_give(const struct device *dev)
5252
static int api_read(const struct device *dev, off_t address, void *buffer, size_t length)
5353
{
5454
const struct max32_flash_dev_config *const cfg = dev->config;
55+
unsigned int key = 0;
5556

5657
address += cfg->flash_base;
58+
59+
key = irq_lock();
60+
5761
MXC_FLC_Read(address, buffer, length);
62+
63+
irq_unlock(key);
64+
5865
return 0;
5966
}
6067

6168
static int api_write(const struct device *dev, off_t address, const void *buffer, size_t length)
6269
{
6370
const struct max32_flash_dev_config *const cfg = dev->config;
6471
int ret = 0;
72+
unsigned int key = 0;
6573

6674
max32_sem_take(dev);
6775

6876
address += cfg->flash_base;
77+
78+
key = irq_lock();
79+
6980
ret = MXC_FLC_Write(address, length, (uint32_t *)buffer);
7081

82+
irq_unlock(key);
83+
7184
max32_sem_give(dev);
7285

7386
return ret != 0 ? -EIO : 0;
@@ -79,9 +92,11 @@ static int api_erase(const struct device *dev, off_t start, size_t len)
7992
uint32_t page_size = cfg->flash_erase_blk_sz;
8093
uint32_t addr = (start + cfg->flash_base);
8194
int ret = 0;
95+
unsigned int key = 0;
8296

8397
max32_sem_take(dev);
8498

99+
key = irq_lock();
85100
while (len) {
86101
ret = MXC_FLC_PageErase(addr);
87102
if (ret) {
@@ -95,6 +110,7 @@ static int api_erase(const struct device *dev, off_t start, size_t len)
95110
len = 0;
96111
}
97112
}
113+
irq_unlock(key);
98114

99115
max32_sem_give(dev);
100116

0 commit comments

Comments
 (0)