diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc index 452ec77e..7ebb6443 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc @@ -1,7 +1,7 @@ @@ -12,7 +12,7 @@ project-path - - Generated: 14/03/2023 13:35:04 + - Generated: 05/05/2023 14:50:21 @@ -44,6 +44,7 @@ + @@ -56,6 +57,7 @@ + diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/MX_Device.h b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/MX_Device.h index 371261ff..d84f24dd 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/MX_Device.h +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/MX_Device.h @@ -1,6 +1,6 @@ /****************************************************************************** * File Name : MX_Device.h - * Date : 14/03/2023 13:35:04 + * Date : 05/05/2023 14:50:21 * Description : STM32Cube MX parameter definitions * Note : This file is generated by STM32CubeMX (DO NOT EDIT!) ******************************************************************************/ diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject index 6b12af56..04eb904e 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject @@ -8,5 +8,5 @@ SourceFiles=;; HeaderPath=..\Inc HeaderFiles=stm32f7xx_it.h;stm32f7xx_hal_conf.h;main.h; SourcePath=..\Src -SourceFiles=stm32f7xx_it.c;stm32f7xx_hal_msp.c;main.c; +SourceFiles=stm32f7xx_it.c;stm32f7xx_hal_msp.c;stm32f7xx_hal_timebase_tim.c;main.c; diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h index f91ee4f8..eeeffc81 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h @@ -64,7 +64,7 @@ /* #define HAL_MMC_MODULE_ENABLED */ /* #define HAL_SPDIFRX_MODULE_ENABLED */ /* #define HAL_SPI_MODULE_ENABLED */ -/* #define HAL_TIM_MODULE_ENABLED */ +#define HAL_TIM_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED /* #define HAL_USART_MODULE_ENABLED */ /* #define HAL_IRDA_MODULE_ENABLED */ diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h index 12b9054a..e6b69435 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h @@ -52,6 +52,7 @@ void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void DebugMon_Handler(void); +void TIM6_DAC_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc index e5edcc6d..11c4940d 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc @@ -24,7 +24,7 @@ Mcu.Pin1=PA1 Mcu.Pin10=PG13 Mcu.Pin11=PB7 Mcu.Pin12=VP_RNG_VS_RNG -Mcu.Pin13=VP_SYS_VS_Systick +Mcu.Pin13=VP_SYS_VS_tim6 Mcu.Pin2=PA2 Mcu.Pin3=PA7 Mcu.Pin4=PC4 @@ -50,6 +50,9 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:false\:false\:true\:false +NVIC.TIM6_DAC_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:true +NVIC.TimeBase=TIM6_DAC_IRQn +NVIC.TimeBaseIP=TIM6 NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false PA1.Mode=RMII PA1.Signal=ETH_REF_CLK @@ -173,6 +176,6 @@ USART3.IPParameters=VirtualMode-Asynchronous USART3.VirtualMode-Asynchronous=VM_ASYNC VP_RNG_VS_RNG.Mode=RNG_Activate VP_RNG_VS_RNG.Signal=RNG_VS_RNG -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick +VP_SYS_VS_tim6.Mode=TIM6 +VP_SYS_VS_tim6.Signal=SYS_VS_tim6 board=custom diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c index 22cdc9b7..cc451be4 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c @@ -84,18 +84,6 @@ static void MX_RNG_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ -// https://www.keil.com/pack/doc/STM32Cube/html/cubemx_using.html -uint32_t HAL_GetTick (void) { - static uint32_t ticks = 0U; - uint32_t i; - if (osKernelGetState() == osKernelRunning) { - return (uint32_t)osKernelGetTickCount(); - } - /* If Kernel is not running wait approximately 1 ms then increment and return auxiliary tick counter value */ - for (i = (SystemCoreClock >> 14U); i > 0U; i--) { __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); } - return ++ticks; -} - void mx_init(void) { SystemClock_Config(); MX_GPIO_Init(); @@ -310,6 +298,27 @@ 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 diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c new file mode 100644 index 00000000..a4f3a4c1 --- /dev/null +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c @@ -0,0 +1,137 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f7xx_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 "stm32f7xx_hal.h" +#include "stm32f7xx_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 = 0U; + + uint32_t uwPrescalerValue = 0U; + uint32_t pFLatency; + HAL_StatusTypeDef status; + + /* 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; + htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + + status = HAL_TIM_Base_Init(&htim6); + if (status == HAL_OK) + { + /* Start the TIM time Base generation in interrupt mode */ + status = HAL_TIM_Base_Start_IT(&htim6); + if (status == HAL_OK) + { + /* Enable the TIM6 global Interrupt */ + HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); + /* Configure the SysTick IRQ priority */ + if (TickPriority < (1UL << __NVIC_PRIO_BITS)) + { + /* Configure the TIM IRQ priority */ + HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority, 0U); + uwTickPrio = TickPriority; + } + else + { + status = HAL_ERROR; + } + } + } + + /* Return function status */ + return status; +} + +/** + * @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); +} + diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c index 6d94cff3..ba6f6981 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c @@ -55,6 +55,7 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ +extern TIM_HandleTypeDef htim6; /* USER CODE BEGIN EV */ @@ -158,6 +159,20 @@ void DebugMon_Handler(void) /* please refer to the startup file (startup_stm32f7xx.s). */ /******************************************************************************/ +/** + * @brief This function handles TIM6 global interrupt, DAC1 and DAC2 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 */ diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/_Target_1/RTE_Components.h b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/_Target_1/RTE_Components.h index 7caab922..b9d788e5 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/_Target_1/RTE_Components.h +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/RTE/_Target_1/RTE_Components.h @@ -54,6 +54,8 @@ #define RTE_DEVICE_HAL_RCC /* Keil::Device:STM32Cube HAL:RNG:1.3.0 */ #define RTE_DEVICE_HAL_RNG +/* Keil::Device:STM32Cube HAL:TIM:1.3.0 */ +#define RTE_DEVICE_HAL_TIM /* Keil::Device:STM32Cube HAL:UART:1.3.0 */ #define RTE_DEVICE_HAL_UART /* Keil::Device:Startup:1.2.5 */ diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/device-dashboard.uvoptx b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/device-dashboard.uvoptx index 80019e32..d3e9d885 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/device-dashboard.uvoptx +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/device-dashboard.uvoptx @@ -382,7 +382,7 @@ ::CMSIS Driver - 0 + 1 0 0 1 diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/device-dashboard.uvprojx b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/device-dashboard.uvprojx index db0569e7..aaf1796a 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/device-dashboard.uvprojx +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2-lwip/device-dashboard.uvprojx @@ -605,6 +605,12 @@ + + + + + + diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc index 452ec77e..8ee2b297 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc @@ -1,7 +1,7 @@ @@ -12,7 +12,7 @@ project-path - - Generated: 14/03/2023 13:35:04 + - Generated: 05/05/2023 14:26:10 @@ -44,6 +44,7 @@ + @@ -56,6 +57,7 @@ + diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/MX_Device.h b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/MX_Device.h index 371261ff..5ccfe8b5 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/MX_Device.h +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/MX_Device.h @@ -1,6 +1,6 @@ /****************************************************************************** * File Name : MX_Device.h - * Date : 14/03/2023 13:35:04 + * Date : 05/05/2023 14:26:10 * Description : STM32Cube MX parameter definitions * Note : This file is generated by STM32CubeMX (DO NOT EDIT!) ******************************************************************************/ diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject index 6b12af56..04eb904e 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject @@ -8,5 +8,5 @@ SourceFiles=;; HeaderPath=..\Inc HeaderFiles=stm32f7xx_it.h;stm32f7xx_hal_conf.h;main.h; SourcePath=..\Src -SourceFiles=stm32f7xx_it.c;stm32f7xx_hal_msp.c;main.c; +SourceFiles=stm32f7xx_it.c;stm32f7xx_hal_msp.c;stm32f7xx_hal_timebase_tim.c;main.c; diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h index f91ee4f8..eeeffc81 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h @@ -64,7 +64,7 @@ /* #define HAL_MMC_MODULE_ENABLED */ /* #define HAL_SPDIFRX_MODULE_ENABLED */ /* #define HAL_SPI_MODULE_ENABLED */ -/* #define HAL_TIM_MODULE_ENABLED */ +#define HAL_TIM_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED /* #define HAL_USART_MODULE_ENABLED */ /* #define HAL_IRDA_MODULE_ENABLED */ diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h index 12b9054a..e6b69435 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h @@ -52,6 +52,7 @@ void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void DebugMon_Handler(void); +void TIM6_DAC_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc index e5edcc6d..11c4940d 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc @@ -24,7 +24,7 @@ Mcu.Pin1=PA1 Mcu.Pin10=PG13 Mcu.Pin11=PB7 Mcu.Pin12=VP_RNG_VS_RNG -Mcu.Pin13=VP_SYS_VS_Systick +Mcu.Pin13=VP_SYS_VS_tim6 Mcu.Pin2=PA2 Mcu.Pin3=PA7 Mcu.Pin4=PC4 @@ -50,6 +50,9 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:false\:false\:true\:false +NVIC.TIM6_DAC_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:true +NVIC.TimeBase=TIM6_DAC_IRQn +NVIC.TimeBaseIP=TIM6 NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false PA1.Mode=RMII PA1.Signal=ETH_REF_CLK @@ -173,6 +176,6 @@ USART3.IPParameters=VirtualMode-Asynchronous USART3.VirtualMode-Asynchronous=VM_ASYNC VP_RNG_VS_RNG.Mode=RNG_Activate VP_RNG_VS_RNG.Signal=RNG_VS_RNG -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick +VP_SYS_VS_tim6.Mode=TIM6 +VP_SYS_VS_tim6.Signal=SYS_VS_tim6 board=custom diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c index 69d4fe6f..cc451be4 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c @@ -84,17 +84,6 @@ static void MX_RNG_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ -uint32_t HAL_GetTick (void) { - static uint32_t ticks = 0U; - uint32_t i; - if (osKernelGetState() == osKernelRunning) { - return (uint32_t)osKernelGetTickCount(); - } - /* If Kernel is not running wait approximately 1 ms then increment and return auxiliary tick counter value */ - for (i = (SystemCoreClock >> 14U); i > 0U; i--) { __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); } - return ++ticks; -} - void mx_init(void) { SystemClock_Config(); MX_GPIO_Init(); @@ -309,6 +298,27 @@ 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 diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c new file mode 100644 index 00000000..a4f3a4c1 --- /dev/null +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c @@ -0,0 +1,137 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f7xx_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 "stm32f7xx_hal.h" +#include "stm32f7xx_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 = 0U; + + uint32_t uwPrescalerValue = 0U; + uint32_t pFLatency; + HAL_StatusTypeDef status; + + /* 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; + htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + + status = HAL_TIM_Base_Init(&htim6); + if (status == HAL_OK) + { + /* Start the TIM time Base generation in interrupt mode */ + status = HAL_TIM_Base_Start_IT(&htim6); + if (status == HAL_OK) + { + /* Enable the TIM6 global Interrupt */ + HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); + /* Configure the SysTick IRQ priority */ + if (TickPriority < (1UL << __NVIC_PRIO_BITS)) + { + /* Configure the TIM IRQ priority */ + HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority, 0U); + uwTickPrio = TickPriority; + } + else + { + status = HAL_ERROR; + } + } + } + + /* Return function status */ + return status; +} + +/** + * @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); +} + diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c index 6d94cff3..ba6f6981 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c @@ -55,6 +55,7 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ +extern TIM_HandleTypeDef htim6; /* USER CODE BEGIN EV */ @@ -158,6 +159,20 @@ void DebugMon_Handler(void) /* please refer to the startup file (startup_stm32f7xx.s). */ /******************************************************************************/ +/** + * @brief This function handles TIM6 global interrupt, DAC1 and DAC2 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 */ diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/_Target_1/RTE_Components.h b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/_Target_1/RTE_Components.h index 7d372e9e..01af5920 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/_Target_1/RTE_Components.h +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/RTE/_Target_1/RTE_Components.h @@ -50,6 +50,8 @@ #define RTE_DEVICE_HAL_RCC /* Keil::Device:STM32Cube HAL:RNG:1.3.0 */ #define RTE_DEVICE_HAL_RNG +/* Keil::Device:STM32Cube HAL:TIM:1.3.0 */ +#define RTE_DEVICE_HAL_TIM /* Keil::Device:STM32Cube HAL:UART:1.3.0 */ #define RTE_DEVICE_HAL_UART /* Keil::Device:Startup:1.2.5 */ diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/device-dashboard.uvprojx b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/device-dashboard.uvprojx index 1ccf208a..476fd33a 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/device-dashboard.uvprojx +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/device-dashboard.uvprojx @@ -575,6 +575,12 @@ + + + + + + diff --git a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc index 452ec77e..122a1e7a 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc +++ b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc @@ -1,7 +1,7 @@ @@ -12,7 +12,7 @@ project-path - - Generated: 14/03/2023 13:35:04 + - Generated: 05/05/2023 16:28:43 @@ -44,6 +44,7 @@ + @@ -56,6 +57,7 @@ + diff --git a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/MX_Device.h b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/MX_Device.h index 371261ff..4b45a413 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/MX_Device.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/MX_Device.h @@ -1,6 +1,6 @@ /****************************************************************************** * File Name : MX_Device.h - * Date : 14/03/2023 13:35:04 + * Date : 05/05/2023 16:28:43 * Description : STM32Cube MX parameter definitions * Note : This file is generated by STM32CubeMX (DO NOT EDIT!) ******************************************************************************/ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject index 6b12af56..04eb904e 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject +++ b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject @@ -8,5 +8,5 @@ SourceFiles=;; HeaderPath=..\Inc HeaderFiles=stm32f7xx_it.h;stm32f7xx_hal_conf.h;main.h; SourcePath=..\Src -SourceFiles=stm32f7xx_it.c;stm32f7xx_hal_msp.c;main.c; +SourceFiles=stm32f7xx_it.c;stm32f7xx_hal_msp.c;stm32f7xx_hal_timebase_tim.c;main.c; diff --git a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h index f91ee4f8..eeeffc81 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h @@ -64,7 +64,7 @@ /* #define HAL_MMC_MODULE_ENABLED */ /* #define HAL_SPDIFRX_MODULE_ENABLED */ /* #define HAL_SPI_MODULE_ENABLED */ -/* #define HAL_TIM_MODULE_ENABLED */ +#define HAL_TIM_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED /* #define HAL_USART_MODULE_ENABLED */ /* #define HAL_IRDA_MODULE_ENABLED */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h index 12b9054a..e6b69435 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h @@ -52,6 +52,7 @@ void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void DebugMon_Handler(void); +void TIM6_DAC_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc index e5edcc6d..11c4940d 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc +++ b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc @@ -24,7 +24,7 @@ Mcu.Pin1=PA1 Mcu.Pin10=PG13 Mcu.Pin11=PB7 Mcu.Pin12=VP_RNG_VS_RNG -Mcu.Pin13=VP_SYS_VS_Systick +Mcu.Pin13=VP_SYS_VS_tim6 Mcu.Pin2=PA2 Mcu.Pin3=PA7 Mcu.Pin4=PC4 @@ -50,6 +50,9 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:false\:false\:true\:false +NVIC.TIM6_DAC_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:true +NVIC.TimeBase=TIM6_DAC_IRQn +NVIC.TimeBaseIP=TIM6 NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false PA1.Mode=RMII PA1.Signal=ETH_REF_CLK @@ -173,6 +176,6 @@ USART3.IPParameters=VirtualMode-Asynchronous USART3.VirtualMode-Asynchronous=VM_ASYNC VP_RNG_VS_RNG.Mode=RNG_Activate VP_RNG_VS_RNG.Signal=RNG_VS_RNG -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick +VP_SYS_VS_tim6.Mode=TIM6 +VP_SYS_VS_tim6.Signal=SYS_VS_tim6 board=custom diff --git a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c index 98f0d5fe..37eab800 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c +++ b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c @@ -84,21 +84,6 @@ static void MX_RNG_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ -// adapted from -// https://www.keil.com/pack/doc/STM32Cube/html/cubemx_using.html -// https://developer.arm.com/documentation/ka003821/latest -uint32_t HAL_GetTick (void) { - static uint32_t ticks = 0U; - uint32_t i; - if (osKernelRunning()) { - extern uint32_t rt_time_get(void); - return rt_time_get(); - } - /* If Kernel is not running wait approximately 1 ms then increment and return auxiliary tick counter value */ - for (i = (SystemCoreClock >> 14U); i > 0U; i--) { __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); } - return ++ticks; -} - void mx_init(void) { SystemClock_Config(); MX_GPIO_Init(); @@ -313,6 +298,27 @@ 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 diff --git a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c new file mode 100644 index 00000000..a4f3a4c1 --- /dev/null +++ b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c @@ -0,0 +1,137 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f7xx_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 "stm32f7xx_hal.h" +#include "stm32f7xx_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 = 0U; + + uint32_t uwPrescalerValue = 0U; + uint32_t pFLatency; + HAL_StatusTypeDef status; + + /* 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; + htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + + status = HAL_TIM_Base_Init(&htim6); + if (status == HAL_OK) + { + /* Start the TIM time Base generation in interrupt mode */ + status = HAL_TIM_Base_Start_IT(&htim6); + if (status == HAL_OK) + { + /* Enable the TIM6 global Interrupt */ + HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); + /* Configure the SysTick IRQ priority */ + if (TickPriority < (1UL << __NVIC_PRIO_BITS)) + { + /* Configure the TIM IRQ priority */ + HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority, 0U); + uwTickPrio = TickPriority; + } + else + { + status = HAL_ERROR; + } + } + } + + /* Return function status */ + return status; +} + +/** + * @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); +} + diff --git a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c index 6d94cff3..ba6f6981 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c +++ b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c @@ -55,6 +55,7 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ +extern TIM_HandleTypeDef htim6; /* USER CODE BEGIN EV */ @@ -158,6 +159,20 @@ void DebugMon_Handler(void) /* please refer to the startup file (startup_stm32f7xx.s). */ /******************************************************************************/ +/** + * @brief This function handles TIM6 global interrupt, DAC1 and DAC2 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 */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/_Target_1/RTE_Components.h b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/_Target_1/RTE_Components.h index 0f309136..7f846979 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/_Target_1/RTE_Components.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/RTE/_Target_1/RTE_Components.h @@ -57,6 +57,8 @@ #define RTE_DEVICE_HAL_RCC /* Keil::Device:STM32Cube HAL:RNG:1.3.0 */ #define RTE_DEVICE_HAL_RNG +/* Keil::Device:STM32Cube HAL:TIM:1.3.0 */ +#define RTE_DEVICE_HAL_TIM /* Keil::Device:STM32Cube HAL:UART:1.3.0 */ #define RTE_DEVICE_HAL_UART /* Keil::Device:Startup:1.2.5 */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/device-dashboard.uvprojx b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/device-dashboard.uvprojx index 8abe12a7..cc6c84b0 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx-mdk/device-dashboard.uvprojx +++ b/examples/stm32/nucleo-f746zg-keil-rtx-mdk/device-dashboard.uvprojx @@ -602,6 +602,12 @@ + + + + + + diff --git a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc index 452ec77e..c8213a69 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc +++ b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc @@ -1,7 +1,7 @@ @@ -12,7 +12,7 @@ project-path - - Generated: 14/03/2023 13:35:04 + - Generated: 05/05/2023 17:27:28 @@ -44,6 +44,7 @@ + @@ -56,6 +57,7 @@ + diff --git a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/MX_Device.h b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/MX_Device.h index 371261ff..a1a079db 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/MX_Device.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/MX_Device.h @@ -1,6 +1,6 @@ /****************************************************************************** * File Name : MX_Device.h - * Date : 14/03/2023 13:35:04 + * Date : 05/05/2023 17:27:28 * Description : STM32Cube MX parameter definitions * Note : This file is generated by STM32CubeMX (DO NOT EDIT!) ******************************************************************************/ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject index 6b12af56..04eb904e 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject +++ b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject @@ -8,5 +8,5 @@ SourceFiles=;; HeaderPath=..\Inc HeaderFiles=stm32f7xx_it.h;stm32f7xx_hal_conf.h;main.h; SourcePath=..\Src -SourceFiles=stm32f7xx_it.c;stm32f7xx_hal_msp.c;main.c; +SourceFiles=stm32f7xx_it.c;stm32f7xx_hal_msp.c;stm32f7xx_hal_timebase_tim.c;main.c; diff --git a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h index f91ee4f8..eeeffc81 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h @@ -64,7 +64,7 @@ /* #define HAL_MMC_MODULE_ENABLED */ /* #define HAL_SPDIFRX_MODULE_ENABLED */ /* #define HAL_SPI_MODULE_ENABLED */ -/* #define HAL_TIM_MODULE_ENABLED */ +#define HAL_TIM_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED /* #define HAL_USART_MODULE_ENABLED */ /* #define HAL_IRDA_MODULE_ENABLED */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h index 12b9054a..e6b69435 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h @@ -52,6 +52,7 @@ void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void DebugMon_Handler(void); +void TIM6_DAC_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc index e5edcc6d..11c4940d 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc +++ b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc @@ -24,7 +24,7 @@ Mcu.Pin1=PA1 Mcu.Pin10=PG13 Mcu.Pin11=PB7 Mcu.Pin12=VP_RNG_VS_RNG -Mcu.Pin13=VP_SYS_VS_Systick +Mcu.Pin13=VP_SYS_VS_tim6 Mcu.Pin2=PA2 Mcu.Pin3=PA7 Mcu.Pin4=PC4 @@ -50,6 +50,9 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:false\:false\:true\:false +NVIC.TIM6_DAC_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:true +NVIC.TimeBase=TIM6_DAC_IRQn +NVIC.TimeBaseIP=TIM6 NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false PA1.Mode=RMII PA1.Signal=ETH_REF_CLK @@ -173,6 +176,6 @@ USART3.IPParameters=VirtualMode-Asynchronous USART3.VirtualMode-Asynchronous=VM_ASYNC VP_RNG_VS_RNG.Mode=RNG_Activate VP_RNG_VS_RNG.Signal=RNG_VS_RNG -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick +VP_SYS_VS_tim6.Mode=TIM6 +VP_SYS_VS_tim6.Signal=SYS_VS_tim6 board=custom diff --git a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c index 98f0d5fe..37eab800 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c +++ b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c @@ -84,21 +84,6 @@ static void MX_RNG_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ -// adapted from -// https://www.keil.com/pack/doc/STM32Cube/html/cubemx_using.html -// https://developer.arm.com/documentation/ka003821/latest -uint32_t HAL_GetTick (void) { - static uint32_t ticks = 0U; - uint32_t i; - if (osKernelRunning()) { - extern uint32_t rt_time_get(void); - return rt_time_get(); - } - /* If Kernel is not running wait approximately 1 ms then increment and return auxiliary tick counter value */ - for (i = (SystemCoreClock >> 14U); i > 0U; i--) { __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); } - return ++ticks; -} - void mx_init(void) { SystemClock_Config(); MX_GPIO_Init(); @@ -313,6 +298,27 @@ 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 diff --git a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c new file mode 100644 index 00000000..a4f3a4c1 --- /dev/null +++ b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c @@ -0,0 +1,137 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f7xx_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 "stm32f7xx_hal.h" +#include "stm32f7xx_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 = 0U; + + uint32_t uwPrescalerValue = 0U; + uint32_t pFLatency; + HAL_StatusTypeDef status; + + /* 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; + htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + + status = HAL_TIM_Base_Init(&htim6); + if (status == HAL_OK) + { + /* Start the TIM time Base generation in interrupt mode */ + status = HAL_TIM_Base_Start_IT(&htim6); + if (status == HAL_OK) + { + /* Enable the TIM6 global Interrupt */ + HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); + /* Configure the SysTick IRQ priority */ + if (TickPriority < (1UL << __NVIC_PRIO_BITS)) + { + /* Configure the TIM IRQ priority */ + HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority, 0U); + uwTickPrio = TickPriority; + } + else + { + status = HAL_ERROR; + } + } + } + + /* Return function status */ + return status; +} + +/** + * @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); +} + diff --git a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c index 6d94cff3..ba6f6981 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c +++ b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c @@ -55,6 +55,7 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ +extern TIM_HandleTypeDef htim6; /* USER CODE BEGIN EV */ @@ -158,6 +159,20 @@ void DebugMon_Handler(void) /* please refer to the startup file (startup_stm32f7xx.s). */ /******************************************************************************/ +/** + * @brief This function handles TIM6 global interrupt, DAC1 and DAC2 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 */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/_Target_1/RTE_Components.h b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/_Target_1/RTE_Components.h index 3a34210b..d7f21089 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx/RTE/_Target_1/RTE_Components.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx/RTE/_Target_1/RTE_Components.h @@ -40,6 +40,8 @@ #define RTE_DEVICE_HAL_RCC /* Keil::Device:STM32Cube HAL:RNG:1.3.0 */ #define RTE_DEVICE_HAL_RNG +/* Keil::Device:STM32Cube HAL:TIM:1.3.0 */ +#define RTE_DEVICE_HAL_TIM /* Keil::Device:STM32Cube HAL:UART:1.3.0 */ #define RTE_DEVICE_HAL_UART /* Keil::Device:Startup:1.2.5 */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx/device-dashboard.uvprojx b/examples/stm32/nucleo-f746zg-keil-rtx/device-dashboard.uvprojx index ac27f70a..8901a4fb 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx/device-dashboard.uvprojx +++ b/examples/stm32/nucleo-f746zg-keil-rtx/device-dashboard.uvprojx @@ -542,6 +542,12 @@ + + + + + + diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc index 452ec77e..f8dfe80a 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc @@ -1,7 +1,7 @@ @@ -12,7 +12,7 @@ project-path - - Generated: 14/03/2023 13:35:04 + - Generated: 05/05/2023 14:58:31 @@ -44,6 +44,7 @@ + @@ -56,6 +57,7 @@ + diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/MX_Device.h b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/MX_Device.h index 371261ff..e80c30dc 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/MX_Device.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/MX_Device.h @@ -1,6 +1,6 @@ /****************************************************************************** * File Name : MX_Device.h - * Date : 14/03/2023 13:35:04 + * Date : 05/05/2023 14:58:31 * Description : STM32Cube MX parameter definitions * Note : This file is generated by STM32CubeMX (DO NOT EDIT!) ******************************************************************************/ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject index 6b12af56..04eb904e 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject @@ -8,5 +8,5 @@ SourceFiles=;; HeaderPath=..\Inc HeaderFiles=stm32f7xx_it.h;stm32f7xx_hal_conf.h;main.h; SourcePath=..\Src -SourceFiles=stm32f7xx_it.c;stm32f7xx_hal_msp.c;main.c; +SourceFiles=stm32f7xx_it.c;stm32f7xx_hal_msp.c;stm32f7xx_hal_timebase_tim.c;main.c; diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h index f91ee4f8..eeeffc81 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h @@ -64,7 +64,7 @@ /* #define HAL_MMC_MODULE_ENABLED */ /* #define HAL_SPDIFRX_MODULE_ENABLED */ /* #define HAL_SPI_MODULE_ENABLED */ -/* #define HAL_TIM_MODULE_ENABLED */ +#define HAL_TIM_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED /* #define HAL_USART_MODULE_ENABLED */ /* #define HAL_IRDA_MODULE_ENABLED */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h index 12b9054a..e6b69435 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h @@ -52,6 +52,7 @@ void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void DebugMon_Handler(void); +void TIM6_DAC_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc index e5edcc6d..11c4940d 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc @@ -24,7 +24,7 @@ Mcu.Pin1=PA1 Mcu.Pin10=PG13 Mcu.Pin11=PB7 Mcu.Pin12=VP_RNG_VS_RNG -Mcu.Pin13=VP_SYS_VS_Systick +Mcu.Pin13=VP_SYS_VS_tim6 Mcu.Pin2=PA2 Mcu.Pin3=PA7 Mcu.Pin4=PC4 @@ -50,6 +50,9 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:false\:false\:true\:false +NVIC.TIM6_DAC_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:true +NVIC.TimeBase=TIM6_DAC_IRQn +NVIC.TimeBaseIP=TIM6 NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false PA1.Mode=RMII PA1.Signal=ETH_REF_CLK @@ -173,6 +176,6 @@ USART3.IPParameters=VirtualMode-Asynchronous USART3.VirtualMode-Asynchronous=VM_ASYNC VP_RNG_VS_RNG.Mode=RNG_Activate VP_RNG_VS_RNG.Signal=RNG_VS_RNG -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick +VP_SYS_VS_tim6.Mode=TIM6 +VP_SYS_VS_tim6.Signal=SYS_VS_tim6 board=custom diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c index 22cdc9b7..cc451be4 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c @@ -84,18 +84,6 @@ static void MX_RNG_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ -// https://www.keil.com/pack/doc/STM32Cube/html/cubemx_using.html -uint32_t HAL_GetTick (void) { - static uint32_t ticks = 0U; - uint32_t i; - if (osKernelGetState() == osKernelRunning) { - return (uint32_t)osKernelGetTickCount(); - } - /* If Kernel is not running wait approximately 1 ms then increment and return auxiliary tick counter value */ - for (i = (SystemCoreClock >> 14U); i > 0U; i--) { __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); } - return ++ticks; -} - void mx_init(void) { SystemClock_Config(); MX_GPIO_Init(); @@ -310,6 +298,27 @@ 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 diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c new file mode 100644 index 00000000..a4f3a4c1 --- /dev/null +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c @@ -0,0 +1,137 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f7xx_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 "stm32f7xx_hal.h" +#include "stm32f7xx_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 = 0U; + + uint32_t uwPrescalerValue = 0U; + uint32_t pFLatency; + HAL_StatusTypeDef status; + + /* 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; + htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + + status = HAL_TIM_Base_Init(&htim6); + if (status == HAL_OK) + { + /* Start the TIM time Base generation in interrupt mode */ + status = HAL_TIM_Base_Start_IT(&htim6); + if (status == HAL_OK) + { + /* Enable the TIM6 global Interrupt */ + HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); + /* Configure the SysTick IRQ priority */ + if (TickPriority < (1UL << __NVIC_PRIO_BITS)) + { + /* Configure the TIM IRQ priority */ + HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority, 0U); + uwTickPrio = TickPriority; + } + else + { + status = HAL_ERROR; + } + } + } + + /* Return function status */ + return status; +} + +/** + * @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); +} + diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c index 6d94cff3..ba6f6981 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c @@ -55,6 +55,7 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ +extern TIM_HandleTypeDef htim6; /* USER CODE BEGIN EV */ @@ -158,6 +159,20 @@ void DebugMon_Handler(void) /* please refer to the startup file (startup_stm32f7xx.s). */ /******************************************************************************/ +/** + * @brief This function handles TIM6 global interrupt, DAC1 and DAC2 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 */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/_Target_1/RTE_Components.h b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/_Target_1/RTE_Components.h index fc47de41..9c7bd881 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/_Target_1/RTE_Components.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/RTE/_Target_1/RTE_Components.h @@ -44,6 +44,8 @@ #define RTE_DEVICE_HAL_RCC /* Keil::Device:STM32Cube HAL:RNG:1.3.0 */ #define RTE_DEVICE_HAL_RNG +/* Keil::Device:STM32Cube HAL:TIM:1.3.0 */ +#define RTE_DEVICE_HAL_TIM /* Keil::Device:STM32Cube HAL:UART:1.3.0 */ #define RTE_DEVICE_HAL_UART /* Keil::Device:Startup:1.2.5 */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/device-dashboard.uvprojx b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/device-dashboard.uvprojx index d6e759bc..1d534457 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/device-dashboard.uvprojx +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-lwip/device-dashboard.uvprojx @@ -572,6 +572,12 @@ + + + + + + diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc index 452ec77e..c05794ad 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc @@ -1,7 +1,7 @@ @@ -12,7 +12,7 @@ project-path - - Generated: 14/03/2023 13:35:04 + - Generated: 05/05/2023 15:02:27 @@ -44,6 +44,7 @@ + @@ -56,6 +57,7 @@ + diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/MX_Device.h b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/MX_Device.h index 371261ff..643da173 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/MX_Device.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/MX_Device.h @@ -1,6 +1,6 @@ /****************************************************************************** * File Name : MX_Device.h - * Date : 14/03/2023 13:35:04 + * Date : 05/05/2023 15:02:28 * Description : STM32Cube MX parameter definitions * Note : This file is generated by STM32CubeMX (DO NOT EDIT!) ******************************************************************************/ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject index 6b12af56..04eb904e 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject @@ -8,5 +8,5 @@ SourceFiles=;; HeaderPath=..\Inc HeaderFiles=stm32f7xx_it.h;stm32f7xx_hal_conf.h;main.h; SourcePath=..\Src -SourceFiles=stm32f7xx_it.c;stm32f7xx_hal_msp.c;main.c; +SourceFiles=stm32f7xx_it.c;stm32f7xx_hal_msp.c;stm32f7xx_hal_timebase_tim.c;main.c; diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h index f91ee4f8..eeeffc81 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h @@ -64,7 +64,7 @@ /* #define HAL_MMC_MODULE_ENABLED */ /* #define HAL_SPDIFRX_MODULE_ENABLED */ /* #define HAL_SPI_MODULE_ENABLED */ -/* #define HAL_TIM_MODULE_ENABLED */ +#define HAL_TIM_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED /* #define HAL_USART_MODULE_ENABLED */ /* #define HAL_IRDA_MODULE_ENABLED */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h index 12b9054a..e6b69435 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h @@ -52,6 +52,7 @@ void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void DebugMon_Handler(void); +void TIM6_DAC_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc index e5edcc6d..11c4940d 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc @@ -24,7 +24,7 @@ Mcu.Pin1=PA1 Mcu.Pin10=PG13 Mcu.Pin11=PB7 Mcu.Pin12=VP_RNG_VS_RNG -Mcu.Pin13=VP_SYS_VS_Systick +Mcu.Pin13=VP_SYS_VS_tim6 Mcu.Pin2=PA2 Mcu.Pin3=PA7 Mcu.Pin4=PC4 @@ -50,6 +50,9 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:false\:false\:true\:false +NVIC.TIM6_DAC_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:true +NVIC.TimeBase=TIM6_DAC_IRQn +NVIC.TimeBaseIP=TIM6 NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false PA1.Mode=RMII PA1.Signal=ETH_REF_CLK @@ -173,6 +176,6 @@ USART3.IPParameters=VirtualMode-Asynchronous USART3.VirtualMode-Asynchronous=VM_ASYNC VP_RNG_VS_RNG.Mode=RNG_Activate VP_RNG_VS_RNG.Signal=RNG_VS_RNG -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick +VP_SYS_VS_tim6.Mode=TIM6 +VP_SYS_VS_tim6.Signal=SYS_VS_tim6 board=custom diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c index 22cdc9b7..cc451be4 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c @@ -84,18 +84,6 @@ static void MX_RNG_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ -// https://www.keil.com/pack/doc/STM32Cube/html/cubemx_using.html -uint32_t HAL_GetTick (void) { - static uint32_t ticks = 0U; - uint32_t i; - if (osKernelGetState() == osKernelRunning) { - return (uint32_t)osKernelGetTickCount(); - } - /* If Kernel is not running wait approximately 1 ms then increment and return auxiliary tick counter value */ - for (i = (SystemCoreClock >> 14U); i > 0U; i--) { __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); } - return ++ticks; -} - void mx_init(void) { SystemClock_Config(); MX_GPIO_Init(); @@ -310,6 +298,27 @@ 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 diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c new file mode 100644 index 00000000..a4f3a4c1 --- /dev/null +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c @@ -0,0 +1,137 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f7xx_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 "stm32f7xx_hal.h" +#include "stm32f7xx_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 = 0U; + + uint32_t uwPrescalerValue = 0U; + uint32_t pFLatency; + HAL_StatusTypeDef status; + + /* 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; + htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + + status = HAL_TIM_Base_Init(&htim6); + if (status == HAL_OK) + { + /* Start the TIM time Base generation in interrupt mode */ + status = HAL_TIM_Base_Start_IT(&htim6); + if (status == HAL_OK) + { + /* Enable the TIM6 global Interrupt */ + HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); + /* Configure the SysTick IRQ priority */ + if (TickPriority < (1UL << __NVIC_PRIO_BITS)) + { + /* Configure the TIM IRQ priority */ + HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority, 0U); + uwTickPrio = TickPriority; + } + else + { + status = HAL_ERROR; + } + } + } + + /* Return function status */ + return status; +} + +/** + * @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); +} + diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c index 6d94cff3..ba6f6981 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c @@ -55,6 +55,7 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ +extern TIM_HandleTypeDef htim6; /* USER CODE BEGIN EV */ @@ -158,6 +159,20 @@ void DebugMon_Handler(void) /* please refer to the startup file (startup_stm32f7xx.s). */ /******************************************************************************/ +/** + * @brief This function handles TIM6 global interrupt, DAC1 and DAC2 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 */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/_Target_1/RTE_Components.h b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/_Target_1/RTE_Components.h index a795d9d1..02251248 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/_Target_1/RTE_Components.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/RTE/_Target_1/RTE_Components.h @@ -57,6 +57,8 @@ #define RTE_DEVICE_HAL_RCC /* Keil::Device:STM32Cube HAL:RNG:1.3.0 */ #define RTE_DEVICE_HAL_RNG +/* Keil::Device:STM32Cube HAL:TIM:1.3.0 */ +#define RTE_DEVICE_HAL_TIM /* Keil::Device:STM32Cube HAL:UART:1.3.0 */ #define RTE_DEVICE_HAL_UART /* Keil::Device:Startup:1.2.5 */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/device-dashboard.uvoptx b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/device-dashboard.uvoptx index fce7d8d7..68f145cb 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/device-dashboard.uvoptx +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/device-dashboard.uvoptx @@ -365,7 +365,7 @@ ::CMSIS Driver - 0 + 1 0 0 1 @@ -381,7 +381,7 @@ ::Device - 0 + 1 0 0 1 diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/device-dashboard.uvprojx b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/device-dashboard.uvprojx index e1bf39ff..f66fcafa 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/device-dashboard.uvprojx +++ b/examples/stm32/nucleo-f746zg-keil-rtx5-mdk/device-dashboard.uvprojx @@ -602,6 +602,12 @@ + + + + + + diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc index 452ec77e..25595316 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc +++ b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/FrameworkCubeMX.gpdsc @@ -1,7 +1,7 @@ @@ -12,7 +12,7 @@ project-path - - Generated: 14/03/2023 13:35:04 + - Generated: 05/05/2023 17:33:46 @@ -44,6 +44,7 @@ + @@ -56,6 +57,7 @@ + diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/MX_Device.h b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/MX_Device.h index 371261ff..84934f9f 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/MX_Device.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/MX_Device.h @@ -1,6 +1,6 @@ /****************************************************************************** * File Name : MX_Device.h - * Date : 14/03/2023 13:35:04 + * Date : 05/05/2023 17:33:47 * Description : STM32Cube MX parameter definitions * Note : This file is generated by STM32CubeMX (DO NOT EDIT!) ******************************************************************************/ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject index 6b12af56..04eb904e 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject +++ b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/.mxproject @@ -8,5 +8,5 @@ SourceFiles=;; HeaderPath=..\Inc HeaderFiles=stm32f7xx_it.h;stm32f7xx_hal_conf.h;main.h; SourcePath=..\Src -SourceFiles=stm32f7xx_it.c;stm32f7xx_hal_msp.c;main.c; +SourceFiles=stm32f7xx_it.c;stm32f7xx_hal_msp.c;stm32f7xx_hal_timebase_tim.c;main.c; diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h index f91ee4f8..eeeffc81 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_hal_conf.h @@ -64,7 +64,7 @@ /* #define HAL_MMC_MODULE_ENABLED */ /* #define HAL_SPDIFRX_MODULE_ENABLED */ /* #define HAL_SPI_MODULE_ENABLED */ -/* #define HAL_TIM_MODULE_ENABLED */ +#define HAL_TIM_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED /* #define HAL_USART_MODULE_ENABLED */ /* #define HAL_IRDA_MODULE_ENABLED */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h index 12b9054a..e6b69435 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Inc/stm32f7xx_it.h @@ -52,6 +52,7 @@ void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void DebugMon_Handler(void); +void TIM6_DAC_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc index e5edcc6d..11c4940d 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc +++ b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/STCubeGenerated.ioc @@ -24,7 +24,7 @@ Mcu.Pin1=PA1 Mcu.Pin10=PG13 Mcu.Pin11=PB7 Mcu.Pin12=VP_RNG_VS_RNG -Mcu.Pin13=VP_SYS_VS_Systick +Mcu.Pin13=VP_SYS_VS_tim6 Mcu.Pin2=PA2 Mcu.Pin3=PA7 Mcu.Pin4=PC4 @@ -50,6 +50,9 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:false\:false\:true\:false +NVIC.TIM6_DAC_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:true +NVIC.TimeBase=TIM6_DAC_IRQn +NVIC.TimeBaseIP=TIM6 NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false PA1.Mode=RMII PA1.Signal=ETH_REF_CLK @@ -173,6 +176,6 @@ USART3.IPParameters=VirtualMode-Asynchronous USART3.VirtualMode-Asynchronous=VM_ASYNC VP_RNG_VS_RNG.Mode=RNG_Activate VP_RNG_VS_RNG.Signal=RNG_VS_RNG -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick +VP_SYS_VS_tim6.Mode=TIM6 +VP_SYS_VS_tim6.Signal=SYS_VS_tim6 board=custom diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c index 22cdc9b7..cc451be4 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c +++ b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/main.c @@ -84,18 +84,6 @@ static void MX_RNG_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ -// https://www.keil.com/pack/doc/STM32Cube/html/cubemx_using.html -uint32_t HAL_GetTick (void) { - static uint32_t ticks = 0U; - uint32_t i; - if (osKernelGetState() == osKernelRunning) { - return (uint32_t)osKernelGetTickCount(); - } - /* If Kernel is not running wait approximately 1 ms then increment and return auxiliary tick counter value */ - for (i = (SystemCoreClock >> 14U); i > 0U; i--) { __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); } - return ++ticks; -} - void mx_init(void) { SystemClock_Config(); MX_GPIO_Init(); @@ -310,6 +298,27 @@ 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 diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c new file mode 100644 index 00000000..a4f3a4c1 --- /dev/null +++ b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_hal_timebase_tim.c @@ -0,0 +1,137 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f7xx_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 "stm32f7xx_hal.h" +#include "stm32f7xx_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 = 0U; + + uint32_t uwPrescalerValue = 0U; + uint32_t pFLatency; + HAL_StatusTypeDef status; + + /* 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; + htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + + status = HAL_TIM_Base_Init(&htim6); + if (status == HAL_OK) + { + /* Start the TIM time Base generation in interrupt mode */ + status = HAL_TIM_Base_Start_IT(&htim6); + if (status == HAL_OK) + { + /* Enable the TIM6 global Interrupt */ + HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); + /* Configure the SysTick IRQ priority */ + if (TickPriority < (1UL << __NVIC_PRIO_BITS)) + { + /* Configure the TIM IRQ priority */ + HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority, 0U); + uwTickPrio = TickPriority; + } + else + { + status = HAL_ERROR; + } + } + } + + /* Return function status */ + return status; +} + +/** + * @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); +} + diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c index 6d94cff3..ba6f6981 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c +++ b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/Device/STM32F746ZGTx/STCubeGenerated/Src/stm32f7xx_it.c @@ -55,6 +55,7 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ +extern TIM_HandleTypeDef htim6; /* USER CODE BEGIN EV */ @@ -158,6 +159,20 @@ void DebugMon_Handler(void) /* please refer to the startup file (startup_stm32f7xx.s). */ /******************************************************************************/ +/** + * @brief This function handles TIM6 global interrupt, DAC1 and DAC2 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 */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/_Target_1/RTE_Components.h b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/_Target_1/RTE_Components.h index f771b6b8..61456aa3 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/_Target_1/RTE_Components.h +++ b/examples/stm32/nucleo-f746zg-keil-rtx5/RTE/_Target_1/RTE_Components.h @@ -40,6 +40,8 @@ #define RTE_DEVICE_HAL_RCC /* Keil::Device:STM32Cube HAL:RNG:1.3.0 */ #define RTE_DEVICE_HAL_RNG +/* Keil::Device:STM32Cube HAL:TIM:1.3.0 */ +#define RTE_DEVICE_HAL_TIM /* Keil::Device:STM32Cube HAL:UART:1.3.0 */ #define RTE_DEVICE_HAL_UART /* Keil::Device:Startup:1.2.5 */ diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5/device-dashboard.uvprojx b/examples/stm32/nucleo-f746zg-keil-rtx5/device-dashboard.uvprojx index d3b86536..9c618447 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5/device-dashboard.uvprojx +++ b/examples/stm32/nucleo-f746zg-keil-rtx5/device-dashboard.uvprojx @@ -542,6 +542,12 @@ + + + + + + diff --git a/test/keil/Clean b/test/keil/Clean new file mode 100644 index 00000000..5d1c13fd --- /dev/null +++ b/test/keil/Clean @@ -0,0 +1,12 @@ +# Do NOT use parenthesis on Windows project dir names +PROJECTS ?= $(wildcard ../../examples/stm32/nucleo-*-keil-*) + +MAKEFILEPATH := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))) +BATPATH := $(subst /,\,$(MAKEFILEPATH)) + +all: $(PROJECTS) + +$(PROJECTS): FORCE + $(BATPATH)uniclean.bat $(subst /,\,$@) + +FORCE: diff --git a/test/keil/uniclean.bat b/test/keil/uniclean.bat new file mode 100644 index 00000000..5a57fb09 --- /dev/null +++ b/test/keil/uniclean.bat @@ -0,0 +1,6 @@ +cd %* +C:\Keil_v5\UV4\UV4.exe -c device-dashboard.uvprojx -j0 +del /S /Q DebugConfig Listings Objects +rd /S /Q DebugConfig +rd /S /Q Listings +rd /S /Q Objects