cancel
Showing results for 
Search instead for 
Did you mean: 

STM32MatTarget_V430: UsartRcv.slx

michaelkotthaus9
Associate II
Posted on August 11, 2016 at 21:59

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. Itried 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),
G_USART2_RxPollTimeOut);
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*)
USART2_RxDataLink.ptRcv++;
}
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;
USART2_SendDataFcn(&USART2_TxDataLink);
}
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,

michaeL #usart
3 REPLIES 3
michaelkotthaus9
Associate II
Posted on August 11, 2016 at 22:15

The attached picture makes the connection clearer.

________________

Attachments :

Simulink_USART_Receive_to_USART_Send.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Htqr&d=%2Fa%2F0X0000000aXs%2FhVzpcMW3H5WdArEBzkZN4KkRBa2JaymrctMK1LSpAFM&asPdf=false
michaelkotthaus9
Associate II
Posted on August 16, 2016 at 09:45

I would appreciate any Simulink UART example, which is runnable on a STM32F303 Nucleo board. Can anybody provide an slx and the relating ioc file? Thanks in advance!

michaelkotthaus9
Associate II
Posted on September 08, 2016 at 21:08

Can anyone tell me, how to solve these issues? Many thanks in advance...