Skip to content

Commit

Permalink
cleanup & debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
trentgill committed Jun 4, 2024
1 parent 941ce1b commit 80358fc
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 11 deletions.
6 changes: 6 additions & 0 deletions ll/debug_pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions ll/debug_pin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 2 additions & 0 deletions ll/debug_usart.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 23 additions & 1 deletion ll/timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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]) ); }
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions ll/timers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );

4 changes: 4 additions & 0 deletions stm32f7xx_it.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "stm32f7xx_it.h"

#include "stm32f7xx_hal.h" // HAL_IncTick
#include "ll/debug_pin.h"

volatile int CPU_count = 0;

Expand Down Expand Up @@ -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);
Expand All @@ -49,6 +52,7 @@ void PendSV_Handler(void){ error("!PendSV"); }
// prvGetRegistersFromStack().
void HardFault_Handler(void)
{
Debug_Error_state();
__asm volatile
(
" tst lr, #4 \n"
Expand Down
1 change: 0 additions & 1 deletion usbd/usbd_cdc_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 0 additions & 7 deletions usbd/usbd_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions usbd/usbd_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 80358fc

Please sign in to comment.