samples: mpu_test: Add controller specific write
This patch add a controller specific write function and fixes a documentation error in the mpu_test README file. Signed-off-by: Vincenzo Frascino <vincenzo.frascino@linaro.org>
This commit is contained in:
parent
14a892f7a4
commit
8162bb63c4
2 changed files with 80 additions and 14 deletions
|
@ -51,16 +51,12 @@ Sample Output
|
||||||
|
|
||||||
.. code-block:: console
|
.. code-block:: console
|
||||||
|
|
||||||
***** BOOTING ZEPHYR OS v1.7.99 - BUILD: Mar 9 2017 13:01:59 *****
|
***** BOOTING ZEPHYR OS v1.7.99 - BUILD: May 12 2017 09:47:02 *****
|
||||||
*** MPU test options ***
|
shell> select mpu_test
|
||||||
1 - Read a reserved address in the memory map
|
mpu_test> read
|
||||||
2 - Write in to boot FLASH/ROM
|
***** BUS FAULT *****
|
||||||
3 - Run code located in RAM
|
Executing thread ID (thread): 0x200003b8
|
||||||
Select an option:
|
Faulting instruction address: 0x290
|
||||||
1 - Read a reserved address in the memory map
|
Precise data bus error
|
||||||
***** MPU FAULT *****
|
Address: 0x24000000
|
||||||
Executing thread ID (thread): 0x20000258
|
Fatal fault in thread 0x200003b8! Aborting.
|
||||||
Faulting instruction address: 0x2ac
|
|
||||||
Data Access Violation
|
|
||||||
Address: 0x20040000
|
|
||||||
Fatal fault in essential thread! Spinning...
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <zephyr.h>
|
#include <zephyr.h>
|
||||||
|
#include <flash.h>
|
||||||
#include <misc/printk.h>
|
#include <misc/printk.h>
|
||||||
#include <shell/shell.h>
|
#include <shell/shell.h>
|
||||||
|
|
||||||
|
@ -33,18 +34,81 @@ static int shell_cmd_read(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(CONFIG_SOC_FLASH_MCUX)
|
||||||
|
static int shell_cmd_write_mcux(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
ARG_UNUSED(argc);
|
||||||
|
ARG_UNUSED(argv);
|
||||||
|
|
||||||
|
struct device *flash_dev;
|
||||||
|
flash_dev = device_get_binding(CONFIG_SOC_FLASH_MCUX_DEV_NAME);
|
||||||
|
|
||||||
|
u32_t value[2];
|
||||||
|
|
||||||
|
/* 128K reserved to the application */
|
||||||
|
u32_t offset = FLASH_MEM + 0x20000;
|
||||||
|
value[0] = 0xBADC0DE;
|
||||||
|
value[1] = 0xBADC0DE;
|
||||||
|
|
||||||
|
printk("write address: 0x%x\n", offset);
|
||||||
|
|
||||||
|
flash_write_protection_set(flash_dev, false);
|
||||||
|
|
||||||
|
if (flash_write(flash_dev, offset, value,
|
||||||
|
sizeof(value)) != 0) {
|
||||||
|
printk("Flash write failed!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
flash_write_protection_set(flash_dev, true);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
#elif defined(CONFIG_SOC_FLASH_STM32)
|
||||||
|
static int shell_cmd_write_stm32(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
ARG_UNUSED(argc);
|
||||||
|
ARG_UNUSED(argv);
|
||||||
|
|
||||||
|
struct device *flash_dev;
|
||||||
|
flash_dev = device_get_binding(CONFIG_SOC_FLASH_STM32_DEV_NAME);
|
||||||
|
|
||||||
|
/* 16K reserved to the application */
|
||||||
|
u32_t offset = FLASH_MEM + 0x4000;
|
||||||
|
u32_t value = 0xBADC0DE;
|
||||||
|
|
||||||
|
printk("write address: 0x%x\n", offset);
|
||||||
|
|
||||||
|
flash_write_protection_set(flash_dev, false);
|
||||||
|
|
||||||
|
if (flash_write(flash_dev, offset, &value,
|
||||||
|
sizeof(value)) != 0) {
|
||||||
|
printk("Flash write failed!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
flash_write_protection_set(flash_dev, true);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
static int shell_cmd_write(int argc, char *argv[])
|
static int shell_cmd_write(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
ARG_UNUSED(argc);
|
ARG_UNUSED(argc);
|
||||||
ARG_UNUSED(argv);
|
ARG_UNUSED(argv);
|
||||||
|
|
||||||
u32_t *p_mem = (u32_t *) FLASH_MEM;
|
/* 16K reserved to the application */
|
||||||
|
u32_t *p_mem = (u32_t *) (FLASH_MEM + 0x4000);
|
||||||
|
|
||||||
|
printk("write address: 0x%x\n", FLASH_MEM + 0x4000);
|
||||||
|
|
||||||
/* Write in to boot FLASH/ROM */
|
/* Write in to boot FLASH/ROM */
|
||||||
*p_mem = 0xBADC0DE;
|
*p_mem = 0xBADC0DE;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif /* SOC_FLASH_MCUX */
|
||||||
|
|
||||||
static int shell_cmd_run(int argc, char *argv[])
|
static int shell_cmd_run(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -83,7 +147,13 @@ static int shell_cmd_mtest(int argc, char *argv[])
|
||||||
|
|
||||||
static struct shell_cmd commands[] = {
|
static struct shell_cmd commands[] = {
|
||||||
{ "read", shell_cmd_read, READ_CMD_HELP},
|
{ "read", shell_cmd_read, READ_CMD_HELP},
|
||||||
|
#if defined(CONFIG_SOC_FLASH_MCUX)
|
||||||
|
{ "write", shell_cmd_write_mcux, WRITE_CMD_HELP },
|
||||||
|
#elif defined(CONFIG_SOC_FLASH_STM32)
|
||||||
|
{ "write", shell_cmd_write_stm32, WRITE_CMD_HELP },
|
||||||
|
#else
|
||||||
{ "write", shell_cmd_write, WRITE_CMD_HELP },
|
{ "write", shell_cmd_write, WRITE_CMD_HELP },
|
||||||
|
#endif /* SOC_FLASH_MCUX*/
|
||||||
{ "run", shell_cmd_run, RUN_CMD_HELP },
|
{ "run", shell_cmd_run, RUN_CMD_HELP },
|
||||||
{ "mtest", shell_cmd_mtest, MTEST_CMD_HELP },
|
{ "mtest", shell_cmd_mtest, MTEST_CMD_HELP },
|
||||||
{ NULL, NULL, NULL }
|
{ NULL, NULL, NULL }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue