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));
}
}
This basic code is intended to toggle gpio 36 every 3 milliseconds and it does what it should in the above configuration.
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:
The period is correct but not the frequency...
Note : If I use gpio 39 instead of gpio 36, it works on all situations:
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