M Makefile => Makefile +10 -3
@@ 23,9 23,9 @@ CFLAGS=-I$(INCDIR) \
-I$(DEVICEDIR)/$(INCDIR) \
-Ilibs/CMSIS_6/CMSIS/Core/Include \
-Ilibs/cmsis_device_h7/Include \
- -mthumb -mcpu=$(CPU) -nostdlib -g \
+ -mthumb -mcpu=$(CPU) --specs=nano.specs -g \
-DCORE_CM7
-LDFLAGS=-T$(DEVICEDIR)/linker_script.ld -nostdlib
+LDFLAGS=-T$(DEVICEDIR)/linker_script.ld
CC=arm-none-eabi-gcc
LD=arm-none-eabi-ld
@@ 33,7 33,7 @@ OPENOCD=openocd
$(BINDIR)/$(APP): $(OBJS)
mkdir -p $(BINDIR)
- $(LD) $^ -o $@ $(LDFLAGS)
+ $(CC) $^ -o $@ $(CFLAGS) $(LDFLAGS)
$(OBJDIR)/src/%.o: $(SRCDIR)/%.c
mkdir -p "$(OBJDIR)/src"
@@ 56,3 56,10 @@ flash: $(BINDIR)/$(APP)
clean:
rm -rf $(OBJDIR) $(BINDIR)
+
+depend: .depend
+.depend: $(SRCS)
+ rm -f "$@"
+ $(CC) $(CFLAGS) -MM $^ > "$@"
+
+include .depend
M devices/general/startup.c => devices/general/startup.c +2 -0
@@ 3,6 3,7 @@
extern uint32_t _data_size, _bss_size, _data_loadaddr, _sdata, _sbss;
void main(void);
+void __libc_init_array();
void reset_handler(void)
{
@@ 25,5 26,6 @@ void reset_handler(void)
bss[i] = 0;
}
+ __libc_init_array();
main();
}
M devices/stm32h747/linker_script.ld => devices/stm32h747/linker_script.ld +23 -0
@@ 22,6 22,27 @@ SECTIONS
_etext = .;
} >FLASH
+ .preinit_array :
+ {
+ PROVIDE_HIDDEN (__preinit_array_start = .);
+ KEEP (*(.preinit_array*))
+ PROVIDE_HIDDEN (__preinit_array_end = .);
+ } >FLASH
+ .init_array :
+ {
+ PROVIDE_HIDDEN (__init_array_start = .);
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array*))
+ PROVIDE_HIDDEN (__init_array_end = .);
+ } >FLASH
+ .fini_array :
+ {
+ PROVIDE_HIDDEN (__fini_array_start = .);
+ KEEP (*(SORT(.fini_array.*)))
+ KEEP (*(.fini_array*))
+ PROVIDE_HIDDEN (__fini_array_end = .);
+ } >FLASH
+
.data :
{
. = ALIGN(4);
@@ 40,11 61,13 @@ SECTIONS
{
. = ALIGN(4);
_sbss = .;
+ __bss_start__ = _sbss;
*(.bss)
. = ALIGN(4);
_ebss = .;
+ __bss_end__ = _ebss;
} >SRAM
_bss_size = _ebss - _sbss;
M src/main.c => src/main.c +24 -0
@@ 1,10 1,27 @@
#include <stdint.h>
#include <stm32h747xx.h>
#include <core_cm7.h>
+#include <stdlib.h>
#define LED1_PIN 12
#define LED2_PIN 13
+void hard_fault_handler() {
+ while(1) {}
+}
+
+void usage_fault_handler() {
+ while(1) {}
+}
+
+void nmi_handler() {
+ while(1) {}
+}
+
+void bus_fault_handler() {
+ while(1) {}
+}
+
void led_toggle()
{
GPIOI->ODR ^= (1 << LED1_PIN);
@@ 33,6 50,13 @@ void exti15_10_handler(void)
void main()
{
+ uint32_t *i1 = malloc(sizeof(uint32_t));
+ uint32_t *i2 = malloc(sizeof(uint32_t));
+
+ free(i1);
+
+ uint32_t *i3 = malloc(sizeof(uint32_t));
+
led_gpio_en();
led_input();
led_toggle();
A src/syscalls.c => src/syscalls.c +112 -0
@@ 0,0 1,112 @@
+#include <sys/stat.h>
+#include <sys/times.h>
+#include <errno.h>
+#undef errno
+extern int errno;
+
+void _exit(int exit_code)
+{
+ while (1)
+ {
+
+ }
+}
+
+int _close(int file) {
+ return -1;
+}
+
+char *__env[1] = { 0 };
+char **environ = __env;
+
+int _execve(char *name, char **argv, char **env) {
+ errno = ENOMEM;
+ return -1;
+}
+
+int _fork(void) {
+ errno = EAGAIN;
+ return -1;
+}
+
+
+int _fstat(int file, struct stat *st) {
+ st->st_mode = S_IFCHR;
+ return 0;
+}
+
+int _getpid(void) {
+ return 1;
+}
+
+int _isatty(int file) {
+ return 1;
+}
+
+int _kill(int pid, int sig) {
+ errno = EINVAL;
+ return -1;
+}
+
+int _link(char *old, char *new) {
+ errno = EMLINK;
+ return -1;
+}
+
+int _lseek(int file, int ptr, int dir) {
+ return 0;
+}
+
+int _open(const char *name, int flags, int mode) {
+ return -1;
+}
+
+int _read(int file, char *ptr, int len) {
+ return 0;
+}
+
+register char * stack_ptr asm("sp");
+
+caddr_t _sbrk(int incr) {
+ extern char __bss_end__; /* Defined by the linker */
+ static char *heap_end;
+ char *prev_heap_end;
+
+ if (heap_end == 0) {
+ heap_end = &__bss_end__;
+ }
+ prev_heap_end = heap_end;
+ if (heap_end + incr > stack_ptr) {
+ while (1)
+ {
+ // Heap and stack collision
+ }
+ }
+
+ heap_end += incr;
+ return (caddr_t) prev_heap_end;
+}
+
+int _stat(char *file, struct stat *st) {
+ st->st_mode = S_IFCHR;
+ return 0;
+}
+
+int _times(struct tms *buf) {
+ return -1;
+}
+
+int _unlink(char *name) {
+ errno = ENOENT;
+ return -1;
+}
+
+int _wait(int *status) {
+ errno = ECHILD;
+ return -1;
+}
+
+int _write(int file, char *ptr, int len) {
+ errno = ENOENT;
+ return -1;
+}