Skip to content

Support user_rf_pre_init() for SDK v3.0 #8888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ extern "C" uint8_t uart_rx_one_char_block();
#include "flash_hal.h"
#endif

extern "C" void user_rf_pre_init();

extern "C" void ICACHE_FLASH_ATTR user_pre_init(void)
{
const char *flash_map_str = NULL;
Expand Down Expand Up @@ -623,16 +625,26 @@ extern "C" void ICACHE_FLASH_ATTR user_pre_init(void)
uart_rx_one_char_block(); // Someone said hello - repeat message
} while(true);
}
/*
The function user_rf_pre_init() is no longer called from SDK 3.0 and up.
The SDK manual and release notes skipped this detail. The 2023 ESP-FAQ
hints at the change with "* Call system_phy_set_powerup_option(3) in
function user_pre_init or user_rf_pre_init"
https://docs.espressif.com/_/downloads/espressif-esp-faq/en/latest/pdf/#page=14

Add call to user_rf_pre_init(), so we can still perform early calls like
system_phy_set_rfoption(rf_mode), system_phy_set_powerup_option(2), etc.

Placement, should this be at the beginning or end of user_pre_init()?
By the end, we have registered the PHY_DATA partition; however, PHY_DATA
read occurs after return and before user_init() is called.
*/
user_rf_pre_init();
}
#endif // #if (NONOSDK >= (0x30000))

extern "C" void user_init(void) {

#if (NONOSDK >= (0x30000))
extern void user_rf_pre_init();
user_rf_pre_init(); // Stop spoofing logic
#endif

struct rst_info *rtc_info_ptr = system_get_rst_info();
memcpy((void *) &resetInfo, (void *) rtc_info_ptr, sizeof(resetInfo));

Expand Down
9 changes: 7 additions & 2 deletions cores/esp8266/core_esp8266_phy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ extern int IRAM_ATTR __wrap_spi_flash_read(uint32_t addr, uint32_t* dst, size_t
return __real_spi_flash_read(addr, dst, size);
}

#if (NONOSDK >= (0x30000))
spoof_init_data = false;
#endif
memcpy(dst, phy_init_data, sizeof(phy_init_data));
((uint8_t*)dst)[107] = __get_adc_mode();
return 0;
Expand All @@ -340,13 +343,13 @@ extern int __get_adc_mode(void)
extern void __run_user_rf_pre_init(void) __attribute__((weak));
extern void __run_user_rf_pre_init(void)
{
return; // default do noting
return; // default do nothing
}

#if (NONOSDK >= (0x30000))
void sdk3_begin_phy_data_spoof(void)
{
spoof_init_data = true;
spoof_init_data = true;
}
#else
uint32_t user_rf_cal_sector_set(void)
Expand All @@ -359,7 +362,9 @@ uint32_t user_rf_cal_sector_set(void)
void user_rf_pre_init()
{
// *((volatile uint32_t*) 0x60000710) = 0;
#if (NONOSDK < (0x30000))
spoof_init_data = false;
#endif

int rf_mode = __get_rf_mode();
if (rf_mode >= 0) {
Expand Down