cancel
Showing results for 
Search instead for 
Did you mean: 

what is the the hardware fifo size of STM32f103CB and how to know whether the FIFO is empty or full?

Olly Kao
Associate III

Hi

As the title mentioned, I can't find relevant information in the datasheet.

I get some problem when using UART. I have two chips, the master chip transmits packages to RS485 Bus line, and the slave chip receives it then transmits the respond(UART1), at the same time, every second the timer will transmit debugging stuff to pc by TTL(UART2), they should be mutual independent, however the UART1 doesn't work when UART2 is working, and the data is still transmiting to RS485 bus from master chip, so some of the data will not received by slave chip when slave chip is using UART2, after a while whole system on slave chip get weird (the timer is still working), I guess it is the FIFO overflow. So I am asking for function or ways to know the fifo size remain.

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Guenael Cadier
ST Employee

Dear @Olly Kao​ 

On STM32 F1 devices, there's no HW Rx fifo as such. Only a shift register exists prior received data is copied in RDR.

This means, 2 data could be received while nothing is retrieved from Receive Data register, with nothing lost. If more, some overrun errors will happen.

Regarding your use case, it is anyway possible to have UART2 transmitting data (Tx), while UART2 reception is ongoing, without losing data on UART1.

What kind of API are you using for sending/receiving data on UART1 and UART2 ?

For example, in order to allow parallel process (1 UART sending, the other one receiving) you will need to use IT or DMA based routines (like HAL_UART_Transmit_IT(), HAL_UART_Transmit_DMA(),HAL_UART_Receive_IT(), HAL_UART_Receive_DMA()).

Regards

View solution in original post

3 REPLIES 3
Guenael Cadier
ST Employee

Dear @Olly Kao​ 

On STM32 F1 devices, there's no HW Rx fifo as such. Only a shift register exists prior received data is copied in RDR.

This means, 2 data could be received while nothing is retrieved from Receive Data register, with nothing lost. If more, some overrun errors will happen.

Regarding your use case, it is anyway possible to have UART2 transmitting data (Tx), while UART2 reception is ongoing, without losing data on UART1.

What kind of API are you using for sending/receiving data on UART1 and UART2 ?

For example, in order to allow parallel process (1 UART sending, the other one receiving) you will need to use IT or DMA based routines (like HAL_UART_Transmit_IT(), HAL_UART_Transmit_DMA(),HAL_UART_Receive_IT(), HAL_UART_Receive_DMA()).

Regards

HI, Thanks for your reply.

You're right, I originally used HAL_UART_Transmit() so the UART1 and UART2 can't work at the same time, as below

0693W000002lBBbQAM.jpg

So I just wrote a testing code to check for UART1 and UART2 work simultaneously, using HAL_UART_Transmit_IT(), and i got the result as below

0693W000002lBCPQA2.jpg

As you can see, the UART1 and UART2 can work together, however the data of UART1 are totally broken, I have no idea why.

The uart configs are generate by cubeMX, and the code are below

char UART1Tx[5] = {'0', '1', '2', '3', '4'};
char UART2Tx[5] = {'5', '6', '7', '8', '9'};
 
int main(void)
{
  HAL_Init();
 
  SystemClock_Config();
 
  MX_GPIO_Init();
  MX_TIM2_Init();
  MX_USART2_UART_Init();
  MX_USART1_UART_Init();
 
  HAL_TIM_Base_Start_IT(&htim2);
  HAL_UART_Transmit_IT(&huart1, UART1Tx, 5);
 
  while (1)
  {
  }
}

​The timer calls handler every second, and transmit 5~9 by UART2

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  HAL_UART_Transmit_IT(&huart2, UART2Tx, 5);
}

and the UART1 keeps Transmitting 0~4, enable tx interrupt by callback function

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
  if(huart == &huart1)
    HAL_UART_Transmit_IT(&huart1, UART1Tx, 5);
}

Please, Can you help me out in this ?

Dear @Olly Kao​ 

No clear idea of what is the problem. Only some ideas to help investigating ...

1 - during first sending on USART1, are 0,1,2,3,4 chars properly sent ?

2 - If you break in your debugger, while erroneous transmissions are ongoing, could you check content of UART1Tx buffer (to check it still contains 0,1,2,3,4) ?

3 - could you give a try to check what happens when USART2 Tx is disabled (comment HAL_UART_Transmit_IT() call in HAL_TIM_PeriodElapsedCallback) ?

Hope this helps.

Guenael