cancel
Showing results for 
Search instead for 
Did you mean: 

How to set UART RX manipulated data to GPIO

nirb
Associate II
Posted on September 21, 2016 at 15:45

The original post was too long to process during our migration. Please click on the attachment to read the original post.
9 REPLIES 9
slimen
Senior
Posted on September 21, 2016 at 16:49

Hi berkovich.nir,

You can use DMA for UART transmission, refer to this 

http://http//www.st.com/content/ccc/resource/technical/document/reference_manual/5d/b1/ef/b2/a1/66/40/80/DM00096844.pdf/files/DM00096844.pdf/jcr:content/translations/en.DM00096844.pdf

 in ''19.3.13 Continuous communication using DMA'' paragraph, for more details.

I suggest you refer to UART example using DMA within

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef4.html

under this path: 

 STM32Cube_FW_F4_V1.13.0\Projects\STM32F410xx-Nucleo\Examples\UART\UART_TwoBoards_ComDMA

Regards

Posted on September 21, 2016 at 18:05

The OP isn't asking to use DMA for the USART, but rather to drive a pattern buffer to the GPIO pins (ie &GPIOB->BSRR) to increase the rate of those transitions from the bit-banging being used now.

I'd probably up the baud rate, buffer the USART data, and manage the selection of the pattern buffers (ie 16 different ones to handle the different nibble receptions)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
nirb
Associate II
Posted on September 21, 2016 at 18:38

Thank you,

Can you please explain what do you mean by Buffer the USART data and manage it by 16 different ones for different nibble???

Thank you

Posted on September 21, 2016 at 19:31

Your code looks dysfunctional, but I'm assuming you are trying to take ASCII digits, 0-9, and A-F can generate a sequence of 4-bits shifting out with a clock.

I'd receive the USART data via an RXNE interrupt, buffering a list of 4-bit sequences I wanted sent. In the DMA TC interrupt I would light off the next available 4-bit sequence by pointing the DMA transfer to use one of 16 prebuilt pattern buffers (what I want the pins to do) base on the 4-bit code I'd extracted earlier.

You are using HAL with interrupts, but are basically in a polling loop alternating between receiving serial data and then sequencing GPIO output. To increase throughput these two tasks should really be independent, and use interrupts to do so.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
nirb
Associate II
Posted on September 21, 2016 at 19:47

Hi Clive1,

Since it is my first code I am not really familiar with it.

In order I can fully understand, do you have a simple code example??

''To increase throughput these two tasks should really be independent, and use interrupts to do so'' - How can I seperate it, I would like to have an input and based on it to do some actions.

Sorry for my bad  basics...

Nir

Posted on September 21, 2016 at 20:06

Your code/project is very specific to what you want to do, I don't have a prebuilt example for that. I have posted a number DMA+GPIO examples over the years, review forum content. I don't use/like HAL, the examples I have used the SPL. For the F4 you'd need to us DMA2 to go from memory to GPIO. The GPIO BSRR register permits you to drive specific pins high/low with a single 32-bit write, and you'd create an array of these words to generate a sequence onto the GPIO ODR.

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

My project should support 2 GPIO lines.

1. CLK

2. DATA from user - 0-9, A-F and not the ascii value, so translation is used.

This is just an example for myself and based on that I will expand the IO.

This HW should be communication device for automatic test environment so I would like to reach baude rate of ~2MHz and more if possible.

I hope my project a little bit more clear. 

Posted on September 22, 2016 at 01:21

Well it is certainly possible to drive pins at these types of rates, for scan-chain type activity, I'd probably lean toward using the SPI peripheral if possible (8/16-bit granularity).

Your problem here would be more related to the disparity in how quickly you can supply vector data (115200 baud, throwing away 1/2 the bits) vs vector generation (2 MHz)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
nirb
Associate II
Posted on September 28, 2016 at 16:07

Hi Clive,

Thank you very much, it was very helpful.

Nir