Page 1 of 1

Timing issue for blinky while using some gpios and bt_controler

Posted: Mon Oct 09, 2023 9:43 am
by julienD
Hello,

I have "timing related" issues while using together several IO as outputs and bt_controler.

I've built a minimal code and you'll get some explanations below:

Code: Select all

#include <string.h>
#include <sys/stat.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"

#include "sdkconfig.h"
#include "board.h"
#include "esp_peripherals.h"

#include "nvs.h"
#include "nvs_flash.h"

#include "esp32s3/pm.h"
#include "esp_pm.h"
#include "esp_sleep.h"
#include "defines.h"

#include "ble.h"
#include "audio.h"

#include "audio_idf_version.h"
#include "audio_test.h"
#include "driver/ledc.h"
#include "esp_bt.h"
#include "esp_gap_ble_api.h"
#include "esp_gattc_api.h"
#include "esp_gatt_defs.h"
#include "esp_bt_main.h"
#include "esp_gatt_common_api.h"


static char TAG[] = "main";

#define TEST_PIN		36
#define CODECS_MODE_PIN                 2


#define CONCAT(A,B)         A##B
#define GPIO_SEL(x)          CONCAT(GPIO_SEL_,x)
#define GPIO_NUM(x)          CONCAT(GPIO_NUM_,x)



void test()
{

    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));

    esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
    esp_err_t ret = 0;
  //  ret = esp_bt_controller_init(&bt_cfg);     // <<-- note the commented-out code
    if (ret)
    {
        ESP_LOGE(TAG, "%s initialize controller failed: %s", __func__, esp_err_to_name(ret));
        return;
    }


    gpio_config_t io_conf = {};
    io_conf.intr_type = GPIO_INTR_DISABLE;
    io_conf.mode = GPIO_MODE_OUTPUT;
    io_conf.pin_bit_mask = GPIO_SEL(CODECS_MODE_PIN);
    io_conf.pull_down_en = 0;
    io_conf.pull_up_en = 0;
//    gpio_config(&io_conf);		 <<-- note the commented-out code

    io_conf.pin_bit_mask = GPIO_SEL(TEST_PIN);
    gpio_config(&io_conf);

    while (1)
    {
        gpio_set_level(GPIO_NUM(TEST_PIN), 0);
        vTaskDelay(pdMS_TO_TICKS(3));
        gpio_set_level(GPIO_NUM(TEST_PIN), 1);
        vTaskDelay(pdMS_TO_TICKS(3));
    }
}
ESP-IDF 4.4.5 on ESP32-S3

This basic code is intended to toggle gpio 36 every 3 milliseconds and it does what it should in the above configuration.

1.jpg
1.jpg (57.54 KiB) Viewed 1570 times

Now, if I uncomment one of the two commented lines (eg. esp_bt_controller_init() or gpio_config(&io_conf)), it works the same.
But if I uncomment both the two commented lines (eg. esp_bt_controller_init() and gpio_config(&io_conf)), here's the result:

2.jpg
2.jpg (62.38 KiB) Viewed 1570 times

The period is correct but not the frequency...

Note : If I use gpio 39 instead of gpio 36, it works on all situations:

3.jpg
3.jpg (59.9 KiB) Viewed 1570 times

I've looked in the documentation, and in sdk config file and did not find any specific behaviour for gpio 36 pin and the relationship between those 3 functions calls is definitively not obvious to me...

Any idea would be greatly appreciated.

Thanks
Julien

Re: Timing issue for blinky while using some gpios and bt_controler

Posted: Mon Oct 09, 2023 11:57 am
by MicroController
What board/module/SoC are you using?
When using Octal Flash or Octal PSRAM or both, GPIO33~37 are connected to SPIIO4 ~ SPIIO7 and SPIDQS. Therefore on ESP32-S3R8 / ESP32-S3R8V board GPIO33~37 are also not recommended for other uses.

Re: Timing issue for blinky while using some gpios and bt_controler

Posted: Mon Oct 09, 2023 12:38 pm
by julienD
Hello,

None of them.
Btw, I'm back from lunch, the board has been power cycled and it does not occur anymore!

The dark side certainly...

Thanks for your help.
Julien

Re: Timing issue for blinky while using some gpios and bt_controler

Posted: Mon Oct 09, 2023 12:42 pm
by julienD
julienD wrote:
Mon Oct 09, 2023 9:43 am

ESP-IDF 4.4.5 on ESP32-S3
The "none of them" in previous post was about the question you modified which asked for os tick.

Re: Timing issue for blinky while using some gpios and bt_controler

Posted: Mon Oct 09, 2023 1:18 pm
by MicroController
The "none of them" in previous post was about the question you modified which asked for os tick.
Ok, sorry for the rug pulling ;-)