Skip to content

Commit 7201cab

Browse files
committed
Support mbed_start_application for Cortex-M0+
1 parent f61dee1 commit 7201cab

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

platform/mbed_application.c

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

9090
static void powerdown_nvic()
9191
{
92-
int isr_groups_32;
9392
int i;
93+
#if defined(__CORTEX_M0PLUS)
94+
NVIC->ICER[0] = 0xFFFFFFFF;
95+
NVIC->ICPR[0] = 0xFFFFFFFF;
96+
for (i = 0; i < 8; i++) {
97+
NVIC->IP[i] = 0x00000000;
98+
}
99+
#else
94100
int j;
95-
101+
int isr_groups_32;
96102
#if defined(__CORTEX_M23)
97103
// M23 doesn't support ICTR and supports up to 240 external interrupts.
98104
isr_groups_32 = 8;
@@ -110,6 +116,7 @@ static void powerdown_nvic()
110116
#endif
111117
}
112118
}
119+
#endif
113120
}
114121

115122
static void powerdown_scb(uint32_t vtor)
@@ -122,21 +129,21 @@ static void powerdown_scb(uint32_t vtor)
122129
SCB->AIRCR = 0x05FA | 0x0000;
123130
SCB->SCR = 0x00000000;
124131
// SCB->CCR - Implementation defined value
125-
#if defined(__CORTEX_M23)
126-
for (i = 0; i < 2; i++) {
127-
SCB->SHPR[i] = 0x00;
128-
}
132+
int num_pri_reg; // Number of priority registers
133+
#if defined(__CORTEX_M0PLUS) || defined(__CORTEX_M23)
134+
num_pri_reg = 2;
129135
#else
130-
for (i = 0; i < 12; i++) {
131-
#if defined(__CORTEX_M7)
136+
num_pri_reg = 12;
137+
#endif
138+
for (i = 0; i < num_pri_reg; i++) {
139+
#if defined(__CORTEX_M7) || defined(__CORTEX_M23)
132140
SCB->SHPR[i] = 0x00;
133141
#else
134142
SCB->SHP[i] = 0x00;
135143
#endif
136144
}
137-
#endif
138145
SCB->SHCSR = 0x00000000;
139-
#if defined(__CORTEX_M23)
146+
#if defined(__CORTEX_M23) || defined(__CORTEX_M0PLUS)
140147
#else
141148
SCB->CFSR = 0xFFFFFFFF;
142149
SCB->HFSR = SCB_HFSR_DEBUGEVT_Msk | SCB_HFSR_FORCED_Msk | SCB_HFSR_VECTTBL_Msk;
@@ -170,7 +177,11 @@ __asm static void start_new_application(void *sp, void *pc)
170177
void start_new_application(void *sp, void *pc)
171178
{
172179
__asm volatile(
173-
"movw r2, #0 \n" // Fail to compile "mov r2, #0" with ARMC6. Replace with MOVW.
180+
#if defined(__CORTEX_M0PLUS)
181+
"mov r2, #0 \n" // No MOVW instruction on Cortex-M0+
182+
#else
183+
"movw r2, #0 \n" // Fail to compile "mov r2, #0" with ARMC6. Replace with MOVW.
184+
#endif
174185
// We needn't "movt r2, #0" immediately following because MOVW
175186
// will zero-extend the 16-bit immediate.
176187
"msr control, r2 \n" // Switch to main stack

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)