AnsweredAssumed Answered

STM32MatTarget_V430: UsartRcv.slx

Question asked by michaeL on Aug 11, 2016
Latest reply on Sep 8, 2016 by michaeL

Hi there,

I am using MATLAB/Simulink R2015b with STM32MatTarget V4.30 to access the USART. I generated also a software framework with STM32CubeMX 4.16 and the firmware package for the STM32F3 Family 1.6.0. I tried to send the received data back to a PC terminal program.

I did it similarly like in demo UsartRcv.slx:

The USART_Receive block connects with NbRcv to Nb2Send of USART_Send block.
The USART_Receive block connects with PtRcv to Data2Send of USART_Send block.
The USART_Receive block is connected to a constant of 10 with Nb2Rcv.

I am using the STM32 Nucleo-F303RE evaluation board.

When I try it out and press a button on the terminal program the character is sent out ever and ever. Should this be the intended behaviour?

I had a look in the generated code. It looks like this:

/* S-Function Block: <Root>/USART_Receive */
if (USART2_RxDataLink.rxStatus == USART_RX_OFF) {
  USART2_RxDataLink.ptRcv = G_USART2_RxDataBuffer;
  TestProject14_B.USART_Receive_o1 = 0;
  /* USART2 pooling receive mode*/
  HAL_UART_Receive(&huart2, G_USART2_RxDataBuffer, ((uint16_T)10U),
  USART2_RxDataLink.rxStatus = USART_RX_OK;
if (USART2_RxDataLink.rxStatus == USART_RX_OK) {
  TestProject14_B.USART_Receive_o1 = ((uint16_T)10U);
  TestProject14_B.USART_Receive_o2 = (uint32_T)G_USART2_RxDataBuffer;
  for (G_USART2_Rx_idx=0; G_USART2_Rx_idx<((uint16_T)10U); G_USART2_Rx_idx++)
    *(char*)(&TestProject14_B.USART_Receive_o3[0]+G_USART2_Rx_idx) = *(char*)
  G_USART2_RxDataBuffer[G_USART2_Rx_idx] = 0;
  USART2_RxDataLink.rxStatus = USART_RX_OFF;
/* S-Function Block: <Root>/USART_Send */
if (TestProject14_B.USART_Receive_o1 != 0) {
  /* Wait for end of current send data*/
  while (USART2_TxDataLink.txStatus == USART_TX_ON) ;
  /* Copy data to send */
  USART2_CopyDataFcn((uint8_t*)TestProject14_B.USART_Receive_o2, (uint16_t)
                     TestProject14_B.USART_Receive_o1, &USART2_TxDataLink);
//RP_MODIF        if(huart2.State == HAL_UART_STATE_READY)
if (USART2_TxDataLink.nb2Send) {
  TestProject14_B.USART_Send = 0;
if (USART2_TxDataLink.txStatus != USART_TX_ON) {
  TestProject14_B.USART_Send = USART2_TxDataLink.nbSent;

I also wonder, if it is all right, that the return value of HAL_UART_Receive is ignored.

Also a test (similar to TestUSART_Rcv_Send_SIT.slx) with an S-function RcvUsartBuf showed the same behaviour.

Has anyone used the USART blocks successfully with some STM32F303 controller?

Thanks for any hints.

Best regards,