diff --git a/.vscode/settings.json b/.vscode/settings.json index 8d5cb57..13b0224 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,6 +17,8 @@ "streambuf": "cpp", "system_error": "cpp", "tuple": "cpp", - "main.h": "c" + "main.h": "c", + "led.h": "c", + "stm32f730xx.h": "c" } } \ No newline at end of file diff --git a/numworks_port/Makefile b/numworks_port/Makefile index d7a1831..cce2ae8 100644 --- a/numworks_port/Makefile +++ b/numworks_port/Makefile @@ -50,18 +50,19 @@ LFLAGS += -mthumb LFLAGS += -Wall LFLAGS += --specs=nosys.specs LFLAGS += -nostdlib -LFLAGS += -lgcc LFLAGS += -T$(LSCRIPT) # AS_SRC = $(SRC_DIR)/core.S #C_SRC = $(SRC_DIR)/main.c -CPP_SRC := $(wildcard $(SRC_DIR)/*.cpp) +CPP_SRC := $(wildcard $(SRC_DIR)/*.cpp) $(wildcard $(SRC_DIR)/Laplace/*.cpp) +C_SRC := $(wildcard $(SRC_DIR)/*.c) $(wildcard $(SRC_DIR)/Laplace/*.c) INCLUDE = -I./ INCLUDE += -I./device #OBJS = $(BUILD_DIR)/$(notdir $(AS_SRC:.S=.o)) #OBJS += $(BUILD_DIR)/$(notdir $(C_SRC:.c=.o)) +OBJS += $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(C_SRC)) OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(BUILD_DIR)/%.o, $(CPP_SRC)) .PHONY: all diff --git a/numworks_port/README.md b/numworks_port/README.md index e43026c..ddcec10 100644 --- a/numworks_port/README.md +++ b/numworks_port/README.md @@ -10,6 +10,6 @@ This is a bare metal os attempt on the numworks n0110 ## TODO - [x] Working thing -- [ ] Led interface +- [x] Led interface - [ ] Keyboard interface - [ ] Screen interface \ No newline at end of file diff --git a/numworks_port/build/Laplace/led.o b/numworks_port/build/Laplace/led.o new file mode 100644 index 0000000..1951be5 Binary files /dev/null and b/numworks_port/build/Laplace/led.o differ diff --git a/numworks_port/build/main.bin b/numworks_port/build/main.bin index 5f5d8c7..423b97f 100755 Binary files a/numworks_port/build/main.bin and b/numworks_port/build/main.bin differ diff --git a/numworks_port/build/main.elf b/numworks_port/build/main.elf index 3e81d59..e0cbe78 100755 Binary files a/numworks_port/build/main.elf and b/numworks_port/build/main.elf differ diff --git a/numworks_port/build/rt0.o b/numworks_port/build/rt0.o deleted file mode 100644 index 86c4d35..0000000 Binary files a/numworks_port/build/rt0.o and /dev/null differ diff --git a/numworks_port/build/start_handler.o b/numworks_port/build/start_handler.o new file mode 100644 index 0000000..abcdf0d Binary files /dev/null and b/numworks_port/build/start_handler.o differ diff --git a/numworks_port/src/Laplace/README.md b/numworks_port/src/Laplace/README.md new file mode 100644 index 0000000..19c3786 --- /dev/null +++ b/numworks_port/src/Laplace/README.md @@ -0,0 +1,2 @@ +# Laplace +Laplace is the abstraction layer of Zeta, it is used to control the led, keyboard, screen ... \ No newline at end of file diff --git a/numworks_port/src/Laplace/led.cpp b/numworks_port/src/Laplace/led.cpp new file mode 100644 index 0000000..3d2f664 --- /dev/null +++ b/numworks_port/src/Laplace/led.cpp @@ -0,0 +1,59 @@ +#include "led.h" + +// Variable to store the current state of LEDs +uint8_t led_state = 0; + +void led_init(){ + // It should be set to push-pull low-speed output. + + // setup red led + GPIOB->MODER &= ~(0x3 << (RED_LED_PIN*2)); + GPIOB->MODER |= (0x1 << (RED_LED_PIN*2)); + GPIOB->OTYPER &= ~(1 << RED_LED_PIN); + + // setup green led + GPIOB->MODER &= ~(0x3 << (GREEN_LED_PIN*2)); + GPIOB->MODER |= (0x1 << (GREEN_LED_PIN*2)); + GPIOB->OTYPER &= ~(1 << GREEN_LED_PIN); + + // setup blue led + GPIOB->MODER &= ~(0x3 << (BLUE_LED_PIN*2)); + GPIOB->MODER |= (0x1 << (BLUE_LED_PIN*2)); + GPIOB->OTYPER &= ~(1 << BLUE_LED_PIN); +} + +void set_led_red(bool state){ + if(state){ + led_state |= (1 << RED_LED_PIN); + }else{ + led_state &= ~(1 << RED_LED_PIN); + } + GPIOB->ODR = led_state; +} + +void set_led_green(bool state){ + if(state){ + led_state |= (1 << GREEN_LED_PIN); + }else{ + led_state &= ~(1 << GREEN_LED_PIN); + } + GPIOB->ODR = led_state; +} + +void set_led_blue(bool state){ + if(state){ + led_state |= (1 << BLUE_LED_PIN); + }else{ + led_state &= ~(1 << BLUE_LED_PIN); + } + GPIOB->ODR = led_state; +} + +void set_led_all(bool state){ + if(state){ + led_state = (1 << RED_LED_PIN) | (1 << GREEN_LED_PIN) | (1 << BLUE_LED_PIN); + }else{ + led_state = 0; + } + GPIOB->ODR = led_state; +} \ No newline at end of file diff --git a/numworks_port/src/Laplace/led.h b/numworks_port/src/Laplace/led.h new file mode 100644 index 0000000..60b22d2 --- /dev/null +++ b/numworks_port/src/Laplace/led.h @@ -0,0 +1,23 @@ +/** @file led.h + * + * @brief Control the led + * + */ + +#ifndef LED_H +#define LED_H + +#define RED_LED_PIN (4) +#define GREEN_LED_PIN (5) +#define BLUE_LED_PIN (0) + +#include +#include "../device/stm32f730xx.h" + +void led_init(); +void set_led_red(bool state); +void set_led_green(bool state); +void set_led_blue(bool state); +void set_led_all(bool state); + +#endif \ No newline at end of file diff --git a/numworks_port/src/core.S.BAK b/numworks_port/src/core.S.BAK deleted file mode 100644 index 6e9ddf1..0000000 --- a/numworks_port/src/core.S.BAK +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Test program to boot an STM32 chip with the absolute - * minimum required code for teaching about the chips. - * - * Copyright William Ransohoff, Vivonomicon, LLC, 2017 - * - * Open source under the MIT License - */ - -.syntax unified -.cpu cortex-m7 -.fpu softvfp -.thumb - -// Global values. -.global vtable -.global reset_handler - -/* - * The vector table. - * Most entries are ommitted for simplicity. - */ - -/* - * The Reset handler. Called on reset. - */ -.type reset_handler, %function -reset_handler: - // Set the stack pointer to the end of the stack. - // The '_estack' value is defined in our linker script. - LDR r0, =_estack - MOV sp, r0 - - // Copy data from flash to RAM data init section. - // R2 will store our progress along the sidata section. - MOVS r0, #0 - // Load the start/end addresses of the data section, - // and the start of the data init section. - LDR r1, =_sdata - LDR r2, =_edata - LDR r3, =_sidata - B copy_sidata_loop - - copy_sidata: - // Offset the data init section by our copy progress. - LDR r4, [r3, r0] - // Copy the current word into data, and increment. - STR r4, [r1, r0] - ADDS r0, r0, #4 - - copy_sidata_loop: - // Unless we've copied the whole data section, copy the - // next word from sidata->data. - ADDS r4, r0, r1 - CMP r4, r2 - BCC copy_sidata - - // Once we are done copying the data section into RAM, - // move on to filling the BSS section with 0s. - MOVS r0, #0 - LDR r1, =_sbss - LDR r2, =_ebss - B reset_bss_loop - - // Zero out the BSS segment. - reset_bss: - // Store a 0 and increment by a word. - STR r0, [r1] - ADDS r1, r1, #4 - - reset_bss_loop: - // We'll use R1 to count progress here; if we aren't - // done, reset the next word and increment. - CMP r1, r2 - BCC reset_bss - - // Branch to the 'main' method. - B main -.size reset_handler, .-reset_handler \ No newline at end of file diff --git a/numworks_port/src/linker.ld b/numworks_port/src/linker.ld index b2e3544..8dfd328 100644 --- a/numworks_port/src/linker.ld +++ b/numworks_port/src/linker.ld @@ -1,9 +1,11 @@ -/* Label for the program's entry point */ -/*ENTRY(reset_handler)*/ -/* End of RAM / Start of stack */ -/* (4KB SRAM) */ +/* This is the linker file it required to map out the memory. + * This linker is heavely inspired by epsilon/omega/upsilon and their bootloader_common.ld. + * It is necessary if we want our os to be considered as valid. + * At this time we can only compile this os to slot B, but it might change in the future */ -/* epsilon stuff */ + + +/* numworks stuff */ STACK_SIZE = 32K; FIRST_FLASH_SECTOR_SIZE = 4K; SIGNED_PAYLOAD_LENGTH = 8; @@ -28,15 +30,18 @@ SECTIONS . = ORIGIN(FLASH) + SIGNED_PAYLOAD_LENGTH; } >FLASH + /* Contains some info and is requiered to be considered as a valid slot by the bootloader. + * Located in info_headers.cpp */ .kernel_header : { KEEP(*(.kernel_header)) } >FLASH + /* Nothing in there for now */ .slot_info : { *(.slot_info*) } >RAM - /* The vector table goes at the start of flash. */ + /* The vector table (handle all the interrupts) located in vector_table.cpp */ .isr_vector_table ORIGIN(RAM) + 512 : AT(ORIGIN(FLASH) + SIZEOF(.signed_payload_prefix) + SIZEOF(.kernel_header)) { /* When booting, the STM32F412 fetches the content of address 0x0, and * extracts from it various key infos: the initial value of the PC register @@ -57,6 +62,7 @@ SECTIONS _isr_vector_table_end_ram = .; } >RAM + /* this is to prevent the bootloader from booting straight up in our os (we set all to 0) */ .exam_mode_buffer ORIGIN(FLASH) + SIZEOF(.signed_payload_prefix) + SIZEOF(.kernel_header) + SIZEOF(.isr_vector_table) : { . = ALIGN(4K); _exam_mode_buffer_start = .; @@ -66,7 +72,8 @@ SECTIONS _exam_mode_buffer_end = .; } >FLASH - /* External flash memory */ + /* Contains some more info and is requiered to be considered as a valid slot by the bootloader. + * Located in info_headers.cpp */ .userland_header : { . = ORIGIN(FLASH) + USERLAND_OFFSET; KEEP(*(.userland_header)); @@ -77,6 +84,7 @@ SECTIONS *(.text) *(.text.*) } >FLASH + /* The 'rodata' section contains read-only data, * constants, strings, information that won't change. */ .rodata : { @@ -84,6 +92,7 @@ SECTIONS *(.rodata.*) } >FLASH + /* TODO, understand what is it's purpose */ .init_array : { . = ALIGN(4); _init_array_start = .; diff --git a/numworks_port/src/main.c.BAK b/numworks_port/src/main.c.BAK deleted file mode 100644 index b2c6a83..0000000 --- a/numworks_port/src/main.c.BAK +++ /dev/null @@ -1,21 +0,0 @@ -#include "main.h" - -/* Main program. */ -int main(void) { - // Enable the GPIOa and GPIOC peripheral in RCC. - RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN ; - - // C0 is connected to the LED - // It should be set to push-pull low-speed output. - GPIOB->MODER &= ~(0x3 << (LED_PIN*2)); - GPIOB->MODER |= (0x1 << (LED_PIN*2)); - GPIOB->OTYPER &= ~(1 << LED_PIN); - - // set the led on - GPIOB->ODR = (1 << LED_PIN); - while (0) - { - GPIOB->ODR = (1 << LED_PIN); - } - -} \ No newline at end of file diff --git a/numworks_port/src/main.h.BAK b/numworks_port/src/main.h.BAK deleted file mode 100644 index b1f960e..0000000 --- a/numworks_port/src/main.h.BAK +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef _VVC_MAIN_H -#define _VVC_MAIN_H -#include -#include "device/stm32f730xx.h" -// Define GPIOB pin mappings for our LED and button. -#define LED_PIN (3) // led on PC0 -#endif \ No newline at end of file diff --git a/numworks_port/src/rt0.cpp b/numworks_port/src/start_handler.cpp similarity index 89% rename from numworks_port/src/rt0.cpp rename to numworks_port/src/start_handler.cpp index 2d3ffee..8f5e097 100644 --- a/numworks_port/src/rt0.cpp +++ b/numworks_port/src/start_handler.cpp @@ -2,8 +2,9 @@ #include #include #include "device/stm32f730xx.h" +#include "Laplace/led.h" -#define LED_PIN (4) // PC0 +//#define LED_PIN (4) // PB0 typedef void (*cxx_constructor)(); @@ -42,6 +43,7 @@ void* memset_custom(void* ptr, int value, size_t num_bytes) { return ptr; } +// This the first function when the os boot void __attribute__((noinline)) start() { /* Copy data section to RAM * The data section is R/W but its initialization value matters. It's stored @@ -56,19 +58,22 @@ void __attribute__((noinline)) start() { size_t bssSectionLength = (&_bss_section_end_ram - &_bss_section_start_ram); memset_custom(&_bss_section_start_ram, 0, bssSectionLength); - // Enable the GPIOa and GPIOC peripheral in RCC. + // Enable the GPIO peripheral in RCC. RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN ; - - // C0 is connected to the LED. + led_init(); + set_led_green(true); + set_led_red(true); + /* + // B0 is connected to the LED. // It should be set to push-pull low-speed output. GPIOB->MODER &= ~(0x3 << (LED_PIN*2)); GPIOB->MODER |= (0x1 << (LED_PIN*2)); GPIOB->OTYPER &= ~(1 << LED_PIN); GPIOB->ODR = (1 << LED_PIN); - + */ while (0) { - GPIOB->ODR = (1 << LED_PIN); + // code } } \ No newline at end of file