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>
This commit is contained in:
Tahsin Mutlugun 2024-12-20 14:35:03 +03:00 committed by Fabio Baltieri
parent 1876f60f9f
commit 41f2be9e5f

View File

@ -52,9 +52,16 @@ static inline void max32_sem_give(const struct device *dev)
static int api_read(const struct device *dev, off_t address, void *buffer, size_t length)
{
const struct max32_flash_dev_config *const cfg = dev->config;
unsigned int key = 0;
address += cfg->flash_base;
key = irq_lock();
MXC_FLC_Read(address, buffer, length);
irq_unlock(key);
return 0;
}
@ -62,12 +69,18 @@ static int api_write(const struct device *dev, off_t address, const void *buffer
{
const struct max32_flash_dev_config *const cfg = dev->config;
int ret = 0;
unsigned int key = 0;
max32_sem_take(dev);
address += cfg->flash_base;
key = irq_lock();
ret = MXC_FLC_Write(address, length, (uint32_t *)buffer);
irq_unlock(key);
max32_sem_give(dev);
return ret != 0 ? -EIO : 0;
@ -79,9 +92,11 @@ static int api_erase(const struct device *dev, off_t start, size_t len)
uint32_t page_size = cfg->flash_erase_blk_sz;
uint32_t addr = (start + cfg->flash_base);
int ret = 0;
unsigned int key = 0;
max32_sem_take(dev);
key = irq_lock();
while (len) {
ret = MXC_FLC_PageErase(addr);
if (ret) {
@ -95,6 +110,7 @@ static int api_erase(const struct device *dev, off_t start, size_t len)
len = 0;
}
}
irq_unlock(key);
max32_sem_give(dev);