Skip to content

Commit a3359d6

Browse files
Merge pull request #4721 from marcuschangarm/flashiap_rtl8195am
REALTEK_RTL8195AM: FlashIAP read and address scope
2 parents 4b19e14 + 1930c4b commit a3359d6

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

targets/TARGET_Realtek/TARGET_AMEBA/flash_api.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
*/
1616
#include "flash_ext.h"
1717

18-
#define FLASH_START (SPI_FLASH_BASE + FLASH_OFS_START)
19-
#define FLASH_END (SPI_FLASH_BASE + FLASH_OFS_END)
20-
#define FLASH_OFS(addr) ((addr) - SPI_FLASH_BASE)
21-
2218
int32_t flash_init(flash_t *obj)
2319
{
2420
__flash_ext_turnon();
@@ -35,20 +31,25 @@ int32_t flash_free(flash_t *obj)
3531

3632
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
3733
{
38-
__flash_ext_erase_sector(obj, FLASH_OFS(address));
34+
flash_ext_erase_sector(obj, address);
3935

4036
return 0;
4137
}
4238

39+
int32_t flash_read(flash_t *obj, uint32_t address, uint8_t *data, uint32_t size)
40+
{
41+
return flash_ext_stream_read(obj, address, size, data);;
42+
}
43+
4344
int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size)
4445
{
45-
return __flash_ext_stream_write(obj, FLASH_OFS(address), size, data);
46+
return flash_ext_stream_write(obj, address, size, data);
4647
}
4748

4849
uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
4950
{
50-
if (address < FLASH_START || address >= FLASH_END)
51-
return 0;
51+
if (address >= FLASH_OFS_END)
52+
return MBED_FLASH_INVALID_SIZE;
5253

5354
return FLASH_SECTOR_SIZE;
5455
}
@@ -60,7 +61,7 @@ uint32_t flash_get_page_size(const flash_t *obj)
6061

6162
uint32_t flash_get_start_address(const flash_t *obj)
6263
{
63-
return FLASH_START;
64+
return FLASH_OFS_START;
6465
}
6566

6667
uint32_t flash_get_size(const flash_t *obj)

targets/TARGET_Realtek/TARGET_AMEBA/flash_ext.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ int flash_ext_stream_read(flash_t *obj, uint32_t addr, uint32_t len, uint8_t *da
128128
__flash_ext_turnon();
129129

130130
SpicWaitWipDoneRefinedRtl8195A(flashobj.SpicInitPara);
131-
131+
132132
offset = addr & 0x03;
133133
addr = addr & ~0x03;
134134
pbuf = data;
@@ -189,13 +189,13 @@ int __flash_ext_stream_write(flash_t *obj, uint32_t addr, uint32_t len, const ui
189189
uint32_t i, offset, word;
190190
const uint8_t*pbuf;
191191
uint8_t *ptr;
192-
u8 flashtype = 0;
192+
u8 flashtype = 0;
193193

194194
offset = addr & 0x03;
195195
addr = addr & ~0x03;
196196
pbuf = data;
197197
flashtype = flashobj.SpicInitPara.flashtype;
198-
198+
199199
if (offset != 0) {
200200
word = HAL_READ32(SPI_FLASH_BASE, addr);
201201
ptr = (uint8_t *)&word + offset;
@@ -207,7 +207,7 @@ int __flash_ext_stream_write(flash_t *obj, uint32_t addr, uint32_t len, const ui
207207
}
208208
HAL_WRITE32(SPI_FLASH_BASE, addr, word);
209209
SpicWaitBusyDoneRtl8195A();
210-
210+
211211
if(flashtype == FLASH_MICRON){
212212
SpicWaitOperationDoneRtl8195A(flashobj.SpicInitPara);
213213
} else {
@@ -222,7 +222,7 @@ int __flash_ext_stream_write(flash_t *obj, uint32_t addr, uint32_t len, const ui
222222
((uint32_t)(*(pbuf+2)) << 16) | ((uint32_t)(*(pbuf+3)) << 24);
223223
HAL_WRITE32(SPI_FLASH_BASE, addr, word);
224224
SpicWaitBusyDoneRtl8195A();
225-
225+
226226
if(flashtype == FLASH_MICRON){
227227
SpicWaitOperationDoneRtl8195A(flashobj.SpicInitPara);
228228
} else {
@@ -237,7 +237,7 @@ int __flash_ext_stream_write(flash_t *obj, uint32_t addr, uint32_t len, const ui
237237
while (len >= 4) {
238238
HAL_WRITE32(SPI_FLASH_BASE, addr, (uint32_t)*((uint32_t *)pbuf));
239239
SpicWaitBusyDoneRtl8195A();
240-
240+
241241
if(flashtype == FLASH_MICRON){
242242
SpicWaitOperationDoneRtl8195A(flashobj.SpicInitPara);
243243
} else {
@@ -260,7 +260,7 @@ int __flash_ext_stream_write(flash_t *obj, uint32_t addr, uint32_t len, const ui
260260

261261
HAL_WRITE32(SPI_FLASH_BASE, addr, word);
262262
SpicWaitBusyDoneRtl8195A();
263-
263+
264264
if(flashtype == FLASH_MICRON){
265265
SpicWaitOperationDoneRtl8195A(flashobj.SpicInitPara);
266266
} else {
@@ -271,7 +271,7 @@ int __flash_ext_stream_write(flash_t *obj, uint32_t addr, uint32_t len, const ui
271271
return 0;
272272
}
273273

274-
int flash_ext_stream_write(flash_t *obj, uint32_t addr, uint32_t len, uint8_t *data)
274+
int flash_ext_stream_write(flash_t *obj, uint32_t addr, uint32_t len, const uint8_t *data)
275275
{
276276
int32_t status;
277277

@@ -287,7 +287,7 @@ int flash_stream_read(flash_t *obj, uint32_t addr, uint32_t len, uint8_t *data)
287287
return flash_ext_stream_read(obj, addr, len, data);
288288
}
289289

290-
int flash_stream_write(flash_t *obj, uint32_t addr, uint32_t len, uint8_t *data)
290+
int flash_stream_write(flash_t *obj, uint32_t addr, uint32_t len, const uint8_t *data)
291291
{
292292
return flash_ext_stream_write(obj, addr, len, data);
293293
}
@@ -308,7 +308,7 @@ Users can use either of functions depending on their needs.
308308
*/
309309

310310
int flash_ext_burst_write(flash_t *obj, uint32_t address ,uint32_t length, uint8_t *data)
311-
{
311+
{
312312
u32 OccuSize;
313313
u32 ProgramSize;
314314
u32 PageSize;
@@ -340,7 +340,7 @@ int flash_ext_burst_write(flash_t *obj, uint32_t address ,uint32_t length, uint8
340340
}
341341

342342
address += ProgramSize;
343-
data += ProgramSize;
343+
data += ProgramSize;
344344
length -= ProgramSize;
345345
OccuSize = 0;
346346
} else{
@@ -435,7 +435,7 @@ This function aims to reset the status register, please make sure the operation
435435
void flash_ext_reset_status(flash_t *obj)
436436
{
437437
__flash_ext_turnon();
438-
SpicSetFlashStatusRefinedRtl8195A(0, flashobj.SpicInitPara);
438+
SpicSetFlashStatusRefinedRtl8195A(0, flashobj.SpicInitPara);
439439
SpicWaitWipDoneRefinedRtl8195A(flashobj.SpicInitPara);
440440
__flash_ext_turnoff();
441441
}

targets/TARGET_Realtek/TARGET_AMEBA/flash_ext.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ extern "C" {
2525

2626
#define FLASH_PAGE_SIZE 256
2727
#define FLASH_SIZE 0x100000
28-
#define FLASH_OFS_START 0xc0000
28+
#define FLASH_OFS_START 0x0
2929
#define FLASH_OFS_END (FLASH_OFS_START + FLASH_SIZE)
3030

3131
extern void flash_ext_erase_sector(flash_t *obj, uint32_t address);
3232
extern void flash_ext_erase_block(flash_t * obj, uint32_t address);
33-
extern int flash_ext_read_word(flash_t *obj, uint32_t address, uint32_t * data);
33+
extern int flash_ext_read_word(flash_t *obj, uint32_t address, uint32_t *data);
3434
extern int flash_ext_write_word(flash_t *obj, uint32_t address, uint32_t data);
35-
extern int flash_ext_stream_read(flash_t *obj, uint32_t address, uint32_t len, uint8_t * data);
36-
extern int flash_ext_stream_write(flash_t *obj, uint32_t address, uint32_t len, uint8_t * data);
35+
extern int flash_ext_stream_read(flash_t *obj, uint32_t address, uint32_t len, uint8_t *data);
36+
extern int flash_ext_stream_write(flash_t *obj, uint32_t address, uint32_t len, const uint8_t *data);
3737
extern int flash_stream_read(flash_t *obj, uint32_t addr, uint32_t len, uint8_t *data);
38-
extern int flash_stream_write(flash_t *obj, uint32_t addr, uint32_t len, uint8_t *data);
38+
extern int flash_stream_write(flash_t *obj, uint32_t addr, uint32_t len, const uint8_t *data);
3939
extern void flash_ext_write_protect(flash_t *obj, uint32_t protect);
4040
extern int flash_ext_get_status(flash_t *obj);
4141
extern int flash_ext_set_status(flash_t *obj, uint32_t data);

0 commit comments

Comments
 (0)