palEnableLineEvent issue

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

angainor
Posts: 11
Joined: Mon Dec 20, 2021 6:43 pm
Been thanked: 2 times

palEnableLineEvent issue

Postby angainor » Tue Apr 04, 2023 10:09 pm

Hi, Giovanni,

I am having a hard time enabling an interrupt from an SPI device, which brings GPIOD_PIN2 low on my STM32F405. I have in my code:

Code: Select all

        palEnableLineEvent(GPIOD_PIN2_SPI3_INT, PAL_EVENT_MODE_FALLING_EDGE);
        palSetLineCallback(GPIOD_PIN2_SPI3_INT, rfm22b_int_cb, NULL);


The device is an RFM22b transceiver. During the operation I enable the interrupts, but my callback is never called. I do check that the GPIO pin in question is initially high, then it is brought low by the device:

Code: Select all

    rfm22b_data_ready = 0; // this is set to 1 in the callback
    chprintf(current_chp, "INT gpio pad is %d\r\n", palReadPad(GPIOD, GPIOD_PIN2_SPI3_INT));

    // Enable the transmitter.
    rfm22_write(RFM22_op_and_func_ctrl1, RFM22_opfc1_pllon | RFM22_opfc1_txon);

    // wait for end of transmission
    uint32_t cnt = 0;
    while(palReadPad(GPIOD, GPIOD_PIN2_SPI3_INT)) cnt++;
    chprintf(current_chp, "counter %d, data ready %d, INT gpio pad is %d\r\n", cnt, rfm22b_data_ready, palReadPad(GPIOD, GPIOD_PIN2_SPI3_INT));


The above prints the following output

Code: Select all

INT gpio pad is 1
counter 50063, data ready 0, INT gpio pad is 0


So initially my GPIO pin is high, after 50k loop iterations it was brought down by the device, but the callback was not called.

I have used this method for another device, connected to another SPI bus, and it works correctly there. I really have no idea why it's not working in this case. Could you help out? Do you have any idea what I could be doing wrong?

Thanks!

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: palEnableLineEvent issue

Postby Giovanni » Wed Apr 05, 2023 3:00 am

Hi,

Do you have other PAL callbacks? STM32 only allows for one callback for each port bit, for example you cannot have callbacks on both pins 5 of GPIOA and GPIOB.

Have you enabled assertions in chconf.h? is something caught? which version are you using?

Giovanni

angainor
Posts: 11
Joined: Mon Dec 20, 2021 6:43 pm
Been thanked: 2 times

Re: palEnableLineEvent issue

Postby angainor » Wed Apr 05, 2023 6:18 am

Thanks for the answer!

I have another callback enabled on GPIOC_PIN4. That one works. I have now compiled the code with CH_DBG_ENABLE_ASSERTS. Nothing was printed to the serial console. I am using ChibiOS-ver21.11.3.

I can add some debug statements here and there, if you think it would help.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: palEnableLineEvent issue

Postby Giovanni » Wed Apr 05, 2023 6:38 am

Hi,

Assertions cause a system halt, nothing is printed, apparently not your case.

Giovanni

angainor
Posts: 11
Joined: Mon Dec 20, 2021 6:43 pm
Been thanked: 2 times

Re: palEnableLineEvent issue

Postby angainor » Tue Apr 25, 2023 6:48 pm

Hi,

FYI, this turned out to be my fault (of course). I used `palSetLineCallback` on a GPIO PAD definition. Curious though that this does not result in any compiler error. I didn't look too much at the code, but you do define `PAL_LINE` as a tuple of port and pad.

In any case, all works when I use it as intended ;)

m


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 15 guests