esp32c3 - build project and flash successfully but RGB Led doesn't blink accordingly

User avatar
666hjk
Posts: 47
Joined: Wed Jan 12, 2022 3:09 am
Location: 小红点

esp32c3 - build project and flash successfully but RGB Led doesn't blink accordingly

Postby 666hjk » Sat Aug 06, 2022 12:37 pm

Hi,

i've build the below project and flash to my esp32c3 successfully (see below , main , 2 cmakelists & output from terminal ) . press on the reset button but the RGBLed doesn't start blinking accordingly.

what have i miss out? any help appreciated. thanks.

=====================================================


main code >> RGBLed.c

#include <stdio.h>
#include <time.h>
#include <string.h>
#include <math.h>
#include "driver/gpio.h"
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#define LED_R_PIN 3
#define LED_G_PIN 4
#define LED_B_PIN 5

void app_main(void)
{
printf("C3 LEDs");
gpio_pad_select_gpio(LED_R_PIN);
gpio_set_direction(LED_R_PIN, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(LED_G_PIN);
gpio_set_direction(LED_G_PIN, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(LED_B_PIN); // select pin
gpio_set_direction(LED_B_PIN, GPIO_MODE_OUTPUT); // select ON/OFF

while(1) {
gpio_set_level(LED_R_PIN, 1); // red ON // red flicking
vTaskDelay( 500/portTICK_PERIOD_MS );
gpio_set_level(LED_R_PIN, 0 ); // red OFF
vTaskDelay( 500/portTICK_PERIOD_MS );
gpio_set_level(LED_G_PIN, 1); // green ON // green flicking
vTaskDelay( 500/portTICK_PERIOD_MS );
gpio_set_level(LED_G_PIN, 0 ); // green OFF
vTaskDelay( 500/portTICK_PERIOD_MS );
gpio_set_level(LED_B_PIN, 1); // blue ON // blue flicking
vTaskDelay( 500/portTICK_PERIOD_MS );
gpio_set_level(LED_B_PIN, 0 ); // blue OFF
vTaskDelay( 500/portTICK_PERIOD_MS );
gpio_set_level(LED_R_PIN, 1 ); // mix color // red ON
gpio_set_level(LED_G_PIN, 1 ); // mix color // green ON
gpio_set_level(LED_B_PIN, 0 ); // mix color // blue OFF
vTaskDelay( 500/portTICK_PERIOD_MS );
gpio_set_level(LED_R_PIN, 0 ); // mix color // red OFF
gpio_set_level(LED_G_PIN, 1 ); // mix color // green ON
gpio_set_level(LED_B_PIN, 1 ); // mix color // blue ON
vTaskDelay( 500/portTICK_PERIOD_MS );
gpio_set_level(LED_R_PIN, 1 ); // mix color // red ON
gpio_set_level(LED_G_PIN, 0 ); // mix color // green OFF
gpio_set_level(LED_B_PIN, 1 ); // mix color // blue ON
vTaskDelay( 500/portTICK_PERIOD_MS );
gpio_set_level(LED_R_PIN, 1 ); // mix color // red ON
gpio_set_level(LED_G_PIN, 1 ); // mix color // green ON
gpio_set_level(LED_B_PIN, 1 ); // mix color // blue ON
vTaskDelay( 500/portTICK_PERIOD_MS );
gpio_set_level(LED_R_PIN, 0 ); // mix color // red OFF
gpio_set_level(LED_G_PIN, 0 ); // mix color // green OFF
gpio_set_level(LED_B_PIN, 0 ); // mix color // blue OFF
vTaskDelay( 500/portTICK_PERIOD_MS );
}
}
====================================================================================================
CMakeLists.txt in main folder

idf_component_register(SRCS "RGBLed.c"
INCLUDE_DIRS ".")


====================================================================================================
project CMakeLists.txt

# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(RGBLed)

=====================================================================================================

output from flashing

ar@xox:~/esp/RGBLed$ idf.py -p /dev/ttyUSB0 -b 115200 flash
Executing action: flash
Running ninja in directory /home/ar/esp/RGBLed/build
Executing "ninja flash"...
[1/5] cd /home/ar/esp/RGBLed/build/e.../home/ar/esp/RGBLed/build/RGBLed.bin
RGBLed.bin binary size 0x252a0 bytes. Smallest app partition is 0x100000 bytes. 0xdad60 bytes (85%) free.
[2/5] Performing build step for 'bootloader'
[1/1] cd /home/ar/esp/RGBLed/build/bootloader/esp-idf/esptool_py && /home/ar/.espressif/python_env/idf4.4_py3.6_env/bin/python /home/ar/esp/esp-idf/components/partition_table/check_sizes.py --offset 0x8000 bootloader 0x0 /home/ar/esp/RGBLed/build/bootloader/bootloader.bin
Bootloader binary size 0x4d60 bytes. 0x32a0 bytes (40%) free.
[2/3] cd /home/ar/esp/esp-idf/compon...nents/esptool_py/run_serial_tool.cmake
esptool.py esp32c3 -p /dev/ttyUSB0 -b 115200 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 2MB 0x0 bootloader/bootloader.bin 0x10000 RGBLed.bin 0x8000 partition_table/partition-table.bin
esptool.py v3.3.2-dev
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-C3 (revision 3)
Features: Wi-Fi
Crystal is 40MHz
MAC: 7c:df:a1:df:e4:e4
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00004fff...
Flash will be erased from 0x00010000 to 0x00035fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Compressed 19808 bytes to 12015...
Writing at 0x00000000... (100 %)
Wrote 19808 bytes (12015 compressed) at 0x00000000 in 1.5 seconds (effective 106.9 kbit/s)...
Hash of data verified.
Compressed 152224 bytes to 81772...
Writing at 0x00010000... (20 %)
Writing at 0x00019a02... (40 %)
Writing at 0x0002034c... (60 %)
Writing at 0x000275ca... (80 %)
Writing at 0x0002dd9e... (100 %)
Wrote 152224 bytes (81772 compressed) at 0x00010000 in 7.6 seconds (effective 159.2 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 103...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.1 seconds (effective 264.4 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
Done
学习中找战友。

Who is online

Users browsing this forum: Baidu [Spider] and 114 guests