Skip to content

Commit

Permalink
Merge pull request #20 from CR-Formula/freertos-fix
Browse files Browse the repository at this point in the history
Switch to FreeRTOS direct
  • Loading branch information
APBashara authored Sep 21, 2024
2 parents ecc8c99 + 4b12367 commit d51489e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 71 deletions.
48 changes: 7 additions & 41 deletions Core/Inc/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
/* USER CODE BEGIN Header */
/*
* FreeRTOS Kernel V10.3.1
* Portion Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Portion Copyright (C) 2019 StMicroelectronics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
/* USER CODE END Header */
/************************************************
* @file FreeRTOSConfig.h
* @author APBashara
* @date 9/2024
*
* @brief FreeRTOS Configuration File
***********************************************/

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
Expand All @@ -43,10 +21,6 @@
* See http://www.freertos.org/a00110.html
*----------------------------------------------------------*/

/* USER CODE BEGIN Includes */
/* Section where include file can be added */
/* USER CODE END Includes */

/* Ensure definitions are only used by the compiler, and not by the assembler. */
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
#include <stdint.h>
Expand Down Expand Up @@ -78,11 +52,9 @@
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
/* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */
/* Defaults to size_t for backward compatibility, but can be changed
if lengths will always be less than the number of bytes in a size_t. */
#define configMESSAGE_BUFFER_LENGTH_TYPE size_t
/* USER CODE END MESSAGE_BUFFER_LENGTH_TYPE */

/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
Expand Down Expand Up @@ -151,9 +123,7 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */

/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
/* USER CODE BEGIN 1 */
#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}
/* USER CODE END 1 */

/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
Expand All @@ -164,8 +134,4 @@ standard names. */

#define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 1

/* USER CODE BEGIN Defines */
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
/* USER CODE END Defines */

#endif /* FREERTOS_CONFIG_H */
13 changes: 12 additions & 1 deletion Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ extern "C" {
#endif

/* Includes -----------------------------------------------------------------*/
// OS Specific Includes
#include "FreeRTOS.h" /* Must come first. */
#include "task.h" /* RTOS task related API prototypes. */
#include "queue.h" /* RTOS queue related API prototypes. */
#include "timers.h" /* Software timer related API prototypes. */
#include "semphr.h" /* Semaphore related API prototypes. */
// Hardware Specific Includes
#include "stm32f4xx_hal.h"
#include "stm32f415xx.h"
#include "cmsis_os2.h"

#include <stdint.h>

Expand Down Expand Up @@ -62,6 +68,11 @@ typedef struct {
} Telemetry;

/* Functions prototypes -----------------------------------------------------*/

/**
* @brief Handles Systems Errors
* @note Currently holds LED on in infinite loop
*/
void Error_Handler(void);

/**
Expand Down
47 changes: 18 additions & 29 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,29 @@
/* Global Variables ---------------------------------------------------------*/
Telemetry telemetry;

/* Thread Attributes --------------------------------------------------------*/
osThreadId_t StatusLED;
const osThreadAttr_t StatusLED_attr = {
.name = "Status_Task",
.priority = osPriorityBelowNormal,
.stack_size = 128 * 4
};

osThreadId_t CANTask;
const osThreadAttr_t CANTask_attr = {
.name = "CAN_Task",
.priority = osPriorityNormal,
.stack_size = 128 * 4
};

osThreadId_t GPSTask;
const osThreadAttr_t GPSTask_attr = {
.name = "GPS_Task",
.priority = osPriorityNormal,
.stack_size = 128 * 4
};

/* Function Calls -----------------------------------------------------------*/
void main() {
osKernelInitialize(); // Initialize FreeRTOS
uint8_t Task_Status = 1;

// Initialize Peripherals
// Initialize Hardware
Sysclk_168();
LED_Init();
I2C1_Init();
CAN1_Init();
CAN_Filters_Init();
CAN_Start();

// Create FreeRTOS Threads
StatusLED = osThreadNew(Status_LED, NULL, &StatusLED_attr);
CANTask = osThreadNew(CAN_Task, NULL, &CANTask_attr);
GPSTask = osThreadNew(GPS_Task, NULL, &GPSTask_attr);
// Create FreeRTOS Tasks
Task_Status &= xTaskCreate(Status_LED, "Status_Task", 128, NULL, 1, NULL);
Task_Status &= xTaskCreate(CAN_Task, "CAN_Task", 128, NULL, 1, NULL);
Task_Status &= xTaskCreate(GPS_Task, "GPS_Task", 128, NULL, 1, NULL);

if (Task_Status != pdPASS) {
Error_Handler();
}

vTaskStartScheduler(); // Start FreeRTOS Scheduler

osKernelStart(); // Start FreeRTOS
while(1);
}

Expand Down Expand Up @@ -89,4 +73,9 @@ void GPS_Task() {
while(1) {
osDelay(1000);
}
}

void Error_Handler() {
Set_Pin(GPIOC, STATUS_LED_PIN);
while(1);
}

0 comments on commit d51489e

Please sign in to comment.