aboutsummaryrefslogtreecommitdiff
path: root/apps/cpp1
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2016-01-04 23:53:44 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2016-01-04 23:53:44 +0100
commitec96951943921b57ef9c1e9dacb63e34716fe5b7 (patch)
treec85d1c0a063712459ad12144900eb522b39ef7a0 /apps/cpp1
parentbaedda497d16c5096971eee83a0c467fe663fe6d (diff)
downloadstm32f103-playground-ec96951943921b57ef9c1e9dacb63e34716fe5b7.tar.gz
stm32f103-playground-ec96951943921b57ef9c1e9dacb63e34716fe5b7.tar.bz2
stm32f103-playground-ec96951943921b57ef9c1e9dacb63e34716fe5b7.tar.xz
stm32f103-playground-ec96951943921b57ef9c1e9dacb63e34716fe5b7.zip
o Actually working implementation of context switching.
It is important to remember to update the stack to the task descriptor on every switch!
Diffstat (limited to 'apps/cpp1')
-rw-r--r--apps/cpp1/CMakeLists.txt19
-rw-r--r--apps/cpp1/cpp1.cpp88
2 files changed, 107 insertions, 0 deletions
diff --git a/apps/cpp1/CMakeLists.txt b/apps/cpp1/CMakeLists.txt
new file mode 100644
index 0000000..2580535
--- /dev/null
+++ b/apps/cpp1/CMakeLists.txt
@@ -0,0 +1,19 @@
+add_executable(cpp1.elf cpp1.cpp
+ ${STM32F10X_STDPERIPH_LIB}/Libraries/CMSIS/CM3/CoreSupport/core_cm3.c
+ ${STM32F10X_STDPERIPH_LIB}/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c
+ ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/misc.c
+ ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_rcc.c
+ ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_spi.c
+ ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_gpio.c
+ ${STM32F10X_STDPERIPH_LIB}/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dma.c
+ $<TARGET_OBJECTS:playground>
+ )
+
+target_include_directories(cpp1.elf PUBLIC
+ $<TARGET_PROPERTY:playground,INTERFACE_INCLUDE_DIRECTORIES>
+ )
+target_compile_definitions(cpp1.elf PUBLIC ${STM32F10X_STDPERIPH_DEFINES})
+target_link_libraries(cpp1.elf tinyprintf)
+
+set_target_properties(cpp1.elf PROPERTIES LINK_FLAGS "-nostartfiles -T${CMAKE_SOURCE_DIR}/cmake/stm32.ld")
+add_extra_commands(cpp1.elf)
diff --git a/apps/cpp1/cpp1.cpp b/apps/cpp1/cpp1.cpp
new file mode 100644
index 0000000..5cea157
--- /dev/null
+++ b/apps/cpp1/cpp1.cpp
@@ -0,0 +1,88 @@
+#include <stdint.h>
+#include <stm32f10x.h>
+
+#include "debug.h"
+#include "tinyprintf.h"
+#include "playground.h"
+
+extern "C"
+__attribute__((naked, used))
+void HardFault_Handler_C(uint32_t *hardfault_args) {
+ dbg_printf("r0 = 0x%08lx (%lu)\n", hardfault_args[0], hardfault_args[0]);
+ dbg_printf("r1 = 0x%08lx (%lu)\n", hardfault_args[1], hardfault_args[1]);
+ dbg_printf("r2 = 0x%08lx (%lu)\n", hardfault_args[2], hardfault_args[2]);
+ dbg_printf("r3 = 0x%08lx (%lu)\n", hardfault_args[3], hardfault_args[3]);
+ dbg_printf("r12 = 0x%08lx (%lu)\n", hardfault_args[4], hardfault_args[4]);
+ dbg_printf("lr = 0x%08lx (%lu)\n", hardfault_args[5], hardfault_args[5]);
+ dbg_printf("pc = 0x%08lx (%lu)\n", hardfault_args[6], hardfault_args[6]);
+ dbg_printf("psr = 0x%08lx (%lu)\n", hardfault_args[7], hardfault_args[7]);
+ dbg_printf("\n");
+
+ halt();
+}
+
+volatile bool run = true;
+
+class StaticMyClass {
+public:
+ StaticMyClass(int value) : value(value) {
+ dbg_printf("StaticMyClass::StaticMyClass(%d)\n", value);
+ }
+
+ // Destructors are not supported for classes that are globally allocated.
+// ~StaticMyClass() {
+// }
+
+ int value;
+};
+
+class ConstStaticMyClass {
+public:
+ ConstStaticMyClass(int value) : value(value) {
+ dbg_printf("ConstStaticMyClass::ConstStaticMyClass(%d)\n", value);
+ }
+
+ int value;
+};
+
+class MyClass {
+public:
+ MyClass(int value) : value(value) {
+ dbg_printf("MyClass::MyClass(%d)\n", value);
+ }
+
+ ~MyClass() {
+ dbg_printf("MyClass::~MyClass\n");
+ }
+
+ int value;
+};
+
+StaticMyClass staticInstance(1337);
+static const ConstStaticMyClass constStaticInstance(9876);
+
+/*
+ * When we get there the stack pointer is set
+ */
+int main() {
+ SystemInit();
+
+ init_printf(nullptr, dbg_putc);
+
+ dbg_printf("C++ Test #1\n");
+
+ dbg_printf("staticInstance.value=%d\n", staticInstance.value);
+ dbg_printf("constStaticInstance.value=%d\n", constStaticInstance.value);
+
+ {
+ MyClass instance2(1234);
+ dbg_printf("instance2.value=%d\n", instance2.value);
+ }
+
+ dbg_printf("Sleeping..\n");
+ while (run) {
+ __NOP();
+ }
+
+ return 0;
+}