Skip to main content
BCoch
Senior
October 25, 2019
Solved

Copy input pin to output.

  • October 25, 2019
  • 12 replies
  • 4075 views

What would be an efficient, low latency way to reflect the state of an input pin onto an output pin?

Is there anything more automated than configuring the input pin as an EXTI, then in the interrupt handler, reading it and setting the state of the output pin accordingly? Could it be done with a comparator or timer?

This topic has been closed for replies.
Best answer by berendi

A couple of other ideas

STM32L1 Routing Interface. These are analog switches intended for touch sensing. Activating two switches in one "touch group" connects the two pins internally.

Timer + DMA to GPIO. Works when DMA is able to write the GPIO registers, target can be any pin. E.g. on STM32F4, TIM1 or TIM8 Channel 1 triggers on TI1 rising edge, Channel 2 on falling edge. They can be assigned to different channels on DMA2. One DMA channel copies the pin set mask, the other one the pin reset mask to GPIOx->BSRR.

SPI with DMA to itself, when you need a specific delay. This again needs a DMA that can copy to/from anywhere. SPI in master mode, RX complete DMA request copies the value in the data register back to itself, creating a true shifter. STM32H7 SPI controller can do it by itself without DMA.

12 replies

Pavel A.
October 26, 2019

Just wire them together?

S.Ma
Principal
October 26, 2019

Add SmartIO type functionality in the 2019 STM32 Wish list?

waclawek.jan
Super User
October 26, 2019

Comparator may be plausible.

Timer: input signal on CH1, slave mode set as external clock fed from TI1F_ED. ARR set to 1. One of the other channels set to output, one of the PWM modes, CCR=1. Delays and frequency/edge distance restrictions apply.

I too wonder, what's the point.

JW

berendi
Principal
October 26, 2019

The point might be overriding a signal sometimes, otherwise letting it pass through. E.g. there is an external component that wants to signal a warning sometimes, and the MCU itself should be able to turn on the buzzer too.

berendi
berendiBest answer
Principal
October 26, 2019

A couple of other ideas

STM32L1 Routing Interface. These are analog switches intended for touch sensing. Activating two switches in one "touch group" connects the two pins internally.

Timer + DMA to GPIO. Works when DMA is able to write the GPIO registers, target can be any pin. E.g. on STM32F4, TIM1 or TIM8 Channel 1 triggers on TI1 rising edge, Channel 2 on falling edge. They can be assigned to different channels on DMA2. One DMA channel copies the pin set mask, the other one the pin reset mask to GPIOx->BSRR.

SPI with DMA to itself, when you need a specific delay. This again needs a DMA that can copy to/from anywhere. SPI in master mode, RX complete DMA request copies the value in the data register back to itself, creating a true shifter. STM32H7 SPI controller can do it by itself without DMA.

S.Ma
Principal
October 26, 2019

Routing interface would be analog mux with serial resistance (no buffering).

BCoch
BCochAuthor
Senior
October 28, 2019

Thanks for the great suggestions, Berendi. I don't suppose the STM32G0 series has the routing interface?

Indeed the application is as you surmised. It's for a test fixture, that can be in either an active mode, where the microprocessor is driving a signal, or in a passive mode, where an externally generated signal should be "passed through" instead. We could simply connect both external and internal together, tri-stating the internally generated one when in passive mode, but there would be no protection if put in active mode while the external driver is still connected.

David Viens
Associate II
January 27, 2021

Looking for an answer to this as well

Basically what I need to do offload in DMA what I can do in code but need the CPU for something else.

While using an STM32 as a switch or router is a silly idea, it could save on BOM a lot and make it more flexible.

In short in CERTAIN circumstances in my design (silly to justify adding a 16pin switch to BOM) I need to mirror as FAST as possible one GPIO port's inputs to another port's outputs:

while(1)

GPIOx->ODR=GPIOy->IDR;

}

What are the real options here?

1)Memory To Memory DMA could do this, but only once if at all since you can't use circular mode.

2)memory to perif or perif to memory can accept two GPIO ports?

3)one DMA that does GPIO to memory and another from that memory to another GPIO? (one 16bit word of memory only?)

4)something never explained on H7's MDMA could do this?

This is driving me nuts. Surely it can be done? (STM32F7 and H7 here)

waclawek.jan
Super User
January 27, 2021

As OP hinted, using the comparator is maybe the simplest and easiest way.

JW

David Viens
Associate II
January 27, 2021

Hi JW and thanks for the reply

The analog comparator only has 2 pins and afaik they are only available on analog input pins. What I need is a full mirror of the full 16 digital pins of one GPIO port to another.

waclawek.jan
Super User
January 27, 2021

> 2)memory to perif or perif to memory can accept two GPIO ports?

BDMA in 'H7 yes, and DMA2 in 'F7 too. Both would require some tricks for continuous triggering, but IMO in both cases that's quite easily doable. They will choke on the continuous transfers, though, and so will the related buses.

Doable? Probably. Practical? No.

JW

David Viens
Associate II
January 27, 2021

Guess its worth a try. I'm fully aware its not elegant. As long as there is no corrupted port writes (that they are atomic), then its all fine if there is lots of internal fights. Thanks