PORT_SetPinConfig for green LED on FRDM-K64F crashes

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PORT_SetPinConfig for green LED on FRDM-K64F crashes

Jump to solution
2,319 Views
robertbaruch
Contributor III

Installed KDS 3.1, and SDK 2.0 for the FRDM-K64F board. I wanted to light the red, green, and blue LEDs just to start. I added this code to BOARD_InitPins:

 

    // Initialize LED pins

    port_pin_config_t ledConfig = {

      .pullSelect = kPORT_PullDisable,

      .slewRate = kPORT_SlowSlewRate,

      .passiveFilterEnable = kPORT_PassiveFilterDisable,

      .openDrainEnable = kPORT_OpenDrainDisable,

      .driveStrength = kPORT_LowDriveStrength,

      .mux = kPORT_MuxAsGpio,

      .lockRegister = kPORT_UnlockRegister,

    };

 

    PORT_SetPinConfig(BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, &ledConfig);

    PORT_SetPinConfig(BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, &ledConfig);

    PORT_SetPinConfig(BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, &ledConfig);

 

Then in main.c, I added:

 

  LED_RED_INIT(LOGIC_LED_ON);

  LED_GREEN_INIT(LOGIC_LED_ON);

  LED_BLUE_INIT(LOGIC_LED_ON);

 

I ran it in debug mode, and found that the PORT_SetPinConfig for the green LED crashed the board. Commenting out that line worked, although of course only the red and blue LEDs lit.

 

What's going on?

Labels (1)
Tags (2)
0 Kudos
1 Solution
1,088 Views
Jmart
NXP Employee
NXP Employee

Robert,

I believe the issue that you're seeing is the attempt to write to a peripheral that doesn't have the clock enabled.

The green GPIO on FRDM-K64F is located on PortE. Try adding this line above your pin initialization:

  /* Enable the clock to the PORT module that the LED is on. */

  CLOCK_EnableClock(kCLOCK_PortE);

- Jason

View solution in original post

0 Kudos
4 Replies
1,089 Views
Jmart
NXP Employee
NXP Employee

Robert,

I believe the issue that you're seeing is the attempt to write to a peripheral that doesn't have the clock enabled.

The green GPIO on FRDM-K64F is located on PortE. Try adding this line above your pin initialization:

  /* Enable the clock to the PORT module that the LED is on. */

  CLOCK_EnableClock(kCLOCK_PortE);

- Jason

0 Kudos
1,088 Views
robertbaruch
Contributor III

Thanks. Do you know of a document that shows a schematic of how each (or a typical) pin functions? Because honestly, I looked through the K64 reference manual, read the chapters on the PORT module and CLOCK modules, and I still don't understand how the clock interacts with the ports. I did see in the GPIO module section that in output mode, the pin is set to 0 or 1 on the rising edge of the system clock, but I don't quite know why the board would have crashed just because I didn't enable the clock for port E.

0 Kudos
1,088 Views
Jmart
NXP Employee
NXP Employee

Robert,

The reference manuals will contain the most information for how a port / gpio functions. Each pin (for the most part) can support many different functions, so it's best to always refer to the SoC reference manual for what's the correct setting for your board. Given that, I've not seen a publicly available FRDM-K64F schematic.

The issue that you've encountered is related to the clocking of the port E peripheral. In order to maintain the lowest possible power, the SoC 'gates' clocks until you're ready to use them, in which case, you must ungate the clock to enable the peripheral. When the clock for a peripheral is gated, it's not possible to read or write to the addresses owned by that peripheral, because they don't 'exist' until you ungate the clock. Access to those memory locations prior to ungating the clock will cause a hard fault. You can find a blurb about clock gating in the K64 reference manual rev 2 from January 2014 (section 5.6 - Clock Gating).

1,088 Views
robertbaruch
Contributor III

Excellent explanation, thanks!

0 Kudos