mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
Merge changes Ib331bae9,I9d5000cd,I65ab7310,Ifbe11515,I1edddefd, ...
* changes: Organize the build system [ion/device] Enable powering the LCD controller from a GPIO [liba] Enable malloc/free logging [ion] Fix the C API [ion] Fix the blackbox platform [ion] Add a C bridge for the logging function [ion] Implement Log::print using SWO on the device
This commit is contained in:
17
Makefile
17
Makefile
@@ -1,17 +1,18 @@
|
||||
PLATFORM ?= device
|
||||
DEBUG ?= 1
|
||||
include build/config.mak
|
||||
|
||||
include Makefile.$(PLATFORM)
|
||||
ifndef USE_LIBA
|
||||
$(error Makefile.PLATFORM should define USE_LIBA)
|
||||
$(error platform.mak should define USE_LIBA)
|
||||
endif
|
||||
ifndef EXE
|
||||
$(error Makefile.PLATFORM should define EXE, the extension for executables)
|
||||
$(error platform.mak should define EXE, the extension for executables)
|
||||
endif
|
||||
|
||||
HOSTCC = gcc
|
||||
HOSTCXX = g++
|
||||
|
||||
# Flags - Optimizations
|
||||
SFLAGS += $(OPTIM_SFLAGS)
|
||||
|
||||
# Flags - Header search path
|
||||
SFLAGS += -Ilib -I.
|
||||
|
||||
@@ -21,12 +22,8 @@ SFLAGS += -Wall
|
||||
# Flags - Header dependency tracking
|
||||
SFLAGS += -MD -MP
|
||||
|
||||
# Flags - Optimizations
|
||||
ifeq ($(DEBUG),1)
|
||||
SFLAGS += -ggdb3 -DDEBUG=1 -O0
|
||||
else
|
||||
SFLAGS += -Os -fdata-sections -ffunction-sections
|
||||
LDFLAGS += --gc-sections
|
||||
SFLAGS += -DDEBUG=1
|
||||
endif
|
||||
|
||||
# Language-specific flags
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
CC=clang
|
||||
CXX=clang++
|
||||
LD=clang++
|
||||
SIZE=size
|
||||
|
||||
LDFLAGS =
|
||||
|
||||
USE_LIBA=1
|
||||
@@ -1,28 +0,0 @@
|
||||
TOOLCHAIN=arm-none-eabi
|
||||
# FIXME decide which one to use.
|
||||
#COMPILER=llvm
|
||||
|
||||
ifeq ($(COMPILER),llvm)
|
||||
CC=clang
|
||||
CXX=clang++
|
||||
else
|
||||
CC=$(TOOLCHAIN)-gcc
|
||||
CXX=$(TOOLCHAIN)-g++
|
||||
endif
|
||||
|
||||
LD=$(TOOLCHAIN)-ld.bfd
|
||||
GDB=$(TOOLCHAIN)-gdb
|
||||
OBJCOPY=$(TOOLCHAIN)-objcopy
|
||||
SIZE=$(TOOLCHAIN)-size
|
||||
|
||||
# Flags - Arch
|
||||
ifeq ($(COMPILER),llvm)
|
||||
SFLAGS += -target thumbv7em-unknown-eabi
|
||||
else
|
||||
SFLAGS += -mthumb -march=armv7e-m -mfloat-abi=hard
|
||||
endif
|
||||
SFLAGS += -mcpu=cortex-m4 -mfpu=fpv4-sp-d16
|
||||
|
||||
# Platform configuration
|
||||
USE_LIBA=1
|
||||
EXE=elf
|
||||
@@ -1,9 +0,0 @@
|
||||
CC=emcc
|
||||
CXX=emcc
|
||||
LD=emcc
|
||||
LDFLAGS=-s EXPORTED_FUNCTIONS="['_main', '_IonEmscriptenPushEvent']" -Os --shell-file ion/src/emscripten/shell.html
|
||||
SIZE=size
|
||||
DEBUG=0
|
||||
|
||||
USE_LIBA=0
|
||||
EXE=html
|
||||
@@ -1,7 +0,0 @@
|
||||
CC=clang
|
||||
CXX=clang++
|
||||
LD=clang++
|
||||
SIZE=size
|
||||
|
||||
USE_LIBA=0
|
||||
EXE=elf
|
||||
20
build/config.mak
Normal file
20
build/config.mak
Normal file
@@ -0,0 +1,20 @@
|
||||
# You can edit this file to change build settings
|
||||
|
||||
PLATFORM ?= device
|
||||
VERBOSE ?= 0
|
||||
DEBUG ?= 1
|
||||
LIBA_LOG_DYNAMIC_MEMORY ?= 0
|
||||
ESCHER_LOG_EVENTS ?= 0
|
||||
ION_EVENTS ?= keyboard
|
||||
# Possible values : keyboard, stdin, random, replay
|
||||
|
||||
# Do not edit below this
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
OPTIM_SFLAGS ?= -O0
|
||||
else
|
||||
OPTIM_SFLAGS ?= -Os
|
||||
endif
|
||||
|
||||
include build/platform.$(PLATFORM).mak
|
||||
include build/toolchain.$(TOOLCHAIN).mak
|
||||
3
build/platform.blackbox.mak
Normal file
3
build/platform.blackbox.mak
Normal file
@@ -0,0 +1,3 @@
|
||||
TOOLCHAIN ?= afl
|
||||
USE_LIBA ?= 1
|
||||
EXE = bin
|
||||
7
build/platform.device.mak
Normal file
7
build/platform.device.mak
Normal file
@@ -0,0 +1,7 @@
|
||||
TOOLCHAIN ?= arm-gcc
|
||||
ifeq ($(COMPILER),llvm)
|
||||
# Compatibility with old build system
|
||||
TOOLCHAIN = arm-llvm
|
||||
endif
|
||||
USE_LIBA = 1
|
||||
EXE = elf
|
||||
3
build/platform.emscripten.mak
Normal file
3
build/platform.emscripten.mak
Normal file
@@ -0,0 +1,3 @@
|
||||
TOOLCHAIN = emscripten
|
||||
USE_LIBA = 0
|
||||
EXE = html
|
||||
3
build/platform.simulator.mak
Normal file
3
build/platform.simulator.mak
Normal file
@@ -0,0 +1,3 @@
|
||||
TOOLCHAIN ?= host-clang
|
||||
USE_LIBA = 0
|
||||
EXE = elf
|
||||
3
build/toolchain.afl.mak
Normal file
3
build/toolchain.afl.mak
Normal file
@@ -0,0 +1,3 @@
|
||||
CC = afl-clang
|
||||
CXX = afl-clang++
|
||||
LD = afl-clang++
|
||||
13
build/toolchain.arm-gcc.mak
Normal file
13
build/toolchain.arm-gcc.mak
Normal file
@@ -0,0 +1,13 @@
|
||||
CC = arm-none-eabi-gcc
|
||||
CXX = arm-none-eabi-g++
|
||||
LD = arm-none-eabi-ld.bfd
|
||||
GDB = arm-none-eabi-gdb
|
||||
OBJCOPY = arm-none-eabi-objcopy
|
||||
SIZE = arm-none-eabi-size
|
||||
ifeq ($(DEBUG),1)
|
||||
OPTIM_SFLAGS += -ggdb3
|
||||
else
|
||||
OPTIM_SFLAGS += -fdata-sections -ffunction-sections
|
||||
LDFLAGS = --gc-sections
|
||||
endif
|
||||
SFLAGS = -mthumb -march=armv7e-m -mfloat-abi=hard -mcpu=cortex-m4 -mfpu=fpv4-sp-d16
|
||||
4
build/toolchain.arm-llvm.mak
Normal file
4
build/toolchain.arm-llvm.mak
Normal file
@@ -0,0 +1,4 @@
|
||||
include build/toolchain.arm-gcc.mak
|
||||
CC = clang
|
||||
CXX = clang++
|
||||
SFLAGS = -target thumbv7em-unknown-eabi -mcpu=cortex-m4 -mfpu=fpv4-sp-d16
|
||||
5
build/toolchain.emscripten.mak
Normal file
5
build/toolchain.emscripten.mak
Normal file
@@ -0,0 +1,5 @@
|
||||
CC = emcc
|
||||
CXX = emcc
|
||||
LD = emcc
|
||||
LDFLAGS = -s EXPORTED_FUNCTIONS="['_main', '_IonEmscriptenPushEvent']" -Os --shell-file ion/src/emscripten/shell.html
|
||||
SIZE = size
|
||||
4
build/toolchain.host-clang.mak
Normal file
4
build/toolchain.host-clang.mak
Normal file
@@ -0,0 +1,4 @@
|
||||
CC = clang
|
||||
CXX = clang++
|
||||
LD = clang++
|
||||
GDB = lldb
|
||||
6
build/toolchain.mingw.mak
Normal file
6
build/toolchain.mingw.mak
Normal file
@@ -0,0 +1,6 @@
|
||||
CC = mingw-w64-x86_64-gcc
|
||||
CXX = mingw-w64-x86_64-g++
|
||||
LD = mingw-w64-x86_64-g++
|
||||
SFLAGS = -D_USE_MATH_DEFINES
|
||||
LDFLAGS = -static -mwindows
|
||||
EXE = exe
|
||||
@@ -1,5 +1,9 @@
|
||||
SFLAGS += -Iescher/include
|
||||
|
||||
ifeq ($(ESCHER_LOG_EVENTS),1)
|
||||
SFLAGS += -DESCHER_LOG_EVENTS=1
|
||||
endif
|
||||
|
||||
objs += $(addprefix escher/src/,\
|
||||
alternate_empty_view_controller.o\
|
||||
app.o\
|
||||
|
||||
@@ -8,6 +8,8 @@ set pagination off
|
||||
load
|
||||
|
||||
# Tell OpenOCD to reset and halt
|
||||
monitor itm ports on
|
||||
monitor tpiu config internal swo.log.bin uart off 16000000
|
||||
monitor reset halt
|
||||
|
||||
break init
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
SFLAGS += -Iion/include -DKD_CONFIG_H=1
|
||||
include ion/src/$(PLATFORM)/Makefile
|
||||
|
||||
objs += $(addprefix ion/src/, \
|
||||
c.o \
|
||||
)
|
||||
|
||||
tests += $(addprefix ion/test/,\
|
||||
crc32.cpp\
|
||||
)
|
||||
|
||||
14
ion/include/ion/c.h
Normal file
14
ion/include/ion/c.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef ION_C_H
|
||||
#define ION_C_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void ion_log_print(const char * message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,13 @@
|
||||
objs += $(addprefix ion/src/blackbox/, boot.o ion.o)
|
||||
objs += $(addprefix ion/src/shared/, \
|
||||
crc32.o \
|
||||
events.o \
|
||||
events_from_keyboard.o \
|
||||
log.o \
|
||||
power.o \
|
||||
)
|
||||
|
||||
ion/src/shared/log.o: SFLAGS=-Iion/include
|
||||
#objs += $(addprefix ion/src/simulator/boot/, main.o)
|
||||
#objs += $(addprefix ion/src/simulator/display/, fltklcd.o)
|
||||
#objs += $(addprefix ion/src/simulator/keyboard/, fltkkbd.o)
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#define HEAP_SIZE 65536
|
||||
char heap[HEAP_SIZE];
|
||||
char * _liba_heap_start = &heap[0];
|
||||
char * _liba_heap_end = &heap[HEAP_SIZE];
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
ion_app();
|
||||
/* while (1) {
|
||||
}*/
|
||||
return 0;
|
||||
}
|
||||
16
ion/src/blackbox/boot.cpp
Normal file
16
ion/src/blackbox/boot.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <ion.h>
|
||||
|
||||
constexpr int kHeapSize = 131072;
|
||||
char heap[kHeapSize];
|
||||
extern "C" {
|
||||
char * _heap_start = (char *)heap;
|
||||
char * _heap_end = _heap_start+kHeapSize;
|
||||
int main(int argc, char * argv[]);
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
ion_app();
|
||||
/* while (1) {
|
||||
}*/
|
||||
return 0;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
#include <stdint.h>
|
||||
#include <ion.h>
|
||||
|
||||
void ion_set_pixel(uint16_t x, uint16_t y, uint8_t color) {
|
||||
}
|
||||
|
||||
bool ion_key_down(ion_key_t key) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ion_sleep() {
|
||||
}
|
||||
18
ion/src/blackbox/ion.cpp
Normal file
18
ion/src/blackbox/ion.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <stdint.h>
|
||||
#include <ion.h>
|
||||
|
||||
void Ion::Display::pushRect(KDRect r, const KDColor * pixels) {
|
||||
}
|
||||
|
||||
void Ion::Display::pushRectUniform(KDRect r, KDColor c) {
|
||||
}
|
||||
|
||||
void Ion::Display::pullRect(KDRect r, KDColor * pixels) {
|
||||
}
|
||||
|
||||
bool Ion::Keyboard::keyDown(Ion::Keyboard::Key key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Ion::msleep(long ms) {
|
||||
}
|
||||
6
ion/src/c.cpp
Normal file
6
ion/src/c.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <ion.h>
|
||||
#include <ion/c.h>
|
||||
|
||||
void ion_log_print(const char * message) {
|
||||
Ion::Log::print(message);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ objs += $(addprefix ion/src/device/, \
|
||||
display.o\
|
||||
keyboard.o\
|
||||
led.o\
|
||||
log.o\
|
||||
power.o\
|
||||
sd_card.o\
|
||||
)
|
||||
|
||||
@@ -61,6 +61,10 @@ void initGPIO() {
|
||||
g.group().AFR()->setAlternateFunction(g.pin(), GPIO::AFR::AlternateFunction::AF12);
|
||||
}
|
||||
|
||||
// Turn on the power
|
||||
PowerPin.group().MODER()->setMode(PowerPin.pin(), GPIO::MODER::Mode::Output);
|
||||
PowerPin.group().ODR()->set(PowerPin.pin(), true);
|
||||
|
||||
// Turn on the reset pin
|
||||
ResetPin.group().MODER()->setMode(ResetPin.pin(), GPIO::MODER::Mode::Output);
|
||||
ResetPin.group().ODR()->set(ResetPin.pin(), true);
|
||||
@@ -79,6 +83,9 @@ void shutdownGPIO() {
|
||||
// Set to true : sleep consumption = 154 uA
|
||||
// Set to false : sleep consumption = 92 uA
|
||||
ResetPin.group().ODR()->set(ResetPin.pin(), false);
|
||||
|
||||
PowerPin.group().MODER()->setMode(PowerPin.pin(), GPIO::MODER::Mode::Analog);
|
||||
PowerPin.group().PUPDR()->setPull(PowerPin.pin(), GPIO::PUPDR::Pull::None);
|
||||
}
|
||||
|
||||
void initFSMC() {
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace Device {
|
||||
* PA3 | LCD D5 | Alternate Function 12 | FSMC_D5 |
|
||||
* PA4 | LCD D6 | Alternate Function 12 | FSMC_D6 |
|
||||
* PB12 | LCD D13 | Alternate Function 12 | FSMC_D13 |
|
||||
* PB14 | LCD power | Output | | LCD controller is powered directly from GPIO
|
||||
* PD0 | LCD D2 | Alternate Function 12 | FSMC_D2 |
|
||||
* PD1 | LCD D3 | Alternate Function 12 | FSMC_D3 |
|
||||
* PD4 | LCD read signal | Alternate Function 12 | FSMC_NOE |
|
||||
@@ -76,6 +77,7 @@ constexpr static GPIOPin FSMCPins[] = {
|
||||
GPIOPin(GPIOE, 15)
|
||||
};
|
||||
|
||||
constexpr static GPIOPin PowerPin = GPIOPin(GPIOB, 14);
|
||||
constexpr static GPIOPin ResetPin = GPIOPin(GPIOE, 9);
|
||||
|
||||
constexpr static int FSMCMemoryBank = 1;
|
||||
|
||||
15
ion/src/device/log.cpp
Normal file
15
ion/src/device/log.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <ion/log.h>
|
||||
#include "regs/itm.h"
|
||||
|
||||
// We're printing using SWO.
|
||||
// This is achieved by writing to the ITM register, which is sent through the
|
||||
// Cortex Debug bus
|
||||
|
||||
void Ion::Log::print(const char * message) {
|
||||
char character = 0;
|
||||
while ((character = *message++) != 0) {
|
||||
if (ITM.TER()->get(0)) {
|
||||
ITM.STIM(0)->set(character);
|
||||
}
|
||||
}
|
||||
}
|
||||
32
ion/src/device/regs/itm.h
Normal file
32
ion/src/device/regs/itm.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef REGS_ITM_H
|
||||
#define REGS_ITM_H
|
||||
|
||||
#include "register.h"
|
||||
|
||||
// See ARM Cortex M4 TRM
|
||||
|
||||
class ITM {
|
||||
public:
|
||||
class STIM : public Register8 {
|
||||
};
|
||||
|
||||
// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0314h/Chdbicac.html
|
||||
class TER : Register32 {
|
||||
public:
|
||||
bool get(int index) volatile { return (bool)getBitRange(index, index); }
|
||||
};
|
||||
|
||||
constexpr ITM() {};
|
||||
volatile STIM * STIM(int i) const {
|
||||
return (class STIM *)(Base() + 4*i);
|
||||
};
|
||||
REGS_REGISTER_AT(TER, 0xE00);
|
||||
private:
|
||||
constexpr uint32_t Base() const {
|
||||
return 0xE0000000;
|
||||
}
|
||||
};
|
||||
|
||||
constexpr ITM ITM;
|
||||
|
||||
#endif
|
||||
@@ -37,6 +37,7 @@ private:
|
||||
T m_value;
|
||||
};
|
||||
|
||||
typedef Register<uint8_t> Register8;
|
||||
typedef Register<uint16_t> Register16;
|
||||
typedef Register<uint32_t> Register32;
|
||||
typedef Register<uint64_t> Register64;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "flash.h"
|
||||
#include "fsmc.h"
|
||||
#include "gpio.h"
|
||||
#include "itm.h"
|
||||
#include "pwr.h"
|
||||
#include "rcc.h"
|
||||
#include "sdio.h"
|
||||
|
||||
@@ -10,6 +10,7 @@ objs += $(addprefix ion/src/shared/, \
|
||||
crc32.o \
|
||||
events.o \
|
||||
events_from_keyboard.o \
|
||||
log.o \
|
||||
power.o \
|
||||
)
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
SFLAGS += -Iliba/include
|
||||
|
||||
ifeq ($(LIBA_LOG_DYNAMIC_MEMORY),1)
|
||||
SFLAGS += -DLIBA_LOG_DYNAMIC_MEMORY=1
|
||||
endif
|
||||
|
||||
liba/src/external/sqlite/mem5.o: CFLAGS += -w
|
||||
|
||||
objs += $(addprefix liba/src/, \
|
||||
|
||||
@@ -2,6 +2,20 @@
|
||||
#include <string.h>
|
||||
#include <private/memconfig.h>
|
||||
|
||||
#if LIBA_LOG_DYNAMIC_MEMORY
|
||||
#include <stdint.h>
|
||||
#include <ion/c.h>
|
||||
|
||||
void write_uint32_in_buffer(uint32_t n, char * buffer) {
|
||||
for (int i=0; i<2*sizeof(uint32_t); i++) {
|
||||
unsigned char v = (n & 0xF);
|
||||
char c = (v>9) ? 'A'+v-10 : '0'+v;
|
||||
buffer[2*sizeof(uint32_t)-1-i] = c;
|
||||
n = n >> 4;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
extern char _heap_start;
|
||||
extern char _heap_end;
|
||||
|
||||
@@ -26,6 +40,11 @@ static void configure_heap() {
|
||||
}
|
||||
|
||||
void free(void *ptr) {
|
||||
#if LIBA_LOG_DYNAMIC_MEMORY
|
||||
char message[5+2*sizeof(uint32_t)+1] = {'F', 'R', 'E', 'E', '-'};
|
||||
write_uint32_in_buffer((uint32_t)ptr, message+5);
|
||||
ion_log_print(message);
|
||||
#endif
|
||||
if (ptr != NULL) {
|
||||
memsys5FreeUnsafe(ptr);
|
||||
}
|
||||
@@ -39,6 +58,14 @@ void * malloc(size_t size) {
|
||||
if (size > 0) {
|
||||
p = memsys5MallocUnsafe(memsys5Roundup(size));
|
||||
}
|
||||
#if LIBA_LOG_DYNAMIC_MEMORY
|
||||
char message[7+2*sizeof(uint32_t)+1+2*sizeof(uint32_t)+1] = {'M','A','L','L','O','C','-'};
|
||||
write_uint32_in_buffer((uint32_t)p, message+7);
|
||||
message[7+2*sizeof(uint32_t)] = '-';
|
||||
write_uint32_in_buffer(size, message+7+2*sizeof(uint32_t)+1);
|
||||
message[7+2*sizeof(uint32_t)+1+2*sizeof(uint32_t)] = 0;
|
||||
ion_log_print(message);
|
||||
#endif
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user