Menu

QP/C port to Espressif ESP-IDF

2021-06-26
2021-06-29
  • Sicris Rey Embay

    I am happy to see that QP/C v6.9.3 has an official support for ESP32 port.

    I did an unofficial port of QP/C for ESP32 some time back on v6.5.0 (i think) and was using QM v4.5.0.
    link: Unofficial QP/C port

    I used this on my hobby projects ESP32-Solar-Battery and MotorControl. In first project, I am sending PV and Battery voltages to AWS MQTT broker. In the second project, I send motor data using QSpy via Bluetooth SPP (Serial Port Profile).

    Now, I am interested to test QP/C v6.9.3 official port. Can anybody care to share their "component.mk" (yay, i'm still using Legacy GNU Make) for QP/C component? My test is on this repo ESP32_QPC_Test

    I hope to see enthusiasts sharing example/demo projects on QP/C ESP32.

    • Sicris Rey
     
  • Sicris Rey Embay

    Hi MMS,
    I am having a build error (note: I'm using legacy GNU make) when building QPC component (see component.mk)
    This proposed patch below on qf_port.h of freertos-esp32 port fixed my issue.
    It has to do with the FreeRTOS.h relative to the esp-idf freertos component directory.
    Please let me know if this patch is acceptable, then I can raise pull request.

    diff --git a/ports/freertos-esp32/qf_port.h b/ports/freertos-esp32/qf_port.h
    index f163b4ea..593a9e65 100644
    --- a/ports/freertos-esp32/qf_port.h
    +++ b/ports/freertos-esp32/qf_port.h
    @@ -52,8 +52,8 @@
     #define QF_CRIT_ENTRY(dummy)  portENTER_CRITICAL(&QF_esp32mux)
     #define QF_CRIT_EXIT(dummy)   portEXIT_CRITICAL(&QF_esp32mux)
    
    -#include "FreeRTOS.h"  /* FreeRTOS master include file, see NOTE4 */
    -#include "task.h"      /* FreeRTOS task  management */
    +#include "freertos/FreeRTOS.h"  /* FreeRTOS master include file, see NOTE4 */
    +#include "freertos/task.h"      /* FreeRTOS task  management */
    
     #include "qep_port.h"  /* QEP port */
     #include "qequeue.h"   /* this QP port uses the native QF event queue */
    

    best regards,
    Sicris Rey

     
    • Quantum Leaps

      Quantum Leaps - 2021-06-29

      Hi Sicris,
      Thank you for your interest in QP. But the QP port to FreeRTOS-ESP32 is actually still an "experimental port". The port has been made available upon multiple requests from the users, but the port has currently no examples and has not been tested at Quantum Leaps.

      I'm not sure what to do with this port. Two options are: (1) keep offering the "experimental port" or (2) remove the port completely from QP.

      A third option to test it thoroughly at Quantum Leaps is difficult, because of the bizarre design of FreeRTOS (with the "normal" and "fromISR" API duplication) and the fact that FreeRTOS-ESP32 actually does not use the official FreeRTOS API (so it isn't FreeRTOS really). So, what is it then and what rules and API documentation should be used?

      --MMS

       
      • Harry Rostovtsev

        Definitely vote for "not removing". I'd rather have access to untested or not fully working ports than none at all. Obviously, they should be marked as such.

         
      • Sicris Rey Embay

        Hi MMS,
        IMO, I'd like to continually see "experimental port" for QP/C.
        There may be other ESP32 users in the community who may be interested in exploring QP on ESP32 targets.

         
  • Sicris Rey Embay

    Additional patch proposal on qf_port.c of freertos-eps32 port

    diff --git a/ports/freertos-esp32/qf_port.c b/ports/freertos-esp32/qf_port.c
    index eebe407c..e788a49a 100644
    --- a/ports/freertos-esp32/qf_port.c
    +++ b/ports/freertos-esp32/qf_port.c
    @@ -47,7 +47,8 @@
     #else
         #include "qs_dummy.h" /* disable the QS software tracing */
     #endif /* Q_SPY */
    -#include <esp_log.h>
    +#include "esp_log.h"
    +#include "esp_freertos_hooks.h"
    
     Q_DEFINE_THIS_MODULE("qf_port")
     //static const char *TAG = "qf_port";
    @@ -60,6 +61,14 @@ Q_DEFINE_THIS_MODULE("qf_port")
         #error "FreeRTOS configMAX_PRIORITIES must not be less than QF_MAX_ACTIVE"
     #endif
    
    +#if defined( CONFIG_QPC_PINNED_TO_CORE_0 )
    +    #define QPC_CPU_NUM         PRO_CPU_NUM
    +#elif defined( CONFIG_QPC_PINNED_TO_CORE_1 )
    +    #define QPC_CPU_NUM         APP_CPU_NUM
    +#else
    +    /* Defaults to APP_CPU */
    +    #define QPC_CPU_NUM         APP_CPU_NUM
    +#endif
    
     /* Global objects ----------------------------------------------------------*/
     PRIVILEGED_DATA portMUX_TYPE QF_esp32mux = portMUX_INITIALIZER_UNLOCKED;
    @@ -69,16 +78,28 @@ static void task_function(void *pvParameters); /* FreeRTOS task signature */
     int_t qf_run_active = 0;
    
     /*==========================================================================*/
    +static IRAM_ATTR void freertos_tick_hook(void)
    +{
    +    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    +    if(qf_run_active != 0) {
    +        /* process time events for rate 0 */
    +        QF_TICK_X_FROM_ISR(0U, &xHigherPriorityTaskWoken, &freertos_tick_hook);
    +        /* notify FreeRTOS to perform context switch from ISR, if needed */
    +        if(xHigherPriorityTaskWoken) {
    +            portYIELD_FROM_ISR();
    +        }
    +    }
    +}
    +/*..........................................................................*/
     void QF_init(void) {
    -    /* empty for FreeRTOS */
    -    /*portMUX_TYPE QF_esp32mux = portMUX_INITIALIZER_UNLOCKED;*/
    +    esp_register_freertos_tick_hook_for_cpu(freertos_tick_hook, QPC_CPU_NUM);
     }
     /*..........................................................................*/
     int_t QF_run(void) {
    -    //QF_onStartup();  /* the startup callback (configure/enable interrupts) */
    +    QF_onStartup();
         //vTaskStartScheduler(); /* start the FreeRTOS scheduler */
         //Q_ERROR_ID(110); /* the FreeRTOS scheduler should never return */
    -   qf_run_active = 100;
    +    qf_run_active = 100;
         return 0; /* dummy return to make the compiler happy */
     }
     /*..........................................................................*/
    @@ -121,7 +142,7 @@ void QActive_start_(QActive * const me, uint_fast8_t prio,
                   (UBaseType_t)(prio + tskIDLE_PRIORITY),  /* FreeRTOS priority */
                   (StackType_t *)stkSto,    /* stack storage */
                   &me->thread,              /* task buffer */
    -              1);                       /* CPU number */
    +              QPC_CPU_NUM);            /* CPU number */
         Q_ENSURE_ID(210, thr != (TaskHandle_t)0); /* must be created */
     }
     /*..........................................................................*/
    
     
  • Sicris Rey Embay

    Done with DPP demo on ESP32 and I found no issue so far.
    Raised pull request.

     
  • Harry Rostovtsev

    Thanks for posting your solutions. That's exactly what keeps these forums alive.

     
  • Quantum Leaps

    Quantum Leaps - 2021-06-29

    Just as an update, the following changes will be made to the experimental QP port to Espressif ESP-IDF:

    1. the port will be renamed from "freertos-esp32" to "esp-idf" to better match the terminology used by Espressif and to clearly distinguish it from the existing "freertos" port.
    2. the "esp-idf" port will have a RREADME.md file, which describes the "experimental" nature of the port
    3. the port itself will have the comments about the "experimental" nature and will contain the changes introduced by Sicris.

    The updated "esp-idf" port has been pushed to GitHub and is ready for preview. The port will be kept in the official QP/C releases.

    --MMS

     

    Last edit: Quantum Leaps 2021-06-29

Log in to post a comment.