platformio / platform-espressif8266

Espressif 8266: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/espressif8266
Apache License 2.0
325 stars 219 forks source link

PIO doesn't flash init data to the right address for 1MB modules #133

Closed maxgerhardt closed 5 years ago

maxgerhardt commented 5 years ago

See https://community.platformio.org/t/checksum-errors-with-esp8266/6719/5

Basically what's been observerd is that for 1MB ESP8266 modules, PlatformIO doesn't seem to flash esp_init_data.bin to the right address for the module (see https://nodemcu.readthedocs.io/en/master/en/flash/#sdk-init-data) causing a boot-failure. This was observed when using the non-RTOS SDK but might occur for other frameworks, too.

The problem can be manually solved by downloading the needed init data from Espressif's SDK and flashing it. Please take a look at this to see if you can reproduce this and how to fix the problem.

maxgerhardt commented 5 years ago

This seems to occur for every module type, not only for 1MB modules. The builder script simply doesn't flash this file?

ivankravets commented 5 years ago

Please re-test with upstream version http://docs.platformio.org/en/latest/platforms/espressif8266.html#stable-and-upstream-versions

Does it work now?

maxgerhardt commented 5 years ago

@ivankravets I've just erased the flash of my ESP12-E and reflashed it with the latest upstream version. The flashing command now includes esp_init_data_default.bin and the firmware works out-of-the box for NONOS framework.

esptool -cd nodemcu -cb 921600 -cp "COM9" -ca 0x00000 -cf C:\Users\Maxi\Desktop\wemos_test\.pioenvs\d1_mini_rtos\eagle.flash.bin -ca 0x10000 -cf C:\Users\Maxi\Desktop\wemos_test\.pioenvs\d1_mini_rtos\eagle.irom0text.bin -ca 0x3fc000 -cf C:\Users\Maxi\.platformio\packages\framework-esp8266-nonos-sdk\bin\esp_init_data_default.bin

However on ESP-RTOS-SDK, my blinky code for GPIO2 (built-LED on ESP12-E) doesn't work. The bootloader doesn't complain but my main code doesn't seem to be executed. So, there might be more to the issue.

#include "esp_common.h"
#include "freertos/task.h"
#include "gpio.h"
#include "uart.h"

/******************************************************************************
 * FunctionName : user_rf_cal_sector_set
 * Description  : SDK just reversed 4 sectors, used for rf init data and paramters.
 *                We add this function to force users to set rf cal sector, since
 *                we don't know which sector is free in user's application.
 *                sector map for last several sectors : ABCCC
 *                A : rf cal
 *                B : rf init data
 *                C : sdk parameters
 * Parameters   : none
 * Returns      : rf cal sector
*******************************************************************************/
uint32 user_rf_cal_sector_set(void)
{
    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;

        default:
            rf_cal_sec = 0;
            break;
    }

    return rf_cal_sec;
}

void task_blink(void* ignore)
{
    os_printf("hello!\n");
    while(true) {
        GPIO_OUTPUT_SET(2, 1);
        vTaskDelay(1000/portTICK_RATE_MS);
        GPIO_OUTPUT_SET(2, 0);
        vTaskDelay(1000/portTICK_RATE_MS);
    }

    vTaskDelete(NULL);
}

/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR user_init(void)
{
    printf("SDK version:%s\n", system_get_sdk_version());
    wifi_set_opmode(STATION_MODE);
    //put GPIO2 pin into GPIO function mode
    PIN_FUNC_SELECT (PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
    xTaskCreate(&task_blink, "startup", 2048, NULL, 1, NULL);
}

For Non-OS it's fixed however.

maxgerhardt commented 5 years ago

@ivankravets also the code only has 2 possible addresses for the init data but there 6 module types? The code at

https://github.com/platformio/platform-espressif8266/blob/ab839a2946998d0a916da12bee77e472a3959c61/builder/frameworks/esp8266-nonos-sdk.py#L104-L110

won't cover all possibilities at https://nodemcu.readthedocs.io/en/master/en/flash/#sdk-init-data

maxgerhardt commented 5 years ago

Ah, the missing key is maybe that we're not flashing blank.bin at the right address like mentioned in #62. Will test later in the day.

Edit: No a quick test shows for me that writing blank.bin to 0x3fe000 doesn't help, so either there's a problem with my code there's still something missing.

ivankravets commented 5 years ago

Yes, I've just fixed all issues => https://github.com/platformio/platform-espressif8266/commit/ce5b99b4576129139a24144b740bc54ba47c7f8b

Does it work now? I tested on NodeMCUv2 and both RTOS and non-RTOS work for me. Can we have a bug fix release?

maxgerhardt commented 5 years ago

@ivankravets Works flawlessly for me now with NONOS and RTOS versions! My code was actually right and started executing after the latest fix commit. Tested with both my NodeMCUv2 and Wemos D1 mini.

ivankravets commented 5 years ago

Thanks, released! https://github.com/platformio/platform-espressif8266/releases/tag/v2.0.4