cancel
Showing results for 
Search instead for 
Did you mean: 

ST OpenBootLoader for stm32g491 on UART1 not work

RS62
Associate

Hi everyone
using the UART1 by modifying the tx and rx pins according to my personal application, I am unable to connect with the 7F synchronization byte using stm32cubeprogrammer. Below is the code I modified:

 

/* ------------------------- Definitions for USART -------------------------- */
#define USARTx USART1 //USART2

#define USARTx_TX_PIN GPIO_PIN_4 //GPIO_PIN_5 USART2 VISIA //GPIO_PIN_9
#define USARTx_TX_GPIO_PORT GPIOC //GPIOD USART2 VISIA //GPIOA
#define USARTx_RX_PIN GPIO_PIN_7 //GPIO_PIN_6 USART2 VISIA //GPIO_PIN_10
#define USARTx_RX_GPIO_PORT GPIOB //GPIOD USART2 VISIA //GPIOA
#define USARTx_ALTERNATE GPIO_AF7_USART1 //GPIO_AF7_USART

 

void OPENBL_USART_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStruct;

/* Enable all resources clocks --------------------------------------------*/
/* Enable used GPIOx clocks */
//__HAL_RCC_GPIOA_CLK_ENABLE();
//__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();


/* Enable USART clock */
__HAL_RCC_USART1_CLK_ENABLE();
//__HAL_RCC_USART2_CLK_ENABLE();

/* USART1 pins configuration -----------------------------------------------*/
/*
+-------------+
| USART1 |
+-----+-------------+
| TX | PA9 |
+-----+-------------+
| RX | PA10 |
+-----+-------------+

+-------------+
|USART2 VISIA |
+-----+-------------+
| TX | PD5 |
+-----+-------------+
| RX | PA15 | PD6 sk beta
+-----+-------------+

+-------------+
|USART1 VISIA |
+-----+-------------+
| TX | PC4 |
+-----+-------------+
| RX | PB7 |
+-----+-------------+*/

GPIO_InitStruct.Pin = USARTx_TX_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;//GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;//GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = USARTx_ALTERNATE;
HAL_GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStruct);

GPIO_InitStruct.Pin = USARTx_RX_PIN;
HAL_GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStruct);

OPENBL_USART_Init();

}

/**
* @brief This function is used to detect if there is any activity on USART protocol.
* @retval None.
*/
uint8_t OPENBL_USART_ProtocolDetection(void)
{
uint8_t detected;

/* Aknowledge the host */
// OPENBL_USART_SendByte(ACK_BYTE);
//
// detected = 1U;
//
// return detected;

/* Check if the USART1 is addressed */
if (((USART1->ISR & LL_USART_ISR_ABRF) != 0) && ((USART1->ISR & LL_USART_ISR_ABRE) == 0)) {
/* Check if the USART2 is addressed */
//if (((USART2->ISR & LL_USART_ISR_ABRF) != 0) && ((USART2->ISR & LL_USART_ISR_ABRE) == 0)) {
/* Read byte in order to flush the 0x7F syncronization byte */
OPENBL_USART_ReadByte();

/* Aknowledge the host */
OPENBL_USART_SendByte(ACK_BYTE);

detected = 1U;
}
else
{
detected = 0U;
}

return detected;
}

If I always use the UART2 of my application it works instead.

I would like to thank anyone who can help me now.

 

1 REPLY 1
BarryWhit
Senior III

You can't do that. The TX/RX pins used by the bootloader are not configurable. The code modifications you've made obviously  have no effect on the bootloader which was programmed into the chip in the factory and is unaltered by downloading new user code into the flash, unless you explicitly replace it with a different bootloader. It's in a different region of the flash memory.

- If a post has answered your question, please acknowledge the help you received by clicking "Accept as Solution".
- Once you've solved your issue, please consider posting a summary of any additional details you've learned. Your new knowledge may help others in the future.