0
\$\begingroup\$

I am using the STM32F0 discovery board. I am looking at this tutorial on UART with the STM32F0. http://letanphuc.net/2015/09/stm32f0-uart-tutorial-5/

//variables need to be declared at the beginning 
char Rx_indx, Rx_data[2], Rx_Buffer[100], Transfer_cplt;

//Interrupt callback routine
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
    uint8_t i;
    if (huart->Instance == USART1)  //current UART
        {
        if (Rx_indx==0) {for (i=0;i<100;i++) Rx_Buffer[i]=0;}   //clear Rx_Buffer before receiving new data 

        if (Rx_data[0]!=13) //if received data different from ascii 13 (enter)
            {
            Rx_Buffer[Rx_indx++]=Rx_data[0];    //add data to Rx_Buffer
            }
        else            //if received data = 13
            {
            Rx_indx=0;
            Transfer_cplt=1;//transfer complete, data is ready to read
            }

        HAL_UART_Receive_IT(&huart1, Rx_data, 1);   //activate UART receive interrupt every time
        }

}

The interrupt routine activates on receiving a single byte on UART. I am not sure if it can support 6Mbps as mentioned in the datasheet. If not, can it support up to at least 115kbps? How can one make the code support up to 6Mbps?

\$\endgroup\$
  • 1
    \$\begingroup\$ Use MxCube and see that 6M is just a dream. \$\endgroup\$ – Marko Buršič May 11 '16 at 7:56
  • \$\begingroup\$ Do you mean 6Mbps is not possible? The datasheet is incorrect? \$\endgroup\$ – user768421 May 11 '16 at 8:02
  • 1
    \$\begingroup\$ Sorry for that, indeed I've cheked mxcube you have the possibility to set max. speed 6M. But you can't evaluate the buffer in that way on that speed. \$\endgroup\$ – Marko Buršič May 11 '16 at 8:14
  • \$\begingroup\$ How should the code be changed to support 6Mbps? \$\endgroup\$ – user768421 May 11 '16 at 8:16
3
\$\begingroup\$

You would need to use DMA transfer in FIFO and one capture timer connected on the same pin as UART RX. At receive all the data is transfered in FIFO with DMA, the capture timer has to be set that after a timeout (with regard the bit length at that speed) triggers an interrupt. In that ISR you evaluate the FIFO and parse the telegram. Of course there have to be gaps in the communication to have the possibility to evaluate, no continous streaming

EDIT: I got a document exactly explaining: http://www.st.com/st-web-ui/static/active/jp/resource/technical/document/application_note/CD00256689.pdf

\$\endgroup\$
  • \$\begingroup\$ Do you think DMA is required if the baud rate is only 56kbps? \$\endgroup\$ – user768421 May 11 '16 at 9:59
  • \$\begingroup\$ The best way is to do a loopback test, you send back the recived telegram when the end char is detected. Altrough if not using capture timer for timeout rx, I don't see any benefit in using DMA as you can have only half fifo or fifo full interrupt, not really usefull information if the telegram is unknown length and it is not continously streaming. \$\endgroup\$ – Marko Buršič May 11 '16 at 13:52
4
\$\begingroup\$

The possible speed of any software routine, whether it be an interrupt routine or not, can be easily profiled. The way this is done is to commit one of the GPIO pins of the MCU as an output pin connected to an oscilloscope. (A logic analyzer can work too). In the piece of code that you want to profile you set the GPIO at the start of the routine and clear it at the end of the routine. Run the code and measure the resulting GPIO pulses on the scope.

Using this technique there is no longer a need to ask questions as to 'is this fast enough' or 'if I change the code how does it affect the timing'.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.