HAL USART serial buffer pointers not declared volatile?
One of the practices of software design is to use volatile buffers when ISR and main loop access the data in the same buffers. This makes sure certain compiler register optimisations do not create unreliable code.
If I look at the HAL code for the USART for example:
/**
* @brief TX interrupt handler for 7 or 8 bits data word length .
* @note Function is called under interruption only, once
* interruptions have been enabled by HAL_UART_Transmit_IT().
* huart UART handle.
* @retval None
*/
static void UART_TxISR_8BIT(UART_HandleTypeDef *huart)
{
/* Check that a Tx process is ongoing */
if (huart->gState == HAL_UART_STATE_BUSY_TX)
{
if (huart->TxXferCount == 0U)
{
/* Disable the UART Transmit Data Register Empty Interrupt */
ATOMIC_CLEAR_BIT(huart->Instance->CR1, USART_CR1_TXEIE);
/* Enable the UART Transmit Complete Interrupt */
ATOMIC_SET_BIT(huart->Instance->CR1, USART_CR1_TCIE);
}
else
{
huart->Instance->TDR = (uint8_t)(*huart->pTxBuffPtr & (uint8_t)0xFF);
huart->pTxBuffPtr++;
huart->TxXferCount--;
}
}
}
I observe that the *huart->pTxBufferPtr is not declared volatile.
Nor is the type of const uint8_t pData in the signature of HAL_UART_Transmit_IT:
HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size);
Hence my question: how should I relate the concept of volatile to the HAL code sample above?
One could imagine (maybe too far - fetched): fill the buffer, call HAL_UART_Transmit_IT and later on the buffer is written due to some register optimisation?
