cancel
Showing results for 
Search instead for 
Did you mean: 

Usart_interrupt

julienterrier39
Associate II
Posted on August 25, 2015 at 21:34

Hello, I work with a STM32F429ZIT Âµcontroller and I have a set back. I wish find someone who could explain me what's happening in details in this part of the prog:

                                                

/** @brief  Enable the specified UART interrupt.

  * @param  __HANDLE__: specifies the UART Handle.

  *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or

  *         UART peripheral.

  * @param  __INTERRUPT__: specifies the UART interrupt source to enable.

  *          This parameter can be one of the following values:

  *            @arg UART_IT_CTS:  CTS change interrupt

  *            @arg UART_IT_LBD:  LIN Break detection interrupt

  *            @arg UART_IT_TXE:  Transmit Data Register empty interrupt

  *            @arg UART_IT_TC:   Transmission complete interrupt

  *            @arg UART_IT_RXNE: Receive Data register not empty interrupt

  *            @arg UART_IT_IDLE: Idle line detection interrupt

  *            @arg UART_IT_PE:   Parity Error interrupt

  *            @arg UART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)

  * @retval None

  */

#define UART_IT_MASK  ((uint32_t)0x0000FFFF)

#define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((((__INTERRUPT__) >> 28) == 1)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & UART_IT_MASK)): \

(((__INTERRUPT__) >> 28) == 2)? ((__HANDLE__)->Instance->CR2 |=  ((__INTERRUPT__) & UART_IT_MASK)): \

((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & UART_IT_MASK)))

11 REPLIES 11
julienterrier39
Associate II
Posted on August 26, 2015 at 05:31

FYI

/* Enable the UART Parity Error Interrupt */

    __HAL_UART_ENABLE_IT(huart, UART_IT_PE); it call from another fonction.

And UART_IT_PE = #define UART_IT_PE           ((uint32_t)(UART_CR1_REG_INDEX << 28 | USART_CR1_PEIE))

With

#define UART_CR1_REG_INDEX   1

#define  USART_CR1_PEIE                      ((uint32_t)0x0100)            /*!<PE Interrupt Enable

thanK you.

Posted on August 26, 2015 at 06:09

ST's libraries tend to use a compound bit encoding that can infer register and bit usage.

You have a macro here that with OR a low-order 16-bit value with one of the three control registers, CR1, CR2 or CR3 described by the upper 4-bit value

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
julienterrier39
Associate II
Posted on August 26, 2015 at 20:14

Thank you,

Thanks to some advices I understood how does it work and how to use it. 

However I didn't understand something in this programme which comes from UART_Twoboards_comIT. It's an example of STM32Cube_FW_F4_V1.6.0.

So my problem is located on the parity configuration and enabling its interruption.

In the program:

/*##-1- Configure the UART peripheral ######################################*/

- Parity = None

 UartHandle.Init.Parity       = UART_PARITY_NONE;

Therefore there is no parity and further in the same prog we can find this function:

HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)

Inside this function we can find:

 /* Enable the UART Parity Error Interrupt */

    __HAL_UART_ENABLE_IT(huart, UART_IT_PE);

Actually my question is why enable the parity Error Interrupt whereas the parity configuration is none ?

Posted on August 26, 2015 at 22:08

Actually my question is why enable the parity Error Interrupt whereas the parity configuration is none ?

 

Probably because the code you're looking at is a generic solution for the software side, the hardware is being configured not to generate/check parity, so enabling the interrupt is harmless. The reason they enabled all the interrupts is so the handler gets a chance to deal with issues that might otherwise jam up the USART and prevent further reception and/or transmission. They could check the configured state, they just don't, and the result shouldn't alter the behaviour of the system.

You might also further observe that interrupts that aren't enabled also assert their state in the status registers, but don't physically generate interrupts, as that gating is done against the same bits you're reading, but with down stream logic gate.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
julienterrier39
Associate II
Posted on August 31, 2015 at 10:22 Hello, I met a new issue with the variable UartReady, always in the same programme which comes fromUART_Twoboards_comIT. In the Main we enter in the while loop which expect that SET is true for exit, I try to find where is the interrupt which change the value of UartReady but I didn't find. Exemple in the main:

if(HAL_UART_Transmit_IT(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK)
{
Error_Handler();
}
/*##-3- Wait for the end of the transfer ###################################*/ 
while (UartReady != SET)
{
}
/* Reset transmission flag */
UartReady = RESET;
/* Turn LED3 Off */
BSP_LED_Off(LED3);
/*##-4- Put UART peripheral in reception process ###########################*/ 
if(HAL_UART_Receive_IT(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK)
{
Error_Handler();
}

Function in the STM32F4xx_HAL_UART.c

HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
{
uint32_t tmp = 0;
tmp = huart->State;
if((tmp == HAL_UART_STATE_READY) || (tmp == HAL_UART_STATE_BUSY_RX))
{
if((pData == NULL ) || (Size == 0)) 
{
return HAL_ERROR;
}
/* Process Locked */
__HAL_LOCK(huart);
huart->pTxBuffPtr = pData;
huart->TxXferSize = Size;
huart->TxXferCount = Size;
huart->ErrorCode = HAL_UART_ERROR_NONE;
/* Check if a receive process is ongoing or not */
if(huart->State == HAL_UART_STATE_BUSY_RX) 
{
huart->State = HAL_UART_STATE_BUSY_TX_RX;
}
else
{
huart->State = HAL_UART_STATE_BUSY_TX;
}
/* Enable the UART Parity Error Interrupt */
__HAL_UART_ENABLE_IT(huart, UART_IT_PE);
/* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
__HAL_UART_ENABLE_IT(huart, UART_IT_ERR);
/* Process Unlocked */
__HAL_UNLOCK(huart);
/* Enable the UART Transmit data register empty Interrupt */
__HAL_UART_ENABLE_IT(huart, UART_IT_TXE);
return HAL_OK;
}
else
{
return HAL_BUSY; 
}
}

If you need more information, I could bring the typdef enum and struct in relation with this piece of program. Thanks
Posted on August 31, 2015 at 14:58

I'm not providing support for HAL/Cube code.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on August 31, 2015 at 15:50

Hi julien.terrier,

in the main.c, UartReady is set in  HAL_UART_TxCpltCallback() fucntion.

-Shahrzad-

julienterrier39
Associate II
Posted on September 01, 2015 at 12:22

Hi,

no problem dear clive1 and thank youshahrzad! After your answer of course I found where is changed the variable UartReady in the main!

/**
* @brief Tx Transfer completed callback
* @param UartHandle: UART handle. 
* @note This example shows a simple way to report end of IT Tx transfer, and 
* you can add your own implementation. 
* @retval None
*/
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *UartHandle)
{
/* Set transmission flag: transfer complete*/
UartReady = SET;
/* Turn LED3 on: Transfer in transmission process is correct */
BSP_LED_On(LED3);
}
/**
* @brief Rx Transfer completed callback
* @param UartHandle: UART handle
* @note This example shows a simple way to report end of IT Rx transfer, and 
* you can add your own implementation.
* @retval None
*/
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
/* Set transmission flag: transfer complete*/
UartReady = SET;
/* Turn LED3 on: Transfer in reception process is correct */
BSP_LED_On(LED3);
}

However I didn't find the call of these function, I thought it was called in:

HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)

or

HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)

For the momentI haven't understood how does it work. But I read in User Manual 1725 that Callback Functions ''HAL_PPP_ProcessCpltCallback '' manage:

Ex: HAL_USART_TxCpltCallback

Called by peripheral or DMA interrupt handler when the process completes

Therefore I am going follow this way and explore ''HAL_PPP_ProcessCpltCallback '' function Thanks for your help!
julienterrier39
Associate II
Posted on September 03, 2015 at 09:41

No one to explain me how the vector works and what about _weak reference in this function?

__weak void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)

Thanks a lot!