4
\$\begingroup\$

I am designing a board with an stm32f722 MCU (64 pin version) and I can't afford to waste / not use any GPIO.

My question is following: Is there an option to only use the Rx-pin of a uart / usart so that the Tx-pin can be used for something else (in my case SPI_SCK)?

If I enable a uart / usart in STM32CubeMx and go to the "Configuration" tab I can change "Data Direction" to "Receive only". But this doesn't disable the Tx-pin.

Another way may be using half-duplex mode but then the Tx-pin would be used anyways and I couldn't use it for SPI.

Note: I am still planning my own board and don't have any hardware to test.

\$\endgroup\$
  • 3
    \$\begingroup\$ Have you considered reading the datasheet for the MCU? \$\endgroup\$ – Spehro Pefhany Dec 22 '17 at 17:23
  • 3
    \$\begingroup\$ From reference manual: "When the transmitter is disabled, the output pin returns to its I/O port configuration.". I am not 100% sure so I am not posting it as an answer, but I think this means you can have any kind of config for this pin. So alternate function set to SPI_SCK and UART won't control this pin. For sure contact ST itself. \$\endgroup\$ – Bence Kaulics Dec 22 '17 at 17:24
  • \$\begingroup\$ or just try it. \$\endgroup\$ – old_timer Dec 22 '17 at 18:16
1
\$\begingroup\$

Without studying the spec-sheet for your particular part, it would be unusual if it did allow you that flexibility. Though according to Bence's comment this one might.

However, that does not mean you can not share pins for different functions.

The key here is to dedicate some pin, or a number of pins, to allow the external circuitry, multiplexers, gates etc., to understand how the device is currently using the pins. That sounds like it means tying up a couple more pins, but if you have enough pins you can share, the total number of pins can be reduced.

In the case of the serial lines, you would of course need to time-multiplex it. That is, you would not be able to do serial communication at the same time as you were using the pins for the other functions.

\$\endgroup\$
  • 1
    \$\begingroup\$ It's actually quite common for MCU U(S)ARTS to support a half-duplex mode where one pin or the other is used for both transmit and receive. But if supported, the question is then if the pin used is the one the asker wants, or if it it's the other one. \$\endgroup\$ – Chris Stratton Dec 22 '17 at 17:50
0
\$\begingroup\$

You'd have to check the data sheet to see if a half-duplex mode is supported using the Receive pin only - you might, for example, be unlucky and find that one is offered but uses the transmit pin.

However, there is a solution which would definitely work

  1. Configure the transmit pin for the non-USART function you want to use it for, since STM32 permits unique assignment of any pin irregardless of the others.

  2. Configure the RX pin for the USART receive alternate function

  3. When you want to transmit, reconfigure the RX pin as a GPIO and bit bang the signal. Bit banging transmit is perhaps cleaner than having to bit-sample receive anyway, since you can continue to use the USART's receive interrupt as long as you reconfigure the pin in time.

One thing you'll have to figure out is what happens with the USART while you are bit bang transmitting - not sure if you'll receive your own transmissions or not, or even get into an error state, but you can clear the flags when you switch back to receive mode.

\$\endgroup\$
  • \$\begingroup\$ I only need to receive data and don't want to send anything. Thus step 3 is not needed. Are you sure using the RX pin for USART won't affect the functionality of the SPI clock on the TX pin? \$\endgroup\$ – Lukas Jan 20 '18 at 10:08

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.