查看: 793|回复: 5

请教,arduino如何开发ESP32上面的双核?

[复制链接]

该用户从未签到

发表于 2018-11-29 16:19 | 显示全部楼层 |阅读模式
本帖最后由 kylongmu 于 2018-12-4 22:10 编辑

ESP32具有两个核心,arduino开发的程序如何用到它们呢?由于只有一个loop入口,不知道如何放多核代码。
partitions.jpg
D:\Arduino\hardware\arduino-esp32\esp32\tools\partitions
从分区文件看有app0、app1两个应用程序分段,但是如何开发两个app并把他们写入到各自的flash,又是如何共享交互数据呢?//追加-----------------------------------------------
现在搞清楚了app0、app1是用来做OTA升级用的,不是写两个core的app。


  • TA的每日心情
    郁闷
    2018-12-6 22:21
  • 签到天数: 48 天

    [LV.5]常住居民I

    发表于 2018-11-29 17:09 | 显示全部楼层
    arduino应该是不行的
    如果以上内容对你有帮助,你可以通过打赏支持作者

    该用户从未签到

     楼主| 发表于 2018-11-29 21:02 | 显示全部楼层
    这么看来arduino的发展落后了,esp32用单核版的就可以了,双核版纯浪费啊。
    以后需要有loop_01()、loop_02()来做多核心的支持。

    该用户从未签到

     楼主| 发表于 2018-12-4 21:57 | 显示全部楼层
    本帖最后由 kylongmu 于 2018-12-4 22:07 编辑

    找到了一篇说明:
    https://techtutorialsx.com/2017/05/09/esp32-running-code-on-a-specific-core/
    看意思应该是只需要启动FreeRtOS的多TASK就能利用多核。在tools\sdk\include\freertos\freertos\task.h中有如下函数:

    kittenblock中小学创客名师推荐的图形化编程软件

    /*-----------------------------------------------------------
     * TASK CREATION API
     *----------------------------------------------------------*/
    
    /**
     * Create a new task with a specified affinity.
     *
     * This function is similar to xTaskCreate, but allows setting task affinity
     * in SMP system.
     *
     * @param pvTaskCode Pointer to the task entry function.  Tasks
     * must be implemented to never return (i.e. continuous loop).
     *
     * @param pcName A descriptive name for the task.  This is mainly used to
     * facilitate debugging.  Max length defined by configMAX_TASK_NAME_LEN - default
     * is 16.
     *
     * @param usStackDepth The size of the task stack specified as the number of
     * variables the stack can hold - not the number of bytes.  For example, if
     * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
     * will be allocated for stack storage.
     *
     * @param pvParameters Pointer that will be used as the parameter for the task
     * being created.
     *
     * @param uxPriority The priority at which the task should run.  Systems that
     * include MPU support can optionally create tasks in a privileged (system)
     * mode by setting bit portPRIVILEGE_BIT of the priority parameter.  For
     * example, to create a privileged task at priority 2 the uxPriority parameter
     * should be set to ( 2 | portPRIVILEGE_BIT ).
     *
     * @param pvCreatedTask Used to pass back a handle by which the created task
     * can be referenced.
     *
     * @param xCoreID If the value is tskNO_AFFINITY, the created task is not
     * pinned to any CPU, and the scheduler can run it on any core available.
     * Other values indicate the index number of the CPU which the task should
     * be pinned to. Specifying values larger than (portNUM_PROCESSORS - 1) will
     * cause the function to fail.
     *
     * @return pdPASS if the task was successfully created and added to a ready
     * list, otherwise an error code defined in the file projdefs.h
     *
     * \ingroup Tasks
     */
    #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
            BaseType_t xTaskCreatePinnedToCore(        TaskFunction_t pvTaskCode,
                                                                                    const char * const pcName,
                                                                                    const uint32_t usStackDepth,
                                                                                    void * const pvParameters,
                                                                                    UBaseType_t uxPriority,
                                                                                    TaskHandle_t * const pvCreatedTask,
                                                                                    const BaseType_t xCoreID);
    
    #endif
    

  • TA的每日心情
    开心
    2018-12-18 11:05
  • 签到天数: 1 天

    [LV.1]初来乍到

    发表于 2018-12-18 11:09 | 显示全部楼层
    两个核创建任务的函数是不同的  用对应函数使用对应的核

    该用户从未签到

     楼主| 发表于 2018-12-21 09:08 | 显示全部楼层

    kittenblock中小学创客名师推荐的图形化编程软件

    #ifndef LED_BUILTIN
    #define LED_BUILTIN 33
    #endif
    
    // define two tasks for Blink & AnalogRead
    void TaskBlink( void *pvParameters );
    void TaskAnalogReadA3( void *pvParameters );
    
    // the setup function runs once when you press reset or power the board
    void setup() {
      
      // initialize serial communication at 115200 bits per second:
      Serial.begin(115200);
      
      // Now set up two tasks to run independently.
      xTaskCreatePinnedToCore(
        TaskBlink
        ,  "TaskBlink"   // A name just for humans
        ,  1024  // This stack size can be checked & adjusted by reading the Stack Highwater
        ,  NULL
        ,  2  // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
        ,  NULL 
        ,  0);
    
      xTaskCreatePinnedToCore(
        TaskAnalogReadA3
        ,  "AnalogReadA3"
        ,  1024  // Stack size
        ,  NULL
        ,  1  // Priority
        ,  NULL 
        ,  1);
    
      // Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started.
    }
    
    void loop()
    {
      // Empty. Things are done in Tasks.
    }
    
    /*--------------------------------------------------*/
    /*---------------------- Tasks ---------------------*/
    /*--------------------------------------------------*/
    
    void TaskBlink(void *pvParameters)  // This is a task.
    {
      (void) pvParameters;
    
    /*
      Blink
      Turns on an LED on for one second, then off for one second, repeatedly.
        
      If you want to know what pin the on-board LED is connected to on your ESP32 model, check
      the Technical Specs of your board.
    */
        String taskMessage = "Task running on core ";
        taskMessage = taskMessage + xPortGetCoreID();
     
    
      // initialize digital LED_BUILTIN on pin 13 as an output.
      pinMode(LED_BUILTIN, OUTPUT);
    
      for (;;) // A Task shall never return or exit.
      {
        digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
        vTaskDelay(500);  // one tick delay (15ms) in between reads for stability
        digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
        vTaskDelay(500);  // one tick delay (15ms) in between reads for stability
        Serial.println(taskMessage);
      }
    }
    
    void TaskAnalogReadA3(void *pvParameters)  // This is a task.
    {
      (void) pvParameters;
      
    /*
      AnalogReadSerial
      Reads an analog input on pin A3, prints the result to the serial monitor.
      Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
      Attach the center pin of a potentiometer to pin A3, and the outside pins to +5V and ground.
    
      This example code is in the public domain.
    */
        String taskMessage = "Task running on core ";
        taskMessage = taskMessage + xPortGetCoreID();
    
      for (;;)
      {
        // read the input on analog pin A3:
        int sensorValueA3 = analogRead(A3);
        // print out the value you read:
        Serial.println(sensorValueA3);
        Serial.println(taskMessage);
        vTaskDelay(1000);  // one tick delay (15ms) in between reads for stability
      }
    }

    自测的代码,实现了双核运行。
    您需要登录后才可以回帖 登录 | 立即注册  

    本版积分规则

    热门推荐

    博哥零基础教你玩转ESP8266(十三) ESP8266WiFiGeneric库
    博哥零基础教你玩转ESP826
    帖子导航帖 博哥零基础教你玩转ESP8266(一) 重识ESP8266 博哥零基础教你玩转ESP8266
    求助!WeMos D1 WiFi怎么接0.96寸OLED?(ㄒoㄒ)
    求助!WeMos D1 WiFi怎么
    求助!WeMos D1 WiFi怎么接0.96寸OLED?(ㄒoㄒ) 想用WeMos D1 WiFi接收服务器的数据然
    串口发送16进制指令求助
    串口发送16进制指令求助
    我准备串口发出16进制指令到我的外置设备 代码如下图 我分别监控ARDUINO的tx口和USB口
    一文教你选择Arduino开发板,小白进
    一文教你选择Arduino开发
    笔者在2016年接触了Arduino,跳了万条坑,行了千里弯,到今天也算是Arduino的一
    大神们!1602显示屏上的MQ2浓度示数不是实时监测的何解
    大神们!1602显示屏上的MQ
    本人小白,刚刚接触arduino,长时间的查阅资料后,通过复制修改代码接线实现了DHT11实
    Copyright   ©2015-2016  Arduino中文社区  Powered by©Discuz!   ( 蜀ICP备14017632号-3 )
    快速回复 返回顶部 返回列表