mirror of
https://gitee.com/Armink/EasyFlash.git
synced 2024-11-30 03:07:40 +08:00
【更新】STM32F4 demo 中的片内 flash 驱动
Signed-off-by: armink <armink.ztl@gmail.com>
This commit is contained in:
parent
e379be4513
commit
7abf3d3500
@ -102,12 +102,12 @@ 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 ef_port_read(uint32_t addr, uint32_t *buf, size_t size) {
|
||||||
EfErrCode result = EF_NO_ERR;
|
EfErrCode result = EF_NO_ERR;
|
||||||
|
uint8_t *buf_8 = (uint8_t *)buf;
|
||||||
EF_ASSERT(size % 4 == 0);
|
size_t i;
|
||||||
|
|
||||||
/*copy from flash to ram */
|
/*copy from flash to ram */
|
||||||
for (; size > 0; size -= 4, addr += 4, buf++) {
|
for (i = 0; i < size; i++, addr ++, buf_8++) {
|
||||||
*buf = *(uint32_t *) addr;
|
*buf_8 = *(uint8_t *) addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -165,18 +165,19 @@ EfErrCode ef_port_write(uint32_t addr, const uint32_t *buf, size_t size) {
|
|||||||
EfErrCode result = EF_NO_ERR;
|
EfErrCode result = EF_NO_ERR;
|
||||||
size_t i;
|
size_t i;
|
||||||
uint32_t read_data;
|
uint32_t read_data;
|
||||||
|
uint8_t *buf_8 = (uint8_t *)buf;
|
||||||
EF_ASSERT(size % 4 == 0);
|
|
||||||
|
|
||||||
FLASH_Unlock();
|
FLASH_Unlock();
|
||||||
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR
|
FLASH_ClearFlag(
|
||||||
| FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
|
FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR
|
||||||
for (i = 0; i < size; i += 4, buf++, addr += 4) {
|
| FLASH_FLAG_PGSERR);
|
||||||
|
for (i = 0; i < size; i++, buf_8++, addr++)
|
||||||
|
{
|
||||||
/* write data */
|
/* write data */
|
||||||
FLASH_ProgramWord(addr, *buf);
|
FLASH_ProgramByte(addr, *buf_8);
|
||||||
read_data = *(uint32_t *)addr;
|
read_data = *(uint8_t *) addr;
|
||||||
/* check data */
|
/* check data */
|
||||||
if (read_data != *buf) {
|
if (read_data != *buf_8) {
|
||||||
result = EF_WRITE_ERR;
|
result = EF_WRITE_ERR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user