See "SPRUFL8B" 2.9 Initialization section
1. Set device pin multiplexing
2. Set PSC (Power and Sleep Control Register) to enable GPIO
3. Set the direction, data, and interrupt control registers to configure as needed
4. Introduction to StarterWare's GPIO library functions
To use the GPIO function of StarterWare, you need to add "gpio.c" or "C:\ti\C6748_StarterWare_1_20_04_01\binary\c674x\cgt_ccs\c6748\drivers\Debug\drivers.lib". In addition, you also need to add the header files "gpio.h", "soc_C6748.h", "hw_syscfg0_C6748.h", "hw_types.h". These header files define the physical addresses of many registers and the function macros used to calculate the address location.
1. Following the steps, let's first look at the multiplexed register PINMUXn. Because my development board uses GPIO2[8], I directly locate the PINMUX5 register:
We can see that GP2[8] is at bits 31-28 of PINMUX5, so we can set this bit to "1". The following figure shows the physical address of the PINMUX5 register:
We adopt the "read-mask-write" operation to avoid affecting the configuration of other bits. HWREG(x) (*((volatile unsigned int *)(x))) is defined in hw_types.h, so we can set it as follows:
PINMUX_5_VAL=HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(5)); /* Read the value of PINMUX5 (multiplexing register) register*/
PINMUX_5_VAL=(PINMUX_5_VAL&0x0fffffff)|0x80000000;
HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(5))=PINMUX_5_VAL;/* Write the set value back to PINMUX5 register GP2[8] */
The value of SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(5) above is 0x1c14134, which is exactly the address of PINMUX5. StarterWare will calculate the address of a register under a peripheral according to the base address of the peripheral register, just like SOC_SYSCFG_0_REGS, which is defined as 0x01C14000 in line 289 of soc_C6748.h, and PINMUX5 is under this peripheral. SYSCFG0_PINMUX(n) (0x120 + (n * 4)) takes advantage of the fact that there are nine other registers between each PINMUXn, and each register is 32 bits for linear calculation.
2. Here, just use the default setting after hardware reset for PSC.
3. Set the input/output register. The library function defines void GPIODirModeSet(unsigned int baseAdd, unsigned int pinNumber, unsigned int pinDir); to set the input/output status of the IO port. Note that pinNumber has the following description in the function entry parameters:
The 144 GPIO pins have serial numbers from
1
to
144
. [0] 97, GPIO7[0] 113
* GPIO8[0] 129
For example, if I want to set GPIO2[8] as output, then pinNumber=41.
GPIODirModeSet(SOC_GPIO_0_REGS, 41, GPIO_DIR_OUTPUT); can set GPIO2[8] to output; similarly, the principle of writing GPIO function is the same, but the calculation of register address is different, so it is not listed here. GPIOPinWrite(SOC_GPIO_0_REGS, 41, GPIO_PIN_HIGH); can make GPIO2[8] output high level. For the specific function of read operation, please refer to "C:\ti\C6748_StarterWare_1_20_04_01\drivers\gpio.c". In this way, we can easily operate GPIO!
|