2020-08-25 01:06:50 +08:00
|
|
|
/* USER CODE BEGIN Header */
|
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* File Name : app_freertos.c
|
|
|
|
* Description : Code for freertos applications
|
|
|
|
******************************************************************************
|
|
|
|
* @attention
|
|
|
|
*
|
2022-03-08 05:51:17 +08:00
|
|
|
* Copyright (c) 2022 STMicroelectronics.
|
|
|
|
* All rights reserved.
|
2020-08-25 01:06:50 +08:00
|
|
|
*
|
2022-03-08 05:51:17 +08:00
|
|
|
* This software is licensed under terms that can be found in the LICENSE file
|
|
|
|
* in the root directory of this software component.
|
|
|
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
2020-08-25 01:06:50 +08:00
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
/* USER CODE END Header */
|
|
|
|
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
|
|
#include "FreeRTOS.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
/* Private includes ----------------------------------------------------------*/
|
2020-11-24 23:28:57 +08:00
|
|
|
/* USER CODE BEGIN Includes */
|
2020-08-25 01:06:50 +08:00
|
|
|
|
|
|
|
/* USER CODE END Includes */
|
|
|
|
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN PTD */
|
|
|
|
|
|
|
|
/* USER CODE END PTD */
|
|
|
|
|
|
|
|
/* Private define ------------------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN PD */
|
|
|
|
|
|
|
|
/* USER CODE END PD */
|
|
|
|
|
|
|
|
/* Private macro -------------------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN PM */
|
|
|
|
|
|
|
|
/* USER CODE END PM */
|
|
|
|
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN Variables */
|
|
|
|
|
|
|
|
/* USER CODE END Variables */
|
|
|
|
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN FunctionPrototypes */
|
2022-03-08 05:51:17 +08:00
|
|
|
|
2020-08-25 01:06:50 +08:00
|
|
|
/* USER CODE END FunctionPrototypes */
|
|
|
|
|
2020-08-30 22:20:00 +08:00
|
|
|
/* GetIdleTaskMemory prototype (linked to static allocation support) */
|
|
|
|
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );
|
|
|
|
|
2022-08-07 09:01:22 +08:00
|
|
|
/* Hook prototypes */
|
|
|
|
void vApplicationIdleHook(void);
|
|
|
|
|
|
|
|
/* USER CODE BEGIN 2 */
|
|
|
|
__weak void vApplicationIdleHook( void )
|
|
|
|
{
|
|
|
|
/* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
|
|
|
|
to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
|
|
|
|
task. It is essential that code added to this hook function never attempts
|
|
|
|
to block in any way (for example, call xQueueReceive() with a block time
|
|
|
|
specified, or call vTaskDelay()). If the application makes use of the
|
|
|
|
vTaskDelete() API function (as this demo application does) then it is also
|
|
|
|
important that vApplicationIdleHook() is permitted to return to its calling
|
|
|
|
function, because it is the responsibility of the idle task to clean up
|
|
|
|
memory allocated by the kernel to any task that has since been deleted. */
|
|
|
|
}
|
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
2020-08-30 22:20:00 +08:00
|
|
|
/* USER CODE BEGIN GET_IDLE_TASK_MEMORY */
|
|
|
|
static StaticTask_t xIdleTaskTCBBuffer;
|
|
|
|
static StackType_t xIdleStack[configMINIMAL_STACK_SIZE];
|
2022-03-08 05:51:17 +08:00
|
|
|
|
2020-08-30 22:20:00 +08:00
|
|
|
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
|
|
|
|
{
|
|
|
|
*ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
|
|
|
|
*ppxIdleTaskStackBuffer = &xIdleStack[0];
|
|
|
|
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
|
|
|
/* place for user code */
|
2022-03-08 05:51:17 +08:00
|
|
|
}
|
2020-08-30 22:20:00 +08:00
|
|
|
/* USER CODE END GET_IDLE_TASK_MEMORY */
|
|
|
|
|
2020-08-25 01:06:50 +08:00
|
|
|
/* Private application code --------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN Application */
|
2022-11-19 22:46:17 +08:00
|
|
|
/* The prototype shows it is a naked function - in effect this is just an
|
|
|
|
assembly function. */
|
|
|
|
void HardFault_Handler( void ) __attribute__( ( naked ) );
|
2022-03-08 05:51:17 +08:00
|
|
|
|
2022-11-19 22:46:17 +08:00
|
|
|
void prvGetRegistersFromStack( uint32_t *pulFaultStackAddress )
|
|
|
|
{
|
|
|
|
/* These are volatile to try and prevent the compiler/linker optimising them
|
|
|
|
away as the variables never actually get used. If the debugger won't show the
|
|
|
|
values of the variables, make them global my moving their declaration outside
|
|
|
|
of this function. */
|
|
|
|
volatile uint32_t r0;
|
|
|
|
volatile uint32_t r1;
|
|
|
|
volatile uint32_t r2;
|
|
|
|
volatile uint32_t r3;
|
|
|
|
volatile uint32_t r12;
|
|
|
|
volatile uint32_t lr; /* Link register. */
|
|
|
|
volatile uint32_t pc; /* Program counter. */
|
|
|
|
volatile uint32_t psr;/* Program status register. */
|
|
|
|
|
|
|
|
r0 = pulFaultStackAddress[ 0 ];
|
|
|
|
r1 = pulFaultStackAddress[ 1 ];
|
|
|
|
r2 = pulFaultStackAddress[ 2 ];
|
|
|
|
r3 = pulFaultStackAddress[ 3 ];
|
|
|
|
|
|
|
|
r12 = pulFaultStackAddress[ 4 ];
|
|
|
|
lr = pulFaultStackAddress[ 5 ];
|
|
|
|
pc = pulFaultStackAddress[ 6 ];
|
|
|
|
psr = pulFaultStackAddress[ 7 ];
|
|
|
|
|
|
|
|
/* When the following line is hit, the variables contain the register values. */
|
|
|
|
for( ;; );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The fault handler implementation calls a function called
|
|
|
|
prvGetRegistersFromStack(). */
|
|
|
|
void HardFault_Handler(void)
|
|
|
|
{
|
|
|
|
__asm volatile
|
|
|
|
(
|
|
|
|
" tst lr, #4 \n"
|
|
|
|
" ite eq \n"
|
|
|
|
" mrseq r0, msp \n"
|
|
|
|
" mrsne r0, psp \n"
|
|
|
|
" ldr r1, [r0, #24] \n"
|
|
|
|
" ldr r2, handler2_address_const \n"
|
|
|
|
" bx r2 \n"
|
|
|
|
" handler2_address_const: .word prvGetRegistersFromStack \n"
|
|
|
|
);
|
|
|
|
}
|
2020-08-25 01:06:50 +08:00
|
|
|
/* USER CODE END Application */
|
|
|
|
|