From f04904c6e8dc8601c98ecd5d8daa764d4454f446 Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Thu, 13 Dec 2018 16:05:04 +0200 Subject: [PATCH 1/2] CM3: Make ACTLR bit definitions conditional The ACTLR register itself is conditional on chip revision, but its bit definitions were always defined. Make the the bit definitions also conditional, so it is possible to produce portable code that sets DISDEFWBUF if available: #ifdef SCnSCB_ACTLR_DISDEFWBUF_Msk SCnSCB->ACTLR |= SCnSCB_ACTLR_DISDEFWBUF_Msk; #endif (cherry-picked from CMSIS b2b04dbeece0a046556bfc320bef6b20bef3f16f) --- cmsis/TARGET_CORTEX_M/core_cm3.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmsis/TARGET_CORTEX_M/core_cm3.h b/cmsis/TARGET_CORTEX_M/core_cm3.h index 74bff64be4..e84a9f5b7d 100644 --- a/cmsis/TARGET_CORTEX_M/core_cm3.h +++ b/cmsis/TARGET_CORTEX_M/core_cm3.h @@ -668,7 +668,7 @@ typedef struct #define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL /*<< SCnSCB_ICTR_INTLINESNUM_Pos*/) /*!< ICTR: INTLINESNUM Mask */ /* Auxiliary Control Register Definitions */ - +#if defined (__CM3_REV) && (__CM3_REV >= 0x200U) #define SCnSCB_ACTLR_DISFOLD_Pos 2U /*!< ACTLR: DISFOLD Position */ #define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */ @@ -677,6 +677,7 @@ typedef struct #define SCnSCB_ACTLR_DISMCYCINT_Pos 0U /*!< ACTLR: DISMCYCINT Position */ #define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL /*<< SCnSCB_ACTLR_DISMCYCINT_Pos*/) /*!< ACTLR: DISMCYCINT Mask */ +#endif /*@} end of group CMSIS_SCnotSCB */ From bd413f1d82dc80f93209dc82aab29bd45330584c Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Tue, 6 Nov 2018 16:45:45 +0200 Subject: [PATCH 2/2] Disable write buffer in debug builds (M3/M4) As part of work to improve the debugging of exceptions, have Mbed OS make an effort to make exceptions more precise in debug builds at the cost of performance. Related pyOCD work: https://github.com/mbedmicro/pyOCD/pull/430 --- platform/mbed_application.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/platform/mbed_application.c b/platform/mbed_application.c index b55519491b..41930fcd65 100644 --- a/platform/mbed_application.c +++ b/platform/mbed_application.c @@ -71,6 +71,17 @@ void mbed_start_application(uintptr_t address) powerdown_scb(address); mbed_mpu_free(); +#ifdef MBED_DEBUG + // Configs to make debugging easier +#ifdef SCnSCB_ACTLR_DISDEFWBUF_Msk + // Disable write buffer to make BusFaults (eg write to ROM via NULL pointer) precise. + // Possible on Cortex-M3 and M4, not on M0, M7 or M33. + // Would be less necessary if ROM was write-protected in MPU to give a + // precise MemManage exception. + SCnSCB->ACTLR |= SCnSCB_ACTLR_DISDEFWBUF_Msk; +#endif +#endif + sp = *((void **)address + 0); pc = *((void **)address + 1); start_new_application(sp, pc);