Skip to content

Commit

Permalink
Esp32 FreeRTOS hello_world project
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeStone20 committed Aug 26, 2021
1 parent dc0da03 commit 0583412
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
52 changes: 52 additions & 0 deletions FreeRTOSHelloWorld/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
cmake_minimum_required(VERSION 3.13)

set(esp_idf_dir "${CMAKE_CURRENT_LIST_DIR}/FreeRTOS/vendors/espressif/esp-idf")
include(${esp_idf_dir}/tools/cmake/idf.cmake)
string(FIND "${CMAKE_TOOLCHAIN_FILE}" "esp32s2" SOC_TOOLCHAIN_ESP32S2)
string(FIND "${CMAKE_TOOLCHAIN_FILE}" "esp32" SOC_TOOLCHAIN_ESP32)
if (NOT(${SOC_TOOLCHAIN_ESP32S2} EQUAL -1))
set(SOC_NAME "esp32s2")
elseif(NOT($SOC_TOOLCHAIN_ESP32) EQUAL -1)
set(SOC_NAME "esp32")
endif()

project(freertos_examples)

# Tell IDF build to link against this target.
set(IDF_PROJECT_EXECUTABLE afr_demo)
get_filename_component(
IDF_EXECUTABLE_SRCS
"src/main.c" ABSOLUTE
)

# Add some extra components. IDF_EXTRA_COMPONENT_DIRS is an variable used by ESP-IDF
# to collect extra components.
#get_filename_component(
# EXTRA_COMPONENT_DIRS
# "components/foo" ABSOLUTE
#)
#idf_build_component(${EXTRA_COMPONENT_DIRS})

# As of now there's no offical way to redefine config files outside of FreeRTOS source tree.
# This is a temporary approach to inject an include path so that this takes precedence over the
# config file directory inside FreeRTOS.
include_directories(BEFORE freertos-configs)

# Add freertos as an subdirectory. AFR_BOARD tells which board to target.
if ("${SOC_NAME}" STREQUAL "esp32s2")
set(AFR_BOARD espressif.esp32s2_saola_1 CACHE INTERNAL "")
elseif("${SOC_NAME}" STREQUAL "esp32")
set(AFR_BOARD espressif.esp32_devkitc CACHE INTERNAL "")
endif()
add_subdirectory(FreeRTOS)

# Link against the mqtt demo so that we can use it. Dependencies of this demo are transitively
# linked.
#target_link_libraries(
# AFR::greengrass
# afr_demo
# PRIVATE
# AFR::demo_core_mqtt
# AFR::common_io
# idf::foo
#)
71 changes: 71 additions & 0 deletions FreeRTOSHelloWorld/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <stdio.h>
#include "FreeRTOS.h"
#include "task.h"
#include "esp_system.h"
#define PIN_OUT 13

void vHelloWorld(void *pvParams)
{
while(1){
printf("HelloWorld!\n");
vTaskDelay(pdMS_TO_TICKS(1000));
}
}

void app_main()
{
xTaskCreate(vHelloWorld, "HelloWorld", 1024, NULL, 2, NULL);
}

/*-----------------------------------------------------------*/
extern void esp_vApplicationTickHook();
void IRAM_ATTR vApplicationTickHook()
{
esp_vApplicationTickHook();
}

extern void esp_vApplicationIdleHook();
void vApplicationIdleHook()
{
esp_vApplicationIdleHook();
}

void vApplicationDaemonTaskStartupHook()
{
}

/*-----------------------------------------------------------*/

/* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
* implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
* used by the Idle task. */
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
StackType_t **ppxIdleTaskStackBuffer,
uint32_t *pulIdleTaskStackSize)
{
static StaticTask_t xIdleTaskTCB;
static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE];
*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
*ppxIdleTaskStackBuffer = uxIdleTaskStack;
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
}
/*-----------------------------------------------------------*/

/**
* @brief This is to provide the memory that is used by the RTOS daemon/time task.
*
* If configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
* implementation of vApplicationGetTimerTaskMemory() to provide the memory that is
* used by the RTOS daemon/time task.
*/
void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
StackType_t **ppxTimerTaskStackBuffer,
uint32_t *pulTimerTaskStackSize)
{
static StaticTask_t xTimerTaskTCB;
static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH];

*ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
*ppxTimerTaskStackBuffer = uxTimerTaskStack;
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}

0 comments on commit 0583412

Please sign in to comment.