diff options
author | AlejandroColomar <colomar.6.4.3@gmail.com> | 2019-01-12 21:42:24 +0100 |
---|---|---|
committer | AlejandroColomar <colomar.6.4.3@gmail.com> | 2019-01-12 21:42:24 +0100 |
commit | d05c6a2acfbdf4bb1e42e95c8e13cb19c87bf222 (patch) | |
tree | 1935e3f60992abe5ce4c92b777929eb4eed5a420 | |
parent | e39af4bf3903843de429ac73b2b416dd1f3e3ad8 (diff) |
dos2unix1.0
-rw-r--r-- | inc/actuators.h | 140 | ||||
-rw-r--r-- | inc/ctrl.h | 140 | ||||
-rw-r--r-- | src/actuators.c | 480 | ||||
-rw-r--r-- | src/ctrl.c | 538 | ||||
-rw-r--r-- | src/main.c | 368 | ||||
-rw-r--r-- | src/startup_stm32l476xx.s | 1048 | ||||
-rw-r--r-- | src/stm32l4xx_it.c | 292 | ||||
-rw-r--r-- | src/system_stm32l4xx.c | 726 | ||||
m--------- | stm32l4-drivers | 0 | ||||
m--------- | stm32l4-modules | 0 |
10 files changed, 1866 insertions, 1866 deletions
diff --git a/inc/actuators.h b/inc/actuators.h index c507330..3283fbd 100644 --- a/inc/actuators.h +++ b/inc/actuators.h @@ -1,70 +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 **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * 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 ********************************************************** + ******************************************************************************/ @@ -1,70 +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 **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * 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 index e4f8efa..d4c7e1d 100644 --- a/src/actuators.c +++ b/src/actuators.c @@ -1,240 +1,240 @@ -/******************************************************************************
- * 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 "libalx/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 **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * 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 "libalx/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 ********************************************************** + ******************************************************************************/ @@ -1,269 +1,269 @@ -/******************************************************************************
- * 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 "libalx/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 **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * 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 "libalx/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 ********************************************************** + ******************************************************************************/ @@ -1,184 +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 **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * 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 01 + if (proc_actuators_init()) { + stuck_forever(true); + } + #elif 1 + if (proc_ctrl_init()) { + stuck_forever(true); + } + #endif + + #if 01 + 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 index b93d40a..f353700 100644 --- a/src/startup_stm32l476xx.s +++ b/src/startup_stm32l476xx.s @@ -1,524 +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>© 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****/
+/** + ****************************************************************************** + * @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>© 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 index 31477a0..6aade74 100644 --- a/src/stm32l4xx_it.c +++ b/src/stm32l4xx_it.c @@ -1,146 +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>© 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****/
+/** + ****************************************************************************** + * @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>© 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 index d09954f..a207999 100644 --- a/src/system_stm32l4xx.c +++ b/src/system_stm32l4xx.c @@ -1,363 +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>© 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****/
+/** + ****************************************************************************** + * @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>© 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/stm32l4-drivers b/stm32l4-drivers -Subproject 108fd492d21998a3c5dcbd9037352509a353220 +Subproject 4ce59057c85bbac81fa44f956bfc392fcb6f120 diff --git a/stm32l4-modules b/stm32l4-modules -Subproject 098db59a417dbe7c226b9c58d369475d48a8cfc +Subproject f061888de747ef36615a396200b32d5a72ccdc3 |