Using TMS570 Peripheral Pins as GPIO - SFUSatClub/obc-firmware GitHub Wiki
Many of the pins normally dedicated to peripherals can be coerced into GPIO mode.
-
In the HALCoGen tab for the peripheral, set the pin's mode to GPIO.
-
If applicable, appropriately mux the pin in the PINMUX tab.
-
For GPIO pins, you use the pointer
gioPORTA
in the GPIO functions, for example. Peripherals have their own version of this. You can find it inreg_<peripheral name>.h
. For MIBSPI, these look likemibspiPORTx
. It's generally the lowercase peripheral name, followed byPORTx
. -
Now that you have the correct pointer to the port, you need the right pin number. You can find these in the peripheral's section of the TRM, or by poking into the
<peripheral>Init
function.
For example, here are the spiREG5 pins getting their mode set in spiInit()
:
/* SPI5 set all pins to functional */
spiREG5->PC0 = (uint32)((uint32)0U << 0U) /* SCS[0] */
| (uint32)((uint32)1U << 1U) /* SCS[1] */
| (uint32)((uint32)1U << 2U) /* SCS[2] */
| (uint32)((uint32)1U << 3U) /* SCS[3] */
| (uint32)((uint32)1U << 8U) /* ENA */
| (uint32)((uint32)1U << 9U) /* CLK */
| (uint32)((uint32)1U << 10U) /* SIMO[0] */
| (uint32)((uint32)1U << 11U) /* SOMI[0] */
| (uint32)((uint32)1U << 17U) /* SIMO[1] */
| (uint32)((uint32)1U << 18U) /* SIMO[2] */
| (uint32)((uint32)1U << 19U) /* SIMO[3] */
| (uint32)((uint32)1U << 25U) /* SOMI[1] */
| (uint32)((uint32)1U << 26U) /* SOMI[2] */
| (uint32)((uint32)1U << 27U); /* SOMI[3] */
In this case, setting the bit to 0 means it'll be a GPIO.
You can also find this in the TRM. It'll be in a mode set or direction set register.
So, for the peripheral above, if we'd set SIMO [3] to GPIO mode in HALCoGen, we would use spiPORT5
and 19
as arguments to the GPIO functions.