Skip to content

Commit 3195fa3

Browse files
committed
Add FreeRTOS to container image and demo project
1 parent 3d8b06e commit 3195fa3

File tree

4 files changed

+219
-1
lines changed

4 files changed

+219
-1
lines changed

Dockerfile

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,21 @@ RUN apk update && \
1414
gcc-arm-none-eabi
1515

1616
# Raspberry Pi Pico SDK
17-
ARG SDK_PATH=/usr/share/pico_sdk
17+
ARG SDK_PATH=/usr/local/picosdk
1818
RUN git clone --depth 1 --branch 1.5.1 https://github.com/raspberrypi/pico-sdk $SDK_PATH && \
1919
cd $SDK_PATH && \
2020
git submodule update --init
2121

2222
ENV PICO_SDK_PATH=$SDK_PATH
2323

24+
# FreeRTOS
25+
ARG FREERTOS_PATH=/usr/local/freertos
26+
RUN git clone --depth 1 --branch V11.0.1 https://github.com/FreeRTOS/FreeRTOS-Kernel $FREERTOS_PATH && \
27+
cd $FREERTOS_PATH && \
28+
git submodule update --init --recursive
29+
30+
ENV FREERTOS_KERNEL_PATH=$FREERTOS_PATH
31+
2432
# Picotool installation
2533
RUN git clone --depth 1 --branch 1.1.2 https://github.com/raspberrypi/picotool.git /home/picotool && \
2634
cd /home/picotool && \

freertos_test_project/CMakeLists.txt

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
4+
include($ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake)
5+
6+
set(CMAKE_C_COMPILER /usr/bin/arm-none-eabi-gcc CACHE PATH "" FORCE)
7+
set(CMAKE_CXX_COMPILER /usr/bin/arm-none-eabi-g++ CACHE PATH "" FORCE)
8+
9+
project(freertos_demo C CXX ASM)
10+
11+
set(CMAKE_C_STANDARD 11)
12+
set(CMAKE_CXX_STANDARD 17)
13+
14+
pico_sdk_init()
15+
16+
add_library(FreeRTOS-Config INTERFACE)
17+
target_include_directories(FreeRTOS-Config INTERFACE ${CMAKE_SOURCE_DIR}/config)
18+
19+
add_executable(freertos_demo main.cpp)
20+
21+
target_include_directories(freertos_demo PRIVATE ${CMAKE_CURRENT_LIST_DIR})
22+
23+
target_link_libraries(freertos_demo
24+
pico_stdlib
25+
FreeRTOS-Config
26+
FreeRTOS-Kernel
27+
FreeRTOS-Kernel-Heap4)
28+
29+
pico_add_extra_outputs(freertos_demo)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* FreeRTOS V202107.00
3+
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
* this software and associated documentation files (the "Software"), to deal in
7+
* the Software without restriction, including without limitation the rights to
8+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
* the Software, and to permit persons to whom the Software is furnished to do so,
10+
* subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
*
22+
* http://www.FreeRTOS.org
23+
* http://aws.amazon.com/freertos
24+
*
25+
* 1 tab == 4 spaces!
26+
*/
27+
28+
#ifndef FREERTOS_CONFIG_H
29+
#define FREERTOS_CONFIG_H
30+
31+
/*-----------------------------------------------------------
32+
* Application specific definitions.
33+
*
34+
* These definitions should be adjusted for your particular hardware and
35+
* application requirements.
36+
*
37+
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
38+
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
39+
*
40+
* See http://www.freertos.org/a00110.html
41+
*----------------------------------------------------------*/
42+
43+
/* Scheduler Related */
44+
#define configUSE_PREEMPTION 1
45+
#define configUSE_TICKLESS_IDLE 0
46+
#define configUSE_IDLE_HOOK 0
47+
#define configUSE_TICK_HOOK 1
48+
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
49+
#define configMAX_PRIORITIES 32
50+
#define configMINIMAL_STACK_SIZE ( configSTACK_DEPTH_TYPE ) 256
51+
#define configUSE_16_BIT_TICKS 0
52+
53+
#define configIDLE_SHOULD_YIELD 1
54+
55+
/* Synchronization Related */
56+
#define configUSE_MUTEXES 1
57+
#define configUSE_RECURSIVE_MUTEXES 1
58+
#define configUSE_APPLICATION_TASK_TAG 0
59+
#define configUSE_COUNTING_SEMAPHORES 1
60+
#define configQUEUE_REGISTRY_SIZE 8
61+
#define configUSE_QUEUE_SETS 1
62+
#define configUSE_TIME_SLICING 1
63+
#define configUSE_NEWLIB_REENTRANT 0
64+
#define configENABLE_BACKWARD_COMPATIBILITY 1
65+
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
66+
67+
/* System */
68+
#define configSTACK_DEPTH_TYPE uint32_t
69+
#define configMESSAGE_BUFFER_LENGTH_TYPE size_t
70+
71+
/* Memory allocation related definitions. */
72+
#define configSUPPORT_STATIC_ALLOCATION 0
73+
#define configSUPPORT_DYNAMIC_ALLOCATION 1
74+
#define configTOTAL_HEAP_SIZE (128*1024)
75+
#define configAPPLICATION_ALLOCATED_HEAP 0
76+
77+
/* Hook function related definitions. */
78+
#define configCHECK_FOR_STACK_OVERFLOW 2
79+
#define configUSE_MALLOC_FAILED_HOOK 1
80+
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
81+
82+
/* Run time and task stats gathering related definitions. */
83+
#define configGENERATE_RUN_TIME_STATS 0
84+
#define configUSE_TRACE_FACILITY 1
85+
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
86+
87+
/* Co-routine related definitions. */
88+
#define configUSE_CO_ROUTINES 0
89+
#define configMAX_CO_ROUTINE_PRIORITIES 1
90+
91+
/* Software timer related definitions. */
92+
#define configUSE_TIMERS 1
93+
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
94+
#define configTIMER_QUEUE_LENGTH 10
95+
#define configTIMER_TASK_STACK_DEPTH 1024
96+
97+
/* Interrupt nesting behaviour configuration. */
98+
/*
99+
#define configKERNEL_INTERRUPT_PRIORITY [dependent of processor]
100+
#define configMAX_SYSCALL_INTERRUPT_PRIORITY [dependent on processor and application]
101+
#define configMAX_API_CALL_INTERRUPT_PRIORITY [dependent on processor and application]
102+
*/
103+
104+
/* SMP port only */
105+
#define configNUM_CORES 2
106+
#define configTICK_CORE 0
107+
#define configRUN_MULTIPLE_PRIORITIES 1
108+
#define configSUPPORT_PICO_SYNC_INTEROP 1
109+
#define configSUPPORT_PICO_TIME_INTEROP 1
110+
111+
#include <assert.h>
112+
/* Define to trap errors during development. */
113+
#define configASSERT(x) assert(x)
114+
115+
/* Set the following definitions to 1 to include the API function, or zero
116+
to exclude the API function. */
117+
#define INCLUDE_vTaskPrioritySet 1
118+
#define INCLUDE_uxTaskPriorityGet 1
119+
#define INCLUDE_vTaskDelete 1
120+
#define INCLUDE_vTaskSuspend 1
121+
#define INCLUDE_vTaskDelayUntil 1
122+
#define INCLUDE_vTaskDelay 1
123+
#define INCLUDE_xTaskGetSchedulerState 1
124+
#define INCLUDE_xTaskGetCurrentTaskHandle 1
125+
#define INCLUDE_uxTaskGetStackHighWaterMark 1
126+
#define INCLUDE_xTaskGetIdleTaskHandle 1
127+
#define INCLUDE_eTaskGetState 1
128+
#define INCLUDE_xTimerPendFunctionCall 1
129+
#define INCLUDE_xTaskAbortDelay 1
130+
#define INCLUDE_xTaskGetHandle 1
131+
#define INCLUDE_xTaskResumeFromISR 1
132+
#define INCLUDE_xQueueGetMutexHolder 1
133+
134+
/* A header file that defines trace macro can be included here. */
135+
136+
#endif /* FREERTOS_CONFIG_H */

freertos_test_project/main.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "FreeRTOS.h"
2+
#include "task.h"
3+
#include <stdio.h>
4+
#include "pico/stdlib.h"
5+
#include "hardware/gpio.h"
6+
7+
#ifdef __cplusplus
8+
extern "C" {
9+
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
10+
void vApplicationTickHook( void );
11+
void vApplicationMallocFailedHook( void );
12+
}
13+
#endif
14+
15+
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName ) {}
16+
void vApplicationTickHook( void ) {}
17+
void vApplicationMallocFailedHook( void ) {}
18+
19+
void vBlink(void* unused_arg) {
20+
21+
for (;;) {
22+
23+
gpio_put(PICO_DEFAULT_LED_PIN, 1);
24+
25+
vTaskDelay(250);
26+
27+
gpio_put(PICO_DEFAULT_LED_PIN, 0);
28+
29+
vTaskDelay(250);
30+
31+
}
32+
33+
}
34+
35+
int main() {
36+
37+
gpio_init(PICO_DEFAULT_LED_PIN);
38+
39+
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
40+
41+
xTaskCreate(vBlink, "Blink", 128, NULL, 1, NULL);
42+
43+
vTaskStartScheduler();
44+
45+
}

0 commit comments

Comments
 (0)