Step 4.1: Modify the Local bsp.hconfig File
MPLAB® Harmony Configurator (MHC) executes the script in local bsp.hconfig file to:
- Configure the PIC32 device pins as per your configuration.
- Add the Board Support Package (BSP) source and header files to the project.
The script in the .hconfig files is sensitive to whitespace. Ensure that there are no extra spaces or tabs in the script you add or modify.
1
The bsp.hconfig file, located in <harmony_installation_path>/bsp/<bsp_name>/config, contains a script that includes an IF block with two menu configurations covering the:
- Pin configurations which have to be added.
- Path to map the BSP template files, bsp.c.ftl and bsp.h.ftl, to bsp.c and bsp.h in the project folder.
2
Change the condition in the IF block.
The code block below enables the pin configurations for the custom BSP when it is selected in MHC.
ifblock BSP_PIC32MZ_EF_CUSTOM menu "Select BSP Features" depends on USE_BSP depends on BSP_PIC32MZ_EF_CUSTOM
3
Configure the pins.
As per the analysis made in Step 1.2, write the script as below:
config BSP_CONFIGURE_PIC32MZ_EF_CUSTOM bool depends on USE_BSP depends on BSP_PIC32MZ_EF_CUSTOM default y select BSP_TRIGGER select BSP_POSC_24MHz set BSP_PIN_17_FUNCTION_NAME to "BSP_WIFI_SLEEP" set BSP_PIN_17_FUNCTION_TYPE to "GPIO_OUT" set BSP_PIN_2_FUNCTION_NAME to "BSP_AK4642_PDN" if SELECT_DRV_AK4642 = y set BSP_PIN_2_FUNCTION_NAME to "BSP_AK7755_PDN" if SELECT_DRV_AK7755 = y set BSP_PIN_2_FUNCTION_NAME to "BSP_STBY_RST" if SELECT_DRV_AK4642 = n || SELECT_DRV_AK7755 = n set BSP_PIN_2_FUNCTION_TYPE to "GPIO_OUT" set BSP_PIN_25_FUNCTION_NAME to "BSP_RGB_LED_BLUE" set BSP_PIN_25_FUNCTION_TYPE to "LED_AL" set BSP_PIN_24_FUNCTION_NAME to "BSP_RGB_LED_GREEN" set BSP_PIN_24_FUNCTION_TYPE to "LED_AL" set BSP_PIN_20_FUNCTION_NAME to "BSP_RGB_LED_RED" set BSP_PIN_20_FUNCTION_TYPE to "LED_AL" set BSP_PIN_99_FUNCTION_NAME to "BSP_LED_1" set BSP_PIN_99_FUNCTION_TYPE to "LED_AH" set BSP_PIN_100_FUNCTION_NAME to "BSP_LED_2" set BSP_PIN_100_FUNCTION_TYPE to "LED_AH" set BSP_PIN_4_FUNCTION_NAME to "BSP_LED_3" set BSP_PIN_4_FUNCTION_TYPE to "LED_AH" set BSP_PIN_96_FUNCTION_NAME to "BSP_SWITCH_1" set BSP_PIN_96_FUNCTION_TYPE to "SWITCH" set BSP_PIN_97_FUNCTION_NAME to "USB_VBUS_SWITCH" set BSP_PIN_97_FUNCTION_TYPE to "VBUS" endmenu
The following lines conditionally enable the pin configurations done for the Custom BSP if the Use BSP? and PIC32MZ EF Custom Development Board options are selected in MHC.
bool
depends on USE_BSP
depends on BSP_PIC32MZ_EF_CUSTOM
default y
select BSP_TRIGGER
select BSP_POSC_24MHz
The script also sets the Primary Oscillator to 24 MHz.
The set instructions in the script assign a Function Name and Function Type to a particular pin of the PIC32 device.
For example, the following lines assign the name BSP_WIFI_SLEEP to Pin Number 17 of the PIC32 device and configure it to be a General Purpose Output (GPIO_OUT).
set BSP_PIN_17_FUNCTION_NAME to "BSP_WIFI_SLEEP"
set BSP_PIN_17_FUNCTION_TYPE to "GPIO_OUT"
The set instructions can also conditionally set the Function Name of the PIC32 device pins.
For example, the lines:
set BSP_PIN_2_FUNCTION_NAME to "BSP_AK4642_PDN" if SELECT_DRV_AK4642 = y
set BSP_PIN_2_FUNCTION_NAME to "BSP_AK7755_PDN" if SELECT_DRV_AK7755 = y
set BSP_PIN_2_FUNCTION_NAME to "BSP_STBY_RST" if SELECT_DRV_AK4642 = n || SELECT_DRV_AK7755 = n
set BSP_PIN_2_FUNCTION_TYPE to "GPIO_OUT"
set the Function Name of Pin Number 2 to:
- BSP_AK4642_PDN if CODEC AK4642 is selected in MHC.
- BSP_AK7755_PDN if CODEC AK7755 is selected in MHC or
- BSP_STBY_RST if none of the above CODECs are selected.
4
Map the template files.
The BSP source and header files for your custom board are in the form of template (FTL) files inside the BSP folder.
They have to be added to the project to be compiled along with your application. When the MHC generates the code, it decodes the template files and place the resultant source and header files into the project workspace.
The script below enables this operation; append it to the local bsp.hconfig file.
menu "Custom Board Configurations for PIC32MZ EF Custom Development Board" depends on USE_BSP import PIC32MZ_EF_CUSTOM_IMPORT_ICB "Select Custom Configuration To Import" default "../*/*.mhc" ---help--- IDH_HTML_Board_Support_Package_Help ---endhelp--- template BSP_pic32mz_ef_custom_H "$HARMONY_VERSION_PATH/bsp/pic32mz_ef_custom/templates/bsp.h.ftl" to "$PROJECT_HEADER_FILES/app/system_config/$CONFIGURATION/bsp/bsp.h" template BSP_pic32mz_ef_custom_C "$HARMONY_VERSION_PATH/bsp/pic32mz_ef_custom/templates/bsp.c.ftl" to "$PROJECT_SOURCE_FILES/app/system_config/$CONFIGURATION/bsp/bsp.c" compiler BSP_COMPILER_INCLUDE_pic32mz_ef_custom includepath "$PROJECT_HEADER_FILES/system_config/$CONFIGURATION/bsp" endmenu endif