Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions drivers/flash/soc_flash_nrf_rram.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ LOG_MODULE_REGISTER(flash_nrf_rram, CONFIG_FLASH_LOG_LEVEL);
#define ERASE_VALUE 0xFF
#define WRITE_LINE_SIZE WRITE_BLOCK_SIZE_FROM_DT

static volatile bool write_busy;

static inline bool is_aligned_32(uint32_t data)
{
return (data & 0x3) ? false : true;
Expand Down Expand Up @@ -88,6 +90,18 @@ static int nrf_rram_read(const struct device *dev, off_t addr, void *data, size_
return 0;
}

void rrw_done(void)
{
uint32_t pm = __get_PRIMASK();

__disable_irq();
write_busy = false;
if (!pm) {
__enable_irq();
}
barrier_dmem_fence_full(); /* Barrier following our last write. */
}

static int nrf_rram_write(const struct device *dev, off_t addr, const void *data, size_t len)
{
int ret = 0;
Expand All @@ -113,6 +127,18 @@ static int nrf_rram_write(const struct device *dev, off_t addr, const void *data
return 0;
}

uint32_t pm = __get_PRIMASK();

__disable_irq();
if (write_busy) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be enough to use an atomic here instead of enabling/disabling the IRQs? By setting write_busy before calling sd_flash_write, the write event should not occur before it is set.
Also, I don't see where write_busy is set to true(?).

if (!pm) {
__enable_irq();
}
return -EBUSY;
}
if (!pm) {
__enable_irq();
}
LOG_DBG("Write: %p: %zu", (void *)addr, len);

ret = sd_flash_write((uint32_t *)addr, data, len / sizeof(uint32_t));
Expand All @@ -121,30 +147,6 @@ static int nrf_rram_write(const struct device *dev, off_t addr, const void *data
return -EIO;
}

while (1) {
int taskid;

/* Wait for an event. */
__WFE();

/* Clear Event Register */
__SEV();
__WFE();

ret = sd_evt_get(&taskid);

if (!ret && (taskid == NRF_EVT_FLASH_OPERATION_SUCCESS ||
taskid == NRF_EVT_FLASH_OPERATION_ERROR)) {
if (taskid != NRF_EVT_FLASH_OPERATION_SUCCESS) {
ret = -EIO;
}

break;
}
}

barrier_dmem_fence_full(); /* Barrier following our last write. */

return ret;
}

Expand Down
7 changes: 7 additions & 0 deletions subsys/softdevice_handler/nrf_sdh_soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const char *nrf_sdh_soc_evt_to_str(uint32_t evt)
}
}

void rrw_done(void);

static void soc_evt_poll(void *context)
{
uint32_t nrf_err;
Expand All @@ -64,6 +66,11 @@ static void soc_evt_poll(void *context)

LOG_DBG("%s", nrf_sdh_soc_evt_to_str(evt_id));

if (evt_id == NRF_EVT_FLASH_OPERATION_SUCCESS) {
#if defined(CONFIG_SOC_FLASH_NRF_RRAM_BM)
rrw_done();
#endif
}
Comment on lines +69 to +73
Copy link
Contributor

@eivindj-nordic eivindj-nordic Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this cannot be an HIGHESTprio NRF_SDH_SOC_OBSERVER in soc_flash_nrf_rram.c?

/* Forward the event to SoC observers. */
TYPE_SECTION_FOREACH(
struct nrf_sdh_soc_evt_observer, nrf_sdh_soc_evt_observers, obs) {
Expand Down
Loading