aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--init_high.cpp27
-rw-r--r--init_low.s (renamed from init.s)33
-rw-r--r--test1.cpp101
4 files changed, 64 insertions, 99 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8a8ef4d..5bee982 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,7 +6,7 @@ project(teensy-playground C CXX ASM)
#include(cmake/Teensy.cmake)
-add_executable(test1.elf test1.cpp init.s include/stm32f10x_conf.h
+add_executable(test1.elf test1.cpp init_low.s init_high.cpp include/stm32f10x_conf.h
# http://www.sparetimelabs.com/tinyprintf/tinyprintf.php
tmp/printf/printf.h tmp/printf/printf.c
tmp/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/CoreSupport/core_cm3.c
diff --git a/init_high.cpp b/init_high.cpp
new file mode 100644
index 0000000..235a649
--- /dev/null
+++ b/init_high.cpp
@@ -0,0 +1,27 @@
+#include <stdint.h>
+
+extern uint32_t _copy_data_load, _copy_data_store, _copy_data_store_end;
+extern uint32_t _bss_start, _bss_end;
+
+extern int main();
+extern "C" int init_high();
+
+int init_high() {
+ // Copy data from flash to ram
+ uint32_t *src = &_copy_data_load;
+ uint32_t *dest = &_copy_data_store;
+ uint32_t *end = &_copy_data_store_end;
+
+ while (dest <= end) {
+ *dest++ = *src++;
+ }
+
+ // Clear the BSS segment
+ dest = &_bss_start;
+ end = &_bss_end;
+ while (dest <= end) {
+ *dest++ = 0;
+ }
+
+ return main();
+}
diff --git a/init.s b/init_low.s
index 122a6ad..bd7f329 100644
--- a/init.s
+++ b/init_low.s
@@ -18,15 +18,15 @@ stacktop: .word 0x20001000
.word MemManage_Handler
.word BusFault_Handler
.word UsageFault_Handler
-.word hang2
-.word hang2
-.word hang2
-.word hang2
-.word hang2
-.word hang2
-.word hang2
-.word hang2
-.word hang2
+.word halt
+.word halt
+.word halt
+.word halt
+.word halt
+.word halt
+.word halt
+.word halt
+.word halt
/* VERY significant */
.section .text
@@ -34,16 +34,17 @@ stacktop: .word 0x20001000
.thumb_func
.global _Reset_Handler
_Reset_Handler:
- bl main
- b hang2
+ bl init_high
+ b halt
.thumb_func
-hang2:
+.global halt
+halt:
b .
.thumb_func
NMI_Handler:
- b hang2
+ b halt
.thumb_func
HardFault_Handler:
@@ -55,14 +56,14 @@ HardFault_Handler:
.thumb_func
MemManage_Handler:
- b hang2
+ b halt
.thumb_func
BusFault_Handler:
- b hang2
+ b halt
.thumb_func
UsageFault_Handler:
- b hang2
+ b halt
.end
diff --git a/test1.cpp b/test1.cpp
index 89e859f..57149c3 100644
--- a/test1.cpp
+++ b/test1.cpp
@@ -5,15 +5,15 @@
#include <stm32f10x_gpio.h>
#include <stddef.h>
+int init_high();
+
+extern "C" void halt();
+
#include "tmp/printf/printf.h"
#include "stm32f10x_conf.h"
extern "C"
-//__attribute__((naked))
-int main(void);
-
-extern "C"
__attribute__((naked))
void HardFault_Handler_C(uint32_t *hardfault_args);
@@ -46,8 +46,7 @@ void HardFault_Handler_C(uint32_t *hardfault_args) {
hardfault_data->pc = hardfault_args[6];
hardfault_data->psr = hardfault_args[7];
- do {
- } while (1);
+ halt();
}
void send_command(int command, void *message) {
@@ -64,77 +63,21 @@ void send_command(int command, void *message) {
);
}
-//static
-const char *alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n";
-
-extern uint32_t _copy_data_load, _copy_data_store, _copy_data_store_end;
-extern uint32_t _bss_start, _bss_end;
-
size_t strlen(const char *s) {
size_t size = 0;
while (*s++ != '\0') size++;
return size;
}
-void test_command() {
- char msg[100];
-
- tfp_sprintf(msg, "Hello World: c=%c\r\n", 'c');
- size_t len = strlen(msg);
-
- uint32_t message[] = {
- 2,
- (uint32_t) msg,
- len
- };
- send_command(0x05, &message);
-
- tfp_sprintf(msg, "Hello %s\r\n", "World!");
- len = strlen(msg);
-
- uint32_t message3[] = {
- 2,
- (uint32_t) msg,
- len
- };
-
- uint32_t message2[] = {
- 2,
- (uint32_t) alphabet,
- 28
- };
- send_command(0x05, &message2);
-
- send_command(0x05, &message3);
-
- send_command(0x05, &message2);
-}
+int run = 1;
/*
* When we get there the stack pointer is set
*/
int main() {
- // Copy data from flash to ram
- uint32_t *src = &_copy_data_load;
- uint32_t *dest = &_copy_data_store;
- uint32_t *end = &_copy_data_store_end;
-
- while (dest <= end) {
- *dest++ = *src++;
- }
-
- // Clear the BSS segment
- dest = &_bss_start;
- end = &_bss_end;
- while (dest <= end) {
- *dest++ = 0;
- }
-
- test_command();
-
SystemInit();
- SystemCoreClockUpdate();
-// RCC->APB2ENR = RCC_APB2ENR_IOPCEN;
+// SystemCoreClockUpdate();
+
SCB->SHCSR |= SCB_SHCSR_USGFAULTENA_Msk | SCB_SHCSR_MEMFAULTPENDED_Msk | SCB_SHCSR_BUSFAULTENA_Msk;
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, ENABLE);
@@ -146,25 +89,19 @@ int main() {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOA,
ENABLE);
- if (1) {
- GPIO_InitTypeDef init;
- GPIO_StructInit(&init);
- init.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOB, &init);
-
- while (1) {
- GPIO_SetBits(GPIOA, GPIO_Pin_All);
- GPIO_SetBits(GPIOB, GPIO_Pin_All);
- GPIO_SetBits(GPIOC, GPIO_Pin_All);
-
-// send_command(0x05, &message);
+ GPIO_InitTypeDef init;
+ GPIO_StructInit(&init);
+ init.GPIO_Mode = GPIO_Mode_Out_PP;
+ GPIO_Init(GPIOB, &init);
- GPIO_ResetBits(GPIOA, GPIO_Pin_All);
- GPIO_ResetBits(GPIOB, GPIO_Pin_All);
- GPIO_ResetBits(GPIOC, GPIO_Pin_All);
+ while (run) {
+// GPIO_SetBits(GPIOA, GPIO_Pin_All);
+ GPIO_SetBits(GPIOB, GPIO_Pin_All);
+// GPIO_SetBits(GPIOC, GPIO_Pin_All);
-// send_command(0x05, &message);
- }
+// GPIO_ResetBits(GPIOA, GPIO_Pin_All);
+ GPIO_ResetBits(GPIOB, GPIO_Pin_All);
+// GPIO_ResetBits(GPIOC, GPIO_Pin_All);
}
return 0;