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

Program Freezes When Using [MICROPY_BEGIN_ATOMIC_SECTION(); ]Function #165

Open
scarletwiz opened this issue Dec 5, 2023 · 1 comment
Open

Comments

@scarletwiz
Copy link

I am currently working on integrating the network functionality into an existing MicroPython module, specifically for WIZNET5K.

I've successfully implemented most features by porating SPI and the micropython-microbit-v2\lib\micropython\extmod\network_wiznet5k.c file.
However, I encounter a problem where the process freezes at the point in the code where MICROPY_BEGIN_ATOMIC_SECTION(); is called.

Here's the relevant code snippet (micropython-microbit-v2\lib\micropython\extmod\network_wiznet5k.c/ Line 130):

STATIC void wiz_cris_enter(void) {
    wiznet5k_obj.cris_state = MICROPY_BEGIN_ATOMIC_SECTION();
}

If I omit this section, the process runs, but the mutex functionality, which is crucial for this program, is lost.

This feature operates flawlessly on other MCUs, such as the rp2040 and stm32. What might be causing the difference with the microbit? Or is there another aspect of the modification that I might have overlooked?

@dpgeorge
Copy link
Collaborator

With the wiznet driver, SPI transactions are done within critical sections. On the microbit, the CODAL handles SPI transfers and probably uses interrupts (and DMA) to perform this transfer. With MICROPY_BEGIN_ATOMIC_SECTION the interrupts are disabled and that probably breaks SPI.

You'll need to implement the atomic section in a different way. I'm not sure exactly why the wiznet driver needs atomicity. It may be enough to just implement them as a no-op.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants