Forum: Mikrocontroller und Digitale Elektronik esp32, CPU1 ganz für mich


von Martin B. (ratazong)


Angehängte Dateien:

Lesenswert?

Hallo zusammen,
der esp32 ist Dank seines RTOS nicht ganz echtzeitfähig. Man kann aber 
die CPU1 einfach ganz für sich bekommen.

Beispiel ist einfacher Rechteckgenerator:
Ich habe auf esp32-s3 getested mit der idf (bleeding edge), das sollte 
aber auch auf esp32 WROOM32 laufen:
1
/*
2
 * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
3
 *
4
 * SPDX-License-Identifier: Unlicense OR CC0-1.0
5
 */
6
7
#include <stdint.h>
8
#include "esp_log.h"
9
#include "freertos/FreeRTOS.h"
10
#include "freertos/task.h"
11
#include "driver/gpio.h"
12
#include "sdkconfig.h"
13
14
static const char *TAG = "example";
15
16
#define OUT_PORT 9
17
18
static volatile int cpu1Cnt=0;
19
20
/*------------------------------------------------------------------------*\
21
\*------------------------------------------------------------------------*/
22
void IRAM_ATTR task_cpu1(void *dummy)
23
{
24
  // first config the outputs
25
    gpio_config_t io_conf = {};
26
    //disable interrupt
27
    io_conf.intr_type = GPIO_INTR_DISABLE;
28
    //set as output mode
29
    io_conf.mode = GPIO_MODE_OUTPUT;
30
    //bit mask of the pins that you want to set,e.g.GPIO18/19
31
    io_conf.pin_bit_mask = (1<<OUT_PORT);
32
    //disable pull-down mode
33
    io_conf.pull_down_en = 0;
34
    //disable pull-up mode
35
    io_conf.pull_up_en = 0;
36
    //configure GPIO with the given settings
37
    gpio_config(&io_conf);
38
  
39
  // now disable interrupts for CPU1
40
  portDISABLE_INTERRUPTS();
41
  // never enable it again, so Taskscheduler will not steal cycles
42
  // DMA will steal them nevertheless
43
  // if you uncomment it, you will see interrutions of about 10 us every RTOS tick
44
  
45
#if 1  // slow version, generates about 1 MHz at fCPU = 160 MHz on ESP32-S3
46
  while(1)
47
  {
48
    gpio_set_level(OUT_PORT, 0);
49
    cpu1Cnt ++;
50
    gpio_set_level(OUT_PORT, 1);
51
  }
52
#else   // fast Version with direct access to the GPIO register
53
    // generates about 8 MHz square at fCPU = 160 MHz on esp32-s3
54
  // register addresses are valid only for esp32-s3
55
  volatile uint32_t * pGPIOw1tc = (uint32_t *)0x6000400c;
56
        volatile uint32_t * pGPIOw1ts = (uint32_t *)0x60004008;
57
        volatile uint32_t * pGPIOin = (uint32_t *)0x6000403c;
58
  while(1)
59
  {
60
    *pGPIOw1tc = (1 << OUT_PORT); // clear Port
61
    *pGPIOw1ts = (1 << OUT_PORT); // set Port
62
  }
63
#endif  
64
}
65
66
/*------------------------------------------------------------------------*\
67
\*------------------------------------------------------------------------*/
68
void tuwas(void)
69
{
70
    volatile int i,k,jj=0;
71
    for(k=0;k<10000;k++)
72
    {
73
        for(i=0;i<1000;i++) jj+= k+i;
74
    }
75
}
76
77
/*------------------------------------------------------------------------*\
78
\*------------------------------------------------------------------------*/
79
void app_main(void)
80
{
81
    ESP_LOGI(TAG, "Start CPU1");
82
    xTaskCreatePinnedToCore(task_cpu1, "tskCpu1", 2048, NULL, 10, NULL, 1);
83
    
84
  int Cnt=0;
85
  while (1)
86
  {
87
    ESP_LOGI(TAG,"Cnt = %d, cpu1Cnt = %d",Cnt,cpu1Cnt);
88
    Cnt++;
89
    tuwas();
90
  }
91
}

Damit das läuft, müssen Watchdogs disabled werden. Also idf Anleitung:

idf.py settarget esp32-s3
idf.py menuconfig
   bei menuconfig unter component config/esp system settings
   1) disable: Initialize task watchdog timer on startup
   2) disable: also watch cpu1 timer tick
idf.py - p yourComPort flash monitor

Wenn es mal einer mit dem normale esp probiert, mag der ja seine 
Ergenisse hier berichten. Ich habe gerade keinen zur Hand.

idf-projekt habe ich als zip angehängt. Vielleicht hilft es ja jemandem

-Martin

von Martin B. (ratazong)


Lesenswert?

huch, Formatierung ist mist.
habe wohl tabs und leerzeichen gemischt

von Wolfgang (Gast)


Lesenswert?

Martin B. schrieb:
> RTOS nicht ganz echtzeitfähig

Übersetze mal das "RT" von RTOS auf deutsch ;-)

"echtzeitfähig" ist eine ziemlich leere Buzz-Worthülse

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.