What are the APIs to access SPI FLASH Data Section?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi,

I am trying to access(read/write) the data section of the SPI FLASH (Not only SS) for a custom OTA development. Our ultimate requirement is have our own OTA mechanism with an access (read/write) to the upper 64KB of flash memory. Can any body suggest the APIs to access the SPI flash memory of 128Kbytes.   Is there any APIs with which we can read/write a SPI flash memory by mentioning the read/write address with the size as arguments.

Thanks and regards

Rajesh Kumar V

0 Likes
1 Solution
JacobT_81
Employee
Employee
250 replies posted 100 replies posted 50 replies posted

Hi rajeshwisilica

The following APIs, imported within bleappfwu.h, can be used to write/read/erase SFLASH:

/// Reads len bytes from readFrom  into buf (a caller owned buffer).
/// Bitwise OR in INDIRECT_MEM_MAP_SF the offset to read. For ex.

/// if you want to read from address 0x100, readFrom = (INDIRECT_MEM_MAP_SF | 0x100)

BOOL32 readMem(UINT8* buf, UINT32 readFrom, INT32 len);


/// Writes len bytes to writeTo  from buf (a caller owned buffer).

/// Bitwise OR in INDIRECT_MEM_MAP_SF the offset to write. For ex.

/// if you want to write to address 0x100, writeTo = (INDIRECT_MEM_MAP_SF | 0x100)

BOOL32 writeMem(const UINT8* buf, UINT32 writeTo, INT32 len);


/// Erases len bytes starting from eraseAddr.

/// Bitwise OR in INDIRECT_MEM_MAP_SF the address to erase. For ex.

/// if you want to erase 4K starting from 0x1000, eraseAddr = (INDIRECT_MEM_MAP_SF | 0x1000).

/// Note that len will be rounded up to a sector boundary.

BOOL32 eraseMem(UINT32 eraseAddr, INT32 len);

Please refer to WICED Smart BCM92073X EEPROM and SFLASH Layout for further information on memory allocation/layout when designing your OTA.

Jacob

View solution in original post

0 Likes
6 Replies
JacobT_81
Employee
Employee
250 replies posted 100 replies posted 50 replies posted

Hi rajeshwisilica

The following APIs, imported within bleappfwu.h, can be used to write/read/erase SFLASH:

/// Reads len bytes from readFrom  into buf (a caller owned buffer).
/// Bitwise OR in INDIRECT_MEM_MAP_SF the offset to read. For ex.

/// if you want to read from address 0x100, readFrom = (INDIRECT_MEM_MAP_SF | 0x100)

BOOL32 readMem(UINT8* buf, UINT32 readFrom, INT32 len);


/// Writes len bytes to writeTo  from buf (a caller owned buffer).

/// Bitwise OR in INDIRECT_MEM_MAP_SF the offset to write. For ex.

/// if you want to write to address 0x100, writeTo = (INDIRECT_MEM_MAP_SF | 0x100)

BOOL32 writeMem(const UINT8* buf, UINT32 writeTo, INT32 len);


/// Erases len bytes starting from eraseAddr.

/// Bitwise OR in INDIRECT_MEM_MAP_SF the address to erase. For ex.

/// if you want to erase 4K starting from 0x1000, eraseAddr = (INDIRECT_MEM_MAP_SF | 0x1000).

/// Note that len will be rounded up to a sector boundary.

BOOL32 eraseMem(UINT32 eraseAddr, INT32 len);

Please refer to WICED Smart BCM92073X EEPROM and SFLASH Layout for further information on memory allocation/layout when designing your OTA.

Jacob

0 Likes

Similar guidance was provided to him in the previous thread he created here: BCM20736S NVRAM functions for External I2C EEPROM Device (con't)

0 Likes
Anonymous
Not applicable

Hi jakewtorres

Thanks for the your responses.

Now am able to access the entire flash (read/write/erase). With the APIs I can access above 64KB (Tested only with 128KB sflash).

One other issue what I can observe is that the static segment data remains unchanged after API call bleappfwu_eraseMem().

Reading the erased area with API bleappfwu_readMem() shows the data remains unchanged.

Does there need any waiting time after flash erase?


Thanks and regards

Rajesh 

0 Likes
JacobT_81
Employee
Employee
250 replies posted 100 replies posted 50 replies posted

Hi rajeshwisilica,

There shouldn't be any need for a delay between erasing and writing SFLASH. In my test app I used the two API calls back to back with no problems.

Are you writing to SFLASH after booting from it? Or booting from EEPROM and writing SFLASH? It's possible that some sections are not accessible if you've booted from SFLASH.

Jacob

0 Likes
Anonymous
Not applicable

Hi Jacob,

I have booted from SFLASH and try to modify the same active Static Segment. But the same active static segment (40 bytes from 0x0000) is found not erased. The Same time i can see that the other Static segment got erased and written as expected.

Thanks

Rajesh

0 Likes
JacobT_81
Employee
Employee
250 replies posted 100 replies posted 50 replies posted

Hi rajeshwisilica,

I recommend testing this after booting from EEPROM. If it works after booting from EEPROM, you're likely being blocked by something internal to the API that restricts you from overwriting the source from which it booted.

I cannot be sure whether or not this can be worked around. One surefire way  would be to write your own driver for the SFLASH. Or if you were able to write the SS after booting from EEPROM, you could always have both attached to your chip and OTA upgrade back and forth between EEPROM and SFLASH and dynamically switch each on and off during boot using a switch.

Jacob

0 Likes