diff --git a/samples/arch/mpu/mpu_test/src/main.c b/samples/arch/mpu/mpu_test/src/main.c index 292c297a03f..8a48b79f764 100644 --- a/samples/arch/mpu/mpu_test/src/main.c +++ b/samples/arch/mpu/mpu_test/src/main.c @@ -7,6 +7,8 @@ #include #include +#include +#include #include #include @@ -27,6 +29,11 @@ #define MTEST_CMD_HELP "Memory Test writes or reads a memory location.\n" \ "Command accepts 1 (Read) or 2 (Write) parameters." +#if defined(CONFIG_SOC_FLASH_MCUX) || defined(CONFIG_SOC_FLASH_LPC) || \ + defined(CONFIG_SOC_FLASH_STM32) +static const struct device *flash_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller)); +#endif + static int cmd_read(const struct shell *shell, size_t argc, char *argv[]) { ARG_UNUSED(argc); @@ -46,13 +53,9 @@ static int cmd_write_mcux(const struct shell *shell, size_t argc, char *argv[]) ARG_UNUSED(argc); ARG_UNUSED(argv); - const struct device *flash_dev; uint32_t value[2]; uint32_t offset; - flash_dev = - device_get_binding(DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL); - /* 128K reserved to the application */ offset = FLASH_MEM + 0x20000; value[0] = 0xBADC0DE; @@ -75,11 +78,6 @@ static int cmd_write_stm32(const struct shell *shell, size_t argc, char *argv[]) ARG_UNUSED(argc); ARG_UNUSED(argv); - const struct device *flash_dev; - - flash_dev = - device_get_binding(DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL); - /* 16K reserved to the application */ uint32_t offset = FLASH_MEM + 0x4000; uint32_t value = 0xBADC0DE; @@ -143,7 +141,13 @@ static int cmd_mtest(const struct shell *shell, size_t argc, char *argv[]) void main(void) { - +#if defined(CONFIG_SOC_FLASH_MCUX) || defined(CONFIG_SOC_FLASH_LPC) || \ + defined(CONFIG_SOC_FLASH_STM32) + if (!device_is_ready(flash_dev)) { + printk("Flash device not ready\n"); + return; + } +#endif } SHELL_STATIC_SUBCMD_SET_CREATE(sub_mpu,