Like the title says, why shouldn't I modify the pin_mux.c file in my project? I'm trying to assign GPIO pins other than the pre-defined pins for my FRDM-K22F board, and I'm having a heck of a time. For simplicity's sake, I've written a little program (see below) that flashes the Green, Red, and Blue LEDs in sequence:
#include "fsl_device_registers.h"
#include "board.h"
static int i = 0;
static int delay = 0x08FFFF;
// LEDs are common-anode, with cathodes connected to port pins.
// Therefore, logic high (1) turns them off, and logic low
// (0) turns them on.
short OFF = 1;
short ON = 0;
int main(void)
{
hardware_init();
GPIO_DRV_SetPinDir(kGpioLED1, kGpioDigitalOutput); //Green LED
GPIO_DRV_SetPinDir(kGpioLED2, kGpioDigitalOutput); //Red LED
GPIO_DRV_SetPinDir(kGpioLED3, kGpioDigitalOutput); //Blue LED
GPIO_DRV_WritePinOutput(kGpioLED1, OFF); //Green LED initially off
GPIO_DRV_WritePinOutput(kGpioLED2, OFF); //Red LED initially off
GPIO_DRV_WritePinOutput(kGpioLED3, OFF); //Blue LED initially off
while (1)
{
for (i = 0; i<delay; i++)
{
}
GPIO_DRV_WritePinOutput(kGpioLED1, ON); //Green LED on
for (i = 0; i<delay; i++)
{
}
GPIO_DRV_WritePinOutput(kGpioLED1, OFF); //Green LED off
for (i = 0; i<delay; i++)
{
}
GPIO_DRV_WritePinOutput(kGpioLED2, ON); //Red LED on
for (i = 0; i<delay; i++)
{
}
GPIO_DRV_WritePinOutput(kGpioLED2, OFF); //Red LED off
for (i = 0; i<delay; i++)
{
};
GPIO_DRV_WritePinOutput(kGpioLED3, ON); //Blue LED on
for (i = 0; i<delay; i++)
{
}
GPIO_DRV_WritePinOutput(kGpioLED3, OFF); //Blue LED off
}
return 0;
}
This works fine using the kGpioLED1, kGpioLED2, and kGpioLED3 definitions and pin assignments that came with the KSDK package for the K22F. So to try different GPIO pins (for example, to PORT_A pins 4 & 5 instead of the pins 1 & 2 defined for kGpioLED1 and kGpioLED2 (respectively), I made the appropriate changes in gpio_pins.h. PORT_A pins 1 & 2 stopped toggling, so only the blue LED flashed on board, which is what was expected. However, there was no activity at PORT_A pins 4 & 5, available at the headers. I can make these pins toggle IF I modify the pin_mux.c file, changing
void pin_mux_GPIO(uint32_t instance)
{
switch(instance) {
case 0: /* PTA */
/* PORTA_PCR1 */
PORT_HAL_SetMuxMode(g_portBaseAddr[0],1u,kPortMuxAsGpio);
/* PORTA_PCR2 */
PORT_HAL_SetMuxMode(g_portBaseAddr[0],2u,kPortMuxAsGpio);
to
void pin_mux_GPIO(uint32_t instance)
{
switch(instance) {
case 0: /* PTA */
/* PORTA_PCR1 */
PORT_HAL_SetMuxMode(g_portBaseAddr[0],4u,kPortMuxAsGpio);
/* PORTA_PCR2 */
PORT_HAL_SetMuxMode(g_portBaseAddr[0],5u,kPortMuxAsGpio);
I'm almost content with going ahead with this approach, but since the remarks at the beggining of the pin_mux.c file tell me NOT to modify the file, it's clear that I'm missing a step or two in my program that would otherwise cause KDS/KSDK to make the changes to the pin_mux.c file for me. So my question is this: what am I missing? I've looked at various pieces of demo code, mostly written for other boards, and I can't seem to figure this out. I suppose it has something to do with setting up muxes and/or clocks for the desired pins, but I'm too dense to figure out what's required by reading the API reference manual.
Can anyone help?
Thanks - Jeff