Skip to content

MPU flash write #654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions arch/arm/core/cortex_m/mpu/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ config NXP_MPU
default n
help
MCU has NXP MPU

config MPU_ALLOW_FLASH_WRITE
bool "Add MPU access to write to flash"
depends on ARM_MPU || NXP_MPU
default n
help
Enable this to allow MPU RWX access to flash memory
6 changes: 6 additions & 0 deletions include/arch/arm/cortex_m/mpu/arm_mpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,14 @@ struct arm_mpu {
#define REGION_RAM_ATTR(size) \
(NORMAL_OUTER_INNER_NON_CACHEABLE_NON_SHAREABLE | \
NOT_EXEC | size | FULL_ACCESS)
#if defined(CONFIG_MPU_ALLOW_FLASH_WRITE)
#define REGION_FLASH_ATTR(size) \
(NORMAL_OUTER_INNER_NON_CACHEABLE_NON_SHAREABLE | size | \
P_RW_U_RO)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does REGION_RAM_ATTR need execute access as in the NXP MPU?

#else
#define REGION_FLASH_ATTR(size) \
(NORMAL_OUTER_INNER_NON_CACHEABLE_NON_SHAREABLE | size | RO)
#endif
#define REGION_PPB_ATTR(size) (STRONGLY_ORDERED_SHAREABLE | size | FULL_ACCESS)
#define REGION_IO_ATTR(size) (DEVICE_NON_SHAREABLE | size | FULL_ACCESS)

Expand Down
13 changes: 12 additions & 1 deletion include/arch/arm/cortex_m/mpu/nxp_mpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,25 @@
#define ENDADDR_ROUND(x) (x - 0x1F)

/* Some helper defines for common regions */
#if defined(CONFIG_MPU_ALLOW_FLASH_WRITE)
#define REGION_RAM_ATTR (MPU_REGION_READ | \
MPU_REGION_WRITE | \
MPU_REGION_EXEC | \
MPU_REGION_SU)

#define REGION_FLASH_ATTR (MPU_REGION_READ | \
MPU_REGION_WRITE | \
MPU_REGION_EXEC | \
MPU_REGION_SU)
#else
#define REGION_RAM_ATTR (MPU_REGION_READ | \
MPU_REGION_WRITE | \
MPU_REGION_SU)

#define REGION_FLASH_ATTR (MPU_REGION_READ | \
MPU_REGION_EXEC | \
MPU_REGION_SU)
#endif

#define REGION_IO_ATTR (MPU_REGION_READ | \
MPU_REGION_WRITE | \
Expand All @@ -80,7 +92,6 @@

#define REGION_DEBUG_ATTR MPU_REGION_SU


/* Region definition data structure */
struct nxp_mpu_region {
/* Region Base Address */
Expand Down
4 changes: 4 additions & 0 deletions samples/mpu/mpu_test/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ single thread: :file:`prj_single.conf`:

$ make BOARD=v2m_beetle CONF_FILE=prj_single.conf run

To build a version that allows writes to the flash device, edit
``prj.conf``, and follow the directions in the comments to enable the
proper configs.

Sample Output
=============

Expand Down
14 changes: 14 additions & 0 deletions samples/mpu/mpu_test/prj.conf
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
CONFIG_CONSOLE_SHELL=y

### In order to allow the flash device to be written to, this line will
### need to be uncommented. Note that on some devices (MCUX/NXP), this
### needs to be enabled to even enable CONFIG_FLASH, as the probe needs
### to write to flash. Also, on NXP, enabling flash write also requires
### that execute from RAM be enabled, as this is needed to operate the
### flash device.
# CONFIG_MPU_ALLOW_FLASH_WRITE=y
# CONFIG_FLASH=y

### These can be uncommented to enable the flash device on the
### STM32F4X devices.
# CONFIG_SOC_FLASH_STM32=y
# CONFIG_SOC_SERIES_STM32F4X=y