Skip to content

Commit

Permalink
Fixing UART driver, leading to working TIC decode
Browse files Browse the repository at this point in the history
  • Loading branch information
lains committed Jan 27, 2024
1 parent c543b67 commit 86e42e3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
1 change: 1 addition & 0 deletions inc/stm32f7xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void PendSV_Handler(void);
void SysTick_Handler(void);
void EXTI15_10_IRQHandler(void);
void BSP_SDMMC_IRQHandler(void);
void USARTx_IRQHandler(void);

#ifdef __cplusplus
}
Expand Down
17 changes: 4 additions & 13 deletions src/hal/Stm32SerialDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern "C" {
#define USART3_FORCE_RESET() __HAL_RCC_USART3_FORCE_RESET()
#define USART3_RELEASE_RESET() __HAL_RCC_USART3_RELEASE_RESET()

/* Definition for USART3 Pins (forwarded to J-Link's virtual com port) */
/* Definition for USART3 Pins (forwarded to ST-Link's virtual com port) */
#define USART3_TX_PIN GPIO_PIN_8
#define USART3_TX_GPIO_PORT GPIOD
#define USART3_TX_AF GPIO_AF7_USART3
Expand All @@ -42,7 +42,6 @@ static void onTicUartRx(uint8_t incomingByte);
extern "C" {

static void MX_USART6_UART_Init(UART_HandleTypeDef* huart) {
#if 0
huart->Instance = USART6;
huart->Init.BaudRate = 9600;
huart->Init.WordLength = UART_WORDLENGTH_8B; // Note 7bits+parity bit
Expand All @@ -56,15 +55,13 @@ static void MX_USART6_UART_Init(UART_HandleTypeDef* huart) {
if (HAL_UART_Init(huart) != HAL_OK) {
OnError_Handler(1);
}
#endif
}

#if 0 // FIXME: move the correct init code from stm32f7xx_hal_msp.c into here
void HAL_UART_MspInit(UART_HandleTypeDef *huart) {
GPIO_InitTypeDef GPIO_InitStruct;
memset(&GPIO_InitStruct, 0, sizeof(GPIO_InitStruct));

if (huart->Instance!=USART6 /*&& huart->Instance!=USART3*/) {
if (huart->Instance!=USART6 /*&& huart->Instance!=USART3*/) { /* Initializing USART3 leads to a pinkish display, there is a probably a conflict on PINs */
return;
}

Expand Down Expand Up @@ -113,9 +110,8 @@ void HAL_UART_MspInit(UART_HandleTypeDef *huart) {
HAL_GPIO_Init(USART3_RX_GPIO_PORT, &GPIO_InitStruct);
}
}
#endif

#if 0 // FIXME: move the correct init code from stm32f7xx_hal_msp.c into here

void HAL_UART_MspDeInit(UART_HandleTypeDef *huart) {
/*##-1- Reset peripherals ##################################################*/
if (huart->Instance!=USART6 /*&& huart->Instance!=USART3*/) {
Expand Down Expand Up @@ -153,24 +149,19 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef *huart) {
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_8|GPIO_PIN_9);
}
}
#endif

inline void UART6_Enable_interrupt_callback(UART_HandleTypeDef* huart) {
#if 0
HAL_UART_Receive_IT(huart, UART6_rxBuffer, 1);
#endif
}

void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart)
{
#if 0
if (huart->Instance==USART6) {
unsigned char Received_Data = UART6_rxBuffer[0];
onTicUartRx((uint8_t)Received_Data);
BSP_LED_Toggle(LED3); // Toggle the orange LED when new serial data is received on the TIC UART
BSP_LED_Toggle(LED2); // Toggle the green LED when new serial data is received on the TIC UART
UART6_Enable_interrupt_callback(huart);
}
#endif
}
} // extern "C"

Expand Down
13 changes: 13 additions & 0 deletions src/stm32f7xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
LTDC_HandleTypeDef* get_hltdc(void); // C-linkage exported getter for hltdc handler
DSI_HandleTypeDef* get_hdsi(void); // C-linkage exported getter for hdsi handler
extern UART_HandleTypeDef* get_huart6(void);
/* Private functions ---------------------------------------------------------*/

/******************************************************************************/
Expand Down Expand Up @@ -145,6 +148,16 @@ void SysTick_Handler(void)
/* available peripheral interrupt handler's name please refer to the startup */
/* file (startup_stm32f7xx.s). */
/******************************************************************************/

/**
* @brief This function handles USART1 global interrupt.
*/
void USART6_IRQHandler(void)
{
UART_HandleTypeDef* huart6_ptr = get_huart6();
HAL_UART_IRQHandler(huart6_ptr);
}

/**
* @brief This function handles DSI Handler.
* @param None
Expand Down
16 changes: 14 additions & 2 deletions src/system_stm32f7xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,21 @@ void SystemInit_ExtMemCtl(void)
register uint32_t tmpreg = 0, timeout = 0xFFFF;
register __IO uint32_t index;

/* Enable GPIOD, GPIOE, GPIOF, GPIOG, GPIOH and GPIOI interface
/* Enable GPIOC, GPIOD, GPIOE, GPIOF, GPIOG and GPIOH interface
clock */
RCC->AHB1ENR |= 0x000001F8;
RCC->AHB1ENR |= 0x000000FC;

/* Connect PCx pins to FMC Alternate function */
GPIOC->AFR[0] = 0x0000C000;
GPIOC->AFR[1] = 0x00000000;
/* Configure PCx pins in Alternate function mode */
GPIOC->MODER = 0x00000080;
/* Configure PCx pins speed to 50 MHz */
GPIOC->OSPEEDR = 0x00000080;
/* Configure PCx pins Output type to push-pull */
GPIOC->OTYPER = 0x00000000;
/* No pull-up, pull-down for PCx pins */
GPIOC->PUPDR = 0x00000040;

/* Connect PDx pins to FMC Alternate function */
GPIOD->AFR[0] = 0x000000CC;
Expand Down

0 comments on commit 86e42e3

Please sign in to comment.