Introduction the BSP configuration file in MQX for Kinetis SDK

Document created by Daniel Chen Employee on Sep 14, 2015Last modified by Daniel Chen Employee on Sep 14, 2015
Version 1Show Document
  • View in full screen mode

Introduction the BSP configuration file in MQX for Kinetis SDK

 

1  Overview of BSP directory in MQX classic  and MQX for KSDK

If you compare the BSP directory of MQX classic and MQX for KSDK , you will find that there are significant differences in how the Board Support Package for MQX for KSDK and classic MQX are configured.  For MQX classic directory, the compiled BSP library is used for drivers and hardware configuration (see picture 1), there are 35 files, while for MQX for KSDK directory (see picture 2), the BSP directory is nearly empty, much of the equivalent functionality of the BSP library is now moved to the example board directory. See picture 3. If you want to port your application to your custom board, these files are very important, you need to review them carefully.

 

classic-bsp.jpg

 

Picture 1   BSP in MQX classic

 

ksdk-bsp.jpg

 

Picture 2  BSP in MQX for KSDK

 

board.jpg

 

Picture 3   board directory in MQX for KSDK

 

2  Introduction of the BSP configuration file in MQX for KSDK

The BSP configuration  files are located at  sdk_install_folder/examples. Please see picture 3. We need to modify these files according to schematic and reference manual

2.1 Board.c/h:

The C file contains clock and oscillator initialization functions. The header file contains board-specific configuration macros for things such as debug terminal configuration, push buttons, LEDs and other board-specific items.

 

2.2 Gpio_pins.c/h:

Kinetis SDK uses pin configuration structures for each pin

--Pin configuration structures in gpio_pin.c configures input/output, pull-up/pull-down, pin filtering, interrupt enabled/disabled, initial output polarity, slew rate and driver strength setting

Gpio_pins.h

--declares Pin names used by board, PORT pin to use  (ie: PTE3)

--contains definitions for LED, switch, and SD card chip select

/*! @brief Pin names */

enum _gpio_pins_pinNames{

  kGpioSW2      = GPIO_MAKE_PIN(GPIOC_IDX, 6U),

  kGpioSW3      = GPIO_MAKE_PIN(GPIOA_IDX, 4U),

  kGpioSdhc0Cd  = GPIO_MAKE_PIN(GPIOE_IDX, 6U),

  kGpioLED1     = GPIO_MAKE_PIN(GPIOE_IDX, 26U),

  kGpioLED2     = GPIO_MAKE_PIN(GPIOB_IDX, 22U),

  kGpioLED3     = GPIO_MAKE_PIN(GPIOB_IDX, 21U),

};

#endif

 

Gpio_pins.c

Contains GPIO options for each pin

const gpio_output_pin_user_config_t ledPins[] = {

  {

    .pinName = kGpioLED1,

.config.outputLogic = 1,

    .config.slewRate = kPortSlowSlewRate,

    .config.isOpenDrainEnabled = false,

.config.driveStrength = kPortLowDriveStrength,

  },

  {

    .pinName = kGpioLED2,

.config.outputLogic = 1,

    .config.slewRate = kPortSlowSlewRate,

.config.isOpenDrainEnabled = false,

.config.driveStrength = kPortLowDriveStrength,

  },

  {

    .pinName = kGpioLED3,

.config.outputLogic = 1,

    .config.slewRate = kPortSlowSlewRate,

.config.isOpenDrainEnabled = false,

.config.driveStrength = kPortLowDriveStrength,

  },

  {

    .pinName = GPIO_PINS_OUT_OF_RANGE,

  }

};

 

2.3  Pin_mux.c/h:

Kinetis devices provide great flexibility in muxing signals, each digital port pin has up to 8 signals muxed on pin, some peripherals route same signals to multiple pins. In Pin_mux.c:  It implements functions to set pin mux option for all pins used on board, and functions for each peripheral type, like configure_can_pins()

void configure_can_pins(uint32_t instance)

{

  /* PORTB_PCR19 */

  PORT_HAL_SetMuxMode(PORTB,19u,kPortMuxAlt2);

  /* PORTB_PCR18 */

  PORT_HAL_SetMuxMode(PORTB,18u,kPortMuxAlt2);

}

 

Not all instances will be populated so may need to add

void configure_i2c_pins(uint32_t instance)

{

  switch(instance) {   

    case I2C0_IDX:                       /* I2C0 */

      /* Affects PORTE_PCR24 register */

PORT_HAL_SetMuxMode(PORTE,24u,kPortMuxAlt5);

      PORT_HAL_SetOpenDrainCmd(PORTE,24u,true);

      /* Affects PORTE_PCR25 register */

PORT_HAL_SetMuxMode(PORTE,25u,kPortMuxAlt5);

PORT_HAL_SetOpenDrainCmd(PORTE,25u,true);

      break;

    case I2C1_IDX:                       /* I2C1 */

      /* Affects PORTC_PCR10 register */

PORT_HAL_SetMuxMode(PORTC,10u,kPortMuxAlt2);

PORT_HAL_SetOpenDrainCmd(PORTC,10u,true);

      /* Affects PORTC_PCR11 register */

PORT_HAL_SetMuxMode(PORTC,11u,kPortMuxAlt2);

PORT_HAL_SetOpenDrainCmd(PORTC,11u,true);

      break;

    default:

      break;

  }

 

2.4  hardware_init:

Project specified hardware initialization, it uses functions provided in board configuration layers in pin_mux.c during startup

void hardware_init(void) {

/* enable clock for PORTs */

CLOCK_SYS_EnablePortClock(PORTA_IDX);

CLOCK_SYS_EnablePortClock(PORTB_IDX);

CLOCK_SYS_EnablePortClock(PORTC_IDX);

CLOCK_SYS_EnablePortClock(PORTE_IDX);

 

/* Init board clock */

BOARD_ClockInit();

dbg_uart_init();

}

 

3   Kinetis SDK Porting example—Change Default UART

To change default UART port, we need to change the UART instance in board.h, and change the pin muxing in pin_mux.c

 

3.1   Modify board.h to select the UART and baud rate to use

/* The UART to use for debug messages. */

#ifndef BOARD_DEBUG_UART_INSTANCE

    #define BOARD_DEBUG_UART_INSTANCE   0

    #define BOARD_DEBUG_UART_BASEADDR   UART0

#endif

#ifndef BOARD_DEBUG_UART_BAUD

    #define BOARD_DEBUG_UART_BAUD       115200

#endif

 

3.2  Modify pin_mux.c to select the pins to use

void configure_uart_pins(uint32_t instance)

{

  switch(instance) {   

    case UART0_IDX:                      /* UART0 */

      /* Affects PORTB_PCR16 register */

PORT_HAL_SetMuxMode(PORTB,16u,kPortMuxAlt3);

      /* Affects PORTB_PCR17 register */

PORT_HAL_SetMuxMode(PORTB,17u,kPortMuxAlt3);

      break;

    case UART4_IDX:                      /* UART4 */

      /* Affects PORTC_PCR14 register */

PORT_HAL_SetMuxMode(PORTC,14u,kPortMuxAlt3);

      /* Affects PORTC_PCR15 register */

PORT_HAL_SetMuxMode(PORTC,15u,kPortMuxAlt3);

      break;

    default:

      break;

  }

}

Attachments

Outcomes