【优化】stm32f10x flash 驱动。

Signed-off-by: armink <armink.ztl@gmail.com>
This commit is contained in:
armink 2019-01-31 23:16:47 +08:00
parent 45530c4799
commit a3947877d6
3 changed files with 13 additions and 9 deletions

View File

@ -71,12 +71,14 @@ EfErrCode ef_port_init(ef_env const **default_env, size_t *default_env_size) {
*/
EfErrCode ef_port_read(uint32_t addr, uint32_t *buf, size_t size) {
EfErrCode result = EF_NO_ERR;
uint8_t *buf_8 = (uint8_t *)buf;
size_t i;
EF_ASSERT(size % 4 == 0);
EF_ASSERT(addr % 4 == 0);
/*copy from flash to ram */
for (; size > 0; size -= 4, addr += 4, buf++) {
*buf = *(uint32_t *) addr;
for (i = 0; i < size; i++, addr ++, buf_8++) {
*buf_8 = *(uint8_t *) addr;
}
return result;
@ -136,7 +138,7 @@ EfErrCode ef_port_write(uint32_t addr, const uint32_t *buf, size_t size) {
size_t i;
uint32_t read_data;
EF_ASSERT(size % 4 == 0);
EF_ASSERT(addr % 4 == 0);
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);

View File

@ -112,7 +112,7 @@ int rt_application_init(void)
rt_thread_startup(&thread_sys_monitor);
init_thread = rt_thread_create("sys init", sys_init_thread,
NULL, 512, 10, 10);
NULL, 1024, 10, 10);
if (init_thread != NULL) {
rt_thread_startup(init_thread);
}

View File

@ -74,12 +74,14 @@ EfErrCode ef_port_init(ef_env const **default_env, size_t *default_env_size) {
*/
EfErrCode ef_port_read(uint32_t addr, uint32_t *buf, size_t size) {
EfErrCode result = EF_NO_ERR;
uint8_t *buf_8 = (uint8_t *)buf;
size_t i;
EF_ASSERT(size % 4 == 0);
EF_ASSERT(addr % 4 == 0);
/*copy from flash to ram */
for (; size > 0; size -= 4, addr += 4, buf++) {
*buf = *(uint32_t *) addr;
for (i = 0; i < size; i++, addr ++, buf_8++) {
*buf_8 = *(uint8_t *) addr;
}
return result;
@ -139,7 +141,7 @@ EfErrCode ef_port_write(uint32_t addr, const uint32_t *buf, size_t size) {
size_t i;
uint32_t read_data;
EF_ASSERT(size % 4 == 0);
EF_ASSERT(addr % 4 == 0);
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);