-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add feature Flash Memory Feature: - Add feature Flash Memory API Updates: - Add flash memory related API Misc: - Update keywords.txt files - Update library.properties files
- Loading branch information
Showing
30 changed files
with
454 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
Arduino_package/hardware/libraries/Debugging/library.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
Arduino_package/hardware/libraries/FileSystem/library.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
name=AmebaFileSystem | ||
version=1.0.0 | ||
author=Realtek | ||
maintainer=Realtek <[email protected]> | ||
sentence=Access FAT file systems located on SD cards connected to the SDIO bus. | ||
author=Realtek SG | ||
maintainer=Realtek SG | ||
sentence=Access FAT file systems located on SD cards connected to the SDIO bus | ||
paragraph= | ||
category= | ||
category=External Storage | ||
url= | ||
architectures=AmebaPro2 |
48 changes: 48 additions & 0 deletions
48
Arduino_package/hardware/libraries/FlashMemory/examples/ReadWriteStream/ReadWriteStream.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
This sketch shows how to request flash memory read/write stream word. | ||
Example guide: TBD | ||
*/ | ||
|
||
#include <FlashMemory.h> | ||
|
||
#define TEST_SIZE 0x1000 | ||
#define RESET_THRESHOLD 5 | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
|
||
FlashMemory.begin(FLASH_MEMORY_APP_BASE, TEST_SIZE); | ||
FlashMemory.read(); | ||
|
||
int i; | ||
if (FlashMemory.buf[0] >= RESET_THRESHOLD) { | ||
for (i = 0; i < TEST_SIZE; i++) { | ||
FlashMemory.buf[i] = 0x00; | ||
} | ||
FlashMemory.write(); | ||
Serial.print("Reset count to 0"); | ||
} else { | ||
for (i = 0; i < TEST_SIZE; i++) { | ||
FlashMemory.buf[i]++; | ||
} | ||
FlashMemory.write(); | ||
Serial.print("Boot count: "); | ||
|
||
for (i = 0; i < (TEST_SIZE - 1); i++) { | ||
if (FlashMemory.buf[i] != FlashMemory.buf[i + 1]) { | ||
Serial.print("error at "); | ||
Serial.print(i); | ||
Serial.print(" value "); | ||
break; | ||
} | ||
} | ||
Serial.println(FlashMemory.buf[i]); | ||
} | ||
} | ||
|
||
void loop() | ||
{ | ||
delay(1000); | ||
} |
47 changes: 47 additions & 0 deletions
47
Arduino_package/hardware/libraries/FlashMemory/examples/ReadWriteWord/ReadWriteWord.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
This sketch shows how to request flash memory read/write one specific word. | ||
Example guide: TBD | ||
*/ | ||
|
||
#include <FlashMemory.h> | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
|
||
unsigned int value; | ||
unsigned int check_value; | ||
|
||
/* request flash size 0x1000 from FLASH_MEMORY_APP_BASE */ | ||
FlashMemory.begin(FLASH_MEMORY_APP_BASE, 0x1000); | ||
|
||
/* read one word (32-bit) from FLASH_MEMORY_APP_BASE plus offset 0x1E00 */ | ||
value = FlashMemory.readWord(0x1E00); | ||
Serial.println(); | ||
Serial.print("Read value is "); | ||
Serial.println(value, HEX); | ||
|
||
if (value == 0xFFFFFFFF) { | ||
value = 0; | ||
} else { | ||
value++; | ||
} | ||
|
||
/* write one word (32-bit) to FLASH_MEMORY_APP_BASE plus offset 0x1F00 */ | ||
Serial.print("Write value is "); | ||
Serial.println(value, HEX); | ||
FlashMemory.writeWord(0x1E00, value); | ||
|
||
check_value = FlashMemory.readWord(0x1E00); | ||
if (check_value == value) { | ||
Serial.println("Success! Read and Write flash memory by word."); | ||
} else { | ||
Serial.println("Error! Read and Write flash memory by word."); | ||
} | ||
} | ||
|
||
void loop() | ||
{ | ||
delay(1000); | ||
} |
29 changes: 29 additions & 0 deletions
29
Arduino_package/hardware/libraries/FlashMemory/keywords.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
####################################### | ||
# Syntax Coloring Map for FlashMemory | ||
####################################### | ||
|
||
####################################### | ||
# Datatypes (KEYWORD1) | ||
####################################### | ||
|
||
FlashMemory KEYWORD1 | ||
|
||
####################################### | ||
# Methods and Functions (KEYWORD2) | ||
####################################### | ||
|
||
begin KEYWORD2 | ||
end KEYWORD2 | ||
read KEYWORD2 | ||
write KEYWORD2 | ||
readWord KEYWORD2 | ||
writeWord KEYWORD2 | ||
eraseSector KEYWORD2 | ||
eraseWord KEYWORD2 | ||
|
||
####################################### | ||
# Constants (LITERAL1) | ||
####################################### | ||
|
||
buf_size LITERAL1 | ||
buf LITERAL1 |
9 changes: 9 additions & 0 deletions
9
Arduino_package/hardware/libraries/FlashMemory/library.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name=AmebaFlashMemory | ||
version=1.0.0 | ||
author=Realtek SG | ||
maintainer=Realtek SG | ||
sentence=Flash memory lib that allows to eidt flash data | ||
paragraph= | ||
category=Storage | ||
url= | ||
architectures=AmebaPro2 |
162 changes: 162 additions & 0 deletions
162
Arduino_package/hardware/libraries/FlashMemory/src/FlashMemory.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
#include "FlashMemory.h" | ||
|
||
flash_t flash_obj; | ||
|
||
FlashMemoryClass::FlashMemoryClass() | ||
{ | ||
_flash_base_address = FLASH_MEMORY_APP_BASE; | ||
buf_size = MAX_FLASH_MEMORY_APP_SIZE; | ||
|
||
buf = (unsigned char *)(malloc(MAX_FLASH_MEMORY_APP_SIZE)); | ||
_pFlash = &flash_obj; | ||
} | ||
|
||
FlashMemoryClass::~FlashMemoryClass() | ||
{ | ||
if (buf != NULL) { | ||
free(buf); | ||
buf = NULL; | ||
} | ||
} | ||
|
||
void FlashMemoryClass::begin(unsigned int flash_base_address, unsigned int flash_buf_size) | ||
{ | ||
if (buf != NULL) { | ||
free(buf); | ||
buf = NULL; | ||
} | ||
|
||
if ((FLASH_MEMORY_APP_BASE <= flash_base_address) && (flash_base_address <= FLASH_MEMORY_SIZE)) { | ||
_flash_base_address = flash_base_address; | ||
} else { | ||
_flash_base_address = FLASH_MEMORY_APP_BASE; | ||
} | ||
|
||
if (flash_buf_size > MAX_FLASH_MEMORY_APP_SIZE) { | ||
buf_size = MAX_FLASH_MEMORY_APP_SIZE; | ||
} else { | ||
buf_size = flash_buf_size; | ||
} | ||
buf = (unsigned char *)(malloc(buf_size)); | ||
} | ||
|
||
void FlashMemoryClass::end() | ||
{ | ||
if (buf != NULL) { | ||
free(buf); | ||
buf = NULL; | ||
} | ||
} | ||
|
||
void FlashMemoryClass::read(unsigned int offset) | ||
{ | ||
if ((_flash_base_address + offset) < FLASH_MEMORY_APP_BASE) { | ||
printf("\r\n[ERROR] %s. Invalid offset \n", __FUNCTION__); | ||
return; | ||
} else if ((_flash_base_address + offset + buf_size) > FLASH_MEMORY_SIZE) { | ||
printf("\r\n[ERROR] %s. Invalid offset \n", __FUNCTION__); | ||
return; | ||
} | ||
|
||
flash_stream_read(_pFlash, (_flash_base_address + offset), buf_size, (uint8_t *)buf); | ||
} | ||
|
||
void FlashMemoryClass::write(unsigned int offset) | ||
{ | ||
if ((_flash_base_address + offset) < FLASH_MEMORY_APP_BASE) { | ||
printf("\r\n[ERROR] %s. Invalid offset \n", __FUNCTION__); | ||
return; | ||
} else if ((_flash_base_address + offset + buf_size) > FLASH_MEMORY_SIZE) { | ||
printf("\r\n[ERROR] %s. Invalid offset \n", __FUNCTION__); | ||
return; | ||
} | ||
|
||
for (int i = 0; i < (MAX_FLASH_MEMORY_APP_SIZE / FLASH_SECTOR_SIZE); i++) { | ||
flash_erase_sector(_pFlash, (_flash_base_address + (i * FLASH_SECTOR_SIZE))); | ||
} | ||
|
||
flash_stream_write(_pFlash, (_flash_base_address + offset), buf_size, (uint8_t *)buf); | ||
} | ||
|
||
unsigned int FlashMemoryClass::readWord(unsigned int offset) | ||
{ | ||
if ((_flash_base_address + offset) < FLASH_MEMORY_APP_BASE) { | ||
printf("\r\n[ERROR] %s. Invalid offset \n", __FUNCTION__); | ||
return 0; | ||
} else if ((_flash_base_address + offset) > (FLASH_MEMORY_SIZE - 4)) { | ||
printf("\r\n[ERROR] %s. Invalid offset \n", __FUNCTION__); | ||
return 0; | ||
} | ||
|
||
unsigned int value; | ||
|
||
flash_read_word(_pFlash, _flash_base_address + offset, (uint32_t *)&value); | ||
|
||
return value; | ||
} | ||
|
||
void FlashMemoryClass::writeWord(unsigned int offset, unsigned int data) | ||
{ | ||
if ((_flash_base_address + offset) < FLASH_MEMORY_APP_BASE) { | ||
printf("\r\n[ERROR] %s. Invalid offset \n", __FUNCTION__); | ||
return; | ||
} else if ((_flash_base_address + offset) > (FLASH_MEMORY_SIZE - 4)) { | ||
printf("\r\n[ERROR] %s. Invalid offset \n", __FUNCTION__); | ||
return; | ||
} | ||
|
||
unsigned int check_val; | ||
unsigned char *tmp_buf; | ||
unsigned int *tmp_val; | ||
unsigned int tmp_sector_adr; | ||
|
||
flash_write_word(_pFlash, _flash_base_address + offset, data); | ||
flash_read_word(_pFlash, _flash_base_address + offset, (uint32_t *)&check_val); | ||
|
||
if (check_val != data) { | ||
tmp_sector_adr = ((_flash_base_address + offset) / FLASH_SECTOR_SIZE) * FLASH_SECTOR_SIZE; | ||
tmp_buf = (unsigned char *)(malloc(FLASH_SECTOR_SIZE)); | ||
flash_stream_read(_pFlash, tmp_sector_adr, FLASH_SECTOR_SIZE, tmp_buf); | ||
flash_erase_sector(_pFlash, tmp_sector_adr); | ||
tmp_val = (unsigned int *)(tmp_buf + _flash_base_address + offset - tmp_sector_adr); | ||
*tmp_val = data; | ||
flash_stream_write(_pFlash, tmp_sector_adr, FLASH_SECTOR_SIZE, tmp_buf); | ||
free(tmp_buf); | ||
} | ||
} | ||
|
||
void FlashMemoryClass::eraseSector(unsigned int sector_offset) | ||
{ | ||
if ((sector_offset % FLASH_SECTOR_SIZE) != 0) { | ||
printf("\r\n[ERROR] %s. Invalid offset \n", __FUNCTION__); | ||
return; | ||
} | ||
|
||
flash_erase_sector(_pFlash, (_flash_base_address + sector_offset)); | ||
} | ||
|
||
void FlashMemoryClass::eraseWord(unsigned int offset) | ||
{ | ||
if ((_flash_base_address + offset) < FLASH_MEMORY_APP_BASE) { | ||
printf("\r\n[ERROR] %s. Invalid offset \n", __FUNCTION__); | ||
return; | ||
} else if ((_flash_base_address + offset) > (FLASH_MEMORY_SIZE - 4)) { | ||
printf("\r\n[ERROR] %s. Invalid offset \n", __FUNCTION__); | ||
return; | ||
} | ||
|
||
unsigned char *tmp_buf; | ||
unsigned int *tmp_val; | ||
unsigned int tmp_sector_adr; | ||
|
||
tmp_sector_adr = ((_flash_base_address + offset) / FLASH_SECTOR_SIZE) * FLASH_SECTOR_SIZE; | ||
tmp_buf = (unsigned char *)(malloc(FLASH_SECTOR_SIZE)); | ||
flash_stream_read(_pFlash, tmp_sector_adr, FLASH_SECTOR_SIZE, tmp_buf); | ||
flash_erase_sector(_pFlash, tmp_sector_adr); | ||
tmp_val = (unsigned int *)(tmp_buf + _flash_base_address + offset - tmp_sector_adr); | ||
*tmp_val = 0; | ||
flash_stream_write(_pFlash, tmp_sector_adr, FLASH_SECTOR_SIZE, tmp_buf); | ||
free(tmp_buf); | ||
} | ||
|
||
FlashMemoryClass FlashMemory = FlashMemoryClass(); |
Oops, something went wrong.