diff --git a/car_fmw/Makefile b/car_fmw/Makefile index 9673b6d2c18..9362eb65e0a 100644 --- a/car_fmw/Makefile +++ b/car_fmw/Makefile @@ -5,12 +5,12 @@ TRANSLATOR_DIR=$(PWD)/../translator KOTSTD_DIR=$(PWD)/../kotstd CAR_HW_DIR=$(PWD)/../car_hw -OS_ARCH=linux-arm +OS_ARCH=linux-x86_64 CAR_FMW_OBJ=$(BIN_DIR)/car_fmw.o CAR_FMW_ELF=$(BIN_DIR)/car_fmw.elf CAR_FMW_BIN=$(BIN_DIR)/car_fmw.bin -ST_DIR=$(SRC_DIR)/../../devloader/data/$(OS_ARCH) +ST_DIR=$(PWD)/../mcu_utils/$(OS_ARCH) LIB_KOT=$(BIN_DIR)/kotlib.o LIB_KOTSTD=$(KOTSTD_DIR)/build/stdlib_arm.ll @@ -67,7 +67,7 @@ $(BIN_DIR)/kotlib.ll: $(LIB_DIR)/app.ll $(LIB_KOTSTD) $(LIB_KOTSTD): cd $(KOTSTD_DIR) && make -$(LIB_DIR)/app.ll: $(SRC_DIR)/*.kt +$(LIB_DIR)/app.ll: $(SRC_DIR)/**/*.kt $(SRC_DIR)/*.kt $(KT_ALL_DEPS) $(KT): diff --git a/car_fmw/src/include/engine.kt b/car_fmw/src/include/engine.kt new file mode 100644 index 00000000000..560e0021665 --- /dev/null +++ b/car_fmw/src/include/engine.kt @@ -0,0 +1,8 @@ + +external fun engine_init() + +external fun engine_stop() +external fun engine_forward() +external fun engine_backward() +external fun engine_turn_left() +external fun engine_turn_right() diff --git a/car_fmw/src/include/general.kt b/car_fmw/src/include/general.kt new file mode 100644 index 00000000000..271789adce8 --- /dev/null +++ b/car_fmw/src/include/general.kt @@ -0,0 +1,6 @@ + +fun init() { + time_init() + engine_init() + leds_init() +} diff --git a/car_fmw/src/include/leds.kt b/car_fmw/src/include/leds.kt new file mode 100644 index 00000000000..7eeb37a6242 --- /dev/null +++ b/car_fmw/src/include/leds.kt @@ -0,0 +1,9 @@ + +external fun leds_init() +external fun leds_clear_all() +external fun led_set(led: Int, on: Boolean) + +val LED_GREEN = 0 +val LED_ORANGE = 1 +val LED_RED = 2 +val LED_BLUE = 3 diff --git a/car_fmw/src/include/time.kt b/car_fmw/src/include/time.kt new file mode 100644 index 00000000000..0a16d98a546 --- /dev/null +++ b/car_fmw/src/include/time.kt @@ -0,0 +1,4 @@ + +external fun time_init() + +external fun wait(msec: Int) diff --git a/car_fmw/src/include/user_btn.kt b/car_fmw/src/include/user_btn.kt new file mode 100644 index 00000000000..c44be8b814d --- /dev/null +++ b/car_fmw/src/include/user_btn.kt @@ -0,0 +1,4 @@ + +external fun user_btn_init(handler: () -> Unit) +external fun user_btn_is_pushed(): Boolean +external fun EXTI0_IRQHandler() diff --git a/car_fmw/src/main.kt b/car_fmw/src/main.kt index 77bcdaf13e3..b029c546d70 100644 --- a/car_fmw/src/main.kt +++ b/car_fmw/src/main.kt @@ -1,56 +1,5 @@ -external fun time_init() -external fun leds_init() - -external fun engine_init() -external fun engine_stop() -external fun engine_forward() -external fun engine_backward() -external fun engine_turn_left() -external fun engine_turn_right() - -external fun user_brn_init(i: () -> Unit) -external fun run_programmed_car(i: () -> Unit) -external fun run_rc_car(i: () -> Unit) - -external fun VCP_init() - -external fun wait(i: Int) - -val CAR_MODE_PROGRAMMED: Int = 0 -val CAR_MODE_REMOTE_CONTROL: Int = 1 -val CAR_MODE_LAST: Int = 2 - -val PROGRAM_DURATION: Int = 3000 - -annotation class Native(val type: String = "") - -@Native -class MyClass(@Native("i32") val i: Int, @Native("i16") val j: Int, @Native("i8") val k: Int) - -fun engine_program() { - engine_init() - - while (2 < 3) { - engine_forward() - wait(PROGRAM_DURATION) - engine_stop() - - engine_backward() - wait(PROGRAM_DURATION) - engine_stop() - - engine_turn_right() - wait(PROGRAM_DURATION) - engine_stop() - - engine_turn_right() - wait(PROGRAM_DURATION) - engine_stop() - } -} - -fun kotlin_main() { - time_init() - engine_program() +fun main() { + init() + simpleRoute() } diff --git a/car_fmw/src/simpleRoute.kt b/car_fmw/src/simpleRoute.kt new file mode 100644 index 00000000000..7e2e9fa7ec1 --- /dev/null +++ b/car_fmw/src/simpleRoute.kt @@ -0,0 +1,35 @@ + +val PROGRAM_DURATION: Int = 3000 +val BLINK_DURATION: Int = 500 + +fun blink() { + led_set(LED_GREEN, true) + led_set(LED_BLUE, true) + led_set(LED_RED, true) + led_set(LED_ORANGE, true) + wait(BLINK_DURATION) + led_set(LED_GREEN, false) + led_set(LED_BLUE, false) + led_set(LED_RED, false) + led_set(LED_ORANGE, false) +} + +fun simpleRoute() { + while (true) { + engine_forward() + wait(PROGRAM_DURATION) + blink() + + engine_turn_right() + wait(PROGRAM_DURATION) + blink() + + engine_backward() + wait(PROGRAM_DURATION) + blink() + + engine_turn_left() + wait(PROGRAM_DURATION) + blink() + } +} \ No newline at end of file diff --git a/car_hw/Makefile b/car_hw/Makefile index b3dfc10b389..3921c56d481 100644 --- a/car_hw/Makefile +++ b/car_hw/Makefile @@ -36,7 +36,9 @@ INCLUDES=-I$(LIB_CMSIS_DIR) \ -I$(LIB_USB_OTG_DIR) \ -I$(LIB_USB_VCP_DIR) \ -I$(USB_CONF_DIR) \ - -I$(SRC_DIR) + -I$(SRC_DIR) \ + -I$(SRC_DIR)/include + DEFINES=-DUSE_STM32_DISCOVERY=1 -DUSE_STDPERIPH_DRIVER=1 -DSTM32F4XX=1 -DHSE_VALUE=8000000 CFLAGS=-g -nostdlib -ffreestanding -O0 \ -mcpu=cortex-m3 -mfloat-abi=soft -mthumb \ diff --git a/car_hw/src/car_engine.c b/car_hw/src/car_engine.c index 01ba63276a7..f1c21f22801 100644 --- a/car_hw/src/car_engine.c +++ b/car_hw/src/car_engine.c @@ -1,4 +1,5 @@ #include "car_engine.h" + #include "stm32f4_discovery.h" #include "stm32f4xx_conf.h" diff --git a/car_hw/src/car_leds.c b/car_hw/src/car_leds.c index 428efa3fc7d..d49ed2f9b85 100644 --- a/car_hw/src/car_leds.c +++ b/car_hw/src/car_leds.c @@ -1,6 +1,7 @@ #include #include "car_leds.h" + #include "stm32f4_discovery.h" #include "stm32f4xx_conf.h" @@ -12,7 +13,7 @@ void leds_init(void) STM_EVAL_LEDInit(LED_BLUE); } -void led_set(led_t led, bool on) +void led_set(int led, bool on) { if (on) STM_EVAL_LEDOn(led); diff --git a/car_hw/src/car_prog.c b/car_hw/src/car_prog.c index 12e63c1ec07..c81adb87a95 100644 --- a/car_hw/src/car_prog.c +++ b/car_hw/src/car_prog.c @@ -3,10 +3,11 @@ #include "car_leds.h" #include "car_engine.h" -#include "time.h" #include "car_prog.h" +#include "time.h" + +const uint32_t PROGRAM_DURATION_MS = 3000; -const uint32_t PROGRAM_DURATION_MS = 3000; static void program_stop(void) { wait(PROGRAM_DURATION_MS); diff --git a/car_hw/src/car_engine.h b/car_hw/src/include/car_engine.h similarity index 100% rename from car_hw/src/car_engine.h rename to car_hw/src/include/car_engine.h diff --git a/car_hw/src/car_leds.h b/car_hw/src/include/car_leds.h similarity index 86% rename from car_hw/src/car_leds.h rename to car_hw/src/include/car_leds.h index 70007722285..7384538b485 100644 --- a/car_hw/src/car_leds.h +++ b/car_hw/src/include/car_leds.h @@ -13,4 +13,4 @@ typedef enum void leds_init(void); void leds_clear_all(void); -void led_set(led_t led, bool on); +void led_set(int led, bool on); diff --git a/car_hw/src/car_prog.h b/car_hw/src/include/car_prog.h similarity index 100% rename from car_hw/src/car_prog.h rename to car_hw/src/include/car_prog.h diff --git a/car_hw/src/car_rc.h b/car_hw/src/include/car_rc.h similarity index 100% rename from car_hw/src/car_rc.h rename to car_hw/src/include/car_rc.h diff --git a/car_hw/src/car_user_btn.h b/car_hw/src/include/car_user_btn.h similarity index 100% rename from car_hw/src/car_user_btn.h rename to car_hw/src/include/car_user_btn.h diff --git a/car_hw/src/stm32f4xx_conf.h b/car_hw/src/include/stm32f4xx_conf.h similarity index 100% rename from car_hw/src/stm32f4xx_conf.h rename to car_hw/src/include/stm32f4xx_conf.h diff --git a/car_hw/src/stm32f4xx_it.h b/car_hw/src/include/stm32f4xx_it.h similarity index 100% rename from car_hw/src/stm32f4xx_it.h rename to car_hw/src/include/stm32f4xx_it.h diff --git a/car_hw/src/time.h b/car_hw/src/include/time.h similarity index 100% rename from car_hw/src/time.h rename to car_hw/src/include/time.h diff --git a/car_hw/src/main.c b/car_hw/src/main.c index bae58a37e08..7bb5e871c5d 100644 --- a/car_hw/src/main.c +++ b/car_hw/src/main.c @@ -1,10 +1,14 @@ -/* #include */ -/* #include */ +#include +#include -/* #include "car_leds.h" */ -/* #include "car_engine.h" */ -/* #include "time.h" */ -/* #include "car_user_btn.h" */ +#include "car_engine.h" +#include "car_leds.h" +#include "car_rc.h" +#include "car_user_btn.h" +#include "time.h" + +#include "stm32f4xx_conf.h" +#include "stm32f4xx_it.h" /* typedef enum { */ /* CAR_MODE_PROGRAMMED, */ @@ -19,31 +23,28 @@ /* cur_mode_stop = true; */ /* } */ -extern void kotlin_main(); - -int main(void) -{ - kotlin_main(); - /*!< At this stage the microcontroller clock setting is already configured, - this is done through SystemInit() function which is called from startup - file (startup_stm32f4xx.s) before to branch to application main. - To reconfigure the default setting of SystemInit() function, refer to - system_stm32f4xx.c file - */ - - /* time_init(); */ - /* leds_init(); */ - /* engine_init(); */ - /* user_btn_init(stop_cur_mode); */ - /* VCP_init(); */ - - /* while(1) { */ - /* if (cur_mode == CAR_MODE_PROGRAMMED) */ - /* run_programmed_car(&cur_mode_stop); */ - /* else if(cur_mode == CAR_MODE_REMOTE_CONTROL) */ - /* run_rc_car(&cur_mode_stop); */ - - /* cur_mode = (cur_mode + 1) % CAR_MODE_LAST; */ - /* cur_mode_stop = false; */ - /* } */ -} +//int main(void) +//{ +// /*!< At this stage the microcontroller clock setting is already configured, +// this is done through SystemInit() function which is called from startup +// file (startup_stm32f4xx.s) before to branch to application main. +// To reconfigure the default setting of SystemInit() function, refer to +// system_stm32f4xx.c file +// */ +// +// /* time_init(); */ +// /* leds_init(); */ +// /* engine_init(); */ +// /* user_btn_init(stop_cur_mode); */ +// /* VCP_init(); */ +// +// /* while(1) { */ +// /* if (cur_mode == CAR_MODE_PROGRAMMED) */ +// /* run_programmed_car(&cur_mode_stop); */ +// /* else if(cur_mode == CAR_MODE_REMOTE_CONTROL) */ +// /* run_rc_car(&cur_mode_stop); */ +// +// /* cur_mode = (cur_mode + 1) % CAR_MODE_LAST; */ +// /* cur_mode_stop = false; */ +// /* } */ +//} diff --git a/car_hw/src/stm32_flash.ld b/car_hw/src/stm32_flash.ld deleted file mode 100644 index 9a10d57b3c1..00000000000 --- a/car_hw/src/stm32_flash.ld +++ /dev/null @@ -1,177 +0,0 @@ -/* -***************************************************************************** -** -** File : stm32_flash.ld -** -** Abstract : Linker script for STM32F407VG Device with -** 1024KByte FLASH, 192KByte RAM -** -** Set heap size, stack size and stack location according -** to application requirements. -** -** Set memory bank area and size if external memory is used. -** -** Target : STMicroelectronics STM32 -** -** Environment : Atollic TrueSTUDIO(R) -** -** Distribution: The file is distributed “as is,” without any warranty -** of any kind. -** -** (c)Copyright Atollic AB. -** You may use this file as-is or modify it according to the needs of your -** project. Distribution of this file (unmodified or modified) is not -** permitted. Atollic AB permit registered Atollic TrueSTUDIO(R) users the -** rights to distribute the assembled, compiled & linked contents of this -** file as part of an application binary file, provided that it is built -** using the Atollic TrueSTUDIO(R) toolchain. -** -***************************************************************************** -*/ - -/* Entry Point */ -ENTRY(Reset_Handler) - -/* - * _estack is the highest address of user mode stack - * (sp initial value, stack grows down). - * We have 192K RAM on our MCU and _estack should be 0x20030000. - * But our MCU maps only 128K SRAM at 0x20000000 after boot. - * We need to perform some memory remapping to use more. - * This isn't implemented yet. - */ -_estack = 0x20020000; /* end of 128K SRAM region */ - -/* Generate a link error if heap and stack don't fit into RAM */ -_Min_Heap_Size = 0; /* required amount of heap */ -_Min_Stack_Size = 0x400; /* required amount of stack */ - -/* Specify the memory areas */ -MEMORY -{ - FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K - RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K - MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K -} - -/* Define output sections */ -SECTIONS -{ - /* The startup code goes first into FLASH */ - .isr_vector : - { - . = ALIGN(4); - KEEP(*(.isr_vector)) /* Startup code */ - . = ALIGN(4); - } >FLASH - - /* The program code and other data goes into FLASH */ - .text : - { - . = ALIGN(4); - *(.text) /* .text sections (code) */ - *(.text*) /* .text* sections (code) */ - *(.rodata) /* .rodata sections (constants, strings, etc.) */ - *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ - *(.glue_7) /* glue arm to thumb code */ - *(.glue_7t) /* glue thumb to arm code */ - *(.eh_frame) - - KEEP (*(.init)) - KEEP (*(.fini)) - - . = ALIGN(4); - _etext = .; /* define a global symbols at end of code */ - } >FLASH - - - .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH - .ARM : { - __exidx_start = .; - *(.ARM.exidx*) - __exidx_end = .; - } >FLASH - - .preinit_array : - { - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP (*(.preinit_array*)) - PROVIDE_HIDDEN (__preinit_array_end = .); - } >FLASH - .init_array : - { - PROVIDE_HIDDEN (__init_array_start = .); - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array*)) - PROVIDE_HIDDEN (__init_array_end = .); - } >FLASH - .fini_array : - { - PROVIDE_HIDDEN (__fini_array_start = .); - KEEP (*(.fini_array*)) - KEEP (*(SORT(.fini_array.*))) - PROVIDE_HIDDEN (__fini_array_end = .); - } >FLASH - - /* used by the startup to initialize data */ - _sidata = .; - - /* Initialized data sections goes into RAM, load LMA copy after code */ - .data : AT ( _sidata ) - { - . = ALIGN(4); - _sdata = .; /* create a global symbol at data start */ - *(.data) /* .data sections */ - *(.data*) /* .data* sections */ - - . = ALIGN(4); - _edata = .; /* define a global symbol at data end */ - } >RAM - - /* Uninitialized data section */ - . = ALIGN(4); - .bss : - { - /* This is used by the startup in order to initialize the .bss secion */ - _sbss = .; /* define a global symbol at bss start */ - __bss_start__ = _sbss; - *(.bss) - *(.bss*) - *(COMMON) - - . = ALIGN(4); - _ebss = .; /* define a global symbol at bss end */ - __bss_end__ = _ebss; - } >RAM - - /* User_heap_stack section, used to check that there is enough RAM left */ - ._user_heap_stack : - { - . = ALIGN(4); - PROVIDE ( end = . ); - PROVIDE ( _end = . ); - . = . + _Min_Heap_Size; - . = . + _Min_Stack_Size; - . = ALIGN(4); - } >RAM - - /* MEMORY_bank1 section, code must be located here explicitly */ - /* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */ - .memory_b1_text : - { - *(.mb1text) /* .mb1text sections (code) */ - *(.mb1text*) /* .mb1text* sections (code) */ - *(.mb1rodata) /* read-only data (constants) */ - *(.mb1rodata*) - } >MEMORY_B1 - - /* Remove information from the standard libraries */ - /DISCARD/ : - { - libc.a ( * ) - libm.a ( * ) - libgcc.a ( * ) - } - - .ARM.attributes 0 : { *(.ARM.attributes) } -} diff --git a/car_hw/src/time.c b/car_hw/src/time.c index d231768fe37..071b3a9bc0a 100644 --- a/car_hw/src/time.c +++ b/car_hw/src/time.c @@ -1,4 +1,5 @@ #include + #include "time.h" static volatile uint32_t pending_timer_ticks, ticks_since_boot;