Skip to content

Instantly share code, notes, and snippets.

@Gfast2
Created November 18, 2017 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gfast2/85535b71b2d5aec47e99bc7339ce2c34 to your computer and use it in GitHub Desktop.
Save Gfast2/85535b71b2d5aec47e99bc7339ce2c34 to your computer and use it in GitHub Desktop.
A "binky" Example on ESP32 using ESP-IDF FreeRTOS, which address potential bug when man use while(1) in main_app() with vTaskDelayUntil to deal with delay job.
/* Demo program.
* https://esp32.com/viewtopic.php?f=2&t=3389
* esp-idf git commit: 7e8c2a9c00a6fb05cd5da306b62c4474a999b1a2
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#define BLINK_GPIO CONFIG_BLINK_GPIO
void app_main()
{
printf("Hello world!\n");
/* Print chip information */
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
printf("This is the second test.");
printf("This is ESP32 chip with %d CPU cores, WiFi%s%s, ",
chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
printf("silicon revision %d, ", chip_info.revision);
printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
gpio_pad_select_gpio(BLINK_GPIO);
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
TickType_t xLastWakeTime;
xLastWakeTime = xTaskGetTickCount();
const TickType_t xFrequency = (500 / portTICK_PERIOD_MS);
long a = 0;
while(1){
/* LED off */
gpio_set_level(BLINK_GPIO, 0);
vTaskDelayUntil( &xLastWakeTime, xFrequency);
/* LED on */
gpio_set_level(BLINK_GPIO, 1);
vTaskDelayUntil( &xLastWakeTime, xFrequency);
printf("Hi %ld\n",a++);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment