KevinOConnor / can2040

Software CAN bus implementation for rp2040 micro-controllers
GNU General Public License v3.0
667 stars 66 forks source link

Multiple core increases parse errors #50

Closed laser-vectrix closed 8 months ago

laser-vectrix commented 10 months ago

I'm using can2040 on one core and a wifi (lwip_threadsafe_background) on the 2nd core. CANBus data is being replayed on a TCP connection. At 250kbit/s (with a message every 4ms) I get around 0.5% CAN parse errors when TCP connections are running (comparing to near 0 when they are not), I guess that is due to PIO interrupts being handled on the 2nd core in which the cyw43 and lwip are being used.

If this could be the case, is there anyway to force PIO IRQs to being handled in a given core?

    // Enable irqs
    irq_set_exclusive_handler(PIO0_IRQ_0_IRQn, PIOx_IRQHandler);
    NVIC_SetPriority(PIO0_IRQ_0_IRQn, 1);
    NVIC_EnableIRQ(PIO0_IRQ_0_IRQn);
KevinOConnor commented 10 months ago

To the best of my knowledge, running that code on core0 sets the interrupts for core0, and running that code on core1 sets the interrupts for core1. (That is, those functions typically alter registers in a memory space that is private to each core.) However, the technical details like that could vary from build system to build system, so best to check the documentation for the core libraries you are using.

In addition to the processing load on each arm core, be aware that flash access can result in processing stalls. It may be necessary to load the application into ram (or at least, load the can2040 interrupt handling code into ram) in order to get predictable processing time. (Loading an application into ram is heavily dependent on the build environment though - see #18 ).

Cheers, -Kevin

github-actions[bot] commented 8 months ago

Hello,

It looks like there hasn't been any recent updates on this github ticket. We prefer to only list tickets as "open" if they are actively being worked on. Feel free to provide an update on this ticket. Otherwise the ticket will be automatically closed in a few days.

Best regards,

~ Your friendly GitIssueBot

PS: I'm just an automated script, not a human being.