|
|
@ -25,10 +25,15 @@ void config_init(void) |
|
|
|
s_config.mask = 1; // |
|
|
|
|
|
|
|
#endif |
|
|
|
// if (stmflash_write(FLASH_START_ADDRESS, (uint32_t *)&s_config, CONFIG_SIZE) < 0) |
|
|
|
// { |
|
|
|
// printf("flash write config error\r\n"); |
|
|
|
// } |
|
|
|
|
|
|
|
if (config_flash_write() < 0) |
|
|
|
{ |
|
|
|
printf("flash write config error\r\n"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
printf("flash write config success\r\n"); |
|
|
|
} |
|
|
|
|
|
|
|
// config_flash_read(); |
|
|
|
|
|
|
@ -65,3 +70,58 @@ void config_flash_read(void) |
|
|
|
} |
|
|
|
|
|
|
|
config_t *config_get(void) { return &s_config; } |
|
|
|
|
|
|
|
int8_t config_flash_write(void) |
|
|
|
{ |
|
|
|
HAL_StatusTypeDef status; |
|
|
|
uint32_t config_flash_write_start_address = FLASH_START_ADDRESS; |
|
|
|
status = FlashErase(); |
|
|
|
if (status != HAL_OK) |
|
|
|
{ |
|
|
|
printf("flash erase error, status:%d\r\n", status); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
status = FlashWrite(config_flash_write_start_address + 0, s_config.mask); |
|
|
|
if (status != HAL_OK) |
|
|
|
{ |
|
|
|
printf("flash write error, status:%d\r\n", status); |
|
|
|
return -2; |
|
|
|
} |
|
|
|
|
|
|
|
status = FlashWrite(config_flash_write_start_address + 4, s_config.obtaining_ip_mode); |
|
|
|
if (status != HAL_OK) |
|
|
|
{ |
|
|
|
printf("flash write error, status:%d\r\n", status); |
|
|
|
return -3; |
|
|
|
} |
|
|
|
|
|
|
|
status = FlashWrite(config_flash_write_start_address + 8, s_config.ip); |
|
|
|
if (status != HAL_OK) |
|
|
|
{ |
|
|
|
printf("flash write error, status:%d\r\n", status); |
|
|
|
return -4; |
|
|
|
} |
|
|
|
|
|
|
|
status = FlashWrite(config_flash_write_start_address + 12, s_config.gw); |
|
|
|
if (status != HAL_OK) |
|
|
|
{ |
|
|
|
printf("flash write error, status:%d\r\n", status); |
|
|
|
return -5; |
|
|
|
} |
|
|
|
|
|
|
|
status = FlashWrite(config_flash_write_start_address + 16, s_config.netmask); |
|
|
|
if (status != HAL_OK) |
|
|
|
{ |
|
|
|
printf("flash write error, status:%d\r\n", status); |
|
|
|
return -6; |
|
|
|
} |
|
|
|
|
|
|
|
status = FlashWrite(config_flash_write_start_address + 20, s_config.localport); |
|
|
|
if (status != HAL_OK) |
|
|
|
{ |
|
|
|
printf("flash write error, status:%d\r\n", status); |
|
|
|
return -7; |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |