PORT_SetPinConfig for green LED on FRDM-K64F crashes

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

PORT_SetPinConfig for green LED on FRDM-K64F crashes

ソリューションへジャンプ
2,433件の閲覧回数
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?

ラベル(1)
タグ(2)
0 件の賞賛
1 解決策
1,202件の閲覧回数
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 件の賞賛
4 返答(返信)
1,203件の閲覧回数
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 件の賞賛
1,202件の閲覧回数
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 件の賞賛
1,202件の閲覧回数
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,202件の閲覧回数
robertbaruch
Contributor III

Excellent explanation, thanks!

0 件の賞賛