Skip to content

Commit

Permalink
drivers: flash_sam: fix flash_sam_write_page
Browse files Browse the repository at this point in the history
According to Atmel SAM datasheet when writing data to the latch buffer
"32-bit words must be written continuously, in either ascending or
descending order. Writing the latch buffer in a random order is not
permitted." To enforce the requirement we need to call a memory barrier
instruction after copying every word of data to the latch buffer. In
the absensce of __DSB() call the ARM processor is free to change order
of AHB transfers. This has caused the driver to occasionally corrupt
data programmed in the flash.

Fixes zephyrproject-rtos#37515

Signed-off-by: Piotr Mienkowski <[email protected]>
  • Loading branch information
mnkp authored and cfriedt committed Aug 11, 2021
1 parent 9e0acf3 commit 6c69923
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/flash/flash_sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ static int flash_sam_write_page(const struct device *dev, off_t offset,
/* We need to copy the data using 32-bit accesses */
for (; len > 0; len -= sizeof(*src)) {
*dst++ = *src++;
/* Assure data are written to the latch buffer consecutively */
__DSB();
}
__DSB();

/* Trigger the flash write */
efc->EEFC_FCR = EEFC_FCR_FKEY_PASSWD |
Expand Down

0 comments on commit 6c69923

Please sign in to comment.