How can GPIO be set to output

I would like to use a couple of GPIO pins as output instead of inputs. These would be digital signals.

I see references to setting GPIO_MODE_INPUT and GPIO_ReadPin, but no similar instances for writing or output setting.

Is this feature not available? If so, are there any workarounds?

Anil Sawe

I am wondering that myself currently. I wanna use two GPIOs as digital outputs. Have you figured it out?

Likewise, same question here. Any luck?

OK did it. Just fired up ST32CubeMX, changed GPIO_6 to Output, generated the code, diffed against master and applied resulting patch, then added a few functions to expose to odrivetool. The whole experience to quickly expose functionality to the host was pretty slick.

1 Like

I am not knowledgeable enough to use a program like ST32CubeMX at the moment. Is there any workaround to setting a GPIO pin as output using solely odrivetool? For my application, I need to make any pin go HIGH when a motor should be moving and LOW when the motor has stopped.

You can configure GPIO as output via odrivetool, but you still need a function that will do that check for you and then set the GPIO appropriately.

Thank you for responding! Where should I be looking to set the GPIO as output? I’ve looked into GPIO modes, the pinout page, and GPIO tests so far, but I can’t seem to find anything about writing to a pin. Is output considered a special mode?

Oh, interesting. I may have told a lie. Let me check and get back with you

1 Like

I found a janky workaround for this. You can use the error pin on the board and throw a “fake error” to the pin.

For example,

odrv0.config.error_gpio_pin = 8
odrv0.config.gpio8_mode = GPIO_MODE_STATUS

When there are no errors, the pin will be LOW at 0. You can set an error with

odrv0.axis0.motor.error = 1

or use an error code that you would not expect in your application. When there is an error present on the ODrive, this pin will be HIGH at 1. Very janky, but it worked for what I needed to do.

EDIT: Here is the corresponding firmware code in case anyone more knowledgeable than me in firmware design wants to take a stab at making this a dedicated feature.

1 Like