2024-04-18 01:30 AM - edited 2024-04-18 02:26 AM
Hello,
My STM32F7 crash after Reinit the UART :
- I have an UART for my RS232, and I can communicate to 2 devices by this RS232. So the customers choose on which device he want to send data, then I configure internals variables and the UART baudrate and flow control.
- So I use the next fonction to reinit my UART :
void RS232_Link_USART1_UART_ReInit(uint32_t BaudRate, uint32_t FlowCtrl)
{
HAL_UART_Abort_IT(&huart1);
HAL_UART_DeInit(&huart1);
huart1.Init.BaudRate = BaudRate;
huart1.Init.HwFlowCtl = FlowCtrl;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
uint8_t buff;
if (HAL_UART_Receive_IT(&huart1, &buff, 1) != HAL_OK) {
Error_Handler();
}
}
- This code works for 1 device but not for the other device. The thing that change is that the device which occure the crash send datas back after a transmit but we don't treat them. If I comment the part "HAL_UART_Receive_IT" it works, but I want to resolve the problem because it can maybe happen with the other device.
- Then the STM32 crash in the function :
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size, uint32_t Timeout)
{
const uint8_t *pdata8bits;
const uint16_t *pdata16bits;
uint32_t tickstart;
/* Check that a Tx process is not already ongoing */
if (huart->gState == HAL_UART_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}
__HAL_LOCK(huart);
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->gState = HAL_UART_STATE_BUSY_TX;
/* Init tickstart for timeout management */
tickstart = HAL_GetTick();
huart->TxXferSize = Size;
huart->TxXferCount = Size;
/* In case of 9bits/No Parity transfer, pData needs to be handled as a uint16_t pointer */
if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
{
pdata8bits = NULL;
pdata16bits = (const uint16_t *) pData;
}
else
{
pdata8bits = pData;
pdata16bits = NULL;
}
__HAL_UNLOCK(huart);
while (huart->TxXferCount > 0U)
{
if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}
if (pdata8bits == NULL)
{
huart->Instance->TDR = (uint16_t)(*pdata16bits & 0x01FFU);
pdata16bits++;
}
else
{
huart->Instance->TDR = (uint8_t)(*pdata8bits & 0xFFU);
pdata8bits++;
}
huart->TxXferCount--;
}
if (UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}
/* At end of Tx process, restore huart->gState to Ready */
huart->gState = HAL_UART_STATE_READY;
return HAL_OK;
}
else
{
return HAL_BUSY;
}
}
at this instruction :
huart->Instance->TDR = (uint8_t)(*pdata8bits & 0xFFU);
I dertermined that the problem is the variable "pdata8bits" but I don't know what's happening...
Thanks
Solved! Go to Solution.
2024-04-18 06:32 AM
Ok I found, just a buffer error about the :
uint8_t buff;
if (HAL_UART_Receive_IT(&huart1, &buff, 1) != HAL_OK)
2024-04-18 06:32 AM
Ok I found, just a buffer error about the :
uint8_t buff;
if (HAL_UART_Receive_IT(&huart1, &buff, 1) != HAL_OK)