Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/stm32/gpio_f1: fix IRQ handler #16478

Merged
merged 1 commit into from
May 19, 2021

Conversation

jue89
Copy link
Contributor

@jue89 jue89 commented May 18, 2021

Contribution description

This is a follow-up for #16272 for the STM32F1 family. The same description applies. I was able to reproduce the described problem with a STM32F103RC. Compared to #16272 it's pretty hard to trigger that race. It took me hours of patience. Reducing the system clock to 8MHz seems to raise the probability of running into the described race condition

To verify the described race condition you can checkout the Reference Manual page 207 Figure 20.

Testing procedure

I wrote a poor-man's frequency counter, measuring a NE555 multi-vibrator running at 33kHz (i.e. 33.000 IRQs per second) I had laying around:

#include <stdio.h>
#include <stdatomic.h>
#include "periph/gpio.h"
#include "ztimer.h"
#include "fmt.h"

static void _irq (void * arg) {
    uint32_t *cnt = (uint32_t*) arg;
    (*cnt)++;
}

#define GPIO_PULSE GPIO_PIN(PORT_B, 10)

int main(void)
{
    uint32_t cnt = 0;

    gpio_init_int(GPIO_PULSE, GPIO_IN_PD, GPIO_RISING, _irq, (void*) &cnt);
    gpio_irq_disable(GPIO_PULSE);

    while (true) {
        cnt = 0;
        gpio_irq_enable(GPIO_PULSE);
        ztimer_sleep(ZTIMER_USEC, 1000000);
        gpio_irq_disable(GPIO_PULSE);
        print_u32_dec(cnt);
        print_str("\n");
    }

    return 0;
}

Without this patch, the program stalls after a few hours. With this patch it runs for days (and is still running).

Issues/PRs references

#16272

@jue89 jue89 added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: cpu Area: CPU/MCU ports labels May 18, 2021
@github-actions github-actions bot added the Platform: ARM Platform: This PR/issue effects ARM-based platforms label May 18, 2021
Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, I don't have the hardware to reproduce but I'm trusting @jue89 and the test procedure provided. More important I've gone through the datasheet and the fix is sensible.

@fjmolinas fjmolinas merged commit 967cbcd into RIOT-OS:master May 19, 2021
@jeandudey jeandudey added this to the Release 2021.07 milestone May 19, 2021
@jue89 jue89 deleted the fix/stm32-gpio_f1-isr branch May 19, 2021 10:30
@jue89
Copy link
Contributor Author

jue89 commented May 19, 2021

Thank you for reviewing and merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants