Sony's Developer World forum

    • Home
    • Forum guidelines

    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

    Spresense
    2
    15
    1211
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    This topic has been deleted. Only users with topic management privileges can see it.
    • MezmerizeR
      MezmerizeR @KamilTomaszewski last edited by

      Hey @kamiltomaszewski,

      thank you for the fast reply!

      Best,
      MezmerizeR

      K 1 Reply Last reply Reply Quote
      • K
        KamilTomaszewski DeveloperWorld @MezmerizeR last edited by

        Hi @MezmerizeR

        The new Spresense Arduino Library has been released. Please update this and try to use these functions again.

        Best Regards,
        Kamil Tomaszewski

        MezmerizeR 1 Reply Last reply Reply Quote
        • MezmerizeR
          MezmerizeR @KamilTomaszewski last edited by

          Hey @kamiltomaszewski,

          thank you for the information.
          How do I update? Via git or is it possible in the Arduino IDE?

          Best,
          MezmerizeR

          K 1 Reply Last reply Reply Quote
          • K
            KamilTomaszewski DeveloperWorld @MezmerizeR last edited by

            @mezmerizer

            In the Arduino IDE go to Tools -> Board: "Spresense" -> Boards Manager... Look for "Spresense" and click the update button.

            Best Regards,
            Kamil Tomaszewski

            MezmerizeR 1 Reply Last reply Reply Quote
            • MezmerizeR
              MezmerizeR @KamilTomaszewski last edited by

              Hey @kamiltomaszewski,

              I'll give it a try on monday!

              Best,
              MezmerizeR

              1 Reply Last reply Reply Quote
              • MezmerizeR
                MezmerizeR last edited by

                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

                K 1 Reply Last reply Reply Quote
                • K
                  KamilTomaszewski DeveloperWorld @MezmerizeR last edited by

                  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 of uint8_t * for this function.

                  Best Regards,
                  Kamil Tomaszewski

                  MezmerizeR 1 Reply Last reply Reply Quote
                  • MezmerizeR
                    MezmerizeR @KamilTomaszewski last edited by

                    Hey @KamilTomaszewski,

                    works like a charm. Thank you!

                    Best,
                    MezmerizeR

                    1 Reply Last reply Reply Quote
                    • MezmerizeR
                      MezmerizeR last edited by

                      Hey again,

                      the following code makes a difference in HIGH and LOW 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

                      K 1 Reply Last reply Reply Quote
                      • K
                        KamilTomaszewski DeveloperWorld @MezmerizeR last edited by

                        @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

                        MezmerizeR 1 Reply Last reply Reply Quote
                        • MezmerizeR
                          MezmerizeR @KamilTomaszewski last edited by

                          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

                          K 1 Reply Last reply Reply Quote
                          • K
                            KamilTomaszewski DeveloperWorld @MezmerizeR last edited by

                            @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

                            MezmerizeR 1 Reply Last reply Reply Quote
                            • MezmerizeR
                              MezmerizeR @KamilTomaszewski last edited by

                              Hey @KamilTomaszewski ,

                              ok, good to know. Thank you for your support!

                              Best regards,
                              MezmerizeR

                              1 Reply Last reply Reply Quote
                              • First post
                                Last post
                              Developer World
                              Copyright © 2021 Sony Group Corporation. All rights reserved.
                              • Contact us
                              • Legal