Use AzureRTOS ThreadX
This commit is contained in:
13
Core/Src/app.c
Normal file
13
Core/Src/app.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include "app.h"
|
||||
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "tx_api.h"
|
||||
|
||||
#include "main.h"
|
||||
|
||||
void app_thread_entry(ULONG _) {
|
||||
while (1) {
|
||||
HAL_GPIO_TogglePin(STATUS1_GPIO_Port, STATUS1_Pin);
|
||||
tx_thread_sleep(50);
|
||||
}
|
||||
}
|
||||
89
Core/Src/app_threadx.c
Normal file
89
Core/Src/app_threadx.c
Normal file
@ -0,0 +1,89 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file app_threadx.c
|
||||
* @author MCD Application Team
|
||||
* @brief ThreadX applicative file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2020-2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "app_threadx.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* 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 PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/**
|
||||
* @brief Application ThreadX Initialization.
|
||||
* @param memory_ptr: memory pointer
|
||||
* @retval int
|
||||
*/
|
||||
UINT App_ThreadX_Init(VOID *memory_ptr) {
|
||||
UINT ret = TX_SUCCESS;
|
||||
|
||||
/* USER CODE BEGIN App_ThreadX_Init */
|
||||
// This function is only called with static allocation, but we use dynamic
|
||||
// allocation.
|
||||
/* USER CODE END App_ThreadX_Init */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function that implements the kernel's initialization.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void MX_ThreadX_Init(void) {
|
||||
/* USER CODE BEGIN Before_Kernel_Start */
|
||||
|
||||
/* USER CODE END Before_Kernel_Start */
|
||||
|
||||
tx_kernel_enter();
|
||||
|
||||
/* USER CODE BEGIN Kernel_Start_Error */
|
||||
|
||||
/* USER CODE END Kernel_Start_Error */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
17
Core/Src/graphics.c
Normal file
17
Core/Src/graphics.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include "graphics.h"
|
||||
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "tx_api.h"
|
||||
|
||||
#include "hx8357d.h"
|
||||
#include "main.h"
|
||||
|
||||
void graphics_thread_entry(ULONG _) {
|
||||
HX8357D_Init();
|
||||
HX8357D_Mode_RGB666();
|
||||
|
||||
while (1) {
|
||||
HAL_GPIO_TogglePin(STATUS2_GPIO_Port, STATUS2_Pin);
|
||||
tx_thread_sleep(100);
|
||||
}
|
||||
}
|
||||
@ -18,11 +18,14 @@
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "app_threadx.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "ft_logo_orange_rgb565.h"
|
||||
#include "ft_logo_rainbow_rgb565.h"
|
||||
#include "hx8357d.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
@ -125,22 +128,17 @@ int main(void) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
HX8357D_Init();
|
||||
HX8357D_Mode_RGB666();
|
||||
HAL_Delay(500);
|
||||
/* USER CODE END 2 */
|
||||
|
||||
MX_ThreadX_Init();
|
||||
|
||||
/* We should never get here as control is now taken by the scheduler */
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1) {
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
uint32_t now = HAL_GetTick();
|
||||
GPIO_PinState status1 = (now / 500) % 2 == 0;
|
||||
GPIO_PinState status2 = (now / 1000) % 2 == 0;
|
||||
HAL_GPIO_WritePin(STATUS1_GPIO_Port, STATUS1_Pin, status1);
|
||||
HAL_GPIO_WritePin(STATUS2_GPIO_Port, STATUS2_Pin, status2);
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
@ -176,7 +174,7 @@ void SystemClock_Config(void) {
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
|
||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||
RCC_OscInitStruct.HSICalibrationValue = 64;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||
RCC_OscInitStruct.PLL.PLLM = 4;
|
||||
@ -362,7 +360,7 @@ static void MX_LTDC_Init(void) {
|
||||
pLayerCfg.Alpha0 = 0;
|
||||
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
|
||||
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;
|
||||
pLayerCfg.FBStartAdress = (uint32_t)&image_data_ft_logo_orange_rgb565;
|
||||
pLayerCfg.FBStartAdress = (uint32_t)&image_data_ft_logo_rainbow_rgb565;
|
||||
pLayerCfg.ImageWidth = 320;
|
||||
pLayerCfg.ImageHeight = 480;
|
||||
pLayerCfg.Backcolor.Blue = 0;
|
||||
@ -730,6 +728,26 @@ static void MX_GPIO_Init(void) {
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @brief Period elapsed callback in non blocking mode
|
||||
* @note This function is called when TIM6 interrupt took place, inside
|
||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||
* a global variable "uwTick" used as application time base.
|
||||
* @param htim : TIM handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||
/* USER CODE BEGIN Callback 0 */
|
||||
|
||||
/* USER CODE END Callback 0 */
|
||||
if (htim->Instance == TIM6) {
|
||||
HAL_IncTick();
|
||||
}
|
||||
/* USER CODE BEGIN Callback 1 */
|
||||
|
||||
/* USER CODE END Callback 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
|
||||
@ -267,7 +267,7 @@ void HAL_LTDC_MspInit(LTDC_HandleTypeDef* hltdc)
|
||||
PeriphClkInitStruct.PLL3.PLL3R = 14;
|
||||
PeriphClkInitStruct.PLL3.PLL3RGE = RCC_PLL3VCIRANGE_3;
|
||||
PeriphClkInitStruct.PLL3.PLL3VCOSEL = RCC_PLL3VCOWIDE;
|
||||
PeriphClkInitStruct.PLL3.PLL3FRACN = 0.0;
|
||||
PeriphClkInitStruct.PLL3.PLL3FRACN = 0;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
|
||||
130
Core/Src/stm32h7xx_hal_timebase_tim.c
Normal file
130
Core/Src/stm32h7xx_hal_timebase_tim.c
Normal file
@ -0,0 +1,130 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_timebase_TIM.c
|
||||
* @brief HAL time base based on the hardware TIM.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "stm32h7xx_hal_tim.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
TIM_HandleTypeDef htim6;
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief This function configures the TIM6 as a time base source.
|
||||
* The time source is configured to have 1ms time base with a dedicated
|
||||
* Tick interrupt priority.
|
||||
* @note This function is called automatically at the beginning of program after
|
||||
* reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig().
|
||||
* @param TickPriority: Tick interrupt priority.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||
{
|
||||
RCC_ClkInitTypeDef clkconfig;
|
||||
uint32_t uwTimclock, uwAPB1Prescaler;
|
||||
|
||||
uint32_t uwPrescalerValue;
|
||||
uint32_t pFLatency;
|
||||
/*Configure the TIM6 IRQ priority */
|
||||
if (TickPriority < (1UL << __NVIC_PRIO_BITS))
|
||||
{
|
||||
HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority ,0U);
|
||||
|
||||
/* Enable the TIM6 global Interrupt */
|
||||
HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
|
||||
uwTickPrio = TickPriority;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Enable TIM6 clock */
|
||||
__HAL_RCC_TIM6_CLK_ENABLE();
|
||||
|
||||
/* Get clock configuration */
|
||||
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
|
||||
|
||||
/* Get APB1 prescaler */
|
||||
uwAPB1Prescaler = clkconfig.APB1CLKDivider;
|
||||
/* Compute TIM6 clock */
|
||||
if (uwAPB1Prescaler == RCC_HCLK_DIV1)
|
||||
{
|
||||
uwTimclock = HAL_RCC_GetPCLK1Freq();
|
||||
}
|
||||
else
|
||||
{
|
||||
uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq();
|
||||
}
|
||||
|
||||
/* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
|
||||
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
|
||||
|
||||
/* Initialize TIM6 */
|
||||
htim6.Instance = TIM6;
|
||||
|
||||
/* Initialize TIMx peripheral as follow:
|
||||
+ Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
|
||||
+ Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
|
||||
+ ClockDivision = 0
|
||||
+ Counter direction = Up
|
||||
*/
|
||||
htim6.Init.Period = (1000000U / 1000U) - 1U;
|
||||
htim6.Init.Prescaler = uwPrescalerValue;
|
||||
htim6.Init.ClockDivision = 0;
|
||||
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
|
||||
if(HAL_TIM_Base_Init(&htim6) == HAL_OK)
|
||||
{
|
||||
/* Start the TIM time Base generation in interrupt mode */
|
||||
return HAL_TIM_Base_Start_IT(&htim6);
|
||||
}
|
||||
|
||||
/* Return function status */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Suspend Tick increment.
|
||||
* @note Disable the tick increment by disabling TIM6 update interrupt.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SuspendTick(void)
|
||||
{
|
||||
/* Disable TIM6 update Interrupt */
|
||||
__HAL_TIM_DISABLE_IT(&htim6, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resume Tick increment.
|
||||
* @note Enable the tick increment by Enabling TIM6 update interrupt.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ResumeTick(void)
|
||||
{
|
||||
/* Enable TIM6 Update interrupt */
|
||||
__HAL_TIM_ENABLE_IT(&htim6, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
@ -55,6 +55,7 @@
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern TIM_HandleTypeDef htim6;
|
||||
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
@ -138,19 +139,6 @@ void UsageFault_Handler(void)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System service call via SWI instruction.
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SVCall_IRQn 0 */
|
||||
|
||||
/* USER CODE END SVCall_IRQn 0 */
|
||||
/* USER CODE BEGIN SVCall_IRQn 1 */
|
||||
|
||||
/* USER CODE END SVCall_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Debug monitor.
|
||||
*/
|
||||
@ -164,33 +152,6 @@ void DebugMon_Handler(void)
|
||||
/* USER CODE END DebugMonitor_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Pendable request for system service.
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN PendSV_IRQn 0 */
|
||||
|
||||
/* USER CODE END PendSV_IRQn 0 */
|
||||
/* USER CODE BEGIN PendSV_IRQn 1 */
|
||||
|
||||
/* USER CODE END PendSV_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System tick timer.
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SysTick_IRQn 0 */
|
||||
|
||||
/* USER CODE END SysTick_IRQn 0 */
|
||||
HAL_IncTick();
|
||||
/* USER CODE BEGIN SysTick_IRQn 1 */
|
||||
|
||||
/* USER CODE END SysTick_IRQn 1 */
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* STM32H7xx Peripheral Interrupt Handlers */
|
||||
/* Add here the Interrupt Handlers for the used peripherals. */
|
||||
@ -198,6 +159,20 @@ void SysTick_Handler(void)
|
||||
/* please refer to the startup file (startup_stm32h7xx.s). */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM6 global interrupt, DAC1_CH1 and DAC1_CH2 underrun error interrupts.
|
||||
*/
|
||||
void TIM6_DAC_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM6_DAC_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM6_DAC_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim6);
|
||||
/* USER CODE BEGIN TIM6_DAC_IRQn 1 */
|
||||
|
||||
/* USER CODE END TIM6_DAC_IRQn 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
665
Core/Src/tx_initialize_low_level.s
Normal file
665
Core/Src/tx_initialize_low_level.s
Normal file
@ -0,0 +1,665 @@
|
||||
|
||||
// by default AzureRTOS is configured to use static byte pool for
|
||||
// allocation, in case dynamic allocation is to be used, uncomment
|
||||
// the define below and update the linker files to define the following symbols
|
||||
// EWARM toolchain:
|
||||
// place in RAM_region { last section FREE_MEM};
|
||||
// MDK-ARM toolchain;
|
||||
// either define the RW_IRAM1 region in the ".sct" file or modify this file by referring to the correct memory region.
|
||||
// LDR r1, =|Image$$RW_IRAM1$$ZI$$Limit|
|
||||
// STM32CubeIDE toolchain:
|
||||
// ._threadx_heap :
|
||||
// {
|
||||
// . = ALIGN(8);
|
||||
// __RAM_segment_used_end__ = .;
|
||||
// . = . + 64K;
|
||||
// . = ALIGN(8);
|
||||
// } >RAM_D1 AT> RAM_D1
|
||||
// The simplest way to provide memory for ThreadX is to define a new section, see ._threadx_heap above.
|
||||
// In the example above the ThreadX heap size is set to 64KBytes.
|
||||
// The ._threadx_heap must be located between the .bss and the ._user_heap_stack sections in the linker script.
|
||||
// Caution: Make sure that ThreadX does not need more than the provided heap memory (64KBytes in this example).
|
||||
// Read more in STM32CubeIDE User Guide, chapter: "Linker script".
|
||||
|
||||
#define USE_DYNAMIC_MEMORY_ALLOCATION
|
||||
|
||||
#if defined(__clang__)
|
||||
@/**************************************************************************/
|
||||
@/* */
|
||||
@/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
@/* */
|
||||
@/* This software is licensed under the Microsoft Software License */
|
||||
@/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
@/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
@/* and in the root directory of this software. */
|
||||
@/* */
|
||||
@/**************************************************************************/
|
||||
@
|
||||
@
|
||||
@/**************************************************************************/
|
||||
@/**************************************************************************/
|
||||
@/** */
|
||||
@/** ThreadX Component */
|
||||
@/** */
|
||||
@/** Initialize */
|
||||
@/** */
|
||||
@/**************************************************************************/
|
||||
@/**************************************************************************/
|
||||
@
|
||||
@
|
||||
.global _tx_thread_system_stack_ptr
|
||||
.global _tx_initialize_unused_memory
|
||||
.global _tx_timer_interrupt
|
||||
.global __main
|
||||
.global __tx_SVCallHandler
|
||||
.global __tx_PendSVHandler
|
||||
.global __tx_NMIHandler @ NMI
|
||||
.global __tx_BadHandler @ HardFault
|
||||
.global __tx_SVCallHandler @ SVCall
|
||||
.global __tx_DBGHandler @ Monitor
|
||||
.global __tx_PendSVHandler @ PendSV
|
||||
.global __tx_SysTickHandler @ SysTick
|
||||
.global __tx_IntHandler @ Int 0
|
||||
#ifdef USE_DYNAMIC_MEMORY_ALLOCATION
|
||||
.global Image$$RW_IRAM1$$ZI$$Limit
|
||||
#endif
|
||||
.global __Vectors
|
||||
@
|
||||
@
|
||||
SYSTEM_CLOCK = 64000000
|
||||
SYSTICK_CYCLES = ((SYSTEM_CLOCK / 100) -1)
|
||||
|
||||
.text 32
|
||||
.align 4
|
||||
.syntax unified
|
||||
@/**************************************************************************/
|
||||
@/* */
|
||||
@/* FUNCTION RELEASE */
|
||||
@/* */
|
||||
@/* _tx_initialize_low_level Cortex-M7/AC6 */
|
||||
@/* 6.1 */
|
||||
@/* AUTHOR */
|
||||
@/* */
|
||||
@/* William E. Lamie, Microsoft Corporation */
|
||||
@/* */
|
||||
@/* DESCRIPTION */
|
||||
@/* */
|
||||
@/* This function is responsible for any low-level processor */
|
||||
@/* initialization, including setting up interrupt vectors, setting */
|
||||
@/* up a periodic timer interrupt source, saving the system stack */
|
||||
@/* pointer for use in ISR processing later, and finding the first */
|
||||
@/* available RAM memory address for tx_application_define. */
|
||||
@/* */
|
||||
@/* INPUT */
|
||||
@/* */
|
||||
@/* None */
|
||||
@/* */
|
||||
@/* OUTPUT */
|
||||
@/* */
|
||||
@/* None */
|
||||
@/* */
|
||||
@/* CALLS */
|
||||
@/* */
|
||||
@/* None */
|
||||
@/* */
|
||||
@/* CALLED BY */
|
||||
@/* */
|
||||
@/* _tx_initialize_kernel_enter ThreadX entry function */
|
||||
@/* */
|
||||
@/* RELEASE HISTORY */
|
||||
@/* */
|
||||
@/* DATE NAME DESCRIPTION */
|
||||
@/* */
|
||||
@/* 09-30-2020 William E. Lamie Initial Version 6.1 */
|
||||
@/* */
|
||||
@/**************************************************************************/
|
||||
@VOID _tx_initialize_low_level(VOID)
|
||||
@{
|
||||
.global _tx_initialize_low_level
|
||||
.thumb_func
|
||||
_tx_initialize_low_level:
|
||||
@
|
||||
@ /* Disable interrupts during ThreadX initialization. */
|
||||
@
|
||||
CPSID i
|
||||
@
|
||||
@ /* Set base of available memory to end of non-initialised RAM area. */
|
||||
@
|
||||
#ifdef USE_DYNAMIC_MEMORY_ALLOCATION
|
||||
LDR r0, =_tx_initialize_unused_memory @ Build address of unused memory pointer
|
||||
LDR r1, = Image$$RW_IRAM1$$ZI$$Limit @ Build first free address
|
||||
ADD r1, r1, #4 @
|
||||
STR r1, [r0] @ Setup first unused memory pointer
|
||||
#endif
|
||||
@
|
||||
@ /* Setup Vector Table Offset Register. */
|
||||
@
|
||||
MOV r0, #0xE000E000 @ Build address of NVIC registers
|
||||
LDR r1, =__Vectors @ Pickup address of vector table
|
||||
STR r1, [r0, #0xD08] @ Set vector table address
|
||||
@
|
||||
@ /* Set system stack pointer from vector value. */
|
||||
@
|
||||
LDR r0, =_tx_thread_system_stack_ptr @ Build address of system stack pointer
|
||||
LDR r1, =__Vectors @ Pickup address of vector table
|
||||
LDR r1, [r1] @ Pickup reset stack pointer
|
||||
STR r1, [r0] @ Save system stack pointer
|
||||
@
|
||||
@ /* Enable the cycle count register. */
|
||||
@
|
||||
LDR r0, =0xE0001000 @ Build address of DWT register
|
||||
LDR r1, [r0] @ Pickup the current value
|
||||
ORR r1, r1, #1 @ Set the CYCCNTENA bit
|
||||
STR r1, [r0] @ Enable the cycle count register
|
||||
@
|
||||
@ /* Configure SysTick for 100Hz clock, or 16384 cycles if no reference. */
|
||||
@
|
||||
MOV r0, #0xE000E000 @ Build address of NVIC registers
|
||||
LDR r1, =SYSTICK_CYCLES
|
||||
STR r1, [r0, #0x14] @ Setup SysTick Reload Value
|
||||
MOV r1, #0x7 @ Build SysTick Control Enable Value
|
||||
STR r1, [r0, #0x10] @ Setup SysTick Control
|
||||
@
|
||||
@ /* Configure handler priorities. */
|
||||
@
|
||||
LDR r1, =0x00000000 @ Rsrv, UsgF, BusF, MemM
|
||||
STR r1, [r0, #0xD18] @ Setup System Handlers 4-7 Priority Registers
|
||||
|
||||
LDR r1, =0xFF000000 @ SVCl, Rsrv, Rsrv, Rsrv
|
||||
STR r1, [r0, #0xD1C] @ Setup System Handlers 8-11 Priority Registers
|
||||
@ Note: SVC must be lowest priority, which is 0xFF
|
||||
|
||||
LDR r1, =0x40FF0000 @ SysT, PnSV, Rsrv, DbgM
|
||||
STR r1, [r0, #0xD20] @ Setup System Handlers 12-15 Priority Registers
|
||||
@ Note: PnSV must be lowest priority, which is 0xFF
|
||||
@
|
||||
@ /* Return to caller. */
|
||||
@
|
||||
BX lr
|
||||
@}
|
||||
@
|
||||
|
||||
@/* Define shells for each of the unused vectors. */
|
||||
@
|
||||
.global __tx_BadHandler
|
||||
.thumb_func
|
||||
__tx_BadHandler:
|
||||
B __tx_BadHandler
|
||||
|
||||
@ /* added to catch the hardfault */
|
||||
|
||||
.global __tx_HardfaultHandler
|
||||
.thumb_func
|
||||
__tx_HardfaultHandler:
|
||||
B __tx_HardfaultHandler
|
||||
|
||||
@ /* added to catch the SVC */
|
||||
|
||||
.global __tx_SVCallHandler
|
||||
.thumb_func
|
||||
__tx_SVCallHandler:
|
||||
B __tx_SVCallHandler
|
||||
|
||||
@ /* Generic interrupt handler template */
|
||||
.global __tx_IntHandler
|
||||
.thumb_func
|
||||
__tx_IntHandler:
|
||||
@ VOID InterruptHandler (VOID)
|
||||
@ {
|
||||
PUSH {r0, lr}
|
||||
#ifdef TX_EXECUTION_PROFILE_ENABLE
|
||||
BL _tx_execution_isr_enter @ Call the ISR enter function
|
||||
#endif
|
||||
|
||||
@ /* Do interrupt handler work here */
|
||||
@ /* BL <your C Function>.... */
|
||||
|
||||
#ifdef TX_EXECUTION_PROFILE_ENABLE
|
||||
BL _tx_execution_isr_exit @ Call the ISR exit function
|
||||
#endif
|
||||
POP {r0, lr}
|
||||
BX LR
|
||||
@ }
|
||||
|
||||
@ /* System Tick timer interrupt handler */
|
||||
.global __tx_SysTickHandler
|
||||
.global SysTick_Handler
|
||||
.thumb_func
|
||||
__tx_SysTickHandler:
|
||||
.thumb_func
|
||||
SysTick_Handler:
|
||||
@ VOID TimerInterruptHandler (VOID)
|
||||
@ {
|
||||
@
|
||||
PUSH {r0, lr}
|
||||
#ifdef TX_EXECUTION_PROFILE_ENABLE
|
||||
BL _tx_execution_isr_enter @ Call the ISR enter function
|
||||
#endif
|
||||
BL _tx_timer_interrupt
|
||||
#ifdef TX_EXECUTION_PROFILE_ENABLE
|
||||
BL _tx_execution_isr_exit @ Call the ISR exit function
|
||||
#endif
|
||||
POP {r0, lr}
|
||||
BX LR
|
||||
@ }
|
||||
|
||||
@ /* NMI, DBG handlers */
|
||||
.global __tx_NMIHandler
|
||||
.thumb_func
|
||||
__tx_NMIHandler:
|
||||
B __tx_NMIHandler
|
||||
|
||||
.global __tx_DBGHandler
|
||||
.thumb_func
|
||||
__tx_DBGHandler:
|
||||
B __tx_DBGHandler
|
||||
.end
|
||||
#endif
|
||||
|
||||
#ifdef __IAR_SYSTEMS_ASM__
|
||||
;/**************************************************************************/
|
||||
;/* */
|
||||
;/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
;/* */
|
||||
;/* This software is licensed under the Microsoft Software License */
|
||||
;/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
;/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
;/* and in the root directory of this software. */
|
||||
;/* */
|
||||
;/**************************************************************************/
|
||||
;
|
||||
;
|
||||
;/**************************************************************************/
|
||||
;/**************************************************************************/
|
||||
;/** */
|
||||
;/** ThreadX Component */
|
||||
;/** */
|
||||
;/** Initialize */
|
||||
;/** */
|
||||
;/**************************************************************************/
|
||||
;/**************************************************************************/
|
||||
;
|
||||
EXTERN _tx_thread_system_stack_ptr
|
||||
EXTERN _tx_initialize_unused_memory
|
||||
EXTERN _tx_timer_interrupt
|
||||
EXTERN __vector_table
|
||||
EXTERN _tx_execution_isr_enter
|
||||
EXTERN _tx_execution_isr_exit
|
||||
;
|
||||
;
|
||||
SYSTEM_CLOCK EQU 64000000
|
||||
SYSTICK_CYCLES EQU ((SYSTEM_CLOCK / 100) -1)
|
||||
#ifdef USE_DYNAMIC_MEMORY_ALLOCATION
|
||||
RSEG FREE_MEM:DATA
|
||||
PUBLIC __tx_free_memory_start
|
||||
__tx_free_memory_start
|
||||
DS32 4
|
||||
#endif
|
||||
;
|
||||
;
|
||||
SECTION `.text`:CODE:NOROOT(2)
|
||||
THUMB
|
||||
;/**************************************************************************/
|
||||
;/* */
|
||||
;/* FUNCTION RELEASE */
|
||||
;/* */
|
||||
;/* _tx_initialize_low_level Cortex-M7/IAR */
|
||||
;/* 6.1 */
|
||||
;/* AUTHOR */
|
||||
;/* */
|
||||
;/* William E. Lamie, Microsoft Corporation */
|
||||
;/* */
|
||||
;/* DESCRIPTION */
|
||||
;/* */
|
||||
;/* This function is responsible for any low-level processor */
|
||||
;/* initialization, including setting up interrupt vectors, setting */
|
||||
;/* up a periodic timer interrupt source, saving the system stack */
|
||||
;/* pointer for use in ISR processing later, and finding the first */
|
||||
;/* available RAM memory address for tx_application_define. */
|
||||
;/* */
|
||||
;/* INPUT */
|
||||
;/* */
|
||||
;/* None */
|
||||
;/* */
|
||||
;/* OUTPUT */
|
||||
;/* */
|
||||
;/* None */
|
||||
;/* */
|
||||
;/* CALLS */
|
||||
;/* */
|
||||
;/* None */
|
||||
;/* */
|
||||
;/* CALLED BY */
|
||||
;/* */
|
||||
;/* _tx_initialize_kernel_enter ThreadX entry function */
|
||||
;/* */
|
||||
;/* RELEASE HISTORY */
|
||||
;/* */
|
||||
;/* DATE NAME DESCRIPTION */
|
||||
;/* */
|
||||
;/* 09-30-2020 William E. Lamie Initial Version 6.1 */
|
||||
;/* */
|
||||
;/**************************************************************************/
|
||||
;VOID _tx_initialize_low_level(VOID)
|
||||
;{
|
||||
PUBLIC _tx_initialize_low_level
|
||||
_tx_initialize_low_level:
|
||||
;
|
||||
; /* Ensure that interrupts are disabled. */
|
||||
;
|
||||
CPSID i ; Disable interrupts
|
||||
;
|
||||
;
|
||||
; /* Set base of available memory to end of non-initialised RAM area. */
|
||||
;
|
||||
#ifdef USE_DYNAMIC_MEMORY_ALLOCATION
|
||||
|
||||
LDR r0, =__tx_free_memory_start ; Get end of non-initialized RAM area
|
||||
LDR r2, =_tx_initialize_unused_memory ; Build address of unused memory pointer
|
||||
STR r0, [r2, #0] ; Save first free memory address
|
||||
#endif
|
||||
;
|
||||
; /* Enable the cycle count register. */
|
||||
;
|
||||
LDR r0, =0xE0001000 ; Build address of DWT register
|
||||
LDR r1, [r0] ; Pickup the current value
|
||||
ORR r1, r1, #1 ; Set the CYCCNTENA bit
|
||||
STR r1, [r0] ; Enable the cycle count register
|
||||
;
|
||||
; /* Setup Vector Table Offset Register. */
|
||||
;
|
||||
MOV r0, #0xE000E000 ; Build address of NVIC registers
|
||||
LDR r1, =__vector_table ; Pickup address of vector table
|
||||
STR r1, [r0, #0xD08] ; Set vector table address
|
||||
;
|
||||
; /* Set system stack pointer from vector value. */
|
||||
;
|
||||
LDR r0, =_tx_thread_system_stack_ptr ; Build address of system stack pointer
|
||||
LDR r1, =__vector_table ; Pickup address of vector table
|
||||
LDR r1, [r1] ; Pickup reset stack pointer
|
||||
STR r1, [r0] ; Save system stack pointer
|
||||
;
|
||||
; /* Configure SysTick. */
|
||||
;
|
||||
MOV r0, #0xE000E000 ; Build address of NVIC registers
|
||||
LDR r1, =SYSTICK_CYCLES
|
||||
STR r1, [r0, #0x14] ; Setup SysTick Reload Value
|
||||
MOV r1, #0x7 ; Build SysTick Control Enable Value
|
||||
STR r1, [r0, #0x10] ; Setup SysTick Control
|
||||
;
|
||||
; /* Configure handler priorities. */
|
||||
;
|
||||
LDR r1, =0x00000000 ; Rsrv, UsgF, BusF, MemM
|
||||
STR r1, [r0, #0xD18] ; Setup System Handlers 4-7 Priority Registers
|
||||
|
||||
LDR r1, =0xFF000000 ; SVCl, Rsrv, Rsrv, Rsrv
|
||||
STR r1, [r0, #0xD1C] ; Setup System Handlers 8-11 Priority Registers
|
||||
; Note: SVC must be lowest priority, which is 0xFF
|
||||
|
||||
LDR r1, =0x40FF0000 ; SysT, PnSV, Rsrv, DbgM
|
||||
STR r1, [r0, #0xD20] ; Setup System Handlers 12-15 Priority Registers
|
||||
; Note: PnSV must be lowest priority, which is 0xFF
|
||||
;
|
||||
; /* Return to caller. */
|
||||
;
|
||||
BX lr
|
||||
;}
|
||||
;
|
||||
;
|
||||
PUBLIC SysTick_Handler
|
||||
PUBLIC __tx_SysTickHandler
|
||||
__tx_SysTickHandler:
|
||||
SysTick_Handler:
|
||||
;
|
||||
; VOID SysTick_Handler (VOID)
|
||||
; {
|
||||
;
|
||||
PUSH {r0, lr}
|
||||
#ifdef TX_EXECUTION_PROFILE_ENABLE
|
||||
BL _tx_execution_isr_enter ; Call the ISR enter function
|
||||
#endif
|
||||
BL _tx_timer_interrupt
|
||||
#ifdef TX_EXECUTION_PROFILE_ENABLE
|
||||
BL _tx_execution_isr_exit ; Call the ISR exit function
|
||||
#endif
|
||||
POP {r0, lr}
|
||||
BX LR
|
||||
; }
|
||||
END
|
||||
#endif
|
||||
|
||||
#if defined (__GNUC__) && !defined(__clang__)
|
||||
@/**************************************************************************/
|
||||
@/* */
|
||||
@/* Copyright (c) Microsoft Corporation. All rights reserved. */
|
||||
@/* */
|
||||
@/* This software is licensed under the Microsoft Software License */
|
||||
@/* Terms for Microsoft Azure RTOS. Full text of the license can be */
|
||||
@/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
|
||||
@/* and in the root directory of this software. */
|
||||
@/* */
|
||||
@/**************************************************************************/
|
||||
@
|
||||
@
|
||||
@/**************************************************************************/
|
||||
@/**************************************************************************/
|
||||
@/** */
|
||||
@/** ThreadX Component */
|
||||
@/** */
|
||||
@/** Initialize */
|
||||
@/** */
|
||||
@/**************************************************************************/
|
||||
@/**************************************************************************/
|
||||
@
|
||||
@
|
||||
.global _tx_thread_system_stack_ptr
|
||||
.global _tx_initialize_unused_memory
|
||||
.global __RAM_segment_used_end__
|
||||
.global _tx_timer_interrupt
|
||||
.global __main
|
||||
.global __tx_SVCallHandler
|
||||
.global __tx_PendSVHandler
|
||||
.global _vectors
|
||||
.global __tx_NMIHandler @ NMI
|
||||
.global __tx_BadHandler @ HardFault
|
||||
.global __tx_SVCallHandler @ SVCall
|
||||
.global __tx_DBGHandler @ Monitor
|
||||
.global __tx_PendSVHandler @ PendSV
|
||||
.global __tx_SysTickHandler @ SysTick
|
||||
.global __tx_IntHandler @ Int 0
|
||||
@
|
||||
@
|
||||
|
||||
SYSTEM_CLOCK = 64000000
|
||||
SYSTICK_CYCLES = ((SYSTEM_CLOCK / 100) -1)
|
||||
|
||||
.text 32
|
||||
.align 4
|
||||
.syntax unified
|
||||
@/**************************************************************************/
|
||||
@/* */
|
||||
@/* FUNCTION RELEASE */
|
||||
@/* */
|
||||
@/* _tx_initialize_low_level Cortex-M7/GNU */
|
||||
@/* 6.1 */
|
||||
@/* AUTHOR */
|
||||
@/* */
|
||||
@/* William E. Lamie, Microsoft Corporation */
|
||||
@/* */
|
||||
@/* DESCRIPTION */
|
||||
@/* */
|
||||
@/* This function is responsible for any low-level processor */
|
||||
@/* initialization, including setting up interrupt vectors, setting */
|
||||
@/* up a periodic timer interrupt source, saving the system stack */
|
||||
@/* pointer for use in ISR processing later, and finding the first */
|
||||
@/* available RAM memory address for tx_application_define. */
|
||||
@/* */
|
||||
@/* INPUT */
|
||||
@/* */
|
||||
@/* None */
|
||||
@/* */
|
||||
@/* OUTPUT */
|
||||
@/* */
|
||||
@/* None */
|
||||
@/* */
|
||||
@/* CALLS */
|
||||
@/* */
|
||||
@/* None */
|
||||
@/* */
|
||||
@/* CALLED BY */
|
||||
@/* */
|
||||
@/* _tx_initialize_kernel_enter ThreadX entry function */
|
||||
@/* */
|
||||
@/* RELEASE HISTORY */
|
||||
@/* */
|
||||
@/* DATE NAME DESCRIPTION */
|
||||
@/* */
|
||||
@/* 05-19-2020 William E. Lamie Initial Version 6.0 */
|
||||
@/* 09-30-2020 William E. Lamie Modified Comment(s), fixed */
|
||||
@/* GNU assembly comment, clean */
|
||||
@/* up whitespace, resulting */
|
||||
@/* in version 6.1 */
|
||||
@/* */
|
||||
@/**************************************************************************/
|
||||
@VOID _tx_initialize_low_level(VOID)
|
||||
@{
|
||||
.global _tx_initialize_low_level
|
||||
.thumb_func
|
||||
_tx_initialize_low_level:
|
||||
@
|
||||
@ /* Disable interrupts during ThreadX initialization. */
|
||||
@
|
||||
CPSID i
|
||||
@
|
||||
@ /* Set base of available memory to end of non-initialised RAM area. */
|
||||
@
|
||||
#ifdef USE_DYNAMIC_MEMORY_ALLOCATION
|
||||
LDR r0, =_tx_initialize_unused_memory @ Build address of unused memory pointer
|
||||
LDR r1, =__RAM_segment_used_end__ @ Build first free address
|
||||
ADD r1, r1, #4 @
|
||||
STR r1, [r0] @ Setup first unused memory pointer
|
||||
#endif
|
||||
@
|
||||
@ /* Setup Vector Table Offset Register. */
|
||||
@
|
||||
MOV r0, #0xE000E000 @ Build address of NVIC registers
|
||||
LDR r1, =g_pfnVectors @ Pickup address of vector table
|
||||
STR r1, [r0, #0xD08] @ Set vector table address
|
||||
@
|
||||
@ /* Set system stack pointer from vector value. */
|
||||
@
|
||||
LDR r0, =_tx_thread_system_stack_ptr @ Build address of system stack pointer
|
||||
LDR r1, =g_pfnVectors @ Pickup address of vector table
|
||||
LDR r1, [r1] @ Pickup reset stack pointer
|
||||
STR r1, [r0] @ Save system stack pointer
|
||||
@
|
||||
@ /* Enable the cycle count register. */
|
||||
@
|
||||
LDR r0, =0xE0001000 @ Build address of DWT register
|
||||
LDR r1, [r0] @ Pickup the current value
|
||||
ORR r1, r1, #1 @ Set the CYCCNTENA bit
|
||||
STR r1, [r0] @ Enable the cycle count register
|
||||
@
|
||||
@ /* Configure SysTick for 100Hz clock, or 16384 cycles if no reference. */
|
||||
@
|
||||
MOV r0, #0xE000E000 @ Build address of NVIC registers
|
||||
LDR r1, =SYSTICK_CYCLES
|
||||
STR r1, [r0, #0x14] @ Setup SysTick Reload Value
|
||||
MOV r1, #0x7 @ Build SysTick Control Enable Value
|
||||
STR r1, [r0, #0x10] @ Setup SysTick Control
|
||||
@
|
||||
@ /* Configure handler priorities. */
|
||||
@
|
||||
LDR r1, =0x00000000 @ Rsrv, UsgF, BusF, MemM
|
||||
STR r1, [r0, #0xD18] @ Setup System Handlers 4-7 Priority Registers
|
||||
|
||||
LDR r1, =0xFF000000 @ SVCl, Rsrv, Rsrv, Rsrv
|
||||
STR r1, [r0, #0xD1C] @ Setup System Handlers 8-11 Priority Registers
|
||||
@ Note: SVC must be lowest priority, which is 0xFF
|
||||
|
||||
LDR r1, =0x40FF0000 @ SysT, PnSV, Rsrv, DbgM
|
||||
STR r1, [r0, #0xD20] @ Setup System Handlers 12-15 Priority Registers
|
||||
@ Note: PnSV must be lowest priority, which is 0xFF
|
||||
@
|
||||
@ /* Return to caller. */
|
||||
@
|
||||
BX lr
|
||||
@}
|
||||
@
|
||||
|
||||
@/* Define shells for each of the unused vectors. */
|
||||
@
|
||||
.global __tx_BadHandler
|
||||
.thumb_func
|
||||
__tx_BadHandler:
|
||||
B __tx_BadHandler
|
||||
|
||||
@ /* added to catch the hardfault */
|
||||
|
||||
.global __tx_HardfaultHandler
|
||||
.thumb_func
|
||||
__tx_HardfaultHandler:
|
||||
B __tx_HardfaultHandler
|
||||
|
||||
@ /* added to catch the SVC */
|
||||
|
||||
.global __tx_SVCallHandler
|
||||
.thumb_func
|
||||
__tx_SVCallHandler:
|
||||
B __tx_SVCallHandler
|
||||
|
||||
@ /* Generic interrupt handler template */
|
||||
.global __tx_IntHandler
|
||||
.thumb_func
|
||||
__tx_IntHandler:
|
||||
@ VOID InterruptHandler (VOID)
|
||||
@ {
|
||||
PUSH {r0, lr}
|
||||
#ifdef TX_EXECUTION_PROFILE_ENABLE
|
||||
BL _tx_execution_isr_enter @ Call the ISR enter function
|
||||
#endif
|
||||
|
||||
@ /* Do interrupt handler work here */
|
||||
@ /* BL <your C Function>.... */
|
||||
|
||||
#ifdef TX_EXECUTION_PROFILE_ENABLE
|
||||
BL _tx_execution_isr_exit @ Call the ISR exit function
|
||||
#endif
|
||||
POP {r0, lr}
|
||||
BX LR
|
||||
@ }
|
||||
|
||||
@ /* System Tick timer interrupt handler */
|
||||
.global __tx_SysTickHandler
|
||||
.global SysTick_Handler
|
||||
.thumb_func
|
||||
__tx_SysTickHandler:
|
||||
.thumb_func
|
||||
SysTick_Handler:
|
||||
@ VOID TimerInterruptHandler (VOID)
|
||||
@ {
|
||||
@
|
||||
PUSH {r0, lr}
|
||||
#ifdef TX_EXECUTION_PROFILE_ENABLE
|
||||
BL _tx_execution_isr_enter @ Call the ISR enter function
|
||||
#endif
|
||||
BL _tx_timer_interrupt
|
||||
#ifdef TX_EXECUTION_PROFILE_ENABLE
|
||||
BL _tx_execution_isr_exit @ Call the ISR exit function
|
||||
#endif
|
||||
POP {r0, lr}
|
||||
BX LR
|
||||
@ }
|
||||
|
||||
@ /* NMI, DBG handlers */
|
||||
.global __tx_NMIHandler
|
||||
.thumb_func
|
||||
__tx_NMIHandler:
|
||||
B __tx_NMIHandler
|
||||
|
||||
.global __tx_DBGHandler
|
||||
.thumb_func
|
||||
__tx_DBGHandler:
|
||||
B __tx_DBGHandler
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user