Udoo Neo Arduino Uno library compatibility/porting

Discussion in 'UDOO NEO' started by waltervl, Mar 18, 2017.

  1. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Intel publishes a shield compatibility guide for their Arduino 101 here. Some compatibility rules also apply for the Neo.

    There is already some information on Library Porting for the Neo here.
    But in the Intel Arduino 101 compatibility guide there is some interesting information that could come handy when libraries used with your Arduino shield are not working on the Udoo Neo:

    Arduino direct port manipulation


    On the Arduino* Uno board, software access to the direct ports (analog and digital pins) is abstracted by means of APIs (digitalRead and digitalWrite). The advantage of using these APIs is the compatibility of the sketches between microcontrollers.

    The disadvantage of using these APIs is that the API may introduce overhead that may slow down the pin access. To overcome the performance loss, library and sketch writers uses a means of directly manipulating the microcontroller’s registers. Unfortunately, registers are not compatible between microcontrollers. These access types may cause compile errors. Sketches or Libraries accessing the ports directly can be determined by the presents of headers files referencing the
    “avr” directory. One example is the Arduino TFT Screen, which uses the TFT library.

    Example of header files used for Direct Port Manipulation
    Code:
    <avr/pgmspace.h>
    <avr/sleep.h>
    void setup() {}
    void loop() {}
    PROGMEM / F( ) macro


    On the Arduino Uno board, it is possible to store data in flash (program) memory using the ‘PROGMEM’ statement. There is also another macro call “F() macro”, that indirectly does the same thing. These are routinely found in Arduino sketches. Eliminating these macros can be time consuming; however, the following example can eliminate the use of this special macro with
    one line ( #define PSTR(arg)(arg) ). If a shield library contains F() macros, then this workaround should be placed as the first #define statement to the main header file of the library as removing the F() macros can be tedious and error prone.

    Example 1 Removing F() macro sketch
    Before:
    Code:
    void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
    Serial.println("setup");
    }
    
    void loop() {
    // put your main code here, to run repeatedly:
    Serial.println(F("Loop"));
    }
    After:
    Code:
    #define PSTR(arg)(arg)
    void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
    Serial.println("setup");
    }
    
    void loop() {
    // put your main code here, to run repeatedly:
    Serial.println(F("Loop"));
    }
     
    graugans likes this.

Share This Page