Skip to content

When use SPI device the task is crash after setCpuFrequencyMhz() (v2.0.3)  #6872

Closed
@LusterWong

Description

@LusterWong

Board

ESP32-WROVER-E

Device Description

DevKitC V4

Hardware Configuration

pin_sclk = 18;
pin_mosi = 23;
pin_miso = 19;
pin_dc = 21;

Version

v2.0.3

IDE Name

Sloeber

Operating System

Windows 10

Flash frequency

80Mhz

PSRAM enabled

yes

Upload speed

921000

Description

In projects using LCD, down the frequency to 80Mhz when idle.
Initialize LCD after call setCpuFrequencyMhz(80) and print the current frequency, which freezes each time.

Run the output from serial "in...." will task crash.

Sketch

#include "Arduino.h"
#include <TFT_eSPI.h>

static TFT_eSPI tft;

void setup() 
{
        Serial.begin(115200);
        Serial.println("Test!");
        tft.init();
        tft.startWrite();
}

loop()
{
        Serial.printf("in....\n");
        delay(200);
   
	if(setCpuFrequencyMhz(80) == true)          //<-------------------carsh-------------------
	{
		delay(200);
		Serial.printf("f = %d\n", getCpuFrequencyMhz());
	}
        else
        {
                Serial.printf("fail\n");
        }
        delay(60 * 1000L);
}

Debug Message

[     2-hal-cpu.c:214] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
[   843][I][esp32-hal-psram.c:96] psramInit(): PSRAM enabled 
in....
[  2742][D][esp32-hal-cpu.c:214] setCpuFrequencyMhz(): PLL: 320 / 4 = 80 Mhz, APB: 80000000 Hz

Other Steps to Reproduce

I tried setCpuFrequencyMhz(80) on another task and found that only the current task was crash, the loop() running normally .

#include "Arduino.h"
#include <TFT_eSPI.h>

static TFT_eSPI tft;

void TestTask(void* Parameter)
{
	delay(1000 * 15);
	while(1)
	{
		Serial.printf("in....\n");
                delay(200);
   
	        if(setCpuFrequencyMhz(80) == true)               //<-------------------carsh-------------------
	        {
		       delay(200);
		       Serial.printf("f = %d\n", getCpuFrequencyMhz());
	        }
                else
                {
                        Serial.printf("fail\n");
                }
	}
}

void setup() 
{
        Serial.begin(115200);
        Serial.println("Test!");

        xTaskCreate(TestTask, "TestTask", 4096, NULL, 1, NULL);
        tft.init();
        tft.startWrite();
}

loop()
{
        Serial.printf("run\n");          <----------------output per 5s
        delay(5 * 1000L);
}

### I have checked existing issues, online documentation and the Troubleshooting Guide

- [X] I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions