From abe3c1d3c53122daae914856bdabe7e5a0184b65 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Wed, 23 Mar 2022 15:05:49 +0100 Subject: [PATCH] samples: arch: mpu: mpu_test: use DEVICE_DT_GET Use DEVICE_DT_GET to obtain the flash device at compile time. Add readiness check at main. Signed-off-by: Gerard Marull-Paretas --- samples/arch/mpu/mpu_test/src/main.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) 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,