spi_flash_write at address 0 (zero)

DarkSide
Posts: 29
Joined: Mon Apr 06, 2015 6:51 pm

spi_flash_write at address 0 (zero)

Postby DarkSide » Wed Jul 27, 2016 5:16 am

Hello,
Is it possible to write flash at address 0?
I want to update boot from my code, I using next code:

Code: Select all

static const uint8_t BOOT_DATA[] ICACHE_RODATA_ATTR STORE_ATTR = { ... };
spi_flash_erase_sector(0);
spi_flash_write(0, (uint32*)&BOOT_DATA, sizeof(BOOT_DATA));


but looks like spi_flash_write does not writing. Instead of correct data I have all zeroes (dumping flash content to file to check).
Any suggestions?

tobewinner
Posts: 45
Joined: Tue Jan 19, 2016 2:39 pm

Re: spi_flash_write at address 0 (zero)

Postby tobewinner » Wed Jul 27, 2016 12:20 pm

DarkSide wrote:Hello,
Is it possible to write flash at address 0?
I want to update boot from my code, I using next code:

Code: Select all

static const uint8_t BOOT_DATA[] ICACHE_RODATA_ATTR STORE_ATTR = { ... };
spi_flash_erase_sector(0);
spi_flash_write(0, (uint32*)&BOOT_DATA, sizeof(BOOT_DATA));


but looks like spi_flash_write does not writing. Instead of correct data I have all zeroes (dumping flash content to file to check).
Any suggestions?

Try

Code: Select all

spi_flash_write(0, (uint32*)BOOT_DATA, sizeof(BOOT_DATA));

DarkSide
Posts: 29
Joined: Mon Apr 06, 2015 6:51 pm

Re: spi_flash_write at address 0 (zero)

Postby DarkSide » Wed Jul 27, 2016 4:28 pm

Ok, figured out. To make it work, first it's needed to copy content of array in flash into variable in memory: This code write data as expected:

Code: Select all

uint32 *data = os_malloc(sizeof(BOOT_DATA));
os_memcpy(data, &BOOT_DATA, sizeof(BOOT_DATA));

/* copy current boot header code */

spi_flash_erase_sector(0);
spi_flash_write(0, data, sizeof(BOOT_DATA));

os_free(data);


Now boot is updating and work as expected.

Who is online

Users browsing this forum: No registered users and 15 guests