B4R Question ESP32 - using two cores

derez

Expert
Licensed User
Longtime User
ESP32 has two cores which can run in parallel. This link explain how to set and use them, in arduino IDE:
I would like to do the same for B4R. I found a reference to this function in the file "task.h" which is in this address "C:\Users\dudu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\tools\sdk\include\freertos\freertos\task.h"

B4X:
#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )

    static inline IRAM_ATTR BaseType_t xTaskCreate(
            TaskFunction_t pvTaskCode,
            const char * const pcName,
            const uint32_t usStackDepth,
            void * const pvParameters,
            UBaseType_t uxPriority,
            TaskHandle_t * const pvCreatedTask)
    {
        return xTaskCreatePinnedToCore( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pvCreatedTask, tskNO_AFFINITY );
    }

#endif

In file esp32_hal.h here C:\Users\dudu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32\esp32-hal.h

I found this:
B4X:
//if xCoreID < 0 or CPU is unicore, it will use xTaskCreate, else xTaskCreatePinnedToCore
//allows to easily handle all possible situations without repetitive code
BaseType_t xTaskCreateUniversal( TaskFunction_t pxTaskCode,
                        const char * const pcName,
                        const uint32_t usStackDepth,
                        void * const pvParameters,
                        UBaseType_t uxPriority,
                        TaskHandle_t * const pxCreatedTask,
                        const BaseType_t xCoreID );

I think the last function should be used.
Can anybody help with defining the inline c for this function ? I'm lost...
 
Last edited:

derez

Expert
Licensed User
Longtime User

This solution is good and I use it successfully but now I need to set cores from B4R directly, not inside the arduino code.
How to do it ?

Explanation:
The application of a clock showing time on Mcu TFT. Until I got the esp32 wemos I used two boards - UNO for the tft and nodemcu for reading time from NIST website.
ESP32 can do both but I think I need to split the tasks for the two cores, otherwise there is a slight delay, probably because and when it calls the website.
 
Last edited:
Upvote 0
Top