micro-ros zephyr - Fault during interrupt handling

asked 2021-12-01 09:08:03 -0500

Jefecito gravatar image

updated 2021-12-01 09:10:20 -0500

Hello,

I am developing an app that has 4 GPIO input interrupts for turbine flow sensors. I started developing It on pure Zephyr and everything worked fine. When I added Micro-ROS to the software stack, the interrupts started causing the halting error below when the first interrupt is triggered. BTW, the app has 3 low-frequency sensor threads running in parallel beside the Micro-ROS tasks. I've tried without the additional threads and the issue is still. So, just Micro-ROS with the interrupts is enough to cause the halting. I've tried with ROS Foxy and Galactic.

[00:04:31.528,000] <err> os: ***** BUS FAULT *****
[00:04:31.528,000] <err> os:   Instruction bus error
[00:04:31.528,000] <err> os: r0/a1:  0x2000144c  r1/a2:  0x08018ebf  r2/a3:  0x0
[00:04:31.528,000] <err> os: r3/a4:  0x00b15046 r12/ip:  0x00000030 r14/lr:  0xb
[00:04:31.528,000] <err> os:  xpsr:  0x000d0027                                 
[00:04:31.528,000] <err> os: Faulting instruction address (r15/pc): 0x00b15046  
[00:04:31.528,000] <err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0   
[00:04:31.528,000] <err> os: Fault during interrupt handling                    

[00:04:31.528,000] <err> os: Current thread: 0x20001a58 (unknown)               
[00:04:31.529,000] <err> os: Halting system

I did some experiments and dug a bit on the internet, but didn't find anything related. Does anyone know which measures I have to adopt in order to use GPIO interrupts together with Micro-ROS?

edit retag flag offensive close merge delete

Comments

Hi @Jefecito, great user_namebtw, I am not sure if you have check this tutorial: https://github.com/maksimdrachov/zeph...

Regular Zephyr interrupts introduce some overhead which may be unacceptable for some low-latency use-cases.
osilva gravatar image osilva  ( 2021-12-01 09:30:41 -0500 )edit

Hi, @osilva. Yes, I saw this tutorial. BTW, it's a very good initiative. But, I am not using any of these types of interrupt. I am using GPIO interrupts, like this code below.

static const struct gpio_dt_spec button_a = GPIO_DT_SPEC_GET(DT_NODELABEL(buttona), gpios);
static struct gpio_callback button_a_cb;
struct device *gpio;
void button_a_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins){
    gpio_pin_toggle(gpio,2);
}

void main(void){
    int ret;
    printk("Hello World! %s\n", CONFIG_BOARD);
    gpio=device_get_binding("GPIO_0");
    ret = gpio_pin_configure(gpio,2,GPIO_OUTPUT);
    ret = gpio_pin_configure_dt(&button_a,GPIO_INPUT | GPIO_PULL_UP);
    ret = gpio_pin_interrupt_configure_dt(&button_a,GPIO_INT_EDGE_TO_ACTIVE);
    gpio_init_callback(&button_a_cb, button_a_pressed, BIT(button_a.pin) );
    gpio_add_callback(button_a.port, &button_a_cb);
}
Jefecito gravatar image Jefecito  ( 2021-12-01 13:27:35 -0500 )edit

Yes you were clear it's for GPIO. Sorry I missed that. I don't have much experience in this area but it's something it's in my list to do to learn. Hopefully you find an answer soon, pls make sure to document so others may benefit as well.

osilva gravatar image osilva  ( 2021-12-01 13:44:26 -0500 )edit

Thank you. Yes, I will do it.

Jefecito gravatar image Jefecito  ( 2021-12-01 13:54:04 -0500 )edit

Maybe it is related to stack? a micro-ROS task uses a considerable amount of stack memory. It highly depends on the case. How long is the stack assigned to the Zephyr micro-ROS task?

Pablogs gravatar image Pablogs  ( 2021-12-02 00:32:29 -0500 )edit
1

No, the stack wasn't the problem. I just discovered what was happening. It seems my mistake while using the GPIO API. It turns out that Instead of using the functions gpio_pin_configure_dt(const struct gpio_dt_spec *spec, gpio_flags_t extra_flags) and gpio_pin_interrupt_configure_dt(const struct gpio_dt_spec *spec, gpio_flags_t flags), I decided to use gpio_pin_configure(const struct device * port, gpio_pin_t pin, gpio_flags_t flags) and gpio_pin_interrupt_configure(const struct device * port, gpio_pin_t pin, gpio_flags_t flags). The last ones receive a device struct as the first parameter instead of a gpio spec struct. It worked fine in Zephyr only but messed everything while working together with micro-ROS. Maybe it has caused some memory misallocation only reproduced when more memory is in use.

Anyway, thank you, Guys!

Jefecito gravatar image Jefecito  ( 2021-12-02 02:13:04 -0500 )edit