Skip to content

Commit

Permalink
Fixing ST-LINK USART config
Browse files Browse the repository at this point in the history
  • Loading branch information
lains committed Feb 7, 2024
1 parent 3cd866f commit 75c0559
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
66 changes: 33 additions & 33 deletions src/hal/Stm32SerialDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ extern "C" {
#define USART6_FORCE_RESET() __HAL_RCC_USART6_FORCE_RESET()
#define USART6_RELEASE_RESET() __HAL_RCC_USART6_RELEASE_RESET()

#define USART3_CLK_ENABLE() __HAL_RCC_USART3_CLK_ENABLE()
#define USART3_CLK_DISABLE() __HAL_RCC_USART3_CLK_DISABLE()
#define USART3_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define USART3_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()

#define USART3_FORCE_RESET() __HAL_RCC_USART3_FORCE_RESET()
#define USART3_RELEASE_RESET() __HAL_RCC_USART3_RELEASE_RESET()

/* 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
#define USART3_RX_PIN GPIO_PIN_9
#define USART3_RX_GPIO_PORT GPIOD
#define USART3_RX_AF GPIO_AF7_USART3
#define USART1_CLK_ENABLE() __HAL_RCC_USART1_CLK_ENABLE()
#define USART1_CLK_DISABLE() __HAL_RCC_USART1_CLK_DISABLE()
#define USART1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define USART1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()

#define USART1_FORCE_RESET() __HAL_RCC_USART1_FORCE_RESET()
#define USART1_RELEASE_RESET() __HAL_RCC_USART1_RELEASE_RESET()

/* Definition for USART1 Pins (forwarded to ST-Link's virtual com port) */
#define USART1_TX_PIN GPIO_PIN_9
#define USART1_TX_GPIO_PORT GPIOA
#define USART1_TX_AF GPIO_AF7_USART1
#define USART1_RX_PIN GPIO_PIN_10
#define USART1_RX_GPIO_PORT GPIOA
#define USART1_RX_AF GPIO_AF7_USART1

/* Definition for USART6 Pins */
#define USART6_TX_PIN GPIO_PIN_6
Expand Down Expand Up @@ -91,23 +91,23 @@ void HAL_UART_MspInit(UART_HandleTypeDef *huart) {
HAL_NVIC_SetPriority(USART6_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART6_IRQn);
}
else if (huart->Instance==USART3) {
USART3_TX_GPIO_CLK_ENABLE();
USART3_RX_GPIO_CLK_ENABLE();
else if (huart->Instance==USART1) {
USART1_TX_GPIO_CLK_ENABLE();
USART1_RX_GPIO_CLK_ENABLE();

/* Peripheral clock enable */
USART3_CLK_ENABLE();
USART1_CLK_ENABLE();

GPIO_InitStruct.Pin = USART3_TX_PIN;
GPIO_InitStruct.Pin = USART1_TX_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = USART3_TX_AF;
HAL_GPIO_Init(USART3_TX_GPIO_PORT, &GPIO_InitStruct);
GPIO_InitStruct.Alternate = USART1_TX_AF;
HAL_GPIO_Init(USART1_TX_GPIO_PORT, &GPIO_InitStruct);

GPIO_InitStruct.Pin = USART3_RX_PIN;
GPIO_InitStruct.Alternate = USART3_RX_AF;
HAL_GPIO_Init(USART3_RX_GPIO_PORT, &GPIO_InitStruct);
GPIO_InitStruct.Pin = USART1_RX_PIN;
GPIO_InitStruct.Alternate = USART1_RX_AF;
HAL_GPIO_Init(USART1_RX_GPIO_PORT, &GPIO_InitStruct);
}
}

Expand All @@ -134,19 +134,19 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef *huart) {
/* USART6 interrupt DeInit */
HAL_NVIC_DisableIRQ(USART6_IRQn);
}
else if (huart->Instance==USART3) {
else if (huart->Instance==USART1) {
/* Peripheral clock disable */
USART3_FORCE_RESET();
USART3_RELEASE_RESET();
USART1_FORCE_RESET();
USART1_RELEASE_RESET();

/*##-2- Disable peripherals and GPIO Clocks #################################*/
USART3_CLK_DISABLE();
/* De-Initialize USART3 Tx and RX */
USART1_CLK_DISABLE();
/* De-Initialize USART1 Tx and RX */
/**USART6 GPIO Configuration
PD8 ------> USART3_TX
PD9 ------> USART3_RX
PA9 ------> USART1_TX
PA10 ------> USART1_RX
*/
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_8|GPIO_PIN_9);
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/stm32f7xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void SysTick_Handler(void)
/******************************************************************************/

/**
* @brief This function handles USART1 global interrupt.
* @brief This function handles USART6 global interrupt.
*/
void USART6_IRQHandler(void)
{
Expand Down

0 comments on commit 75c0559

Please sign in to comment.