I tried to follow the sample in order to use "ledc_isr_register" but unsuccessfully,
the retcode for the function gives me back 0x105 (ESP_ERR_NOT_FOUND) it seems something is wrong when trying to find an available spot to install the function
my code:
Code: Select all
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/ledc.h"
#include "esp_err.h"
#define LEDC_HS_TIMER LEDC_TIMER_0
#define LEDC_HS_MODE LEDC_HIGH_SPEED_MODE
#define LEDC_HS_CH0_GPIO (2)
#define LEDC_HS_CH0_CHANNEL LEDC_CHANNEL_0
#define LEDC_TEST_CH_NUM (1)
#define LEDC_TEST_DUTY (4000)
#define LEDC_TEST_FADE_TIME (1000)
QueueHandle_t xQueue = NULL;
ledc_timer_config_t ledc_timer = {
.duty_resolution = LEDC_TIMER_13_BIT, // resolution of PWM duty
.freq_hz = 5000, // frequency of PWM signal
.speed_mode = LEDC_HS_MODE, // timer mode
.timer_num = LEDC_HS_TIMER // timer index
};
ledc_channel_config_t ledc_channel = {
.channel = LEDC_HS_CH0_CHANNEL,
.duty = 0,
.gpio_num = LEDC_HS_CH0_GPIO,
.speed_mode = LEDC_HS_MODE,
.intr_type = LEDC_INTR_FADE_END,
.timer_sel = LEDC_HS_TIMER
};
void IRAM_ATTR ledc_isr_routine(void *param) {
BaseType_t xHigherPriorityTaskWoken;
static uint32_t counter = 0;
printf("*** ledc_isr ***\n");
xQueueSendFromISR(xQueue, &counter, &xHigherPriorityTaskWoken);
}
void app_main()
{
xQueue = xQueueCreate(5, sizeof(uint32_t));
// Set configuration of timer0 for high speed channels
printf("config timer\n");
ledc_timer_config(&ledc_timer);
// Set LED Controller with previously prepared configuration
printf("config channel\n");
ledc_channel_config(&ledc_channel);
// Initialize fade service.
printf("func install\n");
ledc_fade_func_install(0);
// enable ISR routine
esp_err_t ret = ledc_isr_register(ledc_isr_routine, NULL, ESP_INTR_FLAG_IRAM, NULL);
printf("register isr (0x%x)\n", ret);
uint32_t duty = LEDC_TEST_DUTY;
while (1) {
uint32_t param;
ledc_set_fade_with_time(ledc_channel.speed_mode, ledc_channel.channel, duty, LEDC_TEST_FADE_TIME);
ledc_fade_start(ledc_channel.speed_mode, ledc_channel.channel, LEDC_FADE_NO_WAIT);
xQueueReceive(xQueue, ¶m, portMAX_DELAY);
printf("param = %d", param);
if(duty == 0) {
duty = LEDC_TEST_DUTY;
} else {
duty = 0;
}
}
}
the result:
I (28) boot: ESP-IDF v3.1-dev-636-g393f3da3-dirty 2nd stage bootloader
I (28) boot: compile time 12:25:09
I (30) boot: Enabling RNG early entropy source...
I (35) boot: SPI Speed : 40MHz
I (39) boot: SPI Mode : DIO
I (43) boot: SPI Flash Size : 4MB
I (47) boot: Partition Table:
I (51) boot: ## Label Usage Type ST Offset Length
I (58) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (65) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (73) boot: 2 factory factory app 00 00 00010000 00100000
I (80) boot: End of partition table
I (85) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x05ae4 ( 23268) map
I (102) esp_image: segment 1: paddr=0x00015b0c vaddr=0x3ffb0000 size=0x021c4 ( 8644) load
I (106) esp_image: segment 2: paddr=0x00017cd8 vaddr=0x40080000 size=0x00400 ( 1024) load
I (112) esp_image: segment 3: paddr=0x000180e0 vaddr=0x40080400 size=0x07f30 ( 32560) load
I (134) esp_image: segment 4: paddr=0x00020018 vaddr=0x400d0018 size=0x126f8 ( 75512) map
I (160) esp_image: segment 5: paddr=0x00032718 vaddr=0x40088330 size=0x0094c ( 2380) load
I (162) esp_image: segment 6: paddr=0x0003306c vaddr=0x400c0000 size=0x00000 ( 0) load
I (173) boot: Loaded app from partition at offset 0x10000
I (173) boot: Disabling RNG early entropy source...
I (179) cpu_start: Pro cpu up.
I (182) cpu_start: Starting app cpu, entry point is 0x40080e5c
I (0) cpu_start: App cpu up.
I (193) heap_init: Initializing. RAM available for dynamic allocation:
I (200) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (206) heap_init: At 3FFB2A00 len 0002D600 (181 KiB): DRAM
I (212) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (218) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (225) heap_init: At 40088C7C len 00017384 (92 KiB): IRAM
I (231) cpu_start: Pro cpu start user code
I (249) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
config timer
config channel
func install
register isr (0x105)