r/MicroPythonDev • u/lndshrk-ut • Jun 01 '26
Interrupt driven CAN/TWAI ISO-TP
I'm just starting a project that will first run on a C6 and later on an S31.
I want to use micropython to give end users the ability to customize.
Is it possible to write an interrupt driven CAN stack and then add the module to micropython? I've seen more than one "polling" version, but with packets flying at 500k, I'm pretty sure that polling via Python (multiple layers deep) is just going to drop packets and to put it lightly - that would be bad. Really bad.
I could keep it all in ESP-IDF and skip micropython but that ends user customization.
Would love some thoughts.
View all comments
Show parent comment
1
u/Medical-Ocelot Jun 01 '26
It depends on how much processing you actually need to do - if it's a fairly quiet bus, then polling in MicroPython may be fine - the UART handles a chunk of the speed work, and maybe use the viper or native emitter for some of the work like CRC checking. If there's some complex calculations to do then a C module might help.
https://docs.micropython.org/en/v1.9.3/pyboard/reference/speed_python.html
https://docs.micropython.org/en/latest/develop/cmodules.html
If there are genuinely 500k packets/s on the bus that need to be processed to see if they're relevant then I suspect pure C is the only way to go - 320 clock cycles per packet is too few to do anything useful in MicroPython.
If you want to go the Micropython route, I'd double check that the ESP port does what you want with interrupts - the docs suggest it isn't a hard interrupt from the UART, so you'd have to see if the latency penalty is a problem for your application.