Hello, I am new to ESP32-C3 and try to find example using ESP-IDF to generate software interrupt in ESP32-C3 but I cant find anywhere. So I am trying to make a very simple example problem: Print "Hello" to screen using software interrupt (generated every second).
However, my code is not work. Can you guy help me to debug this? Thank you in advance
Here is my code
[Codebox]#include <stdio.h>
#include "include/soc/soc.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_types.h"
#include "esp_intr_alloc.h"
#include "soc/periph_defs.h"
// Timer interval in microseconds
#define TIMER_INTERVAL 1000000
void IRAM_ATTR cbs(void* arg)
{
printf("Hello");
REG_CLR_BIT(SYSTEM_CPU_INTR_FROM_CPU_0_REG, 0);
}
void app_main()
{
// Allocate sofware interrupt for counting min
intr_handle_t handle;
esp_intr_disable(handle);
esp_intr_alloc(ETS_FROM_CPU_INTR0_SOURCE, ESP_INTR_FLAG_LEVEL1, sw_min_cb, &digital_clock, &handle);
esp_intr_enable(handle);
// Keep the task alive
while (1) {
REG_SET_BIT(SYSTEM_CPU_INTR_FROM_CPU_0_REG, 0);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
[/Codebox]
Sofware interrupt
-
- Posts: 9769
- Joined: Thu Nov 26, 2015 4:08 am
Re: Sofware interrupt
What problem are you trying to solve here? Why do you think you need a software interrupt? This feels like an X-Y problem to me, to be honest.
-
- Posts: 4
- Joined: Sat Jun 24, 2023 7:26 pm
Re: Sofware interrupt
The use of printf() in interrupt routines is something best avoided.
(since printf() may be a macro, a function, or something else that disables interrupts)
If you want to "printf()" something, then sprintf() to a (global) buffer first, and then printf the buffer somewhere outside of the interrupt routine.
Good luck!
edit:
No interrupt routine should -or has to- clear it;s own interrupt flag, that is what IRET does.
Furthermore, from your code, you never assigned cbs to be an interrupt routine?
(since printf() may be a macro, a function, or something else that disables interrupts)
If you want to "printf()" something, then sprintf() to a (global) buffer first, and then printf the buffer somewhere outside of the interrupt routine.
Good luck!
edit:
No interrupt routine should -or has to- clear it;s own interrupt flag, that is what IRET does.
Furthermore, from your code, you never assigned cbs to be an interrupt routine?
Re: Sofware interrupt
I didn't solve any problem. I am learning so I go through the technical manual and wanna try as much feature as I canESP_Sprite wrote: ↑Sat Jun 24, 2023 1:55 amWhat problem are you trying to solve here? Why do you think you need a software interrupt? This feels like an X-Y problem to me, to be honest.
Re: Sofware interrupt
Thank you, I fix my code to assign cbs to be an ISR inside esp_intr_alloc() but it still doesn't work.esp_enthousiast wrote: ↑Sat Jun 24, 2023 8:50 pmThe use of printf() in interrupt routines is something best avoided.
(since printf() may be a macro, a function, or something else that disables interrupts)
If you want to "printf()" something, then sprintf() to a (global) buffer first, and then printf the buffer somewhere outside of the interrupt routine.
Good luck!
edit:
No interrupt routine should -or has to- clear it;s own interrupt flag, that is what IRET does.
Furthermore, from your code, you never assigned cbs to be an interrupt routine?
P/s: When I try to just print "Hello" using printf() in a loop and wait for 1 second; it is not printf just 1 but many "Hello" after about 25 second. Can you help me to explain
This is the code
Code: Select all
#include <stdio.h>
#include "freertos/task.h"
void app_main()
{
while (1) {
vTaskDelay(pdMS_TO_TICKS(1000));
printf("Hello");
}
}
Who is online
Users browsing this forum: No registered users and 72 guests