Skip to content

Commit c518a61

Browse files
authored
Merge pull request #2582 from toyowata/master
[GCC_CR] fix runtime hang for baremetal build
2 parents e39932c + 270780c commit c518a61

File tree

6 files changed

+38
-38
lines changed

6 files changed

+38
-38
lines changed

hal/targets/cmsis/TARGET_NXP/TARGET_LPC11U6X/TOOLCHAIN_GCC_CR/TARGET_LPC11U68/startup_LPC11U68.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ AFTER_VECTORS void bss_init(unsigned int start, unsigned int len) {
137137

138138

139139
/* Reset entry point*/
140-
extern "C" void software_init_hook(void) __attribute__((weak));
140+
extern "C" void software_init_hook(void);
141+
extern "C" void pre_main(void) __attribute__((weak));
141142

142143
AFTER_VECTORS void ResetISR(void) {
143144
unsigned int LoadAddr, ExeAddr, SectionLen;
@@ -169,9 +170,10 @@ AFTER_VECTORS void ResetISR(void) {
169170

170171

171172
SystemInit();
172-
if (software_init_hook)
173-
software_init_hook();
174-
else {
173+
if (pre_main) { // give control to the RTOS
174+
software_init_hook(); // this will also call __libc_init_array
175+
}
176+
else { // for BareMetal (non-RTOS) build
175177
__libc_init_array();
176178
main();
177179
}

hal/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX/TOOLCHAIN_GCC_CR/startup_LPC11xx.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ extern unsigned int __data_section_table;
113113
extern unsigned int __data_section_table_end;
114114
extern unsigned int __bss_section_table_end;
115115

116-
extern "C" void software_init_hook(void) __attribute__((weak));
116+
extern "C" void software_init_hook(void);
117+
extern "C" void pre_main(void) __attribute__((weak));
117118

118119
AFTER_VECTORS void ResetISR(void) {
119120
unsigned int LoadAddr, ExeAddr, SectionLen;
@@ -136,9 +137,10 @@ AFTER_VECTORS void ResetISR(void) {
136137
}
137138

138139
SystemInit();
139-
if (software_init_hook) // give control to the RTOS
140+
if (pre_main) { // give control to the RTOS
140141
software_init_hook(); // this will also call __libc_init_array
141-
else {
142+
}
143+
else { // for BareMetal (non-RTOS) build
142144
__libc_init_array();
143145
main();
144146
}

hal/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/TOOLCHAIN_GCC_CR/TARGET_LPC11XX/startup_LPC11xx.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ extern unsigned int __data_section_table;
113113
extern unsigned int __data_section_table_end;
114114
extern unsigned int __bss_section_table_end;
115115

116-
extern "C" void software_init_hook(void) __attribute__((weak));
116+
extern "C" void software_init_hook(void);
117+
extern "C" void pre_main(void) __attribute__((weak));
117118

118119
AFTER_VECTORS void ResetISR(void) {
119120
unsigned int LoadAddr, ExeAddr, SectionLen;
@@ -136,9 +137,10 @@ AFTER_VECTORS void ResetISR(void) {
136137
}
137138

138139
SystemInit();
139-
if (software_init_hook) // give control to the RTOS
140+
if (pre_main) { // give control to the RTOS
140141
software_init_hook(); // this will also call __libc_init_array
141-
else {
142+
}
143+
else { // for BareMetal (non-RTOS) build
142144
__libc_init_array();
143145
main();
144146
}
@@ -147,7 +149,7 @@ AFTER_VECTORS void ResetISR(void) {
147149

148150
AFTER_VECTORS void NMI_Handler (void) {while(1){}}
149151
AFTER_VECTORS void HardFault_Handler(void) {while(1){}}
150-
AFTER_VECTORS void SVC_Handler (void) {while(1){}}
152+
AFTER_VECTORS void SVC_Handler (void) {while(1){}}
151153
AFTER_VECTORS void PendSV_Handler (void) {while(1){}}
152154
AFTER_VECTORS void SysTick_Handler (void) {while(1){}}
153155
AFTER_VECTORS void IntDefaultHandler(void) {while(1){}}

hal/targets/cmsis/TARGET_NXP/TARGET_LPC15XX/TOOLCHAIN_GCC_CR/startup_LPC15xx.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ AFTER_VECTORS void bss_init(unsigned int start, unsigned int len) {
166166

167167

168168
/* Reset entry point*/
169-
extern "C" void software_init_hook(void) __attribute__((weak));
169+
extern "C" void software_init_hook(void);
170+
extern "C" void pre_main(void) __attribute__((weak));
170171

171172
AFTER_VECTORS void ResetISR(void) {
172173
unsigned int LoadAddr, ExeAddr, SectionLen;
@@ -187,9 +188,10 @@ AFTER_VECTORS void ResetISR(void) {
187188
}
188189

189190
SystemInit();
190-
if (software_init_hook)
191-
software_init_hook();
192-
else {
191+
if (pre_main) { // give control to the RTOS
192+
software_init_hook(); // this will also call __libc_init_array
193+
}
194+
else { // for BareMetal (non-RTOS) build
193195
__libc_init_array();
194196
main();
195197
}

hal/targets/cmsis/TARGET_NXP/TARGET_LPC176X/TOOLCHAIN_GCC_CR/startup_LPC17xx.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ AFTER_VECTORS void bss_init(unsigned int start, unsigned int len) {
130130
for (loop = 0; loop < len; loop = loop + 4) *pulDest++ = 0;
131131
}
132132

133-
extern "C" void software_init_hook(void) __attribute__((weak));
133+
extern "C" void software_init_hook(void);
134+
extern "C" void pre_main(void) __attribute__((weak));
134135

135136
AFTER_VECTORS void ResetISR(void) {
136137
unsigned int LoadAddr, ExeAddr, SectionLen;
@@ -151,9 +152,10 @@ AFTER_VECTORS void ResetISR(void) {
151152
}
152153

153154
SystemInit();
154-
if (software_init_hook) // give control to the RTOS
155+
if (pre_main) { // give control to the RTOS
155156
software_init_hook(); // this will also call __libc_init_array
156-
else {
157+
}
158+
else { // for BareMetal (non-RTOS) build
157159
__libc_init_array();
158160
main();
159161
}

hal/targets/cmsis/TARGET_NXP/TARGET_LPC408X/TOOLCHAIN_GCC_CR/startup_lpc407x_8x.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ extern unsigned int __bss_section_table_end;
260260
// library.
261261
//*****************************************************************************
262262

263-
extern "C" void software_init_hook(void) __attribute__((weak));
263+
extern "C" void software_init_hook(void);
264+
extern "C" void pre_main(void) __attribute__((weak));
264265

265266
__attribute__ ((section(".after_vectors")))
266267
void
@@ -319,26 +320,15 @@ ResetISR(void) {
319320
*pSCB_VTOR = (unsigned int)g_pfnVectors;
320321
}
321322

322-
//#ifdef __USE_CMSIS
323-
SystemInit();
324-
//#endif
325-
if (software_init_hook) // give control to the RTOS
326-
software_init_hook(); // this will also call __libc_init_array
327-
else {
328-
#if defined (__cplusplus)
329-
//
330-
// Call C++ library initialisation
331-
//
332-
__libc_init_array();
333-
#endif
334-
335-
#if defined (__REDLIB__)
336-
// Call the Redlib library, which in turn calls main()
337-
__main() ;
338-
#else
339-
main();
323+
SystemInit();
324+
if (pre_main) { // give control to the RTOS
325+
software_init_hook(); // this will also call __libc_init_array
326+
}
327+
else { // for BareMetal (non-RTOS) build
328+
__libc_init_array();
329+
main();
340330
#endif
341-
}
331+
}
342332
//
343333
// main() shouldn't return, but if it does, we'll just enter an infinite loop
344334
//

0 commit comments

Comments
 (0)