Step 4.1: Modify the Local bsp.hconfig File
MPLAB® Harmony Configurator (MHC) executes the script in localbsp.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
Thebsp.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 andbsp.h.ftl, tobsp.c andbsp.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.
ifblockBSP_PIC32MZ_EF_CUSTOMmenu"Select BSP Features"dependsonUSE_BSPdependsonBSP_PIC32MZ_EF_CUSTOM
3
Configure the pins.
As per the analysis made inStep 1.2, write the script as below:
configBSP_CONFIGURE_PIC32MZ_EF_CUSTOMbooldependsonUSE_BSPdependsonBSP_PIC32MZ_EF_CUSTOMdefaultyselectBSP_TRIGGERselectBSP_POSC_24MHzsetBSP_PIN_17_FUNCTION_NAMEto"BSP_WIFI_SLEEP"setBSP_PIN_17_FUNCTION_TYPEto"GPIO_OUT"setBSP_PIN_2_FUNCTION_NAMEto"BSP_AK4642_PDN"ifSELECT_DRV_AK4642 =ysetBSP_PIN_2_FUNCTION_NAMEto"BSP_AK7755_PDN"ifSELECT_DRV_AK7755 =ysetBSP_PIN_2_FUNCTION_NAMEto"BSP_STBY_RST"ifSELECT_DRV_AK4642 =n ||SELECT_DRV_AK7755 =nsetBSP_PIN_2_FUNCTION_TYPEto"GPIO_OUT"setBSP_PIN_25_FUNCTION_NAMEto"BSP_RGB_LED_BLUE"setBSP_PIN_25_FUNCTION_TYPEto"LED_AL"setBSP_PIN_24_FUNCTION_NAMEto"BSP_RGB_LED_GREEN"setBSP_PIN_24_FUNCTION_TYPEto"LED_AL"setBSP_PIN_20_FUNCTION_NAMEto"BSP_RGB_LED_RED"setBSP_PIN_20_FUNCTION_TYPEto"LED_AL"setBSP_PIN_99_FUNCTION_NAMEto"BSP_LED_1"setBSP_PIN_99_FUNCTION_TYPEto"LED_AH"setBSP_PIN_100_FUNCTION_NAMEto"BSP_LED_2"setBSP_PIN_100_FUNCTION_TYPEto"LED_AH"setBSP_PIN_4_FUNCTION_NAMEto"BSP_LED_3"setBSP_PIN_4_FUNCTION_TYPEto"LED_AH"setBSP_PIN_96_FUNCTION_NAMEto"BSP_SWITCH_1"setBSP_PIN_96_FUNCTION_TYPEto"SWITCH"setBSP_PIN_97_FUNCTION_NAMEto"USB_VBUS_SWITCH"setBSP_PIN_97_FUNCTION_TYPEto"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_24MHzThe 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 localbsp.hconfig file.
menu"Custom Board Configurations for PIC32MZ EF Custom Development Board"dependsonUSE_BSPimportPIC32MZ_EF_CUSTOM_IMPORT_ICB"Select Custom Configuration To Import"default"../*/*.mhc" ---help---IDH_HTML_Board_Support_Package_Help ---endhelp---templateBSP_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"templateBSP_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"compilerBSP_COMPILER_INCLUDE_pic32mz_ef_customincludepath"$PROJECT_HEADER_FILES/system_config/$CONFIGURATION/bsp"endmenuendif


