Upcoming maintenance
Dear Customers and Partners.
This website will be undergoing scheduled maintenance on June 14, 2023. Please be aware there may be disruption to the developer portal website and associated services during the scheduled maintenance period.
This upgrade is essential to ensure the continued performance, reliability, and security of Developer World.
We apologize for any inconvenience.
Fast I/O in Arduino IDE and external class
-
Hi @mezmerizer,
I am sorry for the inconvenience. Fast digital I/O will be released next week with the new version 2.3.0 of Spresense Arduino Libraries. Then you will be able to use these functions after updating the library.
Best Regards,
Kamil Tomaszewski -
-
Hi @MezmerizeR
The new Spresense Arduino Library has been released. Please update this and try to use these functions again.
Best Regards,
Kamil Tomaszewski -
Hey @kamiltomaszewski,
thank you for the information.
How do I update? Via git or is it possible in the Arduino IDE?Best,
MezmerizeR -
In the Arduino IDE go to Tools -> Board: "Spresense" -> Boards Manager... Look for "Spresense" and click the update button.
Best Regards,
Kamil Tomaszewski -
-
Hey @KamilTomaszewski,
this is the code I'm using right now. Actually just the code from the docs.
volatile uint8_t *port = portOutputRegister(digitalPinToPort(3)); void setup() { pinMode(3, OUTPUT); } void loop() { *port = 1; /* High */ *port = 0; /* Low */ }
It has no compile or linker errors but it has also no effect. So my pin 3 on the extension board is doing nothing. If I use
digitalWrite
it still works as expected.Best,
MezmerizeR -
Hi @MezmerizeR I found what causes this issue. It will be fixed. Currently, please try the code below:
volatile uint32_t *port = (volatile uint32_t *)portOutputRegister(digitalPinToPort(3)); void setup() { pinMode(3, OUTPUT); } void loop() { *port = 1; /* High */ *port = 0; /* Low */ }
Please use
uint32_t *
instead ofuint8_t *
for this function.Best Regards,
Kamil Tomaszewski -
-
Hey again,
the following code makes a difference in
HIGH
andLOW
times of the pulse.#include <MP.h> #ifdef SUBCORE #if (SUBCORE == 1) uint8_t pinNo = 3; volatile uint32_t *port = (volatile uint32_t *)portOutputRegister(digitalPinToPort(pinNo)); #define CORENO 1 #endif #if (SUBCORE == 2) uint8_t pinNo = 4; volatile uint32_t *port = (volatile uint32_t *)portOutputRegister(digitalPinToPort(pinNo)); #define CORENO 2 #endif #if (SUBCORE == 3) uint8_t pinNo = 5; volatile uint32_t *port = (volatile uint32_t *)portOutputRegister(digitalPinToPort(pinNo)); #define CORENO 3 #endif #if (SUBCORE == 4) uint8_t pinNo = 6; volatile uint32_t *port = (volatile uint32_t *)portOutputRegister(digitalPinToPort(pinNo)); #define CORENO 4 #endif void setup() { pinMode(pinNo, OUTPUT); MP.begin(); } void loop() { while(1){ *port = 1; /* High */ *port = 0; /* Low */ } } #else void setup() { MP.begin(1); // use only this -> ~760 ns // MP.begin(2); // additional 760 ns -> ~1520 ns // MP.begin(3); // ... // MP.begin(4); // ... more than 3 µs } void loop() { } #endif
The problem is when using multi-core programming. WITHOUT using the code on multiple cores, the pulses are about 760 ns. WITH multiple cores the pulses are X*760 ns, where X is the number of cores that I'm using. Is there a way (except maybe assembler code) to get it faster when I use multi-core programming? Or is this a limitation due to sequential commands of the CPU or something like this?
Thanks,
MezmerizeR -
@mezmerizer Don't you measure the time the
MP.begin()
function takes to execute? I mean you mainly consider the time the main core needs to initialize the sub cores.Best Regards,
Kamil Tomaszewski -
Hey @kamiltomaszewski,
I'm measuring the signals on the pins (3,4,5,6 in that case), that are produced by the different subcores with an oscilloscope.
Best,
MezmerizeR -
@mezmerizer I checked it and it is unfortunately a limitation due to the bus architecture. The bus I/O access is serialized and cannot be multiplexed.
Best Regards,
Kamil Tomaszewski -