From b3f17a9e01bce66de423d2a6bfb8c58af7d1e9e8 Mon Sep 17 00:00:00 2001 From: ccli8 Date: Thu, 17 May 2018 18:18:18 +0800 Subject: [PATCH 1/4] Support mbed_start_application for Cortex-M23 --- platform/mbed_application.c | 26 +++++++++++++++++++++++++- platform/mbed_application.h | 3 ++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/platform/mbed_application.c b/platform/mbed_application.c index 75657f69e7..dd0b6a6157 100644 --- a/platform/mbed_application.c +++ b/platform/mbed_application.c @@ -48,12 +48,20 @@ static void powerdown_nvic() int i; int j; +#if defined(__CORTEX_M23) + isr_groups_32 = 16; +#else isr_groups_32 = ((SCnSCB->ICTR & SCnSCB_ICTR_INTLINESNUM_Msk) >> SCnSCB_ICTR_INTLINESNUM_Pos) + 1; +#endif for (i = 0; i < isr_groups_32; i++) { NVIC->ICER[i] = 0xFFFFFFFF; NVIC->ICPR[i] = 0xFFFFFFFF; for (j = 0; j < 8; j++) { +#if defined(__CORTEX_M23) + NVIC->IPR[i * 8 + j] = 0x00000000; +#else NVIC->IP[i * 8 + j] = 0x00000000; +#endif } } } @@ -69,17 +77,20 @@ static void powerdown_scb(uint32_t vtor) SCB->SCR = 0x00000000; // SCB->CCR - Implementation defined value for (i = 0; i < 12; i++) { -#if defined(__CORTEX_M7) +#if defined(__CORTEX_M7) || defined(__CORTEX_M23) SCB->SHPR[i] = 0x00; #else SCB->SHP[i] = 0x00; #endif } SCB->SHCSR = 0x00000000; +#if defined(__CORTEX_M23) +#else SCB->CFSR = 0xFFFFFFFF; SCB->HFSR = SCB_HFSR_DEBUGEVT_Msk | SCB_HFSR_FORCED_Msk | SCB_HFSR_VECTTBL_Msk; SCB->DFSR = SCB_DFSR_EXTERNAL_Msk | SCB_DFSR_VCATCH_Msk | SCB_DFSR_DWTTRAP_Msk | SCB_DFSR_BKPT_Msk | SCB_DFSR_HALTED_Msk; +#endif // SCB->MMFAR - Implementation defined value // SCB->BFAR - Implementation defined value // SCB->AFSR - Implementation defined value @@ -106,6 +117,18 @@ __asm static void start_new_application(void *sp, void *pc) void start_new_application(void *sp, void *pc) { +#if defined(__CORTEX_M23) + __asm volatile ( + "ldr r2, =0 \n" + "msr control, r2 \n" // Switch to main stack + "mov sp, %0 \n" + "msr primask, r2 \n" // Enable interrupts + "bx %1 \n" + : + : "l" (sp), "l" (pc) + : "r2", "cc", "memory" + ); +#else __asm volatile ( "mov r2, #0 \n" "msr control, r2 \n" // Switch to main stack @@ -116,6 +139,7 @@ void start_new_application(void *sp, void *pc) : "l" (sp), "l" (pc) : "r2", "cc", "memory" ); +#endif } #else diff --git a/platform/mbed_application.h b/platform/mbed_application.h index 43b4813f75..d02ac67651 100644 --- a/platform/mbed_application.h +++ b/platform/mbed_application.h @@ -19,7 +19,8 @@ #include -#if defined(__CORTEX_M3) || defined(__CORTEX_M4) || defined(__CORTEX_M7) +#if defined(__CORTEX_M3) || defined(__CORTEX_M4) || defined(__CORTEX_M7)\ + || defined(__CORTEX_M23) #define MBED_APPLICATION_SUPPORT 1 #else #define MBED_APPLICATION_SUPPORT 0 From 646f61400abb4d80aced65bbd286865fe68fea12 Mon Sep 17 00:00:00 2001 From: ccli8 Date: Mon, 21 May 2018 17:39:09 +0800 Subject: [PATCH 2/4] Fix start_new_application compile error on Cortex-M23 With "mov r2, #0", compile OK with GCC_ARM, but failed with ARMC6. With "ldr r2, =0", compile OK with ARMC6, but failed with GCC_ARM. Finally, with "movw r2, #0"/"movt r2, #0", compile OK with both ARMC6 and GCC_ARM. --- platform/mbed_application.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/platform/mbed_application.c b/platform/mbed_application.c index dd0b6a6157..5daed4e6f4 100644 --- a/platform/mbed_application.c +++ b/platform/mbed_application.c @@ -117,20 +117,13 @@ __asm static void start_new_application(void *sp, void *pc) void start_new_application(void *sp, void *pc) { + __asm volatile ( #if defined(__CORTEX_M23) - __asm volatile ( - "ldr r2, =0 \n" - "msr control, r2 \n" // Switch to main stack - "mov sp, %0 \n" - "msr primask, r2 \n" // Enable interrupts - "bx %1 \n" - : - : "l" (sp), "l" (pc) - : "r2", "cc", "memory" - ); + "movw r2, #0 \n" + "movt r2, #0 \n" #else - __asm volatile ( "mov r2, #0 \n" +#endif "msr control, r2 \n" // Switch to main stack "mov sp, %0 \n" "msr primask, r2 \n" // Enable interrupts @@ -139,7 +132,6 @@ void start_new_application(void *sp, void *pc) : "l" (sp), "l" (pc) : "r2", "cc", "memory" ); -#endif } #else From 3c14cb633222cbc42fc9c1ea257da49db3a73d15 Mon Sep 17 00:00:00 2001 From: ccli8 Date: Mon, 28 May 2018 11:43:27 +0800 Subject: [PATCH 3/4] Fix mbed_start_application on Cortex-M23 1. M23 doesn't support ICTR and supports up to 240 external interrupts. 2. Fix reset of SHPR 3. Fix inline assembly compile error with ARMC6 --- platform/mbed_application.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/platform/mbed_application.c b/platform/mbed_application.c index 5daed4e6f4..012f04a064 100644 --- a/platform/mbed_application.c +++ b/platform/mbed_application.c @@ -49,7 +49,8 @@ static void powerdown_nvic() int j; #if defined(__CORTEX_M23) - isr_groups_32 = 16; + // M23 doesn't support ICTR and supports up to 240 external interrupts. + isr_groups_32 = 8; #else isr_groups_32 = ((SCnSCB->ICTR & SCnSCB_ICTR_INTLINESNUM_Msk) >> SCnSCB_ICTR_INTLINESNUM_Pos) + 1; #endif @@ -76,13 +77,19 @@ static void powerdown_scb(uint32_t vtor) SCB->AIRCR = 0x05FA | 0x0000; SCB->SCR = 0x00000000; // SCB->CCR - Implementation defined value +#if defined(__CORTEX_M23) + for (i = 0; i < 2; i++) { + SCB->SHPR[i] = 0x00; + } +#else for (i = 0; i < 12; i++) { -#if defined(__CORTEX_M7) || defined(__CORTEX_M23) +#if defined(__CORTEX_M7) SCB->SHPR[i] = 0x00; #else SCB->SHP[i] = 0x00; #endif } +#endif SCB->SHCSR = 0x00000000; #if defined(__CORTEX_M23) #else @@ -118,12 +125,8 @@ __asm static void start_new_application(void *sp, void *pc) void start_new_application(void *sp, void *pc) { __asm volatile ( -#if defined(__CORTEX_M23) - "movw r2, #0 \n" + "movw r2, #0 \n" // Fail to compile "mov r2, #0" with ARMC6. Replace with movw/movt. "movt r2, #0 \n" -#else - "mov r2, #0 \n" -#endif "msr control, r2 \n" // Switch to main stack "mov sp, %0 \n" "msr primask, r2 \n" // Enable interrupts From 23dcd82fabcb81a40078fc904d604d63997aca6c Mon Sep 17 00:00:00 2001 From: ccli8 Date: Wed, 30 May 2018 09:39:07 +0800 Subject: [PATCH 4/4] Remove superfluous MOVT in mbed_start_application/start_new_application --- platform/mbed_application.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/platform/mbed_application.c b/platform/mbed_application.c index 012f04a064..768e9c62df 100644 --- a/platform/mbed_application.c +++ b/platform/mbed_application.c @@ -125,8 +125,9 @@ __asm static void start_new_application(void *sp, void *pc) void start_new_application(void *sp, void *pc) { __asm volatile ( - "movw r2, #0 \n" // Fail to compile "mov r2, #0" with ARMC6. Replace with movw/movt. - "movt r2, #0 \n" + "movw r2, #0 \n" // Fail to compile "mov r2, #0" with ARMC6. Replace with MOVW. + // We needn't "movt r2, #0" immediately following because MOVW + // will zero-extend the 16-bit immediate. "msr control, r2 \n" // Switch to main stack "mov sp, %0 \n" "msr primask, r2 \n" // Enable interrupts