4

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.

SamGibson
  • 17,231
  • 5
  • 37
  • 58
Lukas
  • 107
  • 6
  • 3
    Have you considered reading the datasheet for the MCU? – Spehro Pefhany Dec 22 '17 at 17:23
  • 3
    From [reference manual](http://www.st.com/content/ccc/resource/technical/document/reference_manual/group0/c8/6b/6e/ce/dd/f7/4b/97/DM00305990/files/DM00305990.pdf/jcr:content/translations/en.DM00305990.pdf): "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. – Bence Kaulics Dec 22 '17 at 17:24
  • or just try it. – old_timer Dec 22 '17 at 18:16

2 Answers2

1

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.

Trevor_G
  • 46,364
  • 8
  • 68
  • 151
  • 1
    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. – Chris Stratton Dec 22 '17 at 17:50
0

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.

Bence Kaulics
  • 6,353
  • 12
  • 33
  • 60
Chris Stratton
  • 33,282
  • 3
  • 43
  • 89
  • 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? – Lukas Jan 20 '18 at 10:08