diff --git a/.github/ISSUE_TEMPLATE/bug-form.yml b/.github/ISSUE_TEMPLATE/bug-form.yml new file mode 100644 index 0000000..f3df30d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-form.yml @@ -0,0 +1,34 @@ +name: Bug +description: For any issue related to a bug +title: '[Area] - Short Description' +labels: [bug] +body: + - type: textarea + id: observed-behavior + attributes: + label: Observed Behavior + description: What happened? + validations: + required: true + - type: textarea + id: expected-behavior + attributes: + label: Expected Behavior + description: What should have happened? + validations: + required: true + - type: textarea + id: steps-to-reproduce + attributes: + label: Steps to Reproduce + description: How could someone reproduce this bug? + value: "1. \n2. \n3. " + validations: + required: true + - type: textarea + id: screenshots + attributes: + label: Screenshots (as needed) + description: Add screenshots of the bug if applicable + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..0086358 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1 @@ +blank_issues_enabled: true diff --git a/.github/ISSUE_TEMPLATE/epic.yml b/.github/ISSUE_TEMPLATE/epic.yml new file mode 100644 index 0000000..1827d9e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/epic.yml @@ -0,0 +1,64 @@ +name: Epic +description: A collection of many tasks +title: '[Area] - Short Description' +labels: [epic] +body: + - type: textarea + id: overview + attributes: + label: Overview + description: Provide a brief summary of this epic + validations: + required: true + - type: textarea + id: stakeholders + attributes: + label: Stakeholders + description: Who to contact for this epic? + value: | + Product Stakeholder: + Software Stakeholder: + Reference Users: + - type: textarea + id: metrics + attributes: + label: Success Metrics + description: What are the metrics we will use to determine if this is successful? + validations: + required: true + - type: textarea + id: rollout + attributes: + label: Rollout Plan + description: How will this be released? All at once? In parts? + validations: + required: true + - type: textarea + id: scope + attributes: + label: Out of Scope + description: What is not included in this epic? + validations: + required: true + - type: textarea + id: background-context + attributes: + label: Background / Context + description: What is the context for this epic? What already exists? + validations: + required: true + - type: textarea + id: acceptance + attributes: + label: Acceptance Criteria + description: How are we evaluating the success of this epic? + validations: + required: true + - type: textarea + id: tickets + attributes: + label: Tickets + description: What tickets will be a part of this epic? + value: " - [ ] #\n - [ ] #" + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml new file mode 100644 index 0000000..4b491b0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.yml @@ -0,0 +1,26 @@ +name: Feature Request +description: Suggest a new feature for the project +title: '[Area] - Short Description' +labels: [new feature] +body: + - type: textarea + id: current-features + attributes: + label: Current Features + description: What exists currently? + validations: + required: true + - type: textarea + id: desired-features + attributes: + label: Desired Additional Features + description: What features do you want to add? + validations: + required: true + - type: textarea + id: screenshots + attributes: + label: Screenshots (as needed) + description: Add screenshots of the current or desired state if applicable + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/other.yml b/.github/ISSUE_TEMPLATE/other.yml new file mode 100644 index 0000000..7df8945 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/other.yml @@ -0,0 +1,18 @@ +name: Other +description: For issues that don't fit the other categories +title: '[Area] - Short Description' +body: + - type: textarea + id: desired-changes + attributes: + label: Desired Changes + description: What changes do you want to make? + validations: + required: true + - type: textarea + id: screenshots + attributes: + label: Screenshots (as needed) + description: Add screenshots if applicable + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/spike.yml b/.github/ISSUE_TEMPLATE/spike.yml new file mode 100644 index 0000000..f5dc1c4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/spike.yml @@ -0,0 +1,38 @@ +name: Spike +description: For any research or investigation into a feature or our current architecture +title: '[Area] - Short Description' +labels: [spike] +body: + - type: markdown + attributes: + value: For a spike ticket, please make sure to remember to add links to the resources you are pulling information from so others who are reviewing and giving feedback can also take a look at the same information you are looking at. + - type: dropdown + id: spike-type + attributes: + label: Spike Type + description: Is this spike about the product (functional) or the implementation of the product (technical)? + multiple: true + options: + - Functional + - Technical + - type: textarea + id: goal + attributes: + label: Goal + description: What is this spike ticket looking into/trying to solve? Is this about enhancing something we currently do or looking into a new feature? + validations: + required: true + - type: textarea + id: purpose + attributes: + label: Reason for Spike + description: Why is this spike ticket necessary? + validations: + required: true + - type: textarea + id: sidenotes + attributes: + label: Additional notes + description: Add any extra comments related to the spike. + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/task.yml b/.github/ISSUE_TEMPLATE/task.yml new file mode 100644 index 0000000..81bd791 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/task.yml @@ -0,0 +1,25 @@ +name: Task +description: Create a task that a developer can complete. +title: '[Area] - Short Description' +body: + - type: textarea + id: description + attributes: + label: Description + description: Provide a brief summary of this issue + validations: + required: true + - type: textarea + id: acceptance-criteria + attributes: + label: Acceptance Criteria + description: What are the conditions that need to be satisified to complete this task? + validations: + required: true + - type: textarea + id: proposed-solution + attributes: + label: Proposed Solution + description: How will this solution be implemented? What will be changed or added? + validations: + required: true diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..5c723e3 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,36 @@ +## Changes + +_Explanation of changes goes here_ + +## Notes + +_Any other notes go here_ + +## Test Cases + +- Case A +- Edge case +- ... + +## To Do + +_Any remaining things that need to get done_ + +- [ ] item 1 +- [ ] ... + +## Checklist + +It can be helpful to check the `Checks` and `Files changed` tabs. +Please reach out to your Project Lead if anything is unclear. +Please request reviewers and ping on slack only after you've gone through this whole checklist. + +- [ ] All commits are tagged with the ticket number +- [ ] No merge conflicts +- [ ] All checks passing +- [ ] Remove any non-applicable sections of this template +- [ ] Assign the PR to yourself +- [ ] Request reviewers & ping on Slack +- [ ] PR is linked to the ticket (fill in the closes line below) + +Closes # (issue #) diff --git a/.github/workflows/build-check.yml b/.github/workflows/build-check.yml index 2cb67d6..4dec4f0 100644 --- a/.github/workflows/build-check.yml +++ b/.github/workflows/build-check.yml @@ -17,4 +17,4 @@ jobs: if ! make; then echo "The application has failed to build." exit 1 # This will cause the workflow to fail - fi + fi \ No newline at end of file diff --git a/Core/Inc/can_handler.h b/Core/Inc/can_handler.h new file mode 100644 index 0000000..559ea8e --- /dev/null +++ b/Core/Inc/can_handler.h @@ -0,0 +1,37 @@ +#ifndef CAN_HANDLER_H +#define CAN_HANDLER_H + +#include "can.h" +#include "stm32f4xx_hal.h" +#include + + +#define NUM_INBOUND_CAN1_IDS 1 +#define NUM_INBOUND_CAN2_IDS 1 + +extern CAN_HandleTypeDef hcan1; +extern CAN_HandleTypeDef hcan2; + +extern ringbuffer_t* can1_rx_queue; +extern ringbuffer_t* can2_rx_queue; + +static const uint16_t can1_id_list[NUM_INBOUND_CAN1_IDS] = { + //CANID_X, + 0x0000 +}; + +static const uint16_t can2_id_list[NUM_INBOUND_CAN2_IDS] = { + //CANID_X, + 0x0000 +}; + + +void can_receive_callback(CAN_HandleTypeDef *hcan); + +/* for 1st CAN bus */ +int8_t get_can1_msg(); + +/* for 2nd CAN bus */ +int8_t get_can2_msg(); + +#endif // CAN_HANDLER_H \ No newline at end of file diff --git a/Core/Inc/compute.h b/Core/Inc/compute.h index 8e328ff..a9eaf25 100644 --- a/Core/Inc/compute.h +++ b/Core/Inc/compute.h @@ -3,6 +3,7 @@ #include "datastructs.h" #include "stateMachine.h" +#include "ringbuffer.h" #define CURRENT_SENSOR_PIN_L A1 #define CURRENT_SENSOR_PIN_H A0 diff --git a/Core/Inc/main.h b/Core/Inc/main.h index ac4b283..d20ed6b 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -1,121 +1,121 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.h - * @brief : Header for main.c file. - * This file contains the common defines of the application. - ****************************************************************************** - * @attention - * - * Copyright (c) 2023 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __MAIN_H -#define __MAIN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "stm32f4xx_hal.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -#include -/* USER CODE END Includes */ - -/* Exported types ------------------------------------------------------------*/ -/* USER CODE BEGIN ET */ - -/* USER CODE END ET */ - -/* Exported constants --------------------------------------------------------*/ -/* USER CODE BEGIN EC */ - -/* USER CODE END EC */ - -/* Exported macro ------------------------------------------------------------*/ -/* USER CODE BEGIN EM */ - -/* USER CODE END EM */ - -/* Exported functions prototypes ---------------------------------------------*/ -void Error_Handler(void); - -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -/* Private defines -----------------------------------------------------------*/ -#define FPGA_Reset_Pin GPIO_PIN_13 -#define FPGA_Reset_GPIO_Port GPIOC -#define Communication_GPIO_Pin GPIO_PIN_14 -#define Communication_GPIO_GPIO_Port GPIOC -#define Communication_GPIOC15_Pin GPIO_PIN_15 -#define Communication_GPIOC15_GPIO_Port GPIOC -#define Communication_GPIOC0_Pin GPIO_PIN_0 -#define Communication_GPIOC0_GPIO_Port GPIOC -#define SPI_2_CS_Pin GPIO_PIN_1 -#define SPI_2_CS_GPIO_Port GPIOC -#define Interlock_Read_Pin GPIO_PIN_2 -#define Interlock_Read_GPIO_Port GPIOA -#define Fault_Output_Pin GPIO_PIN_3 -#define Fault_Output_GPIO_Port GPIOA -#define SPI_1_CS_Pin GPIO_PIN_4 -#define SPI_1_CS_GPIO_Port GPIOA -#define Debug_LED_Pin GPIO_PIN_4 -#define Debug_LED_GPIO_Port GPIOC -#define I_Sense_Pin GPIO_PIN_5 -#define I_Sense_GPIO_Port GPIOC -#define I_SenseB0_Pin GPIO_PIN_0 -#define I_SenseB0_GPIO_Port GPIOB -#define I_SenseB1_Pin GPIO_PIN_1 -#define I_SenseB1_GPIO_Port GPIOB -#define I_SenseB2_Pin GPIO_PIN_2 -#define I_SenseB2_GPIO_Port GPIOB -#define Debug_LEDB11_Pin GPIO_PIN_11 -#define Debug_LEDB11_GPIO_Port GPIOB -#define Watchdog_Out_Pin GPIO_PIN_14 -#define Watchdog_Out_GPIO_Port GPIOB -#define Fan_PWM_Pin GPIO_PIN_6 -#define Fan_PWM_GPIO_Port GPIOC -#define Fan_PWMC7_Pin GPIO_PIN_7 -#define Fan_PWMC7_GPIO_Port GPIOC -#define Fan_PWMC8_Pin GPIO_PIN_8 -#define Fan_PWMC8_GPIO_Port GPIOC -#define Fan_PWMC9_Pin GPIO_PIN_9 -#define Fan_PWMC9_GPIO_Port GPIOC -#define Fan_PWMA8_Pin GPIO_PIN_8 -#define Fan_PWMA8_GPIO_Port GPIOA -#define Fan_PWMA10_Pin GPIO_PIN_10 -#define Fan_PWMA10_GPIO_Port GPIOA -#define SPI_3_CS_Pin GPIO_PIN_15 -#define SPI_3_CS_GPIO_Port GPIOA -#define External_GPIO_Pin GPIO_PIN_2 -#define External_GPIO_GPIO_Port GPIOD -#define External_GPIOB3_Pin GPIO_PIN_3 -#define External_GPIOB3_GPIO_Port GPIOB -#define External_GPIOB4_Pin GPIO_PIN_4 -#define External_GPIOB4_GPIO_Port GPIOB -#define External_GPIOB5_Pin GPIO_PIN_5 -#define External_GPIOB5_GPIO_Port GPIOB - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -#ifdef __cplusplus -} -#endif - -#endif /* __MAIN_H */ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.h + * @brief : Header for main.c file. + * This file contains the common defines of the application. + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __MAIN_H +#define __MAIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f4xx_hal.h" + +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ +#include +/* USER CODE END Includes */ + +/* Exported types ------------------------------------------------------------*/ +/* USER CODE BEGIN ET */ + +/* USER CODE END ET */ + +/* Exported constants --------------------------------------------------------*/ +/* USER CODE BEGIN EC */ + +/* USER CODE END EC */ + +/* Exported macro ------------------------------------------------------------*/ +/* USER CODE BEGIN EM */ + +/* USER CODE END EM */ + +/* Exported functions prototypes ---------------------------------------------*/ +void Error_Handler(void); + +/* USER CODE BEGIN EFP */ + +/* USER CODE END EFP */ + +/* Private defines -----------------------------------------------------------*/ +#define FPGA_Reset_Pin GPIO_PIN_13 +#define FPGA_Reset_GPIO_Port GPIOC +#define Communication_GPIO_Pin GPIO_PIN_14 +#define Communication_GPIO_GPIO_Port GPIOC +#define Communication_GPIOC15_Pin GPIO_PIN_15 +#define Communication_GPIOC15_GPIO_Port GPIOC +#define Communication_GPIOC0_Pin GPIO_PIN_0 +#define Communication_GPIOC0_GPIO_Port GPIOC +#define SPI_2_CS_Pin GPIO_PIN_1 +#define SPI_2_CS_GPIO_Port GPIOC +#define Interlock_Read_Pin GPIO_PIN_2 +#define Interlock_Read_GPIO_Port GPIOA +#define Fault_Output_Pin GPIO_PIN_3 +#define Fault_Output_GPIO_Port GPIOA +#define SPI_1_CS_Pin GPIO_PIN_4 +#define SPI_1_CS_GPIO_Port GPIOA +#define Debug_LED_Pin GPIO_PIN_4 +#define Debug_LED_GPIO_Port GPIOC +#define I_Sense_Pin GPIO_PIN_5 +#define I_Sense_GPIO_Port GPIOC +#define I_SenseB0_Pin GPIO_PIN_0 +#define I_SenseB0_GPIO_Port GPIOB +#define I_SenseB1_Pin GPIO_PIN_1 +#define I_SenseB1_GPIO_Port GPIOB +#define I_SenseB2_Pin GPIO_PIN_2 +#define I_SenseB2_GPIO_Port GPIOB +#define Debug_LEDB11_Pin GPIO_PIN_11 +#define Debug_LEDB11_GPIO_Port GPIOB +#define Watchdog_Out_Pin GPIO_PIN_14 +#define Watchdog_Out_GPIO_Port GPIOB +#define Fan_PWM_Pin GPIO_PIN_6 +#define Fan_PWM_GPIO_Port GPIOC +#define Fan_PWMC7_Pin GPIO_PIN_7 +#define Fan_PWMC7_GPIO_Port GPIOC +#define Fan_PWMC8_Pin GPIO_PIN_8 +#define Fan_PWMC8_GPIO_Port GPIOC +#define Fan_PWMC9_Pin GPIO_PIN_9 +#define Fan_PWMC9_GPIO_Port GPIOC +#define Fan_PWMA8_Pin GPIO_PIN_8 +#define Fan_PWMA8_GPIO_Port GPIOA +#define Fan_PWMA10_Pin GPIO_PIN_10 +#define Fan_PWMA10_GPIO_Port GPIOA +#define SPI_3_CS_Pin GPIO_PIN_15 +#define SPI_3_CS_GPIO_Port GPIOA +#define External_GPIO_Pin GPIO_PIN_2 +#define External_GPIO_GPIO_Port GPIOD +#define External_GPIOB3_Pin GPIO_PIN_3 +#define External_GPIOB3_GPIO_Port GPIOB +#define External_GPIOB4_Pin GPIO_PIN_4 +#define External_GPIOB4_GPIO_Port GPIOB +#define External_GPIOB5_Pin GPIO_PIN_5 +#define External_GPIOB5_GPIO_Port GPIOB + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H */ diff --git a/Core/Inc/stateMachine.h b/Core/Inc/stateMachine.h index c9f40fe..949cf99 100644 --- a/Core/Inc/stateMachine.h +++ b/Core/Inc/stateMachine.h @@ -43,7 +43,7 @@ uint32_t sm_fault_return(acc_data_t *accData); * @param index * @return fault_code */ -uint32_t sm_fault_eval(fault_eval_t index); +uint32_t sm_fault_eval(fault_eval_t* index); /** * @brief handles the state machine, calls the appropriate handler function and runs every loop functions diff --git a/Core/Inc/stm32f4xx_hal_conf.h b/Core/Inc/stm32f4xx_hal_conf.h index cb8a65f..ddcd734 100644 --- a/Core/Inc/stm32f4xx_hal_conf.h +++ b/Core/Inc/stm32f4xx_hal_conf.h @@ -1,495 +1,495 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32f4xx_hal_conf_template.h - * @author MCD Application Team - * @brief HAL configuration template file. - * This file should be copied to the application folder and renamed - * to stm32f4xx_hal_conf.h. - ****************************************************************************** - * @attention - * - * Copyright (c) 2017 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32F4xx_HAL_CONF_H -#define __STM32F4xx_HAL_CONF_H - -#ifdef __cplusplus - extern "C" { -#endif - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ - -/* ########################## Module Selection ############################## */ -/** - * @brief This is the list of modules to be used in the HAL driver - */ -#define HAL_MODULE_ENABLED - - /* #define HAL_CRYP_MODULE_ENABLED */ -/* #define HAL_ADC_MODULE_ENABLED */ -#define HAL_CAN_MODULE_ENABLED -/* #define HAL_CRC_MODULE_ENABLED */ -/* #define HAL_CAN_LEGACY_MODULE_ENABLED */ -/* #define HAL_DAC_MODULE_ENABLED */ -/* #define HAL_DCMI_MODULE_ENABLED */ -/* #define HAL_DMA2D_MODULE_ENABLED */ -/* #define HAL_ETH_MODULE_ENABLED */ -/* #define HAL_ETH_LEGACY_MODULE_ENABLED */ -/* #define HAL_NAND_MODULE_ENABLED */ -/* #define HAL_NOR_MODULE_ENABLED */ -/* #define HAL_PCCARD_MODULE_ENABLED */ -/* #define HAL_SRAM_MODULE_ENABLED */ -/* #define HAL_SDRAM_MODULE_ENABLED */ -/* #define HAL_HASH_MODULE_ENABLED */ -#define HAL_I2C_MODULE_ENABLED -/* #define HAL_I2S_MODULE_ENABLED */ -/* #define HAL_IWDG_MODULE_ENABLED */ -/* #define HAL_LTDC_MODULE_ENABLED */ -/* #define HAL_RNG_MODULE_ENABLED */ -/* #define HAL_RTC_MODULE_ENABLED */ -/* #define HAL_SAI_MODULE_ENABLED */ -/* #define HAL_SD_MODULE_ENABLED */ -/* #define HAL_MMC_MODULE_ENABLED */ -#define HAL_SPI_MODULE_ENABLED -/* #define HAL_TIM_MODULE_ENABLED */ -#define HAL_UART_MODULE_ENABLED -/* #define HAL_USART_MODULE_ENABLED */ -/* #define HAL_IRDA_MODULE_ENABLED */ -/* #define HAL_SMARTCARD_MODULE_ENABLED */ -/* #define HAL_SMBUS_MODULE_ENABLED */ -/* #define HAL_WWDG_MODULE_ENABLED */ -#define HAL_PCD_MODULE_ENABLED -/* #define HAL_HCD_MODULE_ENABLED */ -/* #define HAL_DSI_MODULE_ENABLED */ -/* #define HAL_QSPI_MODULE_ENABLED */ -/* #define HAL_QSPI_MODULE_ENABLED */ -/* #define HAL_CEC_MODULE_ENABLED */ -/* #define HAL_FMPI2C_MODULE_ENABLED */ -/* #define HAL_FMPSMBUS_MODULE_ENABLED */ -/* #define HAL_SPDIFRX_MODULE_ENABLED */ -/* #define HAL_DFSDM_MODULE_ENABLED */ -/* #define HAL_LPTIM_MODULE_ENABLED */ -#define HAL_GPIO_MODULE_ENABLED -#define HAL_EXTI_MODULE_ENABLED -#define HAL_DMA_MODULE_ENABLED -#define HAL_RCC_MODULE_ENABLED -#define HAL_FLASH_MODULE_ENABLED -#define HAL_PWR_MODULE_ENABLED -#define HAL_CORTEX_MODULE_ENABLED - -/* ########################## HSE/HSI Values adaptation ##################### */ -/** - * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. - * This value is used by the RCC HAL module to compute the system frequency - * (when HSE is used as system clock source, directly or through the PLL). - */ -#if !defined (HSE_VALUE) - #define HSE_VALUE 25000000U /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ - -/** - * @brief Internal High Speed oscillator (HSI) value. - * This value is used by the RCC HAL module to compute the system frequency - * (when HSI is used as system clock source, directly or through the PLL). - */ -#if !defined (HSI_VALUE) - #define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ - -/** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) - #define LSI_VALUE 32000U /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz - The real value may vary depending on the variations - in voltage and temperature.*/ -/** - * @brief External Low Speed oscillator (LSE) value. - */ -#if !defined (LSE_VALUE) - #define LSE_VALUE 32768U /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ - -#if !defined (LSE_STARTUP_TIMEOUT) - #define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ - -/** - * @brief External clock source for I2S peripheral - * This value is used by the I2S HAL module to compute the I2S clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined (EXTERNAL_CLOCK_VALUE) - #define EXTERNAL_CLOCK_VALUE 12288000U /*!< Value of the External audio frequency in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ - -/* Tip: To avoid modifying this file each time you need to use different HSE, - === you can define the HSE value in your toolchain compiler preprocessor. */ - -/* ########################### System Configuration ######################### */ -/** - * @brief This is the HAL system configuration section - */ -#define VDD_VALUE 3300U /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY 15U /*!< tick interrupt priority */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 1U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U - -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */ -#define USE_HAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */ -#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */ -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U /* CRYP register callback disabled */ -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */ -#define USE_HAL_DCMI_REGISTER_CALLBACKS 0U /* DCMI register callback disabled */ -#define USE_HAL_DFSDM_REGISTER_CALLBACKS 0U /* DFSDM register callback disabled */ -#define USE_HAL_DMA2D_REGISTER_CALLBACKS 0U /* DMA2D register callback disabled */ -#define USE_HAL_DSI_REGISTER_CALLBACKS 0U /* DSI register callback disabled */ -#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */ -#define USE_HAL_HASH_REGISTER_CALLBACKS 0U /* HASH register callback disabled */ -#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */ -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */ -#define USE_HAL_FMPI2C_REGISTER_CALLBACKS 0U /* FMPI2C register callback disabled */ -#define USE_HAL_FMPSMBUS_REGISTER_CALLBACKS 0U /* FMPSMBUS register callback disabled */ -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */ -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */ -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U /* LPTIM register callback disabled */ -#define USE_HAL_LTDC_REGISTER_CALLBACKS 0U /* LTDC register callback disabled */ -#define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */ -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */ -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */ -#define USE_HAL_PCCARD_REGISTER_CALLBACKS 0U /* PCCARD register callback disabled */ -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */ -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U /* QSPI register callback disabled */ -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U /* RNG register callback disabled */ -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */ -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U /* SAI register callback disabled */ -#define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */ -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */ -#define USE_HAL_SDRAM_REGISTER_CALLBACKS 0U /* SDRAM register callback disabled */ -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */ -#define USE_HAL_SPDIFRX_REGISTER_CALLBACKS 0U /* SPDIFRX register callback disabled */ -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U /* SMBUS register callback disabled */ -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */ -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */ -#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */ -#define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */ -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */ - -/* ########################## Assert Selection ############################## */ -/** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -/* #define USE_FULL_ASSERT 1U */ - -/* ################## Ethernet peripheral configuration ##################### */ - -/* Section 1 : Ethernet peripheral configuration */ - -/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ -#define MAC_ADDR0 2U -#define MAC_ADDR1 0U -#define MAC_ADDR2 0U -#define MAC_ADDR3 0U -#define MAC_ADDR4 0U -#define MAC_ADDR5 0U - -/* Definition of the Ethernet driver buffers size and count */ -#define ETH_RX_BUF_SIZE /* buffer size for receive */ -#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ -#define ETH_RXBUFNB 4U /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ -#define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ - -/* Section 2: PHY configuration section */ - -/* DP83848_PHY_ADDRESS Address*/ -#define DP83848_PHY_ADDRESS -/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ -#define PHY_RESET_DELAY 0x000000FFU -/* PHY Configuration delay */ -#define PHY_CONFIG_DELAY 0x00000FFFU - -#define PHY_READ_TO 0x0000FFFFU -#define PHY_WRITE_TO 0x0000FFFFU - -/* Section 3: Common PHY Registers */ - -#define PHY_BCR ((uint16_t)0x0000U) /*!< Transceiver Basic Control Register */ -#define PHY_BSR ((uint16_t)0x0001U) /*!< Transceiver Basic Status Register */ - -#define PHY_RESET ((uint16_t)0x8000U) /*!< PHY Reset */ -#define PHY_LOOPBACK ((uint16_t)0x4000U) /*!< Select loop-back mode */ -#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100U) /*!< Set the full-duplex mode at 100 Mb/s */ -#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000U) /*!< Set the half-duplex mode at 100 Mb/s */ -#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100U) /*!< Set the full-duplex mode at 10 Mb/s */ -#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000U) /*!< Set the half-duplex mode at 10 Mb/s */ -#define PHY_AUTONEGOTIATION ((uint16_t)0x1000U) /*!< Enable auto-negotiation function */ -#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200U) /*!< Restart auto-negotiation function */ -#define PHY_POWERDOWN ((uint16_t)0x0800U) /*!< Select the power down mode */ -#define PHY_ISOLATE ((uint16_t)0x0400U) /*!< Isolate PHY from MII */ - -#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020U) /*!< Auto-Negotiation process completed */ -#define PHY_LINKED_STATUS ((uint16_t)0x0004U) /*!< Valid link established */ -#define PHY_JABBER_DETECTION ((uint16_t)0x0002U) /*!< Jabber condition detected */ - -/* Section 4: Extended PHY Registers */ -#define PHY_SR ((uint16_t)) /*!< PHY status register Offset */ - -#define PHY_SPEED_STATUS ((uint16_t)) /*!< PHY Speed mask */ -#define PHY_DUPLEX_STATUS ((uint16_t)) /*!< PHY Duplex mask */ - -/* ################## SPI peripheral configuration ########################## */ - -/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver -* Activated: CRC code is present inside driver -* Deactivated: CRC code cleaned from driver -*/ - -#define USE_SPI_CRC 0U - -/* Includes ------------------------------------------------------------------*/ -/** - * @brief Include module's header file - */ - -#ifdef HAL_RCC_MODULE_ENABLED - #include "stm32f4xx_hal_rcc.h" -#endif /* HAL_RCC_MODULE_ENABLED */ - -#ifdef HAL_GPIO_MODULE_ENABLED - #include "stm32f4xx_hal_gpio.h" -#endif /* HAL_GPIO_MODULE_ENABLED */ - -#ifdef HAL_EXTI_MODULE_ENABLED - #include "stm32f4xx_hal_exti.h" -#endif /* HAL_EXTI_MODULE_ENABLED */ - -#ifdef HAL_DMA_MODULE_ENABLED - #include "stm32f4xx_hal_dma.h" -#endif /* HAL_DMA_MODULE_ENABLED */ - -#ifdef HAL_CORTEX_MODULE_ENABLED - #include "stm32f4xx_hal_cortex.h" -#endif /* HAL_CORTEX_MODULE_ENABLED */ - -#ifdef HAL_ADC_MODULE_ENABLED - #include "stm32f4xx_hal_adc.h" -#endif /* HAL_ADC_MODULE_ENABLED */ - -#ifdef HAL_CAN_MODULE_ENABLED - #include "stm32f4xx_hal_can.h" -#endif /* HAL_CAN_MODULE_ENABLED */ - -#ifdef HAL_CAN_LEGACY_MODULE_ENABLED - #include "stm32f4xx_hal_can_legacy.h" -#endif /* HAL_CAN_LEGACY_MODULE_ENABLED */ - -#ifdef HAL_CRC_MODULE_ENABLED - #include "stm32f4xx_hal_crc.h" -#endif /* HAL_CRC_MODULE_ENABLED */ - -#ifdef HAL_CRYP_MODULE_ENABLED - #include "stm32f4xx_hal_cryp.h" -#endif /* HAL_CRYP_MODULE_ENABLED */ - -#ifdef HAL_DMA2D_MODULE_ENABLED - #include "stm32f4xx_hal_dma2d.h" -#endif /* HAL_DMA2D_MODULE_ENABLED */ - -#ifdef HAL_DAC_MODULE_ENABLED - #include "stm32f4xx_hal_dac.h" -#endif /* HAL_DAC_MODULE_ENABLED */ - -#ifdef HAL_DCMI_MODULE_ENABLED - #include "stm32f4xx_hal_dcmi.h" -#endif /* HAL_DCMI_MODULE_ENABLED */ - -#ifdef HAL_ETH_MODULE_ENABLED - #include "stm32f4xx_hal_eth.h" -#endif /* HAL_ETH_MODULE_ENABLED */ - -#ifdef HAL_ETH_LEGACY_MODULE_ENABLED - #include "stm32f4xx_hal_eth_legacy.h" -#endif /* HAL_ETH_LEGACY_MODULE_ENABLED */ - -#ifdef HAL_FLASH_MODULE_ENABLED - #include "stm32f4xx_hal_flash.h" -#endif /* HAL_FLASH_MODULE_ENABLED */ - -#ifdef HAL_SRAM_MODULE_ENABLED - #include "stm32f4xx_hal_sram.h" -#endif /* HAL_SRAM_MODULE_ENABLED */ - -#ifdef HAL_NOR_MODULE_ENABLED - #include "stm32f4xx_hal_nor.h" -#endif /* HAL_NOR_MODULE_ENABLED */ - -#ifdef HAL_NAND_MODULE_ENABLED - #include "stm32f4xx_hal_nand.h" -#endif /* HAL_NAND_MODULE_ENABLED */ - -#ifdef HAL_PCCARD_MODULE_ENABLED - #include "stm32f4xx_hal_pccard.h" -#endif /* HAL_PCCARD_MODULE_ENABLED */ - -#ifdef HAL_SDRAM_MODULE_ENABLED - #include "stm32f4xx_hal_sdram.h" -#endif /* HAL_SDRAM_MODULE_ENABLED */ - -#ifdef HAL_HASH_MODULE_ENABLED - #include "stm32f4xx_hal_hash.h" -#endif /* HAL_HASH_MODULE_ENABLED */ - -#ifdef HAL_I2C_MODULE_ENABLED - #include "stm32f4xx_hal_i2c.h" -#endif /* HAL_I2C_MODULE_ENABLED */ - -#ifdef HAL_SMBUS_MODULE_ENABLED - #include "stm32f4xx_hal_smbus.h" -#endif /* HAL_SMBUS_MODULE_ENABLED */ - -#ifdef HAL_I2S_MODULE_ENABLED - #include "stm32f4xx_hal_i2s.h" -#endif /* HAL_I2S_MODULE_ENABLED */ - -#ifdef HAL_IWDG_MODULE_ENABLED - #include "stm32f4xx_hal_iwdg.h" -#endif /* HAL_IWDG_MODULE_ENABLED */ - -#ifdef HAL_LTDC_MODULE_ENABLED - #include "stm32f4xx_hal_ltdc.h" -#endif /* HAL_LTDC_MODULE_ENABLED */ - -#ifdef HAL_PWR_MODULE_ENABLED - #include "stm32f4xx_hal_pwr.h" -#endif /* HAL_PWR_MODULE_ENABLED */ - -#ifdef HAL_RNG_MODULE_ENABLED - #include "stm32f4xx_hal_rng.h" -#endif /* HAL_RNG_MODULE_ENABLED */ - -#ifdef HAL_RTC_MODULE_ENABLED - #include "stm32f4xx_hal_rtc.h" -#endif /* HAL_RTC_MODULE_ENABLED */ - -#ifdef HAL_SAI_MODULE_ENABLED - #include "stm32f4xx_hal_sai.h" -#endif /* HAL_SAI_MODULE_ENABLED */ - -#ifdef HAL_SD_MODULE_ENABLED - #include "stm32f4xx_hal_sd.h" -#endif /* HAL_SD_MODULE_ENABLED */ - -#ifdef HAL_SPI_MODULE_ENABLED - #include "stm32f4xx_hal_spi.h" -#endif /* HAL_SPI_MODULE_ENABLED */ - -#ifdef HAL_TIM_MODULE_ENABLED - #include "stm32f4xx_hal_tim.h" -#endif /* HAL_TIM_MODULE_ENABLED */ - -#ifdef HAL_UART_MODULE_ENABLED - #include "stm32f4xx_hal_uart.h" -#endif /* HAL_UART_MODULE_ENABLED */ - -#ifdef HAL_USART_MODULE_ENABLED - #include "stm32f4xx_hal_usart.h" -#endif /* HAL_USART_MODULE_ENABLED */ - -#ifdef HAL_IRDA_MODULE_ENABLED - #include "stm32f4xx_hal_irda.h" -#endif /* HAL_IRDA_MODULE_ENABLED */ - -#ifdef HAL_SMARTCARD_MODULE_ENABLED - #include "stm32f4xx_hal_smartcard.h" -#endif /* HAL_SMARTCARD_MODULE_ENABLED */ - -#ifdef HAL_WWDG_MODULE_ENABLED - #include "stm32f4xx_hal_wwdg.h" -#endif /* HAL_WWDG_MODULE_ENABLED */ - -#ifdef HAL_PCD_MODULE_ENABLED - #include "stm32f4xx_hal_pcd.h" -#endif /* HAL_PCD_MODULE_ENABLED */ - -#ifdef HAL_HCD_MODULE_ENABLED - #include "stm32f4xx_hal_hcd.h" -#endif /* HAL_HCD_MODULE_ENABLED */ - -#ifdef HAL_DSI_MODULE_ENABLED - #include "stm32f4xx_hal_dsi.h" -#endif /* HAL_DSI_MODULE_ENABLED */ - -#ifdef HAL_QSPI_MODULE_ENABLED - #include "stm32f4xx_hal_qspi.h" -#endif /* HAL_QSPI_MODULE_ENABLED */ - -#ifdef HAL_CEC_MODULE_ENABLED - #include "stm32f4xx_hal_cec.h" -#endif /* HAL_CEC_MODULE_ENABLED */ - -#ifdef HAL_FMPI2C_MODULE_ENABLED - #include "stm32f4xx_hal_fmpi2c.h" -#endif /* HAL_FMPI2C_MODULE_ENABLED */ - -#ifdef HAL_FMPSMBUS_MODULE_ENABLED - #include "stm32f4xx_hal_fmpsmbus.h" -#endif /* HAL_FMPSMBUS_MODULE_ENABLED */ - -#ifdef HAL_SPDIFRX_MODULE_ENABLED - #include "stm32f4xx_hal_spdifrx.h" -#endif /* HAL_SPDIFRX_MODULE_ENABLED */ - -#ifdef HAL_DFSDM_MODULE_ENABLED - #include "stm32f4xx_hal_dfsdm.h" -#endif /* HAL_DFSDM_MODULE_ENABLED */ - -#ifdef HAL_LPTIM_MODULE_ENABLED - #include "stm32f4xx_hal_lptim.h" -#endif /* HAL_LPTIM_MODULE_ENABLED */ - -#ifdef HAL_MMC_MODULE_ENABLED - #include "stm32f4xx_hal_mmc.h" -#endif /* HAL_MMC_MODULE_ENABLED */ - -/* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT -/** - * @brief The assert_param macro is used for function's parameters check. - * @param expr If expr is false, it calls assert_failed function - * which reports the name of the source file and the source - * line number of the call that failed. - * If expr is true, it returns no value. - * @retval None - */ - #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) -/* Exported functions ------------------------------------------------------- */ - void assert_failed(uint8_t* file, uint32_t line); -#else - #define assert_param(expr) ((void)0U) -#endif /* USE_FULL_ASSERT */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32F4xx_HAL_CONF_H */ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f4xx_hal_conf_template.h + * @author MCD Application Team + * @brief HAL configuration template file. + * This file should be copied to the application folder and renamed + * to stm32f4xx_hal_conf.h. + ****************************************************************************** + * @attention + * + * Copyright (c) 2017 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F4xx_HAL_CONF_H +#define __STM32F4xx_HAL_CONF_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ + +/* ########################## Module Selection ############################## */ +/** + * @brief This is the list of modules to be used in the HAL driver + */ +#define HAL_MODULE_ENABLED + + /* #define HAL_CRYP_MODULE_ENABLED */ +/* #define HAL_ADC_MODULE_ENABLED */ +#define HAL_CAN_MODULE_ENABLED +/* #define HAL_CRC_MODULE_ENABLED */ +/* #define HAL_CAN_LEGACY_MODULE_ENABLED */ +/* #define HAL_DAC_MODULE_ENABLED */ +/* #define HAL_DCMI_MODULE_ENABLED */ +/* #define HAL_DMA2D_MODULE_ENABLED */ +/* #define HAL_ETH_MODULE_ENABLED */ +/* #define HAL_ETH_LEGACY_MODULE_ENABLED */ +/* #define HAL_NAND_MODULE_ENABLED */ +/* #define HAL_NOR_MODULE_ENABLED */ +/* #define HAL_PCCARD_MODULE_ENABLED */ +/* #define HAL_SRAM_MODULE_ENABLED */ +/* #define HAL_SDRAM_MODULE_ENABLED */ +/* #define HAL_HASH_MODULE_ENABLED */ +#define HAL_I2C_MODULE_ENABLED +/* #define HAL_I2S_MODULE_ENABLED */ +/* #define HAL_IWDG_MODULE_ENABLED */ +/* #define HAL_LTDC_MODULE_ENABLED */ +/* #define HAL_RNG_MODULE_ENABLED */ +/* #define HAL_RTC_MODULE_ENABLED */ +/* #define HAL_SAI_MODULE_ENABLED */ +/* #define HAL_SD_MODULE_ENABLED */ +/* #define HAL_MMC_MODULE_ENABLED */ +#define HAL_SPI_MODULE_ENABLED +/* #define HAL_TIM_MODULE_ENABLED */ +#define HAL_UART_MODULE_ENABLED +/* #define HAL_USART_MODULE_ENABLED */ +/* #define HAL_IRDA_MODULE_ENABLED */ +/* #define HAL_SMARTCARD_MODULE_ENABLED */ +/* #define HAL_SMBUS_MODULE_ENABLED */ +/* #define HAL_WWDG_MODULE_ENABLED */ +#define HAL_PCD_MODULE_ENABLED +/* #define HAL_HCD_MODULE_ENABLED */ +/* #define HAL_DSI_MODULE_ENABLED */ +/* #define HAL_QSPI_MODULE_ENABLED */ +/* #define HAL_QSPI_MODULE_ENABLED */ +/* #define HAL_CEC_MODULE_ENABLED */ +/* #define HAL_FMPI2C_MODULE_ENABLED */ +/* #define HAL_FMPSMBUS_MODULE_ENABLED */ +/* #define HAL_SPDIFRX_MODULE_ENABLED */ +/* #define HAL_DFSDM_MODULE_ENABLED */ +/* #define HAL_LPTIM_MODULE_ENABLED */ +#define HAL_GPIO_MODULE_ENABLED +#define HAL_EXTI_MODULE_ENABLED +#define HAL_DMA_MODULE_ENABLED +#define HAL_RCC_MODULE_ENABLED +#define HAL_FLASH_MODULE_ENABLED +#define HAL_PWR_MODULE_ENABLED +#define HAL_CORTEX_MODULE_ENABLED + +/* ########################## HSE/HSI Values adaptation ##################### */ +/** + * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSE is used as system clock source, directly or through the PLL). + */ +#if !defined (HSE_VALUE) + #define HSE_VALUE 25000000U /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */ +#endif /* HSE_STARTUP_TIMEOUT */ + +/** + * @brief Internal High Speed oscillator (HSI) value. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSI is used as system clock source, directly or through the PLL). + */ +#if !defined (HSI_VALUE) + #define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ + +/** + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) + #define LSI_VALUE 32000U /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz + The real value may vary depending on the variations + in voltage and temperature.*/ +/** + * @brief External Low Speed oscillator (LSE) value. + */ +#if !defined (LSE_VALUE) + #define LSE_VALUE 32768U /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ + +#if !defined (LSE_STARTUP_TIMEOUT) + #define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ + +/** + * @brief External clock source for I2S peripheral + * This value is used by the I2S HAL module to compute the I2S clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) + #define EXTERNAL_CLOCK_VALUE 12288000U /*!< Value of the External audio frequency in Hz*/ +#endif /* EXTERNAL_CLOCK_VALUE */ + +/* Tip: To avoid modifying this file each time you need to use different HSE, + === you can define the HSE value in your toolchain compiler preprocessor. */ + +/* ########################### System Configuration ######################### */ +/** + * @brief This is the HAL system configuration section + */ +#define VDD_VALUE 3300U /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY 15U /*!< tick interrupt priority */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 1U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U + +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */ +#define USE_HAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */ +#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */ +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U /* CRYP register callback disabled */ +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */ +#define USE_HAL_DCMI_REGISTER_CALLBACKS 0U /* DCMI register callback disabled */ +#define USE_HAL_DFSDM_REGISTER_CALLBACKS 0U /* DFSDM register callback disabled */ +#define USE_HAL_DMA2D_REGISTER_CALLBACKS 0U /* DMA2D register callback disabled */ +#define USE_HAL_DSI_REGISTER_CALLBACKS 0U /* DSI register callback disabled */ +#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */ +#define USE_HAL_HASH_REGISTER_CALLBACKS 0U /* HASH register callback disabled */ +#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */ +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */ +#define USE_HAL_FMPI2C_REGISTER_CALLBACKS 0U /* FMPI2C register callback disabled */ +#define USE_HAL_FMPSMBUS_REGISTER_CALLBACKS 0U /* FMPSMBUS register callback disabled */ +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */ +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */ +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U /* LPTIM register callback disabled */ +#define USE_HAL_LTDC_REGISTER_CALLBACKS 0U /* LTDC register callback disabled */ +#define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */ +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */ +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */ +#define USE_HAL_PCCARD_REGISTER_CALLBACKS 0U /* PCCARD register callback disabled */ +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */ +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U /* QSPI register callback disabled */ +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U /* RNG register callback disabled */ +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */ +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U /* SAI register callback disabled */ +#define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */ +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */ +#define USE_HAL_SDRAM_REGISTER_CALLBACKS 0U /* SDRAM register callback disabled */ +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */ +#define USE_HAL_SPDIFRX_REGISTER_CALLBACKS 0U /* SPDIFRX register callback disabled */ +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U /* SMBUS register callback disabled */ +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */ +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */ +#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */ +#define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */ +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */ + +/* ########################## Assert Selection ############################## */ +/** + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +/* #define USE_FULL_ASSERT 1U */ + +/* ################## Ethernet peripheral configuration ##################### */ + +/* Section 1 : Ethernet peripheral configuration */ + +/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ +#define MAC_ADDR0 2U +#define MAC_ADDR1 0U +#define MAC_ADDR2 0U +#define MAC_ADDR3 0U +#define MAC_ADDR4 0U +#define MAC_ADDR5 0U + +/* Definition of the Ethernet driver buffers size and count */ +#define ETH_RX_BUF_SIZE /* buffer size for receive */ +#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ +#define ETH_RXBUFNB 4U /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ +#define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ + +/* Section 2: PHY configuration section */ + +/* DP83848_PHY_ADDRESS Address*/ +#define DP83848_PHY_ADDRESS +/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ +#define PHY_RESET_DELAY 0x000000FFU +/* PHY Configuration delay */ +#define PHY_CONFIG_DELAY 0x00000FFFU + +#define PHY_READ_TO 0x0000FFFFU +#define PHY_WRITE_TO 0x0000FFFFU + +/* Section 3: Common PHY Registers */ + +#define PHY_BCR ((uint16_t)0x0000U) /*!< Transceiver Basic Control Register */ +#define PHY_BSR ((uint16_t)0x0001U) /*!< Transceiver Basic Status Register */ + +#define PHY_RESET ((uint16_t)0x8000U) /*!< PHY Reset */ +#define PHY_LOOPBACK ((uint16_t)0x4000U) /*!< Select loop-back mode */ +#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100U) /*!< Set the full-duplex mode at 100 Mb/s */ +#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000U) /*!< Set the half-duplex mode at 100 Mb/s */ +#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100U) /*!< Set the full-duplex mode at 10 Mb/s */ +#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000U) /*!< Set the half-duplex mode at 10 Mb/s */ +#define PHY_AUTONEGOTIATION ((uint16_t)0x1000U) /*!< Enable auto-negotiation function */ +#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200U) /*!< Restart auto-negotiation function */ +#define PHY_POWERDOWN ((uint16_t)0x0800U) /*!< Select the power down mode */ +#define PHY_ISOLATE ((uint16_t)0x0400U) /*!< Isolate PHY from MII */ + +#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020U) /*!< Auto-Negotiation process completed */ +#define PHY_LINKED_STATUS ((uint16_t)0x0004U) /*!< Valid link established */ +#define PHY_JABBER_DETECTION ((uint16_t)0x0002U) /*!< Jabber condition detected */ + +/* Section 4: Extended PHY Registers */ +#define PHY_SR ((uint16_t)) /*!< PHY status register Offset */ + +#define PHY_SPEED_STATUS ((uint16_t)) /*!< PHY Speed mask */ +#define PHY_DUPLEX_STATUS ((uint16_t)) /*!< PHY Duplex mask */ + +/* ################## SPI peripheral configuration ########################## */ + +/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver +* Activated: CRC code is present inside driver +* Deactivated: CRC code cleaned from driver +*/ + +#define USE_SPI_CRC 0U + +/* Includes ------------------------------------------------------------------*/ +/** + * @brief Include module's header file + */ + +#ifdef HAL_RCC_MODULE_ENABLED + #include "stm32f4xx_hal_rcc.h" +#endif /* HAL_RCC_MODULE_ENABLED */ + +#ifdef HAL_GPIO_MODULE_ENABLED + #include "stm32f4xx_hal_gpio.h" +#endif /* HAL_GPIO_MODULE_ENABLED */ + +#ifdef HAL_EXTI_MODULE_ENABLED + #include "stm32f4xx_hal_exti.h" +#endif /* HAL_EXTI_MODULE_ENABLED */ + +#ifdef HAL_DMA_MODULE_ENABLED + #include "stm32f4xx_hal_dma.h" +#endif /* HAL_DMA_MODULE_ENABLED */ + +#ifdef HAL_CORTEX_MODULE_ENABLED + #include "stm32f4xx_hal_cortex.h" +#endif /* HAL_CORTEX_MODULE_ENABLED */ + +#ifdef HAL_ADC_MODULE_ENABLED + #include "stm32f4xx_hal_adc.h" +#endif /* HAL_ADC_MODULE_ENABLED */ + +#ifdef HAL_CAN_MODULE_ENABLED + #include "stm32f4xx_hal_can.h" +#endif /* HAL_CAN_MODULE_ENABLED */ + +#ifdef HAL_CAN_LEGACY_MODULE_ENABLED + #include "stm32f4xx_hal_can_legacy.h" +#endif /* HAL_CAN_LEGACY_MODULE_ENABLED */ + +#ifdef HAL_CRC_MODULE_ENABLED + #include "stm32f4xx_hal_crc.h" +#endif /* HAL_CRC_MODULE_ENABLED */ + +#ifdef HAL_CRYP_MODULE_ENABLED + #include "stm32f4xx_hal_cryp.h" +#endif /* HAL_CRYP_MODULE_ENABLED */ + +#ifdef HAL_DMA2D_MODULE_ENABLED + #include "stm32f4xx_hal_dma2d.h" +#endif /* HAL_DMA2D_MODULE_ENABLED */ + +#ifdef HAL_DAC_MODULE_ENABLED + #include "stm32f4xx_hal_dac.h" +#endif /* HAL_DAC_MODULE_ENABLED */ + +#ifdef HAL_DCMI_MODULE_ENABLED + #include "stm32f4xx_hal_dcmi.h" +#endif /* HAL_DCMI_MODULE_ENABLED */ + +#ifdef HAL_ETH_MODULE_ENABLED + #include "stm32f4xx_hal_eth.h" +#endif /* HAL_ETH_MODULE_ENABLED */ + +#ifdef HAL_ETH_LEGACY_MODULE_ENABLED + #include "stm32f4xx_hal_eth_legacy.h" +#endif /* HAL_ETH_LEGACY_MODULE_ENABLED */ + +#ifdef HAL_FLASH_MODULE_ENABLED + #include "stm32f4xx_hal_flash.h" +#endif /* HAL_FLASH_MODULE_ENABLED */ + +#ifdef HAL_SRAM_MODULE_ENABLED + #include "stm32f4xx_hal_sram.h" +#endif /* HAL_SRAM_MODULE_ENABLED */ + +#ifdef HAL_NOR_MODULE_ENABLED + #include "stm32f4xx_hal_nor.h" +#endif /* HAL_NOR_MODULE_ENABLED */ + +#ifdef HAL_NAND_MODULE_ENABLED + #include "stm32f4xx_hal_nand.h" +#endif /* HAL_NAND_MODULE_ENABLED */ + +#ifdef HAL_PCCARD_MODULE_ENABLED + #include "stm32f4xx_hal_pccard.h" +#endif /* HAL_PCCARD_MODULE_ENABLED */ + +#ifdef HAL_SDRAM_MODULE_ENABLED + #include "stm32f4xx_hal_sdram.h" +#endif /* HAL_SDRAM_MODULE_ENABLED */ + +#ifdef HAL_HASH_MODULE_ENABLED + #include "stm32f4xx_hal_hash.h" +#endif /* HAL_HASH_MODULE_ENABLED */ + +#ifdef HAL_I2C_MODULE_ENABLED + #include "stm32f4xx_hal_i2c.h" +#endif /* HAL_I2C_MODULE_ENABLED */ + +#ifdef HAL_SMBUS_MODULE_ENABLED + #include "stm32f4xx_hal_smbus.h" +#endif /* HAL_SMBUS_MODULE_ENABLED */ + +#ifdef HAL_I2S_MODULE_ENABLED + #include "stm32f4xx_hal_i2s.h" +#endif /* HAL_I2S_MODULE_ENABLED */ + +#ifdef HAL_IWDG_MODULE_ENABLED + #include "stm32f4xx_hal_iwdg.h" +#endif /* HAL_IWDG_MODULE_ENABLED */ + +#ifdef HAL_LTDC_MODULE_ENABLED + #include "stm32f4xx_hal_ltdc.h" +#endif /* HAL_LTDC_MODULE_ENABLED */ + +#ifdef HAL_PWR_MODULE_ENABLED + #include "stm32f4xx_hal_pwr.h" +#endif /* HAL_PWR_MODULE_ENABLED */ + +#ifdef HAL_RNG_MODULE_ENABLED + #include "stm32f4xx_hal_rng.h" +#endif /* HAL_RNG_MODULE_ENABLED */ + +#ifdef HAL_RTC_MODULE_ENABLED + #include "stm32f4xx_hal_rtc.h" +#endif /* HAL_RTC_MODULE_ENABLED */ + +#ifdef HAL_SAI_MODULE_ENABLED + #include "stm32f4xx_hal_sai.h" +#endif /* HAL_SAI_MODULE_ENABLED */ + +#ifdef HAL_SD_MODULE_ENABLED + #include "stm32f4xx_hal_sd.h" +#endif /* HAL_SD_MODULE_ENABLED */ + +#ifdef HAL_SPI_MODULE_ENABLED + #include "stm32f4xx_hal_spi.h" +#endif /* HAL_SPI_MODULE_ENABLED */ + +#ifdef HAL_TIM_MODULE_ENABLED + #include "stm32f4xx_hal_tim.h" +#endif /* HAL_TIM_MODULE_ENABLED */ + +#ifdef HAL_UART_MODULE_ENABLED + #include "stm32f4xx_hal_uart.h" +#endif /* HAL_UART_MODULE_ENABLED */ + +#ifdef HAL_USART_MODULE_ENABLED + #include "stm32f4xx_hal_usart.h" +#endif /* HAL_USART_MODULE_ENABLED */ + +#ifdef HAL_IRDA_MODULE_ENABLED + #include "stm32f4xx_hal_irda.h" +#endif /* HAL_IRDA_MODULE_ENABLED */ + +#ifdef HAL_SMARTCARD_MODULE_ENABLED + #include "stm32f4xx_hal_smartcard.h" +#endif /* HAL_SMARTCARD_MODULE_ENABLED */ + +#ifdef HAL_WWDG_MODULE_ENABLED + #include "stm32f4xx_hal_wwdg.h" +#endif /* HAL_WWDG_MODULE_ENABLED */ + +#ifdef HAL_PCD_MODULE_ENABLED + #include "stm32f4xx_hal_pcd.h" +#endif /* HAL_PCD_MODULE_ENABLED */ + +#ifdef HAL_HCD_MODULE_ENABLED + #include "stm32f4xx_hal_hcd.h" +#endif /* HAL_HCD_MODULE_ENABLED */ + +#ifdef HAL_DSI_MODULE_ENABLED + #include "stm32f4xx_hal_dsi.h" +#endif /* HAL_DSI_MODULE_ENABLED */ + +#ifdef HAL_QSPI_MODULE_ENABLED + #include "stm32f4xx_hal_qspi.h" +#endif /* HAL_QSPI_MODULE_ENABLED */ + +#ifdef HAL_CEC_MODULE_ENABLED + #include "stm32f4xx_hal_cec.h" +#endif /* HAL_CEC_MODULE_ENABLED */ + +#ifdef HAL_FMPI2C_MODULE_ENABLED + #include "stm32f4xx_hal_fmpi2c.h" +#endif /* HAL_FMPI2C_MODULE_ENABLED */ + +#ifdef HAL_FMPSMBUS_MODULE_ENABLED + #include "stm32f4xx_hal_fmpsmbus.h" +#endif /* HAL_FMPSMBUS_MODULE_ENABLED */ + +#ifdef HAL_SPDIFRX_MODULE_ENABLED + #include "stm32f4xx_hal_spdifrx.h" +#endif /* HAL_SPDIFRX_MODULE_ENABLED */ + +#ifdef HAL_DFSDM_MODULE_ENABLED + #include "stm32f4xx_hal_dfsdm.h" +#endif /* HAL_DFSDM_MODULE_ENABLED */ + +#ifdef HAL_LPTIM_MODULE_ENABLED + #include "stm32f4xx_hal_lptim.h" +#endif /* HAL_LPTIM_MODULE_ENABLED */ + +#ifdef HAL_MMC_MODULE_ENABLED + #include "stm32f4xx_hal_mmc.h" +#endif /* HAL_MMC_MODULE_ENABLED */ + +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT +/** + * @brief The assert_param macro is used for function's parameters check. + * @param expr If expr is false, it calls assert_failed function + * which reports the name of the source file and the source + * line number of the call that failed. + * If expr is true, it returns no value. + * @retval None + */ + #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ + void assert_failed(uint8_t* file, uint32_t line); +#else + #define assert_param(expr) ((void)0U) +#endif /* USE_FULL_ASSERT */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32F4xx_HAL_CONF_H */ diff --git a/Core/Inc/stm32f4xx_it.h b/Core/Inc/stm32f4xx_it.h index 37f04b4..0f1d5fe 100644 --- a/Core/Inc/stm32f4xx_it.h +++ b/Core/Inc/stm32f4xx_it.h @@ -1,66 +1,66 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32f4xx_it.h - * @brief This file contains the headers of the interrupt handlers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2023 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __STM32F4xx_IT_H -#define __STM32F4xx_IT_H - -#ifdef __cplusplus - extern "C" { -#endif - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Exported types ------------------------------------------------------------*/ -/* USER CODE BEGIN ET */ - -/* USER CODE END ET */ - -/* Exported constants --------------------------------------------------------*/ -/* USER CODE BEGIN EC */ - -/* USER CODE END EC */ - -/* Exported macro ------------------------------------------------------------*/ -/* USER CODE BEGIN EM */ - -/* USER CODE END EM */ - -/* Exported functions prototypes ---------------------------------------------*/ -void NMI_Handler(void); -void HardFault_Handler(void); -void MemManage_Handler(void); -void BusFault_Handler(void); -void UsageFault_Handler(void); -void SVC_Handler(void); -void DebugMon_Handler(void); -void PendSV_Handler(void); -void SysTick_Handler(void); -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32F4xx_IT_H */ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f4xx_it.h + * @brief This file contains the headers of the interrupt handlers. + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F4xx_IT_H +#define __STM32F4xx_IT_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* Exported types ------------------------------------------------------------*/ +/* USER CODE BEGIN ET */ + +/* USER CODE END ET */ + +/* Exported constants --------------------------------------------------------*/ +/* USER CODE BEGIN EC */ + +/* USER CODE END EC */ + +/* Exported macro ------------------------------------------------------------*/ +/* USER CODE BEGIN EM */ + +/* USER CODE END EM */ + +/* Exported functions prototypes ---------------------------------------------*/ +void NMI_Handler(void); +void HardFault_Handler(void); +void MemManage_Handler(void); +void BusFault_Handler(void); +void UsageFault_Handler(void); +void SVC_Handler(void); +void DebugMon_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +/* USER CODE BEGIN EFP */ + +/* USER CODE END EFP */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32F4xx_IT_H */ diff --git a/Core/Src/analyzer.c b/Core/Src/analyzer.c index d52bac4..51b3ba2 100644 --- a/Core/Src/analyzer.c +++ b/Core/Src/analyzer.c @@ -403,7 +403,7 @@ void calc_open_cell_voltage() /* If we are within the current threshold for open voltage measurments */ else if (bmsdata->pack_current < (OCV_CURR_THRESH * 10) && bmsdata->pack_current > (-OCV_CURR_THRESH * 10)) { - if (is_timer_expired(&ocvTimer)) { + if (is_timer_expired(&ocvTimer) || !is_timer_active(&ocvTimer)) { for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) { for (uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { /* Sets open cell voltage to a moving average of OCV_AVG values */ diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c new file mode 100644 index 0000000..0651343 --- /dev/null +++ b/Core/Src/can_handler.c @@ -0,0 +1,69 @@ +#include "analyzer.h" +#include "ringbuffer.h" +#include "can_handler.h" + +ringbuffer_t* can1_rx_queue = NULL; +ringbuffer_t* can2_rx_queue = NULL; + +void can_receive_callback(CAN_HandleTypeDef* hcan) +{ + CAN_RxHeaderTypeDef rx_header; + can_msg_t new_msg; + /* Read in CAN message */ + if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &rx_header, new_msg.data) != HAL_OK) { + + // TODO add non crtical fault capability - could create one for failed can receieve + return; + } + + new_msg.len = rx_header.DLC; + new_msg.id = rx_header.StdId; + if (hcan == &hcan1) { + ringbuffer_enqueue(can1_rx_queue, &new_msg); + } else { + ringbuffer_enqueue(can2_rx_queue, &new_msg); + } +} + +int8_t get_can1_msg() +{ + /* no messages to read */ + if (ringbuffer_is_empty(can1_rx_queue)) + return -1; + + can_msg_t msg; + ringbuffer_dequeue(can1_rx_queue, &msg); + + // TODO list : + // 1. + switch (msg.id) { + default: + break; + } + return 0; +} + +int8_t get_can2_msg() +{ + /* no messages to read */ + if (ringbuffer_is_empty(can2_rx_queue)) + return -1; + + can_msg_t msg; + ringbuffer_dequeue(can2_rx_queue, &msg); + + // TODO list : + // 1. Charger connection flag - have Charger set up with following logic, add correct CAN ID + switch (msg.id) { + case 0x00: + if (msg.data[0] == 0x01) { + bmsdata->is_charger_connected = true; + } else { + bmsdata->is_charger_connected = false; + } + break; + default: + break; + } + return 0; +} diff --git a/Core/Src/compute.c b/Core/Src/compute.c index 76804f3..2112b25 100644 --- a/Core/Src/compute.c +++ b/Core/Src/compute.c @@ -1,23 +1,40 @@ #include "compute.h" +#include "can_handler.h" +#include "can.h" +#include "main.h" #include +#define MAX_CAN1_STORAGE 10 +#define MAX_CAN2_STORAGE 10 + uint8_t fan_speed; bool is_charging_enabled; enum { CHARGE_ENABLED, CHARGE_DISABLED }; +extern CAN_HandleTypeDef hcan1; +extern CAN_HandleTypeDef hcan2; + +can_t can1; // main can bus, used by most peripherals +can_t can2; // p2p can bus with charger + /* private function defintions */ uint8_t calc_charger_led_state(); void compute_init() { - // TODO UPDATE DRIVER HERE - //pinMode(CURRENT_SENSOR_PIN_H, INPUT); - //pinMode(CURRENT_SENSOR_PIN_L, INPUT); - //pinMode(MEAS_5VREF_PIN, INPUT); - //pinMode(FAULT_PIN, OUTPUT); - //pinMode(CHARGE_DETECT, INPUT); - //initializeCAN(CANLINE_2, CHARGER_BAUD, &(this->compute_charger_callback)); - //initializeCAN(CANLINE_1, MC_BAUD, &(this->compute_mc_callback)); + can1.hcan = &hcan1; + can1.id_list = can1_id_list; + can1.id_list_len = sizeof(can1_id_list) / sizeof(can1_id_list[0]); + can1.callback = can_receive_callback; + can1_rx_queue = ringbuffer_create(MAX_CAN1_STORAGE, sizeof(can_msg_t)); + can_init(&can1); + + can2.hcan = &hcan2; + can2.id_list = can2_id_list; + can2.id_list_len = sizeof(can2_id_list) / sizeof(can2_id_list[0]); + can2.callback = can_receive_callback; + can2_rx_queue = ringbuffer_create(MAX_CAN2_STORAGE, sizeof(can_msg_t)); + can_init(&can2); } void compute_enable_charging(bool enable_charging) @@ -34,45 +51,45 @@ int compute_send_charging_message(uint16_t voltage_to_set, acc_data_t* bms_data) // + 3200 uint8_t charger_leds; uint16_t reserved2_3; - } charger_msg; + } charger_msg_data; uint16_t current_to_set = bms_data->charge_limit; if (!is_charging_enabled) { - charger_msg.charger_control = 0b101; - //TODO NEW CAN DRIVER--------------------------------------------------------------------------------------------// - //sendMessageCAN2(CANMSG_CHARGER, 8, charger_msg); + charger_msg_data.charger_control = 0b101; + + can_msg_t charger_msg; + charger_msg.id = 0x00; // TODO replace with correct ID; + charger_msg.len = sizeof(charger_msg_data); + memcpy(charger_msg.data, &charger_msg_data, sizeof(charger_msg_data)); + + can_send_msg(&can2, &charger_msg); - /* return a fault if we DO detect a voltage after we stop charging */ - //return isCharging() ? 1 : 0; - } // equations taken from TSM2500 CAN protocol datasheet - charger_msg.charger_control = 0xFC; - charger_msg.charger_voltage = voltage_to_set * 10; + charger_msg_data.charger_control = 0xFC; + charger_msg_data.charger_voltage = voltage_to_set * 10; if (current_to_set > 10) { current_to_set = 10; } - charger_msg.charger_current = current_to_set * 10 + 3200; - charger_msg.charger_leds = calc_charger_led_state(bms_data); - charger_msg.reserved2_3 = 0xFFFF; - - uint8_t buf[8] = { 0 }; - memcpy(buf, &charger_msg, sizeof(charger_msg)); + charger_msg_data.charger_current = current_to_set * 10 + 3200; + charger_msg_data.charger_leds = calc_charger_led_state(bms_data); + charger_msg_data.reserved2_3 = 0xFFFF; - //TODO NEW CAN DRIVER--------------------------------------------------------------------------------------------// - //sendMessageCAN2(CANMSG_CHARGER, 8, buf); + can_msg_t charger_msg; + charger_msg.id = 0x00; // TODO replace with correct ID; + charger_msg.len = 8; + memcpy(charger_msg.data, &charger_msg_data, sizeof(charger_msg_data)); + can_send_msg(&can2, &charger_msg); - // return isCharging() ? NOT_FAULTED : FAULTED; //return a fault if we DON'T detect a voltage - // after we begin charging return 0; } bool compute_charger_connected() { - //TODO update pin - //return !(digitalRead(CHARGE_DETECT) == 1); + //TODO need to set up CAN msg that actually toggles this bool + return bmsdata->is_charger_connected; } //TODO add this back @@ -89,8 +106,8 @@ void compute_set_fan_speed(uint8_t new_fan_speed) void compute_set_fault(int fault_state) { - //TODO add this back - // digitalWrite(FAULT_PIN, !fault_state); + //TODO work with charger fw on this + HAL_GPIO_WritePin(GPIOA, Fault_Output_Pin, !fault_state); //if (true) digitalWrite(CHARGE_SAFETY_RELAY, 1); } @@ -145,16 +162,17 @@ void compute_send_mc_message(uint16_t user_max_charge, uint16_t user_max_dischar uint16_t maxDischarge; uint16_t maxCharge; - } mcMsg; + } mc_msg_data; - mcMsg.maxCharge = user_max_charge; - mcMsg.maxDischarge = user_max_discharge; + mc_msg_data.maxCharge = user_max_charge; + mc_msg_data.maxDischarge = user_max_discharge; - uint8_t buf[4] = { 0 }; - memcpy(buf, &mcMsg, sizeof(mcMsg)); + can_msg_t mc_msg; + mc_msg.id = 0x00; // TODO replace with correct ID; + mc_msg.len = sizeof(mc_msg_data); + memcpy(mc_msg.data, &mc_msg_data, sizeof(mc_msg_data)); - //TODO NEW CAN DRIVER--------------------------------------------------------------------------------------------// - //sendMessageCAN1(CANMSG_BMSCURRENTLIMITS, 4, buf); + can_send_msg(&can1, &mc_msg); } void compute_send_acc_status_message(acc_data_t* bmsdata) @@ -166,152 +184,133 @@ void compute_send_acc_status_message(acc_data_t* bmsdata) uint16_t pack_ah; uint8_t pack_soc; uint8_t pack_health; - } acc_status_msg; + } acc_status_msg_data; - acc_status_msg.packVolt = __builtin_bswap16(bmsdata->pack_voltage); - acc_status_msg.pack_current = __builtin_bswap16((uint16_t)(bmsdata->pack_current)); // convert with 2s complement - acc_status_msg.pack_ah = __builtin_bswap16(0); - acc_status_msg.pack_soc = bmsdata->soc; - acc_status_msg.pack_health = 0; + acc_status_msg_data.packVolt = __builtin_bswap16(bmsdata->pack_voltage); + acc_status_msg_data.pack_current = __builtin_bswap16((uint16_t)(bmsdata->pack_current)); // convert with 2s complement + acc_status_msg_data.pack_ah = __builtin_bswap16(0); + acc_status_msg_data.pack_soc = bmsdata->soc; + acc_status_msg_data.pack_health = 0; - uint8_t buf[8] = { 0 }; - memcpy(buf, &acc_status_msg, sizeof(acc_status_msg)); + can_msg_t acc_msg; + acc_msg.id = 0x00; // TODO replace with correct ID; + acc_msg.len = sizeof(acc_status_msg_data); + memcpy(acc_msg.data, &acc_status_msg_data, sizeof(acc_status_msg_data)); - //TODO NEW CAN DRIVER--------------------------------------------------------------------------------------------// - //sendMessageCAN1(CANMSG_BMSACCSTATUS, 8, buf); + can_send_msg(&can1, &acc_msg); } void compute_send_bms_status_message(acc_data_t* bmsdata, int bms_state, bool balance) { - - struct __attribute__((packed)) { - uint8_t state; - uint32_t fault; - int8_t temp_avg; - uint8_t temp_internal; - uint8_t balance; - } bms_status_msg; - - bms_status_msg.temp_avg = (int8_t)(bmsdata->avg_temp); - bms_status_msg.state = (uint8_t)(bms_state); - bms_status_msg.fault = bmsdata->fault_code; - bms_status_msg.temp_internal = (uint8_t)(0); - bms_status_msg.balance = (uint8_t)(balance); - - /* uint8_t msg[8] = { - bms_status_msg.cfg.state, - (fault_status & 0xff000000), - (fault_status & 0x00ff0000), - (fault_status & 0x0000ff00), - (fault_status & 0x000000ff), - bms_status_msg.cfg.temp_avg, - bms_status_msg.cfg.balance - }; - */ - uint8_t buf[8] = { 0 }; - memcpy(buf, &bms_status_msg, sizeof(bms_status_msg)); - - //TODO NEW CAN DRIVER--------------------------------------------------------------------------------------------// - //sendMessageCAN1(CANMSG_BMSDTCSTATUS, 8, buf); + struct __attribute__((packed)) { + uint8_t state; + uint32_t fault; + int8_t temp_avg; + uint8_t temp_internal; + uint8_t balance; + } bms_status_msg_data; + + bms_status_msg_data.temp_avg = (int8_t)(bmsdata->avg_temp); + bms_status_msg_data.state = (uint8_t)(bms_state); + bms_status_msg_data.fault = bmsdata->fault_code; + bms_status_msg_data.temp_internal = (uint8_t)(0); + bms_status_msg_data.balance = (uint8_t)(balance); + + can_msg_t acc_msg; + acc_msg.id = 0x00; // TODO replace with correct ID; + acc_msg.len = sizeof(bms_status_msg_data); + memcpy(acc_msg.data, &bms_status_msg_data, sizeof(bms_status_msg_data)); + + can_send_msg(&can1, &acc_msg); } void compute_send_shutdown_ctrl_message(uint8_t mpe_state) { + struct __attribute__((packed)) { + uint8_t mpeState; + } shutdown_control_msg_data; - struct __attribute__((packed)) { - uint8_t mpeState; - - } shutdownControlMsg; - - shutdownControlMsg.mpeState = mpe_state; + shutdown_control_msg_data.mpeState = mpe_state; - uint8_t buf[1] = { 0 }; - memcpy(buf, &compute_send_shutdown_ctrl_message, sizeof(compute_send_shutdown_ctrl_message)); + can_msg_t acc_msg; + acc_msg.id = 0x00; // TODO replace with correct ID; + acc_msg.len = sizeof(shutdown_control_msg_data); + memcpy(acc_msg.data, &shutdown_control_msg_data, sizeof(shutdown_control_msg_data)); - //TODO NEW CAN DRIVER--------------------------------------------------------------------------------------------// - //sendMessageCAN1(0x03, 1, buf); + can_send_msg(&can1, &acc_msg); } void compute_send_cell_data_message(acc_data_t* bmsdata) { - struct __attribute__((packed)) { - uint16_t high_cell_voltage; - uint8_t high_cell_id; - uint16_t low_cell_voltage; - uint8_t low_cell_id; - uint16_t volt_avg; - } cell_data_msg; - - cell_data_msg.high_cell_voltage = bmsdata->max_voltage.val; - cell_data_msg.high_cell_id = bmsdata->max_voltage.chipIndex; - cell_data_msg.low_cell_voltage = bmsdata->min_voltage.val; - // Chip number Cell number - cell_data_msg.low_cell_id - = (bmsdata->min_voltage.chipIndex << 4) | bmsdata->min_voltage.cellNum; - cell_data_msg.volt_avg = bmsdata->avg_voltage; - - /* uint8_t msg[8] = { - ( cell_data_msg.cfg.high_cell_voltage & 0x00ff), - ((cell_data_msg.cfg.high_cell_voltage & 0xff00)>>8), - cell_data_msg.cfg.high_cell_id, - ( cell_data_msg.cfg.low_cell_voltage & 0x00ff), - ((cell_data_msg.cfg.low_cell_voltage & 0xff00)>>8), - cell_data_msg.cfg.low_cell_id, - ( cell_data_msg.cfg.volt_avg & 0x00ff), - ((cell_data_msg.cfg.volt_avg & 0xff00)>>8) - }; - */ - uint8_t buf[8] = { 0 }; - memcpy(buf, &cell_data_msg, sizeof(cell_data_msg)); - - //TODO NEW CAN DRIVER--------------------------------------------------------------------------------------------// - //sendMessageCAN1(CANMSG_BMSCELLDATA, 8, buf); + struct __attribute__((packed)) { + uint16_t high_cell_voltage; + uint8_t high_cell_id; + uint16_t low_cell_voltage; + uint8_t low_cell_id; + uint16_t volt_avg; + } cell_data_msg_data; + + cell_data_msg_data.high_cell_voltage = bmsdata->max_voltage.val; + cell_data_msg_data.high_cell_id = bmsdata->max_voltage.chipIndex; + cell_data_msg_data.low_cell_voltage = bmsdata->min_voltage.val; + cell_data_msg_data.low_cell_id = (bmsdata->min_voltage.chipIndex << 4) | bmsdata->min_voltage.cellNum; + cell_data_msg_data.volt_avg = bmsdata->avg_voltage; + + can_msg_t acc_msg; + acc_msg.id = 0x00; // TODO replace with correct ID; + acc_msg.len = sizeof(cell_data_msg_data); + memcpy(acc_msg.data, &cell_data_msg_data, sizeof(cell_data_msg_data)); + + can_send_msg(&can1, &acc_msg); } void compute_send_cell_voltage_message(uint8_t cell_id, uint16_t instant_voltage, - uint16_t internal_Res, uint8_t shunted, - uint16_t open_voltage) + uint16_t internal_Res, uint8_t shunted, + uint16_t open_voltage) { - struct __attribute__((packed)) { - uint8_t cellID; - uint16_t instantVoltage; - uint16_t internalResistance; - uint8_t shunted; - uint16_t openVoltage; - } cell_voltage_msg; - - cell_voltage_msg.cellID = cell_id; - cell_voltage_msg.instantVoltage = __builtin_bswap16(instant_voltage); - cell_voltage_msg.internalResistance = __builtin_bswap16(internal_Res); - cell_voltage_msg.shunted = shunted; - cell_voltage_msg.openVoltage = __builtin_bswap16(open_voltage); - - uint8_t buf[8] = { 0 }; - memcpy(buf, &cell_voltage_msg, sizeof(cell_voltage_msg)); - - //TODO NEW CAN DRIVER--------------------------------------------------------------------------------------------// - //sendMessageCAN1(0x07, 8, buf); + struct __attribute__((packed)) { + uint8_t cellID; + uint16_t instantVoltage; + uint16_t internalResistance; + uint8_t shunted; + uint16_t openVoltage; + } cell_voltage_msg_data; + + cell_voltage_msg_data.cellID = cell_id; + cell_voltage_msg_data.instantVoltage = __builtin_bswap16(instant_voltage); + cell_voltage_msg_data.internalResistance = __builtin_bswap16(internal_Res); + cell_voltage_msg_data.shunted = shunted; + cell_voltage_msg_data.openVoltage = __builtin_bswap16(open_voltage); + + can_msg_t acc_msg; + acc_msg.id = 0x00; // TODO replace with correct ID; + acc_msg.len = sizeof(cell_voltage_msg_data); + memcpy(acc_msg.data, &cell_voltage_msg_data, sizeof(cell_voltage_msg_data)); + + can_send_msg(&can1, &acc_msg); } void compute_send_current_message(acc_data_t* bmsdata) { - struct __attribute__((packed)) { - uint16_t dcl; - uint16_t ccl; - uint16_t pack_curr; - } current_status_msg; - - current_status_msg.dcl = bmsdata->discharge_limit; - current_status_msg.ccl = bmsdata->charge_limit; - current_status_msg.pack_curr = bmsdata->pack_current; - - uint8_t buf[8] = { 0 }; - memcpy(buf, ¤t_status_msg, sizeof(current_status_msg)); - - //TODO NEW CAN DRIVER--------------------------------------------------------------------------------------------// - //sendMessageCAN1(CANMSG_BMSCURRENTS, 8, buf); + struct __attribute__((packed)) { + uint16_t dcl; + uint16_t ccl; + uint16_t pack_curr; + } current_status_msg_data; + + current_status_msg_data.dcl = bmsdata->discharge_limit; + current_status_msg_data.ccl = bmsdata->charge_limit; + current_status_msg_data.pack_curr = bmsdata->pack_current; + + can_msg_t acc_msg; + acc_msg.id = 0x00; // TODO replace with correct ID; + acc_msg.len = sizeof(current_status_msg_data); + memcpy(acc_msg.data, ¤t_status_msg_data, sizeof(current_status_msg_data)); + + can_send_msg(&can1, &acc_msg); } -//TODO ADD THIS BACK + +// TODO ADD THIS BACK // void compute_mc_callback(const CAN_message_t& currentStatusMsg) // { // return; @@ -319,61 +318,51 @@ void compute_send_current_message(acc_data_t* bmsdata) void compute_send_cell_temp_message(acc_data_t* bmsdata) { - - struct __attribute__((packed)) { - uint16_t max_cell_temp; - uint8_t max_cell_id; - uint16_t min_cell_temp; - uint8_t min_cell_id; - uint16_t average_temp; - } cell_temp_msg; - - cell_temp_msg.max_cell_temp = bmsdata->max_temp.val; - cell_temp_msg.max_cell_id - = (bmsdata->max_temp.chipIndex << 4) | (bmsdata->max_temp.cellNum - 17); - cell_temp_msg.min_cell_temp = bmsdata->min_temp.val; - cell_temp_msg.min_cell_id - = (bmsdata->min_temp.chipIndex << 4) | (bmsdata->min_temp.cellNum - 17); - cell_temp_msg.average_temp = bmsdata->avg_temp; - - /* - uint8_t msg[8] = { - ( cell_temp_msg.cfg.max_cell_temp & 0x00ff), - ((cell_temp_msg.cfg.max_cell_temp & 0xff00)>>8), - cell_temp_msg.cfg.max_cell_id, - ( cell_temp_msg.cfg.min_cell_temp & 0x00ff), - ((cell_temp_msg.cfg.min_cell_temp & 0xff00)>>8), - cell_temp_msg.cfg.min_cell_id, - ( cell_temp_msg.cfg.average_temp & 0x00ff), - ((cell_temp_msg.cfg.average_temp & 0xff00)>>8) - }; - */ - uint8_t buf[8] = { 0 }; - memcpy(buf, &cell_temp_msg, sizeof(cell_temp_msg)); - - //TODO NEW CAN DRIVER--------------------------------------------------------------------------------------------// - //sendMessageCAN1(0x08, 8, buf); + struct __attribute__((packed)) { + uint16_t max_cell_temp; + uint8_t max_cell_id; + uint16_t min_cell_temp; + uint8_t min_cell_id; + uint16_t average_temp; + } cell_temp_msg_data; + + cell_temp_msg_data.max_cell_temp = bmsdata->max_temp.val; + cell_temp_msg_data.max_cell_id = (bmsdata->max_temp.chipIndex << 4) | (bmsdata->max_temp.cellNum - 17); + cell_temp_msg_data.min_cell_temp = bmsdata->min_temp.val; + cell_temp_msg_data.min_cell_id = (bmsdata->min_temp.chipIndex << 4) | (bmsdata->min_temp.cellNum - 17); + cell_temp_msg_data.average_temp = bmsdata->avg_temp; + + can_msg_t acc_msg; + acc_msg.id = 0x00; // TODO replace with correct ID; + acc_msg.len = sizeof(cell_temp_msg_data); + memcpy(acc_msg.data, &cell_temp_msg_data, sizeof(cell_temp_msg_data)); + + can_send_msg(&can1, &acc_msg); } void compute_send_segment_temp_message(acc_data_t* bmsdata) { - - struct __attribute__((packed)) { - int8_t segment1_average_temp; - int8_t segment2_average_temp; - int8_t segment3_average_temp; - int8_t segment4_average_temp; - } segment_temp_msg; - - segment_temp_msg.segment1_average_temp = bmsdata->segment_average_temps[0]; - segment_temp_msg.segment2_average_temp = bmsdata->segment_average_temps[1]; - segment_temp_msg.segment3_average_temp = bmsdata->segment_average_temps[2]; - segment_temp_msg.segment4_average_temp = bmsdata->segment_average_temps[3]; - uint8_t buff[4] = { 0 }; - memcpy(buff, &segment_temp_msg, sizeof(segment_temp_msg)); - - //TODO NEW CAN DRIVER--------------------------------------------------------------------------------------------// - //sendMessageCAN1(0x09, 4, buff); + struct __attribute__((packed)) { + int8_t segment1_average_temp; + int8_t segment2_average_temp; + int8_t segment3_average_temp; + int8_t segment4_average_temp; + } segment_temp_msg_data; + + segment_temp_msg_data.segment1_average_temp = bmsdata->segment_average_temps[0]; + segment_temp_msg_data.segment2_average_temp = bmsdata->segment_average_temps[1]; + segment_temp_msg_data.segment3_average_temp = bmsdata->segment_average_temps[2]; + segment_temp_msg_data.segment4_average_temp = bmsdata->segment_average_temps[3]; + + uint8_t buff[4] = { 0 }; + memcpy(buff, &segment_temp_msg_data, sizeof(segment_temp_msg_data)); + + can_msg_t acc_msg; + acc_msg.id = 0x00; // TODO replace with correct ID; + acc_msg.len = sizeof(segment_temp_msg_data); + memcpy(acc_msg.data, &segment_temp_msg_data, sizeof(segment_temp_msg_data)); + + can_send_msg(&can1, &acc_msg); } uint8_t calc_charger_led_state(acc_data_t* bms_data) diff --git a/Core/Src/main.c b/Core/Src/main.c index 2329d7f..9c5c2d4 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -21,6 +21,8 @@ #include "datastructs.h" #include "analyzer.h" #include "stateMachine.h" +#include "can_handler.h" +#include /* USER CODE END Includes */ @@ -32,11 +34,11 @@ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ -#ifdef DEBUG_EVERYTHING -#define DEBUG_CHARGING +//#ifdef DEBUG_EVERYTHING +//#define DEBUG_CHARGING #define DEBUG_STATS // etc etc -#endif +//#endif /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ @@ -75,105 +77,99 @@ static void MX_USB_OTG_FS_PCD_Init(void); static void MX_I2C1_Init(void); /* USER CODE BEGIN PFP */ -void watchdog_init(void); -void watchdog_pet(void); - /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ + +/* the following reroutes printf to uart */ +#ifdef __GNUC__ +#define PUTCHAR_PROTOTYPE int __io_putchar(int ch) +#else +#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) +#endif + +PUTCHAR_PROTOTYPE +{ + HAL_UART_Transmit(&huart4, (uint8_t *)&ch, 1, HAL_MAX_DELAY); + return ch; +} + +int _write(int file, char* ptr, int len) { + int DataIdx; + + for (DataIdx = 0; DataIdx < len; DataIdx++) { + __io_putchar( *ptr++ ); + } + return len; +} + #ifdef DEBUG_STATS const void print_bms_stats(acc_data_t *acc_data) { - static Timer debug_stat_timer; + + static nertimer_t debug_stat_timer; static const uint16_t PRINT_STAT_WAIT = 500; //ms - if(!debug_stat_timer.isTimerExpired()) return; - - Serial.print("Prev Fault: 0x"); - Serial.println(stateMachine.previousFault, HEX); - Serial.print("Current: "); - Serial.println((float)(acc_data->pack_current) / 10.0); - Serial.print("Min, Max, Avg Temps: "); - Serial.print(acc_data->min_temp.val); - Serial.print(", "); - Serial.print(acc_data->max_temp.val); - Serial.print(", "); - Serial.println(acc_data->avg_temp); - Serial.print("Min, Max, Avg, Delta Voltages: "); - Serial.print(acc_data->min_voltage.val); - Serial.print(", "); - Serial.print(acc_data->max_voltage.val); - Serial.print(", "); - Serial.print(acc_data->avg_voltage); - Serial.print(", "); - Serial.println(acc_data->delt_voltage); - - Serial.print("DCL: "); - Serial.println(acc_data->discharge_limit); - - Serial.print("CCL: "); - Serial.println(acc_data->charge_limit); - - Serial.print("SoC: "); - Serial.println(acc_data->soc); - - Serial.print("Is Balancing?: "); - Serial.println(segment.isBalancing()); - - Serial.print("State: "); - if (stateMachine.current_state == 0) Serial.println("BOOT"); - else if (stateMachine.current_state == 1) Serial.println("READY"); - else if (stateMachine.current_state == 2) Serial.println("CHARGING"); - else if (stateMachine.current_state == 1) Serial.println("FAULTED"); - - Serial.println("Raw Cell Voltage:"); - for(uint8_t c = 0; c < NUM_CHIPS; c++) - { - for(uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) - { - Serial.print(acc_data->chip_data[c].voltage_reading[cell]); - Serial.print("\t"); - } - Serial.println(); - } - - Serial.println("Open Cell Voltage:"); - for(uint8_t c = 0; c < NUM_CHIPS; c++) - { - for(uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) - { - Serial.print(acc_data->chip_data[c].open_cell_voltage[cell]); - Serial.print("\t"); - } - Serial.println(); - } - - Serial.println("Cell Temps:"); - for(uint8_t c = 0; c < NUM_CHIPS; c++) - { - for(uint8_t cell = 17; cell < 28; cell++) - { - Serial.print(acc_data->chip_data[c].thermistor_reading[cell]); - Serial.print("\t"); - } - Serial.println(); - } - - Serial.println("Avg Cell Temps:"); - for(uint8_t c = 0; c < NUM_CHIPS; c++) - { - for(uint8_t cell = 17; cell < 28; cell++) - { - Serial.print(acc_data->chip_data[c].thermistor_value[cell]); - Serial.print("\t"); - } - Serial.println(); - } - - - debug_stat_timer.startTimer(PRINT_STAT_WAIT); + if(!is_timer_expired(&debug_stat_timer) && debug_stat_timer.active) return; + HAL_UART_Transmit(&huart4, (char*)"butts", 5, 1000); + //TODO get this from eeprom once implemented + // question - should we read from eeprom here, or do that on loop and store locally? + //printf("Prev Fault: %#x", previousFault); + printf("Current: %f\r\n", (float)(acc_data->pack_current) / 10.0); + printf("Min, Max, Avg Temps: %ld, %ld, %d\r\n", acc_data->min_temp.val, acc_data->max_temp.val, acc_data->avg_temp); + printf("Min, Max, Avg, Delta Voltages: %ld, %ld, %d, %d\n", acc_data->min_voltage.val, acc_data->max_voltage.val, acc_data->avg_voltage, acc_data->delt_voltage); + printf("DCL: %d\r\n", acc_data->discharge_limit); + printf("CCL: %d\r\n", acc_data->charge_limit); + printf("SoC: %d\r\n", acc_data->soc); + printf("Is Balancing?: %d\r\n", segment_is_balancing()); + printf("State: "); + if (current_state == 0) printf("BOOT\r\n"); + else if (current_state == 1) printf("READY\r\n"); + else if (current_state == 2) printf("CHARGING\r\n"); + else if (current_state == 1) printf("FAULTED\r\n"); + printf("Raw Cell Voltage:\r\n"); + for(uint8_t c = 0; c < NUM_CHIPS; c++) + { + for(uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) + { + printf("%d\t", acc_data->chip_data[c].voltage_reading[cell]); + } + printf("\r\n"); + } + + printf("Open Cell Voltage:\n"); + for(uint8_t c = 0; c < NUM_CHIPS; c++) + { + for(uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) + { + printf("%d\t", acc_data->chip_data[c].open_cell_voltage[cell]); + } + printf("\r\n"); +} + + printf("Cell Temps:\r\n"); + for(uint8_t c = 0; c < NUM_CHIPS; c++) + { + for(uint8_t cell = 17; cell < 28; cell++) + { + printf("%d\t", acc_data->chip_data[c].thermistor_reading[cell]); + } + printf("\r\n"); + } + + printf("Avg Cell Temps:\r\n"); + for(uint8_t c = 0; c < NUM_CHIPS; c++) + { + for(uint8_t cell = 17; cell < 28; cell++) + { + printf("%d\t", acc_data->chip_data[c].thermistor_value[cell]); + } + printf("\r\n"); + } + + start_timer(&debug_stat_timer, PRINT_STAT_WAIT); } @@ -196,11 +192,7 @@ int main(void) HAL_Init(); /* USER CODE BEGIN Init */ - compute_set_fault(0); - segment_init(); - analyzer_sht30_init(); - watchdog_init(); - + /* USER CODE END Init */ /* Configure the system clock */ @@ -220,17 +212,22 @@ int main(void) MX_UART4_Init(); MX_USB_OTG_FS_PCD_Init(); MX_I2C1_Init(); - /* USER CODE BEGIN 2 */ - + segment_init(); + analyzer_sht30_init(); + watchdog_init(); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ for(;;) { /* Create a dynamically allocated structure */ + + HAL_GPIO_TogglePin(Debug_LEDB11_GPIO_Port, Debug_LEDB11_Pin); + HAL_Delay(500); + //HAL_UART_Transmit(&huart4, (char*)"hello", 5, 1000); + acc_data_t *acc_data = malloc(sizeof(acc_data_t)); - acc_data->sht30_data = malloc(sizeof(sht30_t)); //acc_data->faultCode = FAULTS_CLEAR; @@ -243,15 +240,20 @@ int main(void) /* Perform calculations on the data in the frame */ analyzer_push(acc_data); - sm_handle_state(acc_data); + /* check for inbound CAN */ + // get_can1_msg(); + // get_can2_msg(); + + #ifdef DEBUG_STATS - print_bms_stats(analyzer.bmsdata); + print_bms_stats(acc_data); #endif - + /* pet the watchdog */ watchdog_pet(); + //delay(10); // not sure if we need this in, it was in before } /* USER CODE END WHILE */ @@ -434,8 +436,8 @@ static void MX_SPI1_Init(void) hspi1.Init.Mode = SPI_MODE_MASTER; hspi1.Init.Direction = SPI_DIRECTION_2LINES; hspi1.Init.DataSize = SPI_DATASIZE_8BIT; - hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; - hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH; + hspi1.Init.CLKPhase = SPI_PHASE_2EDGE; hspi1.Init.NSS = SPI_NSS_SOFT; hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; @@ -699,7 +701,6 @@ static void MX_GPIO_Init(void) } /* USER CODE BEGIN 4 */ - void watchdog_init(void) { HAL_GPIO_WritePin(Watchdog_Out_GPIO_Port, Watchdog_Out_Pin, GPIO_PIN_SET); @@ -712,6 +713,7 @@ void watchdog_pet(void) HAL_GPIO_WritePin(Watchdog_Out_GPIO_Port, Watchdog_Out_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(Watchdog_Out_GPIO_Port, Watchdog_Out_Pin, GPIO_PIN_SET); } + /* USER CODE END 4 */ /** diff --git a/Core/Src/segment.c b/Core/Src/segment.c index 6caa8d2..64c190c 100644 --- a/Core/Src/segment.c +++ b/Core/Src/segment.c @@ -57,10 +57,10 @@ void segment_init() { printf("Initializing Segments..."); - //TODO again, ensure spi 1 is right (spi1 cs is PA04) - ltc68041 = LTC6804_initialize(&hspi1, GPIOA, 4); + ltc68041 = malloc(sizeof(ltc_config)); + LTC6804_initialize(ltc68041, &hspi1, GPIOA, 4); - // pull_chip_configuration(); + pull_chip_configuration(); for (int c = 0; c < NUM_CHIPS; c++) { local_config[c][0] = 0xF8; @@ -181,7 +181,7 @@ int pull_voltages() * just copy over the contents of the last good reading and the fault status * from the most recent attempt */ - if (!is_timer_expired(&voltage_reading_timer)) { + if (!is_timer_expired(&voltage_reading_timer) && voltage_reading_timer.active) { for (uint8_t i = 0; i < NUM_CHIPS; i++) { memcpy(segment_data[i].voltage_reading, previous_data[i].voltage_reading, sizeof(segment_data[i].voltage_reading)); diff --git a/Core/Src/stateMachine.c b/Core/Src/stateMachine.c index 519fb33..3b1e2cc 100644 --- a/Core/Src/stateMachine.c +++ b/Core/Src/stateMachine.c @@ -2,7 +2,7 @@ #include #define MIN(a, b) (((a) < (b)) ? (a) : (b)) - +extern UART_HandleTypeDef huart4; acc_data_t* prevAccData; uint32_t bms_fault = FAULTS_CLEAR; @@ -56,6 +56,7 @@ void handle_boot(acc_data_t* bmsdata) prevAccData = NULL; segment_enable_balancing(false); compute_enable_charging(false); + // bmsdata->fault_code = FAULTS_CLEAR; @@ -112,7 +113,7 @@ void handle_charging(acc_data_t* bmsdata) } /* Send CAN message, but not too often */ - if (is_timer_expired(&charger_message_timer)) { + if (is_timer_expired(&charger_message_timer) || !is_timer_active(&charger_message_timer)) { compute_send_charging_message( (MAX_CHARGE_VOLT * NUM_CELLS_PER_CHIP * NUM_CHIPS), bmsdata); start_timer(&charger_message_timer, CHARGE_MESSAGE_WAIT); @@ -156,22 +157,26 @@ void handle_faulted(acc_data_t* bmsdata) void sm_handle_state(acc_data_t* bmsdata) { bmsdata->is_charger_connected = compute_charger_connected(); + bmsdata->max_temp.val = 75; bmsdata->fault_code = sm_fault_return(bmsdata); + if (bmsdata->fault_code != FAULTS_CLEAR) { bmsdata->discharge_limit = 0; request_transition(FAULTED_STATE); } - - // TODO needs testing + // TODO needs testing - (update, seems to work fine) handler_LUT[current_state](bmsdata); compute_set_fan_speed(analyzer_calc_fan_pwm()); sm_broadcast_current_limit(bmsdata); + char state_test[1] = "0"; + state_test[0] = current_state + '0'; + /* send relevant CAN msgs */ // clang-format off - if (is_timer_expired(&can_msg_timer)) + if (is_timer_expired(&can_msg_timer) || !is_timer_active(&can_msg_timer)) { compute_send_acc_status_message(bmsdata); compute_send_current_message(bmsdata); @@ -182,6 +187,7 @@ void sm_handle_state(acc_data_t* bmsdata) start_timer(&can_msg_timer, CAN_MESSAGE_WAIT); } // clang-format on + } void request_transition(BMSState_t next_state) @@ -218,7 +224,7 @@ uint32_t sm_fault_return(acc_data_t* accData) /* Note that we are only allocating this table once at runtime, so there is no need to free it */ fault_table = (fault_eval_t*) malloc(NUM_FAULTS * sizeof(fault_eval_t)); // clang-format off - // ___________FAULT ID____________ __________TIMER___________ _____________DATA________________ __OPERATOR__ __________________________THRESHOLD____________________________ _______TIMER LENGTH_________ _____________FAULT CODE_________________ ___OPERATOR 2__ _______________DATA 2______________ __THRESHOLD 2__ + // ___________FAULT ID____________ __________TIMER___________ _____________DATA________________ __OPERATOR__ __________________________THRESHOLD____________________________ _______TIMER LENGTH_________ _____________FAULT CODE_________________ ___OPERATOR 2__ _______________DATA 2______________ __THRESHOLD 2__ fault_table[0] = (fault_eval_t) {.id = "Discharge Current Limit", .timer = ovr_curr_timer, .data_1 = fault_data->pack_current, .optype_1 = GT, .lim_1 = (fault_data->discharge_limit + DCDC_CURRENT_DRAW)*10*1.04, .timeout = OVER_CURR_TIME, .code = DISCHARGE_LIMIT_ENFORCEMENT_FAULT, .optype_2 = NOP/* ---------------------------UNUSED------------------- */ }; fault_table[1] = (fault_eval_t) {.id = "Charge Current Limit", .timer = ovr_chgcurr_timer, .data_1 = fault_data->pack_current, .optype_1 = GT, .lim_1 = (fault_data->charge_limit)*10, .timeout = OVER_CHG_CURR_TIME, .code = CHARGE_LIMIT_ENFORCEMENT_FAULT, .optype_2 = LT, .data_2 = fault_data->pack_current, .lim_2 = 0 }; fault_table[2] = (fault_eval_t) {.id = "Low Cell Voltage", .timer = undr_volt_timer, .data_1 = fault_data->min_voltage.val, .optype_1 = LT, .lim_1 = MIN_VOLT * 10000, .timeout = UNDER_VOLT_TIME, .code = CELL_VOLTAGE_TOO_LOW, .optype_2 = NOP/* ---------------------------UNUSED-------------------*/ }; @@ -231,59 +237,58 @@ uint32_t sm_fault_return(acc_data_t* accData) fault_table[8] = (fault_eval_t) {.id = NULL}; // clang-format on } - uint32_t fault_status = 0; + static uint32_t fault_status = 0; int incr = 0; - - while (&fault_table[incr].id != NULL) { - fault_status |= sm_fault_eval(fault_table[incr]); + while (fault_table[incr].id != NULL) { + fault_status |= sm_fault_eval(&fault_table[incr]); incr++; } return fault_status; } -uint32_t sm_fault_eval(fault_eval_t index) +uint32_t sm_fault_eval(fault_eval_t* index) { bool condition1; bool condition2; // clang-format off - switch (index.optype_1) + switch (index->optype_1) { - case GT: condition1 = index.data_1 > index.lim_1; break; - case LT: condition1 = index.data_1 < index.lim_1; break; - case GE: condition1 = index.data_1 >= index.lim_1; break; - case LE: condition1 = index.data_1 <= index.lim_1; break; - case EQ: condition1 = index.data_1 == index.lim_1; break; - case NEQ: condition1 = index.data_1 != index.lim_1; break; + case GT: condition1 = index->data_1 > index->lim_1; break; + case LT: condition1 = index->data_1 < index->lim_1; break; + case GE: condition1 = index->data_1 >= index->lim_1; break; + case LE: condition1 = index->data_1 <= index->lim_1; break; + case EQ: condition1 = index->data_1 == index->lim_1; break; + case NEQ: condition1 = index->data_1 != index->lim_1; break; case NOP: default: condition1 = true; } - switch (index.optype_2) + switch (index->optype_2) { - case GT: condition2 = index.data_2 > index.lim_2; break; - case LT: condition2 = index.data_2 < index.lim_2; break; - case GE: condition2 = index.data_2 >= index.lim_2; break; - case LE: condition2 = index.data_2 <= index.lim_2; break; - case EQ: condition2 = index.data_2 == index.lim_2; break; - case NEQ: condition2 = index.data_2 != index.lim_2; break; + case GT: condition2 = index->data_2 > index->lim_2; break; + case LT: condition2 = index->data_2 < index->lim_2; break; + case GE: condition2 = index->data_2 >= index->lim_2; break; + case LE: condition2 = index->data_2 <= index->lim_2; break; + case EQ: condition2 = index->data_2 == index->lim_2; break; + case NEQ: condition2 = index->data_2 != index->lim_2; break; case NOP: default: condition2 = true; } // clang-format on - if (!is_timer_active(&index.timer) && condition1 && condition2) + if (!is_timer_active(&index->timer) && condition1 && condition2) { - start_timer(&index.timer, index.timeout); + start_timer(&index->timer, index->timeout); } - else if (is_timer_active(&index.timer) && condition1 && condition2) { - if (is_timer_expired(&index.timer)) { - return index.code; + else if (is_timer_active(&index->timer) && condition1 && condition2) { + if (is_timer_expired(&index->timer)) { + return index->code; } if (!(condition1 && condition2)) { - cancel_timer(&index.timer); + cancel_timer(&index->timer); } } @@ -294,7 +299,7 @@ bool sm_charging_check(acc_data_t* bmsdata) { if (!compute_charger_connected()) return false; - if (!is_timer_expired(&charge_timeout)) + if (!is_timer_expired(&charge_timeout) && is_timer_active(&charge_timeout)) return false; if (bmsdata->max_voltage.val >= (MAX_CHARGE_VOLT * 10000) diff --git a/Core/Src/stm32f4xx_hal_msp.c b/Core/Src/stm32f4xx_hal_msp.c index d9a4aca..1ffb847 100644 --- a/Core/Src/stm32f4xx_hal_msp.c +++ b/Core/Src/stm32f4xx_hal_msp.c @@ -1,574 +1,574 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32f4xx_hal_msp.c - * @brief This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - * Copyright (c) 2023 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN TD */ - -/* USER CODE END TD */ - -/* Private define ------------------------------------------------------------*/ -/* USER CODE BEGIN Define */ - -/* USER CODE END Define */ - -/* Private macro -------------------------------------------------------------*/ -/* USER CODE BEGIN Macro */ - -/* USER CODE END Macro */ - -/* Private variables ---------------------------------------------------------*/ -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* External functions --------------------------------------------------------*/ -/* USER CODE BEGIN ExternalFunctions */ - -/* USER CODE END ExternalFunctions */ - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ -/** - * Initializes the Global MSP. - */ -void HAL_MspInit(void) -{ - /* USER CODE BEGIN MspInit 0 */ - - /* USER CODE END MspInit 0 */ - - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); - - /* System interrupt init*/ - - /* USER CODE BEGIN MspInit 1 */ - - /* USER CODE END MspInit 1 */ -} - -static uint32_t HAL_RCC_CAN1_CLK_ENABLED=0; - -/** -* @brief CAN MSP Initialization -* This function configures the hardware resources used in this example -* @param hcan: CAN handle pointer -* @retval None -*/ -void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(hcan->Instance==CAN1) - { - /* USER CODE BEGIN CAN1_MspInit 0 */ - - /* USER CODE END CAN1_MspInit 0 */ - /* Peripheral clock enable */ - HAL_RCC_CAN1_CLK_ENABLED++; - if(HAL_RCC_CAN1_CLK_ENABLED==1){ - __HAL_RCC_CAN1_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**CAN1 GPIO Configuration - PB8 ------> CAN1_RX - PB9 ------> CAN1_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF9_CAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* USER CODE BEGIN CAN1_MspInit 1 */ - - /* USER CODE END CAN1_MspInit 1 */ - } - else if(hcan->Instance==CAN2) - { - /* USER CODE BEGIN CAN2_MspInit 0 */ - - /* USER CODE END CAN2_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_CAN2_CLK_ENABLE(); - HAL_RCC_CAN1_CLK_ENABLED++; - if(HAL_RCC_CAN1_CLK_ENABLED==1){ - __HAL_RCC_CAN1_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**CAN2 GPIO Configuration - PB12 ------> CAN2_RX - PB13 ------> CAN2_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF9_CAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* USER CODE BEGIN CAN2_MspInit 1 */ - - /* USER CODE END CAN2_MspInit 1 */ - } - -} - -/** -* @brief CAN MSP De-Initialization -* This function freeze the hardware resources used in this example -* @param hcan: CAN handle pointer -* @retval None -*/ -void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan) -{ - if(hcan->Instance==CAN1) - { - /* USER CODE BEGIN CAN1_MspDeInit 0 */ - - /* USER CODE END CAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_CAN1_CLK_ENABLED--; - if(HAL_RCC_CAN1_CLK_ENABLED==0){ - __HAL_RCC_CAN1_CLK_DISABLE(); - } - - /**CAN1 GPIO Configuration - PB8 ------> CAN1_RX - PB9 ------> CAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); - - /* USER CODE BEGIN CAN1_MspDeInit 1 */ - - /* USER CODE END CAN1_MspDeInit 1 */ - } - else if(hcan->Instance==CAN2) - { - /* USER CODE BEGIN CAN2_MspDeInit 0 */ - - /* USER CODE END CAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_CAN2_CLK_DISABLE(); - HAL_RCC_CAN1_CLK_ENABLED--; - if(HAL_RCC_CAN1_CLK_ENABLED==0){ - __HAL_RCC_CAN1_CLK_DISABLE(); - } - - /**CAN2 GPIO Configuration - PB12 ------> CAN2_RX - PB13 ------> CAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); - - /* USER CODE BEGIN CAN2_MspDeInit 1 */ - - /* USER CODE END CAN2_MspDeInit 1 */ - } - -} - -/** -* @brief I2C MSP Initialization -* This function configures the hardware resources used in this example -* @param hi2c: I2C handle pointer -* @retval None -*/ -void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(hi2c->Instance==I2C1) - { - /* USER CODE BEGIN I2C1_MspInit 0 */ - - /* USER CODE END I2C1_MspInit 0 */ - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**I2C1 GPIO Configuration - PB6 ------> I2C1_SCL - PB7 ------> I2C1_SDA - */ - GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7; - GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF4_I2C1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* Peripheral clock enable */ - __HAL_RCC_I2C1_CLK_ENABLE(); - /* USER CODE BEGIN I2C1_MspInit 1 */ - - /* USER CODE END I2C1_MspInit 1 */ - } - -} - -/** -* @brief I2C MSP De-Initialization -* This function freeze the hardware resources used in this example -* @param hi2c: I2C handle pointer -* @retval None -*/ -void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c) -{ - if(hi2c->Instance==I2C1) - { - /* USER CODE BEGIN I2C1_MspDeInit 0 */ - - /* USER CODE END I2C1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_I2C1_CLK_DISABLE(); - - /**I2C1 GPIO Configuration - PB6 ------> I2C1_SCL - PB7 ------> I2C1_SDA - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6); - - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7); - - /* USER CODE BEGIN I2C1_MspDeInit 1 */ - - /* USER CODE END I2C1_MspDeInit 1 */ - } - -} - -/** -* @brief SPI MSP Initialization -* This function configures the hardware resources used in this example -* @param hspi: SPI handle pointer -* @retval None -*/ -void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(hspi->Instance==SPI1) - { - /* USER CODE BEGIN SPI1_MspInit 0 */ - - /* USER CODE END SPI1_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_SPI1_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**SPI1 GPIO Configuration - PA5 ------> SPI1_SCK - PA6 ------> SPI1_MISO - PA7 ------> SPI1_MOSI - */ - GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* USER CODE BEGIN SPI1_MspInit 1 */ - - /* USER CODE END SPI1_MspInit 1 */ - } - else if(hspi->Instance==SPI2) - { - /* USER CODE BEGIN SPI2_MspInit 0 */ - - /* USER CODE END SPI2_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_SPI2_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**SPI2 GPIO Configuration - PC2 ------> SPI2_MISO - PC3 ------> SPI2_MOSI - PB10 ------> SPI2_SCK - */ - GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = GPIO_PIN_10; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* USER CODE BEGIN SPI2_MspInit 1 */ - - /* USER CODE END SPI2_MspInit 1 */ - } - else if(hspi->Instance==SPI3) - { - /* USER CODE BEGIN SPI3_MspInit 0 */ - - /* USER CODE END SPI3_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_SPI3_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**SPI3 GPIO Configuration - PC10 ------> SPI3_SCK - PC11 ------> SPI3_MISO - PC12 ------> SPI3_MOSI - */ - GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF6_SPI3; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN SPI3_MspInit 1 */ - - /* USER CODE END SPI3_MspInit 1 */ - } - -} - -/** -* @brief SPI MSP De-Initialization -* This function freeze the hardware resources used in this example -* @param hspi: SPI handle pointer -* @retval None -*/ -void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) -{ - if(hspi->Instance==SPI1) - { - /* USER CODE BEGIN SPI1_MspDeInit 0 */ - - /* USER CODE END SPI1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_SPI1_CLK_DISABLE(); - - /**SPI1 GPIO Configuration - PA5 ------> SPI1_SCK - PA6 ------> SPI1_MISO - PA7 ------> SPI1_MOSI - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7); - - /* USER CODE BEGIN SPI1_MspDeInit 1 */ - - /* USER CODE END SPI1_MspDeInit 1 */ - } - else if(hspi->Instance==SPI2) - { - /* USER CODE BEGIN SPI2_MspDeInit 0 */ - - /* USER CODE END SPI2_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_SPI2_CLK_DISABLE(); - - /**SPI2 GPIO Configuration - PC2 ------> SPI2_MISO - PC3 ------> SPI2_MOSI - PB10 ------> SPI2_SCK - */ - HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2|GPIO_PIN_3); - - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10); - - /* USER CODE BEGIN SPI2_MspDeInit 1 */ - - /* USER CODE END SPI2_MspDeInit 1 */ - } - else if(hspi->Instance==SPI3) - { - /* USER CODE BEGIN SPI3_MspDeInit 0 */ - - /* USER CODE END SPI3_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_SPI3_CLK_DISABLE(); - - /**SPI3 GPIO Configuration - PC10 ------> SPI3_SCK - PC11 ------> SPI3_MISO - PC12 ------> SPI3_MOSI - */ - HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12); - - /* USER CODE BEGIN SPI3_MspDeInit 1 */ - - /* USER CODE END SPI3_MspDeInit 1 */ - } - -} - -/** -* @brief UART MSP Initialization -* This function configures the hardware resources used in this example -* @param huart: UART handle pointer -* @retval None -*/ -void HAL_UART_MspInit(UART_HandleTypeDef* huart) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(huart->Instance==UART4) - { - /* USER CODE BEGIN UART4_MspInit 0 */ - - /* USER CODE END UART4_MspInit 0 */ - /* Peripheral clock enable */ - __HAL_RCC_UART4_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**UART4 GPIO Configuration - PA0-WKUP ------> UART4_TX - PA1 ------> UART4_RX - */ - GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF8_UART4; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* USER CODE BEGIN UART4_MspInit 1 */ - - /* USER CODE END UART4_MspInit 1 */ - } - -} - -/** -* @brief UART MSP De-Initialization -* This function freeze the hardware resources used in this example -* @param huart: UART handle pointer -* @retval None -*/ -void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) -{ - if(huart->Instance==UART4) - { - /* USER CODE BEGIN UART4_MspDeInit 0 */ - - /* USER CODE END UART4_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_UART4_CLK_DISABLE(); - - /**UART4 GPIO Configuration - PA0-WKUP ------> UART4_TX - PA1 ------> UART4_RX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1); - - /* USER CODE BEGIN UART4_MspDeInit 1 */ - - /* USER CODE END UART4_MspDeInit 1 */ - } - -} - -/** -* @brief PCD MSP Initialization -* This function configures the hardware resources used in this example -* @param hpcd: PCD handle pointer -* @retval None -*/ -void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd) -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(hpcd->Instance==USB_OTG_FS) - { - /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */ - - /* USER CODE END USB_OTG_FS_MspInit 0 */ - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**USB_OTG_FS GPIO Configuration - PA9 ------> USB_OTG_FS_VBUS - PA11 ------> USB_OTG_FS_DM - PA12 ------> USB_OTG_FS_DP - */ - GPIO_InitStruct.Pin = GPIO_PIN_9; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* Peripheral clock enable */ - __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); - /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */ - - /* USER CODE END USB_OTG_FS_MspInit 1 */ - } - -} - -/** -* @brief PCD MSP De-Initialization -* This function freeze the hardware resources used in this example -* @param hpcd: PCD handle pointer -* @retval None -*/ -void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd) -{ - if(hpcd->Instance==USB_OTG_FS) - { - /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */ - - /* USER CODE END USB_OTG_FS_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_USB_OTG_FS_CLK_DISABLE(); - - /**USB_OTG_FS GPIO Configuration - PA9 ------> USB_OTG_FS_VBUS - PA11 ------> USB_OTG_FS_DM - PA12 ------> USB_OTG_FS_DP - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_11|GPIO_PIN_12); - - /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */ - - /* USER CODE END USB_OTG_FS_MspDeInit 1 */ - } - -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f4xx_hal_msp.c + * @brief This file provides code for the MSP Initialization + * and de-Initialization codes. + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN TD */ + +/* USER CODE END TD */ + +/* Private define ------------------------------------------------------------*/ +/* USER CODE BEGIN Define */ + +/* USER CODE END Define */ + +/* Private macro -------------------------------------------------------------*/ +/* USER CODE BEGIN Macro */ + +/* USER CODE END Macro */ + +/* Private variables ---------------------------------------------------------*/ +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* External functions --------------------------------------------------------*/ +/* USER CODE BEGIN ExternalFunctions */ + +/* USER CODE END ExternalFunctions */ + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ +/** + * Initializes the Global MSP. + */ +void HAL_MspInit(void) +{ + /* USER CODE BEGIN MspInit 0 */ + + /* USER CODE END MspInit 0 */ + + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); + + /* System interrupt init*/ + + /* USER CODE BEGIN MspInit 1 */ + + /* USER CODE END MspInit 1 */ +} + +static uint32_t HAL_RCC_CAN1_CLK_ENABLED=0; + +/** +* @brief CAN MSP Initialization +* This function configures the hardware resources used in this example +* @param hcan: CAN handle pointer +* @retval None +*/ +void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan) +{ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(hcan->Instance==CAN1) + { + /* USER CODE BEGIN CAN1_MspInit 0 */ + + /* USER CODE END CAN1_MspInit 0 */ + /* Peripheral clock enable */ + HAL_RCC_CAN1_CLK_ENABLED++; + if(HAL_RCC_CAN1_CLK_ENABLED==1){ + __HAL_RCC_CAN1_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**CAN1 GPIO Configuration + PB8 ------> CAN1_RX + PB9 ------> CAN1_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF9_CAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* USER CODE BEGIN CAN1_MspInit 1 */ + + /* USER CODE END CAN1_MspInit 1 */ + } + else if(hcan->Instance==CAN2) + { + /* USER CODE BEGIN CAN2_MspInit 0 */ + + /* USER CODE END CAN2_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_CAN2_CLK_ENABLE(); + HAL_RCC_CAN1_CLK_ENABLED++; + if(HAL_RCC_CAN1_CLK_ENABLED==1){ + __HAL_RCC_CAN1_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**CAN2 GPIO Configuration + PB12 ------> CAN2_RX + PB13 ------> CAN2_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF9_CAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* USER CODE BEGIN CAN2_MspInit 1 */ + + /* USER CODE END CAN2_MspInit 1 */ + } + +} + +/** +* @brief CAN MSP De-Initialization +* This function freeze the hardware resources used in this example +* @param hcan: CAN handle pointer +* @retval None +*/ +void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan) +{ + if(hcan->Instance==CAN1) + { + /* USER CODE BEGIN CAN1_MspDeInit 0 */ + + /* USER CODE END CAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_CAN1_CLK_ENABLED--; + if(HAL_RCC_CAN1_CLK_ENABLED==0){ + __HAL_RCC_CAN1_CLK_DISABLE(); + } + + /**CAN1 GPIO Configuration + PB8 ------> CAN1_RX + PB9 ------> CAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); + + /* USER CODE BEGIN CAN1_MspDeInit 1 */ + + /* USER CODE END CAN1_MspDeInit 1 */ + } + else if(hcan->Instance==CAN2) + { + /* USER CODE BEGIN CAN2_MspDeInit 0 */ + + /* USER CODE END CAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_CAN2_CLK_DISABLE(); + HAL_RCC_CAN1_CLK_ENABLED--; + if(HAL_RCC_CAN1_CLK_ENABLED==0){ + __HAL_RCC_CAN1_CLK_DISABLE(); + } + + /**CAN2 GPIO Configuration + PB12 ------> CAN2_RX + PB13 ------> CAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); + + /* USER CODE BEGIN CAN2_MspDeInit 1 */ + + /* USER CODE END CAN2_MspDeInit 1 */ + } + +} + +/** +* @brief I2C MSP Initialization +* This function configures the hardware resources used in this example +* @param hi2c: I2C handle pointer +* @retval None +*/ +void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) +{ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(hi2c->Instance==I2C1) + { + /* USER CODE BEGIN I2C1_MspInit 0 */ + + /* USER CODE END I2C1_MspInit 0 */ + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**I2C1 GPIO Configuration + PB6 ------> I2C1_SCL + PB7 ------> I2C1_SDA + */ + GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7; + GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF4_I2C1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* Peripheral clock enable */ + __HAL_RCC_I2C1_CLK_ENABLE(); + /* USER CODE BEGIN I2C1_MspInit 1 */ + + /* USER CODE END I2C1_MspInit 1 */ + } + +} + +/** +* @brief I2C MSP De-Initialization +* This function freeze the hardware resources used in this example +* @param hi2c: I2C handle pointer +* @retval None +*/ +void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c) +{ + if(hi2c->Instance==I2C1) + { + /* USER CODE BEGIN I2C1_MspDeInit 0 */ + + /* USER CODE END I2C1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_I2C1_CLK_DISABLE(); + + /**I2C1 GPIO Configuration + PB6 ------> I2C1_SCL + PB7 ------> I2C1_SDA + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6); + + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7); + + /* USER CODE BEGIN I2C1_MspDeInit 1 */ + + /* USER CODE END I2C1_MspDeInit 1 */ + } + +} + +/** +* @brief SPI MSP Initialization +* This function configures the hardware resources used in this example +* @param hspi: SPI handle pointer +* @retval None +*/ +void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) +{ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(hspi->Instance==SPI1) + { + /* USER CODE BEGIN SPI1_MspInit 0 */ + + /* USER CODE END SPI1_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_SPI1_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**SPI1 GPIO Configuration + PA5 ------> SPI1_SCK + PA6 ------> SPI1_MISO + PA7 ------> SPI1_MOSI + */ + GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* USER CODE BEGIN SPI1_MspInit 1 */ + + /* USER CODE END SPI1_MspInit 1 */ + } + else if(hspi->Instance==SPI2) + { + /* USER CODE BEGIN SPI2_MspInit 0 */ + + /* USER CODE END SPI2_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_SPI2_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**SPI2 GPIO Configuration + PC2 ------> SPI2_MISO + PC3 ------> SPI2_MOSI + PB10 ------> SPI2_SCK + */ + GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = GPIO_PIN_10; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* USER CODE BEGIN SPI2_MspInit 1 */ + + /* USER CODE END SPI2_MspInit 1 */ + } + else if(hspi->Instance==SPI3) + { + /* USER CODE BEGIN SPI3_MspInit 0 */ + + /* USER CODE END SPI3_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_SPI3_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**SPI3 GPIO Configuration + PC10 ------> SPI3_SCK + PC11 ------> SPI3_MISO + PC12 ------> SPI3_MOSI + */ + GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF6_SPI3; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /* USER CODE BEGIN SPI3_MspInit 1 */ + + /* USER CODE END SPI3_MspInit 1 */ + } + +} + +/** +* @brief SPI MSP De-Initialization +* This function freeze the hardware resources used in this example +* @param hspi: SPI handle pointer +* @retval None +*/ +void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) +{ + if(hspi->Instance==SPI1) + { + /* USER CODE BEGIN SPI1_MspDeInit 0 */ + + /* USER CODE END SPI1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_SPI1_CLK_DISABLE(); + + /**SPI1 GPIO Configuration + PA5 ------> SPI1_SCK + PA6 ------> SPI1_MISO + PA7 ------> SPI1_MOSI + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7); + + /* USER CODE BEGIN SPI1_MspDeInit 1 */ + + /* USER CODE END SPI1_MspDeInit 1 */ + } + else if(hspi->Instance==SPI2) + { + /* USER CODE BEGIN SPI2_MspDeInit 0 */ + + /* USER CODE END SPI2_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_SPI2_CLK_DISABLE(); + + /**SPI2 GPIO Configuration + PC2 ------> SPI2_MISO + PC3 ------> SPI2_MOSI + PB10 ------> SPI2_SCK + */ + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2|GPIO_PIN_3); + + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10); + + /* USER CODE BEGIN SPI2_MspDeInit 1 */ + + /* USER CODE END SPI2_MspDeInit 1 */ + } + else if(hspi->Instance==SPI3) + { + /* USER CODE BEGIN SPI3_MspDeInit 0 */ + + /* USER CODE END SPI3_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_SPI3_CLK_DISABLE(); + + /**SPI3 GPIO Configuration + PC10 ------> SPI3_SCK + PC11 ------> SPI3_MISO + PC12 ------> SPI3_MOSI + */ + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12); + + /* USER CODE BEGIN SPI3_MspDeInit 1 */ + + /* USER CODE END SPI3_MspDeInit 1 */ + } + +} + +/** +* @brief UART MSP Initialization +* This function configures the hardware resources used in this example +* @param huart: UART handle pointer +* @retval None +*/ +void HAL_UART_MspInit(UART_HandleTypeDef* huart) +{ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(huart->Instance==UART4) + { + /* USER CODE BEGIN UART4_MspInit 0 */ + + /* USER CODE END UART4_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_UART4_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**UART4 GPIO Configuration + PA0-WKUP ------> UART4_TX + PA1 ------> UART4_RX + */ + GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF8_UART4; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* USER CODE BEGIN UART4_MspInit 1 */ + + /* USER CODE END UART4_MspInit 1 */ + } + +} + +/** +* @brief UART MSP De-Initialization +* This function freeze the hardware resources used in this example +* @param huart: UART handle pointer +* @retval None +*/ +void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) +{ + if(huart->Instance==UART4) + { + /* USER CODE BEGIN UART4_MspDeInit 0 */ + + /* USER CODE END UART4_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_UART4_CLK_DISABLE(); + + /**UART4 GPIO Configuration + PA0-WKUP ------> UART4_TX + PA1 ------> UART4_RX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1); + + /* USER CODE BEGIN UART4_MspDeInit 1 */ + + /* USER CODE END UART4_MspDeInit 1 */ + } + +} + +/** +* @brief PCD MSP Initialization +* This function configures the hardware resources used in this example +* @param hpcd: PCD handle pointer +* @retval None +*/ +void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd) +{ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(hpcd->Instance==USB_OTG_FS) + { + /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */ + + /* USER CODE END USB_OTG_FS_MspInit 0 */ + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**USB_OTG_FS GPIO Configuration + PA9 ------> USB_OTG_FS_VBUS + PA11 ------> USB_OTG_FS_DM + PA12 ------> USB_OTG_FS_DP + */ + GPIO_InitStruct.Pin = GPIO_PIN_9; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* Peripheral clock enable */ + __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); + /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */ + + /* USER CODE END USB_OTG_FS_MspInit 1 */ + } + +} + +/** +* @brief PCD MSP De-Initialization +* This function freeze the hardware resources used in this example +* @param hpcd: PCD handle pointer +* @retval None +*/ +void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd) +{ + if(hpcd->Instance==USB_OTG_FS) + { + /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */ + + /* USER CODE END USB_OTG_FS_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USB_OTG_FS_CLK_DISABLE(); + + /**USB_OTG_FS GPIO Configuration + PA9 ------> USB_OTG_FS_VBUS + PA11 ------> USB_OTG_FS_DM + PA12 ------> USB_OTG_FS_DP + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_11|GPIO_PIN_12); + + /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */ + + /* USER CODE END USB_OTG_FS_MspDeInit 1 */ + } + +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/Core/Src/stm32f4xx_it.c b/Core/Src/stm32f4xx_it.c index 1490637..2ae44d9 100644 --- a/Core/Src/stm32f4xx_it.c +++ b/Core/Src/stm32f4xx_it.c @@ -1,203 +1,203 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32f4xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - * Copyright (c) 2023 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" -#include "stm32f4xx_it.h" -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN TD */ - -/* USER CODE END TD */ - -/* Private define ------------------------------------------------------------*/ -/* USER CODE BEGIN PD */ - -/* USER CODE END PD */ - -/* Private macro -------------------------------------------------------------*/ -/* USER CODE BEGIN PM */ - -/* USER CODE END PM */ - -/* Private variables ---------------------------------------------------------*/ -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* External variables --------------------------------------------------------*/ - -/* USER CODE BEGIN EV */ - -/* USER CODE END EV */ - -/******************************************************************************/ -/* Cortex-M4 Processor Interruption and Exception Handlers */ -/******************************************************************************/ -/** - * @brief This function handles Non maskable interrupt. - */ -void NMI_Handler(void) -{ - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ - while (1) - { - } - /* USER CODE END NonMaskableInt_IRQn 1 */ -} - -/** - * @brief This function handles Hard fault interrupt. - */ -void HardFault_Handler(void) -{ - /* USER CODE BEGIN HardFault_IRQn 0 */ - - /* USER CODE END HardFault_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_HardFault_IRQn 0 */ - /* USER CODE END W1_HardFault_IRQn 0 */ - } -} - -/** - * @brief This function handles Memory management fault. - */ -void MemManage_Handler(void) -{ - /* USER CODE BEGIN MemoryManagement_IRQn 0 */ - - /* USER CODE END MemoryManagement_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ - /* USER CODE END W1_MemoryManagement_IRQn 0 */ - } -} - -/** - * @brief This function handles Pre-fetch fault, memory access fault. - */ -void BusFault_Handler(void) -{ - /* USER CODE BEGIN BusFault_IRQn 0 */ - - /* USER CODE END BusFault_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_BusFault_IRQn 0 */ - /* USER CODE END W1_BusFault_IRQn 0 */ - } -} - -/** - * @brief This function handles Undefined instruction or illegal state. - */ -void UsageFault_Handler(void) -{ - /* USER CODE BEGIN UsageFault_IRQn 0 */ - - /* USER CODE END UsageFault_IRQn 0 */ - while (1) - { - /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ - /* USER CODE END W1_UsageFault_IRQn 0 */ - } -} - -/** - * @brief This function handles System service call via SWI instruction. - */ -void SVC_Handler(void) -{ - /* USER CODE BEGIN SVCall_IRQn 0 */ - - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ - - /* USER CODE END SVCall_IRQn 1 */ -} - -/** - * @brief This function handles Debug monitor. - */ -void DebugMon_Handler(void) -{ - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - - /* USER CODE END DebugMonitor_IRQn 1 */ -} - -/** - * @brief This function handles Pendable request for system service. - */ -void PendSV_Handler(void) -{ - /* USER CODE BEGIN PendSV_IRQn 0 */ - - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ - - /* USER CODE END PendSV_IRQn 1 */ -} - -/** - * @brief This function handles System tick timer. - */ -void SysTick_Handler(void) -{ - /* USER CODE BEGIN SysTick_IRQn 0 */ - - /* USER CODE END SysTick_IRQn 0 */ - HAL_IncTick(); - /* USER CODE BEGIN SysTick_IRQn 1 */ - - /* USER CODE END SysTick_IRQn 1 */ -} - -/******************************************************************************/ -/* STM32F4xx Peripheral Interrupt Handlers */ -/* Add here the Interrupt Handlers for the used peripherals. */ -/* For the available peripheral interrupt handler names, */ -/* please refer to the startup file (startup_stm32f4xx.s). */ -/******************************************************************************/ - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32f4xx_it.c + * @brief Interrupt Service Routines. + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" +#include "stm32f4xx_it.h" +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN TD */ + +/* USER CODE END TD */ + +/* Private define ------------------------------------------------------------*/ +/* USER CODE BEGIN PD */ + +/* USER CODE END PD */ + +/* Private macro -------------------------------------------------------------*/ +/* USER CODE BEGIN PM */ + +/* USER CODE END PM */ + +/* Private variables ---------------------------------------------------------*/ +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* Private user code ---------------------------------------------------------*/ +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/* External variables --------------------------------------------------------*/ + +/* USER CODE BEGIN EV */ + +/* USER CODE END EV */ + +/******************************************************************************/ +/* Cortex-M4 Processor Interruption and Exception Handlers */ +/******************************************************************************/ +/** + * @brief This function handles Non maskable interrupt. + */ +void NMI_Handler(void) +{ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + while (1) + { + } + /* USER CODE END NonMaskableInt_IRQn 1 */ +} + +/** + * @brief This function handles Hard fault interrupt. + */ +void HardFault_Handler(void) +{ + /* USER CODE BEGIN HardFault_IRQn 0 */ + + /* USER CODE END HardFault_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_HardFault_IRQn 0 */ + /* USER CODE END W1_HardFault_IRQn 0 */ + } +} + +/** + * @brief This function handles Memory management fault. + */ +void MemManage_Handler(void) +{ + /* USER CODE BEGIN MemoryManagement_IRQn 0 */ + + /* USER CODE END MemoryManagement_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ + /* USER CODE END W1_MemoryManagement_IRQn 0 */ + } +} + +/** + * @brief This function handles Pre-fetch fault, memory access fault. + */ +void BusFault_Handler(void) +{ + /* USER CODE BEGIN BusFault_IRQn 0 */ + + /* USER CODE END BusFault_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_BusFault_IRQn 0 */ + /* USER CODE END W1_BusFault_IRQn 0 */ + } +} + +/** + * @brief This function handles Undefined instruction or illegal state. + */ +void UsageFault_Handler(void) +{ + /* USER CODE BEGIN UsageFault_IRQn 0 */ + + /* USER CODE END UsageFault_IRQn 0 */ + while (1) + { + /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ + /* USER CODE END W1_UsageFault_IRQn 0 */ + } +} + +/** + * @brief This function handles System service call via SWI instruction. + */ +void SVC_Handler(void) +{ + /* USER CODE BEGIN SVCall_IRQn 0 */ + + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ + + /* USER CODE END SVCall_IRQn 1 */ +} + +/** + * @brief This function handles Debug monitor. + */ +void DebugMon_Handler(void) +{ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + + /* USER CODE END DebugMonitor_IRQn 1 */ +} + +/** + * @brief This function handles Pendable request for system service. + */ +void PendSV_Handler(void) +{ + /* USER CODE BEGIN PendSV_IRQn 0 */ + + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ + + /* USER CODE END PendSV_IRQn 1 */ +} + +/** + * @brief This function handles System tick timer. + */ +void SysTick_Handler(void) +{ + /* USER CODE BEGIN SysTick_IRQn 0 */ + + /* USER CODE END SysTick_IRQn 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ + + /* USER CODE END SysTick_IRQn 1 */ +} + +/******************************************************************************/ +/* STM32F4xx Peripheral Interrupt Handlers */ +/* Add here the Interrupt Handlers for the used peripherals. */ +/* For the available peripheral interrupt handler names, */ +/* please refer to the startup file (startup_stm32f4xx.s). */ +/******************************************************************************/ + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/Makefile b/Makefile index 1ff416e..e40ffd5 100644 --- a/Makefile +++ b/Makefile @@ -1,211 +1,213 @@ -########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [4.1.0] date: [Thu Nov 02 09:41:55 EDT 2023] -########################################################################################################################## - -# ------------------------------------------------ -# Generic Makefile (based on gcc) -# -# ChangeLog : -# 2017-02-10 - Several enhancements + project update mode -# 2015-07-22 - first version -# ------------------------------------------------ - -###################################### -# target -###################################### -TARGET = shepherd2 - - -###################################### -# building variables -###################################### -# debug build? -DEBUG = 1 -# optimization -OPT = -Og - - -####################################### -# paths -####################################### -# Build path -BUILD_DIR = build - -###################################### -# source -###################################### -# C sources -C_SOURCES = \ -Core/Src/main.c \ -Core/Src/analyzer.c \ -Core/Src/compute.c \ -Core/Src/eepromdirectory.c \ -Core/Src/segment.c \ -Core/Src/stateMachine.c \ -Core/Src/stm32f4xx_it.c \ -Core/Src/stm32f4xx_hal_msp.c \ -Drivers/Embedded-Base/platforms/stm32f405/src/can.c \ -Drivers/Embedded-Base/general/src/m24c32.c \ -Drivers/Embedded-Base/general/src/ltc68041.c \ -Drivers/Embedded-Base/general/src/sht30.c \ -Drivers/Embedded-Base/middleware/src/timer.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c \ -Core/Src/system_stm32f4xx.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c \ -Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c - -# ASM sources -ASM_SOURCES = \ -startup_stm32f405xx.s - - -####################################### -# binaries -####################################### -PREFIX = arm-none-eabi- -# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx) -# either it can be added to the PATH environment variable. -ifdef GCC_PATH -CC = $(GCC_PATH)/$(PREFIX)gcc -AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp -CP = $(GCC_PATH)/$(PREFIX)objcopy -SZ = $(GCC_PATH)/$(PREFIX)size -else -CC = $(PREFIX)gcc -AS = $(PREFIX)gcc -x assembler-with-cpp -CP = $(PREFIX)objcopy -SZ = $(PREFIX)size -endif -HEX = $(CP) -O ihex -BIN = $(CP) -O binary -S - -####################################### -# CFLAGS -####################################### -# cpu -CPU = -mcpu=cortex-m4 - -# fpu -FPU = -mfpu=fpv4-sp-d16 - -# float-abi -FLOAT-ABI = -mfloat-abi=hard - -# mcu -MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI) - -# macros for gcc -# AS defines -AS_DEFS = - -# C defines -C_DEFS = \ --DUSE_HAL_DRIVER \ --DSTM32F405xx - - -# AS includes -AS_INCLUDES = - -# C includes -C_INCLUDES = \ --ICore/Inc \ --IDrivers/STM32F4xx_HAL_Driver/Inc \ --IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy \ --IDrivers/CMSIS/Device/ST/STM32F4xx/Include \ --IDrivers/CMSIS/Include \ --IDrivers/Embedded-Base/general/include \ --IDrivers/Embedded-Base/platforms/stm32f405/include \ --IDrivers/Embedded-Base/middleware/include - - -# compile gcc flags -ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections - -CFLAGS += $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections - -ifeq ($(DEBUG), 1) -CFLAGS += -g -gdwarf-2 -endif - - -# Generate dependency information -CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" - - -####################################### -# LDFLAGS -####################################### -# link script -LDSCRIPT = STM32F405RGTx_FLASH.ld - -# libraries -LIBS = -lc -lm -lnosys -LIBDIR = -LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections - -# default action: build all -all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin - - -####################################### -# build the application -####################################### -# list of objects -OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) -vpath %.c $(sort $(dir $(C_SOURCES))) -# list of ASM program objects -OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o))) -vpath %.s $(sort $(dir $(ASM_SOURCES))) - -$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) - $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ - -$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR) - $(AS) -c $(CFLAGS) $< -o $@ - -$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile - $(CC) $(OBJECTS) $(LDFLAGS) -o $@ - $(SZ) $@ - -$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR) - $(HEX) $< $@ - -$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) - $(BIN) $< $@ - -$(BUILD_DIR): - mkdir $@ - -####################################### -# clean up -####################################### -clean: - -rm -fR $(BUILD_DIR) - -####################################### -# dependencies -####################################### --include $(wildcard $(BUILD_DIR)/*.d) - -# *** EOF *** +########################################################################################################################## +# File automatically-generated by tool: [projectgenerator] version: [4.2.0-B44] date: [Tue Jan 02 00:01:05 EST 2024] +########################################################################################################################## + +# ------------------------------------------------ +# Generic Makefile (based on gcc) +# +# ChangeLog : +# 2017-02-10 - Several enhancements + project update mode +# 2015-07-22 - first version +# ------------------------------------------------ + +###################################### +# target +###################################### +TARGET = shepherd2 + + +###################################### +# building variables +###################################### +# debug build? +DEBUG = 1 +# optimization +OPT = -Og + + +####################################### +# paths +####################################### +# Build path +BUILD_DIR = build + +###################################### +# source +###################################### +# C sources +C_SOURCES = \ +Core/Src/main.c \ +Core/Src/analyzer.c \ +Core/Src/compute.c \ +Core/Src/eepromdirectory.c \ +Core/Src/segment.c \ +Core/Src/stateMachine.c \ +Core/Src/can_handler.c \ +Core/Src/stm32f4xx_it.c \ +Core/Src/stm32f4xx_hal_msp.c \ +Drivers/Embedded-Base/platforms/stm32f405/src/can.c \ +Drivers/Embedded-Base/general/src/m24c32.c \ +Drivers/Embedded-Base/general/src/ltc68041.c \ +Drivers/Embedded-Base/general/src/sht30.c \ +Drivers/Embedded-Base/middleware/src/timer.c \ +Drivers/Embedded-Base/middleware/src/ringbuffer.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c \ +Core/Src/system_stm32f4xx.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c \ +Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c + +# ASM sources +ASM_SOURCES = \ +startup_stm32f405xx.s + + +####################################### +# binaries +####################################### +PREFIX = arm-none-eabi- +# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx) +# either it can be added to the PATH environment variable. +ifdef GCC_PATH +CC = $(GCC_PATH)/$(PREFIX)gcc +AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp +CP = $(GCC_PATH)/$(PREFIX)objcopy +SZ = $(GCC_PATH)/$(PREFIX)size +else +CC = $(PREFIX)gcc +AS = $(PREFIX)gcc -x assembler-with-cpp +CP = $(PREFIX)objcopy +SZ = $(PREFIX)size +endif +HEX = $(CP) -O ihex +BIN = $(CP) -O binary -S + +####################################### +# CFLAGS +####################################### +# cpu +CPU = -mcpu=cortex-m4 + +# fpu +FPU = -mfpu=fpv4-sp-d16 + +# float-abi +FLOAT-ABI = -mfloat-abi=hard + +# mcu +MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI) + +# macros for gcc +# AS defines +AS_DEFS = + +# C defines +C_DEFS = \ +-DUSE_HAL_DRIVER \ +-DSTM32F405xx + + +# AS includes +AS_INCLUDES = + +# C includes +C_INCLUDES = \ +-ICore/Inc \ +-IDrivers/STM32F4xx_HAL_Driver/Inc \ +-IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy \ +-IDrivers/CMSIS/Device/ST/STM32F4xx/Include \ +-IDrivers/CMSIS/Include \ +-IDrivers/Embedded-Base/general/include \ +-IDrivers/Embedded-Base/platforms/stm32f405/include \ +-IDrivers/Embedded-Base/middleware/include + + +# compile gcc flags +ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections + +CFLAGS += $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections + +ifeq ($(DEBUG), 1) +CFLAGS += -g -gdwarf-2 +endif + + +# Generate dependency information +CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" + + +####################################### +# LDFLAGS +####################################### +# link script +LDSCRIPT = STM32F405RGTx_FLASH.ld + +# libraries +LIBS = -lc -lm -lnosys +LIBDIR = +LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections + +# default action: build all +all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin + + +####################################### +# build the application +####################################### +# list of objects +OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) +vpath %.c $(sort $(dir $(C_SOURCES))) +# list of ASM program objects +OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o))) +vpath %.s $(sort $(dir $(ASM_SOURCES))) + +$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) + $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ + +$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR) + $(AS) -c $(CFLAGS) $< -o $@ + +$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile + $(CC) $(OBJECTS) $(LDFLAGS) -o $@ + $(SZ) $@ + +$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR) + $(HEX) $< $@ + +$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) + $(BIN) $< $@ + +$(BUILD_DIR): + mkdir $@ + +####################################### +# clean up +####################################### +clean: + -rm -fR $(BUILD_DIR) + +####################################### +# dependencies +####################################### +-include $(wildcard $(BUILD_DIR)/*.d) + +# *** EOF *** diff --git a/shepherd2.ioc b/shepherd2.ioc index ed9d0d0..e8c0db3 100644 --- a/shepherd2.ioc +++ b/shepherd2.ioc @@ -106,8 +106,8 @@ Mcu.PinsNb=51 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32F405RGTx -MxCube.Version=6.9.1 -MxDb.Version=DB.6.0.91 +MxCube.Version=6.10.0 +MxDb.Version=DB.6.0.100 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.ForceEnableDMAVector=true @@ -304,7 +304,7 @@ ProjectManager.ToolChainLocation= ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_CAN1_Init-CAN1-false-HAL-true,4-MX_CAN2_Init-CAN2-false-HAL-true,5-MX_SPI1_Init-SPI1-false-HAL-true,6-MX_SPI2_Init-SPI2-false-HAL-true,7-MX_SPI3_Init-SPI3-false-HAL-true,8-MX_UART4_Init-UART4-false-HAL-true,9-MX_USB_OTG_FS_PCD_Init-USB_OTG_FS-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_CAN1_Init-CAN1-false-HAL-true,4-MX_CAN2_Init-CAN2-false-HAL-true,5-MX_SPI1_Init-SPI1-false-HAL-true,6-MX_SPI2_Init-SPI2-false-HAL-true,7-MX_SPI3_Init-SPI3-false-HAL-true,8-MX_UART4_Init-UART4-false-HAL-true,9-MX_USB_OTG_FS_PCD_Init-USB_OTG_FS-false-HAL-true,10-MX_I2C1_Init-I2C1-false-HAL-true RCC.48MHZClocksFreq_Value=48000000 RCC.AHBFreq_Value=16000000 RCC.APB1Freq_Value=16000000 @@ -342,8 +342,8 @@ SH.S_TIM8_CH3.ConfNb=1 SH.S_TIM8_CH4.0=TIM8_CH4 SH.S_TIM8_CH4.ConfNb=1 SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_2 -SPI1.CLKPhase=SPI_PHASE_1EDGE -SPI1.CLKPolarity=SPI_POLARITY_LOW +SPI1.CLKPhase=SPI_PHASE_2EDGE +SPI1.CLKPolarity=SPI_POLARITY_HIGH SPI1.CRCCalculation=SPI_CRCCALCULATION_DISABLE SPI1.CalculateBaudRate=8.0 MBits/s SPI1.DataSize=SPI_DATASIZE_8BIT