summaryrefslogtreecommitdiffstatshomepage
path: root/stm/malloc0.c
diff options
context:
space:
mode:
authorDamien <damien.p.george@gmail.com>2013-10-13 00:42:20 +0100
committerDamien <damien.p.george@gmail.com>2013-10-13 00:42:20 +0100
commited65605edc5c1376947a34723b9c750400b5a028 (patch)
treed0317e867c4286ec7c889fc9ed18591a1d9990dd /stm/malloc0.c
parent3ef4abb446dfcbdbc426a0921a33e0883607e677 (diff)
downloadmicropython-ed65605edc5c1376947a34723b9c750400b5a028.tar.gz
micropython-ed65605edc5c1376947a34723b9c750400b5a028.zip
Inital commit of stm32f4xx framework.
Diffstat (limited to 'stm/malloc0.c')
-rw-r--r--stm/malloc0.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/stm/malloc0.c b/stm/malloc0.c
new file mode 100644
index 0000000000..55c1ae8044
--- /dev/null
+++ b/stm/malloc0.c
@@ -0,0 +1,38 @@
+#include <stdint.h>
+#include "std.h"
+
+static uint32_t mem = 0;
+
+void *malloc(size_t n) {
+ if (mem == 0) {
+ mem = 0x20008000; // need to use big ram block so we can execute code from it; start up a bit in case that's where bss is...?
+ }
+ void *ptr = (void*)mem;
+ mem = (mem + n + 3) & (~3);
+ if (mem > 0x20000000 + 0x18000) {
+ void __fatal_error(const char*);
+ __fatal_error("out of memory");
+ }
+ return ptr;
+}
+
+void free(void *ptr) {
+}
+
+void *calloc(size_t sz, size_t n) {
+ char *ptr = malloc(sz * n);
+ for (int i = 0; i < sz * n; i++) {
+ ptr[i] = 0;
+ }
+ return ptr;
+}
+
+void *realloc(void *ptr, size_t n) {
+ return malloc(n);
+}
+
+void __assert_func() {
+ printf("\nASSERT FAIL!");
+ for (;;) {
+ }
+}