Skip to content
Snippets Groups Projects
Commit b6e716dd authored by q3k's avatar q3k Committed by Serge Bazanski
Browse files

l0dables/lib: implement stdout and heap via newlib

parent af3a2196
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,9 @@
* initialization before main() gets called.
*/
#include <stddef.h>
#include "epicardium.h"
#include "max32665.h"
#include "mxc_sys.h"
#include "gcr_regs.h"
......@@ -72,3 +75,38 @@ __weak void SystemInit() {
SystemCoreClockUpdate();
}
// newlib syscall to allow printf to work.
long _write(int fd, const char *buf, size_t cnt)
{
/*
* Only print one line at a time. Insert `\r` between lines so
* they are properly displayed on the serial console.
*/
size_t i, last = 0;
for (i = 0; i < cnt; i++) {
if (buf[i] == '\n') {
epic_uart_write_str(&buf[last], i - last);
epic_uart_write_str("\r", 1);
last = i;
}
}
if (last != i) {
epic_uart_write_str(&buf[last], cnt - last);
}
return cnt;
}
// newlib syscall to allow for a heap
extern uint32_t __heap_start;
uint32_t _sbrk(int incr)
{
static char *brk = NULL;
if (brk == NULL) {
brk = (char *)&__heap_start;
}
char *prev_brk = brk;
brk += incr;
return (uint32_t)prev_brk;
}
......@@ -71,6 +71,9 @@ SECTIONS {
*(COMMON)
} :data
/* Used by hardware.c as start of heap. */
__heap_start = .;
/* Limit based on current limitations of l0dable setup - only uses core1 RAM. */
ASSERT(. < 0x40000, "Exceeded available RAM")
......
......@@ -2,7 +2,7 @@ l0dable_startup_lib = static_library(
'l0dable-startup',
'crt.s',
'hardware.c',
dependencies: periphdriver,
dependencies: [periphdriver, api_caller],
pic: true,
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment