Skip to content

What is the proper init sequence to avoid racing / bad configurations? #473

@ve2opn

Description

@ve2opn

For ESP32, for some reason I need a delay otherwise the board keeps rebooting, Here I put too much 200ms just as example.
But the same sequence, on T2 (T2-U board) adding tal_system_sleep(200); somehow breaks either CPU speed or power modes so later I have nop loops for delay they do not have expected timing.

My questions are:

  • What is the best sequence to do application HW setup (GPIOs drivers) vs. Tuya system / underlay WiFi stuff initialization?
  • When the earliest I can call tal_system_sleep(); ?
void user_main(void)
{
    int rt = OPRT_OK;
    cJSON_InitHooks(&(cJSON_Hooks){.malloc_fn = tal_malloc, .free_fn = tal_free});
    tal_log_init(TAL_LOG_LEVEL_DEBUG, 1024, (TAL_LOG_OUTPUT_CB)tkl_log_output);
...
    PR_INFO("🔍 Initial free heap: %d", tal_system_get_free_heap_size());

    tal_system_sleep(200);  <-----------needed for ESP32 but breaks T2 timing

    /* HW init */
    gpio_init();
    PR_INFO("🔍 After GPIO init - free heap: %d", tal_system_get_free_heap_size());
    alt_sensor_init();

    /* system services */
    tal_kv_init(&(tal_kv_cfg_t){
        .seed = "vmlkasdh93dlvlcy",
        .key = "dflfuap134ddlduq",
    });
    tal_sw_timer_init();
    tal_workq_init();
#if !defined(PLATFORM_UBUNTU) || (PLATFORM_UBUNTU == 0)
    tal_cli_init();
    tuya_authorize_init();
    tuya_app_cli_init();
#endif

    /* init registration */
    reset_netconfig_start();

    /* license */

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions