Skip to content

Commit 25fb041

Browse files
qwangYafeiJin
authored andcommitted
Add basic C++ support
1 parent e231762 commit 25fb041

File tree

6 files changed

+56
-10
lines changed

6 files changed

+56
-10
lines changed

components/bl602/bl602/evb/ld/flash_rom.ld

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@ SECTIONS
8080
_rom_framework_audio_device_end = .;
8181
} > flash
8282

83+
.preinit_array :
84+
{
85+
. = ALIGN(4);
86+
__preinit_array_start = .;
87+
KEEP (*(.preinit_array))
88+
__preinit_array_end = .;
89+
} > flash
90+
91+
.init_array :
92+
{
93+
. = ALIGN(4);
94+
__init_array_start = .;
95+
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)))
96+
KEEP (*(.init_array))
97+
__init_array_end = .;
98+
} > flash
99+
83100
/*put wifibss in the first place*/
84101
.wifibss (NOLOAD) :
85102
{

components/bl602/bl602/evb/src/boot/gcc/start.S

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,27 @@ bl602_start:
119119
sd ra, 8(sp)
120120
#endif
121121

122+
// call global obj constructors
123+
la s1, __preinit_array_start
124+
la s2, __preinit_array_end
125+
li s3, 4
126+
1:
127+
bgeu s1, s2, 2f
128+
lw a3, (s1)
129+
jalr a3
130+
add s1, s1, s3
131+
j 1b
132+
2:
133+
la s1, __init_array_start
134+
la s2, __init_array_end
135+
li s3, 4
136+
1:
137+
bgeu s1, s2, 2f
138+
lw a3, (s1)
139+
jalr a3
140+
add s1, s1, s3
141+
j 1b
142+
2:
122143
/* argc = argv = 0 */
123144
li a0, 0
124145
li a1, 0

components/hal_drv/bl602.mk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Component Makefile
22
#
33
## These include paths would be exported to project level
4-
COMPONENT_ADD_INCLUDEDIRS += bl602_hal
4+
COMPONENT_ADD_INCLUDEDIRS += bl602_hal platform_hal
55

66
## not be exported to project level
77
COMPONENT_PRIV_INCLUDEDIRS :=
@@ -50,8 +50,10 @@ COMPONENT_SRCS := bl602_hal/bl_uart.c \
5050
bl602_hal/hal_spi.c \
5151
bl602_hal/hal_adc.c \
5252
bl602_hal/hal_wifi.c \
53+
platform_hal/platform_hal_device.cpp \
5354

54-
COMPONENT_SRCDIRS := bl602_hal
55+
56+
COMPONENT_SRCDIRS := bl602_hal platform_hal
5557

5658
COMPONENT_OBJS := $(patsubst %.c,%.o, $(COMPONENT_SRCS))
5759
COMPONENT_OBJS := $(patsubst %.cpp,%.o, $(COMPONENT_OBJS))

components/hal_drv/platform_hal/platform_hal_device.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@
3232

3333
extern "C" void* operator new(size_t size)
3434
{
35-
printf("[C++] new %d\r\n", size);
35+
/* printf("[C++] new %d\r\n", size); */
3636
return pvPortMalloc(size);
3737
}
3838

3939
extern "C" void* operator new[](size_t size)
4040
{
41-
printf("[C++] new[] %d\r\n", size);
41+
/* printf("[C++] new[] %d\r\n", size); */
4242
return pvPortMalloc(size);
4343
}
4444

4545
extern "C" void operator delete(void* ptr) {
46-
printf("[C++] delete %p\r\n", ptr);
46+
/* printf("[C++] delete %p\r\n", ptr); */
4747
vPortFree(ptr);
4848
}
4949

5050
extern "C" void operator delete[](void* ptr) {
51-
printf("[C++] delete[] %p\r\n", ptr);
51+
/* printf("[C++] delete[] %p\r\n", ptr); */
5252
vPortFree(ptr);
5353
}
5454

@@ -242,6 +242,7 @@ extern "C" int platform_hal_device_init(void)
242242
class BLAesRequest *aes_request = new BLAesRequest[6];
243243
aes_engine = new BLAesEngine();
244244

245+
(void)aes_request;
245246
#if 0
246247
aes_engine->encryption(aes_request[0]);
247248
#endif

make_scripts_riscv/component_wrapper.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ $(2)/%.o: $$(COMPONENT_PATH)/$(1)/%.c $(COMMON_MAKEFILES) $(COMPONENT_MAKEFILE)
281281

282282
$(2)/%.o: $$(COMPONENT_PATH)/$(1)/%.cpp $(COMMON_MAKEFILES) $(COMPONENT_MAKEFILE) | $(COMPONENT_OBJDIRS)
283283
$$(summary) CXX $$(patsubst $$(PWD)/%,%,$$(CURDIR))/$$@
284-
$$(CXX) $$(CFLAGS) $$(CXXFLAGS) -D __FILENAME__=\"$$(notdir $$<)\" -D __FILENAME_WO_SUFFIX__=\"$$(subst .c,,$$(notdir $$<))\" -D __FILENAME_WO_SUFFIX_DEQUOTED__=$$(subst .c,,$$(notdir $$<)) -D __COMPONENT_NAME__=\"$$(COMPONENT_NAME)\" -D __COMPONENT_NAME_DEQUOTED__=$$(COMPONENT_NAME) -D __COMPONENT_FILE_NAME__=\"$$(COMPONENT_NAME)$$(subst .c,,$$(notdir $$<))\" -D__COMPONENT_FILE_NAMED__=$$(COMPONENT_NAME).$$(subst .c,,$$(notdir $$<)) -D__COMPONENT_FILE_NAME_DEQUOTED__=$$(COMPONENT_NAME)$$(subst .c,,$$(notdir $$<)) $$(CPPFLAGS) $$(addprefix -I ,$$(COMPONENT_INCLUDES)) $$(addprefix -I ,$$(COMPONENT_EXTRA_INCLUDES)) -I $(1) -c $$(abspath $$<) -o $$@
284+
$$(CXX) $$(CXXFLAGS) $$(CPPFLAGS) -D __FILENAME__=\"$$(notdir $$<)\" -D __FILENAME_WO_SUFFIX__=\"$$(subst .c,,$$(notdir $$<))\" -D __FILENAME_WO_SUFFIX_DEQUOTED__=$$(subst .c,,$$(notdir $$<)) -D __COMPONENT_NAME__=\"$$(COMPONENT_NAME)\" -D __COMPONENT_NAME_DEQUOTED__=$$(COMPONENT_NAME) -D __COMPONENT_FILE_NAME__=\"$$(COMPONENT_NAME)$$(subst .c,,$$(notdir $$<))\" -D__COMPONENT_FILE_NAMED__=$$(COMPONENT_NAME).$$(subst .c,,$$(notdir $$<)) -D__COMPONENT_FILE_NAME_DEQUOTED__=$$(COMPONENT_NAME)$$(subst .c,,$$(notdir $$<)) $$(CPPFLAGS) $$(addprefix -I ,$$(COMPONENT_INCLUDES)) $$(addprefix -I ,$$(COMPONENT_EXTRA_INCLUDES)) -I $(1) -c $$(abspath $$<) -o $$@
285285
$(call AppendSourceToDependencies,$$<,$$@)
286286

287287
$(2)/%.o: $$(COMPONENT_PATH)/$(1)/%.cc $(COMMON_MAKEFILES) $(COMPONENT_MAKEFILE) | $(COMPONENT_OBJDIRS)

make_scripts_riscv/project.mk

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,11 @@ CFLAGS := $(strip \
341341
-save-temps=obj
342342

343343
CXXFLAGS := $(strip \
344-
$(CPPFLAGS) \
345-
$(OPTIMIZATION_FLAGS) \
344+
-std=c++11 \
345+
$(OPTIMIZATION_FLAGS) $(DEBUG_FLAGS) \
346+
$(COMMON_FLAGS) \
347+
$(COMMON_WARNING_FLAGS) \
348+
$(CXXFLAGS) \
346349
$(E21_CPU_CFLAGS) \
347350
-nostdlib \
348351
-g3 \
@@ -357,7 +360,9 @@ CXXFLAGS := $(strip \
357360
-Wswitch-default \
358361
-Wunused \
359362
-Wundef \
360-
-fno-rtti -fno-exceptions)
363+
-fno-rtti -fno-exceptions \
364+
-save-temps=obj \
365+
)
361366

362367
export CFLAGS CPPFLAGS CXXFLAGS ASMFLAGS
363368

0 commit comments

Comments
 (0)