summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <Colomar.6.4.3@GMail.com>2019-01-12 00:13:57 +0100
committerGitHub <noreply@github.com>2019-01-12 00:13:57 +0100
commitf937f279b1c4ec01a1f92678b82b9b841d5a540d (patch)
tree9bef123a1bab44fcb918e6dd318d65cfd459837d
parent795820720ca6c87b9bf543ed1d6b4d5aa6c50ca1 (diff)
Stable 1.0
-rw-r--r--COPYING.txt121
-rw-r--r--Makefile235
-rw-r--r--README.txt2
-rw-r--r--bin/Makefile84
-rw-r--r--bin/STM32L476RG.ld184
-rw-r--r--inc/actuators.h70
-rw-r--r--inc/ctrl.h70
-rw-r--r--src/actuators.c244
-rw-r--r--src/ctrl.c273
-rw-r--r--src/main.c184
-rw-r--r--src/startup_stm32l476xx.s524
-rw-r--r--src/stm32l4xx_it.c146
-rw-r--r--src/system_stm32l4xx.c363
-rw-r--r--tmp/Makefile138
14 files changed, 2638 insertions, 0 deletions
diff --git a/COPYING.txt b/COPYING.txt
new file mode 100644
index 0000000..0e259d4
--- /dev/null
+++ b/COPYING.txt
@@ -0,0 +1,121 @@
+Creative Commons Legal Code
+
+CC0 1.0 Universal
+
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
+ HEREUNDER.
+
+Statement of Purpose
+
+The laws of most jurisdictions throughout the world automatically confer
+exclusive Copyright and Related Rights (defined below) upon the creator
+and subsequent owner(s) (each and all, an "owner") of an original work of
+authorship and/or a database (each, a "Work").
+
+Certain owners wish to permanently relinquish those rights to a Work for
+the purpose of contributing to a commons of creative, cultural and
+scientific works ("Commons") that the public can reliably and without fear
+of later claims of infringement build upon, modify, incorporate in other
+works, reuse and redistribute as freely as possible in any form whatsoever
+and for any purposes, including without limitation commercial purposes.
+These owners may contribute to the Commons to promote the ideal of a free
+culture and the further production of creative, cultural and scientific
+works, or to gain reputation or greater distribution for their Work in
+part through the use and efforts of others.
+
+For these and/or other purposes and motivations, and without any
+expectation of additional consideration or compensation, the person
+associating CC0 with a Work (the "Affirmer"), to the extent that he or she
+is an owner of Copyright and Related Rights in the Work, voluntarily
+elects to apply CC0 to the Work and publicly distribute the Work under its
+terms, with knowledge of his or her Copyright and Related Rights in the
+Work and the meaning and intended legal effect of CC0 on those rights.
+
+1. Copyright and Related Rights. A Work made available under CC0 may be
+protected by copyright and related or neighboring rights ("Copyright and
+Related Rights"). Copyright and Related Rights include, but are not
+limited to, the following:
+
+ i. the right to reproduce, adapt, distribute, perform, display,
+ communicate, and translate a Work;
+ ii. moral rights retained by the original author(s) and/or performer(s);
+iii. publicity and privacy rights pertaining to a person's image or
+ likeness depicted in a Work;
+ iv. rights protecting against unfair competition in regards to a Work,
+ subject to the limitations in paragraph 4(a), below;
+ v. rights protecting the extraction, dissemination, use and reuse of data
+ in a Work;
+ vi. database rights (such as those arising under Directive 96/9/EC of the
+ European Parliament and of the Council of 11 March 1996 on the legal
+ protection of databases, and under any national implementation
+ thereof, including any amended or successor version of such
+ directive); and
+vii. other similar, equivalent or corresponding rights throughout the
+ world based on applicable law or treaty, and any national
+ implementations thereof.
+
+2. Waiver. To the greatest extent permitted by, but not in contravention
+of, applicable law, Affirmer hereby overtly, fully, permanently,
+irrevocably and unconditionally waives, abandons, and surrenders all of
+Affirmer's Copyright and Related Rights and associated claims and causes
+of action, whether now known or unknown (including existing as well as
+future claims and causes of action), in the Work (i) in all territories
+worldwide, (ii) for the maximum duration provided by applicable law or
+treaty (including future time extensions), (iii) in any current or future
+medium and for any number of copies, and (iv) for any purpose whatsoever,
+including without limitation commercial, advertising or promotional
+purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
+member of the public at large and to the detriment of Affirmer's heirs and
+successors, fully intending that such Waiver shall not be subject to
+revocation, rescission, cancellation, termination, or any other legal or
+equitable action to disrupt the quiet enjoyment of the Work by the public
+as contemplated by Affirmer's express Statement of Purpose.
+
+3. Public License Fallback. Should any part of the Waiver for any reason
+be judged legally invalid or ineffective under applicable law, then the
+Waiver shall be preserved to the maximum extent permitted taking into
+account Affirmer's express Statement of Purpose. In addition, to the
+extent the Waiver is so judged Affirmer hereby grants to each affected
+person a royalty-free, non transferable, non sublicensable, non exclusive,
+irrevocable and unconditional license to exercise Affirmer's Copyright and
+Related Rights in the Work (i) in all territories worldwide, (ii) for the
+maximum duration provided by applicable law or treaty (including future
+time extensions), (iii) in any current or future medium and for any number
+of copies, and (iv) for any purpose whatsoever, including without
+limitation commercial, advertising or promotional purposes (the
+"License"). The License shall be deemed effective as of the date CC0 was
+applied by Affirmer to the Work. Should any part of the License for any
+reason be judged legally invalid or ineffective under applicable law, such
+partial invalidity or ineffectiveness shall not invalidate the remainder
+of the License, and in such case Affirmer hereby affirms that he or she
+will not (i) exercise any of his or her remaining Copyright and Related
+Rights in the Work or (ii) assert any associated claims and causes of
+action with respect to the Work, in either case contrary to Affirmer's
+express Statement of Purpose.
+
+4. Limitations and Disclaimers.
+
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
+ surrendered, licensed or otherwise affected by this document.
+ b. Affirmer offers the Work as-is and makes no representations or
+ warranties of any kind concerning the Work, express, implied,
+ statutory or otherwise, including without limitation warranties of
+ title, merchantability, fitness for a particular purpose, non
+ infringement, or the absence of latent or other defects, accuracy, or
+ the present or absence of errors, whether or not discoverable, all to
+ the greatest extent permissible under applicable law.
+ c. Affirmer disclaims responsibility for clearing rights of other persons
+ that may apply to the Work or any use thereof, including without
+ limitation any person's Copyright and Related Rights in the Work.
+ Further, Affirmer disclaims responsibility for obtaining any necessary
+ consents, permissions or other rights required for any use of the
+ Work.
+ d. Affirmer understands and acknowledges that Creative Commons is not a
+ party to this document and has no duty or obligation with respect to
+ this CC0 or use of the Work.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e7c03dc
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,235 @@
+#!/usr/bin/make -f
+
+VERSION = 0
+PATCHLEVEL = .5
+SUBLEVEL =
+EXTRAVERSION =
+
+export VERSION
+export PATCHLEVEL
+export SUBLEVEL
+
+################################################################################
+# Project template for development board STM32F0Discovery
+# Uses libraries HAL, which are placed in dedicated
+# directory (where is also Makefile for them)
+# Andrej Bendzo <andrej.sl@azet.sk>
+# 2016.08.11
+#
+# Modified for development board STM32L476xx
+# Colomar Andrés, Alejandro <1903716@gmail.com>
+# García Pedroche, Francisco Javier <@.>
+# 2018
+################################################################################
+
+# This Makefile contains:
+# rule "flash", which is intended for writing of program into MCU,
+# rule "erase" for erasing Flash memory of MCU
+# rule "reset" for system resetting of MCU.
+
+################################################################################
+# Beautify output
+# ---------------------------------------------------------------------------
+# Prefix commands with $(Q) - that's useful
+# for commands that shall be hidden in non-verbose mode.
+#
+# $(Q)some command here
+#
+# If BUILD_VERBOSE equals 0 then the above command will be hidden.
+# If BUILD_VERBOSE equals 1 then the above command is displayed.
+#
+# To put more focus on warnings, be less verbose as default
+# Use 'make V=1' to see the full commands
+
+ifeq ("$(origin V)","command line")
+ BUILD_VERBOSE = $(V)
+endif
+ifndef BUILD_VERBOSE
+ BUILD_VERBOSE = 0
+endif
+
+ifeq ($(BUILD_VERBOSE), 1)
+ Q =
+else
+ Q = @
+endif
+
+# If the user is running make -s (silent mode), suppress echoing of
+# commands
+
+ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
+ Q = @
+endif
+
+export Q
+export BUILD_VERBOSE
+
+################################################################################
+# Do not print "Entering directory ...",
+# but we want to display it when entering to the output directory
+# so that IDEs/editors are able to understand relative filenames.
+MAKEFLAGS += --no-print-directory
+
+################################################################################
+PROGRAMVERSION = $(VERSION)$(if $(PATCHLEVEL),$(PATCHLEVEL)$(if $(SUBLEVEL),$(SUBLEVEL)))$(EXTRAVERSION)
+export PROGRAMVERSION
+
+################################################################################
+
+
+
+
+# ***** Basic settings of project *****
+# ==============================================================================
+
+# all the files will be generated with this name (main.elf, main.bin, main.hex, etc)
+PROJECT_NAME = main
+
+export PROJECT_NAME
+
+# ==============================================================================
+
+################################################################################
+# directories
+
+MAIN_DIR = $(CURDIR)
+LIBALX_DIR = $(MAIN_DIR)/libalx/
+DRIVERS_DIR = $(MAIN_DIR)/stm32l4-drivers/
+MODULES_DIR = $(MAIN_DIR)/stm32l4-modules/
+SRC_DIR = $(MAIN_DIR)/src/
+INC_DIR = $(MAIN_DIR)/inc/
+DEP_DIR = $(MAIN_DIR)/dep/
+TMP_DIR = $(MAIN_DIR)/tmp/
+BIN_DIR = $(MAIN_DIR)/bin/
+
+export MAIN_DIR
+export LIBALX_DIR
+export DRIVERS_DIR
+export MODULES_DIR
+
+
+################################################################################
+# Make variables (CC, etc...)
+CC = arm-none-eabi-gcc
+AS = arm-none-eabi-as
+AR = arm-none-eabi-ar
+GDB = arm-none-eabi-gdb
+OBJCOPY = arm-none-eabi-objcopy
+OBJDUMP = arm-none-eabi-objdump
+SIZE = arm-none-eabi-size
+
+export CC
+export AS
+export AR
+export GDB
+export OBJCOPY
+export OBJDUMP
+export SIZE
+
+
+################################################################################
+# CFLAGS
+CFLAGS_STD = -std=c11
+
+CFLAGS_OPT = -Os
+
+CFLAGS_MCU = -mlittle-endian
+CFLAGS_MCU += -march=armv7e-m
+CFLAGS_MCU += -mcpu=cortex-m4
+CFLAGS_MCU += -mthumb
+CFLAGS_MCU += -mfpu=fpv4-sp-d16
+CFLAGS_MCU += -mfloat-abi=hard
+
+CFLAGS_W = -Wall
+CFLAGS_W += -Wextra
+CFLAGS_W += -Wstrict-prototypes
+CFLAGS_W += -Werror
+
+CFLAGS_F = -ffreestanding
+CFLAGS_F += -flto
+CFLAGS_F += -fsingle-precision-constant
+CFLAGS_F += -ffunction-sections
+CFLAGS_F += -fdata-sections
+
+# defining used MCU (instead of in file stm32f00x.h): -DSTM32F051x8//
+CFLAGS_D = -D USE_HAL_DRIVER # to include file stm32l4xx_hal.h
+
+CFLAGS = $(CFLAGS_STD)
+CFLAGS += $(CFLAGS_OPT)
+CFLAGS += $(CFLAGS_MCU)
+CFLAGS += $(CFLAGS_W)
+CFLAGS += $(CFLAGS_F)
+CFLAGS += $(CFLAGS_D)
+CFLAGS += $(C_INCLUDES)
+
+export CFLAGS
+
+
+################################################################################
+# LDFLAGS
+# Settings of linker
+LDFLAGS = -mcpu=cortex-m4 -mthumb
+LDFLAGS += -Wl,--gc-sections -Wl,-Map=$(PROJECT_NAME).map,--cref,--no-warn-mismatch
+
+export LDFLAGS
+
+
+################################################################################
+
+
+.PHONY: all stm32l4-drivers libalx stm32l4-modules objects target flash erase reset clean mrproper
+
+all: stm32l4-drivers libalx stm32l4-modules objects target
+
+stm32l4-drivers:
+ @echo ' MAKE drivers'
+ $(Q)$(MAKE) -C $(DRIVERS_DIR)
+
+libalx:
+ @echo ' MAKE libalx'
+ $(Q)$(MAKE) base -C $(LIBALX_DIR)
+
+stm32l4-modules:
+ @echo ' MAKE modules'
+ $(Q)$(MAKE) -C $(MODULES_DIR)
+
+objects:
+ @echo " MAKE objects"
+ $(Q)$(MAKE) -C $(TMP_DIR)
+
+target:
+ @echo " MAKE target"
+ $(Q)$(MAKE) -C $(BIN_DIR)
+
+
+flash:
+ openocd -f board/stm32l4nucleo.cfg -c "program $(BIN_DIR)/$(PROJECT_NAME).hex verify reset exit"
+#second approach: openocd -f board/stm32f0discovery.cfg -c "init" -c "reset halt" -c "flash write_image erase $(BINDIR)/$(PROJECT_NAME).hex" -c "verify_image $(BINDIR)/$(PROJECT_NAME).hex" -c "reset run" -c "exit"
+#third approach: openocd -f interface/stlink-v2.cfg -f target/stm32f0x_stlink.cfg -c "init" -c "reset halt" -c "flash write_image erase $(BINDIR)/$(PROJECT_NAME).hex" -c "verify_image $(BINDIR)/$(PROJECT_NAME).hex" -c "reset run" -c "exit"
+
+erase:
+ openocd -f board/stm32l4nucleo.cfg -c "init" -c "reset halt" -c "stm32l4x mass_erase 0" -c "reset" -c "shutdown"
+
+reset:
+ openocd -f board/stm32l4nucleo.cfg -c "init" -c "reset" -c "shutdown"
+
+clean:
+ @echo ' CLEAN bin'
+ $(Q)$(MAKE) clean -C $(BIN_DIR)
+ @echo ' CLEAN tmp'
+ $(Q)$(MAKE) clean -C $(TMP_DIR)
+
+mrproper: clean
+ @echo ' CLEAN modules'
+ $(Q)$(MAKE) clean -C $(MODULES_DIR)
+ @echo ' CLEAN libalx'
+ $(Q)$(MAKE) clean -C $(LIBALX_DIR)
+ @echo ' CLEAN drivers'
+ $(Q)$(MAKE) clean -C $(DRIVERS_DIR)
+
+
+
+
+################################################################################
+######## End of file ###########################################################
+################################################################################
diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..0a26051
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,2 @@
+# sistemas-embebidos-p6
+sistemas-embebidos-p6
diff --git a/bin/Makefile b/bin/Makefile
new file mode 100644
index 0000000..80a970a
--- /dev/null
+++ b/bin/Makefile
@@ -0,0 +1,84 @@
+#!/usr/bin/make -f
+
+
+################################################################################
+# directories
+
+LIBALX_LIB_DIR = $(LIBALX_DIR)/lib/
+DRIVERS_LIB_DIR = $(DRIVERS_DIR)/lib/
+MODULES_LIB_DIR = $(MODULES_DIR)/lib/
+
+SRC_DIR = $(MAIN_DIR)/src/
+TMP_DIR = $(MAIN_DIR)/tmp/
+
+################################################################################
+# dependencies
+ALL = $(PROJECT_NAME).elf $(PROJECT_NAME).hex $(PROJECT_NAME).lst size
+
+MAIN_OBJ_MODULES = \
+ system_stm32l4xx.o stm32l4xx_it.o main.o \
+ ctrl.o actuators.o
+MAIN_OBJS = $(patsubst %,$(TMP_DIR)/%,$(MAIN_OBJ_MODULES))
+
+
+MAIN_LIB_LIBALX = libalx-base.a
+MAIN_LIB_DRIVERS = libstm32l4.a
+MAIN_LIB_MODULES = \
+ libstm32l4-modules-test.a \
+ libstm32l4-modules-dev.a \
+ libstm32l4-modules-base.a
+MAIN_LIBS = \
+ $(patsubst %,$(LIBALX_LIB_DIR)/%,$(MAIN_LIB_LIBALX)) \
+ $(patsubst %,$(DRIVERS_LIB_DIR)/%,$(MAIN_LIB_DRIVERS)) \
+ $(patsubst %,$(MODULES_LIB_DIR)/%,$(MAIN_LIB_MODULES))
+
+# static libs
+STATIC_LIB_MODULES = -L $(MODULES_LIB_DIR) \
+ -l stm32l4-modules-test \
+ -l stm32l4-modules-dev \
+ -l stm32l4-modules-base
+STATIC_LIB_DRIVERS = -L $(DRIVERS_LIB_DIR) -l stm32l4
+STATIC_LIB_LIBALX = -L $(LIBALX_LIB_DIR) -l alx-base
+
+STATIC_LIBS = $(STATIC_LIB_MODULES)
+STATIC_LIBS += $(STATIC_LIB_DRIVERS)
+STATIC_LIBS += $(STATIC_LIB_LIBALX)
+
+
+# target: dependencies
+# action
+
+all: $(ALL)
+
+
+$(PROJECT_NAME).elf: $(MAIN_OBJS) $(MAIN_LIBS)
+ @echo " CC $@"
+ $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(MAIN_OBJS) -o $@ \
+ $(SRC_DIR)/startup_stm32l476xx.s\
+ $(STATIC_LIBS) $(LIBS) -TSTM32L476RG.ld
+
+$(PROJECT_NAME).hex: $(PROJECT_NAME).elf
+ @echo " OBJCOPY $@"
+ $(Q)$(OBJCOPY) -O ihex $(PROJECT_NAME).elf $@
+
+$(PROJECT_NAME).bin: $(PROJECT_NAME).elf
+ @echo " OBJCOPY $@"
+ $(Q)$(OBJCOPY) -O binary $(PROJECT_NAME).elf $@
+
+$(PROJECT_NAME).lst: $(PROJECT_NAME).elf
+ @echo " OBJDUMP $@"
+ $(Q)$(OBJDUMP) -St $(PROJECT_NAME).elf > $@
+
+size: $(PROJECT_NAME).elf
+ @echo " SIZE $<"
+ $(Q)$(SIZE) -B $(PROJECT_NAME).elf
+
+
+clean:
+ @echo " RM $(ALL)"
+ $(Q)rm -f $(ALL)
+ $(Q)rm -f *.map
+
+################################################################################
+######## End of file ###########################################################
+################################################################################
diff --git a/bin/STM32L476RG.ld b/bin/STM32L476RG.ld
new file mode 100644
index 0000000..4543da3
--- /dev/null
+++ b/bin/STM32L476RG.ld
@@ -0,0 +1,184 @@
+/*
+*****************************************************************************
+**
+
+** File : LinkerScript.ld
+**
+** Abstract : Linker script for STM32L476RGTx Device with
+** 1024KByte FLASH, 128KByte 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
+**
+**
+** Distribution: The file is distributed as is, without any warranty
+** of any kind.
+**
+** (c)Copyright Ac6.
+** 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. Ac6 permit registered System Workbench for MCU 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 System Workbench for MCU toolchain.
+**
+*****************************************************************************
+*/
+
+/* Entry Point */
+ENTRY(Reset_Handler)
+
+/* Highest address of the user mode stack */
+_estack = 0x20018000; /* end of RAM */
+/* Generate a link error if heap and stack don't fit into RAM */
+_Min_Heap_Size = 0x200; /* required amount of heap */
+_Min_Stack_Size = 0x400; /* required amount of stack */
+
+/* Specify the memory areas */
+MEMORY
+{
+RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
+RAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 32K
+FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
+}
+
+/* Define output sections */
+SECTIONS
+{
+ /* The startup code goes first into FLASH */
+ .isr_vector :
+ {
+ . = ALIGN(8);
+ KEEP(*(.isr_vector)) /* Startup code */
+ . = ALIGN(8);
+ } >FLASH
+
+ /* The program code and other data goes into FLASH */
+ .text :
+ {
+ . = ALIGN(8);
+ *(.text) /* .text sections (code) */
+ *(.text*) /* .text* sections (code) */
+ *(.glue_7) /* glue arm to thumb code */
+ *(.glue_7t) /* glue thumb to arm code */
+ *(.eh_frame)
+
+ KEEP (*(.init))
+ KEEP (*(.fini))
+
+ . = ALIGN(8);
+ _etext = .; /* define a global symbols at end of code */
+ } >FLASH
+
+ /* Constant data goes into FLASH */
+ .rodata :
+ {
+ . = ALIGN(8);
+ *(.rodata) /* .rodata sections (constants, strings, etc.) */
+ *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
+ . = ALIGN(8);
+ } >FLASH
+
+ .ARM.extab :
+ {
+ . = ALIGN(8);
+ *(.ARM.extab* .gnu.linkonce.armextab.*)
+ . = ALIGN(8);
+ } >FLASH
+ .ARM : {
+ . = ALIGN(8);
+ __exidx_start = .;
+ *(.ARM.exidx*)
+ __exidx_end = .;
+ . = ALIGN(8);
+ } >FLASH
+
+ .preinit_array :
+ {
+ . = ALIGN(8);
+ PROVIDE_HIDDEN (__preinit_array_start = .);
+ KEEP (*(.preinit_array*))
+ PROVIDE_HIDDEN (__preinit_array_end = .);
+ . = ALIGN(8);
+ } >FLASH
+
+ .init_array :
+ {
+ . = ALIGN(8);
+ PROVIDE_HIDDEN (__init_array_start = .);
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array*))
+ PROVIDE_HIDDEN (__init_array_end = .);
+ . = ALIGN(8);
+ } >FLASH
+ .fini_array :
+ {
+ . = ALIGN(8);
+ PROVIDE_HIDDEN (__fini_array_start = .);
+ KEEP (*(SORT(.fini_array.*)))
+ KEEP (*(.fini_array*))
+ PROVIDE_HIDDEN (__fini_array_end = .);
+ . = ALIGN(8);
+ } >FLASH
+
+ /* used by the startup to initialize data */
+ _sidata = LOADADDR(.data);
+
+ /* Initialized data sections goes into RAM, load LMA copy after code */
+ .data :
+ {
+ . = ALIGN(8);
+ _sdata = .; /* create a global symbol at data start */
+ *(.data) /* .data sections */
+ *(.data*) /* .data* sections */
+
+ . = ALIGN(8);
+ _edata = .; /* define a global symbol at data end */
+ } >RAM AT> FLASH
+
+
+ /* 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(8);
+ PROVIDE ( end = . );
+ PROVIDE ( _end = . );
+ . = . + _Min_Heap_Size;
+ . = . + _Min_Stack_Size;
+ . = ALIGN(8);
+ } >RAM
+
+
+
+ /* Remove information from the standard libraries */
+ /DISCARD/ :
+ {
+ libc.a ( * )
+ libm.a ( * )
+ libgcc.a ( * )
+ }
+
+ .ARM.attributes 0 : { *(.ARM.attributes) }
+}
+
+
diff --git a/inc/actuators.h b/inc/actuators.h
new file mode 100644
index 0000000..c507330
--- /dev/null
+++ b/inc/actuators.h
@@ -0,0 +1,70 @@
+/******************************************************************************
+ * Copyright (C) 2018 Colomar Andrés, Alejandro *
+ * Copyright (C) 2018 García Pedroche, Francisco Javier *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+/**
+ * @file actuators.h
+ * @author Colomar Andrés, Alejandro
+ * @author García Pedroche, Francisco Javier
+ * @copyright GPL-2.0-only
+ * @date 2018/dec/26
+ * @brief Actuators
+ */
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# ifndef ACTUATORS_H
+ # define ACTUATORS_H
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* Standard C ----------------------------------------------------------------*/
+/* Drivers -------------------------------------------------------------------*/
+/* libalx --------------------------------------------------------------------*/
+/* STM32L4 modules -----------------------------------------------------------*/
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+ # define REFRESH_FREQ (50u)
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs **************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+int proc_actuators_init (void);
+int proc_actuators_1 (void);
+int proc_actuators_2 (void);
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# endif /* actuators.h */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/inc/ctrl.h b/inc/ctrl.h
new file mode 100644
index 0000000..6bbad56
--- /dev/null
+++ b/inc/ctrl.h
@@ -0,0 +1,70 @@
+/******************************************************************************
+ * Copyright (C) 2018 Colomar Andrés, Alejandro *
+ * Copyright (C) 2018 García Pedroche, Francisco Javier *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+/**
+ * @file ctrl.h
+ * @author Colomar Andrés, Alejandro
+ * @author García Pedroche, Francisco Javier
+ * @copyright GPL-2.0-only
+ * @date 2018/dec/26
+ * @brief Control
+ */
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# ifndef CTRL_H
+ # define CTRL_H
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* Standard C ----------------------------------------------------------------*/
+/* Drivers -------------------------------------------------------------------*/
+/* libalx --------------------------------------------------------------------*/
+/* STM32L4 modules -----------------------------------------------------------*/
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+ # define REFRESH_FREQ (50u)
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs **************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+int proc_ctrl_init (void);
+int proc_ctrl_1 (void);
+int proc_ctrl_2 (void);
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# endif /* ctrl.h */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/src/actuators.c b/src/actuators.c
new file mode 100644
index 0000000..c4f2b9c
--- /dev/null
+++ b/src/actuators.c
@@ -0,0 +1,244 @@
+/******************************************************************************
+ * Copyright (C) 2018 Colomar Andrés, Alejandro *
+ * Copyright (C) 2018 García Pedroche, Francisco Javier *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+/**
+ * @file actuators.c
+ * @author Colomar Andrés, Alejandro
+ * @author García Pedroche, Francisco Javier
+ * @copyright GPL-2.0-only
+ * @date 2018/dec/26
+ * @brief Actuators
+ * Set the actuators of the plane to the position received by CAN
+ */
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* Standard C ----------------------------------------------------------------*/
+ #include <stdbool.h>
+ #include <stddef.h>
+ #include <stdint.h>
+
+/* Drivers -------------------------------------------------------------------*/
+ #include "stm32l4xx_hal.h"
+
+/* libalx --------------------------------------------------------------------*/
+ #include "alx_math.h"
+
+/* STM32L4 modules -----------------------------------------------------------*/
+ #include "can.h"
+ #include "delay.h"
+ #include "errors.h"
+ #include "led.h"
+ #include "servo.h"
+ #include "tim.h"
+
+/* project -------------------------------------------------------------------*/
+ #include "actuators.h"
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs **************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+/* Volatile ------------------------------------------------------------------*/
+/* Global --------------------------------------------------------------------*/
+/* Static --------------------------------------------------------------------*/
+static float pitch;
+static float roll;
+static float yaw;
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+static int modules_init (void);
+#if 0
+static int proc_init (void);
+#endif
+static int proc_ref_read (void *data);
+static int proc_actuators_set (void *data);
+
+
+/******************************************************************************
+ ******* global functions *****************************************************
+ ******************************************************************************/
+ /**
+ * @brief Initialize actuators process
+ * @return Error
+ * @note Sets global variable 'prj_error'
+ */
+int proc_actuators_init (void)
+{
+ if (modules_init()) {
+ return ERROR_NOK;
+ }
+
+#if 0
+ if (proc_init()) {
+ return ERROR_NOK;
+ }
+#endif
+
+ return ERROR_OK;
+}
+
+ /**
+ * @brief Run actuators process (based on timer interrupts)
+ * @return Error
+ * @note Sets global variable 'prj_error'
+ */
+int proc_actuators_1 (void)
+{
+ while (true) {
+ __WFE();
+ if (tim_tim3_interrupt) {
+ if (tim_callback_exe()) {
+ prj_error_handle();
+ return ERROR_NOK;
+ }
+ tim_tim3_interrupt = false;
+ }
+ }
+
+ return ERROR_OK;
+}
+
+ /**
+ * @brief Run actuators process (based on delays)
+ * @return Error
+ * @note Sets global variable 'prj_error'
+ */
+int proc_actuators_2 (void)
+{
+ delay_us(1000u);
+
+ while (true) {
+ delay_us(20000u);
+
+ if (!proc_ref_read(NULL)) {
+ if (proc_actuators_set(NULL)) {
+ return ERROR_NOK;
+ }
+ }
+ }
+
+ return ERROR_OK;
+}
+
+
+/******************************************************************************
+ ******* static functions (definitions) ***************************************
+ ******************************************************************************/
+static int modules_init (void)
+{
+#if 0
+ if (tim_tim3_init(REFRESH_FREQ)) {
+ return ERROR_NOK;
+ }
+#endif
+ if (delay_us_init()) {
+ return ERROR_NOK;
+ }
+ if (can_init()) {
+ return ERROR_NOK;
+ }
+ if (servo_init()) {
+ return ERROR_NOK;
+ }
+
+ return ERROR_OK;
+}
+
+#if 0
+static int proc_init (void)
+{
+ if (tim_callback_push(&proc_ref_read, NULL)) {
+ return ERROR_NOK;
+ }
+ if (tim_callback_push(&proc_actuators_set, NULL)) {
+ return ERROR_NOK;
+ }
+
+ return ERROR_OK;
+}
+#endif
+
+static int proc_ref_read (void *data)
+{
+ int8_t plane_pos [CAN_DATA_LEN];
+
+ (void)data;
+
+ if (can_msg_read((uint8_t *)plane_pos)) {
+ return ERROR_NOK;
+ }
+
+ pitch = plane_pos[0];
+ roll = plane_pos[1];
+ yaw = plane_pos[2];
+
+ return ERROR_OK;
+}
+
+static int proc_actuators_set (void *data)
+{
+ float tmp;
+
+ (void)data;
+
+ tmp = alx_scale_linear_f(pitch, -40, 40, -90, 90);
+ if (servo_position_set(SERVO_S1, tmp)) {
+ return ERROR_NOK;
+ }
+
+ tmp = alx_scale_linear_f(roll, -35, 35, -90, -20);
+ if (servo_position_set(SERVO_S2, tmp)) {
+ return ERROR_NOK;
+ }
+
+ if (yaw > 0) {
+ if (servo_position_set(SERVO_S3, 90)) {
+ return ERROR_NOK;
+ }
+
+ tmp = alx_scale_linear_f(yaw, 0, 10, -90, 90);
+ if (servo_position_set(SERVO_S4, tmp)) {
+ return ERROR_NOK;
+ }
+ } else {
+ tmp = alx_scale_linear_f(yaw, -10, 0, -90, 90);
+ if (servo_position_set(SERVO_S3, tmp)) {
+ return ERROR_NOK;
+ }
+
+ if (servo_position_set(SERVO_S4, -90)) {
+ return ERROR_NOK;
+ }
+ }
+
+ return ERROR_OK;
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/src/ctrl.c b/src/ctrl.c
new file mode 100644
index 0000000..4ff58b0
--- /dev/null
+++ b/src/ctrl.c
@@ -0,0 +1,273 @@
+/******************************************************************************
+ * Copyright (C) 2018 Colomar Andrés, Alejandro *
+ * Copyright (C) 2018 García Pedroche, Francisco Javier *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+/**
+ * @file ctrl.c
+ * @author Colomar Andrés, Alejandro
+ * @author García Pedroche, Francisco Javier
+ * @copyright GPL-2.0-only
+ * @date 2018/dec/26
+ * @brief Control
+ * Read values from the nunchuk, and set from them
+ * - pitch
+ * - roll
+ * - yaw
+ * Send those 3 values through CAN
+ */
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* Standard C ----------------------------------------------------------------*/
+ #include <stdbool.h>
+ #include <stddef.h>
+ #include <stdint.h>
+
+/* Drivers -------------------------------------------------------------------*/
+ #include "stm32l4xx_hal.h"
+
+/* libalx --------------------------------------------------------------------*/
+ #include "alx_math.h"
+
+/* STM32L4 modules -----------------------------------------------------------*/
+ #include "can.h"
+ #include "delay.h"
+ #include "errors.h"
+ #include "led.h"
+ #include "nunchuk.h"
+ #include "tim.h"
+
+/* project -------------------------------------------------------------------*/
+ #include "ctrl.h"
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs **************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+/* Global --------------------------------------------------------------------*/
+/* Static --------------------------------------------------------------------*/
+static float pitch;
+static float roll;
+static float yaw;
+static bool level;
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+static int modules_init (void);
+#if 0
+static int proc_init (void);
+#endif
+static int proc_ctrl_read (void *data);
+static int proc_ctrl_report (void *data);
+
+
+/******************************************************************************
+ ******* global functions *****************************************************
+ ******************************************************************************/
+ /**
+ * @brief Initialize controller process
+ * @return Error
+ * @note Sets global variable 'prj_error'
+ */
+int proc_ctrl_init (void)
+{
+ if (modules_init()) {
+ return ERROR_NOK;
+ }
+
+#if 0
+ if (proc_init()) {
+ return ERROR_NOK;
+ }
+#endif
+
+ level = true;
+
+ return ERROR_OK;
+}
+
+ /**
+ * @brief Run controller process (based on timer interrupts)
+ * @return Error
+ * @note Sets global variable 'prj_error'
+ */
+int proc_ctrl_1 (void)
+{
+ while (true) {
+ __WFE();
+ if (tim_tim3_interrupt) {
+ if (tim_callback_exe()) {
+ prj_error_handle();
+ return ERROR_NOK;
+ }
+ tim_tim3_interrupt = false;
+ }
+ }
+
+ return ERROR_OK;
+}
+
+ /**
+ * @brief Run controller process (based on delays)
+ * @return Error
+ * @note Sets global variable 'prj_error'
+ */
+int proc_ctrl_2 (void)
+{
+ delay_us(1000u);
+
+ while (true) {
+ delay_us(20000u);
+
+ if (proc_ctrl_read(NULL)) {
+ prj_error_handle();
+ return ERROR_NOK;
+ }
+
+ if (proc_ctrl_report(NULL)) {
+ prj_error_handle();
+ return ERROR_NOK;
+ }
+ }
+
+ return ERROR_OK;
+}
+
+
+/******************************************************************************
+ ******* static functions (definitions) ***************************************
+ ******************************************************************************/
+static int modules_init (void)
+{
+#if 0
+ if (tim_tim3_init(REFRESH_FREQ)) {
+ return ERROR_NOK;
+ }
+#endif
+ led_init();
+ if (delay_us_init()) {
+ return ERROR_NOK;
+ }
+ if (can_init()) {
+ return ERROR_NOK;
+ }
+
+ if (nunchuk_init()) {
+ return ERROR_NOK;
+ }
+
+ return ERROR_OK;
+}
+
+#if 0
+static int proc_init (void)
+{
+ if (tim_callback_push(&proc_ctrl_read, NULL)) {
+ return ERROR_NOK;
+ }
+ if (tim_callback_push(&proc_ctrl_report, NULL)) {
+ return ERROR_NOK;
+ }
+
+ return ERROR_OK;
+}
+#endif
+
+static int proc_ctrl_read (void *data)
+{
+ Nunchuk_Data_s nunchuk;
+ float tmp;
+
+ (void)data;
+
+ if (nunchuk_read(&nunchuk)) {
+ return ERROR_NOK;
+ }
+
+ tmp = nunchuk.jst.y;
+ pitch = -alx_scale_linear_f(tmp, 0, UINT8_MAX, -40, 40);
+
+ tmp = nunchuk.jst.x;
+ roll = alx_scale_linear_f(tmp, 0, UINT8_MAX, -35, 35);
+
+ tmp = nunchuk.acc.x8;
+ yaw = alx_scale_linear_f(tmp, 30, 150, -10, 10);
+
+ level = nunchuk.btn_c;
+
+ return ERROR_OK;
+}
+
+static int proc_ctrl_report (void *data)
+{
+ int8_t plane_pos [CAN_DATA_LEN];
+ int i;
+
+ (void)data;
+
+ for (i = 3; i < CAN_DATA_LEN; i++) {
+ plane_pos[i] = 0;
+ }
+
+ if (level) {
+ plane_pos[0] = 0;
+ plane_pos[1] = 0;
+ plane_pos[2] = 0;
+ } else {
+ if (pitch > INT8_MAX) {
+ plane_pos[0] = INT8_MAX;
+ } else if (pitch < INT8_MIN) {
+ plane_pos[0] = INT8_MIN;
+ } else {
+ plane_pos[0] = (int8_t)pitch;
+ }
+
+ if (roll > INT8_MAX) {
+ plane_pos[1] = INT8_MAX;
+ } else if (roll < INT8_MIN) {
+ plane_pos[1] = INT8_MIN;
+ } else {
+ plane_pos[1] = (int8_t)roll;
+ }
+
+ if (yaw > INT8_MAX) {
+ plane_pos[2] = INT8_MAX;
+ } else if (yaw < INT8_MIN) {
+ plane_pos[2] = INT8_MIN;
+ } else {
+ plane_pos[2] = (int8_t)yaw;
+ }
+ }
+
+ if (can_msg_write((uint8_t *)plane_pos)) {
+ return ERROR_NOK;
+ }
+
+ return ERROR_OK;
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..6b0bc8a
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,184 @@
+/******************************************************************************
+ * Copyright (C) 2018 Colomar Andrés, Alejandro *
+ * Copyright (C) 2018 García Pedroche, Francisco Javier *
+ * Copyright (C) 2018 Junquera Carrero, Santiago *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+/**
+ * @file main.c
+ * @author Colomar Andrés, Alejandro
+ * @author García Pedroche, Francisco Javier
+ * @author Junquera Carrero, Santiago
+ * @copyright GPL-2.0-only
+ * @date 2018/dec/15
+ * @brief Main
+ */
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* Standard C ----------------------------------------------------------------*/
+ #include <stdbool.h>
+ #include <stdnoreturn.h>
+
+/* Drivers -------------------------------------------------------------------*/
+ #include "stm32l4xx_hal.h"
+
+/* libalx --------------------------------------------------------------------*/
+/* STM32L4 modules -----------------------------------------------------------*/
+ #include "can.h"
+ #include "clk.h"
+ #include "delay.h"
+ #include "display.h"
+ #include "errors.h"
+ #include "led.h"
+ #include "nunchuk.h"
+ #include "servo.h"
+ #include "tim.h"
+
+ #include "can_test.h"
+ #include "display_test.h"
+ #include "led_test.h"
+ #include "nunchuk_test.h"
+ #include "servo_test.h"
+ #include "tim_test.h"
+
+/* project -------------------------------------------------------------------*/
+ #include "ctrl.h"
+ #include "actuators.h"
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs **************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+/* Global --------------------------------------------------------------------*/
+/* Static --------------------------------------------------------------------*/
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+static int test (void);
+static noreturn void stuck_forever (bool led);
+
+
+/******************************************************************************
+ ******* main *****************************************************************
+ ******************************************************************************/
+noreturn int main (void)
+{
+ HAL_Init();
+ sysclk_config();
+ prj_error = 0;
+
+#if 0
+ if (test()) {
+ stuck_forever(true);
+ }
+#else
+ (void)&test;
+
+ #if 1
+ if (proc_actuators_init()) {
+ stuck_forever(true);
+ }
+ #elif 1
+ if (proc_ctrl_init()) {
+ stuck_forever(true);
+ }
+ #endif
+
+ #if 1
+ if (proc_actuators_2()) {
+ stuck_forever(true);
+ }
+ #elif 1
+ if (proc_ctrl_2()) {
+ stuck_forever(true);
+ }
+ #endif
+
+#endif
+
+ stuck_forever(true);
+}
+
+
+/******************************************************************************
+ ******* static functions (definitions) ***************************************
+ ******************************************************************************/
+static noreturn void stuck_forever (bool led)
+{
+ if (led) {
+ led_set();
+ } else {
+ led_reset();
+ }
+
+ while (true) {
+ __WFI();
+ __NOP();
+ }
+}
+
+static int test (void)
+{
+#if 0
+ if (led_test()) {
+ return ERROR_NOK;
+ }
+#endif
+#if 0
+ can_r_test();
+#endif
+#if 0
+ can_w_test();
+#endif
+#if 0
+ if (servo_test_2()) {
+ return ERROR_NOK;
+ }
+#endif
+#if 0
+ if (display_test()) {
+ return ERROR_NOK;
+ }
+#endif
+#if 0
+ if (nunchuk_test_2()) {
+ return ERROR_NOK;
+ }
+#endif
+#if 0
+ if (tim_test()) {
+ return ERROR_NOK;
+ }
+#endif
+#if 0
+ prj_error_handle();
+#endif
+
+ return ERROR_OK;
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/src/startup_stm32l476xx.s b/src/startup_stm32l476xx.s
new file mode 100644
index 0000000..b93d40a
--- /dev/null
+++ b/src/startup_stm32l476xx.s
@@ -0,0 +1,524 @@
+/**
+ ******************************************************************************
+ * @file startup_stm32l476xx.s
+ * @author MCD Application Team
+ * @brief STM32L476xx devices vector table GCC toolchain.
+ * This module performs:
+ * - Set the initial SP
+ * - Set the initial PC == Reset_Handler,
+ * - Set the vector table entries with the exceptions ISR address,
+ * - Configure the clock system
+ * - Branches to main in the C library (which eventually
+ * calls main()).
+ * After Reset the Cortex-M4 processor is in Thread mode,
+ * priority is Privileged, and the Stack is set to Main.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+ .syntax unified
+ .cpu cortex-m4
+ .fpu softvfp
+ .thumb
+
+.global g_pfnVectors
+.global Default_Handler
+
+/* start address for the initialization values of the .data section.
+defined in linker script */
+.word _sidata
+/* start address for the .data section. defined in linker script */
+.word _sdata
+/* end address for the .data section. defined in linker script */
+.word _edata
+/* start address for the .bss section. defined in linker script */
+.word _sbss
+/* end address for the .bss section. defined in linker script */
+.word _ebss
+
+.equ BootRAM, 0xF1E0F85F
+/**
+ * @brief This is the code that gets called when the processor first
+ * starts execution following a reset event. Only the absolutely
+ * necessary set is performed, after which the application
+ * supplied main() routine is called.
+ * @param None
+ * @retval : None
+*/
+
+ .section .text.Reset_Handler
+ .weak Reset_Handler
+ .type Reset_Handler, %function
+Reset_Handler:
+ ldr sp, =_estack /* Atollic update: set stack pointer */
+
+/* Copy the data segment initializers from flash to SRAM */
+ movs r1, #0
+ b LoopCopyDataInit
+
+CopyDataInit:
+ ldr r3, =_sidata
+ ldr r3, [r3, r1]
+ str r3, [r0, r1]
+ adds r1, r1, #4
+
+LoopCopyDataInit:
+ ldr r0, =_sdata
+ ldr r3, =_edata
+ adds r2, r0, r1
+ cmp r2, r3
+ bcc CopyDataInit
+ ldr r2, =_sbss
+ b LoopFillZerobss
+/* Zero fill the bss segment. */
+FillZerobss:
+ movs r3, #0
+ str r3, [r2], #4
+
+LoopFillZerobss:
+ ldr r3, = _ebss
+ cmp r2, r3
+ bcc FillZerobss
+
+/* Call the clock system intitialization function.*/
+ bl SystemInit
+/* Call static constructors */
+ bl __libc_init_array
+/* Call the application's entry point.*/
+ bl main
+
+LoopForever:
+ b LoopForever
+
+.size Reset_Handler, .-Reset_Handler
+
+/**
+ * @brief This is the code that gets called when the processor receives an
+ * unexpected interrupt. This simply enters an infinite loop, preserving
+ * the system state for examination by a debugger.
+ *
+ * @param None
+ * @retval : None
+*/
+ .section .text.Default_Handler,"ax",%progbits
+Default_Handler:
+Infinite_Loop:
+ b Infinite_Loop
+ .size Default_Handler, .-Default_Handler
+/******************************************************************************
+*
+* The minimal vector table for a Cortex-M4. Note that the proper constructs
+* must be placed on this to ensure that it ends up at physical address
+* 0x0000.0000.
+*
+******************************************************************************/
+ .section .isr_vector,"a",%progbits
+ .type g_pfnVectors, %object
+ .size g_pfnVectors, .-g_pfnVectors
+
+
+g_pfnVectors:
+ .word _estack
+ .word Reset_Handler
+ .word NMI_Handler
+ .word HardFault_Handler
+ .word MemManage_Handler
+ .word BusFault_Handler
+ .word UsageFault_Handler
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+ .word SVC_Handler
+ .word DebugMon_Handler
+ .word 0
+ .word PendSV_Handler
+ .word SysTick_Handler
+ .word WWDG_IRQHandler
+ .word PVD_PVM_IRQHandler
+ .word TAMP_STAMP_IRQHandler
+ .word RTC_WKUP_IRQHandler
+ .word FLASH_IRQHandler
+ .word RCC_IRQHandler
+ .word EXTI0_IRQHandler
+ .word EXTI1_IRQHandler
+ .word EXTI2_IRQHandler
+ .word EXTI3_IRQHandler
+ .word EXTI4_IRQHandler
+ .word DMA1_Channel1_IRQHandler
+ .word DMA1_Channel2_IRQHandler
+ .word DMA1_Channel3_IRQHandler
+ .word DMA1_Channel4_IRQHandler
+ .word DMA1_Channel5_IRQHandler
+ .word DMA1_Channel6_IRQHandler
+ .word DMA1_Channel7_IRQHandler
+ .word ADC1_2_IRQHandler
+ .word CAN1_TX_IRQHandler
+ .word CAN1_RX0_IRQHandler
+ .word CAN1_RX1_IRQHandler
+ .word CAN1_SCE_IRQHandler
+ .word EXTI9_5_IRQHandler
+ .word TIM1_BRK_TIM15_IRQHandler
+ .word TIM1_UP_TIM16_IRQHandler
+ .word TIM1_TRG_COM_TIM17_IRQHandler
+ .word TIM1_CC_IRQHandler
+ .word TIM2_IRQHandler
+ .word TIM3_IRQHandler
+ .word TIM4_IRQHandler
+ .word I2C1_EV_IRQHandler
+ .word I2C1_ER_IRQHandler
+ .word I2C2_EV_IRQHandler
+ .word I2C2_ER_IRQHandler
+ .word SPI1_IRQHandler
+ .word SPI2_IRQHandler
+ .word USART1_IRQHandler
+ .word USART2_IRQHandler
+ .word USART3_IRQHandler
+ .word EXTI15_10_IRQHandler
+ .word RTC_Alarm_IRQHandler
+ .word DFSDM1_FLT3_IRQHandler
+ .word TIM8_BRK_IRQHandler
+ .word TIM8_UP_IRQHandler
+ .word TIM8_TRG_COM_IRQHandler
+ .word TIM8_CC_IRQHandler
+ .word ADC3_IRQHandler
+ .word FMC_IRQHandler
+ .word SDMMC1_IRQHandler
+ .word TIM5_IRQHandler
+ .word SPI3_IRQHandler
+ .word UART4_IRQHandler
+ .word UART5_IRQHandler
+ .word TIM6_DAC_IRQHandler
+ .word TIM7_IRQHandler
+ .word DMA2_Channel1_IRQHandler
+ .word DMA2_Channel2_IRQHandler
+ .word DMA2_Channel3_IRQHandler
+ .word DMA2_Channel4_IRQHandler
+ .word DMA2_Channel5_IRQHandler
+ .word DFSDM1_FLT0_IRQHandler
+ .word DFSDM1_FLT1_IRQHandler
+ .word DFSDM1_FLT2_IRQHandler
+ .word COMP_IRQHandler
+ .word LPTIM1_IRQHandler
+ .word LPTIM2_IRQHandler
+ .word OTG_FS_IRQHandler
+ .word DMA2_Channel6_IRQHandler
+ .word DMA2_Channel7_IRQHandler
+ .word LPUART1_IRQHandler
+ .word QUADSPI_IRQHandler
+ .word I2C3_EV_IRQHandler
+ .word I2C3_ER_IRQHandler
+ .word SAI1_IRQHandler
+ .word SAI2_IRQHandler
+ .word SWPMI1_IRQHandler
+ .word TSC_IRQHandler
+ .word LCD_IRQHandler
+ .word 0
+ .word RNG_IRQHandler
+ .word FPU_IRQHandler
+
+
+/*******************************************************************************
+*
+* Provide weak aliases for each Exception handler to the Default_Handler.
+* As they are weak aliases, any function with the same name will override
+* this definition.
+*
+*******************************************************************************/
+
+ .weak NMI_Handler
+ .thumb_set NMI_Handler,Default_Handler
+
+ .weak HardFault_Handler
+ .thumb_set HardFault_Handler,Default_Handler
+
+ .weak MemManage_Handler
+ .thumb_set MemManage_Handler,Default_Handler
+
+ .weak BusFault_Handler
+ .thumb_set BusFault_Handler,Default_Handler
+
+ .weak UsageFault_Handler
+ .thumb_set UsageFault_Handler,Default_Handler
+
+ .weak SVC_Handler
+ .thumb_set SVC_Handler,Default_Handler
+
+ .weak DebugMon_Handler
+ .thumb_set DebugMon_Handler,Default_Handler
+
+ .weak PendSV_Handler
+ .thumb_set PendSV_Handler,Default_Handler
+
+ .weak SysTick_Handler
+ .thumb_set SysTick_Handler,Default_Handler
+
+ .weak WWDG_IRQHandler
+ .thumb_set WWDG_IRQHandler,Default_Handler
+
+ .weak PVD_PVM_IRQHandler
+ .thumb_set PVD_PVM_IRQHandler,Default_Handler
+
+ .weak TAMP_STAMP_IRQHandler
+ .thumb_set TAMP_STAMP_IRQHandler,Default_Handler
+
+ .weak RTC_WKUP_IRQHandler
+ .thumb_set RTC_WKUP_IRQHandler,Default_Handler
+
+ .weak FLASH_IRQHandler
+ .thumb_set FLASH_IRQHandler,Default_Handler
+
+ .weak RCC_IRQHandler
+ .thumb_set RCC_IRQHandler,Default_Handler
+
+ .weak EXTI0_IRQHandler
+ .thumb_set EXTI0_IRQHandler,Default_Handler
+
+ .weak EXTI1_IRQHandler
+ .thumb_set EXTI1_IRQHandler,Default_Handler
+
+ .weak EXTI2_IRQHandler
+ .thumb_set EXTI2_IRQHandler,Default_Handler
+
+ .weak EXTI3_IRQHandler
+ .thumb_set EXTI3_IRQHandler,Default_Handler
+
+ .weak EXTI4_IRQHandler
+ .thumb_set EXTI4_IRQHandler,Default_Handler
+
+ .weak DMA1_Channel1_IRQHandler
+ .thumb_set DMA1_Channel1_IRQHandler,Default_Handler
+
+ .weak DMA1_Channel2_IRQHandler
+ .thumb_set DMA1_Channel2_IRQHandler,Default_Handler
+
+ .weak DMA1_Channel3_IRQHandler
+ .thumb_set DMA1_Channel3_IRQHandler,Default_Handler
+
+ .weak DMA1_Channel4_IRQHandler
+ .thumb_set DMA1_Channel4_IRQHandler,Default_Handler
+
+ .weak DMA1_Channel5_IRQHandler
+ .thumb_set DMA1_Channel5_IRQHandler,Default_Handler
+
+ .weak DMA1_Channel6_IRQHandler
+ .thumb_set DMA1_Channel6_IRQHandler,Default_Handler
+
+ .weak DMA1_Channel7_IRQHandler
+ .thumb_set DMA1_Channel7_IRQHandler,Default_Handler
+
+ .weak ADC1_2_IRQHandler
+ .thumb_set ADC1_2_IRQHandler,Default_Handler
+
+ .weak CAN1_TX_IRQHandler
+ .thumb_set CAN1_TX_IRQHandler,Default_Handler
+
+ .weak CAN1_RX0_IRQHandler
+ .thumb_set CAN1_RX0_IRQHandler,Default_Handler
+
+ .weak CAN1_RX1_IRQHandler
+ .thumb_set CAN1_RX1_IRQHandler,Default_Handler
+
+ .weak CAN1_SCE_IRQHandler
+ .thumb_set CAN1_SCE_IRQHandler,Default_Handler
+
+ .weak EXTI9_5_IRQHandler
+ .thumb_set EXTI9_5_IRQHandler,Default_Handler
+
+ .weak TIM1_BRK_TIM15_IRQHandler
+ .thumb_set TIM1_BRK_TIM15_IRQHandler,Default_Handler
+
+ .weak TIM1_UP_TIM16_IRQHandler
+ .thumb_set TIM1_UP_TIM16_IRQHandler,Default_Handler
+
+ .weak TIM1_TRG_COM_TIM17_IRQHandler
+ .thumb_set TIM1_TRG_COM_TIM17_IRQHandler,Default_Handler
+
+ .weak TIM1_CC_IRQHandler
+ .thumb_set TIM1_CC_IRQHandler,Default_Handler
+
+ .weak TIM2_IRQHandler
+ .thumb_set TIM2_IRQHandler,Default_Handler
+
+ .weak TIM3_IRQHandler
+ .thumb_set TIM3_IRQHandler,Default_Handler
+
+ .weak TIM4_IRQHandler
+ .thumb_set TIM4_IRQHandler,Default_Handler
+
+ .weak I2C1_EV_IRQHandler
+ .thumb_set I2C1_EV_IRQHandler,Default_Handler
+
+ .weak I2C1_ER_IRQHandler
+ .thumb_set I2C1_ER_IRQHandler,Default_Handler
+
+ .weak I2C2_EV_IRQHandler
+ .thumb_set I2C2_EV_IRQHandler,Default_Handler
+
+ .weak I2C2_ER_IRQHandler
+ .thumb_set I2C2_ER_IRQHandler,Default_Handler
+
+ .weak SPI1_IRQHandler
+ .thumb_set SPI1_IRQHandler,Default_Handler
+
+ .weak SPI2_IRQHandler
+ .thumb_set SPI2_IRQHandler,Default_Handler
+
+ .weak USART1_IRQHandler
+ .thumb_set USART1_IRQHandler,Default_Handler
+
+ .weak USART2_IRQHandler
+ .thumb_set USART2_IRQHandler,Default_Handler
+
+ .weak USART3_IRQHandler
+ .thumb_set USART3_IRQHandler,Default_Handler
+
+ .weak EXTI15_10_IRQHandler
+ .thumb_set EXTI15_10_IRQHandler,Default_Handler
+
+ .weak RTC_Alarm_IRQHandler
+ .thumb_set RTC_Alarm_IRQHandler,Default_Handler
+
+ .weak DFSDM1_FLT3_IRQHandler
+ .thumb_set DFSDM1_FLT3_IRQHandler,Default_Handler
+
+ .weak TIM8_BRK_IRQHandler
+ .thumb_set TIM8_BRK_IRQHandler,Default_Handler
+
+ .weak TIM8_UP_IRQHandler
+ .thumb_set TIM8_UP_IRQHandler,Default_Handler
+
+ .weak TIM8_TRG_COM_IRQHandler
+ .thumb_set TIM8_TRG_COM_IRQHandler,Default_Handler
+
+ .weak TIM8_CC_IRQHandler
+ .thumb_set TIM8_CC_IRQHandler,Default_Handler
+
+ .weak ADC3_IRQHandler
+ .thumb_set ADC3_IRQHandler,Default_Handler
+
+ .weak FMC_IRQHandler
+ .thumb_set FMC_IRQHandler,Default_Handler
+
+ .weak SDMMC1_IRQHandler
+ .thumb_set SDMMC1_IRQHandler,Default_Handler
+
+ .weak TIM5_IRQHandler
+ .thumb_set TIM5_IRQHandler,Default_Handler
+
+ .weak SPI3_IRQHandler
+ .thumb_set SPI3_IRQHandler,Default_Handler
+
+ .weak UART4_IRQHandler
+ .thumb_set UART4_IRQHandler,Default_Handler
+
+ .weak UART5_IRQHandler
+ .thumb_set UART5_IRQHandler,Default_Handler
+
+ .weak TIM6_DAC_IRQHandler
+ .thumb_set TIM6_DAC_IRQHandler,Default_Handler
+
+ .weak TIM7_IRQHandler
+ .thumb_set TIM7_IRQHandler,Default_Handler
+
+ .weak DMA2_Channel1_IRQHandler
+ .thumb_set DMA2_Channel1_IRQHandler,Default_Handler
+
+ .weak DMA2_Channel2_IRQHandler
+ .thumb_set DMA2_Channel2_IRQHandler,Default_Handler
+
+ .weak DMA2_Channel3_IRQHandler
+ .thumb_set DMA2_Channel3_IRQHandler,Default_Handler
+
+ .weak DMA2_Channel4_IRQHandler
+ .thumb_set DMA2_Channel4_IRQHandler,Default_Handler
+
+ .weak DMA2_Channel5_IRQHandler
+ .thumb_set DMA2_Channel5_IRQHandler,Default_Handler
+
+ .weak DFSDM1_FLT0_IRQHandler
+ .thumb_set DFSDM1_FLT0_IRQHandler,Default_Handler
+
+ .weak DFSDM1_FLT1_IRQHandler
+ .thumb_set DFSDM1_FLT1_IRQHandler,Default_Handler
+
+ .weak DFSDM1_FLT2_IRQHandler
+ .thumb_set DFSDM1_FLT2_IRQHandler,Default_Handler
+
+ .weak COMP_IRQHandler
+ .thumb_set COMP_IRQHandler,Default_Handler
+
+ .weak LPTIM1_IRQHandler
+ .thumb_set LPTIM1_IRQHandler,Default_Handler
+
+ .weak LPTIM2_IRQHandler
+ .thumb_set LPTIM2_IRQHandler,Default_Handler
+
+ .weak OTG_FS_IRQHandler
+ .thumb_set OTG_FS_IRQHandler,Default_Handler
+
+ .weak DMA2_Channel6_IRQHandler
+ .thumb_set DMA2_Channel6_IRQHandler,Default_Handler
+
+ .weak DMA2_Channel7_IRQHandler
+ .thumb_set DMA2_Channel7_IRQHandler,Default_Handler
+
+ .weak LPUART1_IRQHandler
+ .thumb_set LPUART1_IRQHandler,Default_Handler
+
+ .weak QUADSPI_IRQHandler
+ .thumb_set QUADSPI_IRQHandler,Default_Handler
+
+ .weak I2C3_EV_IRQHandler
+ .thumb_set I2C3_EV_IRQHandler,Default_Handler
+
+ .weak I2C3_ER_IRQHandler
+ .thumb_set I2C3_ER_IRQHandler,Default_Handler
+
+ .weak SAI1_IRQHandler
+ .thumb_set SAI1_IRQHandler,Default_Handler
+
+ .weak SAI2_IRQHandler
+ .thumb_set SAI2_IRQHandler,Default_Handler
+
+ .weak SWPMI1_IRQHandler
+ .thumb_set SWPMI1_IRQHandler,Default_Handler
+
+ .weak TSC_IRQHandler
+ .thumb_set TSC_IRQHandler,Default_Handler
+
+ .weak LCD_IRQHandler
+ .thumb_set LCD_IRQHandler,Default_Handler
+
+ .weak RNG_IRQHandler
+ .thumb_set RNG_IRQHandler,Default_Handler
+
+ .weak FPU_IRQHandler
+ .thumb_set FPU_IRQHandler,Default_Handler
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/src/stm32l4xx_it.c b/src/stm32l4xx_it.c
new file mode 100644
index 0000000..31477a0
--- /dev/null
+++ b/src/stm32l4xx_it.c
@@ -0,0 +1,146 @@
+/**
+ ******************************************************************************
+ * @file Templates/Src/stm32l4xx_it.c
+ * @author MCD Application Team
+ * @version V1.8.0
+ * @date 21-April-2017
+ * @brief Main Interrupt Service Routines.
+ * This file provides template for all exceptions handler and
+ * peripherals interrupt service routine.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Includes ------------------------------------------------------------------*/
+#include <stdbool.h>
+#include "stm32l4xx_hal.h"
+
+/******************************************************************************/
+/* Cortex-M4 Processor Exceptions Handlers */
+/******************************************************************************/
+
+/**
+ * @brief This function handles NMI exception.
+ * @param None
+ * @retval None
+ */
+void NMI_Handler (void)
+{
+}
+
+/**
+ * @brief This function handles Hard Fault exception.
+ * @param None
+ * @retval None
+ */
+void HardFault_Handler (void)
+{
+ /* Go to infinite loop when Hard Fault exception occurs */
+ while (true)
+ {
+ }
+}
+
+/**
+ * @brief This function handles Memory Manage exception.
+ * @param None
+ * @retval None
+ */
+void MemManage_Handler (void)
+{
+ /* Go to infinite loop when Memory Manage exception occurs */
+ while (true)
+ {
+ }
+}
+
+/**
+ * @brief This function handles Bus Fault exception.
+ * @param None
+ * @retval None
+ */
+void BusFault_Handler (void)
+{
+ /* Go to infinite loop when Bus Fault exception occurs */
+ while (true)
+ {
+ }
+}
+
+/**
+ * @brief This function handles Usage Fault exception.
+ * @param None
+ * @retval None
+ */
+void UsageFault_Handler (void)
+{
+ /* Go to infinite loop when Usage Fault exception occurs */
+ while (true)
+ {
+ }
+}
+
+/**
+ * @brief This function handles SVCall exception.
+ * @param None
+ * @retval None
+ */
+void SVC_Handler (void)
+{
+}
+
+/**
+ * @brief This function handles Debug Monitor exception.
+ * @param None
+ * @retval None
+ */
+void DebugMon_Handler (void)
+{
+}
+
+/**
+ * @brief This function handles PendSVC exception.
+ * @param None
+ * @retval None
+ */
+void PendSV_Handler (void)
+{
+}
+
+/**
+ * @brief This function handles SysTick Handler.
+ * @param None
+ * @retval None
+ */
+void SysTick_Handler (void)
+{
+ HAL_IncTick();
+}
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/src/system_stm32l4xx.c b/src/system_stm32l4xx.c
new file mode 100644
index 0000000..d09954f
--- /dev/null
+++ b/src/system_stm32l4xx.c
@@ -0,0 +1,363 @@
+/**
+ ******************************************************************************
+ * @file system_stm32l4xx.c
+ * @author MCD Application Team
+ * @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File
+ *
+ * This file provides two functions and one global variable to be called from
+ * user application:
+ * - SystemInit(): This function is called at startup just after reset and
+ * before branch to main program. This call is made inside
+ * the "startup_stm32l4xx.s" file.
+ *
+ * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
+ * by the user application to setup the SysTick
+ * timer or configure other parameters.
+ *
+ * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
+ * be called whenever the core clock is changed
+ * during program execution.
+ *
+ * After each device reset the MSI (4 MHz) is used as system clock source.
+ * Then SystemInit() function is called, in "startup_stm32l4xx.s" file, to
+ * configure the system clock before to branch to main program.
+ *
+ * This file configures the system clock as follows:
+ *=============================================================================
+ *-----------------------------------------------------------------------------
+ * System Clock source | MSI
+ *-----------------------------------------------------------------------------
+ * SYSCLK(Hz) | 4000000
+ *-----------------------------------------------------------------------------
+ * HCLK(Hz) | 4000000
+ *-----------------------------------------------------------------------------
+ * AHB Prescaler | 1
+ *-----------------------------------------------------------------------------
+ * APB1 Prescaler | 1
+ *-----------------------------------------------------------------------------
+ * APB2 Prescaler | 1
+ *-----------------------------------------------------------------------------
+ * PLL_M | 1
+ *-----------------------------------------------------------------------------
+ * PLL_N | 8
+ *-----------------------------------------------------------------------------
+ * PLL_P | 7
+ *-----------------------------------------------------------------------------
+ * PLL_Q | 2
+ *-----------------------------------------------------------------------------
+ * PLL_R | 2
+ *-----------------------------------------------------------------------------
+ * PLLSAI1_P | NA
+ *-----------------------------------------------------------------------------
+ * PLLSAI1_Q | NA
+ *-----------------------------------------------------------------------------
+ * PLLSAI1_R | NA
+ *-----------------------------------------------------------------------------
+ * PLLSAI2_P | NA
+ *-----------------------------------------------------------------------------
+ * PLLSAI2_Q | NA
+ *-----------------------------------------------------------------------------
+ * PLLSAI2_R | NA
+ *-----------------------------------------------------------------------------
+ * Require 48MHz for USB OTG FS, | Disabled
+ * SDIO and RNG clock |
+ *-----------------------------------------------------------------------------
+ *=============================================================================
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/** @addtogroup CMSIS
+ * @{
+ */
+
+/** @addtogroup stm32l4xx_system
+ * @{
+ */
+
+/** @addtogroup STM32L4xx_System_Private_Includes
+ * @{
+ */
+
+#include "stm32l4xx.h"
+
+#if !defined (HSE_VALUE)
+ # define HSE_VALUE (8000000U) /*!< Value of the External oscillator in Hz */
+#endif /* HSE_VALUE */
+
+#if !defined (MSI_VALUE)
+ # define MSI_VALUE (4000000U) /*!< Value of the Internal oscillator in Hz*/
+#endif /* MSI_VALUE */
+
+#if !defined (HSI_VALUE)
+ # define HSI_VALUE (16000000U) /*!< Value of the Internal oscillator in Hz*/
+#endif /* HSI_VALUE */
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L4xx_System_Private_TypesDefinitions
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L4xx_System_Private_Defines
+ * @{
+ */
+
+/************************* Miscellaneous Configuration ************************/
+/*!< Uncomment the following line if you need to relocate your vector Table in
+ Internal SRAM. */
+/* #define VECT_TAB_SRAM */
+# define VECT_TAB_OFFSET (0x00) /*!< Vector Table base offset field.
+ This value must be a multiple of 0x200. */
+/******************************************************************************/
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L4xx_System_Private_Macros
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L4xx_System_Private_Variables
+ * @{
+ */
+ /* The SystemCoreClock variable is updated in three ways:
+ 1) by calling CMSIS function SystemCoreClockUpdate()
+ 2) by calling HAL API function HAL_RCC_GetHCLKFreq()
+ 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
+ Note: If you use this function to configure the system clock; then there
+ is no need to call the 2 first functions listed above, since SystemCoreClock
+ variable is updated automatically.
+ */
+ uint32_t SystemCoreClock = 4000000U;
+
+ const uint8_t AHBPrescTable [16] = {
+ 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U,
+ 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U
+ };
+ const uint8_t APBPrescTable [8] = {
+ 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U
+ };
+ const uint32_t MSIRangeTable [12] = {
+ 100000U, 200000U, 400000U, 800000U,
+ 1000000U, 2000000U, 4000000U, 8000000U,
+ 16000000U, 24000000U, 32000000U, 48000000U
+ };
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L4xx_System_Private_FunctionPrototypes
+ * @{
+ */
+
+/**
+ * @}
+ */
+
+/** @addtogroup STM32L4xx_System_Private_Functions
+ * @{
+ */
+
+/**
+ * @brief Setup the microcontroller system.
+ * @param None
+ * @retval None
+ */
+
+void SystemInit(void)
+{
+ /* FPU settings ------------------------------------------------------------*/
+ #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
+ SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
+ #endif
+
+ /* Reset the RCC clock configuration to the default reset state ------------*/
+ /* Set MSION bit */
+ RCC->CR |= RCC_CR_MSION;
+
+ /* Reset CFGR register */
+ RCC->CFGR = 0x00000000U;
+
+ /* Reset HSEON, CSSON , HSION, and PLLON bits */
+ RCC->CR &= 0xEAF6FFFFU;
+
+ /* Reset PLLCFGR register */
+ RCC->PLLCFGR = 0x00001000U;
+
+ /* Reset HSEBYP bit */
+ RCC->CR &= 0xFFFBFFFFU;
+
+ /* Disable all interrupts */
+ RCC->CIER = 0x00000000U;
+
+ /* Configure the Vector Table location add offset address ------------------*/
+ #ifdef VECT_TAB_SRAM
+ SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
+ #else
+ SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
+ #endif
+}
+
+/**
+ * @brief Update SystemCoreClock variable according to Clock Register Values.
+ * The SystemCoreClock variable contains the core clock (HCLK), it can
+ * be used by the user application to setup the SysTick timer or configure
+ * other parameters.
+ *
+ * @note Each time the core clock (HCLK) changes, this function must be called
+ * to update SystemCoreClock variable value. Otherwise, any configuration
+ * based on this variable will be incorrect.
+ *
+ * @note - The system frequency computed by this function is not the real
+ * frequency in the chip. It is calculated based on the predefined
+ * constant and the selected clock source:
+ *
+ * - If SYSCLK source is MSI, SystemCoreClock will contain the MSI_VALUE(*)
+ *
+ * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**)
+ *
+ * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
+ *
+ * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***)
+ * or HSI_VALUE(*) or MSI_VALUE(*) multiplied/divided by the PLL factors.
+ *
+ * (*) MSI_VALUE is a constant defined in stm32l4xx_hal.h file (default value
+ * 4 MHz) but the real value may vary depending on the variations
+ * in voltage and temperature.
+ *
+ * (**) HSI_VALUE is a constant defined in stm32l4xx_hal.h file (default value
+ * 16 MHz) but the real value may vary depending on the variations
+ * in voltage and temperature.
+ *
+ * (***) HSE_VALUE is a constant defined in stm32l4xx_hal.h file (default value
+ * 8 MHz), user has to ensure that HSE_VALUE is same as the real
+ * frequency of the crystal used. Otherwise, this function may
+ * have wrong result.
+ *
+ * - The result of this function could be not correct when using fractional
+ * value for HSE crystal.
+ *
+ * @param None
+ * @retval None
+ */
+void SystemCoreClockUpdate(void)
+{
+ uint32_t tmp = 0u;
+ uint32_t msirange = 0u;
+ uint32_t pllvco = 0u;
+ uint32_t pllr = 2u;
+ uint32_t pllsource = 0u;
+ uint32_t pllm = 2u;
+
+ /* Get MSI Range frequency--------------------------------------------------*/
+ if ((RCC->CR & RCC_CR_MSIRGSEL) == RESET) {
+ /* MSISRANGE from RCC_CSR applies */
+ msirange = (RCC->CSR & RCC_CSR_MSISRANGE) >> 8u;
+ } else {
+ /* MSIRANGE from RCC_CR applies */
+ msirange = (RCC->CR & RCC_CR_MSIRANGE) >> 4u;
+ }
+ /*MSI frequency range in HZ*/
+ msirange = MSIRangeTable[msirange];
+
+ /* Get SYSCLK source -------------------------------------------------------*/
+ switch (RCC->CFGR & RCC_CFGR_SWS) {
+ case 0x00: /* MSI used as system clock source */
+ SystemCoreClock = msirange;
+ break;
+
+ case 0x04: /* HSI used as system clock source */
+ SystemCoreClock = HSI_VALUE;
+ break;
+
+ case 0x08: /* HSE used as system clock source */
+ SystemCoreClock = HSE_VALUE;
+ break;
+
+ case 0x0C: /* PLL used as system clock source */
+ /* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN
+ * SYSCLK = PLL_VCO / PLLR
+ */
+ pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);
+ pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4U) + 1U;
+
+ switch (pllsource) {
+ case 0x02: /* HSI used as PLL clock source */
+ pllvco = (HSI_VALUE / pllm);
+ break;
+
+ case 0x03: /* HSE used as PLL clock source */
+ pllvco = (HSE_VALUE / pllm);
+ break;
+
+ default: /* MSI used as PLL clock source */
+ pllvco = (msirange / pllm);
+ break;
+ }
+ pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 8U);
+ pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 25U) + 1U) * 2U;
+ SystemCoreClock = pllvco / pllr;
+ break;
+
+ default:
+ SystemCoreClock = msirange;
+ break;
+ }
+ /* Compute HCLK clock frequency --------------------------------------------*/
+ /* Get HCLK prescaler */
+ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)];
+ /* HCLK clock frequency */
+ SystemCoreClock >>= tmp;
+}
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/tmp/Makefile b/tmp/Makefile
new file mode 100644
index 0000000..48d6486
--- /dev/null
+++ b/tmp/Makefile
@@ -0,0 +1,138 @@
+#!/usr/bin/make -f
+
+# directories
+
+STM32_CMSIS_DIR = $(DRIVERS_DIR)/CMSIS/
+STM32L4_CMSIS_DIR = $(STM32_CMSIS_DIR)/ST/STM32L4xx/
+STM32L4_HAL_DIR = $(DRIVERS_DIR)/STM32L4xx_HAL_Driver/
+
+LIBALX_INC_DIR = $(LIBALX_DIR)/inc/
+STM32_CMSIS_INC_DIR = $(STM32_CMSIS_DIR)/Include/
+STM32L4_CMSIS_INC_DIR = $(STM32L4_CMSIS_DIR)/Include/
+STM32L4_HAL_INC_DIR = $(STM32L4_HAL_DIR)/Inc/
+
+MODULES_BASE_INC_DIR = $(MODULES_DIR)/inc/
+MODULES_DEV_INC_DIR = $(MODULES_DIR)/inc/dev/
+MODULES_TST_INC_DIR = $(MODULES_DIR)/inc/test/
+
+SRC_DIR = $(MAIN_DIR)/src/
+INC_DIR = $(MAIN_DIR)/inc/
+DEP_DIR = $(MAIN_DIR)/dep/
+
+# dependencies
+
+ALL = \
+ system_stm32l4xx.o stm32l4xx_it.o main.o \
+ ctrl.o actuators.o
+
+COMMON_INC_CMSIS = core_cm4.h cmsis_gcc.h
+COMMON_INC_CMSIS_L4 = stm32l4xx.h
+COMMON_INC_HAL = stm32l4xx_hal.h
+COMMON_DEPS = \
+ $(patsubst %,$(STM32_CMSIS_INC_DIR)/%,$(COMMON_INC_CMSIS)) \
+ $(patsubst %,$(STM32L4_CMSIS_INC_DIR)/%,$(COMMON_INC_CMSIS_L4)) \
+ $(patsubst %,$(STM32L4_HAL_INC_DIR)/%,$(COMMON_INC_HAL))
+COMMON_INC_DIRS = \
+ -I $(STM32_CMSIS_INC_DIR) \
+ -I $(STM32L4_CMSIS_INC_DIR) \
+ -I $(STM32L4_HAL_INC_DIR)
+
+
+SYS_DEPS = $(SRC_DIR)/system_stm32l4xx.c \
+ $(COMMON_DEPS)
+SYS_INC_DIRS = \
+ $(COMMON_INC_DIRS)
+
+
+IT_DEPS = $(SRC_DIR)/stm32l4xx_it.c \
+ $(COMMON_DEPS)
+IT_INC_DIRS = \
+ $(COMMON_INC_DIRS)
+
+
+MAIN_INC_BASE = can.h clk.h delay.h errors.h led.h tim.h
+MAIN_INC_DEV = display.h nunchuk.h servo.h
+MAIN_INC_TST = \
+ can_test.h led_test.h tim_test.h \
+ display_test.h nunchuk_test.h servo_test.h
+MAIN_INC = ctrl.h actuators.h
+MAIN_DEPS = $(SRC_DIR)/main.c \
+ $(COMMON_DEPS) \
+ $(patsubst %,$(MODULES_BASE_INC_DIR)/%,$(MAIN_INC_BASE)) \
+ $(patsubst %,$(MODULES_DEV_INC_DIR)/%,$(MAIN_INC_DEV)) \
+ $(patsubst %,$(MODULES_TST_INC_DIR)/%,$(MAIN_INC_TST)) \
+ $(patsubst %,$(INC_DIR)/%,$(MAIN_INC))
+MAIN_INC_DIRS = -I $(INC_DIR) \
+ -I $(MODULES_BASE_INC_DIR) \
+ -I $(MODULES_DEV_INC_DIR) \
+ -I $(MODULES_TST_INC_DIR) \
+ $(COMMON_INC_DIRS)
+
+
+CTRL_INC_LIBALX = alx_math.h
+CTRL_INC_BASE = can.h delay.h errors.h led.h tim.h
+CTRL_INC_DEV = nunchuk.h
+CTRL_INC = ctrl.h
+CTRL_DEPS = $(SRC_DIR)/ctrl.c \
+ $(COMMON_DEPS) \
+ $(patsubst %,$(LIBALX_INC_DIR)/%,$(CTRL_INC_LIBALX)) \
+ $(patsubst %,$(MODULES_BASE_INC_DIR)/%,$(CTRL_INC_BASE)) \
+ $(patsubst %,$(MODULES_DEV_INC_DIR)/%,$(CTRL_INC_DEV)) \
+ $(patsubst %,$(INC_DIR)/%,$(CTRL_INC))
+CTRL_INC_DIRS = -I $(INC_DIR) \
+ -I $(LIBALX_INC_DIR) \
+ -I $(MODULES_BASE_INC_DIR) \
+ -I $(MODULES_DEV_INC_DIR) \
+ $(COMMON_INC_DIRS)
+
+
+ACT_INC_LIBALX = alx_math.h
+ACT_INC_BASE = can.h delay.h errors.h led.h tim.h
+ACT_INC_DEV = servo.h
+ACT_INC = actuators.h
+ACT_DEPS = $(SRC_DIR)/actuators.c \
+ $(COMMON_DEPS) \
+ $(patsubst %,$(LIBALX_INC_DIR)/%,$(ACT_INC_LIBALX)) \
+ $(patsubst %,$(MODULES_BASE_INC_DIR)/%,$(ACT_INC_BASE)) \
+ $(patsubst %,$(MODULES_DEV_INC_DIR)/%,$(ACT_INC_DEV)) \
+ $(patsubst %,$(INC_DIR)/%,$(ACT_INC))
+ACT_INC_DIRS = -I $(INC_DIR) \
+ -I $(LIBALX_INC_DIR) \
+ -I $(MODULES_BASE_INC_DIR) \
+ -I $(MODULES_DEV_INC_DIR) \
+ $(COMMON_INC_DIRS)
+
+
+# target: dependencies
+# action
+
+all: $(ALL)
+
+
+system_stm32l4xx.o: $(SYS_DEPS)
+ @echo " CC $@"
+ $(Q)$(CC) $(CFLAGS) $(SYS_INC_DIRS) -c $< -o $@
+
+stm32l4xx_it.o: $(IT_DEPS)
+ @echo " CC $@"
+ $(Q)$(CC) $(CFLAGS) $(IT_INC_DIRS) -c $< -o $@
+
+main.o: $(MAIN_DEPS)
+ @echo " CC $@"
+ $(Q)$(CC) $(CFLAGS) $(MAIN_INC_DIRS) -c $< -o $@
+
+ctrl.o: $(CTRL_DEPS)
+ @echo " CC $@"
+ $(Q)$(CC) $(CFLAGS) $(CTRL_INC_DIRS) -c $< -o $@
+
+actuators.o: $(ACT_DEPS)
+ @echo " CC $@"
+ $(Q)$(CC) $(CFLAGS) $(ACT_INC_DIRS) -c $< -o $@
+
+
+clean:
+ $(Q)rm -f *.o
+
+################################################################################
+######## End of file ###########################################################
+################################################################################