Skip to content

Commit 5f38878

Browse files
authored
Merge pull request #9791 from sarahmarshy/m0-start-app
Support mbed_start_application for Cortex-M0+
2 parents 92385a1 + 3b98ebc commit 5f38878

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

platform/mbed_application.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,19 @@ void mbed_start_application(uintptr_t address)
8989

9090
static void powerdown_nvic()
9191
{
92-
int isr_groups_32;
9392
int i;
9493
int j;
94+
int isr_groups_32;
9595

9696
#if defined(__CORTEX_M23)
9797
// M23 doesn't support ICTR and supports up to 240 external interrupts.
9898
isr_groups_32 = 8;
99+
#elif defined(__CORTEX_M0PLUS)
100+
isr_groups_32 = 1;
99101
#else
100102
isr_groups_32 = ((SCnSCB->ICTR & SCnSCB_ICTR_INTLINESNUM_Msk) >> SCnSCB_ICTR_INTLINESNUM_Pos) + 1;
101103
#endif
104+
102105
for (i = 0; i < isr_groups_32; i++) {
103106
NVIC->ICER[i] = 0xFFFFFFFF;
104107
NVIC->ICPR[i] = 0xFFFFFFFF;
@@ -122,21 +125,21 @@ static void powerdown_scb(uint32_t vtor)
122125
SCB->AIRCR = 0x05FA | 0x0000;
123126
SCB->SCR = 0x00000000;
124127
// SCB->CCR - Implementation defined value
125-
#if defined(__CORTEX_M23)
126-
for (i = 0; i < 2; i++) {
127-
SCB->SHPR[i] = 0x00;
128-
}
128+
int num_pri_reg; // Number of priority registers
129+
#if defined(__CORTEX_M0PLUS) || defined(__CORTEX_M23)
130+
num_pri_reg = 2;
129131
#else
130-
for (i = 0; i < 12; i++) {
131-
#if defined(__CORTEX_M7)
132+
num_pri_reg = 12;
133+
#endif
134+
for (i = 0; i < num_pri_reg; i++) {
135+
#if defined(__CORTEX_M7) || defined(__CORTEX_M23)
132136
SCB->SHPR[i] = 0x00;
133137
#else
134138
SCB->SHP[i] = 0x00;
135139
#endif
136140
}
137-
#endif
138141
SCB->SHCSR = 0x00000000;
139-
#if defined(__CORTEX_M23)
142+
#if defined(__CORTEX_M23) || defined(__CORTEX_M0PLUS)
140143
#else
141144
SCB->CFSR = 0xFFFFFFFF;
142145
SCB->HFSR = SCB_HFSR_DEBUGEVT_Msk | SCB_HFSR_FORCED_Msk | SCB_HFSR_VECTTBL_Msk;
@@ -158,7 +161,7 @@ static void powerdown_scb(uint32_t vtor)
158161

159162
__asm static void start_new_application(void *sp, void *pc)
160163
{
161-
MOV R2, #0
164+
MOVS R2, #0
162165
MSR CONTROL, R2 // Switch to main stack
163166
MOV SP, R0
164167
MSR PRIMASK, R2 // Enable interrupts
@@ -170,9 +173,7 @@ __asm static void start_new_application(void *sp, void *pc)
170173
void start_new_application(void *sp, void *pc)
171174
{
172175
__asm volatile(
173-
"movw r2, #0 \n" // Fail to compile "mov r2, #0" with ARMC6. Replace with MOVW.
174-
// We needn't "movt r2, #0" immediately following because MOVW
175-
// will zero-extend the 16-bit immediate.
176+
"movs r2, #0 \n"
176177
"msr control, r2 \n" // Switch to main stack
177178
"mov sp, %0 \n"
178179
"msr primask, r2 \n" // Enable interrupts

platform/mbed_application.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include<stdint.h>
2222

23-
#if defined(__CORTEX_M3) || defined(__CORTEX_M4) || defined(__CORTEX_M7)\
23+
#if defined(__CORTEX_M0PLUS) || defined(__CORTEX_M3) || defined(__CORTEX_M4) || defined(__CORTEX_M7)\
2424
|| defined(__CORTEX_M23) || defined(__CORTEX_A9)
2525
#define MBED_APPLICATION_SUPPORT 1
2626
#else

0 commit comments

Comments
 (0)