reformatted, ifdef USER_RF_CAL user_rf_cal_sector_set(), used user_rf_cal_sector_set() in user_rf_pre_init()

This commit is contained in:
Holger Müller
2025-02-07 18:07:45 +01:00
parent 52efb0ae0f
commit cd9cfe09f9
+78 -93
View File
@@ -25,21 +25,21 @@ uint32_t reg0, reg1, reg3;
reg3 = *(uint32*)(0x3ff0005c);
if (reg3 != 0) {
mac[0] = (reg3 >> 16) & 0xff;
mac[1] = (reg3 >> 8) & 0xff;
mac[2] = reg3 & 0xff;
mac[0] = (reg3 >> 16) & 0xff;
mac[1] = (reg3 >> 8) & 0xff;
mac[2] = reg3 & 0xff;
} else
if (((reg1 >> 16) & 0xff) == 0) {
mac[0] = 0x18;
mac[1] = 0xfe;
mac[2] = 0x34;
mac[0] = 0x18;
mac[1] = 0xfe;
mac[2] = 0x34;
} else
if (((reg1 >> 16) & 0xff) == 1) {
mac[0] = 0xac;
mac[1] = 0xd0;
mac[2] = 0x74;
mac[0] = 0xac;
mac[1] = 0xd0;
mac[2] = 0x74;
} else {
os_printf("MAC read error\r\n");
os_printf("MAC read error\r\n");
}
mac[3] = (reg1 >> 8) & 0xff;
@@ -200,7 +200,7 @@ int ICACHE_FLASH_ATTR config_load(sysconfig_p config)
os_printf("Length Mismatch (should be %d), probably old version of config, loading defaults\r\n", sizeof(sysconfig_t));
config_load_default(config);
config_save(config);
return -1;
return -1;
}
ip_route_max = config->no_routes;
@@ -243,7 +243,7 @@ void ICACHE_FLASH_ATTR blob_load(uint8_t blob_no, uint32_t *data, uint16_t len)
void ICACHE_FLASH_ATTR blob_zero(uint8_t blob_no, uint16_t len)
{
int i;
int i;
uint8_t z[len];
os_memset(z, 0,len);
uint16_t base_address = FLASH_BLOCK_NO + 1 + blob_no;
@@ -251,6 +251,44 @@ int i;
spi_flash_write(base_address * SPI_FLASH_SEC_SIZE, (uint32_t *)z, len);
}
// For versions ESP8266_NONOS_SDK v1.5.2 to v2.2.1, user_rf_cal_sector_set() need to be added.
// Docker SDK comes with a user_rf_cal_sector_set() in libmain.a, needed for official SDKs.
#if USER_RF_CAL
uint32 ICACHE_FLASH_ATTR user_rf_cal_sector_set(void)
{
enum flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0;
switch (size_map)
{
case FLASH_SIZE_4M_MAP_256_256:
rf_cal_sec = 128 - 5;
break;
case FLASH_SIZE_8M_MAP_512_512:
rf_cal_sec = 256 - 5;
break;
case FLASH_SIZE_16M_MAP_512_512:
case FLASH_SIZE_16M_MAP_1024_1024:
rf_cal_sec = 512 - 5;
break;
case FLASH_SIZE_32M_MAP_512_512:
case FLASH_SIZE_32M_MAP_1024_1024:
rf_cal_sec = 1024 - 5;
break;
case FLASH_SIZE_64M_MAP_1024_1024:
rf_cal_sec = 2048 - 5;
break;
case FLASH_SIZE_128M_MAP_1024_1024:
rf_cal_sec = 4096 - 5;
break;
default:
rf_cal_sec = 0;
break;
}
return rf_cal_sec;
}
#endif
const uint8_t esp_init_data_default[] = {
"\x05\x08\x04\x02\x05\x05\x05\x02\x05\x00\x04\x05\x05\x04\x05\x05"
"\x04\xFE\xFD\xFF\xF0\xF0\xF0\xE0\xE0\xE0\xE1\x0A\xFF\xFF\xF8\x00"
@@ -261,56 +299,38 @@ const uint8_t esp_init_data_default[] = {
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\x00\x00\x00\x00"
"\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"};
void user_rf_pre_init() {
uint8_t esp_init_data_current[sizeof(esp_init_data_default)];
void user_rf_pre_init()
{
uint8_t esp_init_data_current[sizeof(esp_init_data_default)];
enum flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0, addr, i;
enum flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0, addr, i;
//os_printf("\nUser preinit: ");
switch (size_map) {
case FLASH_SIZE_4M_MAP_256_256:
rf_cal_sec = 128 - 5;
break;
rf_cal_sec = user_rf_cal_sector_set();
addr = ((rf_cal_sec)*SPI_FLASH_SEC_SIZE) + SPI_FLASH_SEC_SIZE;
spi_flash_read(addr, (uint32_t *)esp_init_data_current, sizeof(esp_init_data_current));
case FLASH_SIZE_8M_MAP_512_512:
rf_cal_sec = 256 - 5;
break;
for (i = 0; i < sizeof(esp_init_data_default); i++)
{
if (esp_init_data_current[i] != esp_init_data_default[i])
{
spi_flash_erase_sector(rf_cal_sec);
spi_flash_erase_sector(rf_cal_sec + 1);
spi_flash_erase_sector(rf_cal_sec + 2);
addr = ((rf_cal_sec)*SPI_FLASH_SEC_SIZE) + SPI_FLASH_SEC_SIZE;
os_printf("Writing rfcal init data @0x%08X\n", addr);
spi_flash_write(addr, (uint32 *)esp_init_data_default, sizeof(esp_init_data_default));
case FLASH_SIZE_16M_MAP_512_512:
case FLASH_SIZE_16M_MAP_1024_1024:
rf_cal_sec = 512 - 5;
break;
case FLASH_SIZE_32M_MAP_512_512:
case FLASH_SIZE_32M_MAP_1024_1024:
rf_cal_sec = 1024 - 5;
break;
default:
rf_cal_sec = 0;
break;
}
addr = ((rf_cal_sec) * SPI_FLASH_SEC_SIZE)+SPI_FLASH_SEC_SIZE;
spi_flash_read(addr, (uint32_t *)esp_init_data_current, sizeof(esp_init_data_current));
for (i=0; i<sizeof(esp_init_data_default); i++) {
if (esp_init_data_current[i] != esp_init_data_default[i]) {
spi_flash_erase_sector(rf_cal_sec);
spi_flash_erase_sector(rf_cal_sec+1);
spi_flash_erase_sector(rf_cal_sec+2);
addr = ((rf_cal_sec) * SPI_FLASH_SEC_SIZE)+SPI_FLASH_SEC_SIZE;
os_printf("Storing rfcal init data @ address=0x%08X\n", addr);
spi_flash_write(addr, (uint32 *)esp_init_data_default, sizeof(esp_init_data_default));
break;
break;
}
/*
else
{
os_printf("RF data[%u] is ok\n", i);
}
*/
}
/* else {
os_printf("RF data[%u] is ok\n", i);
}*/
}
}
/*
// user_pre_init is required from SDK v3.0.0 onwards
// It is used to register the parition map with the SDK, primarily to allow
@@ -382,45 +402,10 @@ void ICACHE_FLASH_ATTR user_pre_init(void)
while (!rc)
{
rc = system_partition_table_regist(part_table,
sizeof(part_table)/sizeof(part_table[0]),
sizeof(part_table)/sizeof(part_table[0]),
4);
}
return;
}
*/
/*
uint32 ICACHE_FLASH_ATTR user_rf_cal_sector_set(void)
{
enum flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0;
switch (size_map) {
case FLASH_SIZE_4M_MAP_256_256:
rf_cal_sec = 128 - 5;
break;
case FLASH_SIZE_8M_MAP_512_512:
rf_cal_sec = 256 - 5;
break;
case FLASH_SIZE_16M_MAP_512_512:
case FLASH_SIZE_16M_MAP_1024_1024:
rf_cal_sec = 512 - 5;
break;
case FLASH_SIZE_32M_MAP_512_512:
case FLASH_SIZE_32M_MAP_1024_1024:
rf_cal_sec = 1024 - 5;
break;
case FLASH_SIZE_64M_MAP_1024_1024:
rf_cal_sec = 2048 - 5;
break;
case FLASH_SIZE_128M_MAP_1024_1024:
rf_cal_sec = 4096 - 5;
break;
default:
rf_cal_sec = 0;
break;
}
return rf_cal_sec;
}
*/