Skip to content

Commit 1d6a69b

Browse files
committed
Update MSP setup
Use asm code to set MSP
1 parent 22b183a commit 1d6a69b

File tree

4 files changed

+101
-14
lines changed

4 files changed

+101
-14
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
;
2+
; Copyright (c) 2017 Realtek Semiconductor Corp.
3+
;
4+
; Licensed under the Apache License, Version 2.0 (the "License");
5+
; you may not use this file except in compliance with the License.
6+
; You may obtain a copy of the License at
7+
;
8+
; http://www.apache.org/licenses/LICENSE-2.0
9+
;
10+
; Unless required by applicable law or agreed to in writing, software
11+
; distributed under the License is distributed on an "AS IS" BASIS,
12+
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
; See the License for the specific language governing permissions and
14+
; limitations under the License.
15+
16+
PRESERVE8
17+
THUMB
18+
19+
AREA |i.PLAT_Start|, CODE, READONLY
20+
21+
PLAT_Start PROC
22+
23+
EXPORT PLAT_Start
24+
IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit|
25+
IMPORT PLAT_Init
26+
LDR SP, =|Image$$ARM_LIB_STACK$$ZI$$Limit|
27+
LDR R0, =PLAT_Init
28+
BX R0
29+
ENDP
30+
ALIGN
31+
END
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2017 Realtek Semiconductor Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
.syntax unified
18+
.thumb
19+
20+
.global __StackTop
21+
.global PLAT_Init
22+
23+
/* entry point of application image */
24+
.section .text.PLAT_Start
25+
.weak PLAT_Start
26+
.type PLAT_Start, %function
27+
PLAT_Start:
28+
ldr sp, =__StackTop
29+
ldr r0, =PLAT_Init
30+
bx r0
31+
.size PLAT_Start, .-PLAT_Start
32+
.end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
;
2+
; Copyright (c) 2017 Realtek Semiconductor Corp.
3+
;
4+
; Licensed under the Apache License, Version 2.0 (the "License");
5+
; you may not use this file except in compliance with the License.
6+
; You may obtain a copy of the License at
7+
;
8+
; http://www.apache.org/licenses/LICENSE-2.0
9+
;
10+
; Unless required by applicable law or agreed to in writing, software
11+
; distributed under the License is distributed on an "AS IS" BASIS,
12+
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
; See the License for the specific language governing permissions and
14+
; limitations under the License.
15+
16+
MODULE ?cstartup
17+
18+
SECTION .text:CODE:NOROOT:REORDER(2)
19+
EXTERN CSTACK$$Limit
20+
EXTERN PLAT_Init
21+
22+
; Default image 2 entry
23+
THUMB
24+
PUBWEAK PLAT_Start
25+
26+
PLAT_Start
27+
LDR SP, =CSTACK$$Limit
28+
LDR R0, =PLAT_Init
29+
BX R0
30+
31+
END

targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/rtl8195a_init.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#if defined(__CC_ARM) || \
2828
(defined (__ARMCC_VERSION) && __ARMCC_VERSION >= 6010050)
2929

30-
extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Limit;
3130
extern uint8_t Image$$RW_IRAM2$$ZI$$Base[];
3231
extern uint8_t Image$$RW_IRAM2$$ZI$$Limit[];
3332
extern uint8_t Image$$TCM_OVERLAY$$ZI$$Base[];
@@ -40,7 +39,6 @@ extern uint8_t Image$$RW_DRAM2$$ZI$$Limit[];
4039
#define __bss_dtcm_end__ Image$$TCM_OVERLAY$$ZI$$Limit
4140
#define __bss_dram_start__ Image$$RW_DRAM2$$ZI$$Base
4241
#define __bss_dram_end__ Image$$RW_DRAM2$$ZI$$Limit
43-
#define __stackp Image$$ARM_LIB_STACK$$ZI$$Limit
4442

4543
#elif defined (__ICCARM__)
4644

@@ -55,7 +53,6 @@ void __iar_data_init_app(void)
5553
__bss_start__ = (uint8_t *)__section_begin(".ram.bss");
5654
__bss_end__ = (uint8_t *)__section_end(".ram.bss");
5755
}
58-
#define __stackp CSTACK$$Limit
5956

6057
#else
6158

@@ -68,12 +65,12 @@ extern uint8_t __bss_dtcm_end__[];
6865
extern uint8_t __bss_dram_start__[];
6966
extern uint8_t __bss_dram_end__[];
7067

71-
#define __stackp __StackTop
7268
#endif
7369

7470
extern VECTOR_Func NewVectorTable[];
7571
extern void SystemCoreClockUpdate(void);
7672
extern void PLAT_Start(void);
73+
extern void PLAT_Init(void);
7774
extern void PLAT_Main(void);
7875

7976
IMAGE2_START_RAM_FUN_SECTION
@@ -173,30 +170,26 @@ void TRAP_HardFaultHandler_Patch(void)
173170

174171
extern _LONG_CALL_ void * __rtl_memset_v1_00(void * m , int c , size_t n);
175172
// Image2 Entry Function
176-
void PLAT_Start(void)
173+
void PLAT_Init(void)
177174
{
178175
uint32_t val;
179176

180-
#if defined (__ICCARM__)
181-
__iar_data_init_app();
177+
// Overwrite vector table
178+
NewVectorTable[2] = (VECTOR_Func) TRAP_NMIHandler;
179+
#if defined ( __ICCARM__ )
180+
NewVectorTable[3] = (VECTOR_Func) TRAP_HardFaultHandler_Patch;
182181
#endif
183182

184183
// Clear RAM BSS
185184
#if defined (__ICCARM__)
185+
__iar_data_init_app();
186186
__rtl_memset_v1_00((void *)__bss_start__, 0, __bss_end__ - __bss_start__);
187187
#else
188188
__rtl_memset_v1_00((void *)__bss_sram_start__, 0, __bss_sram_end__ - __bss_sram_start__);
189189
__rtl_memset_v1_00((void *)__bss_dtcm_start__, 0, __bss_dtcm_end__ - __bss_dtcm_start__);
190190
__rtl_memset_v1_00((void *)__bss_dram_start__, 0, __bss_dram_end__ - __bss_dram_start__);
191191
#endif
192192

193-
// Set MSP
194-
__set_MSP((uint32_t)&__stackp - 0x100);
195-
// Overwrite vector table
196-
NewVectorTable[2] = (VECTOR_Func) TRAP_NMIHandler;
197-
#if defined ( __ICCARM__ )
198-
NewVectorTable[3] = (VECTOR_Func) TRAP_HardFaultHandler_Patch;
199-
#endif
200193

201194
extern HAL_TIMER_OP_EXT HalTimerOpExt;
202195
__rtl_memset_v1_00((void *)&HalTimerOpExt, 0, sizeof(HalTimerOpExt));

0 commit comments

Comments
 (0)