Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1
30
Ver.1.0.0
The correct formats should be:
u16 x = *(volatile u16*)0x808000;
// 0x808000 is 2-byte aligned
*(volatile u32*)0x808004 = 0x12345678;
// 0x808004 is 4-byte aligned
2.1.3.2 Flash Space Operation
Reading or writing
Flash space is implemented via functions
“flash_read_page” and
“flash_write_page”. Code of Flash erasing is available in “drivers/5316/flash.c” and
“flash.h”.
1) Flash read/write
F
unctions “flash_read_page” and “flash_write_page” serve to read or write Flash space
correspondingly.
void flash_read_page(u32 addr, u32 len, u8 *buf);
void flash_write_page(u32 addr, u32 len, u8 *buf)
Fla
sh read operation via “flash_read_page”:
void flash_read_page(u32 addr, u32 len, u8 *buf);
u8 data[6] = {0 };
flash_read_page(0x11000, 6, data); // read 6 bytes starting from 0x11000 in Flash
into a data array
Fl
ash write via “flash_write_page”:
flash_write_page(u32 addr, u32 len, u8 *buf);
u8 data[6] = {0x11,0x22,0x33,0x44,0x55,0x66 };
flash_write_page(0x12000, 6, data); // write 6-
byte data “0x665544332211” into
Flash starting from 0x12000
“flash_write_page” accesses pages in Flash. The maximum “len” for operations of
“flash_write_page” is 256 bytes, the size of one page. This function is not allowed to write
Flash space across two or more pages.
If the “addr” is the starting address of one page, the “len” cannot exceed 256 bytes.
flash_write_page (0x12000, 256, data) is correct. flash_write_page (0x12000, 257,
data) is incorrect as the final byte does not belong to the page where 0x12000 is,
and the write will fail.
If the “addr” is not the starting address of one page, the “len” cannot exceed the end
address of the page -
“addr” + 1. For example, flash_write_page (0x120f0, 20, data)
is incorrect as the first 16 bytes are in page of 0x12000 while the last 4 bytes are in
page of 0x12100.
“flash_read_page” can read data more than 256 bytes once. It’s allowed to read Flash
area across pages.
2) Flash erase operation
Use
function “flash_erase_sector” to erase Flash.
void flash_erase_sector(u32 addr);