From 80358fc3b2502a3dbd491407032eb86d4530c265 Mon Sep 17 00:00:00 2001 From: Trent Gill Date: Tue, 4 Jun 2024 11:28:17 -0700 Subject: [PATCH] cleanup & debugging --- ll/debug_pin.c | 6 ++++++ ll/debug_pin.h | 2 ++ ll/debug_usart.h | 2 ++ ll/timers.c | 24 +++++++++++++++++++++++- ll/timers.h | 2 ++ stm32f7xx_it.c | 4 ++++ usbd/usbd_cdc_interface.c | 1 - usbd/usbd_main.c | 7 ------- usbd/usbd_main.h | 4 ++-- 9 files changed, 41 insertions(+), 11 deletions(-) diff --git a/ll/debug_pin.c b/ll/debug_pin.c index 4179a24b..ec18227b 100644 --- a/ll/debug_pin.c +++ b/ll/debug_pin.c @@ -19,3 +19,9 @@ void Debug_Pin_Set(int chan, int state ){ case 2: HAL_GPIO_WritePin( DBG_P_GPIO, DBG_P_PIN_B, state ); break; } } + +void Debug_Error_state(void){ + Debug_Pin_Set(0, 0); + Debug_Pin_Set(1, 0); + Debug_Pin_Set(2, 1); +} diff --git a/ll/debug_pin.h b/ll/debug_pin.h index 6799a86c..566bf02e 100644 --- a/ll/debug_pin.h +++ b/ll/debug_pin.h @@ -14,3 +14,5 @@ void Debug_Pin_Set(int chan, int state ); #define DBG_P_PIN_B GPIO_PIN_13 #define DBG_P_PIN_R GPIO_PIN_14 #define DBG_P_PIN_G GPIO_PIN_15 + +void Debug_Error_state(void); diff --git a/ll/debug_usart.h b/ll/debug_usart.h index 96c3a4d1..0ecb8790 100644 --- a/ll/debug_usart.h +++ b/ll/debug_usart.h @@ -40,9 +40,11 @@ // Setup functions & DMA/IT Handlers void Debug_USART_Init(void); void Debug_USART_DeInit(void); + void USARTx_DMA_TX_IRQHandler(void); void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart); void USARTx_IRQHandler(void); +void HAL_USART_ErrorCallback( USART_HandleTypeDef *husart ); // Communication Fns void U_PrintNow(void); diff --git a/ll/timers.c b/ll/timers.c index aae1ee07..63f11918 100644 --- a/ll/timers.c +++ b/ll/timers.c @@ -15,6 +15,8 @@ typedef struct{ TIM_CLK_ENABLE_t CLK_ENABLE; } Timer_setup_t; +static void Timer_Restart(int ix); + // function wrappers over HAL macros // TODO add TIM1 & TIM8. use different HAL functions //static void TIM1_CLK_EN(){ __HAL_RCC_TIM1_CLK_ENABLE } @@ -52,7 +54,6 @@ static const Timer_setup_t _timer[]= static TIM_HandleTypeDef TimHandle[MAX_LL_TIMERS]; static Timer_Callback_t callback[MAX_LL_TIMERS]; -// FIXME have to manually index the following void TIM3_IRQHandler( void ){ HAL_TIM_IRQHandler( &(TimHandle[0]) ); } void TIM4_IRQHandler( void ){ HAL_TIM_IRQHandler( &(TimHandle[1]) ); } void TIM5_IRQHandler( void ){ HAL_TIM_IRQHandler( &(TimHandle[2]) ); } @@ -106,6 +107,16 @@ void HAL_TIM_PeriodElapsedCallback( TIM_HandleTypeDef *htim ) } } +void HAL_TIM_ErrorCallback(TIM_HandleTypeDef* htim){ + Caw_printf("TIM error\n\r"); + for( int i=(MAX_LL_TIMERS-1); i>=0; i-- ){ + if( htim == &(TimHandle[i]) ){ + Timer_Restart(i); + return; + } + } +} + void Timer_Set_Params( int ix, float seconds ) { //FIXME limited to max~20s (p=0xFFFF & ps=0xFFFF) @@ -148,6 +159,17 @@ void Timer_Start( int ix, Timer_Callback_t cb ) } } +static void Timer_Restart(int ix){ + /// TODO need to reinit the timers? + uint8_t err; + BLOCK_IRQS( + err = HAL_TIM_Base_Start_IT( &(TimHandle[ix]) ); + ); + if( err != HAL_OK ){ + printf("Timer_Restart(%i) failed\n", ix); + } +} + void Timer_Stop( int ix ) { uint8_t err; diff --git a/ll/timers.h b/ll/timers.h index f09f6e4d..b12eb049 100644 --- a/ll/timers.h +++ b/ll/timers.h @@ -51,6 +51,7 @@ void Timer_Priority( int ix, int priority_level ); // public declarations of hal lib functions void HAL_TIM_PeriodElapsedCallback( TIM_HandleTypeDef *htim ); +void HAL_TIM_ErrorCallback(TIM_HandleTypeDef* htim); void TIM3_IRQHandler( void ); void TIM4_IRQHandler( void ); @@ -63,3 +64,4 @@ void TIM1_TRG_COM_TIM11_IRQHandler( void ); void TIM8_BRK_TIM12_IRQHandler( void ); void TIM8_UP_TIM13_IRQHandler( void ); void TIM8_TRG_COM_TIM14_IRQHandler( void ); + diff --git a/stm32f7xx_it.c b/stm32f7xx_it.c index 5eadef51..60b99d3a 100644 --- a/stm32f7xx_it.c +++ b/stm32f7xx_it.c @@ -1,6 +1,7 @@ #include "stm32f7xx_it.h" #include "stm32f7xx_hal.h" // HAL_IncTick +#include "ll/debug_pin.h" volatile int CPU_count = 0; @@ -31,6 +32,8 @@ int CPU_GetCount( void ) #include "ll/debug_usart.h" // U_PrintNow static void error( char* msg ){ + Debug_Error_state(); + printf("%s\n", msg); U_PrintNow(); while(1); @@ -49,6 +52,7 @@ void PendSV_Handler(void){ error("!PendSV"); } // prvGetRegistersFromStack(). void HardFault_Handler(void) { + Debug_Error_state(); __asm volatile ( " tst lr, #4 \n" diff --git a/usbd/usbd_cdc_interface.c b/usbd/usbd_cdc_interface.c index f937ca7d..88830813 100755 --- a/usbd/usbd_cdc_interface.c +++ b/usbd/usbd_cdc_interface.c @@ -80,7 +80,6 @@ static uint8_t UserTxBuffer[APP_TX_DATA_SIZE]; static uint32_t UserTxDataLen = 0; static uint32_t UserRxDataLen = 0; -// static TIM_HandleTypeDef USBTimHandle; int timer_index; extern USBD_HandleTypeDef USBD_Device; diff --git a/usbd/usbd_main.c b/usbd/usbd_main.c index 095c9a4b..a05d8a4d 100755 --- a/usbd/usbd_main.c +++ b/usbd/usbd_main.c @@ -38,10 +38,3 @@ void OTG_FS_IRQHandler(void) { HAL_PCD_IRQHandler(&hpcd); } - -extern TIM_HandleTypeDef USBTimHandle; - -void TIMu_IRQHandler(void) -{ - HAL_TIM_IRQHandler(&USBTimHandle); -} diff --git a/usbd/usbd_main.h b/usbd/usbd_main.h index 69340be9..52dc4406 100755 --- a/usbd/usbd_main.h +++ b/usbd/usbd_main.h @@ -8,9 +8,9 @@ #define USE_USB_FS +extern USBD_HandleTypeDef USBD_Device; + void USB_CDC_Init(int timer_index); void USB_CDC_DeInit(void); void OTG_FS_IRQHandler(void); - -void TIMu_IRQHandler(void);