translator: working firmware, car_hw includes, blink and engines from kotlin
This commit is contained in:
+3
-3
@@ -5,12 +5,12 @@ TRANSLATOR_DIR=$(PWD)/../translator
|
|||||||
KOTSTD_DIR=$(PWD)/../kotstd
|
KOTSTD_DIR=$(PWD)/../kotstd
|
||||||
CAR_HW_DIR=$(PWD)/../car_hw
|
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_OBJ=$(BIN_DIR)/car_fmw.o
|
||||||
CAR_FMW_ELF=$(BIN_DIR)/car_fmw.elf
|
CAR_FMW_ELF=$(BIN_DIR)/car_fmw.elf
|
||||||
CAR_FMW_BIN=$(BIN_DIR)/car_fmw.bin
|
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_KOT=$(BIN_DIR)/kotlib.o
|
||||||
LIB_KOTSTD=$(KOTSTD_DIR)/build/stdlib_arm.ll
|
LIB_KOTSTD=$(KOTSTD_DIR)/build/stdlib_arm.ll
|
||||||
@@ -67,7 +67,7 @@ $(BIN_DIR)/kotlib.ll: $(LIB_DIR)/app.ll $(LIB_KOTSTD)
|
|||||||
$(LIB_KOTSTD):
|
$(LIB_KOTSTD):
|
||||||
cd $(KOTSTD_DIR) && make
|
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_ALL_DEPS)
|
||||||
|
|
||||||
$(KT):
|
$(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()
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
fun init() {
|
||||||
|
time_init()
|
||||||
|
engine_init()
|
||||||
|
leds_init()
|
||||||
|
}
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
external fun time_init()
|
||||||
|
|
||||||
|
external fun wait(msec: Int)
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
external fun user_btn_init(handler: () -> Unit)
|
||||||
|
external fun user_btn_is_pushed(): Boolean
|
||||||
|
external fun EXTI0_IRQHandler()
|
||||||
+3
-54
@@ -1,56 +1,5 @@
|
|||||||
external fun time_init()
|
|
||||||
|
|
||||||
external fun leds_init()
|
fun main() {
|
||||||
|
init()
|
||||||
external fun engine_init()
|
simpleRoute()
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-1
@@ -36,7 +36,9 @@ INCLUDES=-I$(LIB_CMSIS_DIR) \
|
|||||||
-I$(LIB_USB_OTG_DIR) \
|
-I$(LIB_USB_OTG_DIR) \
|
||||||
-I$(LIB_USB_VCP_DIR) \
|
-I$(LIB_USB_VCP_DIR) \
|
||||||
-I$(USB_CONF_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
|
DEFINES=-DUSE_STM32_DISCOVERY=1 -DUSE_STDPERIPH_DRIVER=1 -DSTM32F4XX=1 -DHSE_VALUE=8000000
|
||||||
CFLAGS=-g -nostdlib -ffreestanding -O0 \
|
CFLAGS=-g -nostdlib -ffreestanding -O0 \
|
||||||
-mcpu=cortex-m3 -mfloat-abi=soft -mthumb \
|
-mcpu=cortex-m3 -mfloat-abi=soft -mthumb \
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "car_engine.h"
|
#include "car_engine.h"
|
||||||
|
|
||||||
#include "stm32f4_discovery.h"
|
#include "stm32f4_discovery.h"
|
||||||
#include "stm32f4xx_conf.h"
|
#include "stm32f4xx_conf.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "car_leds.h"
|
#include "car_leds.h"
|
||||||
|
|
||||||
#include "stm32f4_discovery.h"
|
#include "stm32f4_discovery.h"
|
||||||
#include "stm32f4xx_conf.h"
|
#include "stm32f4xx_conf.h"
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ void leds_init(void)
|
|||||||
STM_EVAL_LEDInit(LED_BLUE);
|
STM_EVAL_LEDInit(LED_BLUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_set(led_t led, bool on)
|
void led_set(int led, bool on)
|
||||||
{
|
{
|
||||||
if (on)
|
if (on)
|
||||||
STM_EVAL_LEDOn(led);
|
STM_EVAL_LEDOn(led);
|
||||||
|
|||||||
@@ -3,10 +3,11 @@
|
|||||||
|
|
||||||
#include "car_leds.h"
|
#include "car_leds.h"
|
||||||
#include "car_engine.h"
|
#include "car_engine.h"
|
||||||
#include "time.h"
|
|
||||||
#include "car_prog.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)
|
static void program_stop(void)
|
||||||
{
|
{
|
||||||
wait(PROGRAM_DURATION_MS);
|
wait(PROGRAM_DURATION_MS);
|
||||||
|
|||||||
@@ -13,4 +13,4 @@ typedef enum
|
|||||||
|
|
||||||
void leds_init(void);
|
void leds_init(void);
|
||||||
void leds_clear_all(void);
|
void leds_clear_all(void);
|
||||||
void led_set(led_t led, bool on);
|
void led_set(int led, bool on);
|
||||||
+35
-34
@@ -1,10 +1,14 @@
|
|||||||
/* #include <stddef.h> */
|
#include <stddef.h>
|
||||||
/* #include <stdbool.h> */
|
#include <stdbool.h>
|
||||||
|
|
||||||
/* #include "car_leds.h" */
|
#include "car_engine.h"
|
||||||
/* #include "car_engine.h" */
|
#include "car_leds.h"
|
||||||
/* #include "time.h" */
|
#include "car_rc.h"
|
||||||
/* #include "car_user_btn.h" */
|
#include "car_user_btn.h"
|
||||||
|
#include "time.h"
|
||||||
|
|
||||||
|
#include "stm32f4xx_conf.h"
|
||||||
|
#include "stm32f4xx_it.h"
|
||||||
|
|
||||||
/* typedef enum { */
|
/* typedef enum { */
|
||||||
/* CAR_MODE_PROGRAMMED, */
|
/* CAR_MODE_PROGRAMMED, */
|
||||||
@@ -19,31 +23,28 @@
|
|||||||
/* cur_mode_stop = true; */
|
/* cur_mode_stop = true; */
|
||||||
/* } */
|
/* } */
|
||||||
|
|
||||||
extern void kotlin_main();
|
//int main(void)
|
||||||
|
//{
|
||||||
int main(void)
|
// /*!< At this stage the microcontroller clock setting is already configured,
|
||||||
{
|
// this is done through SystemInit() function which is called from startup
|
||||||
kotlin_main();
|
// file (startup_stm32f4xx.s) before to branch to application main.
|
||||||
/*!< At this stage the microcontroller clock setting is already configured,
|
// To reconfigure the default setting of SystemInit() function, refer to
|
||||||
this is done through SystemInit() function which is called from startup
|
// system_stm32f4xx.c file
|
||||||
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(); */
|
||||||
/* time_init(); */
|
// /* user_btn_init(stop_cur_mode); */
|
||||||
/* leds_init(); */
|
// /* VCP_init(); */
|
||||||
/* engine_init(); */
|
//
|
||||||
/* user_btn_init(stop_cur_mode); */
|
// /* while(1) { */
|
||||||
/* VCP_init(); */
|
// /* if (cur_mode == CAR_MODE_PROGRAMMED) */
|
||||||
|
// /* run_programmed_car(&cur_mode_stop); */
|
||||||
/* while(1) { */
|
// /* else if(cur_mode == CAR_MODE_REMOTE_CONTROL) */
|
||||||
/* if (cur_mode == CAR_MODE_PROGRAMMED) */
|
// /* run_rc_car(&cur_mode_stop); */
|
||||||
/* run_programmed_car(&cur_mode_stop); */
|
//
|
||||||
/* else if(cur_mode == CAR_MODE_REMOTE_CONTROL) */
|
// /* cur_mode = (cur_mode + 1) % CAR_MODE_LAST; */
|
||||||
/* run_rc_car(&cur_mode_stop); */
|
// /* cur_mode_stop = false; */
|
||||||
|
// /* } */
|
||||||
/* cur_mode = (cur_mode + 1) % CAR_MODE_LAST; */
|
//}
|
||||||
/* cur_mode_stop = false; */
|
|
||||||
/* } */
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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) }
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <stm32f4xx.h>
|
#include <stm32f4xx.h>
|
||||||
|
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
|
|
||||||
static volatile uint32_t pending_timer_ticks, ticks_since_boot;
|
static volatile uint32_t pending_timer_ticks, ticks_since_boot;
|
||||||
|
|||||||
Reference in New Issue
Block a user