GPIO Interrupt in ESP32-C3 controller baremetal

Thread Starter

delini

Joined Jan 22, 2023
7
Hi,

I'm new to microcontrollers and try learning ESP32-C3 which has RV32I core by myself. I wanna to code baremetal ESP32-C3 instead of using ESP-IDF library and face some error with GPIO interrupt part

I read the instruction in technical manual then try to do this lab to practice: mapping GPIO source to 1 CPU interrupt to blink LED at GPIO3 (built-in LED) when GPIO9 (which is built-in button) is press using GPIO interrupt.

I've done these things in order:
1. Disable global interrupt (by clear MIE bit in mstatus register)
2. Set up vector table to mtvec
3. Map INTERRUPT_CORE0_GPIO_INTERRUPT_PRO_MAP_REG (which is GPIO source) to CPU interrupt number 9
4. Set up type (EDGE TYPE) and priority (5) of CPU interrupt number 9 and enable it in INTERRUPT_CORE0_CPU_INT_ENABLE_REG
5. Set threshold to 1
6. Enable global interrupt (by set MIE bit in mstatus register)
7. Config LED pin (set GPIO3 as simple output)
8. Config button pin (set GPIO9 as input, pull up, set int_type is FALLING_EDGE)
9. Clear GPIO interrupt status reg of GPIO 9 by set bit 9 of GPIO_STATUS_W1TC_REG reg, setup handler for CPU interrupt number 9, then enable GPIO9 to send interrupt by set bit INT_ENA

My problem:
- I check all register and they are all correct as I expect except for cpu_int_eip_status (it is not pending interrupt number 9 after I press button), detail:
  1. gpio_enable_reg = 0x8 (true cause CPIO3 is set as output)
  2. gpio_func_out_sel_cfg = 0x280
  3. gpio_interrupt_pro_map = 0x9
  4. status0 = 0x8 before press button and = 0x10008 after press button
  5. gpio_status_reg = 0 before press button and = 0x200 after press button
  6. cpu_int_enable = 0x200
  7. cpu_int_eip_status = 0 (both before and after press button)

- I've check config button and led config by running same lab but instead of using interrupt, I using a while loop to always keep track of button value and it's work --> config of led and button might correct
- I've check address of vector table and mtvec register and it's correct (mtvec = address of vector table | 1)
- I've try to call an exception by call "ecall" --> it's successfull jump to handler for exception --> vector table is load correctly to mtvec

So I dont know why everything seem okay but GPIO interrupt is not pending even it's visible in interrupt status0 register and have priority higher than threshold. I'd so appreciate any help or suggestion from you guys. Thank you
 
Top