diff --git a/Makefile b/Makefile index 324268320..8742262ef 100644 --- a/Makefile +++ b/Makefile @@ -2,30 +2,40 @@ CC=arm-none-eabi-gcc LD=arm-none-eabi-ld.bfd GDB=arm-none-eabi-gdb OBJCOPY=arm-none-eabi-objcopy -CFLAGS = -I. -Iinclude -Iexternal/freertos/include -Iexternal -Iexternal/freertos/portable/GCC/ARM_CM4F -Iexternal/newlib/libc/include +CFLAGS = -Ilib -I. -Iinclude -Iexternal/freertos/include -Iexternal -Iexternal/freertos/portable/GCC/ARM_CM4F -Iexternal/newlib/libc/include +CFLAGS += -DHAVE_CONFIG_H=1 -DPIXMAN_NO_TLS=1 -Wno-unused-const-variable +#CFLAGS += -fshort-double # Use the FPU even for doubles #CFLAGS = -I. -Iexternal/freertos/include -Iexternal -Iexternal/freertos/portable/GCC/ARM_CM4F -Iexternal/newlib/libc/include -Iinclude #-I/Users/romain/local/arm-none-eabi/include -CFLAGS += -std=c99 -g -Wall +CFLAGS += -std=c99 -Wall #CFLAGS += -march=armv7e-m -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 CC=clang CFLAGS += -target thumbv7em-unknown-eabi -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -ffreestanding +CXX=clang++ +CXXFLAGS=-target thumbv7em-unknown-eabi -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -ffreestanding +CXXFLAGS += -fno-exceptions -fno-unwind-tables -fno-rtti -nostdlib + # Production +CFLAGS += -g #CFLAGS += -Os -fdata-sections -ffunction-sections #LDFLAGS += --gc-sections -objs := platform/stm32f429/boot/crt0.o +products := boot.elf boot.hex boot.bin + objs += external/freertos/tasks.o external/freertos/list.o external/freertos/queue.o external/freertos/portable/GCC/ARM_CM4F/port.o external/freertos/portable/MemMang/heap_1.o objs += external/newlib/libc/string/memset.o external/newlib/libc/string/memcpy.o -objs += platform/stm32f429/boot/isr.o -#platform/stm32f429/registers/gpio.o platform/stm32f429/registers/rcc.o platform/stm32f429/registers/spi.o platform/stm32f429/registers/ltdc.o +objs += lib/assert.o + +objs += math/expression.o -objs += platform/stm32f429/init.o platform/stm32f429/init_lcd.o -objs += platform/ili9341/ili9341.o default: clean boot.elf +include platform/Makefile +include kandinsky/Makefile + run: boot.elf $(GDB) -x gdb_script.gdb boot.elf @@ -51,6 +61,10 @@ boot.elf: $(objs) @echo "CC $@" @$(CC) $(CFLAGS) -c $< -o $@ +%.o: %.cpp + @echo "CXX $@" + @$(CXX) $(CXXFLAGS) -c $< -o $@ + clean: @echo "CLEAN" - @rm -f $(objs) boot.elf boot.bin boot.hex + @rm -f $(objs) $(products) diff --git a/fonts/rasterizer.c b/fonts/rasterizer.c index dfc1b3364..26c15336f 100644 --- a/fonts/rasterizer.c +++ b/fonts/rasterizer.c @@ -140,12 +140,12 @@ int main(int argc, char * argv[]) { fprintf(headerFile, "#define BITMAP_FONT_LAST_CHARACTER 0x%2x\n\n", CHARACTER_RANGE_END); fprintf(headerFile, "#define BITMAP_FONT_CHARACTER_WIDTH %d\n", glyph_width); fprintf(headerFile, "#define BITMAP_FONT_CHARACTER_HEIGHT %d\n\n", glyph_height); - fprintf(headerFile, "extern unsigned char bitmapFont[%d][%d][%d];\n", CHARACTER_RANGE_END-CHARACTER_RANGE_START+1, glyph_width, glyph_height); + fprintf(headerFile, "extern unsigned char bitmapFont[%d][%d][%d];\n", CHARACTER_RANGE_END-CHARACTER_RANGE_START+1, glyph_height, glyph_width); fclose(headerFile); FILE * sourceFile = fopen("out.c", "w"); fprintf(sourceFile, "/* Auto-generated by rasterizer */\n\n"); - fprintf(sourceFile, "unsigned char bitmapFont[%d][%d][%d] = {\n", CHARACTER_RANGE_END-CHARACTER_RANGE_START+1, glyph_width, glyph_height); + fprintf(sourceFile, "unsigned char bitmapFont[%d][%d][%d] = {\n", CHARACTER_RANGE_END-CHARACTER_RANGE_START+1, glyph_height, glyph_width); for (unsigned char character = CHARACTER_RANGE_START; character <= CHARACTER_RANGE_END; character++) { fprintf(sourceFile, " {\n"); int characterX = ((character-CHARACTER_RANGE_START)%GRID_WIDTH * (glyph_width+grid_size)); diff --git a/gdb_script.gdb b/gdb_script.gdb index 9c1b66c64..0ae16ec57 100644 --- a/gdb_script.gdb +++ b/gdb_script.gdb @@ -8,6 +8,7 @@ load boot.elf monitor reset halt break init -break _halt +break abort +break __assert continue diff --git a/kandinsky/Makefile b/kandinsky/Makefile index 8f3a9da1a..efa70b547 100644 --- a/kandinsky/Makefile +++ b/kandinsky/Makefile @@ -1,4 +1,4 @@ -CFLAGS += -Ikandinsky/include +CFLAGS += -Ikandinsky/include -Iplatform/stm32f429 objs += $(addprefix kandinsky/src/, line.o text.o font.o) FREETYPE_PATH := /usr/local/Cellar/freetype/2.5.5 diff --git a/kandinsky/src/framebuffer.h b/kandinsky/src/framebuffer.h deleted file mode 100644 index 6e5d8b924..000000000 --- a/kandinsky/src/framebuffer.h +++ /dev/null @@ -1,7 +0,0 @@ -typedef uint8_t kdpixel_t; - -#define FRAMEBUFFER_WIDTH 240 -#define FRAMEBUFFER_HEIGHT 320 -#define FRAMEBUFFER_ADDRESS (kdpixel_t *)(0x2001D400) - -#define PIXEL(x,y) *(kdpixel_t *)(FRAMEBUFFER_ADDRESS + y*FRAMEBUFFER_WIDTH + x) diff --git a/kandinsky/src/text.c b/kandinsky/src/text.c index 20865572f..ff3aa9e05 100644 --- a/kandinsky/src/text.c +++ b/kandinsky/src/text.c @@ -1,9 +1,8 @@ #include -#include "framebuffer.h" +#include #include "font.h" void KDDrawChar(char character, KDPoint p) { - char * framebuffer = FRAMEBUFFER_ADDRESS; for (int j=0; j + +#ifdef NDEBUG +#define assert(e) ((void)0) +#else +#define assert(e) ((void) ((e) ? ((void)0) : __assert(#e, __FILE__, __LINE__))) +#endif + +void __assert(const char * expression, const char * file, int line) { + abort(); +} diff --git a/lib/assert.h b/lib/assert.h new file mode 100644 index 000000000..39f6a0aea --- /dev/null +++ b/lib/assert.h @@ -0,0 +1,14 @@ +#ifndef ASSERT_H +#define ASSERT_H + +#ifdef NDEBUG +#define assert(e) ((void)0) +#else +#define assert(e) ((void) ((e) ? ((void)0) : __assert(#e, __FILE__, __LINE__))) +#endif + +void __assert(const char * expression, const char * file, int line); + +void abort(void); + +#endif diff --git a/platform/Makefile b/platform/Makefile new file mode 100644 index 000000000..1fd081d68 --- /dev/null +++ b/platform/Makefile @@ -0,0 +1,2 @@ +objs += $(addprefix platform/stm32f429/, boot/isr.o boot/crt0.o init.o init_lcd.o) +objs += platform/ili9341/ili9341.o diff --git a/platform/stm32f429/boot/crt0.c b/platform/stm32f429/boot/crt0.c index 339282c14..1a3e8d17c 100644 --- a/platform/stm32f429/boot/crt0.c +++ b/platform/stm32f429/boot/crt0.c @@ -9,7 +9,8 @@ extern const void * _bss_section_end_ram; void init(); -void _halt() { +void abort() { + // TODO: #ifdef NDEBUG, maybe trigger a reset? while (1) { } } @@ -33,5 +34,5 @@ void _start(void) { init(); - _halt(); + abort(); } diff --git a/platform/stm32f429/boot/flash.ld b/platform/stm32f429/boot/flash.ld index 3e5b47622..356e4f339 100644 --- a/platform/stm32f429/boot/flash.ld +++ b/platform/stm32f429/boot/flash.ld @@ -89,7 +89,7 @@ SECTIONS { * HardFault one to crt0's _halt. */ PROVIDE(_ResetServiceRoutine = _start); - PROVIDE(_HardFaultServiceRoutine = _halt); + PROVIDE(_HardFaultServiceRoutine = abort); *(.text) *(.text.*) diff --git a/platform/stm32f429/framebuffer.h b/platform/stm32f429/framebuffer.h new file mode 100644 index 000000000..b408cf1ab --- /dev/null +++ b/platform/stm32f429/framebuffer.h @@ -0,0 +1,13 @@ +#ifndef STM32F4_FRAMEBUFFER_H +#define STM32F4_FRAMEBUFFER_H + +typedef uint8_t pixel_t; + +#define FRAMEBUFFER_WIDTH 240 +#define FRAMEBUFFER_HEIGHT 320 +#define FRAMEBUFFER_BITS_PER_PIXEL 8 +#define FRAMEBUFFER_ADDRESS (pixel_t *)(0x2001D400) + +#define PIXEL(x,y) *(pixel_t *)(FRAMEBUFFER_ADDRESS+FRAMEBUFFER_WIDTH*(y)+(x)) + +#endif diff --git a/platform/stm32f429/init_lcd.c b/platform/stm32f429/init_lcd.c index 25ae7195d..eb7765318 100644 --- a/platform/stm32f429/init_lcd.c +++ b/platform/stm32f429/init_lcd.c @@ -27,12 +27,18 @@ #include "registers/gpio.h" #include "registers/spi.h" #include "registers/ltdc.h"*/ +#include #include "registers.h" +#include "framebuffer.h" #include +extern pixel_t _framebuffer_start; +extern pixel_t _framebuffer_end; + static void init_spi_interface(); static void init_rgb_interface(); static void init_panel(); +static void check_framebuffer(); void init_lcd() { /* This routine is responsible for initializing the LCD panel. @@ -45,6 +51,10 @@ void init_lcd() { init_rgb_interface(); init_panel(); + +#ifndef NDEBUG + check_framebuffer(); +#endif } // SPI interface @@ -187,7 +197,6 @@ static void init_rgb_clocks() { } } -extern const void * _framebuffer_start; static void init_rgb_timings() { // Configure the Synchronous timings: VSYNC, HSYNC, Vertical and Horizontal @@ -340,3 +349,12 @@ void gpio_c2_write(bool pin_state) { void gpio_d13_write(bool pin_state) { REGISTER_SET_VALUE(GPIO_ODR(GPIOD), ODR(13), pin_state); } + +// Framebuffer checks + +static void check_framebuffer() { + assert(&_framebuffer_start == FRAMEBUFFER_ADDRESS); + pixel_t * fb_end = &_framebuffer_start + (FRAMEBUFFER_WIDTH*FRAMEBUFFER_HEIGHT*FRAMEBUFFER_BITS_PER_PIXEL)/8; + assert(&_framebuffer_end == fb_end); + assert(8*sizeof(pixel_t) == FRAMEBUFFER_BITS_PER_PIXEL); +}