Zephyr build fails: missing pinctrl file and HAL_NXP
When using the MCUXpresso extension for VS Code and building a Zephyr application, one error that may occur is a missing pinctrl file. The VS Code Output tab would show an error like this when the build fails:
[cmake] In file included from zephyrproject/zephyr/boards/nxp/frdm_mcxn947/frdm_mcxn947.dtsi:7,
[cmake] from zephyrproject/zephyr/boards/nxp/frdm_mcxn947/frdm_mcxn947_mcxn947_cpu0.dts:10,
[cmake] from <command-line>:
[cmake] zephyrproject/zephyr/boards/nxp/frdm_mcxn947/frdm_mcxn947-pinctrl.dtsi:7:10: fatal error: nxp/mcx/MCXN947VDF-pinctrl.h: No such file or directory
[cmake] 7 | #include <nxp/mcx/MCXN947VDF-pinctrl.h>
This file is included in the HAL_NXP repo, which West should clone when the Zephyr repo is imported. You can verify if this repo is missing. If the Zephyr repo is at zephyrproject/zephyr, the HAL_NXP repo is at zephyrproject/modules/hal/nxp. If the pinctrl file is missing, or this HAL_NXP repo is missing, it likely means the `west update` command failed or was interrupted when the repo was imported. One option to resolve this is to re-import the Zephyr repo. But this can take a long time, and needs to download and clone a large amount of files. A faster option is to run the `west update` command using CLI.
Open a command window, and Activate the Python Virtual Environment. Change to the Zephyr repo directory. The Windows command below uses the default path, but the VS Code Output log will show your local path:
cd C:\Users\<username>\zephyrproject\zephyr
Run the `west update` command. Depending on how many repos are missing or need updating, this may take awhile. Poor network bandwidth is one reason the `west update` command may have failed the first time. If the updating the repos times out or is interrupted, you can run `west update` multiple times until all the repos are updated, and west gives no more errors.