Verified Commit 74f3d92b authored by Artur Tynecki's avatar Artur Tynecki Committed by Vincent Coubard
Browse files

[Blinky] Convert FreeRTOS calls into CMSIS RTOS.


- Refactor main.c file to use CMSIS RTOS and GPIO HAL API
- Add FreeRTOS heap definition to application_helpers.c - common for both apps
- Remove FreeRTOS adaptation file.
- Move FreeRTOS configuration file to the common directory.
Signed-off-by: Vincent Coubard's avatarVincent Coubard <vincent.coubard@arm.com>
parent 90d6f871
......@@ -16,6 +16,7 @@ repos:
bsp/aws_configs/|
bsp/aws_libraries/|
bsp/freertos-platform/|
bsp/freertos-config/|
bsp/default_credentials/|
bsp/tf_m_targets/|
kws/ota/
......
# Copyright (c) 2021 ARM Limited. All rights reserved.
# Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.21)
......@@ -107,6 +107,7 @@ include(CTest)
target_include_directories(freertos-kernel
INTERFACE
${PRJ_DIR}/bsp/aws_configs
${PRJ_DIR}/bsp/freertos-config
${PRJ_DIR}/bsp/freertos-platform
${PRJ_DIR}/kws/include
)
......
......@@ -4,20 +4,20 @@
cmake_minimum_required(VERSION 3.21)
# Declare the blinky executable
add_executable(blinky
"${PRJ_DIR}/blinky/freertos_adaptation.c"
"${PRJ_DIR}/blinky/main_ns.c"
)
add_executable(blinky main.c)
target_link_libraries(blinky
startup
lib-bsp
tfm-ns-interface-cmsis-rtos
freertos-kernel-heap-4
mcu-driver-hal
cmsis-rtos-api
mcu-driver-bootstrap
mdh-reference-platforms-for-arm
freertos-cmsis-rtos
freertos-kernel
freertos-kernel-heap-2
tfm-ns-interface-cmsis-rtos
lib-bsp
startup
)
# Copy the result of TF-M build in the top level build directory
......
/*
* Copyright (c) 2021 Arm Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "FreeRTOS.h"
#include "stdio.h"
#include "task.h"
void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
{
printf("ERROR: Stack Overflow in task: %s", pcTaskName);
while (1)
;
}
/* 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)
{
/* If the buffers to be provided to the Idle task are declared inside this
function then they must be declared static - otherwise they will be allocated on
the stack and so not exists after this function exits. */
static StaticTask_t xIdleTaskTCB;
static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE];
/* Pass out a pointer to the StaticTask_t structure in which the Idle task's
state will be stored. */
*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
/* Pass out the array that will be used as the Idle task's stack. */
*ppxIdleTaskStackBuffer = uxIdleTaskStack;
/* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
Note that, as the array is necessarily of type StackType_t,
configMINIMAL_STACK_SIZE is specified in words, not bytes. */
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
}
/*-----------------------------------------------------------*/
/* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
application must provide an implementation of vApplicationGetTimerTaskMemory()
to provide the memory that is used by the Timer service task. */
void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
StackType_t **ppxTimerTaskStackBuffer,
uint32_t *pulTimerTaskStackSize)
{
/* If the buffers to be provided to the Timer task are declared inside this
function then they must be declared static - otherwise they will be allocated on
the stack and so not exists after this function exits. */
static StaticTask_t xTimerTaskTCB;
static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH];
/* Pass out a pointer to the StaticTask_t structure in which the Timer
task's state will be stored. */
*ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
/* Pass out the array that will be used as the Timer task's stack. */
*ppxTimerTaskStackBuffer = uxTimerTaskStack;
/* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
Note that, as the array is necessarily of type StackType_t,
configMINIMAL_STACK_SIZE is specified in words, not bytes. */
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}
/* Copyright (c) 2017-2022, Arm Limited and Contributors. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <stdlib.h>
#include "tfm_ns_interface.h"
#include "bsp_serial.h"
#include "cmsis_os2.h"
#include "hal/gpio_api.h"
extern uint32_t tfm_ns_interface_init(void);
static void app_task(void *arg)
{
(void)arg;
gpio_t led_gpio;
gpio_init_out(&led_gpio, LED1);
printf("The LED started blinking...\r\n");
while (1) {
gpio_write(&led_gpio, 1);
printf("LED on\r\n");
osDelay(1000u);
gpio_write(&led_gpio, 0);
printf("LED off\r\n");
osDelay(1000u);
}
}
int main()
{
bsp_serial_init();
uint32_t ret = tfm_ns_interface_init();
if (ret != 0) {
printf("tfm_ns_interface_init() failed: %d\r\n", ret);
return EXIT_FAILURE;
}
printf("Initialising kernel\r\n");
osStatus_t os_status = osKernelInitialize();
if (os_status != osOK) {
printf("osKernelInitialize failed: %d\r\n", os_status);
return EXIT_FAILURE;
}
osThreadId_t app_thread = osThreadNew(app_task, NULL, NULL);
if (!app_thread) {
printf("Failed to create app thread\r\n");
return EXIT_FAILURE;
}
osKernelState_t os_state = osKernelGetState();
if (os_state != osKernelReady) {
printf("Kernel not ready %d\r\n", os_state);
return EXIT_FAILURE;
}
printf("Starting kernel and threads\r\n");
os_status = osKernelStart();
if (os_status != osOK) {
printf("Failed to start kernel: %d\r\n", os_status);
return EXIT_FAILURE;
}
return 0;
}
/*
* Copyright (c) 2017-2021 Arm Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include "FreeRTOS.h"
#include "task.h"
#include "tfm_ns_interface.h"
#include "psa/protected_storage.h"
#include "bsp_serial.h"
/*
* Semihosting is a mechanism that enables code running on an ARM target
* to communicate and use the Input/Output facilities of a host computer
* that is running a debugger.
* There is an issue where if you use armclang at -O0 optimisation with
* no parameters specified in the main function, the initialisation code
* contains a breakpoint for semihosting by default. This will stop the
* code from running before main is reached.
* Semihosting can be disabled by defining __ARM_use_no_argv symbol
* (or using higher optimization level).
*/
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
__asm(" .global __ARM_use_no_argv\n");
#endif
extern uint32_t tfm_ns_interface_init(void);
uint8_t ucHeap[configTOTAL_HEAP_SIZE];
/*
* Main task to run TFM and ethernet communication testing
*/
static void blink_task(void *pvParameters)
{
uint32_t *fpgaio_leds = (uint32_t *)0x49302000;
const TickType_t xDelay = portTICK_PERIOD_MS * 200;
printf("FreeRTOS blink task started\r\n");
while (1) {
*fpgaio_leds = 0xFF;
printf("LED on\r\n");
vTaskDelay(xDelay);
*fpgaio_leds = 0x00;
printf("LED off\r\n");
vTaskDelay(xDelay);
}
}
int main()
{
tfm_ns_interface_init();
bsp_serial_init();
xTaskCreate(blink_task, "test task", configMINIMAL_STACK_SIZE * 2, NULL, configMAX_PRIORITIES - 2, NULL);
/* Start the scheduler itself. */
vTaskStartScheduler();
printf("End of main. Halting!\r\n");
while (1) {
}
}
/**
* @brief Defines the Ethos-U interrupt handler: just a wrapper around the default
* implementation.
**/
void arm_npu_irq_handler(void)
{
}
# Copyright (c) 2021 Arm Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from timeit import default_timer as timer
import pytest
......@@ -27,7 +15,9 @@ def test_blinky(fvp):
expectations = [
'Starting bootloader',
'Booting TF-M v1.6.0-RC3',
'FreeRTOS blink task started',
'Initialising kernel',
'Starting kernel and threads',
'The LED started blinking...',
'LED on',
'LED off',
'LED on',
......
# Copyright (c) 2021 ARM Limited. All rights reserved.
# Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.18)
......@@ -86,6 +86,7 @@ target_include_directories(${LIB_NAME}
${PRJ_DIR}/bsp/aws_libraries/freertos_plus/standard/tls/include
${PRJ_DIR}/bsp/aws_libraries/logging/include
${PRJ_DIR}/bsp/aws_libraries/3rdparty/lwip_osal/include
${PRJ_DIR}/bsp/freertos-config
${PRJ_DIR}/bsp/freertos-platform
)
......
/*
* Copyright (c) 2021 Arm Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/* Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include "stdio.h"
......@@ -28,6 +16,16 @@
#include "psa/protected_storage.h"
#include "psa/crypto.h"
/* -----------------------------------------------------------------------------
* Helper declarations
* -----------------------------------------------------------------------------
*/
/**
* Freertos heap declaration. It's required when configAPPLICATION_ALLOCATED_HEAP i set.
*/
#if (configAPPLICATION_ALLOCATED_HEAP == 1)
uint8_t ucHeap[configTOTAL_HEAP_SIZE];
#endif /* configAPPLICATION_ALLOCATED_HEAP */
/* -----------------------------------------------------------------------------
* Helper functions
......
/*
* Copyright (c) 2017-2021 Arm Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/* Copyright (c) 2017-2022, Arm Limited and Contributors. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include "stdio.h"
......@@ -68,8 +56,6 @@ extern uint32_t tfm_ns_interface_init(void);
#define FREERTOS_HIGHEST_TASK_PRIORITY (configMAX_PRIORITIES - 1)
uint8_t ucHeap[configTOTAL_HEAP_SIZE];
/**
* Network information
*/
......
# Copyright (c) 2021 ARM Limited. All rights reserved.
# Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
set(LIB_NAME FreeRTOS-Plus-TCP)
......@@ -32,6 +32,7 @@ add_library(${LIB_NAME} STATIC EXCLUDE_FROM_ALL
target_include_directories(${LIB_NAME}
PUBLIC
${PRJ_DIR}/bsp/aws_configs
${PRJ_DIR}/bsp/freertos-config
${freertos-plus-tcp_SOURCE_DIR}/include
${freertos-plus-tcp_SOURCE_DIR}/portable/Compiler/GCC
${TFM_PLATFORM_TARGET_DIR}/arm/mps3/an547
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment