]> git.ayabusa.dev Git - numworks-zeta-os.git/commitdiff
added led interface
authorayabusa <lebgpub@gmail.com>
Sun, 31 Mar 2024 16:17:46 +0000 (18:17 +0200)
committerayabusa <lebgpub@gmail.com>
Sun, 31 Mar 2024 16:17:46 +0000 (18:17 +0200)
17 files changed:
.vscode/settings.json
numworks_port/Makefile
numworks_port/README.md
numworks_port/build/Laplace/led.o [new file with mode: 0644]
numworks_port/build/main.bin
numworks_port/build/main.elf
numworks_port/build/rt0.o [deleted file]
numworks_port/build/start_handler.o [new file with mode: 0644]
numworks_port/src/Laplace/README.md [new file with mode: 0644]
numworks_port/src/Laplace/led.cpp [new file with mode: 0644]
numworks_port/src/Laplace/led.h [new file with mode: 0644]
numworks_port/src/core.S.BAK [deleted file]
numworks_port/src/linker.ld
numworks_port/src/main.c.BAK [deleted file]
numworks_port/src/main.h.BAK [deleted file]
numworks_port/src/rt0.cpp [deleted file]
numworks_port/src/start_handler.cpp [new file with mode: 0644]

index 8d5cb5703fbc5d1bd108aad2f7f813554fa489d6..13b0224ab83c555f3ae6d7dad58657e7209a6217 100644 (file)
@@ -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
index d7a1831580076adb66c8e76d5796e404d7bf74ad..cce2ae8edd8c8619a3e903baaeff7dd0596bff74 100644 (file)
@@ -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
index e43026c30035834c19864825c2816d9208376fbe..ddcec103c33e5e85934125cbd4362d584d475cc7 100644 (file)
@@ -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 (file)
index 0000000..1951be5
Binary files /dev/null and b/numworks_port/build/Laplace/led.o differ
index 5f5d8c7b5d32c3b846b864e4bbf9ee31a6cffd9e..423b97fb77d88d53565b6adfb3d1194379cf2ca6 100755 (executable)
Binary files a/numworks_port/build/main.bin and b/numworks_port/build/main.bin differ
index 3e81d598c56d43ad8bcbe7fba3d2ecdb79dbddf0..e0cbe7893250abeee2226f9a9cd66e6e602b198f 100755 (executable)
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 (file)
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 (file)
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 (file)
index 0000000..19c3786
--- /dev/null
@@ -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 (file)
index 0000000..3d2f664
--- /dev/null
@@ -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 (file)
index 0000000..60b22d2
--- /dev/null
@@ -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 <stdbool.h>
+#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 (file)
index 6e9ddf1..0000000
+++ /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
index b2e35449614de735f990ea275bd2c95ec1ea417a..8dfd328cbd45f5bf10aa5e875ff99a40150fa3da 100644 (file)
@@ -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 (file)
index b2c6a83..0000000
+++ /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 (file)
index b1f960e..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef _VVC_MAIN_H
-#define _VVC_MAIN_H
-#include <stdint.h>
-#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/rt0.cpp
deleted file mode 100644 (file)
index 2d3ffee..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-#include "vector_table.h"
-#include <stddef.h>
-#include <stdint.h>
-#include "device/stm32f730xx.h"
-
-#define LED_PIN    (4) // PC0
-
-typedef void (*cxx_constructor)();
-
-extern "C" {
-  extern char _data_section_start_flash;
-  extern char _data_section_start_ram;
-  extern char _data_section_end_ram;
-  extern char _bss_section_start_ram;
-  extern char _bss_section_end_ram;
-  extern cxx_constructor _init_array_start;
-  extern cxx_constructor _init_array_end;
-}
-
-
-void* memcpy_custom(void* destination, const void* source, size_t num_bytes) {
-    char* dest_ptr = (char*)destination;
-    const char* src_ptr = (const char*)source;
-
-    // Copy each byte from source to destination
-    for (size_t i = 0; i < num_bytes; ++i) {
-        dest_ptr[i] = src_ptr[i];
-    }
-
-    return destination;
-}
-
-void* memset_custom(void* ptr, int value, size_t num_bytes) {
-    unsigned char* p = (unsigned char*)ptr;
-    unsigned char v = (unsigned char)value;
-
-    // Set each byte in the memory block to the specified value
-    for (size_t i = 0; i < num_bytes; ++i) {
-        p[i] = v;
-    }
-
-    return ptr;
-}
-
-void __attribute__((noinline)) start() {
-    /* Copy data section to RAM
-  * The data section is R/W but its initialization value matters. It's stored
-  * in Flash, but linked as if it were in RAM. Now's our opportunity to copy
-  * it. Note that until then the data section (e.g. global variables) contains
-  * garbage values and should not be used. */
-  size_t dataSectionLength = (&_data_section_end_ram - &_data_section_start_ram);
-  memcpy_custom(&_data_section_start_ram, &_data_section_start_flash, dataSectionLength);
-
-  /* Zero-out the bss section in RAM
-  * Until we do, any uninitialized global variable will be unusable. */
-  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.
-  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);
-
-  GPIOB->ODR = (1 << LED_PIN);
-
-  while (0)
-  {
-    GPIOB->ODR = (1 << LED_PIN);
-  }
-}
\ No newline at end of file
diff --git a/numworks_port/src/start_handler.cpp b/numworks_port/src/start_handler.cpp
new file mode 100644 (file)
index 0000000..8f5e097
--- /dev/null
@@ -0,0 +1,79 @@
+#include "vector_table.h"
+#include <stddef.h>
+#include <stdint.h>
+#include "device/stm32f730xx.h"
+#include "Laplace/led.h"
+
+//#define LED_PIN    (4) // PB0
+
+typedef void (*cxx_constructor)();
+
+extern "C" {
+  extern char _data_section_start_flash;
+  extern char _data_section_start_ram;
+  extern char _data_section_end_ram;
+  extern char _bss_section_start_ram;
+  extern char _bss_section_end_ram;
+  extern cxx_constructor _init_array_start;
+  extern cxx_constructor _init_array_end;
+}
+
+
+void* memcpy_custom(void* destination, const void* source, size_t num_bytes) {
+    char* dest_ptr = (char*)destination;
+    const char* src_ptr = (const char*)source;
+
+    // Copy each byte from source to destination
+    for (size_t i = 0; i < num_bytes; ++i) {
+        dest_ptr[i] = src_ptr[i];
+    }
+
+    return destination;
+}
+
+void* memset_custom(void* ptr, int value, size_t num_bytes) {
+    unsigned char* p = (unsigned char*)ptr;
+    unsigned char v = (unsigned char)value;
+
+    // Set each byte in the memory block to the specified value
+    for (size_t i = 0; i < num_bytes; ++i) {
+        p[i] = v;
+    }
+
+    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
+  * in Flash, but linked as if it were in RAM. Now's our opportunity to copy
+  * it. Note that until then the data section (e.g. global variables) contains
+  * garbage values and should not be used. */
+  size_t dataSectionLength = (&_data_section_end_ram - &_data_section_start_ram);
+  memcpy_custom(&_data_section_start_ram, &_data_section_start_flash, dataSectionLength);
+
+  /* Zero-out the bss section in RAM
+  * Until we do, any uninitialized global variable will be unusable. */
+  size_t bssSectionLength = (&_bss_section_end_ram - &_bss_section_start_ram);
+  memset_custom(&_bss_section_start_ram, 0, bssSectionLength);
+
+  // Enable the GPIO peripheral in RCC.
+  RCC->AHB1ENR   |= RCC_AHB1ENR_GPIOBEN ;
+  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)
+  {
+    // code
+  }
+}
\ No newline at end of file