This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28377S: I have a question about GPIO init code.

Part Number: TMS320F28377S

Dear TI members

I have a question about initGpio code.

please refer below red color code.

I think sizeof(GpioCtrlRegs) / 2 is wrong. sizeof(GpioCtrlRegs) / 4 is correct.

because GpioCtrlRegs members are 32bits union or 32 bits array.

so if the code goal is to calculate members count, divide by 4 is correct instead of divide by 2.

if I am a misunderstanding, please explain to me.

F2837xS_GPIO.c code:

void InitGpio()
{
volatile Uint32 *gpioBaseAddr;
Uint16 regOffset;

//
//Disable pin locks
//
EALLOW;
GpioCtrlRegs.GPALOCK.all = 0x00000000;
GpioCtrlRegs.GPBLOCK.all = 0x00000000;
GpioCtrlRegs.GPCLOCK.all = 0x00000000;
GpioCtrlRegs.GPDLOCK.all = 0x00000000;
GpioCtrlRegs.GPELOCK.all = 0x00000000;
GpioCtrlRegs.GPFLOCK.all = 0x00000000;

//
//Fill all registers with zeros. Writing to each register separately
//for six GPIO modules would make this function *very* long. Fortunately,
//we'd be writing them all with zeros anyway, so this saves a lot of space.
//
gpioBaseAddr = (Uint32 *)&GpioCtrlRegs;
for (regOffset = 0; regOffset < sizeof(GpioCtrlRegs)/2; regOffset++)
{
//
//Hack to avoid enabling pull-ups on all pins. GPyPUD is offset
//0x0C in each register group of 0x40 words. Since this is a
//32-bit pointer, the addresses must be divided by 2.
//
if (regOffset % (0x40/2) != (0x0C/2))
{
gpioBaseAddr[regOffset] = 0x00000000;
}
}

gpioBaseAddr = (Uint32 *)&GpioDataRegs;
for (regOffset = 0; regOffset < sizeof(GpioDataRegs)/2; regOffset++)
{
gpioBaseAddr[regOffset] = 0x00000000;
}

EDIS;
}