Page 1 of 1

PWM, SSL and FOTA: ill-compiled libraries or conflicts ?

Posted: Tue Aug 28, 2018 6:39 pm
by Pato
Hi all,

I've got an OTA program that use and link against these libs (among others): libssl, libpwm and libdriver.

But depending on if I link with the option gc-section (to remove unused code), or depending on the libraries I link against, my program crashes to Fatal Exception (0) right after boot, without executing any line of my code. Functions of the libs are even never called (just used them in volountarly dead code to force the linker to link them during my investigation).
Or it seems like removing or adding dead code breaks crashes the ESP...

My app works perfectly fine when compiled in non-OTA version.
Behavior is the same with NONOS-SDK v2.2 and v3.0, on ESP8266 on a WROOM-02 module, 16MBits and 512+512 map.

What's wrong ? Is there any conflicts between PWM and SSL lib ? Related to NMI/hardware timer ? Magic sections in theses libs ?
Removing dead code sould not change the behavior. And linking a library whose functions are not called should not break the app. That's why I suspect a compilation/linking issue, or some obscure broken code relocation...

I'm going crazy, I can't see the logic: could you help me understand and fix this behaviour ?

Here is are the results of my investigastions.
The "y" stands for "yes, I linked against this lib or enabled gc-sections", and "n" is for "no".
By "OK", I mean my app start and runs fine.
Below, it's built for OTA-version.

Empty app (just implement user_init & co. with a printf. Other objects are compiled but functions are never called):

(I got into this after this post :

Re: PWM, SSL and FOTA: ill-compiled libraries or conflicts ?

Posted: Wed Aug 29, 2018 1:09 am
by Pato
Okay, I reworked my test and could narrow the situation a little more.

The simple code below runs as expected when compiled for non-FOTA. But when compiled for FOTA:

- If linked with gc-section option, works only if pwm_start() is commented out.
- If linked without gc-section option, works only if pwm_start() and espconn_secure_set_size() are commented out...

Test code:

Code: Select all

 * Debuging app that crashes with fatal exception when compiled fo OTA.
 * Compiled fo non-OTA: works
 * Compiled for OTA (bootloader 1.7): fatal exception right after boot. Due to PWM lib ?

#include "osapi.h"
#include "os_type.h"
#include "user_interface.h"
#include "gpio.h"
#include "pwm.h"
#include "espconn.h"
#include "driver/i2c_master.h"

void PostInitCb(void);
uint32 user_rf_cal_sector_set(void);
void user_init(void);

 * @brief   Called when system is fully initialized.
void PostInitCb(void)
    os_printf("PostInitCb() !\n");
    /* Force references to functions from the libs without calling them */
    volatile bool tt = false;
        pwm_start();                                      /* Uncommented: crash ! */
        gpio_init();                                      /* Uncommented or commented: ok  */
        espconn_secure_set_size(ESPCONN_CLIENT, 5120);    /* Uncommented or commented: depends on gc-section */
        i2c_master_gpio_init();                           /* Uncommented or commented: ok  */

 * @brief   Was present in IoT_Demo/user/user_main.c on which this code is based...
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;

        case FLASH_SIZE_8M_MAP_512_512:
            rf_cal_sec = 256 - 5;

        case FLASH_SIZE_16M_MAP_512_512:
            rf_cal_sec = 512 - 5;
        case FLASH_SIZE_16M_MAP_1024_1024:
            rf_cal_sec = 512 - 5;

        case FLASH_SIZE_32M_MAP_512_512:
            rf_cal_sec = 1024 - 5;
        case FLASH_SIZE_32M_MAP_1024_1024:
            rf_cal_sec = 1024 - 5;

        case FLASH_SIZE_64M_MAP_1024_1024:
            rf_cal_sec = 2048 - 5;
        case FLASH_SIZE_128M_MAP_1024_1024:
            rf_cal_sec = 4096 - 5;
            rf_cal_sec = 0;

    return rf_cal_sec;

 * @brief   Main entry point of our programm
void user_init(void)