aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2019-04-23 06:53:43 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2019-04-23 06:53:43 +0000
commitceba105275ca7d43a7c425f25787423ea3c90c4c (patch)
tree531590c85a49aa542d7cc7c4ba7fd3251c8b6c0d
parenta7ce9444af2bcd30e0255c712fbab3dba1a82305 (diff)
downloadChibiOS-ceba105275ca7d43a7c425f25787423ea3c90c4c.tar.gz
ChibiOS-ceba105275ca7d43a7c425f25787423ea3c90c4c.tar.bz2
ChibiOS-ceba105275ca7d43a7c425f25787423ea3c90c4c.zip
Fixed bug #1027.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/stable_19.1.x@12753 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
-rw-r--r--os/common/ports/ARMCMx/chcore_v7m.c13
-rw-r--r--os/common/ports/ARMCMx/chcore_v7m.h17
-rw-r--r--os/common/ports/ARMCMx/compilers/GCC/chcoreasm_v7m.S3
-rw-r--r--os/common/ports/ARMCMx/compilers/IAR/chcoreasm_v7m.s6
-rw-r--r--os/common/ports/ARMCMx/compilers/RVCT/chcoreasm_v7m.s7
-rw-r--r--os/common/ports/ARMCMx/mpu.h14
-rw-r--r--os/hal/ports/common/ARMCMx/mpu_v7m.h14
-rw-r--r--readme.txt1
8 files changed, 68 insertions, 7 deletions
diff --git a/os/common/ports/ARMCMx/chcore_v7m.c b/os/common/ports/ARMCMx/chcore_v7m.c
index a40b2c005..8fbe02591 100644
--- a/os/common/ports/ARMCMx/chcore_v7m.c
+++ b/os/common/ports/ARMCMx/chcore_v7m.c
@@ -116,6 +116,19 @@ void PendSV_Handler(void) {
/* Module exported functions. */
/*===========================================================================*/
+#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || \
+ (PORT_ENABLE_GUARD_PAGES == TRUE) || \
+ defined(__DOXYGEN__)
+/**
+ * @brief Setting up MPU region for the current thread.
+ */
+void _port_set_region(void) {
+
+ mpuSetRegionAddress(PORT_USE_MPU_REGION,
+ chThdGetSelfX()->wabase);
+}
+#endif
+
/**
* @brief Exception exit redirection to _port_switch_from_isr().
*/
diff --git a/os/common/ports/ARMCMx/chcore_v7m.h b/os/common/ports/ARMCMx/chcore_v7m.h
index 408070b7e..901925c49 100644
--- a/os/common/ports/ARMCMx/chcore_v7m.h
+++ b/os/common/ports/ARMCMx/chcore_v7m.h
@@ -82,6 +82,13 @@
#endif
/**
+ * @brief MPU region to be used to stack guards.
+ */
+#if !defined(PORT_USE_MPU_REGION) || defined(__DOXYGEN__)
+#define PORT_USE_MPU_REGION MPU_REGION_7
+#endif
+
+/**
* @brief Stack size for the system idle thread.
* @details This size depends on the idle thread implementation, usually
* the idle thread should take no more space than those reserved
@@ -478,12 +485,8 @@ struct port_intctx {
_port_switch(ntp, otp); \
\
/* Setting up the guard page for the switched-in thread.*/ \
- mpuConfigureRegion(MPU_REGION_0, \
- chThdGetSelfX()->wabase, \
- MPU_RASR_ATTR_AP_NA_NA | \
- MPU_RASR_ATTR_NON_CACHEABLE | \
- MPU_RASR_SIZE_32 | \
- MPU_RASR_ENABLE); \
+ mpuSetRegionAddress(PORT_USE_MPU_REGION, \
+ chThdGetSelfX()->wabase); \
}
#endif
#endif
@@ -535,7 +538,7 @@ static inline void port_init(void) {
/* Setting up the guard page on the main() function stack base
initially.*/
- mpuConfigureRegion(MPU_REGION_0,
+ mpuConfigureRegion(PORT_USE_MPU_REGION,
&__main_thread_stack_base__,
MPU_RASR_ATTR_AP_NA_NA |
MPU_RASR_ATTR_NON_CACHEABLE |
diff --git a/os/common/ports/ARMCMx/compilers/GCC/chcoreasm_v7m.S b/os/common/ports/ARMCMx/compilers/GCC/chcoreasm_v7m.S
index db3f675ea..89e37583e 100644
--- a/os/common/ports/ARMCMx/compilers/GCC/chcoreasm_v7m.S
+++ b/os/common/ports/ARMCMx/compilers/GCC/chcoreasm_v7m.S
@@ -103,6 +103,9 @@ _port_switch:
.thumb_func
.globl _port_thread_start
_port_thread_start:
+#if CH_DBG_ENABLE_STACK_CHECK || PORT_ENABLE_GUARD_PAGES
+ bl _port_set_region
+#endif
#if CH_DBG_SYSTEM_STATE_CHECK
bl _dbg_check_unlock
#endif
diff --git a/os/common/ports/ARMCMx/compilers/IAR/chcoreasm_v7m.s b/os/common/ports/ARMCMx/compilers/IAR/chcoreasm_v7m.s
index 0b330e8d3..b0de85ce1 100644
--- a/os/common/ports/ARMCMx/compilers/IAR/chcoreasm_v7m.s
+++ b/os/common/ports/ARMCMx/compilers/IAR/chcoreasm_v7m.s
@@ -64,6 +64,9 @@ ICSR_PENDSVSET SET 0x10000000
EXTERN chThdExit
EXTERN chSysHalt
EXTERN chSchDoReschedule
+#if CH_DBG_ENABLE_STACK_CHECK || PORT_ENABLE_GUARD_PAGES
+ EXTERN _port_set_region
+#endif
#if CH_DBG_STATISTICS
EXTERN _stats_start_measure_crit_thd
EXTERN _stats_stop_measure_crit_thd
@@ -107,6 +110,9 @@ _port_switch:
*/
PUBLIC _port_thread_start
_port_thread_start:
+#if CH_DBG_ENABLE_STACK_CHECK || PORT_ENABLE_GUARD_PAGES
+ bl _port_set_region
+#endif
#if CH_DBG_SYSTEM_STATE_CHECK
bl _dbg_check_unlock
#endif
diff --git a/os/common/ports/ARMCMx/compilers/RVCT/chcoreasm_v7m.s b/os/common/ports/ARMCMx/compilers/RVCT/chcoreasm_v7m.s
index 6f536c2c2..04d082ee5 100644
--- a/os/common/ports/ARMCMx/compilers/RVCT/chcoreasm_v7m.s
+++ b/os/common/ports/ARMCMx/compilers/RVCT/chcoreasm_v7m.s
@@ -59,7 +59,11 @@ ICSR_PENDSVSET EQU 0x10000000
AREA |.text|, CODE, READONLY
IMPORT chThdExit
+ IMPORT chSysHalt
IMPORT chSchDoReschedule
+#if CH_DBG_ENABLE_STACK_CHECK || PORT_ENABLE_GUARD_PAGES
+ IMPORT _port_set_region
+#endif
#if CH_DBG_STATISTICS
IMPORT _stats_start_measure_crit_thd
IMPORT _stats_stop_measure_crit_thd
@@ -102,6 +106,9 @@ _port_switch PROC
*/
EXPORT _port_thread_start
_port_thread_start PROC
+#if CH_DBG_ENABLE_STACK_CHECK || PORT_ENABLE_GUARD_PAGES
+ bl _port_set_region
+#endif
#if CH_DBG_SYSTEM_STATE_CHECK
bl _dbg_check_unlock
#endif
diff --git a/os/common/ports/ARMCMx/mpu.h b/os/common/ports/ARMCMx/mpu.h
index b6c631993..850be915b 100644
--- a/os/common/ports/ARMCMx/mpu.h
+++ b/os/common/ports/ARMCMx/mpu.h
@@ -196,6 +196,20 @@
MPU->RASR = ((uint32_t)attribs); \
}
+/**
+ * @brief Changes an MPU region base address.
+ *
+ * @param[in] region the region number
+ * @param[in] address start address of the region, note, there are alignment
+ * constraints
+ *
+ * @api
+ */
+#define mpuSetRegionAddress(region, addr) { \
+ MPU->RNR = ((uint32_t)region); \
+ MPU->RBAR = ((uint32_t)addr); \
+}
+
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
diff --git a/os/hal/ports/common/ARMCMx/mpu_v7m.h b/os/hal/ports/common/ARMCMx/mpu_v7m.h
index 48954c95c..11e691aab 100644
--- a/os/hal/ports/common/ARMCMx/mpu_v7m.h
+++ b/os/hal/ports/common/ARMCMx/mpu_v7m.h
@@ -196,6 +196,20 @@
MPU->RASR = ((uint32_t)attribs); \
}
+/**
+ * @brief Changes an MPU region base address.
+ *
+ * @param[in] region the region number
+ * @param[in] address start address of the region, note, there are alignment
+ * constraints
+ *
+ * @api
+ */
+#define mpuSetRegionAddress(region, addr) { \
+ MPU->RNR = ((uint32_t)region); \
+ MPU->RBAR = ((uint32_t)addr); \
+}
+
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
diff --git a/readme.txt b/readme.txt
index 405516578..6e41588a1 100644
--- a/readme.txt
+++ b/readme.txt
@@ -78,6 +78,7 @@
- NEW: updates to MFS from trunk code.
- NEW: updates to test library from trunk code.
- HAL: Added H753 to all H7 mcuconf.h files.
+- FIX: Fixed MPU setup missing on thread start (bug #1027).
- FIX: Fixed invalid I2C4 DMAs for STM32F76x (bug #1026).
- FIX: Fixed invalid STM32_UART7_RX_DMA_CHN for STM32F469 (bug #1025).
- FIX: Fixed invalid EXTI registry constant for STM32L4+ (bug #1024).