Assembler in micropython
-
Hey guys,
is it possible to write functions or code snippets in assembler for WiPy 3.0, and how to do that?
In micropython documentation i found this command
@micropython.asm_thumb
but it doesn't work. The error message i get says:SyntaxError: invalid micropython decorator
.Bit to my personal project i 'm working on. I want to drive three WS2812B led stripes. So i need very exact timing for that. Fist solution was to use SPI like the existing WS2812 librarys for micropython are doing. That's working but there is only one SPI module on the WiPy and i don't want to change the routing of it all the time i have to send something. Another idea was to use the RTM modules but there are only two with 100ns resolution. Last idea is to control the pins directly, but only toggling them with the standard micropython commands take more than 5us so that's no solution. So the idea is to write it in assembler but i don't know how to include that into micropython files.
Hopefully someone can help me ;-)
Sorry for bad english. Best wishes from germany.
-
@robert-hh, @jcaron Thanks again for the reply. I knew about the possability to build own firmware but i don't know how to do that and it's going way to far. So i will use the RTM module and multiplex the pins. Haven't tried it yet because actual i'm doing my Bachelor Thesis and i don't have much time for personal projects.
-
@maerkl24 If you build your own firmware, you can add any code you want in there, though it's quite a bit of work to make that accessible from the micro python code I suppose (and it's a lot more cumbersome to develop as you need to rebuild and reflash the firmware for each change).
-
@maerkl24 As far as I know, no. The Machine code emitter has not been implemented for the ESP32. It exists for the ESP8266 in the micropython.org branch. So it may be to port it. But it's not done yet.
-
@jcaron, @robert-hh Thanks for your reply. I knew there is an alternative but i already forgot that, so thanks for reminding me to that, i will keep that in mind. But this project i will finish with the WS2812B because the hardware is already finished.
But a last question, is there no other way to access the hardware faster?
For my opinion, as a good C and assembler programmer, it would be a shame. :D
Seems like this is something i have to deal with in micropython but i also know and like the advantages of it.
-
@jcaron It is deinitely easier to deal with the AP102 devices. With the additional clock signal synchronized to the data timing constraints are gone.
-
Don't forget there's an alternative to the WS2812: the APA102 uses real SPI. They're also marketed by Adafruit as Dotstar (while the WS2812 is the Neopixel).
Depending on your project, it may simplify things quite a bit to use those.
-
@maerkl24 Using the RMT module make pretty reiliable timing. I also tried using SPI, but that does not work reliable on the pycom devices. SPi is not sending the data in a single long burst, but word-wise. And the gaps between words are not guaranteed to have a maximal duration.
-
@robert-hh Thanks for the information, i already thought that the access to assembler through micropython is not ported for WiPy. I already found some drivers, but i haven't seen this one yet, so thanks for that.
I only cascade them not, because of the wiring. Of course I could do that an easier way, but i'm someone who likes to go the harder way. But this time i think i switch the channel between the Pins and go the easier way. :D
-
@maerkl24 Assembler is only available in the micropython.org branch of micropython. About using RMT: you surely have seen this litte driver: https://github.com/robert-hh/WS2812
If you do not need to drive all three stripes at the same time, you may use the same RMT channel but switch between the Pins. And is there a specific reason why you do not cascade the three strips, using just one channel & Pin? Obviously you would have to rewrite all LEDs all the time, but unless you have really MANY leds, this is not a problem.