From 5ad8e0e1ffdbbeb487b7260c0040390b89133579 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 9 Jul 2026 02:16:31 -0700 Subject: [PATCH 001/125] Finish documentation Signed-off-by: Daniel Hansen --- .gitignore | 6 +++++ CUBEMX.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 10 ++++++--- 3 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 CUBEMX.md diff --git a/.gitignore b/.gitignore index 8b70d611a..29c4d66d5 100644 --- a/.gitignore +++ b/.gitignore @@ -81,3 +81,9 @@ local # Makefile GNUmakefile + +# CubeMX Integration +EWARM +.mxproject +*/Core/Src/system_stm32*xx.c +*/*/Core/Src/system_stm32*xx.c diff --git a/CUBEMX.md b/CUBEMX.md new file mode 100644 index 000000000..7c8f81390 --- /dev/null +++ b/CUBEMX.md @@ -0,0 +1,64 @@ +> [!IMPORTANT] +> Note that using a peripheral abstraction (eg our version of CAN) means it will no longer be compatible with CubeMX. As a result please **disable** the peripheral within CubeMX and let the peripheral abstraction handle it. + +# STM32CubeMX + +This was last verified on version `6.18.0` + +STM32CubeMX2 is a different product that coexists with STM32CubeMX and (as of now) cannot be used. + +## Instructions + +The process to add a new MCU to the monorepo is complex. Please see `CMAKE.md` or ask the current Firmware Manager for assistance and they can help set it up for you. + +### Modification + +1. Open the appropriate `.ioc` file, corresponding to the project you are interested in, in CubeMX +2. Make changes as relevant, being careful not to violate the [Configuration](#configuration) steps +3. Generate code and then make sure to add/remove from your project `CMakeLists.txt` as relevant + +### Creation + +0. Ensure the MCU you are working on has been added to the monorepo, see the list in [`Lib/Platform`](Lib/Platform). +1. Open and setup a new project through CubeMX, follow the [Configuration](#configuration) steps +2. Generate code and verify that it lives in the correct area, like the other projects +3. Copy [`ProjectTemplate/CMakeLists.txt](ProjectTemplate/CMakeLists.txt) into your folder, edit as instructed by the comments + - Note that folders/files which are git ignored can be safely deleted or ignored. +4. Add a new entry to the root [`CMakeLists.txt`](CMakeLists.txt) containing the appropriate `add_gr_project` call following [`CMAKE.md`](CMAKE.md) +5. Add the appropriate entries to [`launch.json`](.vscode/launch.json) and [`tasks.json`](.vscode/tasks.json) following [`VSCODE.md`](VSCODE.md) + +## Configuration + +> [!IMPORTANT] +> Please ensure you follow these *exactly*, or it will not be guaranteed to work correctly. + +### Project Manager + +| Field | Value | +| :-- | :-- | +| Project Name | (Shortname, ie CCU, ECU) | +| Project Location | (Root of this Git repository) | +| Application Structure | Advanced | +| Do not generate the main() | FALSE / unchecked | +| Toolchain Location | (Root of this Git repository)/(Shortname from above) | +| Toolchain / IDE | `EWARM` | + +### Code Generator + +| Field | Value | +| :-- | :-- | +| STM32Cube MCU packages and embedded software packs | Add necessary library files as reference in the toolchain project configuration file | +| Generate peripheral initialization as a pair of '.c/.h' files per peripheral | TRUE / checked | +| Backup previously generated files when regenerating | FALSE / unchecked | +| Keep User Code when regenerating | TRUE / checked | +| Delete previously generated files when not regenerating | TRUE / checked | + +## Website + +See [STM32CubeMX](https://www.st.com/en/development-tools/stm32cubemx.html) for more from ST. + +To install please visit the ["Get Software"](https://www.st.com/en/development-tools/stm32cubemx.html#section-get-software-table) tab. + +## Purpose + +CubeMX provides a simple way to change clocks, setup peripheral initializations, and much more (including calculating power consumption!). diff --git a/README.md b/README.md index 2006a43f0..c0dcd5f2a 100644 --- a/README.md +++ b/README.md @@ -43,17 +43,20 @@ When able, please add VS Code comptatible doc comments! These will help debuggin ## Install Tools/Dependencies *For Windows:* -1. `winget install Ninja-build.Ninja Kitware.CMake Arm.GnuArmEmbeddedToolchain` + +1. `winget install Ninja-build.Ninja Kitware.CMake Arm.GnuArmEmbeddedToolchain Microsoft.VisualStudioCode` 2. [OpenOCD](https://github.com/openocd-org/openocd/releases/latest) -> Download the `.tar.gz` file, extract to directory, add the bin directory to your `PATH` 3. Relaunch your terminal *For MacOS:* 1. `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"` -2. `brew install cmake ninja open-ocd` -3. `brew install --cask gcc-arm-embedded` +2. `brew install cmake ninja open-ocd gcc-arm-embedded visual-studio-code` 4. Relaunch your terminal *For Linux / BSD:* + +Install the Visual Studio Code IDE (prefer using the `deb` or `rpm` from [Microsoft](https://code.visualstudio.com/download)). + * `sudo apt install cmake ninja gcc-arm-none-eabi openocd` * `sudo dnf install cmake ninja openocd` (Normally also `arm-none-eabi-gcc-cs arm-none-eabi-newlib` which worked on Fedora 42 but is broken on Fedora 43, use [Arm's version](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads) instead for the moment) * `sudo pacman -S cmake ninja openocd arm-none-eabi-gcc` @@ -61,6 +64,7 @@ When able, please add VS Code comptatible doc comments! These will help debuggin * If you run into issues verify that binutils and newlib are installed for `arm-none-eabi` ### Verify that you have all these dependencies installed: + - CMake - `cmake --version` - Ninja - `ninja --version` - Arm - `arm-none-eabi-gcc --version` From 22c39de1943eec96b031b5efbababa0926ef7852 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 9 Jul 2026 02:16:43 -0700 Subject: [PATCH 002/125] REVERT ME --- Nucleo blinky demo Signed-off-by: Daniel Hansen --- CMakeLists.txt | 2 + Nucleo-Blinky/CMakeLists.txt | 41 ++ Nucleo-Blinky/Core/Inc/gpio.h | 49 +++ Nucleo-Blinky/Core/Inc/main.h | 86 ++++ Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h | 380 ++++++++++++++++++ Nucleo-Blinky/Core/Inc/stm32g4xx_it.h | 67 +++ .../Core/Inc/stm32g4xx_nucleo_conf.h | 78 ++++ Nucleo-Blinky/Core/Src/gpio.c | 55 +++ Nucleo-Blinky/Core/Src/main.c | 209 ++++++++++ Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c | 85 ++++ Nucleo-Blinky/Core/Src/stm32g4xx_it.c | 217 ++++++++++ Nucleo-Blinky/Nucleo-Blinky.ioc | 179 +++++++++ 12 files changed, 1448 insertions(+) create mode 100644 Nucleo-Blinky/CMakeLists.txt create mode 100644 Nucleo-Blinky/Core/Inc/gpio.h create mode 100644 Nucleo-Blinky/Core/Inc/main.h create mode 100644 Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h create mode 100644 Nucleo-Blinky/Core/Inc/stm32g4xx_it.h create mode 100644 Nucleo-Blinky/Core/Inc/stm32g4xx_nucleo_conf.h create mode 100644 Nucleo-Blinky/Core/Src/gpio.c create mode 100644 Nucleo-Blinky/Core/Src/main.c create mode 100644 Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c create mode 100644 Nucleo-Blinky/Core/Src/stm32g4xx_it.c create mode 100644 Nucleo-Blinky/Nucleo-Blinky.ioc diff --git a/CMakeLists.txt b/CMakeLists.txt index dd6d899d4..a6023104a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,3 +185,5 @@ add_gr_project(STM32G474xE BLINKY G4ECHO) # Onboarding Workshops add_gr_project(STM32G474xE Onboarding W3_G4SPI_Receive) add_gr_project(STM32G474xE Onboarding W3_G4SPI_Transmit) + +add_gr_project(STM32G474xE Nucleo-Blinky) diff --git a/Nucleo-Blinky/CMakeLists.txt b/Nucleo-Blinky/CMakeLists.txt new file mode 100644 index 000000000..657a90cdb --- /dev/null +++ b/Nucleo-Blinky/CMakeLists.txt @@ -0,0 +1,41 @@ +cmake_minimum_required(VERSION 3.25) + +# Setup compiler settings +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS ON) + +# Define the build type +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug") +endif() + +# Enable CMake support for ASM and C languages +enable_language( + C + ASM +) + +# Core project settings +project(${CMAKE_PROJECT_NAME}) + +# what, does in fact not get the filename of somthing but rather the name of the project from the path +get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) + +add_library(${PROJECT_NAME}_USER_CODE INTERFACE) +target_sources( + ${PROJECT_NAME}_USER_CODE + INTERFACE + Core/Src/gpio.c + Core/Src/main.c + Core/Src/stm32g4xx_hal_msp.c + Core/Src/stm32g4xx_it.c +) + +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE) + +target_include_directories( + ${PROJECT_NAME}_USER_CODE + INTERFACE + Core/Inc +) diff --git a/Nucleo-Blinky/Core/Inc/gpio.h b/Nucleo-Blinky/Core/Inc/gpio.h new file mode 100644 index 000000000..3c91c4dd6 --- /dev/null +++ b/Nucleo-Blinky/Core/Inc/gpio.h @@ -0,0 +1,49 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file gpio.h + * @brief This file contains all the function prototypes for + * the gpio.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 __GPIO_H__ +#define __GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_GPIO_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif +#endif /*__ GPIO_H__ */ + diff --git a/Nucleo-Blinky/Core/Inc/main.h b/Nucleo-Blinky/Core/Inc/main.h new file mode 100644 index 000000000..e55f7d718 --- /dev/null +++ b/Nucleo-Blinky/Core/Inc/main.h @@ -0,0 +1,86 @@ +/* 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) 2026 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 "stm32g4xx_hal.h" + +#include "stm32g4xx_nucleo.h" +#include + +/* 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 Error_Handler(void); + +/* USER CODE BEGIN EFP */ + +/* USER CODE END EFP */ + +/* Private defines -----------------------------------------------------------*/ +#define RCC_OSC32_IN_Pin GPIO_PIN_14 +#define RCC_OSC32_IN_GPIO_Port GPIOC +#define RCC_OSC32_OUT_Pin GPIO_PIN_15 +#define RCC_OSC32_OUT_GPIO_Port GPIOC +#define RCC_OSC_IN_Pin GPIO_PIN_0 +#define RCC_OSC_IN_GPIO_Port GPIOF +#define RCC_OSC_OUT_Pin GPIO_PIN_1 +#define RCC_OSC_OUT_GPIO_Port GPIOF +#define T_SWDIO_Pin GPIO_PIN_13 +#define T_SWDIO_GPIO_Port GPIOA +#define T_SWCLK_Pin GPIO_PIN_14 +#define T_SWCLK_GPIO_Port GPIOA +#define T_SWO_Pin GPIO_PIN_3 +#define T_SWO_GPIO_Port GPIOB + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H */ diff --git a/Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h b/Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h new file mode 100644 index 000000000..3844b8157 --- /dev/null +++ b/Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h @@ -0,0 +1,380 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g4xx_hal_conf.h + * @author MCD Application Team + * @brief HAL configuration file + ****************************************************************************** + * @attention + * + * Copyright (c) 2019 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 STM32G4xx_HAL_CONF_H +#define STM32G4xx_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_ADC_MODULE_ENABLED */ +/*#define HAL_COMP_MODULE_ENABLED */ +/*#define HAL_CORDIC_MODULE_ENABLED */ +/*#define HAL_CRC_MODULE_ENABLED */ +/*#define HAL_CRYP_MODULE_ENABLED */ +/*#define HAL_DAC_MODULE_ENABLED */ +/*#define HAL_FDCAN_MODULE_ENABLED */ +/*#define HAL_FMAC_MODULE_ENABLED */ +/*#define HAL_HRTIM_MODULE_ENABLED */ +/*#define HAL_IRDA_MODULE_ENABLED */ +/*#define HAL_IWDG_MODULE_ENABLED */ +/*#define HAL_I2C_MODULE_ENABLED */ +/*#define HAL_I2S_MODULE_ENABLED */ +/*#define HAL_LPTIM_MODULE_ENABLED */ +/*#define HAL_NAND_MODULE_ENABLED */ +/*#define HAL_NOR_MODULE_ENABLED */ +/*#define HAL_OPAMP_MODULE_ENABLED */ +/*#define HAL_PCD_MODULE_ENABLED */ +/*#define HAL_QSPI_MODULE_ENABLED */ +/*#define HAL_RNG_MODULE_ENABLED */ +/*#define HAL_RTC_MODULE_ENABLED */ +/*#define HAL_SAI_MODULE_ENABLED */ +/*#define HAL_SMARTCARD_MODULE_ENABLED */ +/*#define HAL_SMBUS_MODULE_ENABLED */ +/*#define HAL_SPI_MODULE_ENABLED */ +/*#define HAL_SRAM_MODULE_ENABLED */ +/*#define HAL_TIM_MODULE_ENABLED */ +#define HAL_UART_MODULE_ENABLED +/*#define HAL_USART_MODULE_ENABLED */ +/*#define HAL_WWDG_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 + +/* ########################## Register Callbacks selection ############################## */ +/** + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + +/* ########################## Oscillator 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 (24000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ + +/** + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined (HSI48_VALUE) + #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ + +/** + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) +/*!< Value of the Internal Low Speed oscillator in Hz +The real value may vary depending on the variations in voltage and temperature.*/ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ +/** + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ + +#if !defined (LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ + +/** + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (0UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U + +/* ########################## Assert Selection ############################## */ +/** + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ + #define USE_FULL_ASSERT 1U + +/* ################## 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 "stm32g4xx_hal_rcc.h" +#endif /* HAL_RCC_MODULE_ENABLED */ + +#ifdef HAL_GPIO_MODULE_ENABLED +#include "stm32g4xx_hal_gpio.h" +#endif /* HAL_GPIO_MODULE_ENABLED */ + +#ifdef HAL_DMA_MODULE_ENABLED +#include "stm32g4xx_hal_dma.h" +#endif /* HAL_DMA_MODULE_ENABLED */ + +#ifdef HAL_CORTEX_MODULE_ENABLED +#include "stm32g4xx_hal_cortex.h" +#endif /* HAL_CORTEX_MODULE_ENABLED */ + +#ifdef HAL_ADC_MODULE_ENABLED +#include "stm32g4xx_hal_adc.h" +#endif /* HAL_ADC_MODULE_ENABLED */ + +#ifdef HAL_COMP_MODULE_ENABLED +#include "stm32g4xx_hal_comp.h" +#endif /* HAL_COMP_MODULE_ENABLED */ + +#ifdef HAL_CORDIC_MODULE_ENABLED +#include "stm32g4xx_hal_cordic.h" +#endif /* HAL_CORDIC_MODULE_ENABLED */ + +#ifdef HAL_CRC_MODULE_ENABLED +#include "stm32g4xx_hal_crc.h" +#endif /* HAL_CRC_MODULE_ENABLED */ + +#ifdef HAL_CRYP_MODULE_ENABLED +#include "stm32g4xx_hal_cryp.h" +#endif /* HAL_CRYP_MODULE_ENABLED */ + +#ifdef HAL_DAC_MODULE_ENABLED +#include "stm32g4xx_hal_dac.h" +#endif /* HAL_DAC_MODULE_ENABLED */ + +#ifdef HAL_EXTI_MODULE_ENABLED +#include "stm32g4xx_hal_exti.h" +#endif /* HAL_EXTI_MODULE_ENABLED */ + +#ifdef HAL_FDCAN_MODULE_ENABLED +#include "stm32g4xx_hal_fdcan.h" +#endif /* HAL_FDCAN_MODULE_ENABLED */ + +#ifdef HAL_FLASH_MODULE_ENABLED +#include "stm32g4xx_hal_flash.h" +#endif /* HAL_FLASH_MODULE_ENABLED */ + +#ifdef HAL_FMAC_MODULE_ENABLED +#include "stm32g4xx_hal_fmac.h" +#endif /* HAL_FMAC_MODULE_ENABLED */ + +#ifdef HAL_HRTIM_MODULE_ENABLED +#include "stm32g4xx_hal_hrtim.h" +#endif /* HAL_HRTIM_MODULE_ENABLED */ + +#ifdef HAL_IRDA_MODULE_ENABLED +#include "stm32g4xx_hal_irda.h" +#endif /* HAL_IRDA_MODULE_ENABLED */ + +#ifdef HAL_IWDG_MODULE_ENABLED +#include "stm32g4xx_hal_iwdg.h" +#endif /* HAL_IWDG_MODULE_ENABLED */ + +#ifdef HAL_I2C_MODULE_ENABLED +#include "stm32g4xx_hal_i2c.h" +#endif /* HAL_I2C_MODULE_ENABLED */ + +#ifdef HAL_I2S_MODULE_ENABLED +#include "stm32g4xx_hal_i2s.h" +#endif /* HAL_I2S_MODULE_ENABLED */ + +#ifdef HAL_LPTIM_MODULE_ENABLED +#include "stm32g4xx_hal_lptim.h" +#endif /* HAL_LPTIM_MODULE_ENABLED */ + +#ifdef HAL_NAND_MODULE_ENABLED +#include "stm32g4xx_hal_nand.h" +#endif /* HAL_NAND_MODULE_ENABLED */ + +#ifdef HAL_NOR_MODULE_ENABLED +#include "stm32g4xx_hal_nor.h" +#endif /* HAL_NOR_MODULE_ENABLED */ + +#ifdef HAL_OPAMP_MODULE_ENABLED +#include "stm32g4xx_hal_opamp.h" +#endif /* HAL_OPAMP_MODULE_ENABLED */ + +#ifdef HAL_PCD_MODULE_ENABLED +#include "stm32g4xx_hal_pcd.h" +#endif /* HAL_PCD_MODULE_ENABLED */ + +#ifdef HAL_PWR_MODULE_ENABLED +#include "stm32g4xx_hal_pwr.h" +#endif /* HAL_PWR_MODULE_ENABLED */ + +#ifdef HAL_QSPI_MODULE_ENABLED +#include "stm32g4xx_hal_qspi.h" +#endif /* HAL_QSPI_MODULE_ENABLED */ + +#ifdef HAL_RNG_MODULE_ENABLED +#include "stm32g4xx_hal_rng.h" +#endif /* HAL_RNG_MODULE_ENABLED */ + +#ifdef HAL_RTC_MODULE_ENABLED +#include "stm32g4xx_hal_rtc.h" +#endif /* HAL_RTC_MODULE_ENABLED */ + +#ifdef HAL_SAI_MODULE_ENABLED +#include "stm32g4xx_hal_sai.h" +#endif /* HAL_SAI_MODULE_ENABLED */ + +#ifdef HAL_SMARTCARD_MODULE_ENABLED +#include "stm32g4xx_hal_smartcard.h" +#endif /* HAL_SMARTCARD_MODULE_ENABLED */ + +#ifdef HAL_SMBUS_MODULE_ENABLED +#include "stm32g4xx_hal_smbus.h" +#endif /* HAL_SMBUS_MODULE_ENABLED */ + +#ifdef HAL_SPI_MODULE_ENABLED +#include "stm32g4xx_hal_spi.h" +#endif /* HAL_SPI_MODULE_ENABLED */ + +#ifdef HAL_SRAM_MODULE_ENABLED +#include "stm32g4xx_hal_sram.h" +#endif /* HAL_SRAM_MODULE_ENABLED */ + +#ifdef HAL_TIM_MODULE_ENABLED +#include "stm32g4xx_hal_tim.h" +#endif /* HAL_TIM_MODULE_ENABLED */ + +#ifdef HAL_UART_MODULE_ENABLED +#include "stm32g4xx_hal_uart.h" +#endif /* HAL_UART_MODULE_ENABLED */ + +#ifdef HAL_USART_MODULE_ENABLED +#include "stm32g4xx_hal_usart.h" +#endif /* HAL_USART_MODULE_ENABLED */ + +#ifdef HAL_WWDG_MODULE_ENABLED +#include "stm32g4xx_hal_wwdg.h" +#endif /* HAL_WWDG_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 /* STM32G4xx_HAL_CONF_H */ diff --git a/Nucleo-Blinky/Core/Inc/stm32g4xx_it.h b/Nucleo-Blinky/Core/Inc/stm32g4xx_it.h new file mode 100644 index 000000000..001ebdf89 --- /dev/null +++ b/Nucleo-Blinky/Core/Inc/stm32g4xx_it.h @@ -0,0 +1,67 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g4xx_it.h + * @brief This file contains the headers of the interrupt handlers. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 __STM32G4xx_IT_H +#define __STM32G4xx_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); +void EXTI15_10_IRQHandler(void); +/* USER CODE BEGIN EFP */ + +/* USER CODE END EFP */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32G4xx_IT_H */ diff --git a/Nucleo-Blinky/Core/Inc/stm32g4xx_nucleo_conf.h b/Nucleo-Blinky/Core/Inc/stm32g4xx_nucleo_conf.h new file mode 100644 index 000000000..602b3233e --- /dev/null +++ b/Nucleo-Blinky/Core/Inc/stm32g4xx_nucleo_conf.h @@ -0,0 +1,78 @@ + +/** + ****************************************************************************** + * @file stm32g4xx_nucleo_conf.h + * @author MCD Application Team + * @brief STM32G4xx_Nucleo board configuration file. + * This file should be copied to the application folder and renamed + * to stm32g4xx_nucleo_conf.h + ****************************************************************************** + * @attention + * + * Copyright (c) 2022 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. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef STM32G4XX_NUCLEO_CONF_H +#define STM32G4XX_NUCLEO_CONF_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32g4xx_hal.h" + +/** @addtogroup BSP + * @{ + */ + +/** @addtogroup STM32G4XX_NUCLEO + * @{ + */ + +/** @defgroup STM32G4XX_NUCLEO_CONFIG Config + * @{ + */ + +/** @defgroup STM32C0XX_NUCLEO_CONFIG_Exported_Constants Exported Constants + * @{ + */ +/* Nucleo pin and part number defines */ +#define USE_STM32G4XX_NUCLEO + +/* COM define */ +#define USE_COM_LOG 1U +#define USE_BSP_COM_FEATURE 1U + +/* IRQ priorities */ +#define BSP_BUTTON_USER_IT_PRIORITY 15U + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* STM32G4XX_NUCLEO_CONF_H */ diff --git a/Nucleo-Blinky/Core/Src/gpio.c b/Nucleo-Blinky/Core/Src/gpio.c new file mode 100644 index 000000000..3a44fbc3e --- /dev/null +++ b/Nucleo-Blinky/Core/Src/gpio.c @@ -0,0 +1,55 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file gpio.c + * @brief This file provides code for the configuration + * of all used GPIO pins. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "gpio.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/*----------------------------------------------------------------------------*/ +/* Configure GPIO */ +/*----------------------------------------------------------------------------*/ +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + +/** Configure pins as + * Analog + * Input + * Output + * EVENT_OUT + * EXTI +*/ +void MX_GPIO_Init(void) +{ + + /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOF_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + +} + +/* USER CODE BEGIN 2 */ + +/* USER CODE END 2 */ diff --git a/Nucleo-Blinky/Core/Src/main.c b/Nucleo-Blinky/Core/Src/main.c new file mode 100644 index 000000000..ab141cb7c --- /dev/null +++ b/Nucleo-Blinky/Core/Src/main.c @@ -0,0 +1,209 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.c + * @brief : Main program body + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "gpio.h" + +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN PTD */ + +/* USER CODE END PTD */ + +/* Private define ------------------------------------------------------------*/ +/* USER CODE BEGIN PD */ + +/* USER CODE END PD */ + +/* Private macro -------------------------------------------------------------*/ +/* USER CODE BEGIN PM */ + +/* USER CODE END PM */ + +/* Private variables ---------------------------------------------------------*/ + +COM_InitTypeDef BspCOMInit; + +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +void SystemClock_Config(void); +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* Private user code ---------------------------------------------------------*/ +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/** + * @brief The application entry point. + * @retval int + */ +int main(void) +{ + + /* USER CODE BEGIN 1 */ + + /* USER CODE END 1 */ + + /* MCU Configuration--------------------------------------------------------*/ + + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); + + /* USER CODE BEGIN Init */ + + /* USER CODE END Init */ + + /* Configure the system clock */ + SystemClock_Config(); + + /* USER CODE BEGIN SysInit */ + + /* USER CODE END SysInit */ + + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + /* USER CODE BEGIN 2 */ + + /* USER CODE END 2 */ + + /* Initialize led */ + BSP_LED_Init(LED_GREEN); + + /* Initialize USER push-button, will be used to trigger an interrupt each time it's pressed.*/ + BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI); + + /* Initialize COM1 port (115200, 8 bits (7-bit data + 1 stop bit), no parity */ + BspCOMInit.BaudRate = 115200; + BspCOMInit.WordLength = COM_WORDLENGTH_8B; + BspCOMInit.StopBits = COM_STOPBITS_1; + BspCOMInit.Parity = COM_PARITY_NONE; + BspCOMInit.HwFlowCtl = COM_HWCONTROL_NONE; + if (BSP_COM_Init(COM1, &BspCOMInit) != BSP_ERROR_NONE) + { + Error_Handler(); + } + + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ + while (1) + { + HAL_Delay(100); + /* USER CODE END WHILE */ + + /* USER CODE BEGIN 3 */ + HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin); + + if (BSP_PB_GetState(BUTTON_USER) == GPIO_PIN_SET) + { + HAL_Delay(10); + } + } + /* USER CODE END 3 */ +} + +/** + * @brief System Clock Configuration + * @retval None + */ +void SystemClock_Config(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + + /** Configure the main internal regulator output voltage + */ + HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST); + + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; + RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4; + RCC_OscInitStruct.PLL.PLLN = 85; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; + RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; + RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) + { + Error_Handler(); + } + + /** Initializes the CPU, AHB and APB buses clocks + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK + |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) + { + Error_Handler(); + } +} + +/* USER CODE BEGIN 4 */ + +/* USER CODE END 4 */ + +/** + * @brief This function is executed in case of error occurrence. + * @retval None + */ +void Error_Handler(void) +{ + /* USER CODE BEGIN Error_Handler_Debug */ + /* User can add his own implementation to report the HAL error return state */ + __disable_irq(); + while (1) + { + } + /* USER CODE END Error_Handler_Debug */ +} +#ifdef USE_FULL_ASSERT +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ +void assert_failed(uint8_t *file, uint32_t line) +{ + /* USER CODE BEGIN 6 */ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + /* USER CODE END 6 */ +} +#endif /* USE_FULL_ASSERT */ diff --git a/Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c b/Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c new file mode 100644 index 000000000..d908bd772 --- /dev/null +++ b/Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c @@ -0,0 +1,85 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g4xx_hal_msp.c + * @brief This file provides code for the MSP Initialization + * and de-Initialization codes. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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*/ + + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); + + /* USER CODE BEGIN MspInit 1 */ + + /* USER CODE END MspInit 1 */ +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/Nucleo-Blinky/Core/Src/stm32g4xx_it.c b/Nucleo-Blinky/Core/Src/stm32g4xx_it.c new file mode 100644 index 000000000..f98aa5695 --- /dev/null +++ b/Nucleo-Blinky/Core/Src/stm32g4xx_it.c @@ -0,0 +1,217 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g4xx_it.c + * @brief Interrupt Service Routines. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "stm32g4xx_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 Prefetch 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 */ +} + +/******************************************************************************/ +/* STM32G4xx 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_stm32g4xx.s). */ +/******************************************************************************/ + +/** + * @brief This function handles EXTI line[15:10] interrupts. + */ +void EXTI15_10_IRQHandler(void) +{ + /* USER CODE BEGIN EXTI15_10_IRQn 0 */ + + /* USER CODE END EXTI15_10_IRQn 0 */ + BSP_PB_IRQHandler(BUTTON_USER); + /* USER CODE BEGIN EXTI15_10_IRQn 1 */ + + /* USER CODE END EXTI15_10_IRQn 1 */ +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/Nucleo-Blinky/Nucleo-Blinky.ioc b/Nucleo-Blinky/Nucleo-Blinky.ioc new file mode 100644 index 000000000..1bc08b38e --- /dev/null +++ b/Nucleo-Blinky/Nucleo-Blinky.ioc @@ -0,0 +1,179 @@ +#MicroXplorer Configuration settings - do not modify +BSP_IP_NAME=NUCLEO-G474RE +CAD.formats= +CAD.pinconfig= +CAD.provider= +File.Version=6 +KeepUserPlacement=false +Mcu.CPN=STM32G474RET6 +Mcu.Family=STM32G4 +Mcu.IP0=NUCLEO-G474RE +Mcu.IP1=NVIC +Mcu.IP2=RCC +Mcu.IP3=SYS +Mcu.IPNb=5 +Mcu.Name=STM32G474R(B-C-E)Tx +Mcu.Package=LQFP64 +Mcu.Pin0=PC13 +Mcu.Pin1=PC14-OSC32_IN +Mcu.Pin10=PB3 +Mcu.Pin11=VP_SYS_VS_Systick +Mcu.Pin12=VP_SYS_VS_DBSignals +Mcu.Pin13=VP_NUCLEO-G474RE_VS_BSP_COMMON +Mcu.Pin2=PC15-OSC32_OUT +Mcu.Pin3=PF0-OSC_IN +Mcu.Pin4=PF1-OSC_OUT +Mcu.Pin5=PA2 +Mcu.Pin6=PA3 +Mcu.Pin7=PA5 +Mcu.Pin8=PA13 +Mcu.Pin9=PA14 +Mcu.PinsNb=14 +Mcu.ThirdPartyNb=0 +Mcu.UserConstants= +Mcu.UserName=STM32G474RETx +MxCube.Version=6.18.0 +MxDb.Version=DB.6.0.180 +NUCLEO-G474RE.BUTTON=1 +NUCLEO-G474RE.IPParameters=BUTTON,LD2,VCP +NUCLEO-G474RE.LD2=true +NUCLEO-G474RE.VCP=true +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.EXTI15_10_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true +NVIC.ForceEnableDMAVector=true +NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 +NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:false +NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +PA13.GPIOParameters=GPIO_Label +PA13.GPIO_Label=T_SWDIO +PA13.Locked=true +PA13.Signal=SYS_JTMS-SWDIO +PA14.GPIOParameters=GPIO_Label +PA14.GPIO_Label=T_SWCLK +PA14.Locked=true +PA14.Signal=SYS_JTCK-SWCLK +PA2.Locked=true +PA2.Signal=LPUART1_TX +PA3.Locked=true +PA3.Signal=LPUART1_RX +PA5.Locked=true +PB3.GPIOParameters=GPIO_Label +PB3.GPIO_Label=T_SWO +PB3.Locked=true +PB3.Signal=SYS_JTDO-SWO +PC13.Locked=true +PC14-OSC32_IN.GPIOParameters=GPIO_Label +PC14-OSC32_IN.GPIO_Label=RCC_OSC32_IN +PC14-OSC32_IN.Locked=true +PC14-OSC32_IN.Signal=RCC_OSC32_IN +PC15-OSC32_OUT.GPIOParameters=GPIO_Label +PC15-OSC32_OUT.GPIO_Label=RCC_OSC32_OUT +PC15-OSC32_OUT.Locked=true +PC15-OSC32_OUT.Signal=RCC_OSC32_OUT +PF0-OSC_IN.GPIOParameters=GPIO_Label +PF0-OSC_IN.GPIO_Label=RCC_OSC_IN +PF0-OSC_IN.Locked=true +PF0-OSC_IN.Signal=RCC_OSC_IN +PF1-OSC_OUT.GPIOParameters=GPIO_Label +PF1-OSC_OUT.GPIO_Label=RCC_OSC_OUT +PF1-OSC_OUT.Locked=true +PF1-OSC_OUT.Signal=RCC_OSC_OUT +PinOutPanel.RotationAngle=0 +ProjectManager.AskForMigrate=true +ProjectManager.BackupPrevious=false +ProjectManager.CompilerLinker=GCC +ProjectManager.CompilerOptimize=6 +ProjectManager.ComputerToolchain=false +ProjectManager.CoupleFile=true +ProjectManager.CustomerFirmwarePackage= +ProjectManager.DefaultFWLocation=true +ProjectManager.DeletePrevious=true +ProjectManager.DeviceId=STM32G474RETx +ProjectManager.FirmwarePackage=STM32Cube FW_G4 V1.6.3 +ProjectManager.FreePins=false +ProjectManager.FreePinsContext= +ProjectManager.HalAssertFull=true +ProjectManager.HeapSize=0x200 +ProjectManager.KeepUserCode=true +ProjectManager.LastFirmware=true +ProjectManager.LibraryCopy=2 +ProjectManager.MainLocation=Core/Src +ProjectManager.NoMain=false +ProjectManager.PreviousToolchain= +ProjectManager.ProjectBuild=false +ProjectManager.ProjectFileName=Nucleo-Blinky.ioc +ProjectManager.ProjectName=Nucleo-Blinky +ProjectManager.ProjectStructure= +ProjectManager.RegisterCallBack= +ProjectManager.StackSize=0x400 +ProjectManager.TargetToolchain=EWARM V8.50 +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,false-0--NUCLEO-G474RE-true-HAL-true +RCC.ADC12Freq_Value=170000000 +RCC.ADC345Freq_Value=170000000 +RCC.AHBFreq_Value=170000000 +RCC.APB1Freq_Value=170000000 +RCC.APB1TimFreq_Value=170000000 +RCC.APB2Freq_Value=170000000 +RCC.APB2TimFreq_Value=170000000 +RCC.CRSFreq_Value=48000000 +RCC.CortexFreq_Value=170000000 +RCC.EXTERNAL_CLOCK_VALUE=12288000 +RCC.FCLKCortexFreq_Value=170000000 +RCC.FDCANFreq_Value=170000000 +RCC.FamilyName=M +RCC.HCLKFreq_Value=170000000 +RCC.HRTIM1Freq_Value=170000000 +RCC.HSE_VALUE=24000000 +RCC.HSI48_VALUE=48000000 +RCC.HSI_VALUE=16000000 +RCC.I2C1Freq_Value=170000000 +RCC.I2C2Freq_Value=170000000 +RCC.I2C3Freq_Value=170000000 +RCC.I2C4Freq_Value=170000000 +RCC.I2SFreq_Value=170000000 +RCC.IPParameters=ADC12Freq_Value,ADC345Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HRTIM1Freq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,PLLM,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PWRFreq_Value,QSPIFreq_Value,RNGFreq_Value,RTCClockSelection,RTCFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value +RCC.LPTIM1Freq_Value=170000000 +RCC.LPUART1Freq_Value=170000000 +RCC.LSCOPinFreq_Value=32000 +RCC.LSE_VALUE=32768 +RCC.LSI_VALUE=32000 +RCC.MCO1PinFreq_Value=16000000 +RCC.PLLM=RCC_PLLM_DIV4 +RCC.PLLN=85 +RCC.PLLPoutputFreq_Value=170000000 +RCC.PLLQoutputFreq_Value=170000000 +RCC.PLLRCLKFreq_Value=170000000 +RCC.PWRFreq_Value=170000000 +RCC.QSPIFreq_Value=170000000 +RCC.RNGFreq_Value=170000000 +RCC.RTCClockSelection=RCC_RTCCLKSOURCE_LSE +RCC.RTCFreq_Value=32768 +RCC.SAI1Freq_Value=170000000 +RCC.SYSCLKFreq_VALUE=170000000 +RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK +RCC.UART4Freq_Value=170000000 +RCC.UART5Freq_Value=170000000 +RCC.USART1Freq_Value=170000000 +RCC.USART2Freq_Value=170000000 +RCC.USART3Freq_Value=170000000 +RCC.USBFreq_Value=170000000 +RCC.VCOInputFreq_Value=4000000 +RCC.VCOOutputFreq_Value=340000000 +VP_NUCLEO-G474RE_VS_BSP_COMMON.Mode=COMMON +VP_NUCLEO-G474RE_VS_BSP_COMMON.Signal=NUCLEO-G474RE_VS_BSP_COMMON +VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals +VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals +VP_SYS_VS_Systick.Mode=SysTick +VP_SYS_VS_Systick.Signal=SYS_VS_Systick +board=NUCLEO-G474RE +boardIOC=true From b13574b90f0bed286f51870f635510225dfc30db Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 9 Jul 2026 02:20:09 -0700 Subject: [PATCH 003/125] Revert "REVERT ME --- Nucleo blinky demo" This reverts commit da7387f34276a452111577b51896c4276b35a762. --- CMakeLists.txt | 2 - Nucleo-Blinky/CMakeLists.txt | 41 -- Nucleo-Blinky/Core/Inc/gpio.h | 49 --- Nucleo-Blinky/Core/Inc/main.h | 86 ---- Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h | 380 ------------------ Nucleo-Blinky/Core/Inc/stm32g4xx_it.h | 67 --- .../Core/Inc/stm32g4xx_nucleo_conf.h | 78 ---- Nucleo-Blinky/Core/Src/gpio.c | 55 --- Nucleo-Blinky/Core/Src/main.c | 209 ---------- Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c | 85 ---- Nucleo-Blinky/Core/Src/stm32g4xx_it.c | 217 ---------- Nucleo-Blinky/Nucleo-Blinky.ioc | 179 --------- 12 files changed, 1448 deletions(-) delete mode 100644 Nucleo-Blinky/CMakeLists.txt delete mode 100644 Nucleo-Blinky/Core/Inc/gpio.h delete mode 100644 Nucleo-Blinky/Core/Inc/main.h delete mode 100644 Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h delete mode 100644 Nucleo-Blinky/Core/Inc/stm32g4xx_it.h delete mode 100644 Nucleo-Blinky/Core/Inc/stm32g4xx_nucleo_conf.h delete mode 100644 Nucleo-Blinky/Core/Src/gpio.c delete mode 100644 Nucleo-Blinky/Core/Src/main.c delete mode 100644 Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c delete mode 100644 Nucleo-Blinky/Core/Src/stm32g4xx_it.c delete mode 100644 Nucleo-Blinky/Nucleo-Blinky.ioc diff --git a/CMakeLists.txt b/CMakeLists.txt index a6023104a..dd6d899d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,5 +185,3 @@ add_gr_project(STM32G474xE BLINKY G4ECHO) # Onboarding Workshops add_gr_project(STM32G474xE Onboarding W3_G4SPI_Receive) add_gr_project(STM32G474xE Onboarding W3_G4SPI_Transmit) - -add_gr_project(STM32G474xE Nucleo-Blinky) diff --git a/Nucleo-Blinky/CMakeLists.txt b/Nucleo-Blinky/CMakeLists.txt deleted file mode 100644 index 657a90cdb..000000000 --- a/Nucleo-Blinky/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -# Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) - -# Define the build type -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug") -endif() - -# Enable CMake support for ASM and C languages -enable_language( - C - ASM -) - -# Core project settings -project(${CMAKE_PROJECT_NAME}) - -# what, does in fact not get the filename of somthing but rather the name of the project from the path -get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) - -add_library(${PROJECT_NAME}_USER_CODE INTERFACE) -target_sources( - ${PROJECT_NAME}_USER_CODE - INTERFACE - Core/Src/gpio.c - Core/Src/main.c - Core/Src/stm32g4xx_hal_msp.c - Core/Src/stm32g4xx_it.c -) - -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE) - -target_include_directories( - ${PROJECT_NAME}_USER_CODE - INTERFACE - Core/Inc -) diff --git a/Nucleo-Blinky/Core/Inc/gpio.h b/Nucleo-Blinky/Core/Inc/gpio.h deleted file mode 100644 index 3c91c4dd6..000000000 --- a/Nucleo-Blinky/Core/Inc/gpio.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file gpio.h - * @brief This file contains all the function prototypes for - * the gpio.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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 __GPIO_H__ -#define __GPIO_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_GPIO_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif -#endif /*__ GPIO_H__ */ - diff --git a/Nucleo-Blinky/Core/Inc/main.h b/Nucleo-Blinky/Core/Inc/main.h deleted file mode 100644 index e55f7d718..000000000 --- a/Nucleo-Blinky/Core/Inc/main.h +++ /dev/null @@ -1,86 +0,0 @@ -/* 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) 2026 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 "stm32g4xx_hal.h" - -#include "stm32g4xx_nucleo.h" -#include - -/* 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 Error_Handler(void); - -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -/* Private defines -----------------------------------------------------------*/ -#define RCC_OSC32_IN_Pin GPIO_PIN_14 -#define RCC_OSC32_IN_GPIO_Port GPIOC -#define RCC_OSC32_OUT_Pin GPIO_PIN_15 -#define RCC_OSC32_OUT_GPIO_Port GPIOC -#define RCC_OSC_IN_Pin GPIO_PIN_0 -#define RCC_OSC_IN_GPIO_Port GPIOF -#define RCC_OSC_OUT_Pin GPIO_PIN_1 -#define RCC_OSC_OUT_GPIO_Port GPIOF -#define T_SWDIO_Pin GPIO_PIN_13 -#define T_SWDIO_GPIO_Port GPIOA -#define T_SWCLK_Pin GPIO_PIN_14 -#define T_SWCLK_GPIO_Port GPIOA -#define T_SWO_Pin GPIO_PIN_3 -#define T_SWO_GPIO_Port GPIOB - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -#ifdef __cplusplus -} -#endif - -#endif /* __MAIN_H */ diff --git a/Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h b/Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h deleted file mode 100644 index 3844b8157..000000000 --- a/Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h +++ /dev/null @@ -1,380 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_conf.h - * @author MCD Application Team - * @brief HAL configuration file - ****************************************************************************** - * @attention - * - * Copyright (c) 2019 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 STM32G4xx_HAL_CONF_H -#define STM32G4xx_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_ADC_MODULE_ENABLED */ -/*#define HAL_COMP_MODULE_ENABLED */ -/*#define HAL_CORDIC_MODULE_ENABLED */ -/*#define HAL_CRC_MODULE_ENABLED */ -/*#define HAL_CRYP_MODULE_ENABLED */ -/*#define HAL_DAC_MODULE_ENABLED */ -/*#define HAL_FDCAN_MODULE_ENABLED */ -/*#define HAL_FMAC_MODULE_ENABLED */ -/*#define HAL_HRTIM_MODULE_ENABLED */ -/*#define HAL_IRDA_MODULE_ENABLED */ -/*#define HAL_IWDG_MODULE_ENABLED */ -/*#define HAL_I2C_MODULE_ENABLED */ -/*#define HAL_I2S_MODULE_ENABLED */ -/*#define HAL_LPTIM_MODULE_ENABLED */ -/*#define HAL_NAND_MODULE_ENABLED */ -/*#define HAL_NOR_MODULE_ENABLED */ -/*#define HAL_OPAMP_MODULE_ENABLED */ -/*#define HAL_PCD_MODULE_ENABLED */ -/*#define HAL_QSPI_MODULE_ENABLED */ -/*#define HAL_RNG_MODULE_ENABLED */ -/*#define HAL_RTC_MODULE_ENABLED */ -/*#define HAL_SAI_MODULE_ENABLED */ -/*#define HAL_SMARTCARD_MODULE_ENABLED */ -/*#define HAL_SMBUS_MODULE_ENABLED */ -/*#define HAL_SPI_MODULE_ENABLED */ -/*#define HAL_SRAM_MODULE_ENABLED */ -/*#define HAL_TIM_MODULE_ENABLED */ -#define HAL_UART_MODULE_ENABLED -/*#define HAL_USART_MODULE_ENABLED */ -/*#define HAL_WWDG_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 - -/* ########################## Register Callbacks selection ############################## */ -/** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U - -/* ########################## Oscillator 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 (24000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ - -/** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined (HSI48_VALUE) - #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ - -/** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) -/*!< Value of the Internal Low Speed oscillator in Hz -The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ -/** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined (LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ - -#if !defined (LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ - -/** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined (EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (0UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U - -/* ########################## Assert Selection ############################## */ -/** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ - #define USE_FULL_ASSERT 1U - -/* ################## 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 "stm32g4xx_hal_rcc.h" -#endif /* HAL_RCC_MODULE_ENABLED */ - -#ifdef HAL_GPIO_MODULE_ENABLED -#include "stm32g4xx_hal_gpio.h" -#endif /* HAL_GPIO_MODULE_ENABLED */ - -#ifdef HAL_DMA_MODULE_ENABLED -#include "stm32g4xx_hal_dma.h" -#endif /* HAL_DMA_MODULE_ENABLED */ - -#ifdef HAL_CORTEX_MODULE_ENABLED -#include "stm32g4xx_hal_cortex.h" -#endif /* HAL_CORTEX_MODULE_ENABLED */ - -#ifdef HAL_ADC_MODULE_ENABLED -#include "stm32g4xx_hal_adc.h" -#endif /* HAL_ADC_MODULE_ENABLED */ - -#ifdef HAL_COMP_MODULE_ENABLED -#include "stm32g4xx_hal_comp.h" -#endif /* HAL_COMP_MODULE_ENABLED */ - -#ifdef HAL_CORDIC_MODULE_ENABLED -#include "stm32g4xx_hal_cordic.h" -#endif /* HAL_CORDIC_MODULE_ENABLED */ - -#ifdef HAL_CRC_MODULE_ENABLED -#include "stm32g4xx_hal_crc.h" -#endif /* HAL_CRC_MODULE_ENABLED */ - -#ifdef HAL_CRYP_MODULE_ENABLED -#include "stm32g4xx_hal_cryp.h" -#endif /* HAL_CRYP_MODULE_ENABLED */ - -#ifdef HAL_DAC_MODULE_ENABLED -#include "stm32g4xx_hal_dac.h" -#endif /* HAL_DAC_MODULE_ENABLED */ - -#ifdef HAL_EXTI_MODULE_ENABLED -#include "stm32g4xx_hal_exti.h" -#endif /* HAL_EXTI_MODULE_ENABLED */ - -#ifdef HAL_FDCAN_MODULE_ENABLED -#include "stm32g4xx_hal_fdcan.h" -#endif /* HAL_FDCAN_MODULE_ENABLED */ - -#ifdef HAL_FLASH_MODULE_ENABLED -#include "stm32g4xx_hal_flash.h" -#endif /* HAL_FLASH_MODULE_ENABLED */ - -#ifdef HAL_FMAC_MODULE_ENABLED -#include "stm32g4xx_hal_fmac.h" -#endif /* HAL_FMAC_MODULE_ENABLED */ - -#ifdef HAL_HRTIM_MODULE_ENABLED -#include "stm32g4xx_hal_hrtim.h" -#endif /* HAL_HRTIM_MODULE_ENABLED */ - -#ifdef HAL_IRDA_MODULE_ENABLED -#include "stm32g4xx_hal_irda.h" -#endif /* HAL_IRDA_MODULE_ENABLED */ - -#ifdef HAL_IWDG_MODULE_ENABLED -#include "stm32g4xx_hal_iwdg.h" -#endif /* HAL_IWDG_MODULE_ENABLED */ - -#ifdef HAL_I2C_MODULE_ENABLED -#include "stm32g4xx_hal_i2c.h" -#endif /* HAL_I2C_MODULE_ENABLED */ - -#ifdef HAL_I2S_MODULE_ENABLED -#include "stm32g4xx_hal_i2s.h" -#endif /* HAL_I2S_MODULE_ENABLED */ - -#ifdef HAL_LPTIM_MODULE_ENABLED -#include "stm32g4xx_hal_lptim.h" -#endif /* HAL_LPTIM_MODULE_ENABLED */ - -#ifdef HAL_NAND_MODULE_ENABLED -#include "stm32g4xx_hal_nand.h" -#endif /* HAL_NAND_MODULE_ENABLED */ - -#ifdef HAL_NOR_MODULE_ENABLED -#include "stm32g4xx_hal_nor.h" -#endif /* HAL_NOR_MODULE_ENABLED */ - -#ifdef HAL_OPAMP_MODULE_ENABLED -#include "stm32g4xx_hal_opamp.h" -#endif /* HAL_OPAMP_MODULE_ENABLED */ - -#ifdef HAL_PCD_MODULE_ENABLED -#include "stm32g4xx_hal_pcd.h" -#endif /* HAL_PCD_MODULE_ENABLED */ - -#ifdef HAL_PWR_MODULE_ENABLED -#include "stm32g4xx_hal_pwr.h" -#endif /* HAL_PWR_MODULE_ENABLED */ - -#ifdef HAL_QSPI_MODULE_ENABLED -#include "stm32g4xx_hal_qspi.h" -#endif /* HAL_QSPI_MODULE_ENABLED */ - -#ifdef HAL_RNG_MODULE_ENABLED -#include "stm32g4xx_hal_rng.h" -#endif /* HAL_RNG_MODULE_ENABLED */ - -#ifdef HAL_RTC_MODULE_ENABLED -#include "stm32g4xx_hal_rtc.h" -#endif /* HAL_RTC_MODULE_ENABLED */ - -#ifdef HAL_SAI_MODULE_ENABLED -#include "stm32g4xx_hal_sai.h" -#endif /* HAL_SAI_MODULE_ENABLED */ - -#ifdef HAL_SMARTCARD_MODULE_ENABLED -#include "stm32g4xx_hal_smartcard.h" -#endif /* HAL_SMARTCARD_MODULE_ENABLED */ - -#ifdef HAL_SMBUS_MODULE_ENABLED -#include "stm32g4xx_hal_smbus.h" -#endif /* HAL_SMBUS_MODULE_ENABLED */ - -#ifdef HAL_SPI_MODULE_ENABLED -#include "stm32g4xx_hal_spi.h" -#endif /* HAL_SPI_MODULE_ENABLED */ - -#ifdef HAL_SRAM_MODULE_ENABLED -#include "stm32g4xx_hal_sram.h" -#endif /* HAL_SRAM_MODULE_ENABLED */ - -#ifdef HAL_TIM_MODULE_ENABLED -#include "stm32g4xx_hal_tim.h" -#endif /* HAL_TIM_MODULE_ENABLED */ - -#ifdef HAL_UART_MODULE_ENABLED -#include "stm32g4xx_hal_uart.h" -#endif /* HAL_UART_MODULE_ENABLED */ - -#ifdef HAL_USART_MODULE_ENABLED -#include "stm32g4xx_hal_usart.h" -#endif /* HAL_USART_MODULE_ENABLED */ - -#ifdef HAL_WWDG_MODULE_ENABLED -#include "stm32g4xx_hal_wwdg.h" -#endif /* HAL_WWDG_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 /* STM32G4xx_HAL_CONF_H */ diff --git a/Nucleo-Blinky/Core/Inc/stm32g4xx_it.h b/Nucleo-Blinky/Core/Inc/stm32g4xx_it.h deleted file mode 100644 index 001ebdf89..000000000 --- a/Nucleo-Blinky/Core/Inc/stm32g4xx_it.h +++ /dev/null @@ -1,67 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_it.h - * @brief This file contains the headers of the interrupt handlers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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 __STM32G4xx_IT_H -#define __STM32G4xx_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); -void EXTI15_10_IRQHandler(void); -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32G4xx_IT_H */ diff --git a/Nucleo-Blinky/Core/Inc/stm32g4xx_nucleo_conf.h b/Nucleo-Blinky/Core/Inc/stm32g4xx_nucleo_conf.h deleted file mode 100644 index 602b3233e..000000000 --- a/Nucleo-Blinky/Core/Inc/stm32g4xx_nucleo_conf.h +++ /dev/null @@ -1,78 +0,0 @@ - -/** - ****************************************************************************** - * @file stm32g4xx_nucleo_conf.h - * @author MCD Application Team - * @brief STM32G4xx_Nucleo board configuration file. - * This file should be copied to the application folder and renamed - * to stm32g4xx_nucleo_conf.h - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 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. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef STM32G4XX_NUCLEO_CONF_H -#define STM32G4XX_NUCLEO_CONF_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "stm32g4xx_hal.h" - -/** @addtogroup BSP - * @{ - */ - -/** @addtogroup STM32G4XX_NUCLEO - * @{ - */ - -/** @defgroup STM32G4XX_NUCLEO_CONFIG Config - * @{ - */ - -/** @defgroup STM32C0XX_NUCLEO_CONFIG_Exported_Constants Exported Constants - * @{ - */ -/* Nucleo pin and part number defines */ -#define USE_STM32G4XX_NUCLEO - -/* COM define */ -#define USE_COM_LOG 1U -#define USE_BSP_COM_FEATURE 1U - -/* IRQ priorities */ -#define BSP_BUTTON_USER_IT_PRIORITY 15U - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* STM32G4XX_NUCLEO_CONF_H */ diff --git a/Nucleo-Blinky/Core/Src/gpio.c b/Nucleo-Blinky/Core/Src/gpio.c deleted file mode 100644 index 3a44fbc3e..000000000 --- a/Nucleo-Blinky/Core/Src/gpio.c +++ /dev/null @@ -1,55 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file gpio.c - * @brief This file provides code for the configuration - * of all used GPIO pins. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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 "gpio.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure GPIO */ -/*----------------------------------------------------------------------------*/ -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI -*/ -void MX_GPIO_Init(void) -{ - - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOF_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ diff --git a/Nucleo-Blinky/Core/Src/main.c b/Nucleo-Blinky/Core/Src/main.c deleted file mode 100644 index ab141cb7c..000000000 --- a/Nucleo-Blinky/Core/Src/main.c +++ /dev/null @@ -1,209 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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 "gpio.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* Private define ------------------------------------------------------------*/ -/* USER CODE BEGIN PD */ - -/* USER CODE END PD */ - -/* Private macro -------------------------------------------------------------*/ -/* USER CODE BEGIN PM */ - -/* USER CODE END PM */ - -/* Private variables ---------------------------------------------------------*/ - -COM_InitTypeDef BspCOMInit; - -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -void SystemClock_Config(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); - - /* USER CODE BEGIN Init */ - - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - /* USER CODE BEGIN 2 */ - - /* USER CODE END 2 */ - - /* Initialize led */ - BSP_LED_Init(LED_GREEN); - - /* Initialize USER push-button, will be used to trigger an interrupt each time it's pressed.*/ - BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI); - - /* Initialize COM1 port (115200, 8 bits (7-bit data + 1 stop bit), no parity */ - BspCOMInit.BaudRate = 115200; - BspCOMInit.WordLength = COM_WORDLENGTH_8B; - BspCOMInit.StopBits = COM_STOPBITS_1; - BspCOMInit.Parity = COM_PARITY_NONE; - BspCOMInit.HwFlowCtl = COM_HWCONTROL_NONE; - if (BSP_COM_Init(COM1, &BspCOMInit) != BSP_ERROR_NONE) - { - Error_Handler(); - } - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) - { - HAL_Delay(100); - /* USER CODE END WHILE */ - - /* USER CODE BEGIN 3 */ - HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin); - - if (BSP_PB_GetState(BUTTON_USER) == GPIO_PIN_SET) - { - HAL_Delay(10); - } - } - /* USER CODE END 3 */ -} - -/** - * @brief System Clock Configuration - * @retval None - */ -void SystemClock_Config(void) -{ - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - - /** Configure the main internal regulator output voltage - */ - HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST); - - /** Initializes the RCC Oscillators according to the specified parameters - * in the RCC_OscInitTypeDef structure. - */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; - RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; - RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4; - RCC_OscInitStruct.PLL.PLLN = 85; - RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; - RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; - RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) - { - Error_Handler(); - } - - /** Initializes the CPU, AHB and APB buses clocks - */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK - |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; - - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) - { - Error_Handler(); - } -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return state */ - __disable_irq(); - while (1) - { - } - /* USER CODE END Error_Handler_Debug */ -} -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line number, - ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ diff --git a/Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c b/Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c deleted file mode 100644 index d908bd772..000000000 --- a/Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c +++ /dev/null @@ -1,85 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_msp.c - * @brief This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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*/ - - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); - - /* USER CODE BEGIN MspInit 1 */ - - /* USER CODE END MspInit 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/Nucleo-Blinky/Core/Src/stm32g4xx_it.c b/Nucleo-Blinky/Core/Src/stm32g4xx_it.c deleted file mode 100644 index f98aa5695..000000000 --- a/Nucleo-Blinky/Core/Src/stm32g4xx_it.c +++ /dev/null @@ -1,217 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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 "stm32g4xx_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 Prefetch 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 */ -} - -/******************************************************************************/ -/* STM32G4xx 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_stm32g4xx.s). */ -/******************************************************************************/ - -/** - * @brief This function handles EXTI line[15:10] interrupts. - */ -void EXTI15_10_IRQHandler(void) -{ - /* USER CODE BEGIN EXTI15_10_IRQn 0 */ - - /* USER CODE END EXTI15_10_IRQn 0 */ - BSP_PB_IRQHandler(BUTTON_USER); - /* USER CODE BEGIN EXTI15_10_IRQn 1 */ - - /* USER CODE END EXTI15_10_IRQn 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/Nucleo-Blinky/Nucleo-Blinky.ioc b/Nucleo-Blinky/Nucleo-Blinky.ioc deleted file mode 100644 index 1bc08b38e..000000000 --- a/Nucleo-Blinky/Nucleo-Blinky.ioc +++ /dev/null @@ -1,179 +0,0 @@ -#MicroXplorer Configuration settings - do not modify -BSP_IP_NAME=NUCLEO-G474RE -CAD.formats= -CAD.pinconfig= -CAD.provider= -File.Version=6 -KeepUserPlacement=false -Mcu.CPN=STM32G474RET6 -Mcu.Family=STM32G4 -Mcu.IP0=NUCLEO-G474RE -Mcu.IP1=NVIC -Mcu.IP2=RCC -Mcu.IP3=SYS -Mcu.IPNb=5 -Mcu.Name=STM32G474R(B-C-E)Tx -Mcu.Package=LQFP64 -Mcu.Pin0=PC13 -Mcu.Pin1=PC14-OSC32_IN -Mcu.Pin10=PB3 -Mcu.Pin11=VP_SYS_VS_Systick -Mcu.Pin12=VP_SYS_VS_DBSignals -Mcu.Pin13=VP_NUCLEO-G474RE_VS_BSP_COMMON -Mcu.Pin2=PC15-OSC32_OUT -Mcu.Pin3=PF0-OSC_IN -Mcu.Pin4=PF1-OSC_OUT -Mcu.Pin5=PA2 -Mcu.Pin6=PA3 -Mcu.Pin7=PA5 -Mcu.Pin8=PA13 -Mcu.Pin9=PA14 -Mcu.PinsNb=14 -Mcu.ThirdPartyNb=0 -Mcu.UserConstants= -Mcu.UserName=STM32G474RETx -MxCube.Version=6.18.0 -MxDb.Version=DB.6.0.180 -NUCLEO-G474RE.BUTTON=1 -NUCLEO-G474RE.IPParameters=BUTTON,LD2,VCP -NUCLEO-G474RE.LD2=true -NUCLEO-G474RE.VCP=true -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.EXTI15_10_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true -NVIC.ForceEnableDMAVector=true -NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 -NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:false -NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -PA13.GPIOParameters=GPIO_Label -PA13.GPIO_Label=T_SWDIO -PA13.Locked=true -PA13.Signal=SYS_JTMS-SWDIO -PA14.GPIOParameters=GPIO_Label -PA14.GPIO_Label=T_SWCLK -PA14.Locked=true -PA14.Signal=SYS_JTCK-SWCLK -PA2.Locked=true -PA2.Signal=LPUART1_TX -PA3.Locked=true -PA3.Signal=LPUART1_RX -PA5.Locked=true -PB3.GPIOParameters=GPIO_Label -PB3.GPIO_Label=T_SWO -PB3.Locked=true -PB3.Signal=SYS_JTDO-SWO -PC13.Locked=true -PC14-OSC32_IN.GPIOParameters=GPIO_Label -PC14-OSC32_IN.GPIO_Label=RCC_OSC32_IN -PC14-OSC32_IN.Locked=true -PC14-OSC32_IN.Signal=RCC_OSC32_IN -PC15-OSC32_OUT.GPIOParameters=GPIO_Label -PC15-OSC32_OUT.GPIO_Label=RCC_OSC32_OUT -PC15-OSC32_OUT.Locked=true -PC15-OSC32_OUT.Signal=RCC_OSC32_OUT -PF0-OSC_IN.GPIOParameters=GPIO_Label -PF0-OSC_IN.GPIO_Label=RCC_OSC_IN -PF0-OSC_IN.Locked=true -PF0-OSC_IN.Signal=RCC_OSC_IN -PF1-OSC_OUT.GPIOParameters=GPIO_Label -PF1-OSC_OUT.GPIO_Label=RCC_OSC_OUT -PF1-OSC_OUT.Locked=true -PF1-OSC_OUT.Signal=RCC_OSC_OUT -PinOutPanel.RotationAngle=0 -ProjectManager.AskForMigrate=true -ProjectManager.BackupPrevious=false -ProjectManager.CompilerLinker=GCC -ProjectManager.CompilerOptimize=6 -ProjectManager.ComputerToolchain=false -ProjectManager.CoupleFile=true -ProjectManager.CustomerFirmwarePackage= -ProjectManager.DefaultFWLocation=true -ProjectManager.DeletePrevious=true -ProjectManager.DeviceId=STM32G474RETx -ProjectManager.FirmwarePackage=STM32Cube FW_G4 V1.6.3 -ProjectManager.FreePins=false -ProjectManager.FreePinsContext= -ProjectManager.HalAssertFull=true -ProjectManager.HeapSize=0x200 -ProjectManager.KeepUserCode=true -ProjectManager.LastFirmware=true -ProjectManager.LibraryCopy=2 -ProjectManager.MainLocation=Core/Src -ProjectManager.NoMain=false -ProjectManager.PreviousToolchain= -ProjectManager.ProjectBuild=false -ProjectManager.ProjectFileName=Nucleo-Blinky.ioc -ProjectManager.ProjectName=Nucleo-Blinky -ProjectManager.ProjectStructure= -ProjectManager.RegisterCallBack= -ProjectManager.StackSize=0x400 -ProjectManager.TargetToolchain=EWARM V8.50 -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,false-0--NUCLEO-G474RE-true-HAL-true -RCC.ADC12Freq_Value=170000000 -RCC.ADC345Freq_Value=170000000 -RCC.AHBFreq_Value=170000000 -RCC.APB1Freq_Value=170000000 -RCC.APB1TimFreq_Value=170000000 -RCC.APB2Freq_Value=170000000 -RCC.APB2TimFreq_Value=170000000 -RCC.CRSFreq_Value=48000000 -RCC.CortexFreq_Value=170000000 -RCC.EXTERNAL_CLOCK_VALUE=12288000 -RCC.FCLKCortexFreq_Value=170000000 -RCC.FDCANFreq_Value=170000000 -RCC.FamilyName=M -RCC.HCLKFreq_Value=170000000 -RCC.HRTIM1Freq_Value=170000000 -RCC.HSE_VALUE=24000000 -RCC.HSI48_VALUE=48000000 -RCC.HSI_VALUE=16000000 -RCC.I2C1Freq_Value=170000000 -RCC.I2C2Freq_Value=170000000 -RCC.I2C3Freq_Value=170000000 -RCC.I2C4Freq_Value=170000000 -RCC.I2SFreq_Value=170000000 -RCC.IPParameters=ADC12Freq_Value,ADC345Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HRTIM1Freq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,PLLM,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PWRFreq_Value,QSPIFreq_Value,RNGFreq_Value,RTCClockSelection,RTCFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value -RCC.LPTIM1Freq_Value=170000000 -RCC.LPUART1Freq_Value=170000000 -RCC.LSCOPinFreq_Value=32000 -RCC.LSE_VALUE=32768 -RCC.LSI_VALUE=32000 -RCC.MCO1PinFreq_Value=16000000 -RCC.PLLM=RCC_PLLM_DIV4 -RCC.PLLN=85 -RCC.PLLPoutputFreq_Value=170000000 -RCC.PLLQoutputFreq_Value=170000000 -RCC.PLLRCLKFreq_Value=170000000 -RCC.PWRFreq_Value=170000000 -RCC.QSPIFreq_Value=170000000 -RCC.RNGFreq_Value=170000000 -RCC.RTCClockSelection=RCC_RTCCLKSOURCE_LSE -RCC.RTCFreq_Value=32768 -RCC.SAI1Freq_Value=170000000 -RCC.SYSCLKFreq_VALUE=170000000 -RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK -RCC.UART4Freq_Value=170000000 -RCC.UART5Freq_Value=170000000 -RCC.USART1Freq_Value=170000000 -RCC.USART2Freq_Value=170000000 -RCC.USART3Freq_Value=170000000 -RCC.USBFreq_Value=170000000 -RCC.VCOInputFreq_Value=4000000 -RCC.VCOOutputFreq_Value=340000000 -VP_NUCLEO-G474RE_VS_BSP_COMMON.Mode=COMMON -VP_NUCLEO-G474RE_VS_BSP_COMMON.Signal=NUCLEO-G474RE_VS_BSP_COMMON -VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals -VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick -board=NUCLEO-G474RE -boardIOC=true From a5a6f8da3be3c2f6341a74669a5e82f22bb2581d Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 9 Jul 2026 02:16:43 -0700 Subject: [PATCH 004/125] REVERT ME --- Nucleo blinky demo Signed-off-by: Daniel Hansen --- CMakeLists.txt | 2 + Nucleo-Blinky/CMakeLists.txt | 41 ++ Nucleo-Blinky/Core/Inc/gpio.h | 49 +++ Nucleo-Blinky/Core/Inc/main.h | 86 ++++ Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h | 380 ++++++++++++++++++ Nucleo-Blinky/Core/Inc/stm32g4xx_it.h | 67 +++ .../Core/Inc/stm32g4xx_nucleo_conf.h | 78 ++++ Nucleo-Blinky/Core/Src/gpio.c | 55 +++ Nucleo-Blinky/Core/Src/main.c | 209 ++++++++++ Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c | 85 ++++ Nucleo-Blinky/Core/Src/stm32g4xx_it.c | 217 ++++++++++ Nucleo-Blinky/Nucleo-Blinky.ioc | 179 +++++++++ 12 files changed, 1448 insertions(+) create mode 100644 Nucleo-Blinky/CMakeLists.txt create mode 100644 Nucleo-Blinky/Core/Inc/gpio.h create mode 100644 Nucleo-Blinky/Core/Inc/main.h create mode 100644 Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h create mode 100644 Nucleo-Blinky/Core/Inc/stm32g4xx_it.h create mode 100644 Nucleo-Blinky/Core/Inc/stm32g4xx_nucleo_conf.h create mode 100644 Nucleo-Blinky/Core/Src/gpio.c create mode 100644 Nucleo-Blinky/Core/Src/main.c create mode 100644 Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c create mode 100644 Nucleo-Blinky/Core/Src/stm32g4xx_it.c create mode 100644 Nucleo-Blinky/Nucleo-Blinky.ioc diff --git a/CMakeLists.txt b/CMakeLists.txt index dd6d899d4..a6023104a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,3 +185,5 @@ add_gr_project(STM32G474xE BLINKY G4ECHO) # Onboarding Workshops add_gr_project(STM32G474xE Onboarding W3_G4SPI_Receive) add_gr_project(STM32G474xE Onboarding W3_G4SPI_Transmit) + +add_gr_project(STM32G474xE Nucleo-Blinky) diff --git a/Nucleo-Blinky/CMakeLists.txt b/Nucleo-Blinky/CMakeLists.txt new file mode 100644 index 000000000..657a90cdb --- /dev/null +++ b/Nucleo-Blinky/CMakeLists.txt @@ -0,0 +1,41 @@ +cmake_minimum_required(VERSION 3.25) + +# Setup compiler settings +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS ON) + +# Define the build type +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug") +endif() + +# Enable CMake support for ASM and C languages +enable_language( + C + ASM +) + +# Core project settings +project(${CMAKE_PROJECT_NAME}) + +# what, does in fact not get the filename of somthing but rather the name of the project from the path +get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) + +add_library(${PROJECT_NAME}_USER_CODE INTERFACE) +target_sources( + ${PROJECT_NAME}_USER_CODE + INTERFACE + Core/Src/gpio.c + Core/Src/main.c + Core/Src/stm32g4xx_hal_msp.c + Core/Src/stm32g4xx_it.c +) + +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE) + +target_include_directories( + ${PROJECT_NAME}_USER_CODE + INTERFACE + Core/Inc +) diff --git a/Nucleo-Blinky/Core/Inc/gpio.h b/Nucleo-Blinky/Core/Inc/gpio.h new file mode 100644 index 000000000..3c91c4dd6 --- /dev/null +++ b/Nucleo-Blinky/Core/Inc/gpio.h @@ -0,0 +1,49 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file gpio.h + * @brief This file contains all the function prototypes for + * the gpio.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 __GPIO_H__ +#define __GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_GPIO_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif +#endif /*__ GPIO_H__ */ + diff --git a/Nucleo-Blinky/Core/Inc/main.h b/Nucleo-Blinky/Core/Inc/main.h new file mode 100644 index 000000000..e55f7d718 --- /dev/null +++ b/Nucleo-Blinky/Core/Inc/main.h @@ -0,0 +1,86 @@ +/* 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) 2026 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 "stm32g4xx_hal.h" + +#include "stm32g4xx_nucleo.h" +#include + +/* 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 Error_Handler(void); + +/* USER CODE BEGIN EFP */ + +/* USER CODE END EFP */ + +/* Private defines -----------------------------------------------------------*/ +#define RCC_OSC32_IN_Pin GPIO_PIN_14 +#define RCC_OSC32_IN_GPIO_Port GPIOC +#define RCC_OSC32_OUT_Pin GPIO_PIN_15 +#define RCC_OSC32_OUT_GPIO_Port GPIOC +#define RCC_OSC_IN_Pin GPIO_PIN_0 +#define RCC_OSC_IN_GPIO_Port GPIOF +#define RCC_OSC_OUT_Pin GPIO_PIN_1 +#define RCC_OSC_OUT_GPIO_Port GPIOF +#define T_SWDIO_Pin GPIO_PIN_13 +#define T_SWDIO_GPIO_Port GPIOA +#define T_SWCLK_Pin GPIO_PIN_14 +#define T_SWCLK_GPIO_Port GPIOA +#define T_SWO_Pin GPIO_PIN_3 +#define T_SWO_GPIO_Port GPIOB + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H */ diff --git a/Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h b/Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h new file mode 100644 index 000000000..3844b8157 --- /dev/null +++ b/Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h @@ -0,0 +1,380 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g4xx_hal_conf.h + * @author MCD Application Team + * @brief HAL configuration file + ****************************************************************************** + * @attention + * + * Copyright (c) 2019 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 STM32G4xx_HAL_CONF_H +#define STM32G4xx_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_ADC_MODULE_ENABLED */ +/*#define HAL_COMP_MODULE_ENABLED */ +/*#define HAL_CORDIC_MODULE_ENABLED */ +/*#define HAL_CRC_MODULE_ENABLED */ +/*#define HAL_CRYP_MODULE_ENABLED */ +/*#define HAL_DAC_MODULE_ENABLED */ +/*#define HAL_FDCAN_MODULE_ENABLED */ +/*#define HAL_FMAC_MODULE_ENABLED */ +/*#define HAL_HRTIM_MODULE_ENABLED */ +/*#define HAL_IRDA_MODULE_ENABLED */ +/*#define HAL_IWDG_MODULE_ENABLED */ +/*#define HAL_I2C_MODULE_ENABLED */ +/*#define HAL_I2S_MODULE_ENABLED */ +/*#define HAL_LPTIM_MODULE_ENABLED */ +/*#define HAL_NAND_MODULE_ENABLED */ +/*#define HAL_NOR_MODULE_ENABLED */ +/*#define HAL_OPAMP_MODULE_ENABLED */ +/*#define HAL_PCD_MODULE_ENABLED */ +/*#define HAL_QSPI_MODULE_ENABLED */ +/*#define HAL_RNG_MODULE_ENABLED */ +/*#define HAL_RTC_MODULE_ENABLED */ +/*#define HAL_SAI_MODULE_ENABLED */ +/*#define HAL_SMARTCARD_MODULE_ENABLED */ +/*#define HAL_SMBUS_MODULE_ENABLED */ +/*#define HAL_SPI_MODULE_ENABLED */ +/*#define HAL_SRAM_MODULE_ENABLED */ +/*#define HAL_TIM_MODULE_ENABLED */ +#define HAL_UART_MODULE_ENABLED +/*#define HAL_USART_MODULE_ENABLED */ +/*#define HAL_WWDG_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 + +/* ########################## Register Callbacks selection ############################## */ +/** + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + +/* ########################## Oscillator 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 (24000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ + +/** + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined (HSI48_VALUE) + #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ + +/** + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) +/*!< Value of the Internal Low Speed oscillator in Hz +The real value may vary depending on the variations in voltage and temperature.*/ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ +/** + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ + +#if !defined (LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ + +/** + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (0UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U + +/* ########################## Assert Selection ############################## */ +/** + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ + #define USE_FULL_ASSERT 1U + +/* ################## 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 "stm32g4xx_hal_rcc.h" +#endif /* HAL_RCC_MODULE_ENABLED */ + +#ifdef HAL_GPIO_MODULE_ENABLED +#include "stm32g4xx_hal_gpio.h" +#endif /* HAL_GPIO_MODULE_ENABLED */ + +#ifdef HAL_DMA_MODULE_ENABLED +#include "stm32g4xx_hal_dma.h" +#endif /* HAL_DMA_MODULE_ENABLED */ + +#ifdef HAL_CORTEX_MODULE_ENABLED +#include "stm32g4xx_hal_cortex.h" +#endif /* HAL_CORTEX_MODULE_ENABLED */ + +#ifdef HAL_ADC_MODULE_ENABLED +#include "stm32g4xx_hal_adc.h" +#endif /* HAL_ADC_MODULE_ENABLED */ + +#ifdef HAL_COMP_MODULE_ENABLED +#include "stm32g4xx_hal_comp.h" +#endif /* HAL_COMP_MODULE_ENABLED */ + +#ifdef HAL_CORDIC_MODULE_ENABLED +#include "stm32g4xx_hal_cordic.h" +#endif /* HAL_CORDIC_MODULE_ENABLED */ + +#ifdef HAL_CRC_MODULE_ENABLED +#include "stm32g4xx_hal_crc.h" +#endif /* HAL_CRC_MODULE_ENABLED */ + +#ifdef HAL_CRYP_MODULE_ENABLED +#include "stm32g4xx_hal_cryp.h" +#endif /* HAL_CRYP_MODULE_ENABLED */ + +#ifdef HAL_DAC_MODULE_ENABLED +#include "stm32g4xx_hal_dac.h" +#endif /* HAL_DAC_MODULE_ENABLED */ + +#ifdef HAL_EXTI_MODULE_ENABLED +#include "stm32g4xx_hal_exti.h" +#endif /* HAL_EXTI_MODULE_ENABLED */ + +#ifdef HAL_FDCAN_MODULE_ENABLED +#include "stm32g4xx_hal_fdcan.h" +#endif /* HAL_FDCAN_MODULE_ENABLED */ + +#ifdef HAL_FLASH_MODULE_ENABLED +#include "stm32g4xx_hal_flash.h" +#endif /* HAL_FLASH_MODULE_ENABLED */ + +#ifdef HAL_FMAC_MODULE_ENABLED +#include "stm32g4xx_hal_fmac.h" +#endif /* HAL_FMAC_MODULE_ENABLED */ + +#ifdef HAL_HRTIM_MODULE_ENABLED +#include "stm32g4xx_hal_hrtim.h" +#endif /* HAL_HRTIM_MODULE_ENABLED */ + +#ifdef HAL_IRDA_MODULE_ENABLED +#include "stm32g4xx_hal_irda.h" +#endif /* HAL_IRDA_MODULE_ENABLED */ + +#ifdef HAL_IWDG_MODULE_ENABLED +#include "stm32g4xx_hal_iwdg.h" +#endif /* HAL_IWDG_MODULE_ENABLED */ + +#ifdef HAL_I2C_MODULE_ENABLED +#include "stm32g4xx_hal_i2c.h" +#endif /* HAL_I2C_MODULE_ENABLED */ + +#ifdef HAL_I2S_MODULE_ENABLED +#include "stm32g4xx_hal_i2s.h" +#endif /* HAL_I2S_MODULE_ENABLED */ + +#ifdef HAL_LPTIM_MODULE_ENABLED +#include "stm32g4xx_hal_lptim.h" +#endif /* HAL_LPTIM_MODULE_ENABLED */ + +#ifdef HAL_NAND_MODULE_ENABLED +#include "stm32g4xx_hal_nand.h" +#endif /* HAL_NAND_MODULE_ENABLED */ + +#ifdef HAL_NOR_MODULE_ENABLED +#include "stm32g4xx_hal_nor.h" +#endif /* HAL_NOR_MODULE_ENABLED */ + +#ifdef HAL_OPAMP_MODULE_ENABLED +#include "stm32g4xx_hal_opamp.h" +#endif /* HAL_OPAMP_MODULE_ENABLED */ + +#ifdef HAL_PCD_MODULE_ENABLED +#include "stm32g4xx_hal_pcd.h" +#endif /* HAL_PCD_MODULE_ENABLED */ + +#ifdef HAL_PWR_MODULE_ENABLED +#include "stm32g4xx_hal_pwr.h" +#endif /* HAL_PWR_MODULE_ENABLED */ + +#ifdef HAL_QSPI_MODULE_ENABLED +#include "stm32g4xx_hal_qspi.h" +#endif /* HAL_QSPI_MODULE_ENABLED */ + +#ifdef HAL_RNG_MODULE_ENABLED +#include "stm32g4xx_hal_rng.h" +#endif /* HAL_RNG_MODULE_ENABLED */ + +#ifdef HAL_RTC_MODULE_ENABLED +#include "stm32g4xx_hal_rtc.h" +#endif /* HAL_RTC_MODULE_ENABLED */ + +#ifdef HAL_SAI_MODULE_ENABLED +#include "stm32g4xx_hal_sai.h" +#endif /* HAL_SAI_MODULE_ENABLED */ + +#ifdef HAL_SMARTCARD_MODULE_ENABLED +#include "stm32g4xx_hal_smartcard.h" +#endif /* HAL_SMARTCARD_MODULE_ENABLED */ + +#ifdef HAL_SMBUS_MODULE_ENABLED +#include "stm32g4xx_hal_smbus.h" +#endif /* HAL_SMBUS_MODULE_ENABLED */ + +#ifdef HAL_SPI_MODULE_ENABLED +#include "stm32g4xx_hal_spi.h" +#endif /* HAL_SPI_MODULE_ENABLED */ + +#ifdef HAL_SRAM_MODULE_ENABLED +#include "stm32g4xx_hal_sram.h" +#endif /* HAL_SRAM_MODULE_ENABLED */ + +#ifdef HAL_TIM_MODULE_ENABLED +#include "stm32g4xx_hal_tim.h" +#endif /* HAL_TIM_MODULE_ENABLED */ + +#ifdef HAL_UART_MODULE_ENABLED +#include "stm32g4xx_hal_uart.h" +#endif /* HAL_UART_MODULE_ENABLED */ + +#ifdef HAL_USART_MODULE_ENABLED +#include "stm32g4xx_hal_usart.h" +#endif /* HAL_USART_MODULE_ENABLED */ + +#ifdef HAL_WWDG_MODULE_ENABLED +#include "stm32g4xx_hal_wwdg.h" +#endif /* HAL_WWDG_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 /* STM32G4xx_HAL_CONF_H */ diff --git a/Nucleo-Blinky/Core/Inc/stm32g4xx_it.h b/Nucleo-Blinky/Core/Inc/stm32g4xx_it.h new file mode 100644 index 000000000..001ebdf89 --- /dev/null +++ b/Nucleo-Blinky/Core/Inc/stm32g4xx_it.h @@ -0,0 +1,67 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g4xx_it.h + * @brief This file contains the headers of the interrupt handlers. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 __STM32G4xx_IT_H +#define __STM32G4xx_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); +void EXTI15_10_IRQHandler(void); +/* USER CODE BEGIN EFP */ + +/* USER CODE END EFP */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32G4xx_IT_H */ diff --git a/Nucleo-Blinky/Core/Inc/stm32g4xx_nucleo_conf.h b/Nucleo-Blinky/Core/Inc/stm32g4xx_nucleo_conf.h new file mode 100644 index 000000000..602b3233e --- /dev/null +++ b/Nucleo-Blinky/Core/Inc/stm32g4xx_nucleo_conf.h @@ -0,0 +1,78 @@ + +/** + ****************************************************************************** + * @file stm32g4xx_nucleo_conf.h + * @author MCD Application Team + * @brief STM32G4xx_Nucleo board configuration file. + * This file should be copied to the application folder and renamed + * to stm32g4xx_nucleo_conf.h + ****************************************************************************** + * @attention + * + * Copyright (c) 2022 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. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef STM32G4XX_NUCLEO_CONF_H +#define STM32G4XX_NUCLEO_CONF_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32g4xx_hal.h" + +/** @addtogroup BSP + * @{ + */ + +/** @addtogroup STM32G4XX_NUCLEO + * @{ + */ + +/** @defgroup STM32G4XX_NUCLEO_CONFIG Config + * @{ + */ + +/** @defgroup STM32C0XX_NUCLEO_CONFIG_Exported_Constants Exported Constants + * @{ + */ +/* Nucleo pin and part number defines */ +#define USE_STM32G4XX_NUCLEO + +/* COM define */ +#define USE_COM_LOG 1U +#define USE_BSP_COM_FEATURE 1U + +/* IRQ priorities */ +#define BSP_BUTTON_USER_IT_PRIORITY 15U + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* STM32G4XX_NUCLEO_CONF_H */ diff --git a/Nucleo-Blinky/Core/Src/gpio.c b/Nucleo-Blinky/Core/Src/gpio.c new file mode 100644 index 000000000..3a44fbc3e --- /dev/null +++ b/Nucleo-Blinky/Core/Src/gpio.c @@ -0,0 +1,55 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file gpio.c + * @brief This file provides code for the configuration + * of all used GPIO pins. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "gpio.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/*----------------------------------------------------------------------------*/ +/* Configure GPIO */ +/*----------------------------------------------------------------------------*/ +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + +/** Configure pins as + * Analog + * Input + * Output + * EVENT_OUT + * EXTI +*/ +void MX_GPIO_Init(void) +{ + + /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOF_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + +} + +/* USER CODE BEGIN 2 */ + +/* USER CODE END 2 */ diff --git a/Nucleo-Blinky/Core/Src/main.c b/Nucleo-Blinky/Core/Src/main.c new file mode 100644 index 000000000..ab141cb7c --- /dev/null +++ b/Nucleo-Blinky/Core/Src/main.c @@ -0,0 +1,209 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.c + * @brief : Main program body + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "gpio.h" + +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN PTD */ + +/* USER CODE END PTD */ + +/* Private define ------------------------------------------------------------*/ +/* USER CODE BEGIN PD */ + +/* USER CODE END PD */ + +/* Private macro -------------------------------------------------------------*/ +/* USER CODE BEGIN PM */ + +/* USER CODE END PM */ + +/* Private variables ---------------------------------------------------------*/ + +COM_InitTypeDef BspCOMInit; + +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +void SystemClock_Config(void); +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* Private user code ---------------------------------------------------------*/ +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/** + * @brief The application entry point. + * @retval int + */ +int main(void) +{ + + /* USER CODE BEGIN 1 */ + + /* USER CODE END 1 */ + + /* MCU Configuration--------------------------------------------------------*/ + + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); + + /* USER CODE BEGIN Init */ + + /* USER CODE END Init */ + + /* Configure the system clock */ + SystemClock_Config(); + + /* USER CODE BEGIN SysInit */ + + /* USER CODE END SysInit */ + + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + /* USER CODE BEGIN 2 */ + + /* USER CODE END 2 */ + + /* Initialize led */ + BSP_LED_Init(LED_GREEN); + + /* Initialize USER push-button, will be used to trigger an interrupt each time it's pressed.*/ + BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI); + + /* Initialize COM1 port (115200, 8 bits (7-bit data + 1 stop bit), no parity */ + BspCOMInit.BaudRate = 115200; + BspCOMInit.WordLength = COM_WORDLENGTH_8B; + BspCOMInit.StopBits = COM_STOPBITS_1; + BspCOMInit.Parity = COM_PARITY_NONE; + BspCOMInit.HwFlowCtl = COM_HWCONTROL_NONE; + if (BSP_COM_Init(COM1, &BspCOMInit) != BSP_ERROR_NONE) + { + Error_Handler(); + } + + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ + while (1) + { + HAL_Delay(100); + /* USER CODE END WHILE */ + + /* USER CODE BEGIN 3 */ + HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin); + + if (BSP_PB_GetState(BUTTON_USER) == GPIO_PIN_SET) + { + HAL_Delay(10); + } + } + /* USER CODE END 3 */ +} + +/** + * @brief System Clock Configuration + * @retval None + */ +void SystemClock_Config(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + + /** Configure the main internal regulator output voltage + */ + HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST); + + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; + RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4; + RCC_OscInitStruct.PLL.PLLN = 85; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; + RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; + RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) + { + Error_Handler(); + } + + /** Initializes the CPU, AHB and APB buses clocks + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK + |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) + { + Error_Handler(); + } +} + +/* USER CODE BEGIN 4 */ + +/* USER CODE END 4 */ + +/** + * @brief This function is executed in case of error occurrence. + * @retval None + */ +void Error_Handler(void) +{ + /* USER CODE BEGIN Error_Handler_Debug */ + /* User can add his own implementation to report the HAL error return state */ + __disable_irq(); + while (1) + { + } + /* USER CODE END Error_Handler_Debug */ +} +#ifdef USE_FULL_ASSERT +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ +void assert_failed(uint8_t *file, uint32_t line) +{ + /* USER CODE BEGIN 6 */ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + /* USER CODE END 6 */ +} +#endif /* USE_FULL_ASSERT */ diff --git a/Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c b/Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c new file mode 100644 index 000000000..d908bd772 --- /dev/null +++ b/Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c @@ -0,0 +1,85 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g4xx_hal_msp.c + * @brief This file provides code for the MSP Initialization + * and de-Initialization codes. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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*/ + + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); + + /* USER CODE BEGIN MspInit 1 */ + + /* USER CODE END MspInit 1 */ +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/Nucleo-Blinky/Core/Src/stm32g4xx_it.c b/Nucleo-Blinky/Core/Src/stm32g4xx_it.c new file mode 100644 index 000000000..f98aa5695 --- /dev/null +++ b/Nucleo-Blinky/Core/Src/stm32g4xx_it.c @@ -0,0 +1,217 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g4xx_it.c + * @brief Interrupt Service Routines. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "stm32g4xx_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 Prefetch 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 */ +} + +/******************************************************************************/ +/* STM32G4xx 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_stm32g4xx.s). */ +/******************************************************************************/ + +/** + * @brief This function handles EXTI line[15:10] interrupts. + */ +void EXTI15_10_IRQHandler(void) +{ + /* USER CODE BEGIN EXTI15_10_IRQn 0 */ + + /* USER CODE END EXTI15_10_IRQn 0 */ + BSP_PB_IRQHandler(BUTTON_USER); + /* USER CODE BEGIN EXTI15_10_IRQn 1 */ + + /* USER CODE END EXTI15_10_IRQn 1 */ +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/Nucleo-Blinky/Nucleo-Blinky.ioc b/Nucleo-Blinky/Nucleo-Blinky.ioc new file mode 100644 index 000000000..1bc08b38e --- /dev/null +++ b/Nucleo-Blinky/Nucleo-Blinky.ioc @@ -0,0 +1,179 @@ +#MicroXplorer Configuration settings - do not modify +BSP_IP_NAME=NUCLEO-G474RE +CAD.formats= +CAD.pinconfig= +CAD.provider= +File.Version=6 +KeepUserPlacement=false +Mcu.CPN=STM32G474RET6 +Mcu.Family=STM32G4 +Mcu.IP0=NUCLEO-G474RE +Mcu.IP1=NVIC +Mcu.IP2=RCC +Mcu.IP3=SYS +Mcu.IPNb=5 +Mcu.Name=STM32G474R(B-C-E)Tx +Mcu.Package=LQFP64 +Mcu.Pin0=PC13 +Mcu.Pin1=PC14-OSC32_IN +Mcu.Pin10=PB3 +Mcu.Pin11=VP_SYS_VS_Systick +Mcu.Pin12=VP_SYS_VS_DBSignals +Mcu.Pin13=VP_NUCLEO-G474RE_VS_BSP_COMMON +Mcu.Pin2=PC15-OSC32_OUT +Mcu.Pin3=PF0-OSC_IN +Mcu.Pin4=PF1-OSC_OUT +Mcu.Pin5=PA2 +Mcu.Pin6=PA3 +Mcu.Pin7=PA5 +Mcu.Pin8=PA13 +Mcu.Pin9=PA14 +Mcu.PinsNb=14 +Mcu.ThirdPartyNb=0 +Mcu.UserConstants= +Mcu.UserName=STM32G474RETx +MxCube.Version=6.18.0 +MxDb.Version=DB.6.0.180 +NUCLEO-G474RE.BUTTON=1 +NUCLEO-G474RE.IPParameters=BUTTON,LD2,VCP +NUCLEO-G474RE.LD2=true +NUCLEO-G474RE.VCP=true +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.EXTI15_10_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true +NVIC.ForceEnableDMAVector=true +NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 +NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:false +NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +PA13.GPIOParameters=GPIO_Label +PA13.GPIO_Label=T_SWDIO +PA13.Locked=true +PA13.Signal=SYS_JTMS-SWDIO +PA14.GPIOParameters=GPIO_Label +PA14.GPIO_Label=T_SWCLK +PA14.Locked=true +PA14.Signal=SYS_JTCK-SWCLK +PA2.Locked=true +PA2.Signal=LPUART1_TX +PA3.Locked=true +PA3.Signal=LPUART1_RX +PA5.Locked=true +PB3.GPIOParameters=GPIO_Label +PB3.GPIO_Label=T_SWO +PB3.Locked=true +PB3.Signal=SYS_JTDO-SWO +PC13.Locked=true +PC14-OSC32_IN.GPIOParameters=GPIO_Label +PC14-OSC32_IN.GPIO_Label=RCC_OSC32_IN +PC14-OSC32_IN.Locked=true +PC14-OSC32_IN.Signal=RCC_OSC32_IN +PC15-OSC32_OUT.GPIOParameters=GPIO_Label +PC15-OSC32_OUT.GPIO_Label=RCC_OSC32_OUT +PC15-OSC32_OUT.Locked=true +PC15-OSC32_OUT.Signal=RCC_OSC32_OUT +PF0-OSC_IN.GPIOParameters=GPIO_Label +PF0-OSC_IN.GPIO_Label=RCC_OSC_IN +PF0-OSC_IN.Locked=true +PF0-OSC_IN.Signal=RCC_OSC_IN +PF1-OSC_OUT.GPIOParameters=GPIO_Label +PF1-OSC_OUT.GPIO_Label=RCC_OSC_OUT +PF1-OSC_OUT.Locked=true +PF1-OSC_OUT.Signal=RCC_OSC_OUT +PinOutPanel.RotationAngle=0 +ProjectManager.AskForMigrate=true +ProjectManager.BackupPrevious=false +ProjectManager.CompilerLinker=GCC +ProjectManager.CompilerOptimize=6 +ProjectManager.ComputerToolchain=false +ProjectManager.CoupleFile=true +ProjectManager.CustomerFirmwarePackage= +ProjectManager.DefaultFWLocation=true +ProjectManager.DeletePrevious=true +ProjectManager.DeviceId=STM32G474RETx +ProjectManager.FirmwarePackage=STM32Cube FW_G4 V1.6.3 +ProjectManager.FreePins=false +ProjectManager.FreePinsContext= +ProjectManager.HalAssertFull=true +ProjectManager.HeapSize=0x200 +ProjectManager.KeepUserCode=true +ProjectManager.LastFirmware=true +ProjectManager.LibraryCopy=2 +ProjectManager.MainLocation=Core/Src +ProjectManager.NoMain=false +ProjectManager.PreviousToolchain= +ProjectManager.ProjectBuild=false +ProjectManager.ProjectFileName=Nucleo-Blinky.ioc +ProjectManager.ProjectName=Nucleo-Blinky +ProjectManager.ProjectStructure= +ProjectManager.RegisterCallBack= +ProjectManager.StackSize=0x400 +ProjectManager.TargetToolchain=EWARM V8.50 +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,false-0--NUCLEO-G474RE-true-HAL-true +RCC.ADC12Freq_Value=170000000 +RCC.ADC345Freq_Value=170000000 +RCC.AHBFreq_Value=170000000 +RCC.APB1Freq_Value=170000000 +RCC.APB1TimFreq_Value=170000000 +RCC.APB2Freq_Value=170000000 +RCC.APB2TimFreq_Value=170000000 +RCC.CRSFreq_Value=48000000 +RCC.CortexFreq_Value=170000000 +RCC.EXTERNAL_CLOCK_VALUE=12288000 +RCC.FCLKCortexFreq_Value=170000000 +RCC.FDCANFreq_Value=170000000 +RCC.FamilyName=M +RCC.HCLKFreq_Value=170000000 +RCC.HRTIM1Freq_Value=170000000 +RCC.HSE_VALUE=24000000 +RCC.HSI48_VALUE=48000000 +RCC.HSI_VALUE=16000000 +RCC.I2C1Freq_Value=170000000 +RCC.I2C2Freq_Value=170000000 +RCC.I2C3Freq_Value=170000000 +RCC.I2C4Freq_Value=170000000 +RCC.I2SFreq_Value=170000000 +RCC.IPParameters=ADC12Freq_Value,ADC345Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HRTIM1Freq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,PLLM,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PWRFreq_Value,QSPIFreq_Value,RNGFreq_Value,RTCClockSelection,RTCFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value +RCC.LPTIM1Freq_Value=170000000 +RCC.LPUART1Freq_Value=170000000 +RCC.LSCOPinFreq_Value=32000 +RCC.LSE_VALUE=32768 +RCC.LSI_VALUE=32000 +RCC.MCO1PinFreq_Value=16000000 +RCC.PLLM=RCC_PLLM_DIV4 +RCC.PLLN=85 +RCC.PLLPoutputFreq_Value=170000000 +RCC.PLLQoutputFreq_Value=170000000 +RCC.PLLRCLKFreq_Value=170000000 +RCC.PWRFreq_Value=170000000 +RCC.QSPIFreq_Value=170000000 +RCC.RNGFreq_Value=170000000 +RCC.RTCClockSelection=RCC_RTCCLKSOURCE_LSE +RCC.RTCFreq_Value=32768 +RCC.SAI1Freq_Value=170000000 +RCC.SYSCLKFreq_VALUE=170000000 +RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK +RCC.UART4Freq_Value=170000000 +RCC.UART5Freq_Value=170000000 +RCC.USART1Freq_Value=170000000 +RCC.USART2Freq_Value=170000000 +RCC.USART3Freq_Value=170000000 +RCC.USBFreq_Value=170000000 +RCC.VCOInputFreq_Value=4000000 +RCC.VCOOutputFreq_Value=340000000 +VP_NUCLEO-G474RE_VS_BSP_COMMON.Mode=COMMON +VP_NUCLEO-G474RE_VS_BSP_COMMON.Signal=NUCLEO-G474RE_VS_BSP_COMMON +VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals +VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals +VP_SYS_VS_Systick.Mode=SysTick +VP_SYS_VS_Systick.Signal=SYS_VS_Systick +board=NUCLEO-G474RE +boardIOC=true From aa01abe147169b6cd442335146e79ef752ba80d5 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 9 Jul 2026 02:20:09 -0700 Subject: [PATCH 005/125] Revert "REVERT ME --- Nucleo blinky demo" This reverts commit da7387f34276a452111577b51896c4276b35a762. --- CMakeLists.txt | 2 - Nucleo-Blinky/CMakeLists.txt | 41 -- Nucleo-Blinky/Core/Inc/gpio.h | 49 --- Nucleo-Blinky/Core/Inc/main.h | 86 ---- Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h | 380 ------------------ Nucleo-Blinky/Core/Inc/stm32g4xx_it.h | 67 --- .../Core/Inc/stm32g4xx_nucleo_conf.h | 78 ---- Nucleo-Blinky/Core/Src/gpio.c | 55 --- Nucleo-Blinky/Core/Src/main.c | 209 ---------- Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c | 85 ---- Nucleo-Blinky/Core/Src/stm32g4xx_it.c | 217 ---------- Nucleo-Blinky/Nucleo-Blinky.ioc | 179 --------- 12 files changed, 1448 deletions(-) delete mode 100644 Nucleo-Blinky/CMakeLists.txt delete mode 100644 Nucleo-Blinky/Core/Inc/gpio.h delete mode 100644 Nucleo-Blinky/Core/Inc/main.h delete mode 100644 Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h delete mode 100644 Nucleo-Blinky/Core/Inc/stm32g4xx_it.h delete mode 100644 Nucleo-Blinky/Core/Inc/stm32g4xx_nucleo_conf.h delete mode 100644 Nucleo-Blinky/Core/Src/gpio.c delete mode 100644 Nucleo-Blinky/Core/Src/main.c delete mode 100644 Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c delete mode 100644 Nucleo-Blinky/Core/Src/stm32g4xx_it.c delete mode 100644 Nucleo-Blinky/Nucleo-Blinky.ioc diff --git a/CMakeLists.txt b/CMakeLists.txt index a6023104a..dd6d899d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,5 +185,3 @@ add_gr_project(STM32G474xE BLINKY G4ECHO) # Onboarding Workshops add_gr_project(STM32G474xE Onboarding W3_G4SPI_Receive) add_gr_project(STM32G474xE Onboarding W3_G4SPI_Transmit) - -add_gr_project(STM32G474xE Nucleo-Blinky) diff --git a/Nucleo-Blinky/CMakeLists.txt b/Nucleo-Blinky/CMakeLists.txt deleted file mode 100644 index 657a90cdb..000000000 --- a/Nucleo-Blinky/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -# Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) - -# Define the build type -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug") -endif() - -# Enable CMake support for ASM and C languages -enable_language( - C - ASM -) - -# Core project settings -project(${CMAKE_PROJECT_NAME}) - -# what, does in fact not get the filename of somthing but rather the name of the project from the path -get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) - -add_library(${PROJECT_NAME}_USER_CODE INTERFACE) -target_sources( - ${PROJECT_NAME}_USER_CODE - INTERFACE - Core/Src/gpio.c - Core/Src/main.c - Core/Src/stm32g4xx_hal_msp.c - Core/Src/stm32g4xx_it.c -) - -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE) - -target_include_directories( - ${PROJECT_NAME}_USER_CODE - INTERFACE - Core/Inc -) diff --git a/Nucleo-Blinky/Core/Inc/gpio.h b/Nucleo-Blinky/Core/Inc/gpio.h deleted file mode 100644 index 3c91c4dd6..000000000 --- a/Nucleo-Blinky/Core/Inc/gpio.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file gpio.h - * @brief This file contains all the function prototypes for - * the gpio.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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 __GPIO_H__ -#define __GPIO_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_GPIO_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif -#endif /*__ GPIO_H__ */ - diff --git a/Nucleo-Blinky/Core/Inc/main.h b/Nucleo-Blinky/Core/Inc/main.h deleted file mode 100644 index e55f7d718..000000000 --- a/Nucleo-Blinky/Core/Inc/main.h +++ /dev/null @@ -1,86 +0,0 @@ -/* 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) 2026 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 "stm32g4xx_hal.h" - -#include "stm32g4xx_nucleo.h" -#include - -/* 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 Error_Handler(void); - -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -/* Private defines -----------------------------------------------------------*/ -#define RCC_OSC32_IN_Pin GPIO_PIN_14 -#define RCC_OSC32_IN_GPIO_Port GPIOC -#define RCC_OSC32_OUT_Pin GPIO_PIN_15 -#define RCC_OSC32_OUT_GPIO_Port GPIOC -#define RCC_OSC_IN_Pin GPIO_PIN_0 -#define RCC_OSC_IN_GPIO_Port GPIOF -#define RCC_OSC_OUT_Pin GPIO_PIN_1 -#define RCC_OSC_OUT_GPIO_Port GPIOF -#define T_SWDIO_Pin GPIO_PIN_13 -#define T_SWDIO_GPIO_Port GPIOA -#define T_SWCLK_Pin GPIO_PIN_14 -#define T_SWCLK_GPIO_Port GPIOA -#define T_SWO_Pin GPIO_PIN_3 -#define T_SWO_GPIO_Port GPIOB - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -#ifdef __cplusplus -} -#endif - -#endif /* __MAIN_H */ diff --git a/Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h b/Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h deleted file mode 100644 index 3844b8157..000000000 --- a/Nucleo-Blinky/Core/Inc/stm32g4xx_hal_conf.h +++ /dev/null @@ -1,380 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_conf.h - * @author MCD Application Team - * @brief HAL configuration file - ****************************************************************************** - * @attention - * - * Copyright (c) 2019 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 STM32G4xx_HAL_CONF_H -#define STM32G4xx_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_ADC_MODULE_ENABLED */ -/*#define HAL_COMP_MODULE_ENABLED */ -/*#define HAL_CORDIC_MODULE_ENABLED */ -/*#define HAL_CRC_MODULE_ENABLED */ -/*#define HAL_CRYP_MODULE_ENABLED */ -/*#define HAL_DAC_MODULE_ENABLED */ -/*#define HAL_FDCAN_MODULE_ENABLED */ -/*#define HAL_FMAC_MODULE_ENABLED */ -/*#define HAL_HRTIM_MODULE_ENABLED */ -/*#define HAL_IRDA_MODULE_ENABLED */ -/*#define HAL_IWDG_MODULE_ENABLED */ -/*#define HAL_I2C_MODULE_ENABLED */ -/*#define HAL_I2S_MODULE_ENABLED */ -/*#define HAL_LPTIM_MODULE_ENABLED */ -/*#define HAL_NAND_MODULE_ENABLED */ -/*#define HAL_NOR_MODULE_ENABLED */ -/*#define HAL_OPAMP_MODULE_ENABLED */ -/*#define HAL_PCD_MODULE_ENABLED */ -/*#define HAL_QSPI_MODULE_ENABLED */ -/*#define HAL_RNG_MODULE_ENABLED */ -/*#define HAL_RTC_MODULE_ENABLED */ -/*#define HAL_SAI_MODULE_ENABLED */ -/*#define HAL_SMARTCARD_MODULE_ENABLED */ -/*#define HAL_SMBUS_MODULE_ENABLED */ -/*#define HAL_SPI_MODULE_ENABLED */ -/*#define HAL_SRAM_MODULE_ENABLED */ -/*#define HAL_TIM_MODULE_ENABLED */ -#define HAL_UART_MODULE_ENABLED -/*#define HAL_USART_MODULE_ENABLED */ -/*#define HAL_WWDG_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 - -/* ########################## Register Callbacks selection ############################## */ -/** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U - -/* ########################## Oscillator 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 (24000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ - -/** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined (HSI48_VALUE) - #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ - -/** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) -/*!< Value of the Internal Low Speed oscillator in Hz -The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ -/** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined (LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ - -#if !defined (LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ - -/** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined (EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (0UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U - -/* ########################## Assert Selection ############################## */ -/** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ - #define USE_FULL_ASSERT 1U - -/* ################## 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 "stm32g4xx_hal_rcc.h" -#endif /* HAL_RCC_MODULE_ENABLED */ - -#ifdef HAL_GPIO_MODULE_ENABLED -#include "stm32g4xx_hal_gpio.h" -#endif /* HAL_GPIO_MODULE_ENABLED */ - -#ifdef HAL_DMA_MODULE_ENABLED -#include "stm32g4xx_hal_dma.h" -#endif /* HAL_DMA_MODULE_ENABLED */ - -#ifdef HAL_CORTEX_MODULE_ENABLED -#include "stm32g4xx_hal_cortex.h" -#endif /* HAL_CORTEX_MODULE_ENABLED */ - -#ifdef HAL_ADC_MODULE_ENABLED -#include "stm32g4xx_hal_adc.h" -#endif /* HAL_ADC_MODULE_ENABLED */ - -#ifdef HAL_COMP_MODULE_ENABLED -#include "stm32g4xx_hal_comp.h" -#endif /* HAL_COMP_MODULE_ENABLED */ - -#ifdef HAL_CORDIC_MODULE_ENABLED -#include "stm32g4xx_hal_cordic.h" -#endif /* HAL_CORDIC_MODULE_ENABLED */ - -#ifdef HAL_CRC_MODULE_ENABLED -#include "stm32g4xx_hal_crc.h" -#endif /* HAL_CRC_MODULE_ENABLED */ - -#ifdef HAL_CRYP_MODULE_ENABLED -#include "stm32g4xx_hal_cryp.h" -#endif /* HAL_CRYP_MODULE_ENABLED */ - -#ifdef HAL_DAC_MODULE_ENABLED -#include "stm32g4xx_hal_dac.h" -#endif /* HAL_DAC_MODULE_ENABLED */ - -#ifdef HAL_EXTI_MODULE_ENABLED -#include "stm32g4xx_hal_exti.h" -#endif /* HAL_EXTI_MODULE_ENABLED */ - -#ifdef HAL_FDCAN_MODULE_ENABLED -#include "stm32g4xx_hal_fdcan.h" -#endif /* HAL_FDCAN_MODULE_ENABLED */ - -#ifdef HAL_FLASH_MODULE_ENABLED -#include "stm32g4xx_hal_flash.h" -#endif /* HAL_FLASH_MODULE_ENABLED */ - -#ifdef HAL_FMAC_MODULE_ENABLED -#include "stm32g4xx_hal_fmac.h" -#endif /* HAL_FMAC_MODULE_ENABLED */ - -#ifdef HAL_HRTIM_MODULE_ENABLED -#include "stm32g4xx_hal_hrtim.h" -#endif /* HAL_HRTIM_MODULE_ENABLED */ - -#ifdef HAL_IRDA_MODULE_ENABLED -#include "stm32g4xx_hal_irda.h" -#endif /* HAL_IRDA_MODULE_ENABLED */ - -#ifdef HAL_IWDG_MODULE_ENABLED -#include "stm32g4xx_hal_iwdg.h" -#endif /* HAL_IWDG_MODULE_ENABLED */ - -#ifdef HAL_I2C_MODULE_ENABLED -#include "stm32g4xx_hal_i2c.h" -#endif /* HAL_I2C_MODULE_ENABLED */ - -#ifdef HAL_I2S_MODULE_ENABLED -#include "stm32g4xx_hal_i2s.h" -#endif /* HAL_I2S_MODULE_ENABLED */ - -#ifdef HAL_LPTIM_MODULE_ENABLED -#include "stm32g4xx_hal_lptim.h" -#endif /* HAL_LPTIM_MODULE_ENABLED */ - -#ifdef HAL_NAND_MODULE_ENABLED -#include "stm32g4xx_hal_nand.h" -#endif /* HAL_NAND_MODULE_ENABLED */ - -#ifdef HAL_NOR_MODULE_ENABLED -#include "stm32g4xx_hal_nor.h" -#endif /* HAL_NOR_MODULE_ENABLED */ - -#ifdef HAL_OPAMP_MODULE_ENABLED -#include "stm32g4xx_hal_opamp.h" -#endif /* HAL_OPAMP_MODULE_ENABLED */ - -#ifdef HAL_PCD_MODULE_ENABLED -#include "stm32g4xx_hal_pcd.h" -#endif /* HAL_PCD_MODULE_ENABLED */ - -#ifdef HAL_PWR_MODULE_ENABLED -#include "stm32g4xx_hal_pwr.h" -#endif /* HAL_PWR_MODULE_ENABLED */ - -#ifdef HAL_QSPI_MODULE_ENABLED -#include "stm32g4xx_hal_qspi.h" -#endif /* HAL_QSPI_MODULE_ENABLED */ - -#ifdef HAL_RNG_MODULE_ENABLED -#include "stm32g4xx_hal_rng.h" -#endif /* HAL_RNG_MODULE_ENABLED */ - -#ifdef HAL_RTC_MODULE_ENABLED -#include "stm32g4xx_hal_rtc.h" -#endif /* HAL_RTC_MODULE_ENABLED */ - -#ifdef HAL_SAI_MODULE_ENABLED -#include "stm32g4xx_hal_sai.h" -#endif /* HAL_SAI_MODULE_ENABLED */ - -#ifdef HAL_SMARTCARD_MODULE_ENABLED -#include "stm32g4xx_hal_smartcard.h" -#endif /* HAL_SMARTCARD_MODULE_ENABLED */ - -#ifdef HAL_SMBUS_MODULE_ENABLED -#include "stm32g4xx_hal_smbus.h" -#endif /* HAL_SMBUS_MODULE_ENABLED */ - -#ifdef HAL_SPI_MODULE_ENABLED -#include "stm32g4xx_hal_spi.h" -#endif /* HAL_SPI_MODULE_ENABLED */ - -#ifdef HAL_SRAM_MODULE_ENABLED -#include "stm32g4xx_hal_sram.h" -#endif /* HAL_SRAM_MODULE_ENABLED */ - -#ifdef HAL_TIM_MODULE_ENABLED -#include "stm32g4xx_hal_tim.h" -#endif /* HAL_TIM_MODULE_ENABLED */ - -#ifdef HAL_UART_MODULE_ENABLED -#include "stm32g4xx_hal_uart.h" -#endif /* HAL_UART_MODULE_ENABLED */ - -#ifdef HAL_USART_MODULE_ENABLED -#include "stm32g4xx_hal_usart.h" -#endif /* HAL_USART_MODULE_ENABLED */ - -#ifdef HAL_WWDG_MODULE_ENABLED -#include "stm32g4xx_hal_wwdg.h" -#endif /* HAL_WWDG_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 /* STM32G4xx_HAL_CONF_H */ diff --git a/Nucleo-Blinky/Core/Inc/stm32g4xx_it.h b/Nucleo-Blinky/Core/Inc/stm32g4xx_it.h deleted file mode 100644 index 001ebdf89..000000000 --- a/Nucleo-Blinky/Core/Inc/stm32g4xx_it.h +++ /dev/null @@ -1,67 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_it.h - * @brief This file contains the headers of the interrupt handlers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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 __STM32G4xx_IT_H -#define __STM32G4xx_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); -void EXTI15_10_IRQHandler(void); -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32G4xx_IT_H */ diff --git a/Nucleo-Blinky/Core/Inc/stm32g4xx_nucleo_conf.h b/Nucleo-Blinky/Core/Inc/stm32g4xx_nucleo_conf.h deleted file mode 100644 index 602b3233e..000000000 --- a/Nucleo-Blinky/Core/Inc/stm32g4xx_nucleo_conf.h +++ /dev/null @@ -1,78 +0,0 @@ - -/** - ****************************************************************************** - * @file stm32g4xx_nucleo_conf.h - * @author MCD Application Team - * @brief STM32G4xx_Nucleo board configuration file. - * This file should be copied to the application folder and renamed - * to stm32g4xx_nucleo_conf.h - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 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. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef STM32G4XX_NUCLEO_CONF_H -#define STM32G4XX_NUCLEO_CONF_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "stm32g4xx_hal.h" - -/** @addtogroup BSP - * @{ - */ - -/** @addtogroup STM32G4XX_NUCLEO - * @{ - */ - -/** @defgroup STM32G4XX_NUCLEO_CONFIG Config - * @{ - */ - -/** @defgroup STM32C0XX_NUCLEO_CONFIG_Exported_Constants Exported Constants - * @{ - */ -/* Nucleo pin and part number defines */ -#define USE_STM32G4XX_NUCLEO - -/* COM define */ -#define USE_COM_LOG 1U -#define USE_BSP_COM_FEATURE 1U - -/* IRQ priorities */ -#define BSP_BUTTON_USER_IT_PRIORITY 15U - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* STM32G4XX_NUCLEO_CONF_H */ diff --git a/Nucleo-Blinky/Core/Src/gpio.c b/Nucleo-Blinky/Core/Src/gpio.c deleted file mode 100644 index 3a44fbc3e..000000000 --- a/Nucleo-Blinky/Core/Src/gpio.c +++ /dev/null @@ -1,55 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file gpio.c - * @brief This file provides code for the configuration - * of all used GPIO pins. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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 "gpio.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure GPIO */ -/*----------------------------------------------------------------------------*/ -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI -*/ -void MX_GPIO_Init(void) -{ - - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOF_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ diff --git a/Nucleo-Blinky/Core/Src/main.c b/Nucleo-Blinky/Core/Src/main.c deleted file mode 100644 index ab141cb7c..000000000 --- a/Nucleo-Blinky/Core/Src/main.c +++ /dev/null @@ -1,209 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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 "gpio.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* Private define ------------------------------------------------------------*/ -/* USER CODE BEGIN PD */ - -/* USER CODE END PD */ - -/* Private macro -------------------------------------------------------------*/ -/* USER CODE BEGIN PM */ - -/* USER CODE END PM */ - -/* Private variables ---------------------------------------------------------*/ - -COM_InitTypeDef BspCOMInit; - -/* USER CODE BEGIN PV */ - -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -void SystemClock_Config(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); - - /* USER CODE BEGIN Init */ - - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - /* USER CODE BEGIN 2 */ - - /* USER CODE END 2 */ - - /* Initialize led */ - BSP_LED_Init(LED_GREEN); - - /* Initialize USER push-button, will be used to trigger an interrupt each time it's pressed.*/ - BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI); - - /* Initialize COM1 port (115200, 8 bits (7-bit data + 1 stop bit), no parity */ - BspCOMInit.BaudRate = 115200; - BspCOMInit.WordLength = COM_WORDLENGTH_8B; - BspCOMInit.StopBits = COM_STOPBITS_1; - BspCOMInit.Parity = COM_PARITY_NONE; - BspCOMInit.HwFlowCtl = COM_HWCONTROL_NONE; - if (BSP_COM_Init(COM1, &BspCOMInit) != BSP_ERROR_NONE) - { - Error_Handler(); - } - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) - { - HAL_Delay(100); - /* USER CODE END WHILE */ - - /* USER CODE BEGIN 3 */ - HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin); - - if (BSP_PB_GetState(BUTTON_USER) == GPIO_PIN_SET) - { - HAL_Delay(10); - } - } - /* USER CODE END 3 */ -} - -/** - * @brief System Clock Configuration - * @retval None - */ -void SystemClock_Config(void) -{ - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - - /** Configure the main internal regulator output voltage - */ - HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST); - - /** Initializes the RCC Oscillators according to the specified parameters - * in the RCC_OscInitTypeDef structure. - */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; - RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; - RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4; - RCC_OscInitStruct.PLL.PLLN = 85; - RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; - RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; - RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) - { - Error_Handler(); - } - - /** Initializes the CPU, AHB and APB buses clocks - */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK - |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; - - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) - { - Error_Handler(); - } -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return state */ - __disable_irq(); - while (1) - { - } - /* USER CODE END Error_Handler_Debug */ -} -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line number, - ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ diff --git a/Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c b/Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c deleted file mode 100644 index d908bd772..000000000 --- a/Nucleo-Blinky/Core/Src/stm32g4xx_hal_msp.c +++ /dev/null @@ -1,85 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_msp.c - * @brief This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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*/ - - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); - - /* USER CODE BEGIN MspInit 1 */ - - /* USER CODE END MspInit 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/Nucleo-Blinky/Core/Src/stm32g4xx_it.c b/Nucleo-Blinky/Core/Src/stm32g4xx_it.c deleted file mode 100644 index f98aa5695..000000000 --- a/Nucleo-Blinky/Core/Src/stm32g4xx_it.c +++ /dev/null @@ -1,217 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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 "stm32g4xx_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 Prefetch 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 */ -} - -/******************************************************************************/ -/* STM32G4xx 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_stm32g4xx.s). */ -/******************************************************************************/ - -/** - * @brief This function handles EXTI line[15:10] interrupts. - */ -void EXTI15_10_IRQHandler(void) -{ - /* USER CODE BEGIN EXTI15_10_IRQn 0 */ - - /* USER CODE END EXTI15_10_IRQn 0 */ - BSP_PB_IRQHandler(BUTTON_USER); - /* USER CODE BEGIN EXTI15_10_IRQn 1 */ - - /* USER CODE END EXTI15_10_IRQn 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/Nucleo-Blinky/Nucleo-Blinky.ioc b/Nucleo-Blinky/Nucleo-Blinky.ioc deleted file mode 100644 index 1bc08b38e..000000000 --- a/Nucleo-Blinky/Nucleo-Blinky.ioc +++ /dev/null @@ -1,179 +0,0 @@ -#MicroXplorer Configuration settings - do not modify -BSP_IP_NAME=NUCLEO-G474RE -CAD.formats= -CAD.pinconfig= -CAD.provider= -File.Version=6 -KeepUserPlacement=false -Mcu.CPN=STM32G474RET6 -Mcu.Family=STM32G4 -Mcu.IP0=NUCLEO-G474RE -Mcu.IP1=NVIC -Mcu.IP2=RCC -Mcu.IP3=SYS -Mcu.IPNb=5 -Mcu.Name=STM32G474R(B-C-E)Tx -Mcu.Package=LQFP64 -Mcu.Pin0=PC13 -Mcu.Pin1=PC14-OSC32_IN -Mcu.Pin10=PB3 -Mcu.Pin11=VP_SYS_VS_Systick -Mcu.Pin12=VP_SYS_VS_DBSignals -Mcu.Pin13=VP_NUCLEO-G474RE_VS_BSP_COMMON -Mcu.Pin2=PC15-OSC32_OUT -Mcu.Pin3=PF0-OSC_IN -Mcu.Pin4=PF1-OSC_OUT -Mcu.Pin5=PA2 -Mcu.Pin6=PA3 -Mcu.Pin7=PA5 -Mcu.Pin8=PA13 -Mcu.Pin9=PA14 -Mcu.PinsNb=14 -Mcu.ThirdPartyNb=0 -Mcu.UserConstants= -Mcu.UserName=STM32G474RETx -MxCube.Version=6.18.0 -MxDb.Version=DB.6.0.180 -NUCLEO-G474RE.BUTTON=1 -NUCLEO-G474RE.IPParameters=BUTTON,LD2,VCP -NUCLEO-G474RE.LD2=true -NUCLEO-G474RE.VCP=true -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.EXTI15_10_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true -NVIC.ForceEnableDMAVector=true -NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 -NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:false -NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -PA13.GPIOParameters=GPIO_Label -PA13.GPIO_Label=T_SWDIO -PA13.Locked=true -PA13.Signal=SYS_JTMS-SWDIO -PA14.GPIOParameters=GPIO_Label -PA14.GPIO_Label=T_SWCLK -PA14.Locked=true -PA14.Signal=SYS_JTCK-SWCLK -PA2.Locked=true -PA2.Signal=LPUART1_TX -PA3.Locked=true -PA3.Signal=LPUART1_RX -PA5.Locked=true -PB3.GPIOParameters=GPIO_Label -PB3.GPIO_Label=T_SWO -PB3.Locked=true -PB3.Signal=SYS_JTDO-SWO -PC13.Locked=true -PC14-OSC32_IN.GPIOParameters=GPIO_Label -PC14-OSC32_IN.GPIO_Label=RCC_OSC32_IN -PC14-OSC32_IN.Locked=true -PC14-OSC32_IN.Signal=RCC_OSC32_IN -PC15-OSC32_OUT.GPIOParameters=GPIO_Label -PC15-OSC32_OUT.GPIO_Label=RCC_OSC32_OUT -PC15-OSC32_OUT.Locked=true -PC15-OSC32_OUT.Signal=RCC_OSC32_OUT -PF0-OSC_IN.GPIOParameters=GPIO_Label -PF0-OSC_IN.GPIO_Label=RCC_OSC_IN -PF0-OSC_IN.Locked=true -PF0-OSC_IN.Signal=RCC_OSC_IN -PF1-OSC_OUT.GPIOParameters=GPIO_Label -PF1-OSC_OUT.GPIO_Label=RCC_OSC_OUT -PF1-OSC_OUT.Locked=true -PF1-OSC_OUT.Signal=RCC_OSC_OUT -PinOutPanel.RotationAngle=0 -ProjectManager.AskForMigrate=true -ProjectManager.BackupPrevious=false -ProjectManager.CompilerLinker=GCC -ProjectManager.CompilerOptimize=6 -ProjectManager.ComputerToolchain=false -ProjectManager.CoupleFile=true -ProjectManager.CustomerFirmwarePackage= -ProjectManager.DefaultFWLocation=true -ProjectManager.DeletePrevious=true -ProjectManager.DeviceId=STM32G474RETx -ProjectManager.FirmwarePackage=STM32Cube FW_G4 V1.6.3 -ProjectManager.FreePins=false -ProjectManager.FreePinsContext= -ProjectManager.HalAssertFull=true -ProjectManager.HeapSize=0x200 -ProjectManager.KeepUserCode=true -ProjectManager.LastFirmware=true -ProjectManager.LibraryCopy=2 -ProjectManager.MainLocation=Core/Src -ProjectManager.NoMain=false -ProjectManager.PreviousToolchain= -ProjectManager.ProjectBuild=false -ProjectManager.ProjectFileName=Nucleo-Blinky.ioc -ProjectManager.ProjectName=Nucleo-Blinky -ProjectManager.ProjectStructure= -ProjectManager.RegisterCallBack= -ProjectManager.StackSize=0x400 -ProjectManager.TargetToolchain=EWARM V8.50 -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,false-0--NUCLEO-G474RE-true-HAL-true -RCC.ADC12Freq_Value=170000000 -RCC.ADC345Freq_Value=170000000 -RCC.AHBFreq_Value=170000000 -RCC.APB1Freq_Value=170000000 -RCC.APB1TimFreq_Value=170000000 -RCC.APB2Freq_Value=170000000 -RCC.APB2TimFreq_Value=170000000 -RCC.CRSFreq_Value=48000000 -RCC.CortexFreq_Value=170000000 -RCC.EXTERNAL_CLOCK_VALUE=12288000 -RCC.FCLKCortexFreq_Value=170000000 -RCC.FDCANFreq_Value=170000000 -RCC.FamilyName=M -RCC.HCLKFreq_Value=170000000 -RCC.HRTIM1Freq_Value=170000000 -RCC.HSE_VALUE=24000000 -RCC.HSI48_VALUE=48000000 -RCC.HSI_VALUE=16000000 -RCC.I2C1Freq_Value=170000000 -RCC.I2C2Freq_Value=170000000 -RCC.I2C3Freq_Value=170000000 -RCC.I2C4Freq_Value=170000000 -RCC.I2SFreq_Value=170000000 -RCC.IPParameters=ADC12Freq_Value,ADC345Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HRTIM1Freq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,PLLM,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PWRFreq_Value,QSPIFreq_Value,RNGFreq_Value,RTCClockSelection,RTCFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value -RCC.LPTIM1Freq_Value=170000000 -RCC.LPUART1Freq_Value=170000000 -RCC.LSCOPinFreq_Value=32000 -RCC.LSE_VALUE=32768 -RCC.LSI_VALUE=32000 -RCC.MCO1PinFreq_Value=16000000 -RCC.PLLM=RCC_PLLM_DIV4 -RCC.PLLN=85 -RCC.PLLPoutputFreq_Value=170000000 -RCC.PLLQoutputFreq_Value=170000000 -RCC.PLLRCLKFreq_Value=170000000 -RCC.PWRFreq_Value=170000000 -RCC.QSPIFreq_Value=170000000 -RCC.RNGFreq_Value=170000000 -RCC.RTCClockSelection=RCC_RTCCLKSOURCE_LSE -RCC.RTCFreq_Value=32768 -RCC.SAI1Freq_Value=170000000 -RCC.SYSCLKFreq_VALUE=170000000 -RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK -RCC.UART4Freq_Value=170000000 -RCC.UART5Freq_Value=170000000 -RCC.USART1Freq_Value=170000000 -RCC.USART2Freq_Value=170000000 -RCC.USART3Freq_Value=170000000 -RCC.USBFreq_Value=170000000 -RCC.VCOInputFreq_Value=4000000 -RCC.VCOOutputFreq_Value=340000000 -VP_NUCLEO-G474RE_VS_BSP_COMMON.Mode=COMMON -VP_NUCLEO-G474RE_VS_BSP_COMMON.Signal=NUCLEO-G474RE_VS_BSP_COMMON -VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals -VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick -board=NUCLEO-G474RE -boardIOC=true From a9597c7dd9d9a26994ade2092bdbfa5422744448 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 9 Jul 2026 22:13:05 -0700 Subject: [PATCH 006/125] Initial skeleton commit Signed-off-by: Daniel Hansen --- CMakeLists.txt | 1 + Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h | 6 ++++++ Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h | 6 ++++++ Lib/Peripherals/CubeCAN/Src/can_clock.c | 0 Lib/Peripherals/CubeCAN/Src/can_it.c | 0 Lib/Peripherals/CubeCAN/Src/can_utils.c | 0 Lib/Peripherals/CubeCAN/cubemx_can.cmake | 17 +++++++++++++++++ 7 files changed, 30 insertions(+) create mode 100644 Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h create mode 100644 Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h create mode 100644 Lib/Peripherals/CubeCAN/Src/can_clock.c create mode 100644 Lib/Peripherals/CubeCAN/Src/can_it.c create mode 100644 Lib/Peripherals/CubeCAN/Src/can_utils.c create mode 100644 Lib/Peripherals/CubeCAN/cubemx_can.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index dd6d899d4..c729556c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,6 +142,7 @@ include("Autogen/CAN/CANfigurator.cmake") include("${lib_path}/Peripherals/USART/common.cmake") include("${lib_path}/Peripherals/TimedCAN/common.cmake") include("${lib_path}/Peripherals/CAN/common.cmake") +include("${lib_path}/Peripherals/CubeCAN/cubemx_can.cmake") include("${lib_path}/FancyLayers-RENAME/GRCAN/grcan_fancylayer.cmake") include("${lib_path}/FancyLayers-RENAME/ADC/adc.cmake") diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h new file mode 100644 index 000000000..0bac3f962 --- /dev/null +++ b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h @@ -0,0 +1,6 @@ +#ifndef CUBEMX_CAN_H +#define CUBEMX_CAN_H + +// TODO + +#endif diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h b/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h new file mode 100644 index 000000000..2b6c3c544 --- /dev/null +++ b/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h @@ -0,0 +1,6 @@ +#ifndef CUBEMX_CAN_EXT_H +#define CUBEMX_CAN_EXT_H + +// TODO + +#endif diff --git a/Lib/Peripherals/CubeCAN/Src/can_clock.c b/Lib/Peripherals/CubeCAN/Src/can_clock.c new file mode 100644 index 000000000..e69de29bb diff --git a/Lib/Peripherals/CubeCAN/Src/can_it.c b/Lib/Peripherals/CubeCAN/Src/can_it.c new file mode 100644 index 000000000..e69de29bb diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c new file mode 100644 index 000000000..e69de29bb diff --git a/Lib/Peripherals/CubeCAN/cubemx_can.cmake b/Lib/Peripherals/CubeCAN/cubemx_can.cmake new file mode 100644 index 000000000..ab7d9470e --- /dev/null +++ b/Lib/Peripherals/CubeCAN/cubemx_can.cmake @@ -0,0 +1,17 @@ +add_library(CUBEMX_CAN_LIB INTERFACE) + +target_include_directories( + CUBEMX_CAN_LIB + INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/Inc +) + +target_sources( + CUBEMX_CAN_LIB + INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/Src/can_it.c + ${CMAKE_CURRENT_LIST_DIR}/Src/can_clock.c + ${CMAKE_CURRENT_LIST_DIR}/Src/can_utils.c +) + +# TODO Unit testing From cd91db0c023923f17d06f699c9aefd1afd45108a Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 9 Jul 2026 23:21:21 -0700 Subject: [PATCH 007/125] Completely random test project Signed-off-by: Daniel Hansen --- CMakeLists.txt | 1 + CUBEMXTESTING/Application/Inc/loop.h | 6 + CUBEMXTESTING/Application/Inc/vcp_config.h | 8 + CUBEMXTESTING/Application/Src/loop.c | 17 + CUBEMXTESTING/CMakeLists.txt | 43 +++ CUBEMXTESTING/CUBEMXTESTING.ioc | 175 +++++++++ CUBEMXTESTING/Core/Inc/fdcan.h | 55 +++ CUBEMXTESTING/Core/Inc/gpio.h | 49 +++ CUBEMXTESTING/Core/Inc/main.h | 84 +++++ CUBEMXTESTING/Core/Inc/stm32_assert.h | 53 +++ CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 380 ++++++++++++++++++++ CUBEMXTESTING/Core/Inc/stm32g4xx_it.h | 66 ++++ CUBEMXTESTING/Core/Src/fdcan.c | 224 ++++++++++++ CUBEMXTESTING/Core/Src/gpio.c | 347 ++++++++++++++++++ CUBEMXTESTING/Core/Src/main.c | 209 +++++++++++ CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 203 +++++++++++ 16 files changed, 1920 insertions(+) create mode 100644 CUBEMXTESTING/Application/Inc/loop.h create mode 100644 CUBEMXTESTING/Application/Inc/vcp_config.h create mode 100644 CUBEMXTESTING/Application/Src/loop.c create mode 100644 CUBEMXTESTING/CMakeLists.txt create mode 100644 CUBEMXTESTING/CUBEMXTESTING.ioc create mode 100644 CUBEMXTESTING/Core/Inc/fdcan.h create mode 100644 CUBEMXTESTING/Core/Inc/gpio.h create mode 100644 CUBEMXTESTING/Core/Inc/main.h create mode 100644 CUBEMXTESTING/Core/Inc/stm32_assert.h create mode 100644 CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h create mode 100644 CUBEMXTESTING/Core/Inc/stm32g4xx_it.h create mode 100644 CUBEMXTESTING/Core/Src/fdcan.c create mode 100644 CUBEMXTESTING/Core/Src/gpio.c create mode 100644 CUBEMXTESTING/Core/Src/main.c create mode 100644 CUBEMXTESTING/Core/Src/stm32g4xx_it.c diff --git a/CMakeLists.txt b/CMakeLists.txt index c729556c6..86537662b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -162,6 +162,7 @@ add_gr_project(STM32G474xE G4PERTESTING) add_gr_project(STM32G474xE G4SPITESTING) add_gr_project(STM32G474xE G4ADCTESTING) add_gr_project(STM32G474xE G4NEOTESTING) +add_gr_project(STM32G474xE CUBEMXTESTING) # CAN Peripheral Testing add_gr_project(STM32G474xE G474xE_CAN_TESTING CAN_BASIC_TEST) diff --git a/CUBEMXTESTING/Application/Inc/loop.h b/CUBEMXTESTING/Application/Inc/loop.h new file mode 100644 index 000000000..4b447f829 --- /dev/null +++ b/CUBEMXTESTING/Application/Inc/loop.h @@ -0,0 +1,6 @@ +#ifndef LOOP_H +#define LOOP_H + +void MainLoop(void); + +#endif diff --git a/CUBEMXTESTING/Application/Inc/vcp_config.h b/CUBEMXTESTING/Application/Inc/vcp_config.h new file mode 100644 index 000000000..77a62a7f7 --- /dev/null +++ b/CUBEMXTESTING/Application/Inc/vcp_config.h @@ -0,0 +1,8 @@ +#ifndef VCP_CONFIG +#define VCP_CONFIG + +#define VCP_CONFIG_CLAIM_USART2 + +#define VCP_TX_BUFFER_SIZE 128 + +#endif diff --git a/CUBEMXTESTING/Application/Src/loop.c b/CUBEMXTESTING/Application/Src/loop.c new file mode 100644 index 000000000..5e1d17751 --- /dev/null +++ b/CUBEMXTESTING/Application/Src/loop.c @@ -0,0 +1,17 @@ +#include "loop.h" + +#include "Logomatic.h" +#include "main.h" + +void MainLoop(void) +{ + LL_GPIO_TogglePin(USER_LED_GPIO_Port, USER_LED_Pin); + + if (LL_GPIO_IsInputPinSet(USER_BUTTON_GPIO_Port, USER_BUTTON_Pin)) { + LL_GPIO_SetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + } else { + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + } + + LOGOMATIC("Doing things!\n"); +} diff --git a/CUBEMXTESTING/CMakeLists.txt b/CUBEMXTESTING/CMakeLists.txt new file mode 100644 index 000000000..7b5232e56 --- /dev/null +++ b/CUBEMXTESTING/CMakeLists.txt @@ -0,0 +1,43 @@ +cmake_minimum_required(VERSION 3.25) + +# Setup compiler settings +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS ON) + +# Define the build type +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug") +endif() + +# Enable CMake support for ASM and C languages +enable_language( + C + ASM +) + +# Core project settings +project(${CMAKE_PROJECT_NAME}) + +# what, does in fact not get the filename of somthing but rather the name of the project from the path +get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) + +add_library(${PROJECT_NAME}_USER_CODE INTERFACE) +target_sources( + ${PROJECT_NAME}_USER_CODE + INTERFACE + Application/Src/loop.c + Core/Src/fdcan.c + Core/Src/gpio.c + Core/Src/main.c + Core/Src/stm32g4xx_it.c +) + +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE VCP_LIB) + +target_include_directories( + ${PROJECT_NAME}_USER_CODE + INTERFACE + Core/Inc + Application/Inc +) diff --git a/CUBEMXTESTING/CUBEMXTESTING.ioc b/CUBEMXTESTING/CUBEMXTESTING.ioc new file mode 100644 index 000000000..be9a705f8 --- /dev/null +++ b/CUBEMXTESTING/CUBEMXTESTING.ioc @@ -0,0 +1,175 @@ +#MicroXplorer Configuration settings - do not modify +CAD.formats=[] +CAD.pinconfig=Dual +CAD.provider= +FDCAN1.AutoRetransmission=ENABLE +FDCAN1.CalculateBaudRateNominal=1000000 +FDCAN1.CalculateTimeBitNominal=1000 +FDCAN1.CalculateTimeQuantumNominal=6.25 +FDCAN1.DataPrescaler=8 +FDCAN1.DataSyncJumpWidth=16 +FDCAN1.DataTimeSeg1=14 +FDCAN1.DataTimeSeg2=5 +FDCAN1.ExtFiltersNbr=2 +FDCAN1.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal,NominalSyncJumpWidth,AutoRetransmission,ProtocolException,DataPrescaler,DataSyncJumpWidth,DataTimeSeg1,DataTimeSeg2,ExtFiltersNbr,NominalPrescaler,NominalTimeSeg1,NominalTimeSeg2 +FDCAN1.NominalPrescaler=1 +FDCAN1.NominalSyncJumpWidth=16 +FDCAN1.NominalTimeSeg1=119 +FDCAN1.NominalTimeSeg2=40 +FDCAN1.ProtocolException=ENABLE +FDCAN2.AutoRetransmission=ENABLE +FDCAN2.CalculateBaudRateNominal=1000000 +FDCAN2.CalculateTimeBitNominal=1000 +FDCAN2.CalculateTimeQuantumNominal=6.25 +FDCAN2.DataPrescaler=8 +FDCAN2.DataSyncJumpWidth=16 +FDCAN2.DataTimeSeg1=14 +FDCAN2.DataTimeSeg2=5 +FDCAN2.ExtFiltersNbr=2 +FDCAN2.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal,AutoRetransmission,ProtocolException,NominalSyncJumpWidth,DataPrescaler,DataSyncJumpWidth,DataTimeSeg1,DataTimeSeg2,ExtFiltersNbr,NominalPrescaler,NominalTimeSeg1,NominalTimeSeg2 +FDCAN2.NominalPrescaler=1 +FDCAN2.NominalSyncJumpWidth=16 +FDCAN2.NominalTimeSeg1=119 +FDCAN2.NominalTimeSeg2=40 +FDCAN2.ProtocolException=ENABLE +File.Version=6 +GPIO.groupedBy=Group By Peripherals +KeepUserPlacement=false +Mcu.CPN=STM32G474RET6 +Mcu.Family=STM32G4 +Mcu.IP0=FDCAN1 +Mcu.IP1=FDCAN2 +Mcu.IP2=NVIC +Mcu.IP3=RCC +Mcu.IP4=SYS +Mcu.IPNb=5 +Mcu.Name=STM32G474R(B-C-E)Tx +Mcu.Package=LQFP64 +Mcu.Pin0=PC13 +Mcu.Pin1=PA5 +Mcu.Pin2=PB12 +Mcu.Pin3=PB13 +Mcu.Pin4=PB8-BOOT0 +Mcu.Pin5=PB9 +Mcu.Pin6=VP_SYS_VS_Systick +Mcu.Pin7=VP_SYS_VS_DBSignals +Mcu.PinsNb=8 +Mcu.ThirdPartyNb=0 +Mcu.UserConstants= +Mcu.UserName=STM32G474RETx +MxCube.Version=6.18.0 +MxDb.Version=DB.6.0.180 +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=false +NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 +NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false +NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +PA5.GPIOParameters=GPIO_Label +PA5.GPIO_Label=USER_LED +PA5.Locked=true +PA5.Signal=GPIO_Output +PB12.Mode=FDCAN_Activate +PB12.Signal=FDCAN2_RX +PB13.Mode=FDCAN_Activate +PB13.Signal=FDCAN2_TX +PB8-BOOT0.Mode=FDCAN_Activate +PB8-BOOT0.Signal=FDCAN1_RX +PB9.Mode=FDCAN_Activate +PB9.Signal=FDCAN1_TX +PC13.GPIOParameters=GPIO_Label +PC13.GPIO_Label=USER_BUTTON +PC13.Locked=true +PC13.Signal=GPIO_Input +PinOutPanel.RotationAngle=0 +ProjectManager.AskForMigrate=true +ProjectManager.BackupPrevious=false +ProjectManager.CompilerLinker=GCC +ProjectManager.CompilerOptimize=6 +ProjectManager.ComputerToolchain=false +ProjectManager.CoupleFile=true +ProjectManager.CustomerFirmwarePackage= +ProjectManager.DefaultFWLocation=true +ProjectManager.DeletePrevious=true +ProjectManager.DeviceId=STM32G474RETx +ProjectManager.FirmwarePackage=STM32Cube FW_G4 V1.6.3 +ProjectManager.FreePins=true +ProjectManager.FreePinsContext= +ProjectManager.HalAssertFull=true +ProjectManager.HeapSize=0x200 +ProjectManager.KeepUserCode=true +ProjectManager.LastFirmware=true +ProjectManager.LibraryCopy=2 +ProjectManager.MainLocation=Core/Src +ProjectManager.NoMain=false +ProjectManager.PreviousToolchain= +ProjectManager.ProjectBuild=false +ProjectManager.ProjectFileName=CUBEMXTESTING.ioc +ProjectManager.ProjectName=CUBEMXTESTING +ProjectManager.ProjectStructure= +ProjectManager.RegisterCallBack= +ProjectManager.StackSize=0x400 +ProjectManager.TargetToolchain=EWARM V8.50 +ProjectManager.ToolChainLocation= +ProjectManager.UAScriptAfterPath= +ProjectManager.UAScriptBeforePath= +ProjectManager.UnderRoot=false +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true +RCC.ADC12Freq_Value=160000000 +RCC.ADC345Freq_Value=160000000 +RCC.AHBFreq_Value=160000000 +RCC.APB1Freq_Value=160000000 +RCC.APB1TimFreq_Value=160000000 +RCC.APB2Freq_Value=160000000 +RCC.APB2TimFreq_Value=160000000 +RCC.CRSFreq_Value=48000000 +RCC.CortexFreq_Value=160000000 +RCC.EXTERNAL_CLOCK_VALUE=12288000 +RCC.FCLKCortexFreq_Value=160000000 +RCC.FDCANFreq_Value=160000000 +RCC.FamilyName=M +RCC.HCLKFreq_Value=160000000 +RCC.HRTIM1Freq_Value=160000000 +RCC.HSE_VALUE=16000000 +RCC.HSI48_VALUE=48000000 +RCC.HSI_VALUE=16000000 +RCC.I2C1Freq_Value=160000000 +RCC.I2C2Freq_Value=160000000 +RCC.I2C3Freq_Value=160000000 +RCC.I2C4Freq_Value=160000000 +RCC.I2SFreq_Value=160000000 +RCC.IPParameters=ADC12Freq_Value,ADC345Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HRTIM1Freq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PWRFreq_Value,QSPIFreq_Value,RNGFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value +RCC.LPTIM1Freq_Value=160000000 +RCC.LPUART1Freq_Value=160000000 +RCC.LSCOPinFreq_Value=32000 +RCC.LSE_VALUE=32768 +RCC.LSI_VALUE=32000 +RCC.MCO1PinFreq_Value=16000000 +RCC.PLLN=20 +RCC.PLLPoutputFreq_Value=160000000 +RCC.PLLQoutputFreq_Value=160000000 +RCC.PLLRCLKFreq_Value=160000000 +RCC.PWRFreq_Value=160000000 +RCC.QSPIFreq_Value=160000000 +RCC.RNGFreq_Value=160000000 +RCC.SAI1Freq_Value=160000000 +RCC.SYSCLKFreq_VALUE=160000000 +RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK +RCC.UART4Freq_Value=160000000 +RCC.UART5Freq_Value=160000000 +RCC.USART1Freq_Value=160000000 +RCC.USART2Freq_Value=160000000 +RCC.USART3Freq_Value=160000000 +RCC.USBFreq_Value=160000000 +RCC.VCOInputFreq_Value=16000000 +RCC.VCOOutputFreq_Value=320000000 +VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals +VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals +VP_SYS_VS_Systick.Mode=SysTick +VP_SYS_VS_Systick.Signal=SYS_VS_Systick +board=custom diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h new file mode 100644 index 000000000..b0fa74968 --- /dev/null +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -0,0 +1,55 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file fdcan.h + * @brief This file contains all the function prototypes for + * the fdcan.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 __FDCAN_H__ +#define __FDCAN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern FDCAN_HandleTypeDef hfdcan1; + +extern FDCAN_HandleTypeDef hfdcan2; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_FDCAN1_Init(void); +void MX_FDCAN2_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __FDCAN_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h new file mode 100644 index 000000000..3c91c4dd6 --- /dev/null +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -0,0 +1,49 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file gpio.h + * @brief This file contains all the function prototypes for + * the gpio.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 __GPIO_H__ +#define __GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_GPIO_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif +#endif /*__ GPIO_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h new file mode 100644 index 000000000..3a736d114 --- /dev/null +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -0,0 +1,84 @@ +/* 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) 2026 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 "stm32g4xx_hal.h" + +#include "stm32g4xx_ll_rcc.h" +#include "stm32g4xx_ll_bus.h" +#include "stm32g4xx_ll_crs.h" +#include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_exti.h" +#include "stm32g4xx_ll_cortex.h" +#include "stm32g4xx_ll_utils.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_gpio.h" + +/* 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 Error_Handler(void); + +/* USER CODE BEGIN EFP */ + +/* USER CODE END EFP */ + +/* Private defines -----------------------------------------------------------*/ +#define USER_BUTTON_Pin LL_GPIO_PIN_13 +#define USER_BUTTON_GPIO_Port GPIOC +#define USER_LED_Pin LL_GPIO_PIN_5 +#define USER_LED_GPIO_Port GPIOA + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H */ diff --git a/CUBEMXTESTING/Core/Inc/stm32_assert.h b/CUBEMXTESTING/Core/Inc/stm32_assert.h new file mode 100644 index 000000000..61631c41e --- /dev/null +++ b/CUBEMXTESTING/Core/Inc/stm32_assert.h @@ -0,0 +1,53 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32_assert.h + * @author MCD Application Team + * @brief STM32 assert file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2019 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 __STM32_ASSERT_H +#define __STM32_ASSERT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Includes ------------------------------------------------------------------*/ +/* 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 /* __STM32_ASSERT_H */ + diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h new file mode 100644 index 000000000..16ef7e356 --- /dev/null +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -0,0 +1,380 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g4xx_hal_conf.h + * @author MCD Application Team + * @brief HAL configuration file + ****************************************************************************** + * @attention + * + * Copyright (c) 2019 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 STM32G4xx_HAL_CONF_H +#define STM32G4xx_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_ADC_MODULE_ENABLED */ +/*#define HAL_COMP_MODULE_ENABLED */ +/*#define HAL_CORDIC_MODULE_ENABLED */ +/*#define HAL_CRC_MODULE_ENABLED */ +/*#define HAL_CRYP_MODULE_ENABLED */ +/*#define HAL_DAC_MODULE_ENABLED */ +#define HAL_FDCAN_MODULE_ENABLED +/*#define HAL_FMAC_MODULE_ENABLED */ +/*#define HAL_HRTIM_MODULE_ENABLED */ +/*#define HAL_IRDA_MODULE_ENABLED */ +/*#define HAL_IWDG_MODULE_ENABLED */ +/*#define HAL_I2C_MODULE_ENABLED */ +/*#define HAL_I2S_MODULE_ENABLED */ +/*#define HAL_LPTIM_MODULE_ENABLED */ +/*#define HAL_NAND_MODULE_ENABLED */ +/*#define HAL_NOR_MODULE_ENABLED */ +/*#define HAL_OPAMP_MODULE_ENABLED */ +/*#define HAL_PCD_MODULE_ENABLED */ +/*#define HAL_QSPI_MODULE_ENABLED */ +/*#define HAL_RNG_MODULE_ENABLED */ +/*#define HAL_RTC_MODULE_ENABLED */ +/*#define HAL_SAI_MODULE_ENABLED */ +/*#define HAL_SMARTCARD_MODULE_ENABLED */ +/*#define HAL_SMBUS_MODULE_ENABLED */ +/*#define HAL_SPI_MODULE_ENABLED */ +/*#define HAL_SRAM_MODULE_ENABLED */ +/*#define HAL_TIM_MODULE_ENABLED */ +/*#define HAL_UART_MODULE_ENABLED */ +/*#define HAL_USART_MODULE_ENABLED */ +/*#define HAL_WWDG_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 + +/* ########################## Register Callbacks selection ############################## */ +/** + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + +/* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ + +/** + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined (HSI48_VALUE) + #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ + +/** + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) +/*!< Value of the Internal Low Speed oscillator in Hz +The real value may vary depending on the variations in voltage and temperature.*/ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ +/** + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ + +#if !defined (LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ + +/** + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U + +/* ########################## Assert Selection ############################## */ +/** + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ + #define USE_FULL_ASSERT 1U + +/* ################## 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 "stm32g4xx_hal_rcc.h" +#endif /* HAL_RCC_MODULE_ENABLED */ + +#ifdef HAL_GPIO_MODULE_ENABLED +#include "stm32g4xx_hal_gpio.h" +#endif /* HAL_GPIO_MODULE_ENABLED */ + +#ifdef HAL_DMA_MODULE_ENABLED +#include "stm32g4xx_hal_dma.h" +#endif /* HAL_DMA_MODULE_ENABLED */ + +#ifdef HAL_CORTEX_MODULE_ENABLED +#include "stm32g4xx_hal_cortex.h" +#endif /* HAL_CORTEX_MODULE_ENABLED */ + +#ifdef HAL_ADC_MODULE_ENABLED +#include "stm32g4xx_hal_adc.h" +#endif /* HAL_ADC_MODULE_ENABLED */ + +#ifdef HAL_COMP_MODULE_ENABLED +#include "stm32g4xx_hal_comp.h" +#endif /* HAL_COMP_MODULE_ENABLED */ + +#ifdef HAL_CORDIC_MODULE_ENABLED +#include "stm32g4xx_hal_cordic.h" +#endif /* HAL_CORDIC_MODULE_ENABLED */ + +#ifdef HAL_CRC_MODULE_ENABLED +#include "stm32g4xx_hal_crc.h" +#endif /* HAL_CRC_MODULE_ENABLED */ + +#ifdef HAL_CRYP_MODULE_ENABLED +#include "stm32g4xx_hal_cryp.h" +#endif /* HAL_CRYP_MODULE_ENABLED */ + +#ifdef HAL_DAC_MODULE_ENABLED +#include "stm32g4xx_hal_dac.h" +#endif /* HAL_DAC_MODULE_ENABLED */ + +#ifdef HAL_EXTI_MODULE_ENABLED +#include "stm32g4xx_hal_exti.h" +#endif /* HAL_EXTI_MODULE_ENABLED */ + +#ifdef HAL_FDCAN_MODULE_ENABLED +#include "stm32g4xx_hal_fdcan.h" +#endif /* HAL_FDCAN_MODULE_ENABLED */ + +#ifdef HAL_FLASH_MODULE_ENABLED +#include "stm32g4xx_hal_flash.h" +#endif /* HAL_FLASH_MODULE_ENABLED */ + +#ifdef HAL_FMAC_MODULE_ENABLED +#include "stm32g4xx_hal_fmac.h" +#endif /* HAL_FMAC_MODULE_ENABLED */ + +#ifdef HAL_HRTIM_MODULE_ENABLED +#include "stm32g4xx_hal_hrtim.h" +#endif /* HAL_HRTIM_MODULE_ENABLED */ + +#ifdef HAL_IRDA_MODULE_ENABLED +#include "stm32g4xx_hal_irda.h" +#endif /* HAL_IRDA_MODULE_ENABLED */ + +#ifdef HAL_IWDG_MODULE_ENABLED +#include "stm32g4xx_hal_iwdg.h" +#endif /* HAL_IWDG_MODULE_ENABLED */ + +#ifdef HAL_I2C_MODULE_ENABLED +#include "stm32g4xx_hal_i2c.h" +#endif /* HAL_I2C_MODULE_ENABLED */ + +#ifdef HAL_I2S_MODULE_ENABLED +#include "stm32g4xx_hal_i2s.h" +#endif /* HAL_I2S_MODULE_ENABLED */ + +#ifdef HAL_LPTIM_MODULE_ENABLED +#include "stm32g4xx_hal_lptim.h" +#endif /* HAL_LPTIM_MODULE_ENABLED */ + +#ifdef HAL_NAND_MODULE_ENABLED +#include "stm32g4xx_hal_nand.h" +#endif /* HAL_NAND_MODULE_ENABLED */ + +#ifdef HAL_NOR_MODULE_ENABLED +#include "stm32g4xx_hal_nor.h" +#endif /* HAL_NOR_MODULE_ENABLED */ + +#ifdef HAL_OPAMP_MODULE_ENABLED +#include "stm32g4xx_hal_opamp.h" +#endif /* HAL_OPAMP_MODULE_ENABLED */ + +#ifdef HAL_PCD_MODULE_ENABLED +#include "stm32g4xx_hal_pcd.h" +#endif /* HAL_PCD_MODULE_ENABLED */ + +#ifdef HAL_PWR_MODULE_ENABLED +#include "stm32g4xx_hal_pwr.h" +#endif /* HAL_PWR_MODULE_ENABLED */ + +#ifdef HAL_QSPI_MODULE_ENABLED +#include "stm32g4xx_hal_qspi.h" +#endif /* HAL_QSPI_MODULE_ENABLED */ + +#ifdef HAL_RNG_MODULE_ENABLED +#include "stm32g4xx_hal_rng.h" +#endif /* HAL_RNG_MODULE_ENABLED */ + +#ifdef HAL_RTC_MODULE_ENABLED +#include "stm32g4xx_hal_rtc.h" +#endif /* HAL_RTC_MODULE_ENABLED */ + +#ifdef HAL_SAI_MODULE_ENABLED +#include "stm32g4xx_hal_sai.h" +#endif /* HAL_SAI_MODULE_ENABLED */ + +#ifdef HAL_SMARTCARD_MODULE_ENABLED +#include "stm32g4xx_hal_smartcard.h" +#endif /* HAL_SMARTCARD_MODULE_ENABLED */ + +#ifdef HAL_SMBUS_MODULE_ENABLED +#include "stm32g4xx_hal_smbus.h" +#endif /* HAL_SMBUS_MODULE_ENABLED */ + +#ifdef HAL_SPI_MODULE_ENABLED +#include "stm32g4xx_hal_spi.h" +#endif /* HAL_SPI_MODULE_ENABLED */ + +#ifdef HAL_SRAM_MODULE_ENABLED +#include "stm32g4xx_hal_sram.h" +#endif /* HAL_SRAM_MODULE_ENABLED */ + +#ifdef HAL_TIM_MODULE_ENABLED +#include "stm32g4xx_hal_tim.h" +#endif /* HAL_TIM_MODULE_ENABLED */ + +#ifdef HAL_UART_MODULE_ENABLED +#include "stm32g4xx_hal_uart.h" +#endif /* HAL_UART_MODULE_ENABLED */ + +#ifdef HAL_USART_MODULE_ENABLED +#include "stm32g4xx_hal_usart.h" +#endif /* HAL_USART_MODULE_ENABLED */ + +#ifdef HAL_WWDG_MODULE_ENABLED +#include "stm32g4xx_hal_wwdg.h" +#endif /* HAL_WWDG_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 /* STM32G4xx_HAL_CONF_H */ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h new file mode 100644 index 000000000..1a144ad22 --- /dev/null +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h @@ -0,0 +1,66 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g4xx_it.h + * @brief This file contains the headers of the interrupt handlers. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 __STM32G4xx_IT_H +#define __STM32G4xx_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 /* __STM32G4xx_IT_H */ diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c new file mode 100644 index 000000000..a1e13a2e8 --- /dev/null +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -0,0 +1,224 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file fdcan.c + * @brief This file provides code for the configuration + * of the FDCAN instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "fdcan.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +FDCAN_HandleTypeDef hfdcan1; +FDCAN_HandleTypeDef hfdcan2; + +/* FDCAN1 init function */ +void MX_FDCAN1_Init(void) +{ + + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_NORMAL; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ + +} +/* FDCAN2 init function */ +void MX_FDCAN2_Init(void) +{ + + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_NORMAL; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ + +} + +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; + +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } +} + +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) +{ + + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); + + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); + + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c new file mode 100644 index 000000000..09690886a --- /dev/null +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -0,0 +1,347 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file gpio.c + * @brief This file provides code for the configuration + * of all used GPIO pins. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "gpio.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/*----------------------------------------------------------------------------*/ +/* Configure GPIO */ +/*----------------------------------------------------------------------------*/ +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + +/** Configure pins +*/ +void MX_GPIO_Init(void) +{ + + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_13; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + +} + +/* USER CODE BEGIN 2 */ + +/* USER CODE END 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c new file mode 100644 index 000000000..0491c7152 --- /dev/null +++ b/CUBEMXTESTING/Core/Src/main.c @@ -0,0 +1,209 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.c + * @brief : Main program body + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "fdcan.h" +#include "gpio.h" + +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ +#include "Logomatic.h" +#include "loop.h" +#include "vcp.h" +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN PTD */ + +/* USER CODE END PTD */ + +/* 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 */ +LogomaticConfig logomaticConfig = {.clock_source = LOGOMATIC_PCLK1, + .bus = LOGOMATIC_BUS, + .gpio_port = LOGOMATIC_GPIOA, + .gpio_pin_rx_tx_mask = LL_GPIO_PIN_9 | LL_GPIO_PIN_10, + .baud_rate = 115200, + .data_width = LOGOMATIC_DATAWIDTH_8B, + .stop_bits = LOGOMATIC_STOPBITS_1, + .parity = LOGOMATIC_PARITY_NONE, + .transfer_direction = LOGOMATIC_DIRECTION_TX, + .hardware_flow_control = LOGOMATIC_HWCONTROL_NONE, + .prescaler = LOGOMATIC_PRESCALER_DIV1, + .tx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8, + .rx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8}; + +VCP_Config vcp_config = {.baud_rate = 2000000, + .clock_source = VCP_CLOCK_PCLK, + .gpio_tx_rx_pin_mask = LL_GPIO_PIN_2 | LL_GPIO_PIN_3, + .bus_port = VCP_Port_A, + .parity = VCP_Parity_None, + .prescaler = VCP_Prescalar_Div2, + .stop_bits = VCP_StopBits_1, + .oversampling = VCP_Oversampling_16, + .tx_fifo_threshold = VCP_Threshold_1_8, + .rx_fifo_threshold = VCP_Threshold_1_8, + .alternate_function = LL_GPIO_AF_7, + .rx_callback = NULL}; +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +void SystemClock_Config(void); +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* Private user code ---------------------------------------------------------*/ +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/** + * @brief The application entry point. + * @retval int + */ +int main(void) +{ + + /* USER CODE BEGIN 1 */ + + /* USER CODE END 1 */ + + /* MCU Configuration--------------------------------------------------------*/ + + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); + + /* USER CODE BEGIN Init */ + + /* USER CODE END Init */ + + /* Configure the system clock */ + SystemClock_Config(); + + /* USER CODE BEGIN SysInit */ + + /* USER CODE END SysInit */ + + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + /* USER CODE BEGIN 2 */ + Logomatic_Init(&logomaticConfig); + VCP_Init(&vcp_config); + /* USER CODE END 2 */ + + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ + LOGOMATIC("Hello World!\n"); + while (1) { + /* USER CODE END WHILE */ + MainLoop(); + LL_mDelay(500); + /* USER CODE BEGIN 3 */ + } + /* USER CODE END 3 */ +} + +/** + * @brief System Clock Configuration + * @retval None + */ +void SystemClock_Config(void) +{ + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while (LL_RCC_HSI_IsReady() != 1) {} + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while (LL_RCC_PLL_IsReady() != 1) {} + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i != 0; i--) + ; + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { + Error_Handler(); + } +} + +/* USER CODE BEGIN 4 */ + +/* USER CODE END 4 */ + +/** + * @brief This function is executed in case of error occurrence. + * @retval None + */ +void Error_Handler(void) +{ + /* USER CODE BEGIN Error_Handler_Debug */ + /* User can add his own implementation to report the HAL error return state */ + __disable_irq(); + while (1) {} + /* USER CODE END Error_Handler_Debug */ +} +#ifdef USE_FULL_ASSERT +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ +void assert_failed(uint8_t *file, uint32_t line) +{ + /* USER CODE BEGIN 6 */ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + /* USER CODE END 6 */ +} +#endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c new file mode 100644 index 000000000..13e0f0c20 --- /dev/null +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -0,0 +1,203 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g4xx_it.c + * @brief Interrupt Service Routines. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "stm32g4xx_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 Prefetch 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 */ +} + +/******************************************************************************/ +/* STM32G4xx 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_stm32g4xx.s). */ +/******************************************************************************/ + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ From fae24b090b9e256aeab8421305bb1ab5e149ed76 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 10 Jul 2026 00:02:53 -0700 Subject: [PATCH 008/125] In progress --- Work on getting initial CAN peripheral abstraction copied over from TimedCAN Signed-off-by: Daniel Hansen --- .../Application/Inc/CubeCAN_Config.h | 12 ++ CUBEMXTESTING/CMakeLists.txt | 2 +- CUBEMXTESTING/Core/Src/main.c | 26 ++-- Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h | 41 +++++- Lib/Peripherals/CubeCAN/Inc/Private/common.h | 15 +++ Lib/Peripherals/CubeCAN/Src/can_clock.c | 0 Lib/Peripherals/CubeCAN/Src/can_it.c | 123 ++++++++++++++++++ Lib/Peripherals/CubeCAN/Src/can_mcu.c | 26 ++++ Lib/Peripherals/CubeCAN/Src/can_utils.c | 29 +++++ Lib/Peripherals/CubeCAN/cubemx_can.cmake | 7 +- 10 files changed, 265 insertions(+), 16 deletions(-) create mode 100644 CUBEMXTESTING/Application/Inc/CubeCAN_Config.h create mode 100644 Lib/Peripherals/CubeCAN/Inc/Private/common.h delete mode 100644 Lib/Peripherals/CubeCAN/Src/can_clock.c create mode 100644 Lib/Peripherals/CubeCAN/Src/can_mcu.c diff --git a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h new file mode 100644 index 000000000..83444c479 --- /dev/null +++ b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h @@ -0,0 +1,12 @@ +#ifndef CUBE_CAN_CONFIG_H +#define CUBE_CAN_CONFIG_H + +// TODO Add a template to the library + +#define USECAN1 +#define TX_BUFFER_1_SIZE 20 + +#define USECAN2 +#define TX_BUFFER_2_SIZE 20 + +#endif diff --git a/CUBEMXTESTING/CMakeLists.txt b/CUBEMXTESTING/CMakeLists.txt index 7b5232e56..bfd25f877 100644 --- a/CUBEMXTESTING/CMakeLists.txt +++ b/CUBEMXTESTING/CMakeLists.txt @@ -33,7 +33,7 @@ target_sources( Core/Src/stm32g4xx_it.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE VCP_LIB) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE VCP_LIB CUBEMX_CAN_LIB) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 0491c7152..03e70c599 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -48,18 +48,18 @@ /* USER CODE BEGIN PV */ LogomaticConfig logomaticConfig = {.clock_source = LOGOMATIC_PCLK1, - .bus = LOGOMATIC_BUS, - .gpio_port = LOGOMATIC_GPIOA, - .gpio_pin_rx_tx_mask = LL_GPIO_PIN_9 | LL_GPIO_PIN_10, - .baud_rate = 115200, - .data_width = LOGOMATIC_DATAWIDTH_8B, - .stop_bits = LOGOMATIC_STOPBITS_1, - .parity = LOGOMATIC_PARITY_NONE, - .transfer_direction = LOGOMATIC_DIRECTION_TX, - .hardware_flow_control = LOGOMATIC_HWCONTROL_NONE, - .prescaler = LOGOMATIC_PRESCALER_DIV1, - .tx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8, - .rx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8}; + .bus = LOGOMATIC_BUS, + .gpio_port = LOGOMATIC_GPIOA, + .gpio_pin_rx_tx_mask = LL_GPIO_PIN_9 | LL_GPIO_PIN_10, + .baud_rate = 115200, + .data_width = LOGOMATIC_DATAWIDTH_8B, + .stop_bits = LOGOMATIC_STOPBITS_1, + .parity = LOGOMATIC_PARITY_NONE, + .transfer_direction = LOGOMATIC_DIRECTION_TX, + .hardware_flow_control = LOGOMATIC_HWCONTROL_NONE, + .prescaler = LOGOMATIC_PRESCALER_DIV1, + .tx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8, + .rx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8}; VCP_Config vcp_config = {.baud_rate = 2000000, .clock_source = VCP_CLOCK_PCLK, @@ -203,7 +203,7 @@ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, - ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h b/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h index 2b6c3c544..2e9475dcd 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h @@ -1,6 +1,45 @@ +#include + +#include "GRCAN_MSG_ID.h" +#include "GRCAN_NODE_ID.h" + #ifndef CUBEMX_CAN_EXT_H #define CUBEMX_CAN_EXT_H -// TODO +/** + * @brief CAN Identifier structure + * + * This structure is used to represent a CAN message identifier, which consists of a transmitting node ID, a receiving node ID, and a message ID. The structure is used in conjunction with the + * Construct_Message_ID and Deconstruct_Message_ID functions to convert between the structure representation and the 32-bit integer representation of the CAN message identifier. + * + * @warning The structure does not represent cusotm IDs. + * @warning The structure does not represent actual bit depth + */ +typedef struct { + GRCAN_NODE_ID tx_node_id; + GRCAN_NODE_ID rx_node_id; + GRCAN_MSG_ID msg_id; +} CAN_Identifier; + +/** + * @brief Constructs a CAN message identifier from the given transmitting node ID, receiving node ID, and message ID. + * + * @param identifier Pointer to the CAN_Identifier structure containing the node and message IDs. + * + * @return The constructed 29-bit CAN message extended identifier. + */ +uint32_t Construct_CAN_Identifier(const CAN_Identifier *identifier); + +/** + * @brief Deconstructs a 29-bit CAN message extended identifier into its constituent transmitting node ID, receiving node ID, and message ID. + * + * @param message_id The 29-bit CAN message extended identifier to be deconstructed. + * + * @return A CAN_Identifier structure containing the deconstructed node and message IDs. + * + * @warning The function does not guarantee that the returned structure will represent a valid CAN message identifier. + * @warning The function does not support custom IDs. + */ +CAN_Identifier Deconstruct_CAN_Identifier(uint32_t message_id); #endif diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/common.h b/Lib/Peripherals/CubeCAN/Inc/Private/common.h new file mode 100644 index 000000000..c1f43d093 --- /dev/null +++ b/Lib/Peripherals/CubeCAN/Inc/Private/common.h @@ -0,0 +1,15 @@ +#include "main.h" + +#ifndef CUBEMX_CAN_INTERNAL_H +#define CUBEMX_CAN_INTERNAL_H + +/** + * @brief Get the name of the FDCAN instance as a string. + * + * @param instance Pointer to the FDCAN instance. + * + * @return A string representing the name of the FDCAN instance. If the instance is not recognized, returns "UNKNOWN". + */ +const char *CAN_GetInstanceName(FDCAN_GlobalTypeDef *instance); + +#endif diff --git a/Lib/Peripherals/CubeCAN/Src/can_clock.c b/Lib/Peripherals/CubeCAN/Src/can_clock.c deleted file mode 100644 index e69de29bb..000000000 diff --git a/Lib/Peripherals/CubeCAN/Src/can_it.c b/Lib/Peripherals/CubeCAN/Src/can_it.c index e69de29bb..569a3979c 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_it.c +++ b/Lib/Peripherals/CubeCAN/Src/can_it.c @@ -0,0 +1,123 @@ +#include "CubeCAN_Config.h" +#include "CubeMXCan.h" +#include "CubeMXCanExt.h" +#include "Private/common.h" +#include "main.h" + +void FDCAN1_IT0_IRQHandler(void) +{ +#ifdef USECAN1 + HAL_FDCAN_IRQHandler(&hal_fdcan1); +#endif +} + +void FDCAN1_IT1_IRQHandler(void) +{ +#ifdef USECAN1 + HAL_FDCAN_IRQHandler(&hal_fdcan1); +#endif +} + +void FDCAN2_IT0_IRQHandler(void) +{ +#ifdef USECAN2 + HAL_FDCAN_IRQHandler(&hal_fdcan2); +#endif +} +void FDCAN2_IT1_IRQHandler(void) +{ +#ifdef USECAN2 + HAL_FDCAN_IRQHandler(&hal_fdcan2); +#endif +} + +void FDCAN3_IT0_IRQHandler(void) +{ +#ifdef USECAN3 + HAL_FDCAN_IRQHandler(&hal_fdcan3); +#endif +} +void FDCAN3_IT1_IRQHandler(void) +{ +#ifdef USECAN3 + HAL_FDCAN_IRQHandler(&hal_fdcan3); +#endif +} + +void CAN_Timer_Start(void) +{ + static bool initialized = false; + + if (initialized) { + LOGOMATIC("CAN_Timer_Start: timer is already initialized\n"); + return; + } + + RCC_ClkInitTypeDef clkconfig = {0}; + uint32_t latency = 0; + HAL_RCC_GetClockConfig(&clkconfig, &latency); + + uint32_t apb1_div = clkconfig.APB1CLKDivider; + uint32_t tim_clock = (apb1_div == RCC_HCLK_DIV1) ? HAL_RCC_GetPCLK1Freq() : (2U * HAL_RCC_GetPCLK1Freq()); + + // 10 kHz counter clock keeps both PSC/ARR in range for a 1 second period. + const uint32_t counter_hz = 10000U; + if (tim_clock < counter_hz) { + LOGOMATIC("CAN_Timer_Start: APB1 clock is too slow to achieve desired timer frequency\n"); + return; + } + + uint32_t prescaler = (tim_clock / counter_hz) - 1U; + if (prescaler > 0xFFFFU) { + LOGOMATIC("CAN_Timer_Start: failed to initialize timer prescaler\n"); + return; + } + + uint32_t autoreload = ((CAN_TIMER_SEND_PERIOD_US * counter_hz) / 1000000U) - 1U; + if (autoreload > 0xFFFFU) { + LOGOMATIC("CAN_Timer_Start: failed to initialize timer autoreload\n"); + return; + } + + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM5); + + LL_TIM_InitTypeDef tim_init = {0}; + tim_init.Prescaler = prescaler; + tim_init.CounterMode = LL_TIM_COUNTERMODE_UP; + tim_init.Autoreload = autoreload; + tim_init.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; + + if (LL_TIM_Init(TIM5, &tim_init) != SUCCESS) { + LOGOMATIC("CAN_Timer_Start: failed to initialize timer\n"); + return; + } + + LL_TIM_SetClockSource(TIM5, LL_TIM_CLOCKSOURCE_INTERNAL); + LL_TIM_ClearFlag_UPDATE(TIM5); + LL_TIM_EnableIT_UPDATE(TIM5); + + HAL_NVIC_SetPriority(TIM5_IRQn, 15U, 0U); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + + LL_TIM_EnableCounter(TIM5); + + initialized = true; + LOGOMATIC("CAN_Timer_Start: timer initialized\n"); + return; +} + +void TIM5_IRQHandler(void) +{ + if (LL_TIM_IsActiveFlag_UPDATE(TIM5)) { + LL_TIM_ClearFlag_UPDATE(TIM5); +#ifdef USECAN1 + can_tx_dequeue_helper(can_get_handle(&hal_fdcan1)); +#endif +#ifdef USECAN2 + can_tx_dequeue_helper(can_get_handle(&hal_fdcan2)); +#endif +#ifdef USECAN3 + can_tx_dequeue_helper(can_get_handle(&hal_fdcan3)); +#endif + } +} diff --git a/Lib/Peripherals/CubeCAN/Src/can_mcu.c b/Lib/Peripherals/CubeCAN/Src/can_mcu.c new file mode 100644 index 000000000..68edf9675 --- /dev/null +++ b/Lib/Peripherals/CubeCAN/Src/can_mcu.c @@ -0,0 +1,26 @@ +#include "CubeMXCan.h" +#include "CubeMXCanExt.h" +#include "Logomatic.h" +#include "Private/common.h" + +const char *CAN_GetInstanceName(FDCAN_GlobalTypeDef *instance) +{ + if (instance == NULL) { + return "NULL"; + } +#if defined(STM32G474xx) + if (instance == FDCAN1) { + return "FDCAN1"; + } else if (instance == FDCAN2) { + return "FDCAN2"; + } else if (instance == FDCAN3) { + return "FDCAN3"; + } +#elif defined(STM32G431xx) + if (instance == FDCAN1) { + return "FDCAN1"; + } +#endif + LOGOMATIC("Get CAN instance name: unknown instance\n"); + return "UNKNOWN"; +} diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index e69de29bb..6119f63f0 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -0,0 +1,29 @@ +#include + +#include "CubeMXCan.h" +#include "CubeMXCanExt.h" +#include "GRCAN_MSG_ID.h" +#include "GRCAN_NODE_ID.h" +#include "Private/common.h" + +uint32_t Construct_CAN_Identifier(const CAN_Identifier *identifier) +{ + uint32_t message_id = 0; + + message_id |= ((0xFF & identifier->tx_node_id) << 20); + message_id |= ((0xFFF & identifier->msg_id) << 8); + message_id |= (0xFF & identifier->rx_node_id); + + return message_id; +} + +CAN_Identifier Deconstruct_CAN_Identifier(uint32_t message_id) +{ + CAN_Identifier identifier = {0}; + + identifier.tx_node_id = (GRCAN_NODE_ID)((message_id >> 20) & 0xFF); + identifier.msg_id = (GRCAN_MSG_ID)((message_id >> 8) & 0xFFF); + identifier.rx_node_id = (GRCAN_NODE_ID)(message_id & 0xFF); + + return identifier; +} diff --git a/Lib/Peripherals/CubeCAN/cubemx_can.cmake b/Lib/Peripherals/CubeCAN/cubemx_can.cmake index ab7d9470e..85cd3db36 100644 --- a/Lib/Peripherals/CubeCAN/cubemx_can.cmake +++ b/Lib/Peripherals/CubeCAN/cubemx_can.cmake @@ -10,8 +10,13 @@ target_sources( CUBEMX_CAN_LIB INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Src/can_it.c - ${CMAKE_CURRENT_LIST_DIR}/Src/can_clock.c ${CMAKE_CURRENT_LIST_DIR}/Src/can_utils.c ) +target_link_libraries( + CUBEMX_CAN_LIB + INTERFACE + CANfigurator +) + # TODO Unit testing From 6efc2bc5ee73353e94314ac897054f606d5c9ae6 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 10 Jul 2026 00:16:43 -0700 Subject: [PATCH 009/125] In progress --- Resolve a few include errors Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Application/Inc/CubeCAN_Config.h | 4 ++++ CUBEMXTESTING/Core/Inc/main.h | 3 ++- Lib/Peripherals/CubeCAN/Inc/Private/common.h | 4 ++-- Lib/Peripherals/CubeCAN/Src/can_it.c | 4 ++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h index 83444c479..866efc956 100644 --- a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h +++ b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h @@ -3,10 +3,14 @@ // TODO Add a template to the library +#include "stm32g4xx_ll_tim.h" + #define USECAN1 #define TX_BUFFER_1_SIZE 20 #define USECAN2 #define TX_BUFFER_2_SIZE 20 +#define CAN_TIMER_SEND_PERIOD_US 500 + #endif diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index 3a736d114..c050c5e89 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -42,7 +42,8 @@ extern "C" { /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ - +#include "stm32g4xx_ll_usart.h" +#include "stm32g4xx_ll_lpuart.h" /* USER CODE END Includes */ /* Exported types ------------------------------------------------------------*/ diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/common.h b/Lib/Peripherals/CubeCAN/Inc/Private/common.h index c1f43d093..a2ae5d5e7 100644 --- a/Lib/Peripherals/CubeCAN/Inc/Private/common.h +++ b/Lib/Peripherals/CubeCAN/Inc/Private/common.h @@ -1,7 +1,7 @@ #include "main.h" -#ifndef CUBEMX_CAN_INTERNAL_H -#define CUBEMX_CAN_INTERNAL_H +#ifndef CUBE_CAN_PRIVATE_COMMON_H +#define CUBE_CAN_PRIVATE_COMMON_H /** * @brief Get the name of the FDCAN instance as a string. diff --git a/Lib/Peripherals/CubeCAN/Src/can_it.c b/Lib/Peripherals/CubeCAN/Src/can_it.c index 569a3979c..242e861fe 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_it.c +++ b/Lib/Peripherals/CubeCAN/Src/can_it.c @@ -1,6 +1,10 @@ +#include +#include + #include "CubeCAN_Config.h" #include "CubeMXCan.h" #include "CubeMXCanExt.h" +#include "Logomatic.h" #include "Private/common.h" #include "main.h" From 11f536a624ec9fc672c497ac7b6b673a0d0ec9b0 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Tue, 14 Jul 2026 23:26:29 -0700 Subject: [PATCH 010/125] Add template from [Discord](https://discord.com/channels/756738476887638107/1525038985175367720/1526432730273943714) to the monorepo Also update extension list for freemarker support Co-authored-by: TrainmanR Signed-off-by: Daniel Hansen --- .vscode/extensions.json | 3 +- Lib/CubeMXTemplates/can_cfg_h.ftl | 66 +++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 Lib/CubeMXTemplates/can_cfg_h.ftl diff --git a/.vscode/extensions.json b/.vscode/extensions.json index b5c60d558..3e5fd3c28 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -9,6 +9,7 @@ "github.vscode-pull-request-github", "eamodio.gitlens", "davidanson.vscode-markdownlint", - "ms-vscode.vscode-serial-monitor" + "ms-vscode.vscode-serial-monitor", + "dcortes92.freemarker" ] } diff --git a/Lib/CubeMXTemplates/can_cfg_h.ftl b/Lib/CubeMXTemplates/can_cfg_h.ftl new file mode 100644 index 000000000..395f27387 --- /dev/null +++ b/Lib/CubeMXTemplates/can_cfg_h.ftl @@ -0,0 +1,66 @@ +[#ftl] +[#-- + Example STM32CubeMX FreeMarker template + + Suggested filename: + can_cfg_h.ftl + + Expected generated filename: + can_cfg.h + + Purpose: + Detect which FDCAN peripherals are enabled in CubeMX and generate + compile-time configuration macros for the Gaucho Racing CAN library. +--] + +[#list configs as dt] + +[#assign usedIPs = (dt.usedIPs)![]] + +[#assign hasFDCAN1 = false] +[#assign hasFDCAN2 = false] +[#assign hasFDCAN3 = false] + +[#list usedIPs as ip] + [#assign ipName = ip?string] + + [#if ipName == "FDCAN1"] + [#assign hasFDCAN1 = true] + [/#if] + + [#if ipName == "FDCAN2"] + [#assign hasFDCAN2 = true] + [/#if] + + [#if ipName == "FDCAN3"] + [#assign hasFDCAN3 = true] + [/#if] +[/#list] + +#ifndef CAN_CFG_H +#define CAN_CFG_H + +/* Generated automatically by STM32CubeMX FreeMarker. */ + +[#if hasFDCAN1] +#define USECAN1 +#define TX_BUFFER_1_SIZE 20U +[/#if] + +[#if hasFDCAN2] +#define USECAN2 +#define TX_BUFFER_2_SIZE 20U +[/#if] + +[#if hasFDCAN3] +#define USECAN3 +#define TX_BUFFER_3_SIZE 20U +[/#if] + +[#if !hasFDCAN1 && !hasFDCAN2 && !hasFDCAN3] +#error "No FDCAN peripheral is enabled in STM32CubeMX" +[/#if] + +#endif /* CAN_CFG_H */ + +[/#list] From b844929cd3200521bac3b95adb624dfc6d6cc167 Mon Sep 17 00:00:00 2001 From: TrainmanR Date: Wed, 15 Jul 2026 14:29:29 -0700 Subject: [PATCH 011/125] New changes to template can_cfg_h.ftl; aimed to preserve user-changed code, while before it would be erased on re-generation of the file. --- Lib/CubeMXTemplates/can_cfg_h.ftl | 42 ++++++++++++++----------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/Lib/CubeMXTemplates/can_cfg_h.ftl b/Lib/CubeMXTemplates/can_cfg_h.ftl index 395f27387..8036a8133 100644 --- a/Lib/CubeMXTemplates/can_cfg_h.ftl +++ b/Lib/CubeMXTemplates/can_cfg_h.ftl @@ -1,17 +1,4 @@ [#ftl] -[#-- - Example STM32CubeMX FreeMarker template - - Suggested filename: - can_cfg_h.ftl - - Expected generated filename: - can_cfg.h - - Purpose: - Detect which FDCAN peripherals are enabled in CubeMX and generate - compile-time configuration macros for the Gaucho Racing CAN library. ---] [#list configs as dt] @@ -24,15 +11,15 @@ [#list usedIPs as ip] [#assign ipName = ip?string] - [#if ipName == "FDCAN1"] + [#if ipName?contains("FDCAN1")] [#assign hasFDCAN1 = true] [/#if] - [#if ipName == "FDCAN2"] + [#if ipName?contains("FDCAN2")] [#assign hasFDCAN2 = true] [/#if] - [#if ipName == "FDCAN3"] + [#if ipName?contains("FDCAN3")] [#assign hasFDCAN3 = true] [/#if] [/#list] @@ -42,23 +29,32 @@ /* Generated automatically by STM32CubeMX FreeMarker. */ +/* USER CODE BEGIN CAN_USER_CONFIG */ + +#ifndef TX_BUFFER_1_SIZE +#define TX_BUFFER_1_SIZE 20U +#endif + +#ifndef TX_BUFFER_2_SIZE +#define TX_BUFFER_2_SIZE 20U +#endif + +#ifndef TX_BUFFER_3_SIZE +#define TX_BUFFER_3_SIZE 20U +#endif + +/* USER CODE END CAN_USER_CONFIG */ + [#if hasFDCAN1] #define USECAN1 -#define TX_BUFFER_1_SIZE 20U [/#if] [#if hasFDCAN2] #define USECAN2 -#define TX_BUFFER_2_SIZE 20U [/#if] [#if hasFDCAN3] #define USECAN3 -#define TX_BUFFER_3_SIZE 20U -[/#if] - -[#if !hasFDCAN1 && !hasFDCAN2 && !hasFDCAN3] -#error "No FDCAN peripheral is enabled in STM32CubeMX" [/#if] #endif /* CAN_CFG_H */ From f00f3a7d1a3a1c12cd8f91be01eefc59239b2071 Mon Sep 17 00:00:00 2001 From: TrainmanR Date: Wed, 15 Jul 2026 14:34:10 -0700 Subject: [PATCH 012/125] Added comments to explain new functionality in the can_cfg_h.ftl template file. --- Lib/CubeMXTemplates/can_cfg_h.ftl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Lib/CubeMXTemplates/can_cfg_h.ftl b/Lib/CubeMXTemplates/can_cfg_h.ftl index 8036a8133..f3a1bcf98 100644 --- a/Lib/CubeMXTemplates/can_cfg_h.ftl +++ b/Lib/CubeMXTemplates/can_cfg_h.ftl @@ -1,5 +1,15 @@ [#ftl] +[#-- +Generates can_cfg.h from the active STM32CubeMX project. + +Detects enabled FDCAN instances and emits the corresponding USECANx macros. +TX buffer sizes remain user-configurable and are preserved across normal +CubeMX regeneration. + +STM32 hardware configuration remains owned by CubeMX. +--] + [#list configs as dt] [#assign usedIPs = (dt.usedIPs)![]] From dbd5d1370083741947f34a32c1728785f15334cc Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Wed, 15 Jul 2026 22:20:43 -0700 Subject: [PATCH 013/125] Modify how we handle templates within the monorepo based on new information Signed-off-by: Daniel Hansen --- Lib/CubeMXTemplates/{ => Autogen/Inc}/can_cfg_h.ftl | 0 Lib/CubeMXTemplates/Autogen/Src/.gitkeep | 0 Lib/CubeMXTemplates/README.md | 9 +++++++++ 3 files changed, 9 insertions(+) rename Lib/CubeMXTemplates/{ => Autogen/Inc}/can_cfg_h.ftl (100%) create mode 100644 Lib/CubeMXTemplates/Autogen/Src/.gitkeep create mode 100644 Lib/CubeMXTemplates/README.md diff --git a/Lib/CubeMXTemplates/can_cfg_h.ftl b/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl similarity index 100% rename from Lib/CubeMXTemplates/can_cfg_h.ftl rename to Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl diff --git a/Lib/CubeMXTemplates/Autogen/Src/.gitkeep b/Lib/CubeMXTemplates/Autogen/Src/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/Lib/CubeMXTemplates/README.md b/Lib/CubeMXTemplates/README.md new file mode 100644 index 000000000..37ba973d7 --- /dev/null +++ b/Lib/CubeMXTemplates/README.md @@ -0,0 +1,9 @@ +# STM32 CubeMX Templates + +## Instructions + +1. Uncheck use default location and configure it to point to this folder (not `Autogen`!) +2. Add all of the relevant templates from available into selected +3. TODO (As we figure out the destination folder bit) + +## TODO From e68c5b6b2416d4ba85cdb951578db2ba233a4e11 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Wed, 15 Jul 2026 22:34:30 -0700 Subject: [PATCH 014/125] Modify line placement and ensure ordering has no precedence on broken builds Signed-off-by: Daniel Hansen --- Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl b/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl index f3a1bcf98..de4b84222 100644 --- a/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl +++ b/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl @@ -33,7 +33,6 @@ STM32 hardware configuration remains owned by CubeMX. [#assign hasFDCAN3 = true] [/#if] [/#list] - #ifndef CAN_CFG_H #define CAN_CFG_H @@ -41,17 +40,9 @@ STM32 hardware configuration remains owned by CubeMX. /* USER CODE BEGIN CAN_USER_CONFIG */ -#ifndef TX_BUFFER_1_SIZE #define TX_BUFFER_1_SIZE 20U -#endif - -#ifndef TX_BUFFER_2_SIZE #define TX_BUFFER_2_SIZE 20U -#endif - -#ifndef TX_BUFFER_3_SIZE #define TX_BUFFER_3_SIZE 20U -#endif /* USER CODE END CAN_USER_CONFIG */ From e0b2e0e6652a3c5d06564b4d58326ca1858db43a Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 16 Jul 2026 00:13:44 -0700 Subject: [PATCH 015/125] Copy ftl from [Discord](https://discord.com/channels/756738476887638107/1525038985175367720/1527205781462712471) into git vcs Co-authored-by: TrainmanR Signed-off-by: Daniel Hansen --- Lib/CubeMXTemplates/can_cfg_h_timer.ftl | 177 ++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 Lib/CubeMXTemplates/can_cfg_h_timer.ftl diff --git a/Lib/CubeMXTemplates/can_cfg_h_timer.ftl b/Lib/CubeMXTemplates/can_cfg_h_timer.ftl new file mode 100644 index 000000000..b7ace5741 --- /dev/null +++ b/Lib/CubeMXTemplates/can_cfg_h_timer.ftl @@ -0,0 +1,177 @@ +[#ftl] +[#-- + Generates can_cfg.h from the active STM32CubeMX project. + + Detects enabled FDCAN instances and emits the corresponding USECANx macros. + Software TX queue sizes and CAN timer settings remain user-configurable and + are preserved across normal CubeMX regeneration. + + CubeMX remains responsible for configuring and generating MX_FDCANx_Init() + and MX_TIMx_Init(). This file only selects the CubeMX-generated timer handle + used to service the CAN software TX queues. +--] + +[#list configs as dt] + +[#assign usedIPs = (dt.usedIPs)![]] +[#assign hasFDCAN1 = false] +[#assign hasFDCAN2 = false] +[#assign hasFDCAN3 = false] +[#assign hasTIM1 = false] +[#assign hasTIM2 = false] +[#assign hasTIM3 = false] +[#assign hasTIM4 = false] +[#assign hasTIM5 = false] +[#assign hasTIM6 = false] +[#assign hasTIM7 = false] +[#assign hasTIM8 = false] +[#assign hasTIM15 = false] +[#assign hasTIM16 = false] +[#assign hasTIM17 = false] + +[#list usedIPs as ip] + [#assign ipName = ip?string] + + [#if ipName?contains("FDCAN1")][#assign hasFDCAN1 = true][/#if] + [#if ipName?contains("FDCAN2")][#assign hasFDCAN2 = true][/#if] + [#if ipName?contains("FDCAN3")][#assign hasFDCAN3 = true][/#if] + + [#if ipName?contains("TIM1")][#assign hasTIM1 = true][/#if] + [#if ipName?contains("TIM2")][#assign hasTIM2 = true][/#if] + [#if ipName?contains("TIM3")][#assign hasTIM3 = true][/#if] + [#if ipName?contains("TIM4")][#assign hasTIM4 = true][/#if] + [#if ipName?contains("TIM5")][#assign hasTIM5 = true][/#if] + [#if ipName?contains("TIM6")][#assign hasTIM6 = true][/#if] + [#if ipName?contains("TIM7")][#assign hasTIM7 = true][/#if] + [#if ipName?contains("TIM8")][#assign hasTIM8 = true][/#if] + [#if ipName?contains("TIM15")][#assign hasTIM15 = true][/#if] + [#if ipName?contains("TIM16")][#assign hasTIM16 = true][/#if] + [#if ipName?contains("TIM17")][#assign hasTIM17 = true][/#if] +[/#list] + +#ifndef CAN_CFG_H +#define CAN_CFG_H + +/* Generated automatically by STM32CubeMX FreeMarker. */ + +/* USER CODE BEGIN CAN_USER_CONFIG */ + +#ifndef TX_BUFFER_1_SIZE +#define TX_BUFFER_1_SIZE 20U +#endif + +#ifndef TX_BUFFER_2_SIZE +#define TX_BUFFER_2_SIZE 20U +#endif + +#ifndef TX_BUFFER_3_SIZE +#define TX_BUFFER_3_SIZE 20U +#endif + +/* Selects htim5 when set to 5. */ +#ifndef CAN_TIMER_INDEX +#define CAN_TIMER_INDEX 5 +#endif + +/* Dequeue one CAN message every X milliseconds. */ +#ifndef CAN_DEQUEUE_PERIOD_MS +#define CAN_DEQUEUE_PERIOD_MS 2U +#endif + +/* USER CODE END CAN_USER_CONFIG */ + +[#if hasFDCAN1] +#define USECAN1 +[/#if] +[#if hasFDCAN2] +#define USECAN2 +[/#if] +[#if hasFDCAN3] +#define USECAN3 +[/#if] + +[#if hasTIM1] +#define CUBEMX_HAS_TIM1 +[/#if] +[#if hasTIM2] +#define CUBEMX_HAS_TIM2 +[/#if] +[#if hasTIM3] +#define CUBEMX_HAS_TIM3 +[/#if] +[#if hasTIM4] +#define CUBEMX_HAS_TIM4 +[/#if] +[#if hasTIM5] +#define CUBEMX_HAS_TIM5 +[/#if] +[#if hasTIM6] +#define CUBEMX_HAS_TIM6 +[/#if] +[#if hasTIM7] +#define CUBEMX_HAS_TIM7 +[/#if] +[#if hasTIM8] +#define CUBEMX_HAS_TIM8 +[/#if] +[#if hasTIM15] +#define CUBEMX_HAS_TIM15 +[/#if] +[#if hasTIM16] +#define CUBEMX_HAS_TIM16 +[/#if] +[#if hasTIM17] +#define CUBEMX_HAS_TIM17 +[/#if] + +#if defined(USECAN1) && (TX_BUFFER_1_SIZE == 0U) +#error "TX_BUFFER_1_SIZE must be greater than zero" +#endif +#if defined(USECAN2) && (TX_BUFFER_2_SIZE == 0U) +#error "TX_BUFFER_2_SIZE must be greater than zero" +#endif +#if defined(USECAN3) && (TX_BUFFER_3_SIZE == 0U) +#error "TX_BUFFER_3_SIZE must be greater than zero" +#endif +#if CAN_DEQUEUE_PERIOD_MS == 0U +#error "CAN_DEQUEUE_PERIOD_MS must be greater than zero" +#endif + +#if (CAN_TIMER_INDEX == 1) && !defined(CUBEMX_HAS_TIM1) +#error "CAN_TIMER_INDEX selects TIM1, but TIM1 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 2) && !defined(CUBEMX_HAS_TIM2) +#error "CAN_TIMER_INDEX selects TIM2, but TIM2 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 3) && !defined(CUBEMX_HAS_TIM3) +#error "CAN_TIMER_INDEX selects TIM3, but TIM3 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 4) && !defined(CUBEMX_HAS_TIM4) +#error "CAN_TIMER_INDEX selects TIM4, but TIM4 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 5) && !defined(CUBEMX_HAS_TIM5) +#error "CAN_TIMER_INDEX selects TIM5, but TIM5 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 6) && !defined(CUBEMX_HAS_TIM6) +#error "CAN_TIMER_INDEX selects TIM6, but TIM6 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 7) && !defined(CUBEMX_HAS_TIM7) +#error "CAN_TIMER_INDEX selects TIM7, but TIM7 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 8) && !defined(CUBEMX_HAS_TIM8) +#error "CAN_TIMER_INDEX selects TIM8, but TIM8 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 15) && !defined(CUBEMX_HAS_TIM15) +#error "CAN_TIMER_INDEX selects TIM15, but TIM15 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 16) && !defined(CUBEMX_HAS_TIM16) +#error "CAN_TIMER_INDEX selects TIM16, but TIM16 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 17) && !defined(CUBEMX_HAS_TIM17) +#error "CAN_TIMER_INDEX selects TIM17, but TIM17 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX != 1) && (CAN_TIMER_INDEX != 2) && \ + (CAN_TIMER_INDEX != 3) && (CAN_TIMER_INDEX != 4) && \ + (CAN_TIMER_INDEX != 5) && (CAN_TIMER_INDEX != 6) && \ + (CAN_TIMER_INDEX != 7) && (CAN_TIMER_INDEX != 8) && \ + (CAN_TIMER_INDEX != 15) && (CAN_TIMER_INDEX != 16) && \ + (CAN_TIMER_INDEX != 17) +#error "CAN_TIMER_INDEX selects an unsupported timer" +#endif + +#define CAN_CFG_JOIN_INNER(a, b) a##b +#define CAN_CFG_JOIN(a, b) CAN_CFG_JOIN_INNER(a, b) +#define CAN_TIMER_HANDLE CAN_CFG_JOIN(htim, CAN_TIMER_INDEX) + +#endif /* CAN_CFG_H */ + +[/#list] From 05e2989533b6d9f2db6e0c70d4ac9f4b39759c98 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 16 Jul 2026 00:28:51 -0700 Subject: [PATCH 016/125] In progress --- Computer seconds from dying so it probably doesn't compile at all so sorry Signed-off-by: Daniel Hansen --- .../Application/Inc/CubeCAN_Config.h | 9 +- CUBEMXTESTING/Core/Src/main.c | 184 ++++++++-------- Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h | 100 ++++++++- Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h | 6 + .../CubeCAN/Inc/Private/PrivateCubeMXCAN.h | 88 ++++++++ Lib/Peripherals/CubeCAN/Inc/Private/common.h | 15 -- Lib/Peripherals/CubeCAN/Src/can_init.c | 208 ++++++++++++++++++ Lib/Peripherals/CubeCAN/Src/can_it.c | 126 +++-------- Lib/Peripherals/CubeCAN/Src/can_mcu.c | 26 --- Lib/Peripherals/CubeCAN/Src/can_utils.c | 87 +++++++- Lib/Peripherals/CubeCAN/cubemx_can.cmake | 1 + 11 files changed, 609 insertions(+), 241 deletions(-) create mode 100644 Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h delete mode 100644 Lib/Peripherals/CubeCAN/Inc/Private/common.h create mode 100644 Lib/Peripherals/CubeCAN/Src/can_init.c delete mode 100644 Lib/Peripherals/CubeCAN/Src/can_mcu.c diff --git a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h index 866efc956..f3c02252e 100644 --- a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h +++ b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h @@ -3,14 +3,13 @@ // TODO Add a template to the library -#include "stm32g4xx_ll_tim.h" +#include "main.h" #define USECAN1 -#define TX_BUFFER_1_SIZE 20 - #define USECAN2 -#define TX_BUFFER_2_SIZE 20 -#define CAN_TIMER_SEND_PERIOD_US 500 +#define CUBEMX_CAN_TIMER_INSTANCE TIM5 +#define CUBEMX_CAN_TX_QUEUE_SIZE 20U +#define CAN_TIMER_SEND_PERIOD_US 500U #endif diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 03e70c599..45a24d683 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,7 +18,6 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" - #include "fdcan.h" #include "gpio.h" @@ -48,18 +47,18 @@ /* USER CODE BEGIN PV */ LogomaticConfig logomaticConfig = {.clock_source = LOGOMATIC_PCLK1, - .bus = LOGOMATIC_BUS, - .gpio_port = LOGOMATIC_GPIOA, - .gpio_pin_rx_tx_mask = LL_GPIO_PIN_9 | LL_GPIO_PIN_10, - .baud_rate = 115200, - .data_width = LOGOMATIC_DATAWIDTH_8B, - .stop_bits = LOGOMATIC_STOPBITS_1, - .parity = LOGOMATIC_PARITY_NONE, - .transfer_direction = LOGOMATIC_DIRECTION_TX, - .hardware_flow_control = LOGOMATIC_HWCONTROL_NONE, - .prescaler = LOGOMATIC_PRESCALER_DIV1, - .tx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8, - .rx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8}; + .bus = LOGOMATIC_BUS, + .gpio_port = LOGOMATIC_GPIOA, + .gpio_pin_rx_tx_mask = LL_GPIO_PIN_9 | LL_GPIO_PIN_10, + .baud_rate = 115200, + .data_width = LOGOMATIC_DATAWIDTH_8B, + .stop_bits = LOGOMATIC_STOPBITS_1, + .parity = LOGOMATIC_PARITY_NONE, + .transfer_direction = LOGOMATIC_DIRECTION_TX, + .hardware_flow_control = LOGOMATIC_HWCONTROL_NONE, + .prescaler = LOGOMATIC_PRESCALER_DIV1, + .tx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8, + .rx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8}; VCP_Config vcp_config = {.baud_rate = 2000000, .clock_source = VCP_CLOCK_PCLK, @@ -87,92 +86,99 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + /* USER CODE BEGIN 2 */ Logomatic_Init(&logomaticConfig); VCP_Init(&vcp_config); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ LOGOMATIC("Hello World!\n"); while (1) { - /* USER CODE END WHILE */ - MainLoop(); - LL_mDelay(500); - /* USER CODE BEGIN 3 */ + /* USER CODE END WHILE */ + + /* USER CODE BEGIN 3 */ } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) + { + } + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while(LL_RCC_HSI_IsReady() != 1) + { + } + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while(LL_RCC_PLL_IsReady() != 1) + { + } + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) + { + } + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i !=0; i--); + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) + { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -180,30 +186,30 @@ void SystemClock_Config(void) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h index 0bac3f962..8a258cc72 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h @@ -1,6 +1,104 @@ +#include +#include + +#include "CubeCAN_Config.h" +#include "CubeMXCanExt.h" +#include "main.h" + #ifndef CUBEMX_CAN_H #define CUBEMX_CAN_H -// TODO +#define FDCAN_MAX_DATA_BYTES 64U + +/** + * @brief Received CAN message structure + * + * This structure is used to represent a received CAN message, which consists of a header and data payload. The header contains information about the message, such as its identifier, data length, and other relevant parameters. The data payload contains the actual data bytes of the message. + * + * @warning The length of the data array may be longer than the actual CAN message. + */ +typedef struct { + /// @brief The header of the received CAN message, containing information such as the identifier, data length, and other relevant parameters. + FDCAN_RxHeaderTypeDef rx_header; + /// @brief The data payload of the received CAN message, containing the actual data bytes of the message. The length of this array may be longer than the actual CAN message. + uint8_t data[FDCAN_MAX_DATA_BYTES]; +} GRCAN_RxMessage; + +/** + * @brief Transmission CAN message structure + * + * This structure is used to represent a transmission CAN message, which consists of a header and data payload. The header contains information about the message, such as its identifier, data length, and other relevant parameters. The data payload contains the actual data bytes of the message. + * + * @warning The length of the data array may be longer than the actual CAN message. + */ +typedef struct { + FDCAN_TxHeaderTypeDef tx_header; + uint8_t data[FDCAN_MAX_DATA_BYTES]; +} GRCAN_TxMessage; + +/// @brief CAN handle for CubeMX CAN. @warning Do not access directly, use the provided API functions. +typedef struct CubeMXCan_Handle CubeMXCan_Handle; + +/// @brief Callback function type for receiving CAN messages. @warning Do not call directly, use the provided API functions. +typedef void (*CubeCAN_RxCallback)(void *user_ctx, const CAN_Identifier *identifier, const uint8_t *data, uint8_t size); + +/** + * @brief Configuration structure for CubeMX CAN. + * + * This structure is used to configure the CubeMX CAN handle, including the receive callback function and user context. The receive callback function is called when a CAN message is received, and the user context is a pointer to user-defined data that can be passed to the callback function. + * + * @warning Do not edit after initialization, as it may lead to undefined behavior. + */ +typedef struct { + /// @brief Callback function for receiving CAN messages. This function is called when a CAN message is received. + CubeCAN_RxCallback rx_callback; + /// @brief User-defined context pointer that can be passed to the receive callback function. This can be used to pass additional data or state information to the callback function. + void *user_ctx; +} CubeCAN_Config; + +/** + * @brief Initializes a CubeMX CAN handle with the given FDCAN handle and configuration. + * @param hfdcan Pointer to the FDCAN handle. + * @param config Pointer to the CubeCAN configuration structure. + * @return Pointer to the initialized CubeMX CAN handle, or NULL if initialization fails. + */ +CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, const CubeCAN_Config *config); + +/** + * @brief Starts the CubeMX CAN handle, enabling message transmission and reception. + * @param handle Pointer to the CubeMX CAN handle. + * @return HAL_StatusTypeDef indicating the success or failure of the operation. + */ +HAL_StatusTypeDef CubeMXCan_Start(CubeMXCan_Handle *handle); + +/** + * @brief Stops the CubeMX CAN handle, disabling message transmission and reception. + * @param handle Pointer to the CubeMX CAN handle. + * @return HAL_StatusTypeDef indicating the success or failure of the operation. + */ +HAL_StatusTypeDef CubeMXCan_Stop(CubeMXCan_Handle *handle); + +/** + * @brief Releases the resources associated with the CubeMX CAN handle. + * @param handle Pointer to the CubeMX CAN handle. + * @return HAL_StatusTypeDef indicating the success or failure of the operation. + */ +HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *handle); + +/** + * @brief Adds a filter to the CubeMX CAN handle, allowing for selective message reception based on the specified filter criteria. + * @param handle Pointer to the CubeMX CAN handle. + * @param filter Pointer to the FDCAN filter configuration structure. + * @return HAL_StatusTypeDef indicating the success or failure of the operation. + */ +HAL_StatusTypeDef CubeMXCan_AddFilter(CubeMXCan_Handle *handle, const FDCAN_FilterTypeDef *filter); + +/** + * @brief Queues a transmission message for the CubeMX CAN handle, allowing for asynchronous message transmission. + * @param handle Pointer to the CubeMX CAN handle. + * @param message Pointer to the GRCAN transmission message structure. + * @return HAL_StatusTypeDef indicating the success or failure of the operation. + */ +HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *handle, const GRCAN_TxMessage *message); #endif diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h b/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h index 2e9475dcd..64eff376a 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h @@ -2,6 +2,7 @@ #include "GRCAN_MSG_ID.h" #include "GRCAN_NODE_ID.h" +#include "main.h" #ifndef CUBEMX_CAN_EXT_H #define CUBEMX_CAN_EXT_H @@ -42,4 +43,9 @@ uint32_t Construct_CAN_Identifier(const CAN_Identifier *identifier); */ CAN_Identifier Deconstruct_CAN_Identifier(uint32_t message_id); +/** + * @brief Builds an exact-match extended-ID filter for a given CAN identifier. + */ +HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *identifier, uint32_t filter_index, uint32_t fifo, FDCAN_FilterTypeDef *filter); + #endif diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h new file mode 100644 index 000000000..3baff2c60 --- /dev/null +++ b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h @@ -0,0 +1,88 @@ +#include +#include + +#include "CubeMXCan.h" +#include "main.h" + +#ifndef PRIVATE_CUBE_MX_CAN_H +#define PRIVATE_CUBE_MX_CAN_H + +/** + * @brief CubeMX CAN handle structure + * + * This structure is used to represent a CubeMX CAN handle, which consists of a pointer to the FDCAN handle, a configuration structure, a transmission queue, and other relevant parameters.\ + * + * @warning Use the provided API functions to interact with the CubeMX CAN handle. + * @warning The structure is intended for internal use only and should not be accessed directly by user code. + */ +typedef struct CubeMXCan_Handle { + /// @brief Pointer to the FDCAN handle associated with this CubeMX CAN handle. + FDCAN_HandleTypeDef *hfdcan; + /// @brief Configuration structure for the CubeMX CAN handle, containing the receive callback and user context. + CubeCAN_Config config; + /// @brief Transmission queue for the CubeMX CAN handle, containing the messages to be transmitted. + GRCAN_TxMessage tx_queue[CUBEMX_CAN_TX_QUEUE_SIZE]; + /// @brief Index of the head of the transmission queue, indicating the next message to be transmitted. + uint32_t tx_head; + /// @brief Count of messages in the transmission queue, indicating the number of messages waiting to be transmitted. + uint32_t tx_count; + /// @brief Flag indicating whether the CubeMX CAN handle has been started. + bool started; +} CubeMXCan_Handle; + +/// @brief Maximum number of CubeMX CAN instances supported by the library. +#define CUBEMX_CAN_MAX_INSTANCES 3U + +/** + * @brief Retrieves the CubeMX CAN handle associated with the given FDCAN handle. + * @param hfdcan Pointer to the FDCAN handle. + * @return Pointer to the CubeMX CAN handle associated with the given FDCAN handle + */ +CubeMXCan_Handle *CubeMXCan_Private_GetHandle(FDCAN_HandleTypeDef *hfdcan); + +/** + * @brief Registers a CubeMX CAN handle with the given FDCAN handle. + * @param hfdcan Pointer to the FDCAN handle. + * @param handle Pointer to the CubeMX CAN handle. + * @return HAL_StatusTypeDef indicating the success or failure of the operation. + */ +HAL_StatusTypeDef CubeMXCan_Private_RegisterHandle(FDCAN_HandleTypeDef *hfdcan, CubeMXCan_Handle *handle); + +/** + * @brief Unregisters the CubeMX CAN handle associated with the given FDCAN handle. + * @param hfdcan Pointer to the FDCAN handle. + */ +void CubeMXCan_Private_UnregisterHandle(FDCAN_HandleTypeDef *hfdcan); + +/** + * @brief Sends a queued message from the CubeMX CAN handle. + * @param handle Pointer to the CubeMX CAN handle. + * @return HAL_StatusTypeDef indicating the success or failure of the operation. + */ +HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(CubeMXCan_Handle *handle); + +/** + * @brief Dispatches a received message from the CubeMX CAN handle. + * @param hfdcan Pointer to the FDCAN handle. + */ +void CubeMXCan_Private_DispatchRx(FDCAN_HandleTypeDef *hfdcan); + +/** + * @brief Converts a Data Length Code (DLC) to the corresponding number of bytes. + * @param dlc The Data Length Code to be converted. + * @return The number of bytes corresponding to the given DLC. + */ +uint8_t CubeMXCan_Private_DlcToBytes(uint32_t dlc); + +/** + * @brief Processes periodic tasks for the CubeMX CAN handle, such as handling timeouts and managing the transmission queue. + */ +void CubeMXCan_Tick(void); + +/** + * @brief Callback function for handling received messages from the FDCAN peripheral. This function is called when a message is received in the RX FIFO 0 of the FDCAN peripheral. + * @param hfdcan Pointer to the FDCAN handle associated with the received message. + */ +void CubeMXCan_OnRxFifo0(FDCAN_HandleTypeDef *hfdcan); + +#endif diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/common.h b/Lib/Peripherals/CubeCAN/Inc/Private/common.h deleted file mode 100644 index a2ae5d5e7..000000000 --- a/Lib/Peripherals/CubeCAN/Inc/Private/common.h +++ /dev/null @@ -1,15 +0,0 @@ -#include "main.h" - -#ifndef CUBE_CAN_PRIVATE_COMMON_H -#define CUBE_CAN_PRIVATE_COMMON_H - -/** - * @brief Get the name of the FDCAN instance as a string. - * - * @param instance Pointer to the FDCAN instance. - * - * @return A string representing the name of the FDCAN instance. If the instance is not recognized, returns "UNKNOWN". - */ -const char *CAN_GetInstanceName(FDCAN_GlobalTypeDef *instance); - -#endif diff --git a/Lib/Peripherals/CubeCAN/Src/can_init.c b/Lib/Peripherals/CubeCAN/Src/can_init.c new file mode 100644 index 000000000..2d164d059 --- /dev/null +++ b/Lib/Peripherals/CubeCAN/Src/can_init.c @@ -0,0 +1,208 @@ +#include +#include + +#include "CubeMXCan.h" +#include "CubeMXCanExt.h" +#include "Logomatic.h" +#include "Private/PrivateCubeMXCAN.h" + +typedef struct { + FDCAN_GlobalTypeDef *instance; + CubeMXCan_Handle *handle; +} CubeMXCan_RegistryEntry; + +static CubeMXCan_RegistryEntry s_registry[CUBEMX_CAN_MAX_INSTANCES] = {0}; +static CubeMXCan_Handle s_handles[CUBEMX_CAN_MAX_INSTANCES] = {0}; +static bool s_timer_started = false; + +static CubeMXCan_RegistryEntry *CubeMXCan_FindRegistryEntry(FDCAN_GlobalTypeDef *instance) +{ + for (uint32_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { + if (s_registry[i].instance == instance) { + return &s_registry[i]; + } + } + + return NULL; +} + +static CubeMXCan_RegistryEntry *CubeMXCan_AllocRegistryEntry(FDCAN_GlobalTypeDef *instance) +{ + CubeMXCan_RegistryEntry *entry = CubeMXCan_FindRegistryEntry(instance); + if (entry != NULL) { + return entry; + } + + for (uint32_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { + if (s_registry[i].instance == NULL) { + s_registry[i].instance = instance; + return &s_registry[i]; + } + } + + return NULL; +} + +CubeMXCan_Handle *CubeMXCan_Private_GetHandle(FDCAN_HandleTypeDef *hfdcan) +{ + if (hfdcan == NULL) { + return NULL; + } + + CubeMXCan_RegistryEntry *entry = CubeMXCan_FindRegistryEntry(hfdcan->Instance); + return (entry != NULL) ? entry->handle : NULL; +} + +HAL_StatusTypeDef CubeMXCan_Private_RegisterHandle(FDCAN_HandleTypeDef *hfdcan, CubeMXCan_Handle *handle) +{ + if (hfdcan == NULL || handle == NULL) { + return HAL_ERROR; + } + + CubeMXCan_RegistryEntry *entry = CubeMXCan_AllocRegistryEntry(hfdcan->Instance); + if (entry == NULL) { + return HAL_ERROR; + } + + entry->handle = handle; + return HAL_OK; +} + +void CubeMXCan_Private_UnregisterHandle(FDCAN_HandleTypeDef *hfdcan) +{ + if (hfdcan == NULL) { + return; + } + + CubeMXCan_RegistryEntry *entry = CubeMXCan_FindRegistryEntry(hfdcan->Instance); + if (entry != NULL) { + entry->instance = NULL; + entry->handle = NULL; + } +} + +void CubeMXCan_Tick(void) +{ + for (uint32_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { + CubeMXCan_Handle *handle = s_registry[i].handle; + if (handle == NULL || !handle->started) { + continue; + } + + (void)CubeMXCan_Private_SendQueuedMessage(handle); + } +} + +CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, const CubeCAN_Config *config) +{ + if (hfdcan == NULL || config == NULL) { + return NULL; + } + + CubeMXCan_Handle *handle = CubeMXCan_Private_GetHandle(hfdcan); + if (handle == NULL) { + for (uint32_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { + if (s_handles[i].hfdcan == NULL) { + handle = &s_handles[i]; + memset(handle, 0, sizeof(*handle)); + handle->hfdcan = hfdcan; + break; + } + } + } + + if (handle == NULL) { + LOGOMATIC("CubeMXCan_Init: no free handle slots\n"); + return NULL; + } + + handle->config = *config; + handle->tx_head = 0U; + handle->tx_count = 0U; + handle->started = false; + + if (CubeMXCan_Private_RegisterHandle(hfdcan, handle) != HAL_OK) { + LOGOMATIC("CubeMXCan_Init: failed to register handle\n"); + return NULL; + } + + uint32_t rx_events = FDCAN_IT_RX_FIFO0_NEW_MESSAGE | FDCAN_IT_RX_FIFO0_FULL | FDCAN_IT_RX_FIFO0_MESSAGE_LOST; + if (HAL_FDCAN_ActivateNotification(hfdcan, rx_events, 0U) != HAL_OK) { + LOGOMATIC("CubeMXCan_Init: failed to activate RX notifications\n"); + return NULL; + } + + if (!s_timer_started) { + s_timer_started = true; + } + + return handle; +} + +HAL_StatusTypeDef CubeMXCan_Start(CubeMXCan_Handle *handle) +{ + if (handle == NULL || handle->hfdcan == NULL) { + return HAL_ERROR; + } + + if (HAL_FDCAN_Start(handle->hfdcan) != HAL_OK) { + return HAL_ERROR; + } + + handle->started = true; + return HAL_OK; +} + +HAL_StatusTypeDef CubeMXCan_Stop(CubeMXCan_Handle *handle) +{ + if (handle == NULL || handle->hfdcan == NULL) { + return HAL_ERROR; + } + + if (HAL_FDCAN_Stop(handle->hfdcan) != HAL_OK) { + return HAL_ERROR; + } + + handle->started = false; + + return HAL_OK; +} + +HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *handle) +{ + if (handle == NULL || handle->hfdcan == NULL) { + return HAL_ERROR; + } + + (void)CubeMXCan_Stop(handle); + CubeMXCan_Private_UnregisterHandle(handle->hfdcan); + memset(handle, 0, sizeof(*handle)); + return HAL_OK; +} + +HAL_StatusTypeDef CubeMXCan_AddFilter(CubeMXCan_Handle *handle, const FDCAN_FilterTypeDef *filter) +{ + if (handle == NULL || handle->hfdcan == NULL || filter == NULL) { + return HAL_ERROR; + } + + return HAL_FDCAN_ConfigFilter(handle->hfdcan, (FDCAN_FilterTypeDef *)filter); +} + +HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *handle, const GRCAN_TxMessage *message) +{ + if (handle == NULL || message == NULL) { + return HAL_ERROR; + } + + uint32_t insert_index = (handle->tx_head + handle->tx_count) % CUBEMX_CAN_TX_QUEUE_SIZE; + handle->tx_queue[insert_index] = *message; + + if (handle->tx_count < CUBEMX_CAN_TX_QUEUE_SIZE) { + handle->tx_count++; + } else { + handle->tx_head = (handle->tx_head + 1U) % CUBEMX_CAN_TX_QUEUE_SIZE; + } + + return HAL_OK; +} diff --git a/Lib/Peripherals/CubeCAN/Src/can_it.c b/Lib/Peripherals/CubeCAN/Src/can_it.c index 242e861fe..309f6d174 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_it.c +++ b/Lib/Peripherals/CubeCAN/Src/can_it.c @@ -1,127 +1,59 @@ #include -#include +#include #include "CubeCAN_Config.h" #include "CubeMXCan.h" #include "CubeMXCanExt.h" #include "Logomatic.h" -#include "Private/common.h" -#include "main.h" +#include "Private/PrivateCubeMXCAN.h" -void FDCAN1_IT0_IRQHandler(void) +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { -#ifdef USECAN1 - HAL_FDCAN_IRQHandler(&hal_fdcan1); -#endif + if (htim != NULL && htim->Instance == CUBEMX_CAN_TIMER_INSTANCE) { + CubeMXCan_Tick(); + } } -void FDCAN1_IT1_IRQHandler(void) +void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) { -#ifdef USECAN1 - HAL_FDCAN_IRQHandler(&hal_fdcan1); -#endif + (void)RxFifo0ITs; + CubeMXCan_OnRxFifo0(hfdcan); } -void FDCAN2_IT0_IRQHandler(void) -{ -#ifdef USECAN2 - HAL_FDCAN_IRQHandler(&hal_fdcan2); -#endif -} -void FDCAN2_IT1_IRQHandler(void) +void HAL_FDCAN_TxBufferCompleteCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndexes) { -#ifdef USECAN2 - HAL_FDCAN_IRQHandler(&hal_fdcan2); -#endif + (void)hfdcan; + (void)BufferIndexes; } -void FDCAN3_IT0_IRQHandler(void) +void CubeMXCan_Private_DispatchRx(FDCAN_HandleTypeDef *hfdcan) { -#ifdef USECAN3 - HAL_FDCAN_IRQHandler(&hal_fdcan3); -#endif -} -void FDCAN3_IT1_IRQHandler(void) -{ -#ifdef USECAN3 - HAL_FDCAN_IRQHandler(&hal_fdcan3); -#endif + CubeMXCan_OnRxFifo0(hfdcan); } -void CAN_Timer_Start(void) +void CubeMXCan_OnRxFifo0(FDCAN_HandleTypeDef *hfdcan) { - static bool initialized = false; - - if (initialized) { - LOGOMATIC("CAN_Timer_Start: timer is already initialized\n"); + if (hfdcan == NULL) { return; } - RCC_ClkInitTypeDef clkconfig = {0}; - uint32_t latency = 0; - HAL_RCC_GetClockConfig(&clkconfig, &latency); - - uint32_t apb1_div = clkconfig.APB1CLKDivider; - uint32_t tim_clock = (apb1_div == RCC_HCLK_DIV1) ? HAL_RCC_GetPCLK1Freq() : (2U * HAL_RCC_GetPCLK1Freq()); - - // 10 kHz counter clock keeps both PSC/ARR in range for a 1 second period. - const uint32_t counter_hz = 10000U; - if (tim_clock < counter_hz) { - LOGOMATIC("CAN_Timer_Start: APB1 clock is too slow to achieve desired timer frequency\n"); - return; - } - - uint32_t prescaler = (tim_clock / counter_hz) - 1U; - if (prescaler > 0xFFFFU) { - LOGOMATIC("CAN_Timer_Start: failed to initialize timer prescaler\n"); + CubeMXCan_Handle *handle = CubeMXCan_Private_GetHandle(hfdcan); + if (handle == NULL || handle->config.rx_callback == NULL) { + FDCAN_RxHeaderTypeDef rx_header = {0}; + uint8_t rx_data[FDCAN_MAX_DATA_BYTES] = {0}; + (void)HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &rx_header, rx_data); + LOGOMATIC("CubeMXCan_OnRxFifo0: no handle or callback registered for %s\n", can_get_instance_name(hfdcan->Instance)); return; } - uint32_t autoreload = ((CAN_TIMER_SEND_PERIOD_US * counter_hz) / 1000000U) - 1U; - if (autoreload > 0xFFFFU) { - LOGOMATIC("CAN_Timer_Start: failed to initialize timer autoreload\n"); + FDCAN_RxHeaderTypeDef rx_header = {0}; + uint8_t rx_data[FDCAN_MAX_DATA_BYTES] = {0}; + if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &rx_header, rx_data) != HAL_OK) { + LOGOMATIC("CubeMXCan_OnRxFifo0: failed to get RX message\n"); return; } - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM5); - - LL_TIM_InitTypeDef tim_init = {0}; - tim_init.Prescaler = prescaler; - tim_init.CounterMode = LL_TIM_COUNTERMODE_UP; - tim_init.Autoreload = autoreload; - tim_init.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; - - if (LL_TIM_Init(TIM5, &tim_init) != SUCCESS) { - LOGOMATIC("CAN_Timer_Start: failed to initialize timer\n"); - return; - } - - LL_TIM_SetClockSource(TIM5, LL_TIM_CLOCKSOURCE_INTERNAL); - LL_TIM_ClearFlag_UPDATE(TIM5); - LL_TIM_EnableIT_UPDATE(TIM5); - - HAL_NVIC_SetPriority(TIM5_IRQn, 15U, 0U); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - - LL_TIM_EnableCounter(TIM5); - - initialized = true; - LOGOMATIC("CAN_Timer_Start: timer initialized\n"); - return; -} - -void TIM5_IRQHandler(void) -{ - if (LL_TIM_IsActiveFlag_UPDATE(TIM5)) { - LL_TIM_ClearFlag_UPDATE(TIM5); -#ifdef USECAN1 - can_tx_dequeue_helper(can_get_handle(&hal_fdcan1)); -#endif -#ifdef USECAN2 - can_tx_dequeue_helper(can_get_handle(&hal_fdcan2)); -#endif -#ifdef USECAN3 - can_tx_dequeue_helper(can_get_handle(&hal_fdcan3)); -#endif - } + CAN_Identifier identifier = Deconstruct_CAN_Identifier(rx_header.Identifier); + uint8_t size = CubeMXCan_Private_DlcToBytes(rx_header.DataLength); + handle->config.rx_callback(handle->config.user_ctx, &identifier, rx_data, size); } diff --git a/Lib/Peripherals/CubeCAN/Src/can_mcu.c b/Lib/Peripherals/CubeCAN/Src/can_mcu.c deleted file mode 100644 index 68edf9675..000000000 --- a/Lib/Peripherals/CubeCAN/Src/can_mcu.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "CubeMXCan.h" -#include "CubeMXCanExt.h" -#include "Logomatic.h" -#include "Private/common.h" - -const char *CAN_GetInstanceName(FDCAN_GlobalTypeDef *instance) -{ - if (instance == NULL) { - return "NULL"; - } -#if defined(STM32G474xx) - if (instance == FDCAN1) { - return "FDCAN1"; - } else if (instance == FDCAN2) { - return "FDCAN2"; - } else if (instance == FDCAN3) { - return "FDCAN3"; - } -#elif defined(STM32G431xx) - if (instance == FDCAN1) { - return "FDCAN1"; - } -#endif - LOGOMATIC("Get CAN instance name: unknown instance\n"); - return "UNKNOWN"; -} diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index 6119f63f0..2ba864b0a 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -4,15 +4,45 @@ #include "CubeMXCanExt.h" #include "GRCAN_MSG_ID.h" #include "GRCAN_NODE_ID.h" -#include "Private/common.h" +#include "Logomatic.h" +#include "Private/PrivateCubeMXCAN.h" + +static const uint8_t s_dlc_to_bytes[] = {0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 12U, 16U, 20U, 24U, 32U, 48U, 64U}; + +const char *CAN_GetInstanceName(FDCAN_GlobalTypeDef *instance) +{ + if (instance == NULL) { + return "NULL"; + } +#ifdef USECAN1 + if (instance == FDCAN1) { + return "FDCAN1"; + } +#endif +#ifdef USECAN2 + if (instance == FDCAN2) { + return "FDCAN2"; + } +#endif +#ifdef USECAN3 + if (instance == FDCAN3) { + return "FDCAN3"; + } +#endif + LOGOMATIC("Get CAN instance name: unknown instance\n"); + return "UNKNOWN"; +} uint32_t Construct_CAN_Identifier(const CAN_Identifier *identifier) { - uint32_t message_id = 0; + if (identifier == NULL) { + return 0U; + } - message_id |= ((0xFF & identifier->tx_node_id) << 20); - message_id |= ((0xFFF & identifier->msg_id) << 8); - message_id |= (0xFF & identifier->rx_node_id); + uint32_t message_id = 0U; + message_id |= ((uint32_t)(identifier->tx_node_id & 0xFFU) << 20U); + message_id |= ((uint32_t)(identifier->msg_id & 0xFFFU) << 8U); + message_id |= (uint32_t)(identifier->rx_node_id & 0xFFU); return message_id; } @@ -21,9 +51,50 @@ CAN_Identifier Deconstruct_CAN_Identifier(uint32_t message_id) { CAN_Identifier identifier = {0}; - identifier.tx_node_id = (GRCAN_NODE_ID)((message_id >> 20) & 0xFF); - identifier.msg_id = (GRCAN_MSG_ID)((message_id >> 8) & 0xFFF); - identifier.rx_node_id = (GRCAN_NODE_ID)(message_id & 0xFF); + identifier.tx_node_id = (GRCAN_NODE_ID)((message_id >> 20U) & 0xFFU); + identifier.msg_id = (GRCAN_MSG_ID)((message_id >> 8U) & 0xFFFU); + identifier.rx_node_id = (GRCAN_NODE_ID)(message_id & 0xFFU); return identifier; } + +HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *identifier, uint32_t filter_index, uint32_t fifo, FDCAN_FilterTypeDef *filter) +{ + if (identifier == NULL || filter == NULL) { + return HAL_ERROR; + } + + filter->IdType = FDCAN_EXTENDED_ID; + filter->FilterIndex = filter_index; + filter->FilterType = FDCAN_FILTER_MASK; + filter->FilterConfig = fifo; + filter->FilterID1 = Construct_CAN_Identifier(identifier); + filter->FilterID2 = 0x1FFFFFFFU; + + return HAL_OK; +} + +uint8_t CubeMXCan_Private_DlcToBytes(uint32_t dlc) +{ + if (dlc > 15U) { + return 64U; + } + + return s_dlc_to_bytes[dlc]; +} + +HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(CubeMXCan_Handle *handle) +{ + if (handle == NULL || handle->hfdcan == NULL || handle->tx_count == 0U) { + return HAL_OK; + } + + const GRCAN_TxMessage *message = &handle->tx_queue[handle->tx_head]; + if (HAL_FDCAN_AddMessageToTxFifoQ(handle->hfdcan, &message->tx_header, message->data) != HAL_OK) { + return HAL_ERROR; + } + + handle->tx_head = (handle->tx_head + 1U) % CUBEMX_CAN_TX_QUEUE_SIZE; + handle->tx_count--; + return HAL_OK; +} diff --git a/Lib/Peripherals/CubeCAN/cubemx_can.cmake b/Lib/Peripherals/CubeCAN/cubemx_can.cmake index 85cd3db36..3fe5c3cd6 100644 --- a/Lib/Peripherals/CubeCAN/cubemx_can.cmake +++ b/Lib/Peripherals/CubeCAN/cubemx_can.cmake @@ -11,6 +11,7 @@ target_sources( INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Src/can_it.c ${CMAKE_CURRENT_LIST_DIR}/Src/can_utils.c + ${CMAKE_CURRENT_LIST_DIR}/Src/can_init.c ) target_link_libraries( From 56c3365d5dc903b5f4f3b7819bbeffa7ee072366 Mon Sep 17 00:00:00 2001 From: TrainmanR Date: Thu, 16 Jul 2026 14:31:40 -0700 Subject: [PATCH 017/125] Timer Update Allows timer to be selected in the CubeMX GUI and generates the necessary code for timer initializat ion and interrupt handling. --- CUBEMXTESTING/CUBEMXTESTING.ioc | 19 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 2 +- CUBEMXTESTING/Core/Inc/stm32g4xx_it.h | 1 + CUBEMXTESTING/Core/Inc/tim.h | 52 ++++ CUBEMXTESTING/Core/Src/main.c | 24 ++ CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 85 ++++++ CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 16 +- CUBEMXTESTING/Core/Src/tim.c | 112 ++++++++ CUBEMXTESTING/can_cfg_h.updated | 145 ++++++++++ .../Autogen/Inc/can_cfg_h_updated.ftl | 268 ++++++++++++++++++ 10 files changed, 719 insertions(+), 5 deletions(-) create mode 100644 CUBEMXTESTING/Core/Inc/tim.h create mode 100644 CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c create mode 100644 CUBEMXTESTING/Core/Src/tim.c create mode 100644 CUBEMXTESTING/can_cfg_h.updated create mode 100644 Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h_updated.ftl diff --git a/CUBEMXTESTING/CUBEMXTESTING.ioc b/CUBEMXTESTING/CUBEMXTESTING.ioc index be9a705f8..7c2f2f98e 100644 --- a/CUBEMXTESTING/CUBEMXTESTING.ioc +++ b/CUBEMXTESTING/CUBEMXTESTING.ioc @@ -42,7 +42,8 @@ Mcu.IP1=FDCAN2 Mcu.IP2=NVIC Mcu.IP3=RCC Mcu.IP4=SYS -Mcu.IPNb=5 +Mcu.IP5=TIM5 +Mcu.IPNb=6 Mcu.Name=STM32G474R(B-C-E)Tx Mcu.Package=LQFP64 Mcu.Pin0=PC13 @@ -53,7 +54,8 @@ Mcu.Pin4=PB8-BOOT0 Mcu.Pin5=PB9 Mcu.Pin6=VP_SYS_VS_Systick Mcu.Pin7=VP_SYS_VS_DBSignals -Mcu.PinsNb=8 +Mcu.Pin8=VP_TIM5_VS_ClockSourceINT +Mcu.PinsNb=9 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32G474RETx @@ -69,6 +71,7 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false +NVIC.TIM5_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false PA5.GPIOParameters=GPIO_Label PA5.GPIO_Label=USER_LED @@ -115,11 +118,16 @@ ProjectManager.ProjectStructure= ProjectManager.RegisterCallBack= ProjectManager.StackSize=0x400 ProjectManager.TargetToolchain=EWARM V8.50 +ProjectManager.TemplateDestinationPath=C\:\\Users\\maxnm\\Firmware\\CUBEMXTESTING +ProjectManager.TemplateSourcePath=C\:\\Users\\maxnm\\Firmware\\Lib\\CubeMXTemplates\\Autogen\\Inc +ProjectManager.TemplatesList=\\can_cfg_h_updated.ftl, ProjectManager.ToolChainLocation= ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true +ProjectManager.UseDefaultDestinationPath=true +ProjectManager.UseDefaultSourcePath=true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_TIM5_Init-TIM5-false-HAL-true RCC.ADC12Freq_Value=160000000 RCC.ADC345Freq_Value=160000000 RCC.AHBFreq_Value=160000000 @@ -168,8 +176,13 @@ RCC.USART3Freq_Value=160000000 RCC.USBFreq_Value=160000000 RCC.VCOInputFreq_Value=16000000 RCC.VCOOutputFreq_Value=320000000 +TIM5.IPParameters=Prescaler,PeriodNoDither +TIM5.PeriodNoDither=999 +TIM5.Prescaler=15999 VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals VP_SYS_VS_Systick.Mode=SysTick VP_SYS_VS_Systick.Signal=SYS_VS_Systick +VP_TIM5_VS_ClockSourceINT.Mode=Internal +VP_TIM5_VS_ClockSourceINT.Signal=TIM5_VS_ClockSourceINT board=custom diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index 16ef7e356..33793dda8 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -62,7 +62,7 @@ /*#define HAL_SMBUS_MODULE_ENABLED */ /*#define HAL_SPI_MODULE_ENABLED */ /*#define HAL_SRAM_MODULE_ENABLED */ -/*#define HAL_TIM_MODULE_ENABLED */ +#define HAL_TIM_MODULE_ENABLED /*#define HAL_UART_MODULE_ENABLED */ /*#define HAL_USART_MODULE_ENABLED */ /*#define HAL_WWDG_MODULE_ENABLED */ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h index 1a144ad22..980377814 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h @@ -55,6 +55,7 @@ void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); +void TIM5_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h new file mode 100644 index 000000000..18374feb3 --- /dev/null +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -0,0 +1,52 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file tim.h + * @brief This file contains all the function prototypes for + * the tim.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 __TIM_H__ +#define __TIM_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern TIM_HandleTypeDef htim5; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_TIM5_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIM_H__ */ + diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 45a24d683..54131f9fd 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -19,6 +19,7 @@ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "fdcan.h" +#include "tim.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ @@ -26,6 +27,10 @@ #include "Logomatic.h" #include "loop.h" #include "vcp.h" + +#include "can.h" +#include "can_cfg.h" +#include "gr_can_init.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -116,9 +121,16 @@ int main(void) MX_GPIO_Init(); MX_FDCAN1_Init(); MX_FDCAN2_Init(); + MX_TIM5_Init(); /* USER CODE BEGIN 2 */ Logomatic_Init(&logomaticConfig); VCP_Init(&vcp_config); + + GR_CAN_Init(); + + if (CAN_Timer_Start() != HAL_OK) { + Error_Handler(); + } /* USER CODE END 2 */ /* Infinite loop */ @@ -183,6 +195,18 @@ void SystemClock_Config(void) /* USER CODE BEGIN 4 */ +/** + * @brief Route the CubeMX-generated CAN service timer callback to the CAN runtime. + * + * CAN_TIMER_HANDLE is generated by can_cfg.h from CAN_TIMER_INDEX. + */ +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) +{ + if (htim == &CAN_TIMER_HANDLE) { + CAN_Timer_Tick(); + } +} + /* USER CODE END 4 */ /** diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c new file mode 100644 index 000000000..d908bd772 --- /dev/null +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -0,0 +1,85 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g4xx_hal_msp.c + * @brief This file provides code for the MSP Initialization + * and de-Initialization codes. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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*/ + + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); + + /* USER CODE BEGIN MspInit 1 */ + + /* USER CODE END MspInit 1 */ +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index 13e0f0c20..b4fb77dff 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -55,7 +55,7 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ - +extern TIM_HandleTypeDef htim5; /* USER CODE BEGIN EV */ /* USER CODE END EV */ @@ -198,6 +198,20 @@ void SysTick_Handler(void) /* please refer to the startup file (startup_stm32g4xx.s). */ /******************************************************************************/ +/** + * @brief This function handles TIM5 global interrupt. + */ +void TIM5_IRQHandler(void) +{ + /* USER CODE BEGIN TIM5_IRQn 0 */ + + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ + + /* USER CODE END TIM5_IRQn 1 */ +} + /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c new file mode 100644 index 000000000..d1aa2063a --- /dev/null +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -0,0 +1,112 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file tim.c + * @brief This file provides code for the configuration + * of the TIM instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "tim.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +TIM_HandleTypeDef htim5; + +/* TIM5 init function */ +void MX_TIM5_Init(void) +{ + + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 15999; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 999; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) + { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ + + /* USER CODE END TIM5_Init 2 */ + +} + +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) +{ + + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspInit 0 */ + + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); + + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ + + /* USER CODE END TIM5_MspInit 1 */ + } +} + +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) +{ + + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ + + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); + + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ + + /* USER CODE END TIM5_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/can_cfg_h.updated b/CUBEMXTESTING/can_cfg_h.updated new file mode 100644 index 000000000..288ec9a9b --- /dev/null +++ b/CUBEMXTESTING/can_cfg_h.updated @@ -0,0 +1,145 @@ + +#ifndef CAN_CFG_H +#define CAN_CFG_H + +/* Generated automatically by STM32CubeMX FreeMarker. */ + +/* + * User-editable CAN runtime configuration. + * + * CAN_TIMER_INDEX: + * Selects the CubeMX-generated timer handle. Example: 5 selects htim5. + * + * CAN_TIMER_TICK_US: + * Duration of one timer counter tick, determined by the CubeMX prescaler. + * For a 160 MHz TIM clock and Prescaler = 15999, one tick is 100 us. + * + * CAN_DEQUEUE_PERIOD_US: + * Time between attempts to dequeue and send one software-queued CAN message. + */ +/* USER CODE BEGIN CAN_USER_CONFIG */ + +#ifndef TX_BUFFER_1_SIZE +#define TX_BUFFER_1_SIZE 20U +#endif + +#ifndef TX_BUFFER_2_SIZE +#define TX_BUFFER_2_SIZE 20U +#endif + +#ifndef TX_BUFFER_3_SIZE +#define TX_BUFFER_3_SIZE 20U +#endif + +#ifndef CAN_TIMER_INDEX +#define CAN_TIMER_INDEX 5 +#endif + +#ifndef CAN_TIMER_TICK_US +#define CAN_TIMER_TICK_US 100U +#endif + +#ifndef CAN_DEQUEUE_PERIOD_US +#define CAN_DEQUEUE_PERIOD_US 500U +#endif + +/* USER CODE END CAN_USER_CONFIG */ + +/* Enabled FDCAN peripherals. */ + +#define USECAN1 + +#define USECAN2 + +/* Timers enabled in CubeMX. */ + +#define CUBEMX_HAS_TIM5 + +/* Configuration validation. */ + +#if defined(USECAN1) && (TX_BUFFER_1_SIZE == 0U) +#error "TX_BUFFER_1_SIZE must be greater than zero" +#endif + +#if defined(USECAN2) && (TX_BUFFER_2_SIZE == 0U) +#error "TX_BUFFER_2_SIZE must be greater than zero" +#endif + +#if defined(USECAN3) && (TX_BUFFER_3_SIZE == 0U) +#error "TX_BUFFER_3_SIZE must be greater than zero" +#endif + +#if CAN_TIMER_TICK_US == 0U +#error "CAN_TIMER_TICK_US must be greater than zero" +#endif + +#if CAN_DEQUEUE_PERIOD_US == 0U +#error "CAN_DEQUEUE_PERIOD_US must be greater than zero" +#endif + +#if CAN_DEQUEUE_PERIOD_US < CAN_TIMER_TICK_US +#error "CAN_DEQUEUE_PERIOD_US cannot be shorter than one timer tick" +#endif + +#if (CAN_DEQUEUE_PERIOD_US % CAN_TIMER_TICK_US) != 0U +#error "CAN_DEQUEUE_PERIOD_US must be divisible by CAN_TIMER_TICK_US" +#endif + +#if ((CAN_DEQUEUE_PERIOD_US / CAN_TIMER_TICK_US) - 1U) > 0xFFFFFFFFU +#error "CAN dequeue period exceeds the supported timer auto-reload range" +#endif + +#if (CAN_TIMER_INDEX == 1) && !defined(CUBEMX_HAS_TIM1) +#error "CAN_TIMER_INDEX selects TIM1, but TIM1 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 2) && !defined(CUBEMX_HAS_TIM2) +#error "CAN_TIMER_INDEX selects TIM2, but TIM2 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 3) && !defined(CUBEMX_HAS_TIM3) +#error "CAN_TIMER_INDEX selects TIM3, but TIM3 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 4) && !defined(CUBEMX_HAS_TIM4) +#error "CAN_TIMER_INDEX selects TIM4, but TIM4 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 5) && !defined(CUBEMX_HAS_TIM5) +#error "CAN_TIMER_INDEX selects TIM5, but TIM5 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 6) && !defined(CUBEMX_HAS_TIM6) +#error "CAN_TIMER_INDEX selects TIM6, but TIM6 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 7) && !defined(CUBEMX_HAS_TIM7) +#error "CAN_TIMER_INDEX selects TIM7, but TIM7 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 8) && !defined(CUBEMX_HAS_TIM8) +#error "CAN_TIMER_INDEX selects TIM8, but TIM8 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 15) && !defined(CUBEMX_HAS_TIM15) +#error "CAN_TIMER_INDEX selects TIM15, but TIM15 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 16) && !defined(CUBEMX_HAS_TIM16) +#error "CAN_TIMER_INDEX selects TIM16, but TIM16 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 17) && !defined(CUBEMX_HAS_TIM17) +#error "CAN_TIMER_INDEX selects TIM17, but TIM17 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX != 1) && \ + (CAN_TIMER_INDEX != 2) && \ + (CAN_TIMER_INDEX != 3) && \ + (CAN_TIMER_INDEX != 4) && \ + (CAN_TIMER_INDEX != 5) && \ + (CAN_TIMER_INDEX != 6) && \ + (CAN_TIMER_INDEX != 7) && \ + (CAN_TIMER_INDEX != 8) && \ + (CAN_TIMER_INDEX != 15) && \ + (CAN_TIMER_INDEX != 16) && \ + (CAN_TIMER_INDEX != 17) +#error "CAN_TIMER_INDEX selects an unsupported timer" +#endif + +#define CAN_TIMER_PERIOD_COUNTS \ + (CAN_DEQUEUE_PERIOD_US / CAN_TIMER_TICK_US) + +#define CAN_TIMER_AUTORELOAD \ + (CAN_TIMER_PERIOD_COUNTS - 1U) + +/* + * Convert CAN_TIMER_INDEX into CubeMX's generated HAL timer handle. + * + * CAN_TIMER_INDEX = 5 + * CAN_TIMER_HANDLE = htim5 + */ +#define CAN_CFG_JOIN_INNER(a, b) a##b +#define CAN_CFG_JOIN(a, b) CAN_CFG_JOIN_INNER(a, b) +#define CAN_TIMER_HANDLE CAN_CFG_JOIN(htim, CAN_TIMER_INDEX) + +#endif /* CAN_CFG_H */ + diff --git a/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h_updated.ftl b/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h_updated.ftl new file mode 100644 index 000000000..815c29617 --- /dev/null +++ b/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h_updated.ftl @@ -0,0 +1,268 @@ +[#ftl] +[#-- + Generates can_cfg.h from the active STM32CubeMX project. + + Detects enabled FDCAN and TIM peripherals and emits compile-time configuration + for the Gaucho Racing CAN runtime. + + CubeMX remains responsible for: + - FDCAN clocks, GPIO, bit timing, HAL handles, and MX_FDCANx_Init() + - TIM clocks, prescaler, NVIC configuration, HAL handle, and MX_TIMx_Init() + + The CAN runtime uses the selected CubeMX-generated TIM handle to periodically + service its software TX queues. +--] + +[#list configs as dt] + +[#assign usedIPs = (dt.usedIPs)![]] + +[#assign hasFDCAN1 = false] +[#assign hasFDCAN2 = false] +[#assign hasFDCAN3 = false] + +[#assign hasTIM1 = false] +[#assign hasTIM2 = false] +[#assign hasTIM3 = false] +[#assign hasTIM4 = false] +[#assign hasTIM5 = false] +[#assign hasTIM6 = false] +[#assign hasTIM7 = false] +[#assign hasTIM8 = false] +[#assign hasTIM15 = false] +[#assign hasTIM16 = false] +[#assign hasTIM17 = false] + +[#list usedIPs as ip] + [#assign ipName = ip?string] + + [#if ipName == "FDCAN1"] + [#assign hasFDCAN1 = true] + [/#if] + [#if ipName == "FDCAN2"] + [#assign hasFDCAN2 = true] + [/#if] + [#if ipName == "FDCAN3"] + [#assign hasFDCAN3 = true] + [/#if] + + [#if ipName == "TIM1"] + [#assign hasTIM1 = true] + [/#if] + [#if ipName == "TIM2"] + [#assign hasTIM2 = true] + [/#if] + [#if ipName == "TIM3"] + [#assign hasTIM3 = true] + [/#if] + [#if ipName == "TIM4"] + [#assign hasTIM4 = true] + [/#if] + [#if ipName == "TIM5"] + [#assign hasTIM5 = true] + [/#if] + [#if ipName == "TIM6"] + [#assign hasTIM6 = true] + [/#if] + [#if ipName == "TIM7"] + [#assign hasTIM7 = true] + [/#if] + [#if ipName == "TIM8"] + [#assign hasTIM8 = true] + [/#if] + [#if ipName == "TIM15"] + [#assign hasTIM15 = true] + [/#if] + [#if ipName == "TIM16"] + [#assign hasTIM16 = true] + [/#if] + [#if ipName == "TIM17"] + [#assign hasTIM17 = true] + [/#if] +[/#list] + +#ifndef CAN_CFG_H +#define CAN_CFG_H + +/* Generated automatically by STM32CubeMX FreeMarker. */ + +/* + * User-editable CAN runtime configuration. + * + * CAN_TIMER_INDEX: + * Selects the CubeMX-generated timer handle. Example: 5 selects htim5. + * + * CAN_TIMER_TICK_US: + * Duration of one timer counter tick, determined by the CubeMX prescaler. + * For a 160 MHz TIM clock and Prescaler = 15999, one tick is 100 us. + * + * CAN_DEQUEUE_PERIOD_US: + * Time between attempts to dequeue and send one software-queued CAN message. + */ +/* USER CODE BEGIN CAN_USER_CONFIG */ + +#ifndef TX_BUFFER_1_SIZE +#define TX_BUFFER_1_SIZE 20U +#endif + +#ifndef TX_BUFFER_2_SIZE +#define TX_BUFFER_2_SIZE 20U +#endif + +#ifndef TX_BUFFER_3_SIZE +#define TX_BUFFER_3_SIZE 20U +#endif + +#ifndef CAN_TIMER_INDEX +#define CAN_TIMER_INDEX 5 +#endif + +#ifndef CAN_TIMER_TICK_US +#define CAN_TIMER_TICK_US 100U +#endif + +#ifndef CAN_DEQUEUE_PERIOD_US +#define CAN_DEQUEUE_PERIOD_US 500U +#endif + +/* USER CODE END CAN_USER_CONFIG */ + +/* Enabled FDCAN peripherals. */ + +[#if hasFDCAN1] +#define USECAN1 +[/#if] + +[#if hasFDCAN2] +#define USECAN2 +[/#if] + +[#if hasFDCAN3] +#define USECAN3 +[/#if] + +/* Timers enabled in CubeMX. */ + +[#if hasTIM1] +#define CUBEMX_HAS_TIM1 +[/#if] +[#if hasTIM2] +#define CUBEMX_HAS_TIM2 +[/#if] +[#if hasTIM3] +#define CUBEMX_HAS_TIM3 +[/#if] +[#if hasTIM4] +#define CUBEMX_HAS_TIM4 +[/#if] +[#if hasTIM5] +#define CUBEMX_HAS_TIM5 +[/#if] +[#if hasTIM6] +#define CUBEMX_HAS_TIM6 +[/#if] +[#if hasTIM7] +#define CUBEMX_HAS_TIM7 +[/#if] +[#if hasTIM8] +#define CUBEMX_HAS_TIM8 +[/#if] +[#if hasTIM15] +#define CUBEMX_HAS_TIM15 +[/#if] +[#if hasTIM16] +#define CUBEMX_HAS_TIM16 +[/#if] +[#if hasTIM17] +#define CUBEMX_HAS_TIM17 +[/#if] + +/* Configuration validation. */ + +#if defined(USECAN1) && (TX_BUFFER_1_SIZE == 0U) +#error "TX_BUFFER_1_SIZE must be greater than zero" +#endif + +#if defined(USECAN2) && (TX_BUFFER_2_SIZE == 0U) +#error "TX_BUFFER_2_SIZE must be greater than zero" +#endif + +#if defined(USECAN3) && (TX_BUFFER_3_SIZE == 0U) +#error "TX_BUFFER_3_SIZE must be greater than zero" +#endif + +#if CAN_TIMER_TICK_US == 0U +#error "CAN_TIMER_TICK_US must be greater than zero" +#endif + +#if CAN_DEQUEUE_PERIOD_US == 0U +#error "CAN_DEQUEUE_PERIOD_US must be greater than zero" +#endif + +#if CAN_DEQUEUE_PERIOD_US < CAN_TIMER_TICK_US +#error "CAN_DEQUEUE_PERIOD_US cannot be shorter than one timer tick" +#endif + +#if (CAN_DEQUEUE_PERIOD_US % CAN_TIMER_TICK_US) != 0U +#error "CAN_DEQUEUE_PERIOD_US must be divisible by CAN_TIMER_TICK_US" +#endif + +#if ((CAN_DEQUEUE_PERIOD_US / CAN_TIMER_TICK_US) - 1U) > 0xFFFFFFFFU +#error "CAN dequeue period exceeds the supported timer auto-reload range" +#endif + +#if (CAN_TIMER_INDEX == 1) && !defined(CUBEMX_HAS_TIM1) +#error "CAN_TIMER_INDEX selects TIM1, but TIM1 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 2) && !defined(CUBEMX_HAS_TIM2) +#error "CAN_TIMER_INDEX selects TIM2, but TIM2 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 3) && !defined(CUBEMX_HAS_TIM3) +#error "CAN_TIMER_INDEX selects TIM3, but TIM3 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 4) && !defined(CUBEMX_HAS_TIM4) +#error "CAN_TIMER_INDEX selects TIM4, but TIM4 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 5) && !defined(CUBEMX_HAS_TIM5) +#error "CAN_TIMER_INDEX selects TIM5, but TIM5 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 6) && !defined(CUBEMX_HAS_TIM6) +#error "CAN_TIMER_INDEX selects TIM6, but TIM6 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 7) && !defined(CUBEMX_HAS_TIM7) +#error "CAN_TIMER_INDEX selects TIM7, but TIM7 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 8) && !defined(CUBEMX_HAS_TIM8) +#error "CAN_TIMER_INDEX selects TIM8, but TIM8 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 15) && !defined(CUBEMX_HAS_TIM15) +#error "CAN_TIMER_INDEX selects TIM15, but TIM15 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 16) && !defined(CUBEMX_HAS_TIM16) +#error "CAN_TIMER_INDEX selects TIM16, but TIM16 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 17) && !defined(CUBEMX_HAS_TIM17) +#error "CAN_TIMER_INDEX selects TIM17, but TIM17 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX != 1) && \ + (CAN_TIMER_INDEX != 2) && \ + (CAN_TIMER_INDEX != 3) && \ + (CAN_TIMER_INDEX != 4) && \ + (CAN_TIMER_INDEX != 5) && \ + (CAN_TIMER_INDEX != 6) && \ + (CAN_TIMER_INDEX != 7) && \ + (CAN_TIMER_INDEX != 8) && \ + (CAN_TIMER_INDEX != 15) && \ + (CAN_TIMER_INDEX != 16) && \ + (CAN_TIMER_INDEX != 17) +#error "CAN_TIMER_INDEX selects an unsupported timer" +#endif + +#define CAN_TIMER_PERIOD_COUNTS \ + (CAN_DEQUEUE_PERIOD_US / CAN_TIMER_TICK_US) + +#define CAN_TIMER_AUTORELOAD \ + (CAN_TIMER_PERIOD_COUNTS - 1U) + +/* + * Convert CAN_TIMER_INDEX into CubeMX's generated HAL timer handle. + * + * CAN_TIMER_INDEX = 5 + * CAN_TIMER_HANDLE = htim5 + */ +#define CAN_CFG_JOIN_INNER(a, b) a##b +#define CAN_CFG_JOIN(a, b) CAN_CFG_JOIN_INNER(a, b) +#define CAN_TIMER_HANDLE CAN_CFG_JOIN(htim, CAN_TIMER_INDEX) + +#endif /* CAN_CFG_H */ + +[/#list] From acc9c3639c31bfb98c6d3f52a2f00b8d2e00c2f2 Mon Sep 17 00:00:00 2001 From: TrainmanR Date: Thu, 16 Jul 2026 21:16:53 -0700 Subject: [PATCH 018/125] README_CAN_Timer_Configuration.md Added Added readme for information on changes/how-to guide. --- .../README_CAN_Timer_Configuration.md | 941 ++++++++++++++++++ 1 file changed, 941 insertions(+) create mode 100644 CUBEMXTESTING/README_CAN_Timer_Configuration.md diff --git a/CUBEMXTESTING/README_CAN_Timer_Configuration.md b/CUBEMXTESTING/README_CAN_Timer_Configuration.md new file mode 100644 index 000000000..ee8330180 --- /dev/null +++ b/CUBEMXTESTING/README_CAN_Timer_Configuration.md @@ -0,0 +1,941 @@ +# CAN Timer Configuration Guide + +This guide explains how to configure, modify, and extend the CubeMX-based CAN timer implementation. + +The current design uses STM32CubeMX for hardware configuration and a custom CAN runtime for software queue handling. + +--- + +# 1. Ownership Model + +## CubeMX controls + +CubeMX owns all hardware-level configuration: + +- enabled FDCAN peripherals +- enabled timer peripherals +- FDCAN GPIO pins +- FDCAN clock source +- FDCAN bit timing +- timer clock source +- timer prescaler +- initial timer period +- NVIC interrupt enable +- NVIC interrupt priority +- generated HAL handles +- generated interrupt handlers + +Examples: + +```c +FDCAN_HandleTypeDef hfdcan1; +FDCAN_HandleTypeDef hfdcan2; +TIM_HandleTypeDef htim5; +``` + +CubeMX also generates: + +```c +MX_FDCAN1_Init(); +MX_FDCAN2_Init(); +MX_TIM5_Init(); +``` + +Do not manually duplicate this hardware initialization inside the custom CAN library. + +## User-controlled runtime settings + +The user-controlled values are stored in the generated `can_cfg.h` file inside a preserved user-code section. + +Example: + +```c +/* USER CODE BEGIN CAN_USER_CONFIG */ + +#ifndef TX_BUFFER_1_SIZE +#define TX_BUFFER_1_SIZE 20U +#endif + +#ifndef TX_BUFFER_2_SIZE +#define TX_BUFFER_2_SIZE 20U +#endif + +#ifndef TX_BUFFER_3_SIZE +#define TX_BUFFER_3_SIZE 20U +#endif + +#ifndef CAN_TIMER_INDEX +#define CAN_TIMER_INDEX 5 +#endif + +#ifndef CAN_TIMER_TICK_US +#define CAN_TIMER_TICK_US 100U +#endif + +#ifndef CAN_DEQUEUE_PERIOD_US +#define CAN_DEQUEUE_PERIOD_US 500U +#endif + +/* USER CODE END CAN_USER_CONFIG */ +``` + +CubeMX preserves values inside this section when code is regenerated. + +--- + +# 2. Editable Values + +## `TX_BUFFER_1_SIZE` + +Controls the number of software-queued transmit messages for CAN1. + +```c +#define TX_BUFFER_1_SIZE 20U +``` + +Example: + +```c +#define TX_BUFFER_1_SIZE 50U +``` + +Use a larger value when CAN1 may temporarily produce messages faster than the hardware can transmit them. + +A larger queue consumes more RAM. + +## `TX_BUFFER_2_SIZE` + +Controls the software TX queue size for CAN2. + +```c +#define TX_BUFFER_2_SIZE 20U +``` + +## `TX_BUFFER_3_SIZE` + +Controls the software TX queue size for CAN3. + +```c +#define TX_BUFFER_3_SIZE 20U +``` + +This value is ignored when CAN3 is not enabled. + +Queue sizes must be greater than zero. + +--- + +## `CAN_TIMER_INDEX` + +Selects the CubeMX-generated timer used for CAN queue servicing. + +```c +#define CAN_TIMER_INDEX 5 +``` + +This maps to: + +```c +htim5 +``` + +Examples: + +```c +#define CAN_TIMER_INDEX 1 +``` + +selects: + +```c +htim1 +``` + +```c +#define CAN_TIMER_INDEX 2 +``` + +selects: + +```c +htim2 +``` + +```c +#define CAN_TIMER_INDEX 3 +``` + +selects: + +```c +htim3 +``` + +The selected timer must also be enabled in CubeMX. + +If the selected timer is not enabled, the generated configuration should produce a compile-time error. + +--- + +## `CAN_TIMER_TICK_US` + +Defines the duration of one timer counter tick in microseconds. + +```c +#define CAN_TIMER_TICK_US 100U +``` + +This value must match the timer prescaler configured in CubeMX. + +The equation is: + +```text +Timer counter frequency = +Timer input clock / (Prescaler + 1) +``` + +Then: + +```text +Timer tick duration = +1 / Timer counter frequency +``` + +For a 160 MHz timer clock and: + +```c +Prescaler = 15999 +``` + +the counter frequency is: + +```text +160,000,000 / 16,000 = 10,000 Hz +``` + +Therefore: + +```text +1 count = 100 us +``` + +The matching runtime value is: + +```c +#define CAN_TIMER_TICK_US 100U +``` + +### Example: 10 us timer tick + +To create a 10 us timer tick with a 160 MHz timer clock: + +```text +Prescaler = 1599 +``` + +because: + +```text +160,000,000 / 1600 = 100,000 Hz +``` + +Therefore: + +```text +1 count = 10 us +``` + +The matching configuration is: + +```c +#define CAN_TIMER_TICK_US 10U +``` + +Always change the prescaler through CubeMX. + +Do not manually edit the generated `tim.c` file. + +--- + +## `CAN_DEQUEUE_PERIOD_US` + +Controls how often the runtime attempts to dequeue and transmit a queued CAN message. + +```c +#define CAN_DEQUEUE_PERIOD_US 500U +``` + +For: + +```c +#define CAN_TIMER_TICK_US 100U +``` + +the timer uses: + +```text +500 us / 100 us = 5 counts +``` + +The auto-reload value becomes: + +```text +ARR = 5 - 1 = 4 +``` + +The generated macros calculate this automatically: + +```c +#define CAN_TIMER_PERIOD_COUNTS \ + (CAN_DEQUEUE_PERIOD_US / CAN_TIMER_TICK_US) + +#define CAN_TIMER_AUTORELOAD \ + (CAN_TIMER_PERIOD_COUNTS - 1U) +``` + +### Example periods + +With a 100 us timer tick: + +| Desired dequeue period | `CAN_DEQUEUE_PERIOD_US` | ARR | +|---:|---:|---:| +| 500 us | `500U` | 4 | +| 1 ms | `1000U` | 9 | +| 2 ms | `2000U` | 19 | +| 5 ms | `5000U` | 49 | +| 10 ms | `10000U` | 99 | +| 100 ms | `100000U` | 999 | + +The dequeue period must be evenly divisible by the timer tick. + +Valid: + +```c +#define CAN_TIMER_TICK_US 100U +#define CAN_DEQUEUE_PERIOD_US 500U +``` + +Invalid: + +```c +#define CAN_TIMER_TICK_US 100U +#define CAN_DEQUEUE_PERIOD_US 550U +``` + +The second example is invalid because 550 us cannot be represented exactly using 100 us timer counts. + +--- + +# 3. Changing the Active Timer + +To change from TIM5 to TIM2: + +## Step 1: Enable TIM2 in CubeMX + +In CubeMX: + +```text +Pinout & Configuration + Timers + TIM2 + Clock Source: Internal Clock +``` + +Configure the desired prescaler and period. + +Enable: + +```text +TIM2 global interrupt +``` + +## Step 2: Regenerate code + +CubeMX should generate: + +```c +TIM_HandleTypeDef htim2; +void MX_TIM2_Init(void); +``` + +and: + +```c +void TIM2_IRQHandler(void) +{ + HAL_TIM_IRQHandler(&htim2); +} +``` + +## Step 3: Change `can_cfg.h` + +```c +#define CAN_TIMER_INDEX 2 +``` + +## Step 4: Update the timer tick + +Set `CAN_TIMER_TICK_US` to match TIM2's prescaler. + +Example: + +```c +#define CAN_TIMER_TICK_US 100U +``` + +## Step 5: Initialize TIM2 in `main.c` + +CubeMX should generate: + +```c +MX_TIM2_Init(); +``` + +before: + +```c +CAN_Timer_Start(); +``` + +--- + +# 4. Using One Shared Timer + +The current implementation uses one selected timer for all enabled CAN buses. + +Example: + +```text +TIM5 + | + +--> CAN_Timer_Tick() + | + +--> service CAN1 queue + +--> service CAN2 queue +``` + +This is the recommended design in most cases. + +Advantages: + +- fewer hardware timers used +- simpler configuration +- simpler startup +- one callback +- easier CubeMX integration +- easier synchronization between CAN buses + +The callback is: + +```c +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) +{ + if (htim == &CAN_TIMER_HANDLE) { + CAN_Timer_Tick(); + } +} +``` + +--- + +# 5. Servicing Multiple CAN Buses + +## Priority-based scheduling + +This approach always checks CAN1 first: + +```c +void CAN_Timer_Tick(void) +{ +#ifdef USECAN1 + if (CAN_ProcessOneTxMessage(&can1)) { + return; + } +#endif + +#ifdef USECAN2 + if (CAN_ProcessOneTxMessage(&can2)) { + return; + } +#endif + +#ifdef USECAN3 + (void)CAN_ProcessOneTxMessage(&can3); +#endif +} +``` + +Advantages: + +- simple +- supports bus priority + +Disadvantage: + +- lower-priority buses can be starved + +## Round-robin scheduling + +This approach alternates between buses: + +```c +void CAN_Timer_Tick(void) +{ + static uint8_t next_bus = 0U; + +#if defined(USECAN1) && defined(USECAN2) + + if (next_bus == 0U) { + (void)CAN_ProcessOneTxMessage(&can1); + next_bus = 1U; + } else { + (void)CAN_ProcessOneTxMessage(&can2); + next_bus = 0U; + } + +#elif defined(USECAN1) + + (void)CAN_ProcessOneTxMessage(&can1); + +#elif defined(USECAN2) + + (void)CAN_ProcessOneTxMessage(&can2); + +#endif +} +``` + +Advantages: + +- fairer between buses +- avoids CAN1 permanently dominating CAN2 + +--- + +# 6. Using Multiple Active Timers + +The current template selects one shared timer. + +It can be extended so each CAN peripheral uses a separate timer. + +Example: + +```text +TIM1 services CAN1 +TIM2 services CAN2 +TIM3 services CAN3 +``` + +Use separate configuration values: + +```c +#define CAN1_TIMER_INDEX 1 +#define CAN2_TIMER_INDEX 2 +#define CAN3_TIMER_INDEX 3 + +#define CAN1_TIMER_TICK_US 100U +#define CAN2_TIMER_TICK_US 100U +#define CAN3_TIMER_TICK_US 100U + +#define CAN1_DEQUEUE_PERIOD_US 500U +#define CAN2_DEQUEUE_PERIOD_US 1000U +#define CAN3_DEQUEUE_PERIOD_US 2000U +``` + +Create separate timer handles: + +```c +#define CAN1_TIMER_HANDLE \ + CAN_CFG_JOIN(htim, CAN1_TIMER_INDEX) + +#define CAN2_TIMER_HANDLE \ + CAN_CFG_JOIN(htim, CAN2_TIMER_INDEX) + +#define CAN3_TIMER_HANDLE \ + CAN_CFG_JOIN(htim, CAN3_TIMER_INDEX) +``` + +Create separate auto-reload values: + +```c +#define CAN1_TIMER_AUTORELOAD \ + ((CAN1_DEQUEUE_PERIOD_US / CAN1_TIMER_TICK_US) - 1U) + +#define CAN2_TIMER_AUTORELOAD \ + ((CAN2_DEQUEUE_PERIOD_US / CAN2_TIMER_TICK_US) - 1U) + +#define CAN3_TIMER_AUTORELOAD \ + ((CAN3_DEQUEUE_PERIOD_US / CAN3_TIMER_TICK_US) - 1U) +``` + +The callback would route each timer separately: + +```c +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) +{ +#ifdef USECAN1 + if (htim == &CAN1_TIMER_HANDLE) { + CAN1_Timer_Tick(); + return; + } +#endif + +#ifdef USECAN2 + if (htim == &CAN2_TIMER_HANDLE) { + CAN2_Timer_Tick(); + return; + } +#endif + +#ifdef USECAN3 + if (htim == &CAN3_TIMER_HANDLE) { + CAN3_Timer_Tick(); + return; + } +#endif +} +``` + +Each timer must also be started separately: + +```c +if (CAN1_Timer_Start() != HAL_OK) { + Error_Handler(); +} + +if (CAN2_Timer_Start() != HAL_OK) { + Error_Handler(); +} + +if (CAN3_Timer_Start() != HAL_OK) { + Error_Handler(); +} +``` + +Use multiple timers only when the buses require: + +- independent transmission periods +- strict timing separation +- different interrupt priorities +- separate bandwidth policies + +For most applications, one shared timer with round-robin queue servicing is simpler and more efficient. + +--- + +# 7. Timer Startup Function + +The shared-timer implementation should use: + +```c +HAL_StatusTypeDef CAN_Timer_Start(void) +{ + TIM_HandleTypeDef *htim = &CAN_TIMER_HANDLE; + + __HAL_TIM_DISABLE(htim); + + __HAL_TIM_SET_AUTORELOAD( + htim, + CAN_TIMER_AUTORELOAD); + + __HAL_TIM_SET_COUNTER(htim, 0U); + + htim->Instance->EGR = TIM_EGR_UG; + + __HAL_TIM_CLEAR_FLAG( + htim, + TIM_FLAG_UPDATE); + + return HAL_TIM_Base_Start_IT(htim); +} +``` + +This function changes only the runtime period. + +It does not configure: + +- timer clocks +- timer prescaler +- NVIC +- timer instance +- timer IRQ handler + +CubeMX owns those settings. + +--- + +# 8. Required Startup Order + +The hardware initialization must happen before custom runtime initialization. + +Correct: + +```c +MX_GPIO_Init(); +MX_FDCAN1_Init(); +MX_FDCAN2_Init(); +MX_TIM5_Init(); + +GR_CAN_Init(); + +if (CAN_Timer_Start() != HAL_OK) { + Error_Handler(); +} +``` + +Incorrect: + +```c +CAN_Timer_Start(); +MX_TIM5_Init(); +``` + +The timer handle is not ready until `MX_TIM5_Init()` runs. + +--- + +# 9. Files That May Be Edited + +## Edit directly + +These files contain custom code: + +```text +can.c +can.h +gr_can_init.c +gr_can_init.h +can_cfg_h.ftl +README +CMakeLists.txt +``` + +## Edit only inside user-code sections + +```text +main.c +``` + +Examples: + +```c +/* USER CODE BEGIN Includes */ +/* USER CODE END Includes */ +``` + +```c +/* USER CODE BEGIN 2 */ +/* USER CODE END 2 */ +``` + +```c +/* USER CODE BEGIN 4 */ +/* USER CODE END 4 */ +``` + +## Do not manually edit + +These files are generated by CubeMX: + +```text +fdcan.c +fdcan.h +tim.c +tim.h +gpio.c +gpio.h +stm32g4xx_it.c +stm32g4xx_it.h +stm32g4xx_hal_conf.h +``` + +Modify their settings through CubeMX and regenerate. + +--- + +# 10. Regeneration Checklist + +After regenerating CubeMX code, verify: + +```text +main.c includes tim.h +main.c calls MX_TIM5_Init() +tim.c exists +tim.h exists +htim5 is declared +TIM5_IRQHandler exists +HAL_TIM_MODULE_ENABLED is defined +FDCAN1 and FDCAN2 still initialize +can_cfg.h contains USECAN1 and USECAN2 +Core/Src/tim.c is included in the build +``` + +Also verify that custom code remains inside user-code sections. + +--- + +# 11. Testing Changes + +## Test timer frequency + +Temporarily replace queue servicing with a counter: + +```c +volatile uint32_t can_timer_ticks = 0U; + +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) +{ + if (htim == &CAN_TIMER_HANDLE) { + can_timer_ticks++; + } +} +``` + +With: + +```c +#define CAN_DEQUEUE_PERIOD_US 500U +``` + +the counter should increment approximately 2,000 times per second. + +For easier debugging: + +```c +#define CAN_DEQUEUE_PERIOD_US 100000U +``` + +This creates one callback every 100 ms. + +## Test CAN queue servicing + +1. Initialize FDCAN. +2. Initialize the custom CAN runtime. +3. Start the timer. +4. Add one frame to the software queue. +5. Confirm `CAN_Timer_Tick()` runs. +6. Confirm one frame is removed from the queue. +7. Confirm the HAL transmit function succeeds. +8. Confirm another CAN node receives the frame. + +--- + +# 12. Common Errors + +## Selected timer is not enabled + +Example: + +```text +CAN_TIMER_INDEX selects TIM2, but TIM2 is not enabled in CubeMX +``` + +Fix: + +- enable TIM2 in CubeMX, or +- select an enabled timer + +## `htim5` linker error + +Confirm: + +```text +Core/Src/tim.c +``` + +is included in the build. + +## No timer callback + +Confirm: + +- `MX_TIM5_Init()` is called +- `CAN_Timer_Start()` returns `HAL_OK` +- the timer interrupt is enabled +- `TIM5_IRQHandler()` exists +- `HAL_TIM_IRQHandler(&htim5)` is called +- global interrupts are enabled + +## Wrong timer rate + +Confirm: + +- timer input clock +- prescaler +- `CAN_TIMER_TICK_US` +- `CAN_DEQUEUE_PERIOD_US` + +All four values must agree. + +## Duplicate interrupt handler + +Do not define another: + +```c +TIM5_IRQHandler() +``` + +inside the CAN library. + +CubeMX owns the IRQ handler. + +## Messages remain queued + +Check: + +- FDCAN was started +- the hardware TX FIFO has room +- another node is present to acknowledge messages +- the transceiver is enabled +- bus bit timing matches +- queue dequeue code is being called + +--- + +# 13. Current Default Configuration + +Current timer: + +```text +TIM5 +``` + +Timer input clock: + +```text +160 MHz +``` + +Prescaler: + +```text +15999 +``` + +Timer tick: + +```text +100 us +``` + +CAN dequeue period: + +```text +500 us +``` + +Calculated auto-reload: + +```text +4 +``` + +Default queue sizes: + +```text +CAN1: 20 messages +CAN2: 20 messages +CAN3: 20 messages +``` + +The current implementation uses one shared timer for all enabled CAN buses. From 6c013d2796af8bc03229a318cc0f05bd7814f533 Mon Sep 17 00:00:00 2001 From: TrainmanR Date: Sat, 18 Jul 2026 18:28:04 -0700 Subject: [PATCH 019/125] Template Autogen Folders Fixed previous issue with can_cfg_h.ftl template not being copied to Autogen folder, and instead generated in CubeMX template. When using do not open/edit template settings, as then we'll need to reedit .ioc's paths. --- .../Inc/can_cfg.h} | 0 CUBEMXTESTING/CUBEMXTESTING.ioc | 39 ++- CUBEMXTESTING/Core/Inc/fdcan.h | 3 + CUBEMXTESTING/Core/Src/fdcan.c | 90 ++++++ CUBEMXTESTING/Core/Src/gpio.c | 12 - CUBEMXTESTING/Core/Src/main.c | 1 + Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl | 227 ++++++++++++++- .../Autogen/Inc/can_cfg_h_updated.ftl | 268 ------------------ Lib/CubeMXTemplates/Autogen/Src/.gitkeep | 0 Lib/CubeMXTemplates/can_cfg_h_timer.ftl | 177 ------------ 10 files changed, 335 insertions(+), 482 deletions(-) rename CUBEMXTESTING/{can_cfg_h.updated => Autogen/Inc/can_cfg.h} (100%) delete mode 100644 Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h_updated.ftl delete mode 100644 Lib/CubeMXTemplates/Autogen/Src/.gitkeep delete mode 100644 Lib/CubeMXTemplates/can_cfg_h_timer.ftl diff --git a/CUBEMXTESTING/can_cfg_h.updated b/CUBEMXTESTING/Autogen/Inc/can_cfg.h similarity index 100% rename from CUBEMXTESTING/can_cfg_h.updated rename to CUBEMXTESTING/Autogen/Inc/can_cfg.h diff --git a/CUBEMXTESTING/CUBEMXTESTING.ioc b/CUBEMXTESTING/CUBEMXTESTING.ioc index 7c2f2f98e..1d4d092cb 100644 --- a/CUBEMXTESTING/CUBEMXTESTING.ioc +++ b/CUBEMXTESTING/CUBEMXTESTING.ioc @@ -32,6 +32,10 @@ FDCAN2.NominalSyncJumpWidth=16 FDCAN2.NominalTimeSeg1=119 FDCAN2.NominalTimeSeg2=40 FDCAN2.ProtocolException=ENABLE +FDCAN3.CalculateBaudRateNominal=3333333 +FDCAN3.CalculateTimeBitNominal=300 +FDCAN3.CalculateTimeQuantumNominal=100.0 +FDCAN3.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal File.Version=6 GPIO.groupedBy=Group By Peripherals KeepUserPlacement=false @@ -39,23 +43,26 @@ Mcu.CPN=STM32G474RET6 Mcu.Family=STM32G4 Mcu.IP0=FDCAN1 Mcu.IP1=FDCAN2 -Mcu.IP2=NVIC -Mcu.IP3=RCC -Mcu.IP4=SYS -Mcu.IP5=TIM5 -Mcu.IPNb=6 +Mcu.IP2=FDCAN3 +Mcu.IP3=NVIC +Mcu.IP4=RCC +Mcu.IP5=SYS +Mcu.IP6=TIM5 +Mcu.IPNb=7 Mcu.Name=STM32G474R(B-C-E)Tx Mcu.Package=LQFP64 Mcu.Pin0=PC13 Mcu.Pin1=PA5 +Mcu.Pin10=VP_TIM5_VS_ClockSourceINT Mcu.Pin2=PB12 Mcu.Pin3=PB13 -Mcu.Pin4=PB8-BOOT0 -Mcu.Pin5=PB9 -Mcu.Pin6=VP_SYS_VS_Systick -Mcu.Pin7=VP_SYS_VS_DBSignals -Mcu.Pin8=VP_TIM5_VS_ClockSourceINT -Mcu.PinsNb=9 +Mcu.Pin4=PA8 +Mcu.Pin5=PA15 +Mcu.Pin6=PB8-BOOT0 +Mcu.Pin7=PB9 +Mcu.Pin8=VP_SYS_VS_Systick +Mcu.Pin9=VP_SYS_VS_DBSignals +Mcu.PinsNb=11 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32G474RETx @@ -73,10 +80,14 @@ NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false NVIC.TIM5_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +PA15.Mode=FDCAN_Activate +PA15.Signal=FDCAN3_TX PA5.GPIOParameters=GPIO_Label PA5.GPIO_Label=USER_LED PA5.Locked=true PA5.Signal=GPIO_Output +PA8.Mode=FDCAN_Activate +PA8.Signal=FDCAN3_RX PB12.Mode=FDCAN_Activate PB12.Signal=FDCAN2_RX PB13.Mode=FDCAN_Activate @@ -118,9 +129,9 @@ ProjectManager.ProjectStructure= ProjectManager.RegisterCallBack= ProjectManager.StackSize=0x400 ProjectManager.TargetToolchain=EWARM V8.50 -ProjectManager.TemplateDestinationPath=C\:\\Users\\maxnm\\Firmware\\CUBEMXTESTING -ProjectManager.TemplateSourcePath=C\:\\Users\\maxnm\\Firmware\\Lib\\CubeMXTemplates\\Autogen\\Inc -ProjectManager.TemplatesList=\\can_cfg_h_updated.ftl, +ProjectManager.TemplateDestinationPath=. +ProjectManager.TemplateSourcePath=..\\Lib\\CubeMXTemplates +ProjectManager.TemplatesList=Autogen\\Inc\\can_cfg_h.ftl, ProjectManager.ToolChainLocation= ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptBeforePath= diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index b0fa74968..4b2cb4094 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -36,12 +36,15 @@ extern FDCAN_HandleTypeDef hfdcan1; extern FDCAN_HandleTypeDef hfdcan2; +extern FDCAN_HandleTypeDef hfdcan3; + /* USER CODE BEGIN Private defines */ /* USER CODE END Private defines */ void MX_FDCAN1_Init(void); void MX_FDCAN2_Init(void); +void MX_FDCAN3_Init(void); /* USER CODE BEGIN Prototypes */ diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index a1e13a2e8..d1f107673 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -26,6 +26,7 @@ FDCAN_HandleTypeDef hfdcan1; FDCAN_HandleTypeDef hfdcan2; +FDCAN_HandleTypeDef hfdcan3; /* FDCAN1 init function */ void MX_FDCAN1_Init(void) @@ -102,6 +103,44 @@ void MX_FDCAN2_Init(void) /* USER CODE END FDCAN2_Init 2 */ +} +/* FDCAN3 init function */ +void MX_FDCAN3_Init(void) +{ + + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_NORMAL; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ + } static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; @@ -169,6 +208,36 @@ void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) /* USER CODE END FDCAN2_MspInit 1 */ } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) @@ -216,6 +285,27 @@ void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) /* USER CODE END FDCAN2_MspDeInit 1 */ } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); + + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index 09690886a..5d1912e85 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -238,12 +238,6 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /**/ GPIO_InitStruct.Pin = LL_GPIO_PIN_9; GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; @@ -280,12 +274,6 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /**/ GPIO_InitStruct.Pin = LL_GPIO_PIN_10; GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 54131f9fd..e189561ec 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -122,6 +122,7 @@ int main(void) MX_FDCAN1_Init(); MX_FDCAN2_Init(); MX_TIM5_Init(); + MX_FDCAN3_Init(); /* USER CODE BEGIN 2 */ Logomatic_Init(&logomaticConfig); VCP_Init(&vcp_config); diff --git a/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl b/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl index de4b84222..815c29617 100644 --- a/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl +++ b/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl @@ -1,13 +1,16 @@ [#ftl] - [#-- -Generates can_cfg.h from the active STM32CubeMX project. + Generates can_cfg.h from the active STM32CubeMX project. + + Detects enabled FDCAN and TIM peripherals and emits compile-time configuration + for the Gaucho Racing CAN runtime. -Detects enabled FDCAN instances and emits the corresponding USECANx macros. -TX buffer sizes remain user-configurable and are preserved across normal -CubeMX regeneration. + CubeMX remains responsible for: + - FDCAN clocks, GPIO, bit timing, HAL handles, and MX_FDCANx_Init() + - TIM clocks, prescaler, NVIC configuration, HAL handle, and MX_TIMx_Init() -STM32 hardware configuration remains owned by CubeMX. + The CAN runtime uses the selected CubeMX-generated TIM handle to periodically + service its software TX queues. --] [#list configs as dt] @@ -18,34 +21,114 @@ STM32 hardware configuration remains owned by CubeMX. [#assign hasFDCAN2 = false] [#assign hasFDCAN3 = false] +[#assign hasTIM1 = false] +[#assign hasTIM2 = false] +[#assign hasTIM3 = false] +[#assign hasTIM4 = false] +[#assign hasTIM5 = false] +[#assign hasTIM6 = false] +[#assign hasTIM7 = false] +[#assign hasTIM8 = false] +[#assign hasTIM15 = false] +[#assign hasTIM16 = false] +[#assign hasTIM17 = false] + [#list usedIPs as ip] [#assign ipName = ip?string] - [#if ipName?contains("FDCAN1")] + [#if ipName == "FDCAN1"] [#assign hasFDCAN1 = true] [/#if] - - [#if ipName?contains("FDCAN2")] + [#if ipName == "FDCAN2"] [#assign hasFDCAN2 = true] [/#if] - - [#if ipName?contains("FDCAN3")] + [#if ipName == "FDCAN3"] [#assign hasFDCAN3 = true] [/#if] + + [#if ipName == "TIM1"] + [#assign hasTIM1 = true] + [/#if] + [#if ipName == "TIM2"] + [#assign hasTIM2 = true] + [/#if] + [#if ipName == "TIM3"] + [#assign hasTIM3 = true] + [/#if] + [#if ipName == "TIM4"] + [#assign hasTIM4 = true] + [/#if] + [#if ipName == "TIM5"] + [#assign hasTIM5 = true] + [/#if] + [#if ipName == "TIM6"] + [#assign hasTIM6 = true] + [/#if] + [#if ipName == "TIM7"] + [#assign hasTIM7 = true] + [/#if] + [#if ipName == "TIM8"] + [#assign hasTIM8 = true] + [/#if] + [#if ipName == "TIM15"] + [#assign hasTIM15 = true] + [/#if] + [#if ipName == "TIM16"] + [#assign hasTIM16 = true] + [/#if] + [#if ipName == "TIM17"] + [#assign hasTIM17 = true] + [/#if] [/#list] + #ifndef CAN_CFG_H #define CAN_CFG_H /* Generated automatically by STM32CubeMX FreeMarker. */ +/* + * User-editable CAN runtime configuration. + * + * CAN_TIMER_INDEX: + * Selects the CubeMX-generated timer handle. Example: 5 selects htim5. + * + * CAN_TIMER_TICK_US: + * Duration of one timer counter tick, determined by the CubeMX prescaler. + * For a 160 MHz TIM clock and Prescaler = 15999, one tick is 100 us. + * + * CAN_DEQUEUE_PERIOD_US: + * Time between attempts to dequeue and send one software-queued CAN message. + */ /* USER CODE BEGIN CAN_USER_CONFIG */ +#ifndef TX_BUFFER_1_SIZE #define TX_BUFFER_1_SIZE 20U +#endif + +#ifndef TX_BUFFER_2_SIZE #define TX_BUFFER_2_SIZE 20U +#endif + +#ifndef TX_BUFFER_3_SIZE #define TX_BUFFER_3_SIZE 20U +#endif + +#ifndef CAN_TIMER_INDEX +#define CAN_TIMER_INDEX 5 +#endif + +#ifndef CAN_TIMER_TICK_US +#define CAN_TIMER_TICK_US 100U +#endif + +#ifndef CAN_DEQUEUE_PERIOD_US +#define CAN_DEQUEUE_PERIOD_US 500U +#endif /* USER CODE END CAN_USER_CONFIG */ +/* Enabled FDCAN peripherals. */ + [#if hasFDCAN1] #define USECAN1 [/#if] @@ -58,6 +141,128 @@ STM32 hardware configuration remains owned by CubeMX. #define USECAN3 [/#if] +/* Timers enabled in CubeMX. */ + +[#if hasTIM1] +#define CUBEMX_HAS_TIM1 +[/#if] +[#if hasTIM2] +#define CUBEMX_HAS_TIM2 +[/#if] +[#if hasTIM3] +#define CUBEMX_HAS_TIM3 +[/#if] +[#if hasTIM4] +#define CUBEMX_HAS_TIM4 +[/#if] +[#if hasTIM5] +#define CUBEMX_HAS_TIM5 +[/#if] +[#if hasTIM6] +#define CUBEMX_HAS_TIM6 +[/#if] +[#if hasTIM7] +#define CUBEMX_HAS_TIM7 +[/#if] +[#if hasTIM8] +#define CUBEMX_HAS_TIM8 +[/#if] +[#if hasTIM15] +#define CUBEMX_HAS_TIM15 +[/#if] +[#if hasTIM16] +#define CUBEMX_HAS_TIM16 +[/#if] +[#if hasTIM17] +#define CUBEMX_HAS_TIM17 +[/#if] + +/* Configuration validation. */ + +#if defined(USECAN1) && (TX_BUFFER_1_SIZE == 0U) +#error "TX_BUFFER_1_SIZE must be greater than zero" +#endif + +#if defined(USECAN2) && (TX_BUFFER_2_SIZE == 0U) +#error "TX_BUFFER_2_SIZE must be greater than zero" +#endif + +#if defined(USECAN3) && (TX_BUFFER_3_SIZE == 0U) +#error "TX_BUFFER_3_SIZE must be greater than zero" +#endif + +#if CAN_TIMER_TICK_US == 0U +#error "CAN_TIMER_TICK_US must be greater than zero" +#endif + +#if CAN_DEQUEUE_PERIOD_US == 0U +#error "CAN_DEQUEUE_PERIOD_US must be greater than zero" +#endif + +#if CAN_DEQUEUE_PERIOD_US < CAN_TIMER_TICK_US +#error "CAN_DEQUEUE_PERIOD_US cannot be shorter than one timer tick" +#endif + +#if (CAN_DEQUEUE_PERIOD_US % CAN_TIMER_TICK_US) != 0U +#error "CAN_DEQUEUE_PERIOD_US must be divisible by CAN_TIMER_TICK_US" +#endif + +#if ((CAN_DEQUEUE_PERIOD_US / CAN_TIMER_TICK_US) - 1U) > 0xFFFFFFFFU +#error "CAN dequeue period exceeds the supported timer auto-reload range" +#endif + +#if (CAN_TIMER_INDEX == 1) && !defined(CUBEMX_HAS_TIM1) +#error "CAN_TIMER_INDEX selects TIM1, but TIM1 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 2) && !defined(CUBEMX_HAS_TIM2) +#error "CAN_TIMER_INDEX selects TIM2, but TIM2 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 3) && !defined(CUBEMX_HAS_TIM3) +#error "CAN_TIMER_INDEX selects TIM3, but TIM3 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 4) && !defined(CUBEMX_HAS_TIM4) +#error "CAN_TIMER_INDEX selects TIM4, but TIM4 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 5) && !defined(CUBEMX_HAS_TIM5) +#error "CAN_TIMER_INDEX selects TIM5, but TIM5 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 6) && !defined(CUBEMX_HAS_TIM6) +#error "CAN_TIMER_INDEX selects TIM6, but TIM6 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 7) && !defined(CUBEMX_HAS_TIM7) +#error "CAN_TIMER_INDEX selects TIM7, but TIM7 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 8) && !defined(CUBEMX_HAS_TIM8) +#error "CAN_TIMER_INDEX selects TIM8, but TIM8 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 15) && !defined(CUBEMX_HAS_TIM15) +#error "CAN_TIMER_INDEX selects TIM15, but TIM15 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 16) && !defined(CUBEMX_HAS_TIM16) +#error "CAN_TIMER_INDEX selects TIM16, but TIM16 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX == 17) && !defined(CUBEMX_HAS_TIM17) +#error "CAN_TIMER_INDEX selects TIM17, but TIM17 is not enabled in CubeMX" +#elif (CAN_TIMER_INDEX != 1) && \ + (CAN_TIMER_INDEX != 2) && \ + (CAN_TIMER_INDEX != 3) && \ + (CAN_TIMER_INDEX != 4) && \ + (CAN_TIMER_INDEX != 5) && \ + (CAN_TIMER_INDEX != 6) && \ + (CAN_TIMER_INDEX != 7) && \ + (CAN_TIMER_INDEX != 8) && \ + (CAN_TIMER_INDEX != 15) && \ + (CAN_TIMER_INDEX != 16) && \ + (CAN_TIMER_INDEX != 17) +#error "CAN_TIMER_INDEX selects an unsupported timer" +#endif + +#define CAN_TIMER_PERIOD_COUNTS \ + (CAN_DEQUEUE_PERIOD_US / CAN_TIMER_TICK_US) + +#define CAN_TIMER_AUTORELOAD \ + (CAN_TIMER_PERIOD_COUNTS - 1U) + +/* + * Convert CAN_TIMER_INDEX into CubeMX's generated HAL timer handle. + * + * CAN_TIMER_INDEX = 5 + * CAN_TIMER_HANDLE = htim5 + */ +#define CAN_CFG_JOIN_INNER(a, b) a##b +#define CAN_CFG_JOIN(a, b) CAN_CFG_JOIN_INNER(a, b) +#define CAN_TIMER_HANDLE CAN_CFG_JOIN(htim, CAN_TIMER_INDEX) + #endif /* CAN_CFG_H */ [/#list] diff --git a/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h_updated.ftl b/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h_updated.ftl deleted file mode 100644 index 815c29617..000000000 --- a/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h_updated.ftl +++ /dev/null @@ -1,268 +0,0 @@ -[#ftl] -[#-- - Generates can_cfg.h from the active STM32CubeMX project. - - Detects enabled FDCAN and TIM peripherals and emits compile-time configuration - for the Gaucho Racing CAN runtime. - - CubeMX remains responsible for: - - FDCAN clocks, GPIO, bit timing, HAL handles, and MX_FDCANx_Init() - - TIM clocks, prescaler, NVIC configuration, HAL handle, and MX_TIMx_Init() - - The CAN runtime uses the selected CubeMX-generated TIM handle to periodically - service its software TX queues. ---] - -[#list configs as dt] - -[#assign usedIPs = (dt.usedIPs)![]] - -[#assign hasFDCAN1 = false] -[#assign hasFDCAN2 = false] -[#assign hasFDCAN3 = false] - -[#assign hasTIM1 = false] -[#assign hasTIM2 = false] -[#assign hasTIM3 = false] -[#assign hasTIM4 = false] -[#assign hasTIM5 = false] -[#assign hasTIM6 = false] -[#assign hasTIM7 = false] -[#assign hasTIM8 = false] -[#assign hasTIM15 = false] -[#assign hasTIM16 = false] -[#assign hasTIM17 = false] - -[#list usedIPs as ip] - [#assign ipName = ip?string] - - [#if ipName == "FDCAN1"] - [#assign hasFDCAN1 = true] - [/#if] - [#if ipName == "FDCAN2"] - [#assign hasFDCAN2 = true] - [/#if] - [#if ipName == "FDCAN3"] - [#assign hasFDCAN3 = true] - [/#if] - - [#if ipName == "TIM1"] - [#assign hasTIM1 = true] - [/#if] - [#if ipName == "TIM2"] - [#assign hasTIM2 = true] - [/#if] - [#if ipName == "TIM3"] - [#assign hasTIM3 = true] - [/#if] - [#if ipName == "TIM4"] - [#assign hasTIM4 = true] - [/#if] - [#if ipName == "TIM5"] - [#assign hasTIM5 = true] - [/#if] - [#if ipName == "TIM6"] - [#assign hasTIM6 = true] - [/#if] - [#if ipName == "TIM7"] - [#assign hasTIM7 = true] - [/#if] - [#if ipName == "TIM8"] - [#assign hasTIM8 = true] - [/#if] - [#if ipName == "TIM15"] - [#assign hasTIM15 = true] - [/#if] - [#if ipName == "TIM16"] - [#assign hasTIM16 = true] - [/#if] - [#if ipName == "TIM17"] - [#assign hasTIM17 = true] - [/#if] -[/#list] - -#ifndef CAN_CFG_H -#define CAN_CFG_H - -/* Generated automatically by STM32CubeMX FreeMarker. */ - -/* - * User-editable CAN runtime configuration. - * - * CAN_TIMER_INDEX: - * Selects the CubeMX-generated timer handle. Example: 5 selects htim5. - * - * CAN_TIMER_TICK_US: - * Duration of one timer counter tick, determined by the CubeMX prescaler. - * For a 160 MHz TIM clock and Prescaler = 15999, one tick is 100 us. - * - * CAN_DEQUEUE_PERIOD_US: - * Time between attempts to dequeue and send one software-queued CAN message. - */ -/* USER CODE BEGIN CAN_USER_CONFIG */ - -#ifndef TX_BUFFER_1_SIZE -#define TX_BUFFER_1_SIZE 20U -#endif - -#ifndef TX_BUFFER_2_SIZE -#define TX_BUFFER_2_SIZE 20U -#endif - -#ifndef TX_BUFFER_3_SIZE -#define TX_BUFFER_3_SIZE 20U -#endif - -#ifndef CAN_TIMER_INDEX -#define CAN_TIMER_INDEX 5 -#endif - -#ifndef CAN_TIMER_TICK_US -#define CAN_TIMER_TICK_US 100U -#endif - -#ifndef CAN_DEQUEUE_PERIOD_US -#define CAN_DEQUEUE_PERIOD_US 500U -#endif - -/* USER CODE END CAN_USER_CONFIG */ - -/* Enabled FDCAN peripherals. */ - -[#if hasFDCAN1] -#define USECAN1 -[/#if] - -[#if hasFDCAN2] -#define USECAN2 -[/#if] - -[#if hasFDCAN3] -#define USECAN3 -[/#if] - -/* Timers enabled in CubeMX. */ - -[#if hasTIM1] -#define CUBEMX_HAS_TIM1 -[/#if] -[#if hasTIM2] -#define CUBEMX_HAS_TIM2 -[/#if] -[#if hasTIM3] -#define CUBEMX_HAS_TIM3 -[/#if] -[#if hasTIM4] -#define CUBEMX_HAS_TIM4 -[/#if] -[#if hasTIM5] -#define CUBEMX_HAS_TIM5 -[/#if] -[#if hasTIM6] -#define CUBEMX_HAS_TIM6 -[/#if] -[#if hasTIM7] -#define CUBEMX_HAS_TIM7 -[/#if] -[#if hasTIM8] -#define CUBEMX_HAS_TIM8 -[/#if] -[#if hasTIM15] -#define CUBEMX_HAS_TIM15 -[/#if] -[#if hasTIM16] -#define CUBEMX_HAS_TIM16 -[/#if] -[#if hasTIM17] -#define CUBEMX_HAS_TIM17 -[/#if] - -/* Configuration validation. */ - -#if defined(USECAN1) && (TX_BUFFER_1_SIZE == 0U) -#error "TX_BUFFER_1_SIZE must be greater than zero" -#endif - -#if defined(USECAN2) && (TX_BUFFER_2_SIZE == 0U) -#error "TX_BUFFER_2_SIZE must be greater than zero" -#endif - -#if defined(USECAN3) && (TX_BUFFER_3_SIZE == 0U) -#error "TX_BUFFER_3_SIZE must be greater than zero" -#endif - -#if CAN_TIMER_TICK_US == 0U -#error "CAN_TIMER_TICK_US must be greater than zero" -#endif - -#if CAN_DEQUEUE_PERIOD_US == 0U -#error "CAN_DEQUEUE_PERIOD_US must be greater than zero" -#endif - -#if CAN_DEQUEUE_PERIOD_US < CAN_TIMER_TICK_US -#error "CAN_DEQUEUE_PERIOD_US cannot be shorter than one timer tick" -#endif - -#if (CAN_DEQUEUE_PERIOD_US % CAN_TIMER_TICK_US) != 0U -#error "CAN_DEQUEUE_PERIOD_US must be divisible by CAN_TIMER_TICK_US" -#endif - -#if ((CAN_DEQUEUE_PERIOD_US / CAN_TIMER_TICK_US) - 1U) > 0xFFFFFFFFU -#error "CAN dequeue period exceeds the supported timer auto-reload range" -#endif - -#if (CAN_TIMER_INDEX == 1) && !defined(CUBEMX_HAS_TIM1) -#error "CAN_TIMER_INDEX selects TIM1, but TIM1 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 2) && !defined(CUBEMX_HAS_TIM2) -#error "CAN_TIMER_INDEX selects TIM2, but TIM2 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 3) && !defined(CUBEMX_HAS_TIM3) -#error "CAN_TIMER_INDEX selects TIM3, but TIM3 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 4) && !defined(CUBEMX_HAS_TIM4) -#error "CAN_TIMER_INDEX selects TIM4, but TIM4 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 5) && !defined(CUBEMX_HAS_TIM5) -#error "CAN_TIMER_INDEX selects TIM5, but TIM5 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 6) && !defined(CUBEMX_HAS_TIM6) -#error "CAN_TIMER_INDEX selects TIM6, but TIM6 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 7) && !defined(CUBEMX_HAS_TIM7) -#error "CAN_TIMER_INDEX selects TIM7, but TIM7 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 8) && !defined(CUBEMX_HAS_TIM8) -#error "CAN_TIMER_INDEX selects TIM8, but TIM8 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 15) && !defined(CUBEMX_HAS_TIM15) -#error "CAN_TIMER_INDEX selects TIM15, but TIM15 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 16) && !defined(CUBEMX_HAS_TIM16) -#error "CAN_TIMER_INDEX selects TIM16, but TIM16 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 17) && !defined(CUBEMX_HAS_TIM17) -#error "CAN_TIMER_INDEX selects TIM17, but TIM17 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX != 1) && \ - (CAN_TIMER_INDEX != 2) && \ - (CAN_TIMER_INDEX != 3) && \ - (CAN_TIMER_INDEX != 4) && \ - (CAN_TIMER_INDEX != 5) && \ - (CAN_TIMER_INDEX != 6) && \ - (CAN_TIMER_INDEX != 7) && \ - (CAN_TIMER_INDEX != 8) && \ - (CAN_TIMER_INDEX != 15) && \ - (CAN_TIMER_INDEX != 16) && \ - (CAN_TIMER_INDEX != 17) -#error "CAN_TIMER_INDEX selects an unsupported timer" -#endif - -#define CAN_TIMER_PERIOD_COUNTS \ - (CAN_DEQUEUE_PERIOD_US / CAN_TIMER_TICK_US) - -#define CAN_TIMER_AUTORELOAD \ - (CAN_TIMER_PERIOD_COUNTS - 1U) - -/* - * Convert CAN_TIMER_INDEX into CubeMX's generated HAL timer handle. - * - * CAN_TIMER_INDEX = 5 - * CAN_TIMER_HANDLE = htim5 - */ -#define CAN_CFG_JOIN_INNER(a, b) a##b -#define CAN_CFG_JOIN(a, b) CAN_CFG_JOIN_INNER(a, b) -#define CAN_TIMER_HANDLE CAN_CFG_JOIN(htim, CAN_TIMER_INDEX) - -#endif /* CAN_CFG_H */ - -[/#list] diff --git a/Lib/CubeMXTemplates/Autogen/Src/.gitkeep b/Lib/CubeMXTemplates/Autogen/Src/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/Lib/CubeMXTemplates/can_cfg_h_timer.ftl b/Lib/CubeMXTemplates/can_cfg_h_timer.ftl deleted file mode 100644 index b7ace5741..000000000 --- a/Lib/CubeMXTemplates/can_cfg_h_timer.ftl +++ /dev/null @@ -1,177 +0,0 @@ -[#ftl] -[#-- - Generates can_cfg.h from the active STM32CubeMX project. - - Detects enabled FDCAN instances and emits the corresponding USECANx macros. - Software TX queue sizes and CAN timer settings remain user-configurable and - are preserved across normal CubeMX regeneration. - - CubeMX remains responsible for configuring and generating MX_FDCANx_Init() - and MX_TIMx_Init(). This file only selects the CubeMX-generated timer handle - used to service the CAN software TX queues. ---] - -[#list configs as dt] - -[#assign usedIPs = (dt.usedIPs)![]] -[#assign hasFDCAN1 = false] -[#assign hasFDCAN2 = false] -[#assign hasFDCAN3 = false] -[#assign hasTIM1 = false] -[#assign hasTIM2 = false] -[#assign hasTIM3 = false] -[#assign hasTIM4 = false] -[#assign hasTIM5 = false] -[#assign hasTIM6 = false] -[#assign hasTIM7 = false] -[#assign hasTIM8 = false] -[#assign hasTIM15 = false] -[#assign hasTIM16 = false] -[#assign hasTIM17 = false] - -[#list usedIPs as ip] - [#assign ipName = ip?string] - - [#if ipName?contains("FDCAN1")][#assign hasFDCAN1 = true][/#if] - [#if ipName?contains("FDCAN2")][#assign hasFDCAN2 = true][/#if] - [#if ipName?contains("FDCAN3")][#assign hasFDCAN3 = true][/#if] - - [#if ipName?contains("TIM1")][#assign hasTIM1 = true][/#if] - [#if ipName?contains("TIM2")][#assign hasTIM2 = true][/#if] - [#if ipName?contains("TIM3")][#assign hasTIM3 = true][/#if] - [#if ipName?contains("TIM4")][#assign hasTIM4 = true][/#if] - [#if ipName?contains("TIM5")][#assign hasTIM5 = true][/#if] - [#if ipName?contains("TIM6")][#assign hasTIM6 = true][/#if] - [#if ipName?contains("TIM7")][#assign hasTIM7 = true][/#if] - [#if ipName?contains("TIM8")][#assign hasTIM8 = true][/#if] - [#if ipName?contains("TIM15")][#assign hasTIM15 = true][/#if] - [#if ipName?contains("TIM16")][#assign hasTIM16 = true][/#if] - [#if ipName?contains("TIM17")][#assign hasTIM17 = true][/#if] -[/#list] - -#ifndef CAN_CFG_H -#define CAN_CFG_H - -/* Generated automatically by STM32CubeMX FreeMarker. */ - -/* USER CODE BEGIN CAN_USER_CONFIG */ - -#ifndef TX_BUFFER_1_SIZE -#define TX_BUFFER_1_SIZE 20U -#endif - -#ifndef TX_BUFFER_2_SIZE -#define TX_BUFFER_2_SIZE 20U -#endif - -#ifndef TX_BUFFER_3_SIZE -#define TX_BUFFER_3_SIZE 20U -#endif - -/* Selects htim5 when set to 5. */ -#ifndef CAN_TIMER_INDEX -#define CAN_TIMER_INDEX 5 -#endif - -/* Dequeue one CAN message every X milliseconds. */ -#ifndef CAN_DEQUEUE_PERIOD_MS -#define CAN_DEQUEUE_PERIOD_MS 2U -#endif - -/* USER CODE END CAN_USER_CONFIG */ - -[#if hasFDCAN1] -#define USECAN1 -[/#if] -[#if hasFDCAN2] -#define USECAN2 -[/#if] -[#if hasFDCAN3] -#define USECAN3 -[/#if] - -[#if hasTIM1] -#define CUBEMX_HAS_TIM1 -[/#if] -[#if hasTIM2] -#define CUBEMX_HAS_TIM2 -[/#if] -[#if hasTIM3] -#define CUBEMX_HAS_TIM3 -[/#if] -[#if hasTIM4] -#define CUBEMX_HAS_TIM4 -[/#if] -[#if hasTIM5] -#define CUBEMX_HAS_TIM5 -[/#if] -[#if hasTIM6] -#define CUBEMX_HAS_TIM6 -[/#if] -[#if hasTIM7] -#define CUBEMX_HAS_TIM7 -[/#if] -[#if hasTIM8] -#define CUBEMX_HAS_TIM8 -[/#if] -[#if hasTIM15] -#define CUBEMX_HAS_TIM15 -[/#if] -[#if hasTIM16] -#define CUBEMX_HAS_TIM16 -[/#if] -[#if hasTIM17] -#define CUBEMX_HAS_TIM17 -[/#if] - -#if defined(USECAN1) && (TX_BUFFER_1_SIZE == 0U) -#error "TX_BUFFER_1_SIZE must be greater than zero" -#endif -#if defined(USECAN2) && (TX_BUFFER_2_SIZE == 0U) -#error "TX_BUFFER_2_SIZE must be greater than zero" -#endif -#if defined(USECAN3) && (TX_BUFFER_3_SIZE == 0U) -#error "TX_BUFFER_3_SIZE must be greater than zero" -#endif -#if CAN_DEQUEUE_PERIOD_MS == 0U -#error "CAN_DEQUEUE_PERIOD_MS must be greater than zero" -#endif - -#if (CAN_TIMER_INDEX == 1) && !defined(CUBEMX_HAS_TIM1) -#error "CAN_TIMER_INDEX selects TIM1, but TIM1 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 2) && !defined(CUBEMX_HAS_TIM2) -#error "CAN_TIMER_INDEX selects TIM2, but TIM2 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 3) && !defined(CUBEMX_HAS_TIM3) -#error "CAN_TIMER_INDEX selects TIM3, but TIM3 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 4) && !defined(CUBEMX_HAS_TIM4) -#error "CAN_TIMER_INDEX selects TIM4, but TIM4 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 5) && !defined(CUBEMX_HAS_TIM5) -#error "CAN_TIMER_INDEX selects TIM5, but TIM5 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 6) && !defined(CUBEMX_HAS_TIM6) -#error "CAN_TIMER_INDEX selects TIM6, but TIM6 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 7) && !defined(CUBEMX_HAS_TIM7) -#error "CAN_TIMER_INDEX selects TIM7, but TIM7 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 8) && !defined(CUBEMX_HAS_TIM8) -#error "CAN_TIMER_INDEX selects TIM8, but TIM8 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 15) && !defined(CUBEMX_HAS_TIM15) -#error "CAN_TIMER_INDEX selects TIM15, but TIM15 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 16) && !defined(CUBEMX_HAS_TIM16) -#error "CAN_TIMER_INDEX selects TIM16, but TIM16 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 17) && !defined(CUBEMX_HAS_TIM17) -#error "CAN_TIMER_INDEX selects TIM17, but TIM17 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX != 1) && (CAN_TIMER_INDEX != 2) && \ - (CAN_TIMER_INDEX != 3) && (CAN_TIMER_INDEX != 4) && \ - (CAN_TIMER_INDEX != 5) && (CAN_TIMER_INDEX != 6) && \ - (CAN_TIMER_INDEX != 7) && (CAN_TIMER_INDEX != 8) && \ - (CAN_TIMER_INDEX != 15) && (CAN_TIMER_INDEX != 16) && \ - (CAN_TIMER_INDEX != 17) -#error "CAN_TIMER_INDEX selects an unsupported timer" -#endif - -#define CAN_CFG_JOIN_INNER(a, b) a##b -#define CAN_CFG_JOIN(a, b) CAN_CFG_JOIN_INNER(a, b) -#define CAN_TIMER_HANDLE CAN_CFG_JOIN(htim, CAN_TIMER_INDEX) - -#endif /* CAN_CFG_H */ - -[/#list] From 63de147562b2c6ed231a42becbd21b93bc5d241f Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 18 Jul 2026 17:26:04 -0700 Subject: [PATCH 020/125] Critical section macro that needs testing still Signed-off-by: Daniel Hansen --- .../CubeCAN/Inc/Private/PrivateCubeMXCAN.h | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h index 3baff2c60..882eede84 100644 --- a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h +++ b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h @@ -2,11 +2,39 @@ #include #include "CubeMXCan.h" +#include "Stringification.h" #include "main.h" #ifndef PRIVATE_CUBE_MX_CAN_H #define PRIVATE_CUBE_MX_CAN_H +/** + * @brief Internal function to automatically restore the interrupt state when exiting a critical section. + * + * This function is intended to be used with the GCC cleanup attribute to automatically restore the interrupt state when a critical section is exited. It takes a pointer to a state variable that holds + * the previous interrupt state and restores it using the __set_PRIMASK function. + * + * @warning This function is intended for internal use only and should not be called directly by user code. Use the CRITICAL_SECTION macro instead. + */ +static inline void _magic_auto_exit_critical(uint32_t *state_var) +{ + if (state_var) { + __set_PRIMASK(*state_var); + } +} + +/** + * @brief Macro to create a critical section that disables interrupts for the duration of the block. + * + * This macro uses the GCC cleanup attribute to automatically restore the interrupt state when the block is exited, regardless of how the block is exited (e.g., return, break, continue). + * + * @warning This macro should be used with caution, as it can lead to deadlocks or other issues if not used correctly. It is recommended to use this macro only in situations where it is necessary to + * disable interrupts for a short period of time. + */ +#define CRITICAL_SECTION \ + for (__attribute__((cleanup(_magic_auto_exit_critical))) uint32_t CONCAT(auto_state_, __LINE__) = __get_PRIMASK(), CONCAT(auto_run_, __LINE__) = (__disable_irq(), 1); \ + CONCAT(auto_run_, __LINE__); CONCAT(auto_run_, __LINE__) = 0) + /** * @brief CubeMX CAN handle structure * From e2d62dd54c3316d7cdf55ef1ff08b25434e2e109 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 18 Jul 2026 17:45:54 -0700 Subject: [PATCH 021/125] Critical section safe code Signed-off-by: Daniel Hansen --- .../CubeCAN/Inc/Private/PrivateCubeMXCAN.h | 1 + Lib/Peripherals/CubeCAN/Src/can_init.c | 79 +++++++++++++------ Lib/Peripherals/CubeCAN/Src/can_it.c | 16 +++- Lib/Peripherals/CubeCAN/Src/can_utils.c | 4 + 4 files changed, 72 insertions(+), 28 deletions(-) diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h index 882eede84..f0e0a8dfa 100644 --- a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h +++ b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h @@ -1,3 +1,4 @@ +#include #include #include diff --git a/Lib/Peripherals/CubeCAN/Src/can_init.c b/Lib/Peripherals/CubeCAN/Src/can_init.c index 2d164d059..78904cfe8 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_init.c +++ b/Lib/Peripherals/CubeCAN/Src/can_init.c @@ -99,14 +99,34 @@ CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, const CubeCAN_Conf return NULL; } - CubeMXCan_Handle *handle = CubeMXCan_Private_GetHandle(hfdcan); - if (handle == NULL) { - for (uint32_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { - if (s_handles[i].hfdcan == NULL) { - handle = &s_handles[i]; + CubeMXCan_Handle *handle = NULL; + bool register_ok = false; + + CRITICAL_SECTION + { + handle = CubeMXCan_Private_GetHandle(hfdcan); + if (handle == NULL) { + for (uint32_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { + if (s_handles[i].hfdcan == NULL) { + handle = &s_handles[i]; + memset(handle, 0, sizeof(*handle)); + handle->hfdcan = hfdcan; + break; + } + } + } + + if (handle != NULL) { + handle->config = *config; + handle->tx_head = 0U; + handle->tx_count = 0U; + handle->started = false; + + if (CubeMXCan_Private_RegisterHandle(hfdcan, handle) == HAL_OK) { + register_ok = true; + } else { memset(handle, 0, sizeof(*handle)); - handle->hfdcan = hfdcan; - break; + handle = NULL; } } } @@ -116,12 +136,7 @@ CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, const CubeCAN_Conf return NULL; } - handle->config = *config; - handle->tx_head = 0U; - handle->tx_count = 0U; - handle->started = false; - - if (CubeMXCan_Private_RegisterHandle(hfdcan, handle) != HAL_OK) { + if (!register_ok) { LOGOMATIC("CubeMXCan_Init: failed to register handle\n"); return NULL; } @@ -135,7 +150,6 @@ CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, const CubeCAN_Conf if (!s_timer_started) { s_timer_started = true; } - return handle; } @@ -149,7 +163,11 @@ HAL_StatusTypeDef CubeMXCan_Start(CubeMXCan_Handle *handle) return HAL_ERROR; } - handle->started = true; + CRITICAL_SECTION + { + handle->started = true; + } + return HAL_OK; } @@ -159,12 +177,15 @@ HAL_StatusTypeDef CubeMXCan_Stop(CubeMXCan_Handle *handle) return HAL_ERROR; } + CRITICAL_SECTION + { + handle->started = false; + } + if (HAL_FDCAN_Stop(handle->hfdcan) != HAL_OK) { return HAL_ERROR; } - handle->started = false; - return HAL_OK; } @@ -175,8 +196,13 @@ HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *handle) } (void)CubeMXCan_Stop(handle); - CubeMXCan_Private_UnregisterHandle(handle->hfdcan); - memset(handle, 0, sizeof(*handle)); + + CRITICAL_SECTION + { + CubeMXCan_Private_UnregisterHandle(handle->hfdcan); + memset(handle, 0, sizeof(*handle)); + } + return HAL_OK; } @@ -195,13 +221,16 @@ HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *handle, const GRCAN_TxMess return HAL_ERROR; } - uint32_t insert_index = (handle->tx_head + handle->tx_count) % CUBEMX_CAN_TX_QUEUE_SIZE; - handle->tx_queue[insert_index] = *message; + CRITICAL_SECTION + { + uint32_t insert_index = (handle->tx_head + handle->tx_count) % CUBEMX_CAN_TX_QUEUE_SIZE; + handle->tx_queue[insert_index] = *message; - if (handle->tx_count < CUBEMX_CAN_TX_QUEUE_SIZE) { - handle->tx_count++; - } else { - handle->tx_head = (handle->tx_head + 1U) % CUBEMX_CAN_TX_QUEUE_SIZE; + if (handle->tx_count < CUBEMX_CAN_TX_QUEUE_SIZE) { + handle->tx_count++; + } else { + handle->tx_head = (handle->tx_head + 1U) % CUBEMX_CAN_TX_QUEUE_SIZE; + } } return HAL_OK; diff --git a/Lib/Peripherals/CubeCAN/Src/can_it.c b/Lib/Peripherals/CubeCAN/Src/can_it.c index 309f6d174..b9ffa71ad 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_it.c +++ b/Lib/Peripherals/CubeCAN/Src/can_it.c @@ -37,8 +37,18 @@ void CubeMXCan_OnRxFifo0(FDCAN_HandleTypeDef *hfdcan) return; } - CubeMXCan_Handle *handle = CubeMXCan_Private_GetHandle(hfdcan); - if (handle == NULL || handle->config.rx_callback == NULL) { + CubeCAN_RxCallback rx_callback_stack = NULL; + void *user_ctx_stack = NULL; + + CRITICAL_SECTION { + CubeMXCan_Handle *handle = CubeMXCan_Private_GetHandle(hfdcan); + if (handle != NULL && handle->config.rx_callback != NULL) { + rx_callback_stack = handle->config.rx_callback; + user_ctx_stack = handle->config.user_ctx; + } + } + + if (rx_callback_stack == NULL) { FDCAN_RxHeaderTypeDef rx_header = {0}; uint8_t rx_data[FDCAN_MAX_DATA_BYTES] = {0}; (void)HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &rx_header, rx_data); @@ -55,5 +65,5 @@ void CubeMXCan_OnRxFifo0(FDCAN_HandleTypeDef *hfdcan) CAN_Identifier identifier = Deconstruct_CAN_Identifier(rx_header.Identifier); uint8_t size = CubeMXCan_Private_DlcToBytes(rx_header.DataLength); - handle->config.rx_callback(handle->config.user_ctx, &identifier, rx_data, size); + rx_callback_stack(user_ctx_stack, &identifier, rx_data, size); } diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index 2ba864b0a..09f2932e3 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -86,6 +86,10 @@ uint8_t CubeMXCan_Private_DlcToBytes(uint32_t dlc) HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(CubeMXCan_Handle *handle) { if (handle == NULL || handle->hfdcan == NULL || handle->tx_count == 0U) { + return HAL_ERROR; + } + + if (handle->tx_count == 0U) { return HAL_OK; } From 99ac3bf795491b866ab4b3eb75a582a854bc8e64 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 18 Jul 2026 18:24:24 -0700 Subject: [PATCH 022/125] HOOTL testing of critical sections is very important Signed-off-by: Daniel Hansen --- Lib/GlobalShare/Inc/CriticalSection.h | 59 ++++++++++ Lib/GlobalShare/Test/criticalsection.c | 109 ++++++++++++++++++ Lib/GlobalShare/common.cmake | 10 ++ .../CubeCAN/Inc/Private/PrivateCubeMXCAN.h | 28 +---- Lib/Peripherals/CubeCAN/cubemx_can.cmake | 4 +- Lib/cmake/HOOTL.cmake | 1 + 6 files changed, 183 insertions(+), 28 deletions(-) create mode 100644 Lib/GlobalShare/Inc/CriticalSection.h create mode 100644 Lib/GlobalShare/Test/criticalsection.c diff --git a/Lib/GlobalShare/Inc/CriticalSection.h b/Lib/GlobalShare/Inc/CriticalSection.h new file mode 100644 index 000000000..d9b47c01a --- /dev/null +++ b/Lib/GlobalShare/Inc/CriticalSection.h @@ -0,0 +1,59 @@ +#include + +#include "Stringification.h" + +#ifndef CRITICAL_SECTION_H +#define CRITICAL_SECTION_H + +#ifdef HOOTL_TEST +#include + +extern pthread_mutex_t __mock_global_irq_mutex; +extern uint32_t __mock_primask_state; + +static inline uint32_t __get_PRIMASK(void) +{ + return __mock_primask_state; +} + +static inline void __disable_irq(void) +{ + pthread_mutex_lock(&__mock_global_irq_mutex); + __mock_primask_state = 1; +} + +static inline void __set_PRIMASK(uint32_t state) +{ + pthread_mutex_unlock(&__mock_global_irq_mutex); + __mock_primask_state = state; +} +#endif + +/** + * @brief Internal function to automatically restore the interrupt state when exiting a critical section. + * + * This function is intended to be used with the GCC cleanup attribute to automatically restore the interrupt state when a critical section is exited. It takes a pointer to a state variable that holds + * the previous interrupt state and restores it using the __set_PRIMASK function. + * + * @warning This function is intended for internal use only and should not be called directly by user code. Use the CRITICAL_SECTION macro instead. + */ +static inline void _magic_auto_exit_critical(uint32_t *state_var) +{ + if (state_var) { + __set_PRIMASK(*state_var); + } +} + +/** + * @brief Macro to create a critical section that disables interrupts for the duration of the block. + * + * This macro uses the GCC cleanup attribute to automatically restore the interrupt state when the block is exited, regardless of how the block is exited (e.g., return, break, continue). + * + * @warning This macro should be used with caution, as it can lead to deadlocks or other issues if not used correctly. It is recommended to use this macro only in situations where it is necessary to + * disable interrupts for a short period of time. + */ +#define CRITICAL_SECTION \ + for (__attribute__((cleanup(_magic_auto_exit_critical))) uint32_t CONCAT(auto_state_, __LINE__) = __get_PRIMASK(), CONCAT(auto_run_, __LINE__) = (__disable_irq(), 1); \ + CONCAT(auto_run_, __LINE__); CONCAT(auto_run_, __LINE__) = 0) + +#endif diff --git a/Lib/GlobalShare/Test/criticalsection.c b/Lib/GlobalShare/Test/criticalsection.c new file mode 100644 index 000000000..472d61a44 --- /dev/null +++ b/Lib/GlobalShare/Test/criticalsection.c @@ -0,0 +1,109 @@ +#include "CriticalSection.h" + +#include +#include +#include + +#include "Unused.h" + +#define NUM_THREADS 40 +#define INCREMENTS_PER_THREAD 100000 + +pthread_mutex_t __mock_global_irq_mutex; +uint32_t __mock_primask_state = 0; + +__attribute__((constructor)) static void init_recursive_mock_mutex(void) +{ + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&__mock_global_irq_mutex, &attr); + pthread_mutexattr_destroy(&attr); +} + +long long global_counter = 0; + +void *thread_worker_good(void *arg) +{ + UNUSED(arg); + + for (int i = 0; i < INCREMENTS_PER_THREAD; i++) { + CRITICAL_SECTION + { + CRITICAL_SECTION + { + global_counter++; + } + } + } + + return NULL; +} + +void *thread_worker_bad(void *arg) +{ + UNUSED(arg); + + for (int i = 0; i < INCREMENTS_PER_THREAD; i++) { + global_counter++; + } + + return NULL; +} + +int main(void) +{ + pthread_t threads[NUM_THREADS]; + int thread_ids[NUM_THREADS]; + + printf("Starting %d 'good' threads, each incrementing %d times...\n", NUM_THREADS, INCREMENTS_PER_THREAD); + global_counter = 0; + + for (int i = 0; i < NUM_THREADS; i++) { + thread_ids[i] = i; + if (pthread_create(&threads[i], NULL, thread_worker_good, &thread_ids[i]) != 0) { + printf("Failed to create thread"); + return 1; + } + } + + for (int i = 0; i < NUM_THREADS; i++) { + pthread_join(threads[i], NULL); + } + + long long expected_value = (long long)NUM_THREADS * INCREMENTS_PER_THREAD; + printf("\tExpected final counter value: %lld\n", expected_value); + printf("\tActual global_counter value: %lld\n", global_counter); + + if (global_counter == expected_value) { + printf("\tMocks and nested critical sections passed!\n"); + } else { + printf("\tData race detected! Your critical section failed.\n"); + return 2; + } + + printf("\nStarting %d 'bad' threads, each incrementing %d times...\n", NUM_THREADS, INCREMENTS_PER_THREAD); + global_counter = 0; + + for (int i = 0; i < NUM_THREADS; i++) { + thread_ids[i] = i; + if (pthread_create(&threads[i], NULL, thread_worker_bad, &thread_ids[i]) != 0) { + printf("Failed to create thread"); + return 3; + } + } + + for (int i = 0; i < NUM_THREADS; i++) { + pthread_join(threads[i], NULL); + } + + printf("\tExpected final counter value: %lld\n", expected_value); + printf("\tActual global_counter value: %lld\n", global_counter); + if (global_counter == expected_value) { + printf("\tUnexpectedly, the counter is correct without critical sections. This is highly unlikely and may indicate a problem with the test setup.\n"); + return 4; + } + + printf("\tAs expected, the counter is incorrect without critical sections. Data race detected!\n"); + return 0; +} diff --git a/Lib/GlobalShare/common.cmake b/Lib/GlobalShare/common.cmake index c47123510..116b5485b 100644 --- a/Lib/GlobalShare/common.cmake +++ b/Lib/GlobalShare/common.cmake @@ -51,4 +51,14 @@ if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") ) target_link_libraries(verify_min_max PRIVATE GLOBALSHARE_LIB) add_test(verify_min_max_test verify_min_max) + + find_package(Threads REQUIRED) + add_executable(criticalsection) + target_sources( + criticalsection + PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/Test/criticalsection.c + ) + target_link_libraries(criticalsection PRIVATE GLOBALSHARE_LIB Threads::Threads) + add_test(criticalsection_test criticalsection) endif() diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h index f0e0a8dfa..7477ffb06 100644 --- a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h +++ b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h @@ -4,38 +4,12 @@ #include "CubeMXCan.h" #include "Stringification.h" +#include "Logomatic.h" #include "main.h" #ifndef PRIVATE_CUBE_MX_CAN_H #define PRIVATE_CUBE_MX_CAN_H -/** - * @brief Internal function to automatically restore the interrupt state when exiting a critical section. - * - * This function is intended to be used with the GCC cleanup attribute to automatically restore the interrupt state when a critical section is exited. It takes a pointer to a state variable that holds - * the previous interrupt state and restores it using the __set_PRIMASK function. - * - * @warning This function is intended for internal use only and should not be called directly by user code. Use the CRITICAL_SECTION macro instead. - */ -static inline void _magic_auto_exit_critical(uint32_t *state_var) -{ - if (state_var) { - __set_PRIMASK(*state_var); - } -} - -/** - * @brief Macro to create a critical section that disables interrupts for the duration of the block. - * - * This macro uses the GCC cleanup attribute to automatically restore the interrupt state when the block is exited, regardless of how the block is exited (e.g., return, break, continue). - * - * @warning This macro should be used with caution, as it can lead to deadlocks or other issues if not used correctly. It is recommended to use this macro only in situations where it is necessary to - * disable interrupts for a short period of time. - */ -#define CRITICAL_SECTION \ - for (__attribute__((cleanup(_magic_auto_exit_critical))) uint32_t CONCAT(auto_state_, __LINE__) = __get_PRIMASK(), CONCAT(auto_run_, __LINE__) = (__disable_irq(), 1); \ - CONCAT(auto_run_, __LINE__); CONCAT(auto_run_, __LINE__) = 0) - /** * @brief CubeMX CAN handle structure * diff --git a/Lib/Peripherals/CubeCAN/cubemx_can.cmake b/Lib/Peripherals/CubeCAN/cubemx_can.cmake index 3fe5c3cd6..23a051caa 100644 --- a/Lib/Peripherals/CubeCAN/cubemx_can.cmake +++ b/Lib/Peripherals/CubeCAN/cubemx_can.cmake @@ -20,4 +20,6 @@ target_link_libraries( CANfigurator ) -# TODO Unit testing +if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") + # FIXME Add HOOTL tests +endif() diff --git a/Lib/cmake/HOOTL.cmake b/Lib/cmake/HOOTL.cmake index e9fc8b613..e2dfaea15 100644 --- a/Lib/cmake/HOOTL.cmake +++ b/Lib/cmake/HOOTL.cmake @@ -29,6 +29,7 @@ add_compile_options( -Wvla -Wdouble-promotion -g + -DHOOTL_TEST ) if(APPLE) # MacOS has a different syntax for linker fatal warnings From f5a178c8df9f595cab86000dd3a9902d2db0831e Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 18 Jul 2026 18:28:58 -0700 Subject: [PATCH 023/125] Make variable names harder to accidentally cross And also you should never start a variable with `_` unless you are doing the dark magic, not merely using it... Signed-off-by: Daniel Hansen --- Lib/GlobalShare/Inc/CriticalSection.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/GlobalShare/Inc/CriticalSection.h b/Lib/GlobalShare/Inc/CriticalSection.h index d9b47c01a..7e6fd0d8d 100644 --- a/Lib/GlobalShare/Inc/CriticalSection.h +++ b/Lib/GlobalShare/Inc/CriticalSection.h @@ -37,7 +37,7 @@ static inline void __set_PRIMASK(uint32_t state) * * @warning This function is intended for internal use only and should not be called directly by user code. Use the CRITICAL_SECTION macro instead. */ -static inline void _magic_auto_exit_critical(uint32_t *state_var) +static inline void _magic_auto_critical_exit(uint32_t *state_var) { if (state_var) { __set_PRIMASK(*state_var); @@ -53,7 +53,7 @@ static inline void _magic_auto_exit_critical(uint32_t *state_var) * disable interrupts for a short period of time. */ #define CRITICAL_SECTION \ - for (__attribute__((cleanup(_magic_auto_exit_critical))) uint32_t CONCAT(auto_state_, __LINE__) = __get_PRIMASK(), CONCAT(auto_run_, __LINE__) = (__disable_irq(), 1); \ - CONCAT(auto_run_, __LINE__); CONCAT(auto_run_, __LINE__) = 0) + for (__attribute__((cleanup(_magic_auto_critical_exit))) uint32_t CONCAT(_magic_auto_critical_state_, __LINE__) = __get_PRIMASK(), CONCAT(_magic_auto_critical_run_, __LINE__) = (__disable_irq(), 1); \ + CONCAT(_magic_auto_critical_run_, __LINE__); CONCAT(_magic_auto_critical_run_, __LINE__) = 0) #endif From 90a0c148fdcb9cd0ba2dbb8ee2fd072f58462477 Mon Sep 17 00:00:00 2001 From: TrainmanR Date: Mon, 20 Jul 2026 12:19:43 -0700 Subject: [PATCH 024/125] Scripting for CubeMX Templates IOC Generation Numereous issues with relative paths that were created in CUBEMX, so to solve template generation we decided to test scripts, the CMAKE one is meant for all OS/use, but the rest are just redundancies/backups in case it fails --- CUBEMXTESTING/Autogen/Inc/can_cfg.h | 2 + CUBEMXTESTING/CUBEMXTESTING.ioc | 8 +- tools/ConfigureCubeMXPaths.cmake | 220 +++++++++++++++++++++++ tools/configure_cubemx_paths.ps1 | 119 +++++++++++++ tools/configure_cubemx_paths_linux.sh | 245 ++++++++++++++++++++++++++ tools/configure_cubemx_paths_macos.sh | 245 ++++++++++++++++++++++++++ 6 files changed, 835 insertions(+), 4 deletions(-) create mode 100644 tools/ConfigureCubeMXPaths.cmake create mode 100644 tools/configure_cubemx_paths.ps1 create mode 100644 tools/configure_cubemx_paths_linux.sh create mode 100644 tools/configure_cubemx_paths_macos.sh diff --git a/CUBEMXTESTING/Autogen/Inc/can_cfg.h b/CUBEMXTESTING/Autogen/Inc/can_cfg.h index 288ec9a9b..0c6609c06 100644 --- a/CUBEMXTESTING/Autogen/Inc/can_cfg.h +++ b/CUBEMXTESTING/Autogen/Inc/can_cfg.h @@ -51,6 +51,8 @@ #define USECAN2 +#define USECAN3 + /* Timers enabled in CubeMX. */ #define CUBEMX_HAS_TIM5 diff --git a/CUBEMXTESTING/CUBEMXTESTING.ioc b/CUBEMXTESTING/CUBEMXTESTING.ioc index 1d4d092cb..098aab57a 100644 --- a/CUBEMXTESTING/CUBEMXTESTING.ioc +++ b/CUBEMXTESTING/CUBEMXTESTING.ioc @@ -129,16 +129,16 @@ ProjectManager.ProjectStructure= ProjectManager.RegisterCallBack= ProjectManager.StackSize=0x400 ProjectManager.TargetToolchain=EWARM V8.50 -ProjectManager.TemplateDestinationPath=. -ProjectManager.TemplateSourcePath=..\\Lib\\CubeMXTemplates -ProjectManager.TemplatesList=Autogen\\Inc\\can_cfg_h.ftl, +ProjectManager.TemplateDestinationPath=C\:\\Users\\maxnm\\Firmware\\CUBEMXTESTING +ProjectManager.TemplateSourcePath=C\:\\Users\\maxnm\\Firmware\\Lib\\CubeMXTemplates +ProjectManager.TemplatesList=\\Autogen\\Inc\\can_cfg_h.ftl, ProjectManager.ToolChainLocation= ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=false ProjectManager.UseDefaultDestinationPath=true ProjectManager.UseDefaultSourcePath=true -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_TIM5_Init-TIM5-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_TIM5_Init-TIM5-false-HAL-true,6-MX_FDCAN3_Init-FDCAN3-false-HAL-true RCC.ADC12Freq_Value=160000000 RCC.ADC345Freq_Value=160000000 RCC.AHBFreq_Value=160000000 diff --git a/tools/ConfigureCubeMXPaths.cmake b/tools/ConfigureCubeMXPaths.cmake new file mode 100644 index 000000000..767cc4bd9 --- /dev/null +++ b/tools/ConfigureCubeMXPaths.cmake @@ -0,0 +1,220 @@ +# ConfigureCubeMXPaths.cmake +# +# Cross-platform STM32CubeMX template path configuration. +# +# Expected repository layout: +# +# Firmware/ +# ├── tools/ +# │ └── ConfigureCubeMXPaths.cmake +# ├── CUBEMXTESTING/ +# │ └── CUBEMXTESTING.ioc +# └── Lib/ +# └── CubeMXTemplates/ +# └── Autogen/ +# └── Inc/ +# └── can_cfg_h.ftl +# +# Run manually from the repository root: +# +# cmake -P tools/ConfigureCubeMXPaths.cmake +# +# Optional overrides: +# +# cmake +# -DIOC_FILE=/path/to/project.ioc +# -DTEMPLATE_ROOT=/path/to/CubeMXTemplates +# -DPROJECT_OUTPUT_DIR=/path/to/project +# -P tools/ConfigureCubeMXPaths.cmake +# +# This script writes absolute paths because STM32CubeMX does not reliably +# resolve relative custom-template paths. + +cmake_minimum_required(VERSION 3.20) + +# --------------------------------------------------------------------------- +# Locate repository and default paths +# --------------------------------------------------------------------------- + +get_filename_component(SCRIPT_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY) +get_filename_component(REPOSITORY_ROOT "${SCRIPT_DIR}/.." ABSOLUTE) + +if(NOT DEFINED IOC_FILE) + set(IOC_FILE + "${REPOSITORY_ROOT}/CUBEMXTESTING/CUBEMXTESTING.ioc" + ) +endif() + +if(NOT DEFINED PROJECT_OUTPUT_DIR) + set(PROJECT_OUTPUT_DIR + "${REPOSITORY_ROOT}/CUBEMXTESTING" + ) +endif() + +if(NOT DEFINED TEMPLATE_ROOT) + set(TEMPLATE_ROOT + "${REPOSITORY_ROOT}/Lib/CubeMXTemplates" + ) +endif() + +set(TEMPLATE_RELATIVE_PATH + "Autogen/Inc/can_cfg_h.ftl" +) + +get_filename_component(IOC_FILE "${IOC_FILE}" ABSOLUTE) +get_filename_component(PROJECT_OUTPUT_DIR "${PROJECT_OUTPUT_DIR}" ABSOLUTE) +get_filename_component(TEMPLATE_ROOT "${TEMPLATE_ROOT}" ABSOLUTE) + +set(TEMPLATE_FILE + "${TEMPLATE_ROOT}/${TEMPLATE_RELATIVE_PATH}" +) + +# --------------------------------------------------------------------------- +# Validate inputs +# --------------------------------------------------------------------------- + +if(NOT EXISTS "${IOC_FILE}") + message(FATAL_ERROR + "CubeMX .ioc file was not found:\n" + " ${IOC_FILE}" + ) +endif() + +if(NOT IS_DIRECTORY "${PROJECT_OUTPUT_DIR}") + message(FATAL_ERROR + "CubeMX project output directory was not found:\n" + " ${PROJECT_OUTPUT_DIR}" + ) +endif() + +if(NOT IS_DIRECTORY "${TEMPLATE_ROOT}") + message(FATAL_ERROR + "CubeMX template root was not found:\n" + " ${TEMPLATE_ROOT}" + ) +endif() + +if(NOT EXISTS "${TEMPLATE_FILE}") + message(FATAL_ERROR + "CubeMX FreeMarker template was not found:\n" + " ${TEMPLATE_FILE}" + ) +endif() + +# --------------------------------------------------------------------------- +# Convert paths to the format expected by CubeMX's .ioc property file +# --------------------------------------------------------------------------- + +function(convert_to_cubemx_path INPUT_PATH OUTPUT_VARIABLE) + if(WIN32) + # Convert: + # C:/Users/name/Firmware + # to: + # C\:\\Users\\name\\Firmware + file(TO_NATIVE_PATH "${INPUT_PATH}" NATIVE_PATH) + string(REPLACE "\\" "\\\\" ESCAPED_PATH "${NATIVE_PATH}") + string(REPLACE ":" "\\:" ESCAPED_PATH "${ESCAPED_PATH}") + else() + # macOS/Linux paths use forward slashes and require no drive-letter + # escaping. + file(TO_CMAKE_PATH "${INPUT_PATH}" ESCAPED_PATH) + endif() + + set("${OUTPUT_VARIABLE}" "${ESCAPED_PATH}" PARENT_SCOPE) +endfunction() + +convert_to_cubemx_path( + "${PROJECT_OUTPUT_DIR}" + CUBEMX_PROJECT_OUTPUT_DIR +) + +convert_to_cubemx_path( + "${TEMPLATE_ROOT}" + CUBEMX_TEMPLATE_ROOT +) + +if(WIN32) + set(CUBEMX_TEMPLATE_LIST + "\\\\Autogen\\\\Inc\\\\can_cfg_h.ftl," + ) +else() + set(CUBEMX_TEMPLATE_LIST + "/Autogen/Inc/can_cfg_h.ftl," + ) +endif() + +set(DESTINATION_LINE + "ProjectManager.TemplateDestinationPath=${CUBEMX_PROJECT_OUTPUT_DIR}" +) + +set(SOURCE_LINE + "ProjectManager.TemplateSourcePath=${CUBEMX_TEMPLATE_ROOT}" +) + +set(TEMPLATES_LINE + "ProjectManager.TemplatesList=${CUBEMX_TEMPLATE_LIST}" +) + +# --------------------------------------------------------------------------- +# Rewrite or add the three CubeMX settings +# --------------------------------------------------------------------------- + +file(STRINGS "${IOC_FILE}" IOC_LINES ENCODING UTF-8) + +set(UPDATED_CONTENT "") +set(FOUND_DESTINATION FALSE) +set(FOUND_SOURCE FALSE) +set(FOUND_TEMPLATES FALSE) + +foreach(LINE IN LISTS IOC_LINES) + if(LINE MATCHES "^ProjectManager\\.TemplateDestinationPath=") + string(APPEND UPDATED_CONTENT "${DESTINATION_LINE}\n") + set(FOUND_DESTINATION TRUE) + + elseif(LINE MATCHES "^ProjectManager\\.TemplateSourcePath=") + string(APPEND UPDATED_CONTENT "${SOURCE_LINE}\n") + set(FOUND_SOURCE TRUE) + + elseif(LINE MATCHES "^ProjectManager\\.TemplatesList=") + string(APPEND UPDATED_CONTENT "${TEMPLATES_LINE}\n") + set(FOUND_TEMPLATES TRUE) + + else() + string(APPEND UPDATED_CONTENT "${LINE}\n") + endif() +endforeach() + +if(NOT FOUND_DESTINATION) + string(APPEND UPDATED_CONTENT "${DESTINATION_LINE}\n") +endif() + +if(NOT FOUND_SOURCE) + string(APPEND UPDATED_CONTENT "${SOURCE_LINE}\n") +endif() + +if(NOT FOUND_TEMPLATES) + string(APPEND UPDATED_CONTENT "${TEMPLATES_LINE}\n") +endif() + +# Keep a backup of the current .ioc file before modifying it. +configure_file( + "${IOC_FILE}" + "${IOC_FILE}.bak" + COPYONLY +) + +file(WRITE "${IOC_FILE}" "${UPDATED_CONTENT}") + +# --------------------------------------------------------------------------- +# Report result +# --------------------------------------------------------------------------- + +message(STATUS "") +message(STATUS "CubeMX template configuration updated successfully.") +message(STATUS "") +message(STATUS "${DESTINATION_LINE}") +message(STATUS "${SOURCE_LINE}") +message(STATUS "${TEMPLATES_LINE}") +message(STATUS "") +message(STATUS "Backup created at:") +message(STATUS " ${IOC_FILE}.bak") diff --git a/tools/configure_cubemx_paths.ps1 b/tools/configure_cubemx_paths.ps1 new file mode 100644 index 000000000..4144b2eba --- /dev/null +++ b/tools/configure_cubemx_paths.ps1 @@ -0,0 +1,119 @@ +# configure_cubemx_paths.ps1 +# Updates STM32CubeMX template paths using the current repository location. +# +# Expected repository structure: +# Firmware/ +# ├── tools/configure_cubemx_paths.ps1 +# ├── CUBEMXTESTING/CUBEMXTESTING.ioc +# └── Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl + +$ErrorActionPreference = "Stop" + +# Script location: Firmware/tools +$toolsDirectory = Split-Path -Parent $MyInvocation.MyCommand.Path + +# Repository root: Firmware +$repoRoot = Split-Path -Parent $toolsDirectory + +$iocPath = Join-Path $repoRoot "CUBEMXTESTING\CUBEMXTESTING.ioc" +$projectPath = Join-Path $repoRoot "CUBEMXTESTING" +$templatePath = Join-Path $repoRoot "Lib\CubeMXTemplates" + +if (!(Test-Path -LiteralPath $iocPath)) { + Write-Error "Could not find CubeMX project file: $iocPath" + exit 1 +} + +if (!(Test-Path -LiteralPath $templatePath)) { + Write-Error "Could not find CubeMX template folder: $templatePath" + exit 1 +} + +$templateFile = Join-Path $templatePath "Autogen\Inc\can_cfg_h.ftl" +if (!(Test-Path -LiteralPath $templateFile)) { + Write-Error "Could not find CubeMX template file: $templateFile" + exit 1 +} + +# CubeMX .ioc escaping: +# C:\Users\... becomes C\:\\Users\\... +function Convert-ToCubeMXPath { + param( + [Parameter(Mandatory = $true)] + [string]$Path + ) + + return $Path.Replace("\", "\\").Replace(":", "\:") +} + +$escapedProjectPath = Convert-ToCubeMXPath -Path $projectPath +$escapedTemplatePath = Convert-ToCubeMXPath -Path $templatePath + +$desiredDestinationLine = "ProjectManager.TemplateDestinationPath=$escapedProjectPath" +$desiredSourceLine = "ProjectManager.TemplateSourcePath=$escapedTemplatePath" + +# CubeMX expects a leading escaped backslash and a trailing comma here. +$desiredTemplatesLine = "ProjectManager.TemplatesList=\\Autogen\\Inc\\can_cfg_h.ftl," + +$content = Get-Content -LiteralPath $iocPath + +function Set-OrAddLine { + param( + [Parameter(Mandatory = $true)] + [string[]]$Content, + + [Parameter(Mandatory = $true)] + [string]$Key, + + [Parameter(Mandatory = $true)] + [string]$Replacement + ) + + $pattern = "^" + [regex]::Escape($Key) + "=.*$" + $found = $false + + $updated = foreach ($line in $Content) { + if ($line -match $pattern) { + $found = $true + $Replacement + } + else { + $line + } + } + + if (!$found) { + $updated += $Replacement + } + + return ,$updated +} + +$content = Set-OrAddLine ` + -Content $content ` + -Key "ProjectManager.TemplateDestinationPath" ` + -Replacement $desiredDestinationLine + +$content = Set-OrAddLine ` + -Content $content ` + -Key "ProjectManager.TemplateSourcePath" ` + -Replacement $desiredSourceLine + +$content = Set-OrAddLine ` + -Content $content ` + -Key "ProjectManager.TemplatesList" ` + -Replacement $desiredTemplatesLine + +# Preserve a normal text encoding without adding a UTF-8 BOM. +[System.IO.File]::WriteAllLines( + $iocPath, + $content, + [System.Text.UTF8Encoding]::new($false) +) + +Write-Host "" +Write-Host "CubeMX template configuration updated successfully." +Write-Host "" +Write-Host $desiredDestinationLine +Write-Host $desiredSourceLine +Write-Host $desiredTemplatesLine \ No newline at end of file diff --git a/tools/configure_cubemx_paths_linux.sh b/tools/configure_cubemx_paths_linux.sh new file mode 100644 index 000000000..fda034ba7 --- /dev/null +++ b/tools/configure_cubemx_paths_linux.sh @@ -0,0 +1,245 @@ +#!/usr/bin/env bash +# +# Cross-platform Unix STM32CubeMX custom-template path configurator. +# Compatible with macOS Bash 3.2+ and common Linux Bash versions. +# +# Expected repository structure: +# +# Firmware/ +# ├── tools/ +# │ └── configure_cubemx_paths_linux.sh +# ├── CUBEMXTESTING/ +# │ └── CUBEMXTESTING.ioc +# └── Lib/ +# └── CubeMXTemplates/ +# └── Autogen/ +# └── Inc/ +# └── can_cfg_h.ftl +# +# Usage: +# bash tools/configure_cubemx_paths_linux.sh +# +# Optional overrides: +# IOC_FILE=/path/project.ioc \ +# PROJECT_OUTPUT_DIR=/path/project \ +# TEMPLATE_ROOT=/path/CubeMXTemplates \ +# bash tools/configure_cubemx_paths_linux.sh +# +# Behavior: +# - validates all expected paths; +# - removes stale or duplicate CubeMX template properties; +# - writes exactly one correct copy of each property; +# - creates an .ioc.bak backup; +# - writes through a temporary file; +# - verifies the result from disk; +# - is idempotent. + +set -euo pipefail + +EXPECTED_OS="linux" + +die() { + printf 'ERROR: %s\n' "$*" >&2 + exit 1 +} + +info() { + printf '%s\n' "$*" +} + +detect_os() { + case "$(uname -s)" in + Darwin) printf '%s\n' "macos" ;; + Linux) printf '%s\n' "linux" ;; + *) printf '%s\n' "unsupported" ;; + esac +} + +CURRENT_OS="$(detect_os)" +if [ "$CURRENT_OS" != "$EXPECTED_OS" ]; then + die "This script is intended for $EXPECTED_OS, but detected $CURRENT_OS." +fi + +# Resolve the physical directory containing this script without requiring +# realpath, which is not included with older macOS installations. +SCRIPT_DIR="$( + CDPATH= cd -- "$(dirname -- "$0")" >/dev/null 2>&1 + pwd -P +)" +REPOSITORY_ROOT="$( + CDPATH= cd -- "$SCRIPT_DIR/.." >/dev/null 2>&1 + pwd -P +)" + +IOC_FILE="${IOC_FILE:-$REPOSITORY_ROOT/CUBEMXTESTING/CUBEMXTESTING.ioc}" +PROJECT_OUTPUT_DIR="${PROJECT_OUTPUT_DIR:-$REPOSITORY_ROOT/CUBEMXTESTING}" +TEMPLATE_ROOT="${TEMPLATE_ROOT:-$REPOSITORY_ROOT/Lib/CubeMXTemplates}" +TEMPLATE_FILE="$TEMPLATE_ROOT/Autogen/Inc/can_cfg_h.ftl" + +[ -f "$IOC_FILE" ] || + die "CubeMX .ioc file was not found: $IOC_FILE" + +[ -d "$PROJECT_OUTPUT_DIR" ] || + die "CubeMX project output directory was not found: $PROJECT_OUTPUT_DIR" + +[ -d "$TEMPLATE_ROOT" ] || + die "CubeMX template root was not found: $TEMPLATE_ROOT" + +[ -f "$TEMPLATE_FILE" ] || + die "CubeMX FreeMarker template was not found: $TEMPLATE_FILE" + +# Convert directories to physical absolute paths. +PROJECT_OUTPUT_DIR="$( + CDPATH= cd -- "$PROJECT_OUTPUT_DIR" >/dev/null 2>&1 + pwd -P +)" +TEMPLATE_ROOT="$( + CDPATH= cd -- "$TEMPLATE_ROOT" >/dev/null 2>&1 + pwd -P +)" + +DESTINATION_KEY='ProjectManager.TemplateDestinationPath' +SOURCE_KEY='ProjectManager.TemplateSourcePath' +TEMPLATES_KEY='ProjectManager.TemplatesList' + +DESTINATION_LINE="${DESTINATION_KEY}=${PROJECT_OUTPUT_DIR}" +SOURCE_LINE="${SOURCE_KEY}=${TEMPLATE_ROOT}" +TEMPLATES_LINE="${TEMPLATES_KEY}=/Autogen/Inc/can_cfg_h.ftl," + +IOC_DIRECTORY="$(dirname -- "$IOC_FILE")" +IOC_BASENAME="$(basename -- "$IOC_FILE")" +BACKUP_FILE="${IOC_FILE}.bak" +TEMP_FILE="$(mktemp "${IOC_DIRECTORY}/.${IOC_BASENAME}.tmp.XXXXXX")" + +cleanup() { + if [ -n "${TEMP_FILE:-}" ] && [ -f "$TEMP_FILE" ]; then + rm -f -- "$TEMP_FILE" + fi +} +trap cleanup EXIT HUP INT TERM + +# Back up the current file before any modification. +cp -p -- "$IOC_FILE" "$BACKUP_FILE" + +# Remove every existing copy of the three properties and append one stable, +# complete block. awk preserves all unrelated lines verbatim at the text level, +# including semicolons and similarly named properties. +awk \ + -v destination_key="$DESTINATION_KEY" \ + -v source_key="$SOURCE_KEY" \ + -v templates_key="$TEMPLATES_KEY" \ + -v destination_line="$DESTINATION_LINE" \ + -v source_line="$SOURCE_LINE" \ + -v templates_line="$TEMPLATES_LINE" ' +BEGIN { + destination_prefix = destination_key "=" + source_prefix = source_key "=" + templates_prefix = templates_key "=" +} +{ + # Remove a possible CR from CRLF input so Unix output is consistently LF. + sub(/\r$/, "", $0) + + if (index($0, destination_prefix) == 1) { + next + } + + if (index($0, source_prefix) == 1) { + next + } + + if (index($0, templates_prefix) == 1) { + next + } + + lines[++count] = $0 +} +END { + # Remove trailing blank lines before appending the generated block. + while (count > 0 && lines[count] == "") { + count-- + } + + for (i = 1; i <= count; i++) { + print lines[i] + } + + if (count > 0) { + print "" + } + + print destination_line + print source_line + print templates_line +} +' "$IOC_FILE" > "$TEMP_FILE" + +[ -s "$TEMP_FILE" ] || + die "Generated temporary .ioc file is empty: $TEMP_FILE" + +verify_exact_line_once() { + expected_line="$1" + description="$2" + + # grep -F treats the path as literal text. -x requires the full line. + count="$( + grep -Fxc -- "$expected_line" "$TEMP_FILE" 2>/dev/null || true + )" + + [ "$count" -eq 1 ] || + die "$description verification failed; expected exactly once, found $count." +} + +verify_key_once() { + key="$1" + description="$2" + + count="$( + awk -v prefix="${key}=" ' + index($0, prefix) == 1 { count++ } + END { print count + 0 } + ' "$TEMP_FILE" + )" + + [ "$count" -eq 1 ] || + die "$description key verification failed; expected exactly one property, found $count." +} + +verify_key_once "$DESTINATION_KEY" "Destination path" +verify_key_once "$SOURCE_KEY" "Source path" +verify_key_once "$TEMPLATES_KEY" "Template list" + +verify_exact_line_once "$DESTINATION_LINE" "Destination path" +verify_exact_line_once "$SOURCE_LINE" "Source path" +verify_exact_line_once "$TEMPLATES_LINE" "Template list" + +# Replace the original only after all temporary-file checks pass. +mv -f -- "$TEMP_FILE" "$IOC_FILE" +TEMP_FILE="" + +# Verify the file again after it has been moved into place. +verify_disk_line_once() { + expected_line="$1" + description="$2" + + count="$( + grep -Fxc -- "$expected_line" "$IOC_FILE" 2>/dev/null || true + )" + + [ "$count" -eq 1 ] || + die "Post-write $description verification failed; found $count copies." +} + +verify_disk_line_once "$DESTINATION_LINE" "destination path" +verify_disk_line_once "$SOURCE_LINE" "source path" +verify_disk_line_once "$TEMPLATES_LINE" "template list" + +info "" +info "CubeMX template configuration updated and verified." +info "" +info "$DESTINATION_LINE" +info "$SOURCE_LINE" +info "$TEMPLATES_LINE" +info "" +info "Backup:" +info " $BACKUP_FILE" diff --git a/tools/configure_cubemx_paths_macos.sh b/tools/configure_cubemx_paths_macos.sh new file mode 100644 index 000000000..f7c0bafde --- /dev/null +++ b/tools/configure_cubemx_paths_macos.sh @@ -0,0 +1,245 @@ +#!/usr/bin/env bash +# +# Cross-platform Unix STM32CubeMX custom-template path configurator. +# Compatible with macOS Bash 3.2+ and common Linux Bash versions. +# +# Expected repository structure: +# +# Firmware/ +# ├── tools/ +# │ └── configure_cubemx_paths_macos.sh +# ├── CUBEMXTESTING/ +# │ └── CUBEMXTESTING.ioc +# └── Lib/ +# └── CubeMXTemplates/ +# └── Autogen/ +# └── Inc/ +# └── can_cfg_h.ftl +# +# Usage: +# bash tools/configure_cubemx_paths_macos.sh +# +# Optional overrides: +# IOC_FILE=/path/project.ioc \ +# PROJECT_OUTPUT_DIR=/path/project \ +# TEMPLATE_ROOT=/path/CubeMXTemplates \ +# bash tools/configure_cubemx_paths_macos.sh +# +# Behavior: +# - validates all expected paths; +# - removes stale or duplicate CubeMX template properties; +# - writes exactly one correct copy of each property; +# - creates an .ioc.bak backup; +# - writes through a temporary file; +# - verifies the result from disk; +# - is idempotent. + +set -euo pipefail + +EXPECTED_OS="macos" + +die() { + printf 'ERROR: %s\n' "$*" >&2 + exit 1 +} + +info() { + printf '%s\n' "$*" +} + +detect_os() { + case "$(uname -s)" in + Darwin) printf '%s\n' "macos" ;; + Linux) printf '%s\n' "linux" ;; + *) printf '%s\n' "unsupported" ;; + esac +} + +CURRENT_OS="$(detect_os)" +if [ "$CURRENT_OS" != "$EXPECTED_OS" ]; then + die "This script is intended for $EXPECTED_OS, but detected $CURRENT_OS." +fi + +# Resolve the physical directory containing this script without requiring +# realpath, which is not included with older macOS installations. +SCRIPT_DIR="$( + CDPATH= cd -- "$(dirname -- "$0")" >/dev/null 2>&1 + pwd -P +)" +REPOSITORY_ROOT="$( + CDPATH= cd -- "$SCRIPT_DIR/.." >/dev/null 2>&1 + pwd -P +)" + +IOC_FILE="${IOC_FILE:-$REPOSITORY_ROOT/CUBEMXTESTING/CUBEMXTESTING.ioc}" +PROJECT_OUTPUT_DIR="${PROJECT_OUTPUT_DIR:-$REPOSITORY_ROOT/CUBEMXTESTING}" +TEMPLATE_ROOT="${TEMPLATE_ROOT:-$REPOSITORY_ROOT/Lib/CubeMXTemplates}" +TEMPLATE_FILE="$TEMPLATE_ROOT/Autogen/Inc/can_cfg_h.ftl" + +[ -f "$IOC_FILE" ] || + die "CubeMX .ioc file was not found: $IOC_FILE" + +[ -d "$PROJECT_OUTPUT_DIR" ] || + die "CubeMX project output directory was not found: $PROJECT_OUTPUT_DIR" + +[ -d "$TEMPLATE_ROOT" ] || + die "CubeMX template root was not found: $TEMPLATE_ROOT" + +[ -f "$TEMPLATE_FILE" ] || + die "CubeMX FreeMarker template was not found: $TEMPLATE_FILE" + +# Convert directories to physical absolute paths. +PROJECT_OUTPUT_DIR="$( + CDPATH= cd -- "$PROJECT_OUTPUT_DIR" >/dev/null 2>&1 + pwd -P +)" +TEMPLATE_ROOT="$( + CDPATH= cd -- "$TEMPLATE_ROOT" >/dev/null 2>&1 + pwd -P +)" + +DESTINATION_KEY='ProjectManager.TemplateDestinationPath' +SOURCE_KEY='ProjectManager.TemplateSourcePath' +TEMPLATES_KEY='ProjectManager.TemplatesList' + +DESTINATION_LINE="${DESTINATION_KEY}=${PROJECT_OUTPUT_DIR}" +SOURCE_LINE="${SOURCE_KEY}=${TEMPLATE_ROOT}" +TEMPLATES_LINE="${TEMPLATES_KEY}=/Autogen/Inc/can_cfg_h.ftl," + +IOC_DIRECTORY="$(dirname -- "$IOC_FILE")" +IOC_BASENAME="$(basename -- "$IOC_FILE")" +BACKUP_FILE="${IOC_FILE}.bak" +TEMP_FILE="$(mktemp "${IOC_DIRECTORY}/.${IOC_BASENAME}.tmp.XXXXXX")" + +cleanup() { + if [ -n "${TEMP_FILE:-}" ] && [ -f "$TEMP_FILE" ]; then + rm -f -- "$TEMP_FILE" + fi +} +trap cleanup EXIT HUP INT TERM + +# Back up the current file before any modification. +cp -p -- "$IOC_FILE" "$BACKUP_FILE" + +# Remove every existing copy of the three properties and append one stable, +# complete block. awk preserves all unrelated lines verbatim at the text level, +# including semicolons and similarly named properties. +awk \ + -v destination_key="$DESTINATION_KEY" \ + -v source_key="$SOURCE_KEY" \ + -v templates_key="$TEMPLATES_KEY" \ + -v destination_line="$DESTINATION_LINE" \ + -v source_line="$SOURCE_LINE" \ + -v templates_line="$TEMPLATES_LINE" ' +BEGIN { + destination_prefix = destination_key "=" + source_prefix = source_key "=" + templates_prefix = templates_key "=" +} +{ + # Remove a possible CR from CRLF input so Unix output is consistently LF. + sub(/\r$/, "", $0) + + if (index($0, destination_prefix) == 1) { + next + } + + if (index($0, source_prefix) == 1) { + next + } + + if (index($0, templates_prefix) == 1) { + next + } + + lines[++count] = $0 +} +END { + # Remove trailing blank lines before appending the generated block. + while (count > 0 && lines[count] == "") { + count-- + } + + for (i = 1; i <= count; i++) { + print lines[i] + } + + if (count > 0) { + print "" + } + + print destination_line + print source_line + print templates_line +} +' "$IOC_FILE" > "$TEMP_FILE" + +[ -s "$TEMP_FILE" ] || + die "Generated temporary .ioc file is empty: $TEMP_FILE" + +verify_exact_line_once() { + expected_line="$1" + description="$2" + + # grep -F treats the path as literal text. -x requires the full line. + count="$( + grep -Fxc -- "$expected_line" "$TEMP_FILE" 2>/dev/null || true + )" + + [ "$count" -eq 1 ] || + die "$description verification failed; expected exactly once, found $count." +} + +verify_key_once() { + key="$1" + description="$2" + + count="$( + awk -v prefix="${key}=" ' + index($0, prefix) == 1 { count++ } + END { print count + 0 } + ' "$TEMP_FILE" + )" + + [ "$count" -eq 1 ] || + die "$description key verification failed; expected exactly one property, found $count." +} + +verify_key_once "$DESTINATION_KEY" "Destination path" +verify_key_once "$SOURCE_KEY" "Source path" +verify_key_once "$TEMPLATES_KEY" "Template list" + +verify_exact_line_once "$DESTINATION_LINE" "Destination path" +verify_exact_line_once "$SOURCE_LINE" "Source path" +verify_exact_line_once "$TEMPLATES_LINE" "Template list" + +# Replace the original only after all temporary-file checks pass. +mv -f -- "$TEMP_FILE" "$IOC_FILE" +TEMP_FILE="" + +# Verify the file again after it has been moved into place. +verify_disk_line_once() { + expected_line="$1" + description="$2" + + count="$( + grep -Fxc -- "$expected_line" "$IOC_FILE" 2>/dev/null || true + )" + + [ "$count" -eq 1 ] || + die "Post-write $description verification failed; found $count copies." +} + +verify_disk_line_once "$DESTINATION_LINE" "destination path" +verify_disk_line_once "$SOURCE_LINE" "source path" +verify_disk_line_once "$TEMPLATES_LINE" "template list" + +info "" +info "CubeMX template configuration updated and verified." +info "" +info "$DESTINATION_LINE" +info "$SOURCE_LINE" +info "$TEMPLATES_LINE" +info "" +info "Backup:" +info " $BACKUP_FILE" From 8f893a72248ea1e0badc7d4b9b4d5ec9442d34f6 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 18 Jul 2026 19:00:10 -0700 Subject: [PATCH 025/125] Advanced critical section usage Signed-off-by: Daniel Hansen --- Lib/GlobalShare/Inc/CriticalSection.h | 17 +++++++++++--- Lib/GlobalShare/Test/criticalsection.c | 5 +++-- Lib/Peripherals/CubeCAN/Src/can_it.c | 2 +- Lib/Peripherals/CubeCAN/Src/can_utils.c | 30 +++++++++++++++++++------ Lib/cmake/HOOTL.cmake | 2 ++ 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/Lib/GlobalShare/Inc/CriticalSection.h b/Lib/GlobalShare/Inc/CriticalSection.h index 7e6fd0d8d..c792731dc 100644 --- a/Lib/GlobalShare/Inc/CriticalSection.h +++ b/Lib/GlobalShare/Inc/CriticalSection.h @@ -9,7 +9,8 @@ #include extern pthread_mutex_t __mock_global_irq_mutex; -extern uint32_t __mock_primask_state; +extern _Thread_local uint32_t __mock_primask_state; +extern _Thread_local uint32_t __mock_irq_nesting_depth; static inline uint32_t __get_PRIMASK(void) { @@ -19,13 +20,23 @@ static inline uint32_t __get_PRIMASK(void) static inline void __disable_irq(void) { pthread_mutex_lock(&__mock_global_irq_mutex); - __mock_primask_state = 1; + if (__mock_irq_nesting_depth == 0) { + __mock_primask_state = 1; + } + __mock_irq_nesting_depth++; } static inline void __set_PRIMASK(uint32_t state) { + (void)state; + + __mock_irq_nesting_depth--; + + if (__mock_irq_nesting_depth == 0) { + __mock_primask_state = 0; + } + pthread_mutex_unlock(&__mock_global_irq_mutex); - __mock_primask_state = state; } #endif diff --git a/Lib/GlobalShare/Test/criticalsection.c b/Lib/GlobalShare/Test/criticalsection.c index 472d61a44..68ebae386 100644 --- a/Lib/GlobalShare/Test/criticalsection.c +++ b/Lib/GlobalShare/Test/criticalsection.c @@ -10,7 +10,8 @@ #define INCREMENTS_PER_THREAD 100000 pthread_mutex_t __mock_global_irq_mutex; -uint32_t __mock_primask_state = 0; +_Thread_local uint32_t __mock_primask_state = 0; +_Thread_local uint32_t __mock_irq_nesting_depth = 0; __attribute__((constructor)) static void init_recursive_mock_mutex(void) { @@ -21,7 +22,7 @@ __attribute__((constructor)) static void init_recursive_mock_mutex(void) pthread_mutexattr_destroy(&attr); } -long long global_counter = 0; +volatile long long global_counter = 0; void *thread_worker_good(void *arg) { diff --git a/Lib/Peripherals/CubeCAN/Src/can_it.c b/Lib/Peripherals/CubeCAN/Src/can_it.c index b9ffa71ad..f44df2258 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_it.c +++ b/Lib/Peripherals/CubeCAN/Src/can_it.c @@ -52,7 +52,7 @@ void CubeMXCan_OnRxFifo0(FDCAN_HandleTypeDef *hfdcan) FDCAN_RxHeaderTypeDef rx_header = {0}; uint8_t rx_data[FDCAN_MAX_DATA_BYTES] = {0}; (void)HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &rx_header, rx_data); - LOGOMATIC("CubeMXCan_OnRxFifo0: no handle or callback registered for %s\n", can_get_instance_name(hfdcan->Instance)); + LOGOMATIC("CubeMXCan_OnRxFifo0: no handle or callback registered for %s\n", CAN_GetInstanceName(hfdcan->Instance)); return; } diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index 09f2932e3..c0f247cef 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -85,20 +85,36 @@ uint8_t CubeMXCan_Private_DlcToBytes(uint32_t dlc) HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(CubeMXCan_Handle *handle) { - if (handle == NULL || handle->hfdcan == NULL || handle->tx_count == 0U) { + if (handle == NULL || handle->hfdcan == NULL) { return HAL_ERROR; } - if (handle->tx_count == 0U) { - return HAL_OK; + GRCAN_TxMessage message_copy; + bool message_found = false; + + CRITICAL_SECTION + { + if (handle->tx_count > 0U) { + message_copy = handle->tx_queue[handle->tx_head]; + message_found = true; + } + } + + if (!message_found) { + return HAL_ERROR; } - const GRCAN_TxMessage *message = &handle->tx_queue[handle->tx_head]; - if (HAL_FDCAN_AddMessageToTxFifoQ(handle->hfdcan, &message->tx_header, message->data) != HAL_OK) { + if (HAL_FDCAN_AddMessageToTxFifoQ(handle->hfdcan, &message_copy.tx_header, message_copy.data) != HAL_OK) { return HAL_ERROR; } - handle->tx_head = (handle->tx_head + 1U) % CUBEMX_CAN_TX_QUEUE_SIZE; - handle->tx_count--; + CRITICAL_SECTION + { + if (handle->tx_count > 0U) { + handle->tx_head = (handle->tx_head + 1U) % CUBEMX_CAN_TX_QUEUE_SIZE; + handle->tx_count--; + } + } + return HAL_OK; } diff --git a/Lib/cmake/HOOTL.cmake b/Lib/cmake/HOOTL.cmake index e2dfaea15..5689d4ce9 100644 --- a/Lib/cmake/HOOTL.cmake +++ b/Lib/cmake/HOOTL.cmake @@ -59,11 +59,13 @@ if(ADDRESS_SANITIZER) -fsanitize=address -fsanitize=undefined -fsanitize=leak + # -fsanitize=thread ) add_link_options( -fsanitize=address -fsanitize=undefined -fsanitize=leak + # -fsanitize=thread ) endif() endif() From b547af11a296de505e6113ae4c2b7d33850dca20 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 19 Jul 2026 23:15:17 -0700 Subject: [PATCH 026/125] In progress --- Check point save while working with atomics Signed-off-by: Daniel Hansen --- .../Application/Inc/CubeCAN_Config.h | 2 +- .../CubeCAN/Inc/Private/PrivateCubeMXCAN.h | 13 ++-- Lib/Peripherals/CubeCAN/Src/can_init.c | 43 ++++++----- Lib/Peripherals/CubeCAN/Src/can_it.c | 3 + Lib/Peripherals/CubeCAN/Src/can_utils.c | 73 ++++++++++++++----- 5 files changed, 93 insertions(+), 41 deletions(-) diff --git a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h index f3c02252e..3df036604 100644 --- a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h +++ b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h @@ -9,7 +9,7 @@ #define USECAN2 #define CUBEMX_CAN_TIMER_INSTANCE TIM5 -#define CUBEMX_CAN_TX_QUEUE_SIZE 20U +#define CUBEMX_CAN_TX_QUEUE_SIZE 32U #define CAN_TIMER_SEND_PERIOD_US 500U #endif diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h index 7477ffb06..7816f8086 100644 --- a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h +++ b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h @@ -1,15 +1,18 @@ #include +#include #include #include #include "CubeMXCan.h" -#include "Stringification.h" #include "Logomatic.h" +#include "Stringification.h" #include "main.h" #ifndef PRIVATE_CUBE_MX_CAN_H #define PRIVATE_CUBE_MX_CAN_H +#define TX_QUEUE_MASK (CUBEMX_CAN_TX_QUEUE_SIZE - 1U) + /** * @brief CubeMX CAN handle structure * @@ -25,10 +28,10 @@ typedef struct CubeMXCan_Handle { CubeCAN_Config config; /// @brief Transmission queue for the CubeMX CAN handle, containing the messages to be transmitted. GRCAN_TxMessage tx_queue[CUBEMX_CAN_TX_QUEUE_SIZE]; - /// @brief Index of the head of the transmission queue, indicating the next message to be transmitted. - uint32_t tx_head; - /// @brief Count of messages in the transmission queue, indicating the number of messages waiting to be transmitted. - uint32_t tx_count; + /// @brief Atomic head index for the transmission queue, indicating the next message to be transmitted. + _Atomic uint32_t tx_head; + /// @brief Atomic tail index for the transmission queue, indicating the next available slot for a new message. + _Atomic uint32_t tx_tail; /// @brief Flag indicating whether the CubeMX CAN handle has been started. bool started; } CubeMXCan_Handle; diff --git a/Lib/Peripherals/CubeCAN/Src/can_init.c b/Lib/Peripherals/CubeCAN/Src/can_init.c index 78904cfe8..35fc89899 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_init.c +++ b/Lib/Peripherals/CubeCAN/Src/can_init.c @@ -17,7 +17,7 @@ static bool s_timer_started = false; static CubeMXCan_RegistryEntry *CubeMXCan_FindRegistryEntry(FDCAN_GlobalTypeDef *instance) { - for (uint32_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { + for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { if (s_registry[i].instance == instance) { return &s_registry[i]; } @@ -33,7 +33,7 @@ static CubeMXCan_RegistryEntry *CubeMXCan_AllocRegistryEntry(FDCAN_GlobalTypeDef return entry; } - for (uint32_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { + for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { if (s_registry[i].instance == NULL) { s_registry[i].instance = instance; return &s_registry[i]; @@ -83,12 +83,20 @@ void CubeMXCan_Private_UnregisterHandle(FDCAN_HandleTypeDef *hfdcan) void CubeMXCan_Tick(void) { - for (uint32_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { + for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { CubeMXCan_Handle *handle = s_registry[i].handle; - if (handle == NULL || !handle->started) { + if (handle == NULL || handle->hfdcan == NULL || !handle->started) { continue; } + if (CubeMXCan_Private_IsDisabled(handle)) { + LOGOMATIC("CAN_send: currently in restricted operation mode\n"); + if (CubeMXCan_Private_RecoverPeripheral(handle->hfdcan) != HAL_OK) { + LOGOMATIC("CAN_send %d: failed to recover peripheral\n", (int)i); + continue; + } + } + (void)CubeMXCan_Private_SendQueuedMessage(handle); } } @@ -106,7 +114,7 @@ CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, const CubeCAN_Conf { handle = CubeMXCan_Private_GetHandle(hfdcan); if (handle == NULL) { - for (uint32_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { + for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { if (s_handles[i].hfdcan == NULL) { handle = &s_handles[i]; memset(handle, 0, sizeof(*handle)); @@ -118,8 +126,8 @@ CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, const CubeCAN_Conf if (handle != NULL) { handle->config = *config; - handle->tx_head = 0U; - handle->tx_count = 0U; + atomic_init (&handle->tx_head, 0U); + atomic_init (&handle->tx_tail, 0U); handle->started = false; if (CubeMXCan_Private_RegisterHandle(hfdcan, handle) == HAL_OK) { @@ -196,7 +204,7 @@ HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *handle) } (void)CubeMXCan_Stop(handle); - + CRITICAL_SECTION { CubeMXCan_Private_UnregisterHandle(handle->hfdcan); @@ -221,17 +229,18 @@ HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *handle, const GRCAN_TxMess return HAL_ERROR; } - CRITICAL_SECTION - { - uint32_t insert_index = (handle->tx_head + handle->tx_count) % CUBEMX_CAN_TX_QUEUE_SIZE; - handle->tx_queue[insert_index] = *message; + uint32_t current_tail = atomic_load(&handle->tx_tail); + uint32_t current_head = atomic_load(&handle->tx_head); - if (handle->tx_count < CUBEMX_CAN_TX_QUEUE_SIZE) { - handle->tx_count++; - } else { - handle->tx_head = (handle->tx_head + 1U) % CUBEMX_CAN_TX_QUEUE_SIZE; - } + if ((current_tail - current_head) >= CUBEMX_CAN_TX_QUEUE_SIZE) { + LOGOMATIC("CubeMXCan_QueueTx: queue is full\n"); + return HAL_BUSY; // FIXME QUEUE IS FULL WHAT TO DO } + uint32_t insert_index = current_tail & TX_QUEUE_MASK; + handle->tx_queue[insert_index] = *message; + + atomic_store_explicit(&handle->tx_tail, current_tail + 1U, memory_order_release); + return HAL_OK; } diff --git a/Lib/Peripherals/CubeCAN/Src/can_it.c b/Lib/Peripherals/CubeCAN/Src/can_it.c index f44df2258..cfd576b67 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_it.c +++ b/Lib/Peripherals/CubeCAN/Src/can_it.c @@ -6,6 +6,9 @@ #include "CubeMXCanExt.h" #include "Logomatic.h" #include "Private/PrivateCubeMXCAN.h" +#include + +static_assert((CUBEMX_CAN_TX_QUEUE_SIZE > 0) && !(CUBEMX_CAN_TX_QUEUE_SIZE & (CUBEMX_CAN_TX_QUEUE_SIZE - 1)), "CUBEMX_CAN_TX_QUEUE_SIZE must be a power of 2"); void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index c0f247cef..abf20f17d 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -83,38 +83,75 @@ uint8_t CubeMXCan_Private_DlcToBytes(uint32_t dlc) return s_dlc_to_bytes[dlc]; } -HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(CubeMXCan_Handle *handle) +bool CubeMXCan_Private_IsDisabled(CubeMXCan_Handle *handle) { if (handle == NULL || handle->hfdcan == NULL) { - return HAL_ERROR; + return true; + } + + HAL_FDCAN_StateTypeDef state = HAL_FDCAN_GetState(handle->hfdcan); + if (state == HAL_FDCAN_STATE_ERROR || state == HAL_FDCAN_STATE_READY) { + return true; } - GRCAN_TxMessage message_copy; - bool message_found = false; + uint32_t error_status = HAL_FDCAN_GetErrorStatus(handle->hfdcan); + if ((error_status & FDCAN_PSR_BO) != 0U) { // BO = Bus-Off Flag + return true; + } + + return false; +} + +HAL_StatusTypeDef CubeMXCan_Private_RecoverPeripheral(CubeMXCan_Handle *handle) +{ + FDCAN_ProtocolStatusTypeDef protocol_status = {0}; + + if (HAL_FDCAN_GetProtocolStatus(handle->hfdcan, &protocol_status) == HAL_OK && protocol_status.BusOff) { + LOGOMATIC("CAN_send: bus off detected, attempting recovery\n"); - CRITICAL_SECTION - { - if (handle->tx_count > 0U) { - message_copy = handle->tx_queue[handle->tx_head]; - message_found = true; + if (HAL_FDCAN_Stop(handle->hfdcan) != HAL_OK) { + LOGOMATIC("CAN_send: failed to stop FDCAN peripheral during bus off recovery\n"); + return HAL_ERROR; + } + + HAL_FDCAN_AbortTxRequest(handle->hfdcan, FDCAN_TX_BUFFER0 | FDCAN_TX_BUFFER1 | FDCAN_TX_BUFFER2); + + if (HAL_FDCAN_Start(handle->hfdcan) != HAL_OK) { + LOGOMATIC("CAN_send: failed to restart FDCAN peripheral during bus off recovery\n"); + return HAL_ERROR; } } - if (!message_found) { - return HAL_ERROR; + if (HAL_FDCAN_IsRestrictedOperationMode(handle->hfdcan)) { + LOGOMATIC("CAN_send: currently in restricted operation mode\n"); + HAL_FDCAN_ExitRestrictedOperationMode(handle->hfdcan); } - if (HAL_FDCAN_AddMessageToTxFifoQ(handle->hfdcan, &message_copy.tx_header, message_copy.data) != HAL_OK) { + return HAL_OK; +} + +HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(CubeMXCan_Handle *handle) +{ + if (handle == NULL || handle->hfdcan == NULL) { + // Invalid parameter return HAL_ERROR; } - CRITICAL_SECTION - { - if (handle->tx_count > 0U) { - handle->tx_head = (handle->tx_head + 1U) % CUBEMX_CAN_TX_QUEUE_SIZE; - handle->tx_count--; - } + uint32_t current_head = atomic_load_explicit(&handle->tx_head, memory_order_relaxed); + uint32_t current_tail = atomic_load_explicit(&handle->tx_tail, memory_order_acquire); + + if (current_head == current_tail) { + // Queue empty + return HAL_OK; + } + + uint32_t current_index = current_head & TX_QUEUE_MASK; + GRCAN_TxMessage message_copy = handle->tx_queue[current_index]; + + if (HAL_FDCAN_AddMessageToTxFifoQ(handle->hfdcan, &message_copy.tx_header, message_copy.data) != HAL_OK) { + return HAL_ERROR; } + atomic_store_explicit(&handle->tx_head, (current_head + 1U), memory_order_release); return HAL_OK; } From 6809e38c4f2ae3ae114ecb10e726f77729b5bcf3 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Tue, 21 Jul 2026 02:54:53 -0700 Subject: [PATCH 027/125] Getting pretty close to a compiling build, needs timer integration work Signed-off-by: Daniel Hansen --- .../Application/Inc/CubeCAN_Config.h | 1 + CUBEMXTESTING/CMakeLists.txt | 2 +- CUBEMXTESTING/Core/Inc/main.h | 48 ++--- CUBEMXTESTING/Core/Src/main.c | 9 +- Lib/GlobalShare/Inc/CriticalSection.h | 4 +- Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h | 9 + Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h | 1 + .../CubeCAN/Inc/Private/PrivateCubeMXCAN.h | 65 ++++++- Lib/Peripherals/CubeCAN/Src/can_assert.c | 28 +++ Lib/Peripherals/CubeCAN/Src/can_global.c | 12 ++ Lib/Peripherals/CubeCAN/Src/can_init.c | 184 +++++------------- Lib/Peripherals/CubeCAN/Src/can_it.c | 72 ------- Lib/Peripherals/CubeCAN/Src/can_rx.c | 44 +++++ Lib/Peripherals/CubeCAN/Src/can_tx.c | 80 ++++++++ Lib/Peripherals/CubeCAN/Src/can_utils.c | 113 ++++------- Lib/Peripherals/CubeCAN/cubemx_can.cmake | 7 +- Lib/Utils/Logomatic/Inc/Logomatic.h | 16 +- 17 files changed, 363 insertions(+), 332 deletions(-) create mode 100644 Lib/Peripherals/CubeCAN/Src/can_assert.c create mode 100644 Lib/Peripherals/CubeCAN/Src/can_global.c delete mode 100644 Lib/Peripherals/CubeCAN/Src/can_it.c create mode 100644 Lib/Peripherals/CubeCAN/Src/can_rx.c create mode 100644 Lib/Peripherals/CubeCAN/Src/can_tx.c diff --git a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h index 3df036604..7ff7a2a33 100644 --- a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h +++ b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h @@ -11,5 +11,6 @@ #define CUBEMX_CAN_TIMER_INSTANCE TIM5 #define CUBEMX_CAN_TX_QUEUE_SIZE 32U #define CAN_TIMER_SEND_PERIOD_US 500U +#define CAN_TIMER_HANDLE TIM5 #endif diff --git a/CUBEMXTESTING/CMakeLists.txt b/CUBEMXTESTING/CMakeLists.txt index bfd25f877..c8fcc8050 100644 --- a/CUBEMXTESTING/CMakeLists.txt +++ b/CUBEMXTESTING/CMakeLists.txt @@ -33,7 +33,7 @@ target_sources( Core/Src/stm32g4xx_it.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE VCP_LIB CUBEMX_CAN_LIB) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE VCP_LIB CUBEMX_CAN_LIB LOGOMATIC_LIB) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index c050c5e89..2ca19b1c6 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -1,21 +1,21 @@ /* 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) 2026 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file : main.h + * @brief : Header for main.c file. + * This file contains the common defines of the application. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 -------------------------------------*/ @@ -28,22 +28,22 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" - -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_system.h" -#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_utils.h" -#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_crs.h" #include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_gpio.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_rcc.h" +#include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_utils.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ -#include "stm32g4xx_ll_usart.h" #include "stm32g4xx_ll_lpuart.h" +#include "stm32g4xx_ll_rcc.h" +#include "stm32g4xx_ll_usart.h" /* USER CODE END Includes */ /* Exported types ------------------------------------------------------------*/ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index e189561ec..7dc29b231 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -28,9 +28,9 @@ #include "loop.h" #include "vcp.h" -#include "can.h" -#include "can_cfg.h" -#include "gr_can_init.h" +// #include "can.h" +// #include "can_cfg.h" +// #include "gr_can_init.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -233,8 +233,7 @@ void Error_Handler(void) void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line number, - ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + printf("Assert failed! File %s on line %d\n", file, line); /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/Lib/GlobalShare/Inc/CriticalSection.h b/Lib/GlobalShare/Inc/CriticalSection.h index c792731dc..d83cdc242 100644 --- a/Lib/GlobalShare/Inc/CriticalSection.h +++ b/Lib/GlobalShare/Inc/CriticalSection.h @@ -1,6 +1,7 @@ #include #include "Stringification.h" +#include "main.h" #ifndef CRITICAL_SECTION_H #define CRITICAL_SECTION_H @@ -64,7 +65,8 @@ static inline void _magic_auto_critical_exit(uint32_t *state_var) * disable interrupts for a short period of time. */ #define CRITICAL_SECTION \ - for (__attribute__((cleanup(_magic_auto_critical_exit))) uint32_t CONCAT(_magic_auto_critical_state_, __LINE__) = __get_PRIMASK(), CONCAT(_magic_auto_critical_run_, __LINE__) = (__disable_irq(), 1); \ + for (__attribute__((cleanup(_magic_auto_critical_exit))) uint32_t CONCAT(_magic_auto_critical_state_, __LINE__) = __get_PRIMASK(), \ + CONCAT(_magic_auto_critical_run_, __LINE__) = (__disable_irq(), 1); \ CONCAT(_magic_auto_critical_run_, __LINE__); CONCAT(_magic_auto_critical_run_, __LINE__) = 0) #endif diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h index 8a258cc72..89db887a7 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h @@ -1,3 +1,4 @@ +#include #include #include @@ -101,4 +102,12 @@ HAL_StatusTypeDef CubeMXCan_AddFilter(CubeMXCan_Handle *handle, const FDCAN_Filt */ HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *handle, const GRCAN_TxMessage *message); +/** + * @brief Converts a Data Length Code (DLC) to the corresponding number of data bytes. + * @param dlc The Data Length Code to be converted. + * @return The number of data bytes corresponding to the given DLC. + * @warning The DLC value must be between 0 and 15, inclusive. Values outside this range will result in undefined behavior. + */ +bool CubeMXCan_Private_IsDisabled(CubeMXCan_Handle *handle); + #endif diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h b/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h index 64eff376a..3cc2ad110 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h @@ -1,3 +1,4 @@ +#include #include #include "GRCAN_MSG_ID.h" diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h index 7816f8086..127a8c910 100644 --- a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h +++ b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h @@ -1,8 +1,8 @@ -#include #include #include #include +#include "CubeCAN_Config.h" #include "CubeMXCan.h" #include "Logomatic.h" #include "Stringification.h" @@ -11,17 +11,37 @@ #ifndef PRIVATE_CUBE_MX_CAN_H #define PRIVATE_CUBE_MX_CAN_H +/** + * @brief Macro to convert a CubeMX CAN instance pointer to its corresponding index. + * + * Works on all supported boards, but new boards should be verified against this operation + * + * @param inst Pointer to the CubeMX CAN instance (FDCAN1, FDCAN2, or FDCAN3). + * @return The index corresponding to the given CubeMX CAN instance (0 for FDCAN1, 1 for FDCAN2, and 2 for FDCAN3). + * @warning This macro assumes that the CubeMX CAN instances are contiguous in memory and that FDCAN1 is the first instance. It may not work correctly if the instances are not contiguous or if FDCAN1 + * is not the first instance. + */ +#define CUBEMX_CAN_INSTANCE_TO_INDEX(inst) ((uint32_t)((uintptr_t)(inst) - FDCAN1_BASE) >> 10) + +/** + * @brief Mask for the transmission queue index, used to wrap around the queue when it reaches its maximum size. + * + * Application code should not use this macro directly. It is intended for internal use only + * + * @warning The transmission queue size must be a power of two for this mask to work correctly + * @warning The transmission queue size must be defined as CUBEMX_CAN_TX_QUEUE_SIZE in the CubeMX CAN configuration header file + */ #define TX_QUEUE_MASK (CUBEMX_CAN_TX_QUEUE_SIZE - 1U) /** * @brief CubeMX CAN handle structure * - * This structure is used to represent a CubeMX CAN handle, which consists of a pointer to the FDCAN handle, a configuration structure, a transmission queue, and other relevant parameters.\ + * This structure is used to represent a CubeMX CAN handle, which consists of a pointer to the FDCAN handle, a configuration structure, a transmission queue, and other relevant parameters. * * @warning Use the provided API functions to interact with the CubeMX CAN handle. * @warning The structure is intended for internal use only and should not be accessed directly by user code. */ -typedef struct CubeMXCan_Handle { +struct CubeMXCan_Handle { /// @brief Pointer to the FDCAN handle associated with this CubeMX CAN handle. FDCAN_HandleTypeDef *hfdcan; /// @brief Configuration structure for the CubeMX CAN handle, containing the receive callback and user context. @@ -34,7 +54,7 @@ typedef struct CubeMXCan_Handle { _Atomic uint32_t tx_tail; /// @brief Flag indicating whether the CubeMX CAN handle has been started. bool started; -} CubeMXCan_Handle; +}; /// @brief Maximum number of CubeMX CAN instances supported by the library. #define CUBEMX_CAN_MAX_INSTANCES 3U @@ -91,4 +111,41 @@ void CubeMXCan_Tick(void); */ void CubeMXCan_OnRxFifo0(FDCAN_HandleTypeDef *hfdcan); +/** + * @brief Structure representing a registry entry for the CubeMX CAN library, used to associate a CubeMX CAN handle with its corresponding FDCAN handle. + */ +struct CubeMXCan_RegistryEntry { + /// @brief Pointer to the FDCAN instance associated with this registry entry. + FDCAN_GlobalTypeDef *instance; + /// @brief Pointer to the CubeMX CAN handle associated with this registry entry. + CubeMXCan_Handle *handle; +}; + +/** + * @brief Registry entry structure for the CubeMX CAN library, used to associate a CubeMX CAN handle with its corresponding FDCAN handle. + * @note The number of entries in the registry is defined by CUBEMX_CAN_MAX_INSTANCES. + */ +extern struct CubeMXCan_RegistryEntry registry[CUBEMX_CAN_MAX_INSTANCES]; + +/** + * @brief Array of CubeMX CAN handles, one for each supported instance. + * @note The number of instances is defined by CUBEMX_CAN_MAX_INSTANCES. + */ +extern struct CubeMXCan_Handle handles[CUBEMX_CAN_MAX_INSTANCES]; + +/** + * @brief Flag indicating whether the CubeMX CAN Tx timer has been started. + */ +extern bool s_timer_started; + +/** + * @brief Attempts to recover the FDCAN peripheral associated with the given CubeMX CAN handle. + * + * Handles recovery from bus off or restricted operation mode by reinitializing the FDCAN peripheral and restoring its configuration. + * + * @param handle Pointer to the CubeMX CAN handle associated with the FDCAN peripheral to be recovered. + * @return HAL_StatusTypeDef indicating the success or failure of the recovery operation. + */ +HAL_StatusTypeDef CubeMXCan_Private_RecoverPeripheral(CubeMXCan_Handle *handle); + #endif diff --git a/Lib/Peripherals/CubeCAN/Src/can_assert.c b/Lib/Peripherals/CubeCAN/Src/can_assert.c new file mode 100644 index 000000000..93df889de --- /dev/null +++ b/Lib/Peripherals/CubeCAN/Src/can_assert.c @@ -0,0 +1,28 @@ +#include +#include + +#include "CriticalSection.h" +#include "CubeCAN_Config.h" +#include "CubeMXCan.h" +#include "CubeMXCanExt.h" +#include "Private/PrivateCubeMXCAN.h" +#include "main.h" + +#pragma region Platform Assertions + +static_assert(sizeof(((CubeMXCan_Handle *)0)->tx_head) == sizeof(uint32_t), "tx_head must be 32 bits"); + +static_assert(sizeof(GRCAN_TxMessage) == (sizeof(FDCAN_TxHeaderTypeDef) + 64), "GRCAN_TxMessage size is incorrect"); + +static_assert(_Alignof(GRCAN_TxMessage) >= 4, "GRCAN_TxMessage must have at least 4-byte alignment"); + +static_assert(ATOMIC_INT_LOCK_FREE == 2, "ATOMIC_INT_LOCK_FREE must be enabled for atomic operations on tx_head and tx_tail"); + +#pragma endregion +#pragma region Configuration Validations + +static_assert((CUBEMX_CAN_TX_QUEUE_SIZE > 0) && !(CUBEMX_CAN_TX_QUEUE_SIZE & (CUBEMX_CAN_TX_QUEUE_SIZE - 1)), "CUBEMX_CAN_TX_QUEUE_SIZE must be a power of two and greater than zero"); + +static_assert(CUBEMX_CAN_MAX_INSTANCES >= 1 && CUBEMX_CAN_MAX_INSTANCES <= 3, "CUBEMX_CAN_MAX_INSTANCES must be configured between 1 and 3 inclusive"); + +#pragma endregion diff --git a/Lib/Peripherals/CubeCAN/Src/can_global.c b/Lib/Peripherals/CubeCAN/Src/can_global.c new file mode 100644 index 000000000..aa7613e89 --- /dev/null +++ b/Lib/Peripherals/CubeCAN/Src/can_global.c @@ -0,0 +1,12 @@ +#include +#include +#include + +#include "CriticalSection.h" +#include "CubeMXCan.h" +#include "CubeMXCanExt.h" +#include "Private/PrivateCubeMXCAN.h" + +struct CubeMXCan_RegistryEntry registry[CUBEMX_CAN_MAX_INSTANCES] = {0}; +struct CubeMXCan_Handle handles[CUBEMX_CAN_MAX_INSTANCES] = {0}; +bool timer_started = false; diff --git a/Lib/Peripherals/CubeCAN/Src/can_init.c b/Lib/Peripherals/CubeCAN/Src/can_init.c index 35fc89899..627d37eea 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_init.c +++ b/Lib/Peripherals/CubeCAN/Src/can_init.c @@ -1,97 +1,88 @@ +#include #include +#include #include +#include "CriticalSection.h" #include "CubeMXCan.h" #include "CubeMXCanExt.h" #include "Logomatic.h" #include "Private/PrivateCubeMXCAN.h" +#include "main.h" -typedef struct { - FDCAN_GlobalTypeDef *instance; - CubeMXCan_Handle *handle; -} CubeMXCan_RegistryEntry; - -static CubeMXCan_RegistryEntry s_registry[CUBEMX_CAN_MAX_INSTANCES] = {0}; -static CubeMXCan_Handle s_handles[CUBEMX_CAN_MAX_INSTANCES] = {0}; -static bool s_timer_started = false; - -static CubeMXCan_RegistryEntry *CubeMXCan_FindRegistryEntry(FDCAN_GlobalTypeDef *instance) +CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, const CubeCAN_Config *config) { - for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { - if (s_registry[i].instance == instance) { - return &s_registry[i]; - } + if (hfdcan == NULL || config == NULL) { + LOGOMATIC("CubeMXCan_Init: invalid null parameters\n"); + return NULL; } - return NULL; -} - -static CubeMXCan_RegistryEntry *CubeMXCan_AllocRegistryEntry(FDCAN_GlobalTypeDef *instance) -{ - CubeMXCan_RegistryEntry *entry = CubeMXCan_FindRegistryEntry(instance); - if (entry != NULL) { - return entry; - } + CubeMXCan_Handle *handle = NULL; + CRITICAL_SECTION + { + for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { + if (handles[i].hfdcan == hfdcan || handles[i].hfdcan == NULL) { + handle = &handles[i]; + break; + } + } - for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { - if (s_registry[i].instance == NULL) { - s_registry[i].instance = instance; - return &s_registry[i]; + if (handle != NULL) { + memset(handle, 0, sizeof(*handle)); + handle->hfdcan = hfdcan; + handle->config = *config; + atomic_init(&handle->tx_head, 0U); + atomic_init(&handle->tx_tail, 0U); + handle->started = false; } } - return NULL; -} + if (handle == NULL) { + LOGOMATIC("CubeMXCan_Init: no free handle slots\n"); + return NULL; + } -CubeMXCan_Handle *CubeMXCan_Private_GetHandle(FDCAN_HandleTypeDef *hfdcan) -{ - if (hfdcan == NULL) { + uint32_t rx_events = FDCAN_IT_RX_FIFO0_NEW_MESSAGE | FDCAN_IT_RX_FIFO0_FULL | FDCAN_IT_RX_FIFO0_MESSAGE_LOST; + if (HAL_FDCAN_ActivateNotification(hfdcan, rx_events, 0U) != HAL_OK) { + LOGOMATIC("CubeMXCan_Init: failed to activate RX notifications\n"); + memset(handle, 0, sizeof(*handle)); return NULL; } - CubeMXCan_RegistryEntry *entry = CubeMXCan_FindRegistryEntry(hfdcan->Instance); - return (entry != NULL) ? entry->handle : NULL; + return handle; } -HAL_StatusTypeDef CubeMXCan_Private_RegisterHandle(FDCAN_HandleTypeDef *hfdcan, CubeMXCan_Handle *handle) +HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *handle) { - if (hfdcan == NULL || handle == NULL) { - return HAL_ERROR; - } - - CubeMXCan_RegistryEntry *entry = CubeMXCan_AllocRegistryEntry(hfdcan->Instance); - if (entry == NULL) { + if (handle == NULL || handle->hfdcan == NULL) { return HAL_ERROR; } - entry->handle = handle; - return HAL_OK; -} + (void)CubeMXCan_Stop(handle); -void CubeMXCan_Private_UnregisterHandle(FDCAN_HandleTypeDef *hfdcan) -{ - if (hfdcan == NULL) { - return; + CRITICAL_SECTION + { + memset(handle, 0, sizeof(*handle)); } - CubeMXCan_RegistryEntry *entry = CubeMXCan_FindRegistryEntry(hfdcan->Instance); - if (entry != NULL) { - entry->instance = NULL; - entry->handle = NULL; - } + return HAL_OK; } void CubeMXCan_Tick(void) { for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { - CubeMXCan_Handle *handle = s_registry[i].handle; - if (handle == NULL || handle->hfdcan == NULL || !handle->started) { - continue; + CubeMXCan_Handle *handle = registry[i].handle; + + CRITICAL_SECTION + { + if (handle == NULL || handle->hfdcan == NULL || !handle->started) { + continue; + } } if (CubeMXCan_Private_IsDisabled(handle)) { LOGOMATIC("CAN_send: currently in restricted operation mode\n"); - if (CubeMXCan_Private_RecoverPeripheral(handle->hfdcan) != HAL_OK) { + if (CubeMXCan_Private_RecoverPeripheral(handle) != HAL_OK) { LOGOMATIC("CAN_send %d: failed to recover peripheral\n", (int)i); continue; } @@ -101,66 +92,6 @@ void CubeMXCan_Tick(void) } } -CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, const CubeCAN_Config *config) -{ - if (hfdcan == NULL || config == NULL) { - return NULL; - } - - CubeMXCan_Handle *handle = NULL; - bool register_ok = false; - - CRITICAL_SECTION - { - handle = CubeMXCan_Private_GetHandle(hfdcan); - if (handle == NULL) { - for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { - if (s_handles[i].hfdcan == NULL) { - handle = &s_handles[i]; - memset(handle, 0, sizeof(*handle)); - handle->hfdcan = hfdcan; - break; - } - } - } - - if (handle != NULL) { - handle->config = *config; - atomic_init (&handle->tx_head, 0U); - atomic_init (&handle->tx_tail, 0U); - handle->started = false; - - if (CubeMXCan_Private_RegisterHandle(hfdcan, handle) == HAL_OK) { - register_ok = true; - } else { - memset(handle, 0, sizeof(*handle)); - handle = NULL; - } - } - } - - if (handle == NULL) { - LOGOMATIC("CubeMXCan_Init: no free handle slots\n"); - return NULL; - } - - if (!register_ok) { - LOGOMATIC("CubeMXCan_Init: failed to register handle\n"); - return NULL; - } - - uint32_t rx_events = FDCAN_IT_RX_FIFO0_NEW_MESSAGE | FDCAN_IT_RX_FIFO0_FULL | FDCAN_IT_RX_FIFO0_MESSAGE_LOST; - if (HAL_FDCAN_ActivateNotification(hfdcan, rx_events, 0U) != HAL_OK) { - LOGOMATIC("CubeMXCan_Init: failed to activate RX notifications\n"); - return NULL; - } - - if (!s_timer_started) { - s_timer_started = true; - } - return handle; -} - HAL_StatusTypeDef CubeMXCan_Start(CubeMXCan_Handle *handle) { if (handle == NULL || handle->hfdcan == NULL) { @@ -197,23 +128,6 @@ HAL_StatusTypeDef CubeMXCan_Stop(CubeMXCan_Handle *handle) return HAL_OK; } -HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *handle) -{ - if (handle == NULL || handle->hfdcan == NULL) { - return HAL_ERROR; - } - - (void)CubeMXCan_Stop(handle); - - CRITICAL_SECTION - { - CubeMXCan_Private_UnregisterHandle(handle->hfdcan); - memset(handle, 0, sizeof(*handle)); - } - - return HAL_OK; -} - HAL_StatusTypeDef CubeMXCan_AddFilter(CubeMXCan_Handle *handle, const FDCAN_FilterTypeDef *filter) { if (handle == NULL || handle->hfdcan == NULL || filter == NULL) { @@ -234,7 +148,7 @@ HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *handle, const GRCAN_TxMess if ((current_tail - current_head) >= CUBEMX_CAN_TX_QUEUE_SIZE) { LOGOMATIC("CubeMXCan_QueueTx: queue is full\n"); - return HAL_BUSY; // FIXME QUEUE IS FULL WHAT TO DO + return HAL_TIMEOUT; } uint32_t insert_index = current_tail & TX_QUEUE_MASK; diff --git a/Lib/Peripherals/CubeCAN/Src/can_it.c b/Lib/Peripherals/CubeCAN/Src/can_it.c deleted file mode 100644 index cfd576b67..000000000 --- a/Lib/Peripherals/CubeCAN/Src/can_it.c +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include - -#include "CubeCAN_Config.h" -#include "CubeMXCan.h" -#include "CubeMXCanExt.h" -#include "Logomatic.h" -#include "Private/PrivateCubeMXCAN.h" -#include - -static_assert((CUBEMX_CAN_TX_QUEUE_SIZE > 0) && !(CUBEMX_CAN_TX_QUEUE_SIZE & (CUBEMX_CAN_TX_QUEUE_SIZE - 1)), "CUBEMX_CAN_TX_QUEUE_SIZE must be a power of 2"); - -void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) -{ - if (htim != NULL && htim->Instance == CUBEMX_CAN_TIMER_INSTANCE) { - CubeMXCan_Tick(); - } -} - -void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) -{ - (void)RxFifo0ITs; - CubeMXCan_OnRxFifo0(hfdcan); -} - -void HAL_FDCAN_TxBufferCompleteCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndexes) -{ - (void)hfdcan; - (void)BufferIndexes; -} - -void CubeMXCan_Private_DispatchRx(FDCAN_HandleTypeDef *hfdcan) -{ - CubeMXCan_OnRxFifo0(hfdcan); -} - -void CubeMXCan_OnRxFifo0(FDCAN_HandleTypeDef *hfdcan) -{ - if (hfdcan == NULL) { - return; - } - - CubeCAN_RxCallback rx_callback_stack = NULL; - void *user_ctx_stack = NULL; - - CRITICAL_SECTION { - CubeMXCan_Handle *handle = CubeMXCan_Private_GetHandle(hfdcan); - if (handle != NULL && handle->config.rx_callback != NULL) { - rx_callback_stack = handle->config.rx_callback; - user_ctx_stack = handle->config.user_ctx; - } - } - - if (rx_callback_stack == NULL) { - FDCAN_RxHeaderTypeDef rx_header = {0}; - uint8_t rx_data[FDCAN_MAX_DATA_BYTES] = {0}; - (void)HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &rx_header, rx_data); - LOGOMATIC("CubeMXCan_OnRxFifo0: no handle or callback registered for %s\n", CAN_GetInstanceName(hfdcan->Instance)); - return; - } - - FDCAN_RxHeaderTypeDef rx_header = {0}; - uint8_t rx_data[FDCAN_MAX_DATA_BYTES] = {0}; - if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &rx_header, rx_data) != HAL_OK) { - LOGOMATIC("CubeMXCan_OnRxFifo0: failed to get RX message\n"); - return; - } - - CAN_Identifier identifier = Deconstruct_CAN_Identifier(rx_header.Identifier); - uint8_t size = CubeMXCan_Private_DlcToBytes(rx_header.DataLength); - rx_callback_stack(user_ctx_stack, &identifier, rx_data, size); -} diff --git a/Lib/Peripherals/CubeCAN/Src/can_rx.c b/Lib/Peripherals/CubeCAN/Src/can_rx.c new file mode 100644 index 000000000..e21f05d9d --- /dev/null +++ b/Lib/Peripherals/CubeCAN/Src/can_rx.c @@ -0,0 +1,44 @@ +#include +#include + +#include "CriticalSection.h" +#include "CubeMXCan.h" +#include "CubeMXCanExt.h" +#include "Logomatic.h" +#include "Private/PrivateCubeMXCAN.h" +#include "Unused.h" +#include "main.h" + +void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) +{ + UNUSED(RxFifo0ITs); + + if (hfdcan == NULL) { + return; + } + + CubeMXCan_Handle *handle = NULL; + for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { + if (s_handles[i].hfdcan == hfdcan) { + handle = &s_handles[i]; + break; + } + } + + if (handle == NULL || handle->config.rx_callback == NULL) { + FDCAN_RxHeaderTypeDef rx_header; + uint8_t rx_data[FDCAN_MAX_DATA_BYTES]; + (void)HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &rx_header, rx_data); + LOGOMATIC("Rx Callback missing for instance\n"); + return; + } + + FDCAN_RxHeaderTypeDef rx_header; + uint8_t rx_data[FDCAN_MAX_DATA_BYTES]; + + if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &rx_header, rx_data) == HAL_OK) { + CAN_Identifier id = Deconstruct_CAN_Identifier(rx_header.Identifier); + uint8_t size = CubeMXCan_Private_DlcToBytes(rx_header.DataLength); + handle->config.rx_callback(handle->config.user_ctx, &id, rx_data, size); + } +} diff --git a/Lib/Peripherals/CubeCAN/Src/can_tx.c b/Lib/Peripherals/CubeCAN/Src/can_tx.c new file mode 100644 index 000000000..3bb804ea8 --- /dev/null +++ b/Lib/Peripherals/CubeCAN/Src/can_tx.c @@ -0,0 +1,80 @@ +#include +#include + +#include "CriticalSection.h" +#include "CubeMXCan.h" +#include "CubeMXCanExt.h" +#include "Logomatic.h" +#include "Private/PrivateCubeMXCAN.h" +#include "main.h" + +void CubeMXCan_Tick(void) +{ + for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { + CubeMXCan_Handle *handle = &handles[i]; + + if (handle->hfdcan == NULL || !handle->started) { + continue; + } + + if (CubeMXCan_Private_IsDisabled(handle)) { + LOGOMATIC("CAN_send: currently in restricted operation mode\n"); + if (CubeMXCan_Private_RecoverPeripheral(handle) != HAL_OK) { + LOGOMATIC("CAN_send %d: failed to recover peripheral\n", (int)i); + continue; + } + } + + (void)CubeMXCan_Private_SendQueuedMessage(handle); + } +} + +HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *handle, const GRCAN_TxMessage *message) +{ + if (handle == NULL || message == NULL) { + return HAL_ERROR; + } + + uint32_t current_tail = atomic_load_explicit(&handle->tx_tail, memory_order_relaxed); + uint32_t current_head = atomic_load_explicit(&handle->tx_head, memory_order_acquire); + + if ((current_tail - current_head) >= CUBEMX_CAN_TX_QUEUE_SIZE) { + LOGOMATIC("CubeMXCan_QueueTx: queue is full\n"); + return HAL_TIMEOUT; + } + + handle->tx_queue[current_tail & TX_QUEUE_MASK] = *message; + atomic_store_explicit(&handle->tx_tail, current_tail + 1U, memory_order_release); + return HAL_OK; +} + +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) +{ + if (htim != NULL && htim->Instance == CUBEMX_CAN_TIMER_INSTANCE) { + CubeMXCan_Tick(); + } +} + +HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(CubeMXCan_Handle *handle) +{ + if (handle == NULL || handle->hfdcan == NULL) { + LOGOMATIC("CubeMXCan_Private_SendQueuedMessage: invalid null parameter\n"); + return HAL_ERROR; + } + + uint32_t current_head = atomic_load_explicit(&handle->tx_head, memory_order_relaxed); + uint32_t current_tail = atomic_load_explicit(&handle->tx_tail, memory_order_acquire); + + if (current_head == current_tail) { + return HAL_OK; + } + + GRCAN_TxMessage message_copy = handle->tx_queue[current_head & TX_QUEUE_MASK]; + + if (HAL_FDCAN_AddMessageToTxFifoQ(handle->hfdcan, &message_copy.tx_header, message_copy.data) != HAL_OK) { + return HAL_ERROR; + } + + atomic_store_explicit(&handle->tx_head, (current_head + 1U), memory_order_release); + return HAL_OK; +} diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index abf20f17d..c60010bdd 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -1,5 +1,8 @@ +#include +#include #include +#include "CriticalSection.h" #include "CubeMXCan.h" #include "CubeMXCanExt.h" #include "GRCAN_MSG_ID.h" @@ -7,55 +10,28 @@ #include "Logomatic.h" #include "Private/PrivateCubeMXCAN.h" -static const uint8_t s_dlc_to_bytes[] = {0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 12U, 16U, 20U, 24U, 32U, 48U, 64U}; - -const char *CAN_GetInstanceName(FDCAN_GlobalTypeDef *instance) -{ - if (instance == NULL) { - return "NULL"; - } -#ifdef USECAN1 - if (instance == FDCAN1) { - return "FDCAN1"; - } -#endif -#ifdef USECAN2 - if (instance == FDCAN2) { - return "FDCAN2"; - } -#endif -#ifdef USECAN3 - if (instance == FDCAN3) { - return "FDCAN3"; - } -#endif - LOGOMATIC("Get CAN instance name: unknown instance\n"); - return "UNKNOWN"; -} - uint32_t Construct_CAN_Identifier(const CAN_Identifier *identifier) { if (identifier == NULL) { return 0U; } - uint32_t message_id = 0U; - message_id |= ((uint32_t)(identifier->tx_node_id & 0xFFU) << 20U); - message_id |= ((uint32_t)(identifier->msg_id & 0xFFFU) << 8U); - message_id |= (uint32_t)(identifier->rx_node_id & 0xFFU); - - return message_id; + return // Transmitting node + ((uint32_t)(identifier->tx_node_id & 0xFFU) << 20U) + // Message ID + | ((uint32_t)(identifier->msg_id & 0xFFFU) << 8U) + // Receiving node + | (uint32_t)(identifier->rx_node_id & 0xFFU); } CAN_Identifier Deconstruct_CAN_Identifier(uint32_t message_id) { - CAN_Identifier identifier = {0}; - - identifier.tx_node_id = (GRCAN_NODE_ID)((message_id >> 20U) & 0xFFU); - identifier.msg_id = (GRCAN_MSG_ID)((message_id >> 8U) & 0xFFFU); - identifier.rx_node_id = (GRCAN_NODE_ID)(message_id & 0xFFU); - - return identifier; + return (CAN_Identifier){// Transmitting node + .tx_node_id = (GRCAN_NODE_ID)((message_id >> 20U) & 0xFFU), + // Message ID + .msg_id = (GRCAN_MSG_ID)((message_id >> 8U) & 0xFFFU), + // Receiving node + .rx_node_id = (GRCAN_NODE_ID)(message_id & 0xFFU)}; } HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *identifier, uint32_t filter_index, uint32_t fifo, FDCAN_FilterTypeDef *filter) @@ -74,13 +50,23 @@ HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *identifie return HAL_OK; } -uint8_t CubeMXCan_Private_DlcToBytes(uint32_t dlc) +HAL_StatusTypeDef CubeMXCan_AddFilter(CubeMXCan_Handle *handle, const FDCAN_FilterTypeDef *filter) { - if (dlc > 15U) { - return 64U; + if (handle == NULL || handle->hfdcan == NULL || filter == NULL) { + LOGOMATIC("CubeMXCan_AddFilter: Invalid null parameter\n"); + return HAL_ERROR; } - return s_dlc_to_bytes[dlc]; + return HAL_FDCAN_ConfigFilter(handle->hfdcan, (FDCAN_FilterTypeDef *)filter); +} + +uint8_t CubeMXCan_Private_DlcToBytes(uint32_t dlc) +{ + static const uint8_t dlc_to_bytes[] = {0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 12U, 16U, 20U, 24U, 32U, 48U, 64U}; + + static_assert((sizeof(dlc_to_bytes) / sizeof(dlc_to_bytes[0])) == 16, "dlc_to_bytes array must have 16 elements"); + + return (dlc > 15U) ? 64U : dlc_to_bytes[dlc]; } bool CubeMXCan_Private_IsDisabled(CubeMXCan_Handle *handle) @@ -90,16 +76,13 @@ bool CubeMXCan_Private_IsDisabled(CubeMXCan_Handle *handle) } HAL_FDCAN_StateTypeDef state = HAL_FDCAN_GetState(handle->hfdcan); - if (state == HAL_FDCAN_STATE_ERROR || state == HAL_FDCAN_STATE_READY) { - return true; - } - - uint32_t error_status = HAL_FDCAN_GetErrorStatus(handle->hfdcan); - if ((error_status & FDCAN_PSR_BO) != 0U) { // BO = Bus-Off Flag - return true; - } + FDCAN_ProtocolStatusTypeDef protocol_status = {0}; - return false; + return // HAL states + state == HAL_FDCAN_STATE_ERROR || + state == HAL_FDCAN_STATE_READY + // Check for bus off condition + || (HAL_FDCAN_GetProtocolStatus(handle->hfdcan, &protocol_status) == HAL_OK && protocol_status.BusOff); } HAL_StatusTypeDef CubeMXCan_Private_RecoverPeripheral(CubeMXCan_Handle *handle) @@ -129,29 +112,3 @@ HAL_StatusTypeDef CubeMXCan_Private_RecoverPeripheral(CubeMXCan_Handle *handle) return HAL_OK; } - -HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(CubeMXCan_Handle *handle) -{ - if (handle == NULL || handle->hfdcan == NULL) { - // Invalid parameter - return HAL_ERROR; - } - - uint32_t current_head = atomic_load_explicit(&handle->tx_head, memory_order_relaxed); - uint32_t current_tail = atomic_load_explicit(&handle->tx_tail, memory_order_acquire); - - if (current_head == current_tail) { - // Queue empty - return HAL_OK; - } - - uint32_t current_index = current_head & TX_QUEUE_MASK; - GRCAN_TxMessage message_copy = handle->tx_queue[current_index]; - - if (HAL_FDCAN_AddMessageToTxFifoQ(handle->hfdcan, &message_copy.tx_header, message_copy.data) != HAL_OK) { - return HAL_ERROR; - } - - atomic_store_explicit(&handle->tx_head, (current_head + 1U), memory_order_release); - return HAL_OK; -} diff --git a/Lib/Peripherals/CubeCAN/cubemx_can.cmake b/Lib/Peripherals/CubeCAN/cubemx_can.cmake index 23a051caa..7f0492132 100644 --- a/Lib/Peripherals/CubeCAN/cubemx_can.cmake +++ b/Lib/Peripherals/CubeCAN/cubemx_can.cmake @@ -9,9 +9,12 @@ target_include_directories( target_sources( CUBEMX_CAN_LIB INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/Src/can_it.c - ${CMAKE_CURRENT_LIST_DIR}/Src/can_utils.c + ${CMAKE_CURRENT_LIST_DIR}/Src/can_assert.c + ${CMAKE_CURRENT_LIST_DIR}/Src/can_global.c ${CMAKE_CURRENT_LIST_DIR}/Src/can_init.c + ${CMAKE_CURRENT_LIST_DIR}/Src/can_rx.c + ${CMAKE_CURRENT_LIST_DIR}/Src/can_tx.c + ${CMAKE_CURRENT_LIST_DIR}/Src/can_utils.c ) target_link_libraries( diff --git a/Lib/Utils/Logomatic/Inc/Logomatic.h b/Lib/Utils/Logomatic/Inc/Logomatic.h index d291f296a..21734ba64 100644 --- a/Lib/Utils/Logomatic/Inc/Logomatic.h +++ b/Lib/Utils/Logomatic/Inc/Logomatic.h @@ -3,8 +3,8 @@ #include "main.h" -#ifndef _LOGOMATIC_H_ -#define _LOGOMATIC_H_ +#ifndef LOGOMATIC_H +#define LOGOMATIC_H #if defined(ITM) && defined(LL_GPIO_MODE_ALTERNATE) typedef enum { @@ -113,10 +113,8 @@ void Setup_Logomatic(LogomaticConfig *config); */ #define LOGOMATIC(...) \ do { \ - _Pragma("GCC diagnostic push"); \ - _Pragma("GCC diagnostic ignored \"-Wdouble-promotion\""); \ - printf(__VA_ARGS__); \ - _Pragma("GCC diagnostic pop"); \ + _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdouble-promotion\"") printf(__VA_ARGS__); \ + _Pragma("GCC diagnostic pop") \ } while (0) #else @@ -129,10 +127,8 @@ void Setup_Logomatic(LogomaticConfig *config); #define LOGOMATIC(...) \ do { \ if (0) { \ - _Pragma("GCC diagnostic push"); \ - _Pragma("GCC diagnostic ignored \"-Wdouble-promotion\""); \ - printf(__VA_ARGS__); \ - _Pragma("GCC diagnostic pop"); \ + _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdouble-promotion\"") printf(__VA_ARGS__); \ + _Pragma("GCC diagnostic pop") \ } \ } while (0) #endif From 4841ca3bdda0ec7e15fe4f4da5e5439128bac14b Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Wed, 22 Jul 2026 23:48:08 -0700 Subject: [PATCH 028/125] Further improvements to internal setup Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Core/Src/main.c | 165 +++++++++--------- .../CubeCAN/Inc/Private/PrivateCubeMXCAN.h | 22 ++- Lib/Peripherals/CubeCAN/Src/can_rx.c | 4 +- Lib/Peripherals/CubeCAN/Src/can_utils.c | 22 +++ Lib/Peripherals/CubeCAN/cubemx_can.cmake | 1 + 5 files changed, 114 insertions(+), 100 deletions(-) diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 7dc29b231..ae2deaf7b 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,9 +18,10 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" + #include "fdcan.h" -#include "tim.h" #include "gpio.h" +#include "tim.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -91,39 +92,39 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + /* USER CODE BEGIN 2 */ Logomatic_Init(&logomaticConfig); VCP_Init(&vcp_config); @@ -132,66 +133,58 @@ int main(void) if (CAN_Timer_Start() != HAL_OK) { Error_Handler(); } - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ LOGOMATIC("Hello World!\n"); while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) - { - } - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while(LL_RCC_HSI_IsReady() != 1) - { - } - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while(LL_RCC_PLL_IsReady() != 1) - { - } - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) - { - } - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i !=0; i--); - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) - { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while (LL_RCC_HSI_IsReady() != 1) {} + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while (LL_RCC_PLL_IsReady() != 1) {} + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i != 0; i--) + ; + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -211,29 +204,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ - printf("Assert failed! File %s on line %d\n", file, line); - /* USER CODE END 6 */ + /* USER CODE BEGIN 6 */ + printf("Assert failed! File %s on line %ld\n", file, line); + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h index 127a8c910..70445e57c 100644 --- a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h +++ b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h @@ -11,18 +11,6 @@ #ifndef PRIVATE_CUBE_MX_CAN_H #define PRIVATE_CUBE_MX_CAN_H -/** - * @brief Macro to convert a CubeMX CAN instance pointer to its corresponding index. - * - * Works on all supported boards, but new boards should be verified against this operation - * - * @param inst Pointer to the CubeMX CAN instance (FDCAN1, FDCAN2, or FDCAN3). - * @return The index corresponding to the given CubeMX CAN instance (0 for FDCAN1, 1 for FDCAN2, and 2 for FDCAN3). - * @warning This macro assumes that the CubeMX CAN instances are contiguous in memory and that FDCAN1 is the first instance. It may not work correctly if the instances are not contiguous or if FDCAN1 - * is not the first instance. - */ -#define CUBEMX_CAN_INSTANCE_TO_INDEX(inst) ((uint32_t)((uintptr_t)(inst) - FDCAN1_BASE) >> 10) - /** * @brief Mask for the transmission queue index, used to wrap around the queue when it reaches its maximum size. * @@ -33,6 +21,16 @@ */ #define TX_QUEUE_MASK (CUBEMX_CAN_TX_QUEUE_SIZE - 1U) +/** + * @brief Function to convert a CubeMX CAN instance pointer to its corresponding index. + * + * Works on all supported boards, but new boards should be verified against this operation + * + * @param can Pointer to the CubeMX CAN instance (FDCAN1, FDCAN2, or FDCAN3). + * @return The index corresponding to the given CubeMX CAN instance (0 for FDCAN1, 1 for FDCAN2, and 2 for FDCAN3). + */ +uint32_t CubeMXCan_Private_InstanceToIndex(FDCAN_GlobalTypeDef *can); + /** * @brief CubeMX CAN handle structure * diff --git a/Lib/Peripherals/CubeCAN/Src/can_rx.c b/Lib/Peripherals/CubeCAN/Src/can_rx.c index e21f05d9d..a786d6c2f 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_rx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_rx.c @@ -19,8 +19,8 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) CubeMXCan_Handle *handle = NULL; for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { - if (s_handles[i].hfdcan == hfdcan) { - handle = &s_handles[i]; + if (handles[i].hfdcan == hfdcan) { + handle = &handles[i]; break; } } diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index c60010bdd..5cd85f551 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -10,6 +10,28 @@ #include "Logomatic.h" #include "Private/PrivateCubeMXCAN.h" +uint32_t CubeMXCan_Private_InstanceToIndex(FDCAN_GlobalTypeDef *can) +{ + assert(can != NULL && "Invalid null parameter"); + + switch ((uint32_t)can) { +#if defined(FDCAN1) + case (uint32_t)FDCAN1: + return 0U; +#endif +#if defined(FDCAN2) + case (uint32_t)FDCAN2: + return 1U; +#endif +#if defined(FDCAN3) + case (uint32_t)FDCAN3: + return 2U; +#endif + default: + assert(false && "Invalid CubeMX CAN instance or improper setup in main.h, please use CubeMX to regenerate code and verify your parameters."); + } +} + uint32_t Construct_CAN_Identifier(const CAN_Identifier *identifier) { if (identifier == NULL) { diff --git a/Lib/Peripherals/CubeCAN/cubemx_can.cmake b/Lib/Peripherals/CubeCAN/cubemx_can.cmake index 7f0492132..998f3da0c 100644 --- a/Lib/Peripherals/CubeCAN/cubemx_can.cmake +++ b/Lib/Peripherals/CubeCAN/cubemx_can.cmake @@ -21,6 +21,7 @@ target_link_libraries( CUBEMX_CAN_LIB INTERFACE CANfigurator + LOGOMATIC_LIB ) if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") From 71af319446a24aba619045353c61c4798bc63d9d Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 23 Jul 2026 00:23:48 -0700 Subject: [PATCH 029/125] Fix locking and atomics, and cleanup Signed-off-by: Daniel Hansen --- Lib/GlobalShare/Inc/CriticalSection.h | 1 + Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h | 2 +- Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h | 2 +- .../CubeCAN/Inc/Private/PrivateCubeMXCAN.h | 55 +--------------- Lib/Peripherals/CubeCAN/Src/can_global.c | 1 - Lib/Peripherals/CubeCAN/Src/can_init.c | 66 ++----------------- Lib/Peripherals/CubeCAN/Src/can_tx.c | 27 +++++--- Lib/Peripherals/CubeCAN/Src/can_utils.c | 49 +++++--------- 8 files changed, 44 insertions(+), 159 deletions(-) diff --git a/Lib/GlobalShare/Inc/CriticalSection.h b/Lib/GlobalShare/Inc/CriticalSection.h index d83cdc242..3d6fa7453 100644 --- a/Lib/GlobalShare/Inc/CriticalSection.h +++ b/Lib/GlobalShare/Inc/CriticalSection.h @@ -63,6 +63,7 @@ static inline void _magic_auto_critical_exit(uint32_t *state_var) * * @warning This macro should be used with caution, as it can lead to deadlocks or other issues if not used correctly. It is recommended to use this macro only in situations where it is necessary to * disable interrupts for a short period of time. + * @warning If you use goto statements it will not automatically cleanup. However, you should not use goto at all. */ #define CRITICAL_SECTION \ for (__attribute__((cleanup(_magic_auto_critical_exit))) uint32_t CONCAT(_magic_auto_critical_state_, __LINE__) = __get_PRIMASK(), \ diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h index 89db887a7..d9b381610 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h @@ -98,7 +98,7 @@ HAL_StatusTypeDef CubeMXCan_AddFilter(CubeMXCan_Handle *handle, const FDCAN_Filt * @brief Queues a transmission message for the CubeMX CAN handle, allowing for asynchronous message transmission. * @param handle Pointer to the CubeMX CAN handle. * @param message Pointer to the GRCAN transmission message structure. - * @return HAL_StatusTypeDef indicating the success or failure of the operation. + * @return HAL_StatusTypeDef if the parameters are non-null or the queue is full. */ HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *handle, const GRCAN_TxMessage *message); diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h b/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h index 3cc2ad110..82f36e008 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h @@ -14,7 +14,7 @@ * This structure is used to represent a CAN message identifier, which consists of a transmitting node ID, a receiving node ID, and a message ID. The structure is used in conjunction with the * Construct_Message_ID and Deconstruct_Message_ID functions to convert between the structure representation and the 32-bit integer representation of the CAN message identifier. * - * @warning The structure does not represent cusotm IDs. + * @warning The structure does not represent custom IDs. * @warning The structure does not represent actual bit depth */ typedef struct { diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h index 70445e57c..e9d6c3c7c 100644 --- a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h +++ b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h @@ -21,16 +21,6 @@ */ #define TX_QUEUE_MASK (CUBEMX_CAN_TX_QUEUE_SIZE - 1U) -/** - * @brief Function to convert a CubeMX CAN instance pointer to its corresponding index. - * - * Works on all supported boards, but new boards should be verified against this operation - * - * @param can Pointer to the CubeMX CAN instance (FDCAN1, FDCAN2, or FDCAN3). - * @return The index corresponding to the given CubeMX CAN instance (0 for FDCAN1, 1 for FDCAN2, and 2 for FDCAN3). - */ -uint32_t CubeMXCan_Private_InstanceToIndex(FDCAN_GlobalTypeDef *can); - /** * @brief CubeMX CAN handle structure * @@ -57,27 +47,6 @@ struct CubeMXCan_Handle { /// @brief Maximum number of CubeMX CAN instances supported by the library. #define CUBEMX_CAN_MAX_INSTANCES 3U -/** - * @brief Retrieves the CubeMX CAN handle associated with the given FDCAN handle. - * @param hfdcan Pointer to the FDCAN handle. - * @return Pointer to the CubeMX CAN handle associated with the given FDCAN handle - */ -CubeMXCan_Handle *CubeMXCan_Private_GetHandle(FDCAN_HandleTypeDef *hfdcan); - -/** - * @brief Registers a CubeMX CAN handle with the given FDCAN handle. - * @param hfdcan Pointer to the FDCAN handle. - * @param handle Pointer to the CubeMX CAN handle. - * @return HAL_StatusTypeDef indicating the success or failure of the operation. - */ -HAL_StatusTypeDef CubeMXCan_Private_RegisterHandle(FDCAN_HandleTypeDef *hfdcan, CubeMXCan_Handle *handle); - -/** - * @brief Unregisters the CubeMX CAN handle associated with the given FDCAN handle. - * @param hfdcan Pointer to the FDCAN handle. - */ -void CubeMXCan_Private_UnregisterHandle(FDCAN_HandleTypeDef *hfdcan); - /** * @brief Sends a queued message from the CubeMX CAN handle. * @param handle Pointer to the CubeMX CAN handle. @@ -85,12 +54,6 @@ void CubeMXCan_Private_UnregisterHandle(FDCAN_HandleTypeDef *hfdcan); */ HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(CubeMXCan_Handle *handle); -/** - * @brief Dispatches a received message from the CubeMX CAN handle. - * @param hfdcan Pointer to the FDCAN handle. - */ -void CubeMXCan_Private_DispatchRx(FDCAN_HandleTypeDef *hfdcan); - /** * @brief Converts a Data Length Code (DLC) to the corresponding number of bytes. * @param dlc The Data Length Code to be converted. @@ -109,22 +72,6 @@ void CubeMXCan_Tick(void); */ void CubeMXCan_OnRxFifo0(FDCAN_HandleTypeDef *hfdcan); -/** - * @brief Structure representing a registry entry for the CubeMX CAN library, used to associate a CubeMX CAN handle with its corresponding FDCAN handle. - */ -struct CubeMXCan_RegistryEntry { - /// @brief Pointer to the FDCAN instance associated with this registry entry. - FDCAN_GlobalTypeDef *instance; - /// @brief Pointer to the CubeMX CAN handle associated with this registry entry. - CubeMXCan_Handle *handle; -}; - -/** - * @brief Registry entry structure for the CubeMX CAN library, used to associate a CubeMX CAN handle with its corresponding FDCAN handle. - * @note The number of entries in the registry is defined by CUBEMX_CAN_MAX_INSTANCES. - */ -extern struct CubeMXCan_RegistryEntry registry[CUBEMX_CAN_MAX_INSTANCES]; - /** * @brief Array of CubeMX CAN handles, one for each supported instance. * @note The number of instances is defined by CUBEMX_CAN_MAX_INSTANCES. @@ -134,7 +81,7 @@ extern struct CubeMXCan_Handle handles[CUBEMX_CAN_MAX_INSTANCES]; /** * @brief Flag indicating whether the CubeMX CAN Tx timer has been started. */ -extern bool s_timer_started; +extern bool timer_started; /** * @brief Attempts to recover the FDCAN peripheral associated with the given CubeMX CAN handle. diff --git a/Lib/Peripherals/CubeCAN/Src/can_global.c b/Lib/Peripherals/CubeCAN/Src/can_global.c index aa7613e89..71f39ff0a 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_global.c +++ b/Lib/Peripherals/CubeCAN/Src/can_global.c @@ -7,6 +7,5 @@ #include "CubeMXCanExt.h" #include "Private/PrivateCubeMXCAN.h" -struct CubeMXCan_RegistryEntry registry[CUBEMX_CAN_MAX_INSTANCES] = {0}; struct CubeMXCan_Handle handles[CUBEMX_CAN_MAX_INSTANCES] = {0}; bool timer_started = false; diff --git a/Lib/Peripherals/CubeCAN/Src/can_init.c b/Lib/Peripherals/CubeCAN/Src/can_init.c index 627d37eea..6621bdf0b 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_init.c +++ b/Lib/Peripherals/CubeCAN/Src/can_init.c @@ -58,7 +58,10 @@ HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *handle) return HAL_ERROR; } - (void)CubeMXCan_Stop(handle); + if (CubeMXCan_Stop(handle) != HAL_OK) { + LOGOMATIC("CubeMXCan_Release: failed to stop CAN peripheral\n"); + return HAL_ERROR; + } CRITICAL_SECTION { @@ -68,30 +71,6 @@ HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *handle) return HAL_OK; } -void CubeMXCan_Tick(void) -{ - for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { - CubeMXCan_Handle *handle = registry[i].handle; - - CRITICAL_SECTION - { - if (handle == NULL || handle->hfdcan == NULL || !handle->started) { - continue; - } - } - - if (CubeMXCan_Private_IsDisabled(handle)) { - LOGOMATIC("CAN_send: currently in restricted operation mode\n"); - if (CubeMXCan_Private_RecoverPeripheral(handle) != HAL_OK) { - LOGOMATIC("CAN_send %d: failed to recover peripheral\n", (int)i); - continue; - } - } - - (void)CubeMXCan_Private_SendQueuedMessage(handle); - } -} - HAL_StatusTypeDef CubeMXCan_Start(CubeMXCan_Handle *handle) { if (handle == NULL || handle->hfdcan == NULL) { @@ -116,45 +95,14 @@ HAL_StatusTypeDef CubeMXCan_Stop(CubeMXCan_Handle *handle) return HAL_ERROR; } - CRITICAL_SECTION - { - handle->started = false; - } - if (HAL_FDCAN_Stop(handle->hfdcan) != HAL_OK) { return HAL_ERROR; } - return HAL_OK; -} - -HAL_StatusTypeDef CubeMXCan_AddFilter(CubeMXCan_Handle *handle, const FDCAN_FilterTypeDef *filter) -{ - if (handle == NULL || handle->hfdcan == NULL || filter == NULL) { - return HAL_ERROR; - } - - return HAL_FDCAN_ConfigFilter(handle->hfdcan, (FDCAN_FilterTypeDef *)filter); -} - -HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *handle, const GRCAN_TxMessage *message) -{ - if (handle == NULL || message == NULL) { - return HAL_ERROR; - } - - uint32_t current_tail = atomic_load(&handle->tx_tail); - uint32_t current_head = atomic_load(&handle->tx_head); - - if ((current_tail - current_head) >= CUBEMX_CAN_TX_QUEUE_SIZE) { - LOGOMATIC("CubeMXCan_QueueTx: queue is full\n"); - return HAL_TIMEOUT; + CRITICAL_SECTION + { + handle->started = false; } - uint32_t insert_index = current_tail & TX_QUEUE_MASK; - handle->tx_queue[insert_index] = *message; - - atomic_store_explicit(&handle->tx_tail, current_tail + 1U, memory_order_release); - return HAL_OK; } diff --git a/Lib/Peripherals/CubeCAN/Src/can_tx.c b/Lib/Peripherals/CubeCAN/Src/can_tx.c index 3bb804ea8..ed71ad3fe 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_tx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_tx.c @@ -18,9 +18,9 @@ void CubeMXCan_Tick(void) } if (CubeMXCan_Private_IsDisabled(handle)) { - LOGOMATIC("CAN_send: currently in restricted operation mode\n"); + LOGOMATIC("CubeMXCan_Tick: currently in restricted operation mode\n"); if (CubeMXCan_Private_RecoverPeripheral(handle) != HAL_OK) { - LOGOMATIC("CAN_send %d: failed to recover peripheral\n", (int)i); + LOGOMATIC("CubeMXCan_Tick %d: failed to recover peripheral\n", (int)i); continue; } } @@ -35,17 +35,24 @@ HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *handle, const GRCAN_TxMess return HAL_ERROR; } - uint32_t current_tail = atomic_load_explicit(&handle->tx_tail, memory_order_relaxed); - uint32_t current_head = atomic_load_explicit(&handle->tx_head, memory_order_acquire); + HAL_StatusTypeDef status = HAL_OK; - if ((current_tail - current_head) >= CUBEMX_CAN_TX_QUEUE_SIZE) { - LOGOMATIC("CubeMXCan_QueueTx: queue is full\n"); - return HAL_TIMEOUT; + CRITICAL_SECTION + { + uint32_t tail = atomic_load_explicit(&handle->tx_tail, memory_order_relaxed); + uint32_t head = atomic_load_explicit(&handle->tx_head, memory_order_relaxed); + + if ((tail - head) >= CUBEMX_CAN_TX_QUEUE_SIZE) { + head++; // Drop oldest message to make room for the new one + atomic_store_explicit(&handle->tx_head, head, memory_order_relaxed); + status = HAL_TIMEOUT; + } + handle->tx_queue[tail & TX_QUEUE_MASK] = *message; + + atomic_store_explicit(&handle->tx_tail, tail + 1U, memory_order_release); } - handle->tx_queue[current_tail & TX_QUEUE_MASK] = *message; - atomic_store_explicit(&handle->tx_tail, current_tail + 1U, memory_order_release); - return HAL_OK; + return status; } void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index 5cd85f551..c0ff274ef 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -10,27 +10,11 @@ #include "Logomatic.h" #include "Private/PrivateCubeMXCAN.h" -uint32_t CubeMXCan_Private_InstanceToIndex(FDCAN_GlobalTypeDef *can) -{ - assert(can != NULL && "Invalid null parameter"); - - switch ((uint32_t)can) { -#if defined(FDCAN1) - case (uint32_t)FDCAN1: - return 0U; -#endif -#if defined(FDCAN2) - case (uint32_t)FDCAN2: - return 1U; -#endif -#if defined(FDCAN3) - case (uint32_t)FDCAN3: - return 2U; -#endif - default: - assert(false && "Invalid CubeMX CAN instance or improper setup in main.h, please use CubeMX to regenerate code and verify your parameters."); - } -} +#define CAN_TX_NODE_SHIFT 20U +#define CAN_MSG_SHIFT 8U +#define CAN_RX_NODE_SHIFT 0U +#define CAN_NODE_MASK 0xFFU +#define CAN_MSG_MASK 0xFFFU uint32_t Construct_CAN_Identifier(const CAN_Identifier *identifier) { @@ -39,21 +23,21 @@ uint32_t Construct_CAN_Identifier(const CAN_Identifier *identifier) } return // Transmitting node - ((uint32_t)(identifier->tx_node_id & 0xFFU) << 20U) + ((uint32_t)(identifier->tx_node_id & CAN_NODE_MASK) << CAN_TX_NODE_SHIFT) // Message ID - | ((uint32_t)(identifier->msg_id & 0xFFFU) << 8U) + | ((uint32_t)(identifier->msg_id & CAN_MSG_MASK) << CAN_MSG_SHIFT) // Receiving node - | (uint32_t)(identifier->rx_node_id & 0xFFU); + | ((uint32_t)(identifier->rx_node_id & CAN_NODE_MASK) << CAN_RX_NODE_SHIFT); } CAN_Identifier Deconstruct_CAN_Identifier(uint32_t message_id) { return (CAN_Identifier){// Transmitting node - .tx_node_id = (GRCAN_NODE_ID)((message_id >> 20U) & 0xFFU), + .tx_node_id = (GRCAN_NODE_ID)((message_id >> CAN_TX_NODE_SHIFT) & CAN_NODE_MASK), // Message ID - .msg_id = (GRCAN_MSG_ID)((message_id >> 8U) & 0xFFFU), + .msg_id = (GRCAN_MSG_ID)((message_id >> CAN_MSG_SHIFT) & CAN_MSG_MASK), // Receiving node - .rx_node_id = (GRCAN_NODE_ID)(message_id & 0xFFU)}; + .rx_node_id = (GRCAN_NODE_ID)(message_id >> CAN_RX_NODE_SHIFT) & CAN_NODE_MASK}; } HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *identifier, uint32_t filter_index, uint32_t fifo, FDCAN_FilterTypeDef *filter) @@ -75,11 +59,10 @@ HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *identifie HAL_StatusTypeDef CubeMXCan_AddFilter(CubeMXCan_Handle *handle, const FDCAN_FilterTypeDef *filter) { if (handle == NULL || handle->hfdcan == NULL || filter == NULL) { - LOGOMATIC("CubeMXCan_AddFilter: Invalid null parameter\n"); return HAL_ERROR; } - return HAL_FDCAN_ConfigFilter(handle->hfdcan, (FDCAN_FilterTypeDef *)filter); + return HAL_FDCAN_ConfigFilter(handle->hfdcan, filter); } uint8_t CubeMXCan_Private_DlcToBytes(uint32_t dlc) @@ -112,23 +95,23 @@ HAL_StatusTypeDef CubeMXCan_Private_RecoverPeripheral(CubeMXCan_Handle *handle) FDCAN_ProtocolStatusTypeDef protocol_status = {0}; if (HAL_FDCAN_GetProtocolStatus(handle->hfdcan, &protocol_status) == HAL_OK && protocol_status.BusOff) { - LOGOMATIC("CAN_send: bus off detected, attempting recovery\n"); + LOGOMATIC("CubeMXCan_Private_RecoverPeripheral: bus off detected, attempting recovery\n"); if (HAL_FDCAN_Stop(handle->hfdcan) != HAL_OK) { - LOGOMATIC("CAN_send: failed to stop FDCAN peripheral during bus off recovery\n"); + LOGOMATIC("CubeMXCan_Private_RecoverPeripheral: failed to stop FDCAN peripheral during bus off recovery\n"); return HAL_ERROR; } HAL_FDCAN_AbortTxRequest(handle->hfdcan, FDCAN_TX_BUFFER0 | FDCAN_TX_BUFFER1 | FDCAN_TX_BUFFER2); if (HAL_FDCAN_Start(handle->hfdcan) != HAL_OK) { - LOGOMATIC("CAN_send: failed to restart FDCAN peripheral during bus off recovery\n"); + LOGOMATIC("CubeMXCan_Private_RecoverPeripheral: failed to restart FDCAN peripheral during bus off recovery\n"); return HAL_ERROR; } } if (HAL_FDCAN_IsRestrictedOperationMode(handle->hfdcan)) { - LOGOMATIC("CAN_send: currently in restricted operation mode\n"); + LOGOMATIC("CubeMXCan_Private_RecoverPeripheral: currently in restricted operation mode\n"); HAL_FDCAN_ExitRestrictedOperationMode(handle->hfdcan); } From fe782e50d71c4e6411cbeae2e7ec5385c29f20f8 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 23 Jul 2026 00:54:59 -0700 Subject: [PATCH 030/125] Ensure proper handling of tick Signed-off-by: Daniel Hansen --- Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h | 6 ++++++ Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h | 5 ----- Lib/Peripherals/CubeCAN/Src/can_tx.c | 7 ------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h index d9b381610..8867628c9 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h @@ -110,4 +110,10 @@ HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *handle, const GRCAN_TxMess */ bool CubeMXCan_Private_IsDisabled(CubeMXCan_Handle *handle); +/** + * @brief Processes periodic tasks for the CubeMX CAN handle, such as handling timeouts and managing the transmission queue. + * @warning This function sends one can message per configured bus per call. Not calling it will simply not send any messages. + */ +void CubeMXCan_Tick(void); + #endif diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h index e9d6c3c7c..ff7d16b9e 100644 --- a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h +++ b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h @@ -61,11 +61,6 @@ HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(CubeMXCan_Handle *handle); */ uint8_t CubeMXCan_Private_DlcToBytes(uint32_t dlc); -/** - * @brief Processes periodic tasks for the CubeMX CAN handle, such as handling timeouts and managing the transmission queue. - */ -void CubeMXCan_Tick(void); - /** * @brief Callback function for handling received messages from the FDCAN peripheral. This function is called when a message is received in the RX FIFO 0 of the FDCAN peripheral. * @param hfdcan Pointer to the FDCAN handle associated with the received message. diff --git a/Lib/Peripherals/CubeCAN/Src/can_tx.c b/Lib/Peripherals/CubeCAN/Src/can_tx.c index ed71ad3fe..9346df5b0 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_tx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_tx.c @@ -55,13 +55,6 @@ HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *handle, const GRCAN_TxMess return status; } -void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) -{ - if (htim != NULL && htim->Instance == CUBEMX_CAN_TIMER_INSTANCE) { - CubeMXCan_Tick(); - } -} - HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(CubeMXCan_Handle *handle) { if (handle == NULL || handle->hfdcan == NULL) { From 590a2b1de2424265b2457c88beb9c68d96e8edc1 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 23 Jul 2026 01:04:38 -0700 Subject: [PATCH 031/125] Cleanup defines Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Application/Inc/CubeCAN_Config.h | 6 ------ Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h | 9 +++++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h index 7ff7a2a33..bd5e39a5a 100644 --- a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h +++ b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h @@ -5,12 +5,6 @@ #include "main.h" -#define USECAN1 -#define USECAN2 - -#define CUBEMX_CAN_TIMER_INSTANCE TIM5 #define CUBEMX_CAN_TX_QUEUE_SIZE 32U -#define CAN_TIMER_SEND_PERIOD_US 500U -#define CAN_TIMER_HANDLE TIM5 #endif diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h index ff7d16b9e..8c8870e5d 100644 --- a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h +++ b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h @@ -6,6 +6,7 @@ #include "CubeMXCan.h" #include "Logomatic.h" #include "Stringification.h" +#include "fdcan.h" #include "main.h" #ifndef PRIVATE_CUBE_MX_CAN_H @@ -45,7 +46,15 @@ struct CubeMXCan_Handle { }; /// @brief Maximum number of CubeMX CAN instances supported by the library. +#if defined(FDCAN3) || defined(CAN3) #define CUBEMX_CAN_MAX_INSTANCES 3U +#elif (defined(FDCAN2) || defined(CAN2)) +#define CUBEMX_CAN_MAX_INSTANCES 2U +#elif (defined(FDCAN1) || defined(CAN1)) +#define CUBEMX_CAN_MAX_INSTANCES 1U +#else +#error "No CAN or FDCAN instances defined. Please check your CubeMX configuration." +#endif /** * @brief Sends a queued message from the CubeMX CAN handle. From 27c7c507514512a3c78867edf1654eda3ba0ad8c Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 31 Jul 2026 02:20:51 -0700 Subject: [PATCH 032/125] Redundancy checking on max instances Signed-off-by: Daniel Hansen --- Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h index 8c8870e5d..bdb91aac0 100644 --- a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h +++ b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h @@ -46,15 +46,17 @@ struct CubeMXCan_Handle { }; /// @brief Maximum number of CubeMX CAN instances supported by the library. -#if defined(FDCAN3) || defined(CAN3) +#ifndef CUBEMX_CAN_MAX_INSTANCES +#if (defined(FDCAN3) || defined(CAN3)) && (defined(FDCAN2) || defined(CAN2)) && (defined(FDCAN1) || defined(CAN1)) #define CUBEMX_CAN_MAX_INSTANCES 3U -#elif (defined(FDCAN2) || defined(CAN2)) +#elif (defined(FDCAN2) || defined(CAN2)) && (defined(FDCAN1) || defined(CAN1)) #define CUBEMX_CAN_MAX_INSTANCES 2U #elif (defined(FDCAN1) || defined(CAN1)) #define CUBEMX_CAN_MAX_INSTANCES 1U #else #error "No CAN or FDCAN instances defined. Please check your CubeMX configuration." #endif +#endif /** * @brief Sends a queued message from the CubeMX CAN handle. From da339e17503e763aea3d4b620653dc9792e0c7e7 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 31 Jul 2026 02:29:35 -0700 Subject: [PATCH 033/125] Remove templates, very broken sadly Thanks to Rehan for trying out different iterations of them Signed-off-by: Daniel Hansen --- Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl | 268 ------------------ Lib/CubeMXTemplates/README.md | 9 - 2 files changed, 277 deletions(-) delete mode 100644 Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl delete mode 100644 Lib/CubeMXTemplates/README.md diff --git a/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl b/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl deleted file mode 100644 index 815c29617..000000000 --- a/Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl +++ /dev/null @@ -1,268 +0,0 @@ -[#ftl] -[#-- - Generates can_cfg.h from the active STM32CubeMX project. - - Detects enabled FDCAN and TIM peripherals and emits compile-time configuration - for the Gaucho Racing CAN runtime. - - CubeMX remains responsible for: - - FDCAN clocks, GPIO, bit timing, HAL handles, and MX_FDCANx_Init() - - TIM clocks, prescaler, NVIC configuration, HAL handle, and MX_TIMx_Init() - - The CAN runtime uses the selected CubeMX-generated TIM handle to periodically - service its software TX queues. ---] - -[#list configs as dt] - -[#assign usedIPs = (dt.usedIPs)![]] - -[#assign hasFDCAN1 = false] -[#assign hasFDCAN2 = false] -[#assign hasFDCAN3 = false] - -[#assign hasTIM1 = false] -[#assign hasTIM2 = false] -[#assign hasTIM3 = false] -[#assign hasTIM4 = false] -[#assign hasTIM5 = false] -[#assign hasTIM6 = false] -[#assign hasTIM7 = false] -[#assign hasTIM8 = false] -[#assign hasTIM15 = false] -[#assign hasTIM16 = false] -[#assign hasTIM17 = false] - -[#list usedIPs as ip] - [#assign ipName = ip?string] - - [#if ipName == "FDCAN1"] - [#assign hasFDCAN1 = true] - [/#if] - [#if ipName == "FDCAN2"] - [#assign hasFDCAN2 = true] - [/#if] - [#if ipName == "FDCAN3"] - [#assign hasFDCAN3 = true] - [/#if] - - [#if ipName == "TIM1"] - [#assign hasTIM1 = true] - [/#if] - [#if ipName == "TIM2"] - [#assign hasTIM2 = true] - [/#if] - [#if ipName == "TIM3"] - [#assign hasTIM3 = true] - [/#if] - [#if ipName == "TIM4"] - [#assign hasTIM4 = true] - [/#if] - [#if ipName == "TIM5"] - [#assign hasTIM5 = true] - [/#if] - [#if ipName == "TIM6"] - [#assign hasTIM6 = true] - [/#if] - [#if ipName == "TIM7"] - [#assign hasTIM7 = true] - [/#if] - [#if ipName == "TIM8"] - [#assign hasTIM8 = true] - [/#if] - [#if ipName == "TIM15"] - [#assign hasTIM15 = true] - [/#if] - [#if ipName == "TIM16"] - [#assign hasTIM16 = true] - [/#if] - [#if ipName == "TIM17"] - [#assign hasTIM17 = true] - [/#if] -[/#list] - -#ifndef CAN_CFG_H -#define CAN_CFG_H - -/* Generated automatically by STM32CubeMX FreeMarker. */ - -/* - * User-editable CAN runtime configuration. - * - * CAN_TIMER_INDEX: - * Selects the CubeMX-generated timer handle. Example: 5 selects htim5. - * - * CAN_TIMER_TICK_US: - * Duration of one timer counter tick, determined by the CubeMX prescaler. - * For a 160 MHz TIM clock and Prescaler = 15999, one tick is 100 us. - * - * CAN_DEQUEUE_PERIOD_US: - * Time between attempts to dequeue and send one software-queued CAN message. - */ -/* USER CODE BEGIN CAN_USER_CONFIG */ - -#ifndef TX_BUFFER_1_SIZE -#define TX_BUFFER_1_SIZE 20U -#endif - -#ifndef TX_BUFFER_2_SIZE -#define TX_BUFFER_2_SIZE 20U -#endif - -#ifndef TX_BUFFER_3_SIZE -#define TX_BUFFER_3_SIZE 20U -#endif - -#ifndef CAN_TIMER_INDEX -#define CAN_TIMER_INDEX 5 -#endif - -#ifndef CAN_TIMER_TICK_US -#define CAN_TIMER_TICK_US 100U -#endif - -#ifndef CAN_DEQUEUE_PERIOD_US -#define CAN_DEQUEUE_PERIOD_US 500U -#endif - -/* USER CODE END CAN_USER_CONFIG */ - -/* Enabled FDCAN peripherals. */ - -[#if hasFDCAN1] -#define USECAN1 -[/#if] - -[#if hasFDCAN2] -#define USECAN2 -[/#if] - -[#if hasFDCAN3] -#define USECAN3 -[/#if] - -/* Timers enabled in CubeMX. */ - -[#if hasTIM1] -#define CUBEMX_HAS_TIM1 -[/#if] -[#if hasTIM2] -#define CUBEMX_HAS_TIM2 -[/#if] -[#if hasTIM3] -#define CUBEMX_HAS_TIM3 -[/#if] -[#if hasTIM4] -#define CUBEMX_HAS_TIM4 -[/#if] -[#if hasTIM5] -#define CUBEMX_HAS_TIM5 -[/#if] -[#if hasTIM6] -#define CUBEMX_HAS_TIM6 -[/#if] -[#if hasTIM7] -#define CUBEMX_HAS_TIM7 -[/#if] -[#if hasTIM8] -#define CUBEMX_HAS_TIM8 -[/#if] -[#if hasTIM15] -#define CUBEMX_HAS_TIM15 -[/#if] -[#if hasTIM16] -#define CUBEMX_HAS_TIM16 -[/#if] -[#if hasTIM17] -#define CUBEMX_HAS_TIM17 -[/#if] - -/* Configuration validation. */ - -#if defined(USECAN1) && (TX_BUFFER_1_SIZE == 0U) -#error "TX_BUFFER_1_SIZE must be greater than zero" -#endif - -#if defined(USECAN2) && (TX_BUFFER_2_SIZE == 0U) -#error "TX_BUFFER_2_SIZE must be greater than zero" -#endif - -#if defined(USECAN3) && (TX_BUFFER_3_SIZE == 0U) -#error "TX_BUFFER_3_SIZE must be greater than zero" -#endif - -#if CAN_TIMER_TICK_US == 0U -#error "CAN_TIMER_TICK_US must be greater than zero" -#endif - -#if CAN_DEQUEUE_PERIOD_US == 0U -#error "CAN_DEQUEUE_PERIOD_US must be greater than zero" -#endif - -#if CAN_DEQUEUE_PERIOD_US < CAN_TIMER_TICK_US -#error "CAN_DEQUEUE_PERIOD_US cannot be shorter than one timer tick" -#endif - -#if (CAN_DEQUEUE_PERIOD_US % CAN_TIMER_TICK_US) != 0U -#error "CAN_DEQUEUE_PERIOD_US must be divisible by CAN_TIMER_TICK_US" -#endif - -#if ((CAN_DEQUEUE_PERIOD_US / CAN_TIMER_TICK_US) - 1U) > 0xFFFFFFFFU -#error "CAN dequeue period exceeds the supported timer auto-reload range" -#endif - -#if (CAN_TIMER_INDEX == 1) && !defined(CUBEMX_HAS_TIM1) -#error "CAN_TIMER_INDEX selects TIM1, but TIM1 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 2) && !defined(CUBEMX_HAS_TIM2) -#error "CAN_TIMER_INDEX selects TIM2, but TIM2 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 3) && !defined(CUBEMX_HAS_TIM3) -#error "CAN_TIMER_INDEX selects TIM3, but TIM3 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 4) && !defined(CUBEMX_HAS_TIM4) -#error "CAN_TIMER_INDEX selects TIM4, but TIM4 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 5) && !defined(CUBEMX_HAS_TIM5) -#error "CAN_TIMER_INDEX selects TIM5, but TIM5 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 6) && !defined(CUBEMX_HAS_TIM6) -#error "CAN_TIMER_INDEX selects TIM6, but TIM6 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 7) && !defined(CUBEMX_HAS_TIM7) -#error "CAN_TIMER_INDEX selects TIM7, but TIM7 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 8) && !defined(CUBEMX_HAS_TIM8) -#error "CAN_TIMER_INDEX selects TIM8, but TIM8 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 15) && !defined(CUBEMX_HAS_TIM15) -#error "CAN_TIMER_INDEX selects TIM15, but TIM15 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 16) && !defined(CUBEMX_HAS_TIM16) -#error "CAN_TIMER_INDEX selects TIM16, but TIM16 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 17) && !defined(CUBEMX_HAS_TIM17) -#error "CAN_TIMER_INDEX selects TIM17, but TIM17 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX != 1) && \ - (CAN_TIMER_INDEX != 2) && \ - (CAN_TIMER_INDEX != 3) && \ - (CAN_TIMER_INDEX != 4) && \ - (CAN_TIMER_INDEX != 5) && \ - (CAN_TIMER_INDEX != 6) && \ - (CAN_TIMER_INDEX != 7) && \ - (CAN_TIMER_INDEX != 8) && \ - (CAN_TIMER_INDEX != 15) && \ - (CAN_TIMER_INDEX != 16) && \ - (CAN_TIMER_INDEX != 17) -#error "CAN_TIMER_INDEX selects an unsupported timer" -#endif - -#define CAN_TIMER_PERIOD_COUNTS \ - (CAN_DEQUEUE_PERIOD_US / CAN_TIMER_TICK_US) - -#define CAN_TIMER_AUTORELOAD \ - (CAN_TIMER_PERIOD_COUNTS - 1U) - -/* - * Convert CAN_TIMER_INDEX into CubeMX's generated HAL timer handle. - * - * CAN_TIMER_INDEX = 5 - * CAN_TIMER_HANDLE = htim5 - */ -#define CAN_CFG_JOIN_INNER(a, b) a##b -#define CAN_CFG_JOIN(a, b) CAN_CFG_JOIN_INNER(a, b) -#define CAN_TIMER_HANDLE CAN_CFG_JOIN(htim, CAN_TIMER_INDEX) - -#endif /* CAN_CFG_H */ - -[/#list] diff --git a/Lib/CubeMXTemplates/README.md b/Lib/CubeMXTemplates/README.md deleted file mode 100644 index 37ba973d7..000000000 --- a/Lib/CubeMXTemplates/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# STM32 CubeMX Templates - -## Instructions - -1. Uncheck use default location and configure it to point to this folder (not `Autogen`!) -2. Add all of the relevant templates from available into selected -3. TODO (As we figure out the destination folder bit) - -## TODO From 63f07dc5040d72004b2e9d3cd6144c22a8437ad2 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 31 Jul 2026 04:14:56 -0700 Subject: [PATCH 034/125] Harden testing of the critical section code Signed-off-by: Daniel Hansen --- Lib/GlobalShare/Inc/CriticalSection.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Lib/GlobalShare/Inc/CriticalSection.h b/Lib/GlobalShare/Inc/CriticalSection.h index 3d6fa7453..7e53dd0b5 100644 --- a/Lib/GlobalShare/Inc/CriticalSection.h +++ b/Lib/GlobalShare/Inc/CriticalSection.h @@ -1,7 +1,6 @@ #include #include "Stringification.h" -#include "main.h" #ifndef CRITICAL_SECTION_H #define CRITICAL_SECTION_H @@ -29,16 +28,17 @@ static inline void __disable_irq(void) static inline void __set_PRIMASK(uint32_t state) { - (void)state; - - __mock_irq_nesting_depth--; - - if (__mock_irq_nesting_depth == 0) { - __mock_primask_state = 0; + if (__mock_irq_nesting_depth > 0) { + __mock_irq_nesting_depth--; + if (__mock_irq_nesting_depth == 0 || state == 0) { + __mock_primask_state = 0; + __mock_irq_nesting_depth = 0; + } } - pthread_mutex_unlock(&__mock_global_irq_mutex); } +#else +#include "main.h" #endif /** From 569662c2d503694a765b7596745dbda5e7eede3d Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 31 Jul 2026 04:15:11 -0700 Subject: [PATCH 035/125] Harden CubeCAN Signed-off-by: Daniel Hansen --- Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h | 31 ++-- Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h | 6 +- .../CubeCAN/Inc/Private/PrivateCubeMXCAN.h | 23 ++- Lib/Peripherals/CubeCAN/Src/can_assert.c | 13 +- Lib/Peripherals/CubeCAN/Src/can_init.c | 68 +++++---- Lib/Peripherals/CubeCAN/Src/can_rx.c | 49 +++++-- Lib/Peripherals/CubeCAN/Src/can_tx.c | 19 ++- Lib/Peripherals/CubeCAN/Src/can_utils.c | 137 ++++++++++++------ 8 files changed, 216 insertions(+), 130 deletions(-) diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h index 8867628c9..91ed9f493 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h @@ -14,7 +14,8 @@ /** * @brief Received CAN message structure * - * This structure is used to represent a received CAN message, which consists of a header and data payload. The header contains information about the message, such as its identifier, data length, and other relevant parameters. The data payload contains the actual data bytes of the message. + * This structure is used to represent a received CAN message, which consists of a header and data payload. The header contains information about the message, such as its identifier, data length, and + * other relevant parameters. The data payload contains the actual data bytes of the message. * * @warning The length of the data array may be longer than the actual CAN message. */ @@ -28,7 +29,8 @@ typedef struct { /** * @brief Transmission CAN message structure * - * This structure is used to represent a transmission CAN message, which consists of a header and data payload. The header contains information about the message, such as its identifier, data length, and other relevant parameters. The data payload contains the actual data bytes of the message. + * This structure is used to represent a transmission CAN message, which consists of a header and data payload. The header contains information about the message, such as its identifier, data length, + * and other relevant parameters. The data payload contains the actual data bytes of the message. * * @warning The length of the data array may be longer than the actual CAN message. */ @@ -41,12 +43,13 @@ typedef struct { typedef struct CubeMXCan_Handle CubeMXCan_Handle; /// @brief Callback function type for receiving CAN messages. @warning Do not call directly, use the provided API functions. -typedef void (*CubeCAN_RxCallback)(void *user_ctx, const CAN_Identifier *identifier, const uint8_t *data, uint8_t size); +typedef void (*CubeCAN_RxCallback)(const void *const user_ctx, const CAN_Identifier *const identifier, const uint8_t *const data, const uint8_t size); /** * @brief Configuration structure for CubeMX CAN. * - * This structure is used to configure the CubeMX CAN handle, including the receive callback function and user context. The receive callback function is called when a CAN message is received, and the user context is a pointer to user-defined data that can be passed to the callback function. + * This structure is used to configure the CubeMX CAN handle, including the receive callback function and user context. The receive callback function is called when a CAN message is received, and the + * user context is a pointer to user-defined data that can be passed to the callback function. * * @warning Do not edit after initialization, as it may lead to undefined behavior. */ @@ -63,28 +66,28 @@ typedef struct { * @param config Pointer to the CubeCAN configuration structure. * @return Pointer to the initialized CubeMX CAN handle, or NULL if initialization fails. */ -CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, const CubeCAN_Config *config); +CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config); /** * @brief Starts the CubeMX CAN handle, enabling message transmission and reception. * @param handle Pointer to the CubeMX CAN handle. * @return HAL_StatusTypeDef indicating the success or failure of the operation. */ -HAL_StatusTypeDef CubeMXCan_Start(CubeMXCan_Handle *handle); +HAL_StatusTypeDef CubeMXCan_Start(CubeMXCan_Handle *const handle); /** * @brief Stops the CubeMX CAN handle, disabling message transmission and reception. * @param handle Pointer to the CubeMX CAN handle. * @return HAL_StatusTypeDef indicating the success or failure of the operation. */ -HAL_StatusTypeDef CubeMXCan_Stop(CubeMXCan_Handle *handle); +HAL_StatusTypeDef CubeMXCan_Stop(CubeMXCan_Handle *const handle); /** * @brief Releases the resources associated with the CubeMX CAN handle. * @param handle Pointer to the CubeMX CAN handle. * @return HAL_StatusTypeDef indicating the success or failure of the operation. */ -HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *handle); +HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *const handle); /** * @brief Adds a filter to the CubeMX CAN handle, allowing for selective message reception based on the specified filter criteria. @@ -92,7 +95,7 @@ HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *handle); * @param filter Pointer to the FDCAN filter configuration structure. * @return HAL_StatusTypeDef indicating the success or failure of the operation. */ -HAL_StatusTypeDef CubeMXCan_AddFilter(CubeMXCan_Handle *handle, const FDCAN_FilterTypeDef *filter); +HAL_StatusTypeDef CubeMXCan_AddFilter(const CubeMXCan_Handle *const handle, const FDCAN_FilterTypeDef *const filter); /** * @brief Queues a transmission message for the CubeMX CAN handle, allowing for asynchronous message transmission. @@ -100,15 +103,7 @@ HAL_StatusTypeDef CubeMXCan_AddFilter(CubeMXCan_Handle *handle, const FDCAN_Filt * @param message Pointer to the GRCAN transmission message structure. * @return HAL_StatusTypeDef if the parameters are non-null or the queue is full. */ -HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *handle, const GRCAN_TxMessage *message); - -/** - * @brief Converts a Data Length Code (DLC) to the corresponding number of data bytes. - * @param dlc The Data Length Code to be converted. - * @return The number of data bytes corresponding to the given DLC. - * @warning The DLC value must be between 0 and 15, inclusive. Values outside this range will result in undefined behavior. - */ -bool CubeMXCan_Private_IsDisabled(CubeMXCan_Handle *handle); +HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *const handle, const GRCAN_TxMessage *const message); /** * @brief Processes periodic tasks for the CubeMX CAN handle, such as handling timeouts and managing the transmission queue. diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h b/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h index 82f36e008..6316e7604 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h @@ -30,7 +30,7 @@ typedef struct { * * @return The constructed 29-bit CAN message extended identifier. */ -uint32_t Construct_CAN_Identifier(const CAN_Identifier *identifier); +uint32_t Construct_CAN_Identifier(const CAN_Identifier *const identifier); /** * @brief Deconstructs a 29-bit CAN message extended identifier into its constituent transmitting node ID, receiving node ID, and message ID. @@ -42,11 +42,11 @@ uint32_t Construct_CAN_Identifier(const CAN_Identifier *identifier); * @warning The function does not guarantee that the returned structure will represent a valid CAN message identifier. * @warning The function does not support custom IDs. */ -CAN_Identifier Deconstruct_CAN_Identifier(uint32_t message_id); +CAN_Identifier Deconstruct_CAN_Identifier(const uint32_t message_id); /** * @brief Builds an exact-match extended-ID filter for a given CAN identifier. */ -HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *identifier, uint32_t filter_index, uint32_t fifo, FDCAN_FilterTypeDef *filter); +HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *const identifier, const uint32_t filter_index, const uint32_t fifo, FDCAN_FilterTypeDef *const filter); #endif diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h index bdb91aac0..53decb535 100644 --- a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h +++ b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h @@ -22,6 +22,13 @@ */ #define TX_QUEUE_MASK (CUBEMX_CAN_TX_QUEUE_SIZE - 1U) +/** + * @brief Rx events mask for FDCAN notifications. + * + * This mask is used to enable notifications for new messages, full FIFO, and message lost events in the FDCAN peripheral. + */ +static const uint32_t rx_events = FDCAN_IT_RX_FIFO0_NEW_MESSAGE | FDCAN_IT_RX_FIFO0_FULL | FDCAN_IT_RX_FIFO0_MESSAGE_LOST; + /** * @brief CubeMX CAN handle structure * @@ -63,20 +70,20 @@ struct CubeMXCan_Handle { * @param handle Pointer to the CubeMX CAN handle. * @return HAL_StatusTypeDef indicating the success or failure of the operation. */ -HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(CubeMXCan_Handle *handle); +HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(const CubeMXCan_Handle *const handle); /** * @brief Converts a Data Length Code (DLC) to the corresponding number of bytes. * @param dlc The Data Length Code to be converted. * @return The number of bytes corresponding to the given DLC. */ -uint8_t CubeMXCan_Private_DlcToBytes(uint32_t dlc); +uint8_t CubeMXCan_Private_DlcToBytes(const uint32_t dlc); /** * @brief Callback function for handling received messages from the FDCAN peripheral. This function is called when a message is received in the RX FIFO 0 of the FDCAN peripheral. * @param hfdcan Pointer to the FDCAN handle associated with the received message. */ -void CubeMXCan_OnRxFifo0(FDCAN_HandleTypeDef *hfdcan); +void CubeMXCan_OnRxFifo0(FDCAN_HandleTypeDef *const hfdcan); /** * @brief Array of CubeMX CAN handles, one for each supported instance. @@ -97,6 +104,14 @@ extern bool timer_started; * @param handle Pointer to the CubeMX CAN handle associated with the FDCAN peripheral to be recovered. * @return HAL_StatusTypeDef indicating the success or failure of the recovery operation. */ -HAL_StatusTypeDef CubeMXCan_Private_RecoverPeripheral(CubeMXCan_Handle *handle); +HAL_StatusTypeDef CubeMXCan_Private_RecoverPeripheral(const CubeMXCan_Handle *const handle); + +/** + * @brief Converts a Data Length Code (DLC) to the corresponding number of data bytes. + * @param dlc The Data Length Code to be converted. + * @return The number of data bytes corresponding to the given DLC. + * @warning The DLC value must be between 0 and 15, inclusive. Values outside this range will result in undefined behavior. + */ +bool CubeMXCan_Private_IsDisabled(const CubeMXCan_Handle *const handle); #endif diff --git a/Lib/Peripherals/CubeCAN/Src/can_assert.c b/Lib/Peripherals/CubeCAN/Src/can_assert.c index 93df889de..87440aeb3 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_assert.c +++ b/Lib/Peripherals/CubeCAN/Src/can_assert.c @@ -8,21 +8,14 @@ #include "Private/PrivateCubeMXCAN.h" #include "main.h" -#pragma region Platform Assertions - static_assert(sizeof(((CubeMXCan_Handle *)0)->tx_head) == sizeof(uint32_t), "tx_head must be 32 bits"); - static_assert(sizeof(GRCAN_TxMessage) == (sizeof(FDCAN_TxHeaderTypeDef) + 64), "GRCAN_TxMessage size is incorrect"); static_assert(_Alignof(GRCAN_TxMessage) >= 4, "GRCAN_TxMessage must have at least 4-byte alignment"); - static_assert(ATOMIC_INT_LOCK_FREE == 2, "ATOMIC_INT_LOCK_FREE must be enabled for atomic operations on tx_head and tx_tail"); -#pragma endregion -#pragma region Configuration Validations - -static_assert((CUBEMX_CAN_TX_QUEUE_SIZE > 0) && !(CUBEMX_CAN_TX_QUEUE_SIZE & (CUBEMX_CAN_TX_QUEUE_SIZE - 1)), "CUBEMX_CAN_TX_QUEUE_SIZE must be a power of two and greater than zero"); +static_assert((offsetof(struct CubeMXCan_Handle, tx_head) % 4U) == 0U, "The atomic tx_head is unaligned"); +static_assert((offsetof(struct CubeMXCan_Handle, tx_tail) % 4U) == 0U, "The atomic tx_tail is unaligned"); +static_assert((CUBEMX_CAN_TX_QUEUE_SIZE > 0) && !(CUBEMX_CAN_TX_QUEUE_SIZE & (CUBEMX_CAN_TX_QUEUE_SIZE - 1U)), "CUBEMX_CAN_TX_QUEUE_SIZE must be a power of two and greater than zero"); static_assert(CUBEMX_CAN_MAX_INSTANCES >= 1 && CUBEMX_CAN_MAX_INSTANCES <= 3, "CUBEMX_CAN_MAX_INSTANCES must be configured between 1 and 3 inclusive"); - -#pragma endregion diff --git a/Lib/Peripherals/CubeCAN/Src/can_init.c b/Lib/Peripherals/CubeCAN/Src/can_init.c index 6621bdf0b..77d19f8c9 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_init.c +++ b/Lib/Peripherals/CubeCAN/Src/can_init.c @@ -10,7 +10,7 @@ #include "Private/PrivateCubeMXCAN.h" #include "main.h" -CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, const CubeCAN_Config *config) +CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config) { if (hfdcan == NULL || config == NULL) { LOGOMATIC("CubeMXCan_Init: invalid null parameters\n"); @@ -42,10 +42,12 @@ CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, const CubeCAN_Conf return NULL; } - uint32_t rx_events = FDCAN_IT_RX_FIFO0_NEW_MESSAGE | FDCAN_IT_RX_FIFO0_FULL | FDCAN_IT_RX_FIFO0_MESSAGE_LOST; if (HAL_FDCAN_ActivateNotification(hfdcan, rx_events, 0U) != HAL_OK) { LOGOMATIC("CubeMXCan_Init: failed to activate RX notifications\n"); - memset(handle, 0, sizeof(*handle)); + CRITICAL_SECTION + { + memset(handle, 0, sizeof(*handle)); + } return NULL; } @@ -54,55 +56,71 @@ CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, const CubeCAN_Conf HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *handle) { - if (handle == NULL || handle->hfdcan == NULL) { + if (handle == NULL) { return HAL_ERROR; } - if (CubeMXCan_Stop(handle) != HAL_OK) { - LOGOMATIC("CubeMXCan_Release: failed to stop CAN peripheral\n"); - return HAL_ERROR; - } + HAL_StatusTypeDef status = HAL_OK; CRITICAL_SECTION { - memset(handle, 0, sizeof(*handle)); - } + if (handle->hfdcan != NULL) { + status = HAL_FDCAN_Stop(handle->hfdcan); - return HAL_OK; + if (status == HAL_OK) { + status = HAL_FDCAN_DeactivateNotification(handle->hfdcan, rx_events); + } + if (status == HAL_OK) { + memset(handle, 0, sizeof(*handle)); + } else { + LOGOMATIC("CubeMXCan_Release: peripheral deactivation failed\n"); + } + + return status; + } else { + return HAL_ERROR; + } + } } -HAL_StatusTypeDef CubeMXCan_Start(CubeMXCan_Handle *handle) +HAL_StatusTypeDef CubeMXCan_Start(CubeMXCan_Handle *const handle) { - if (handle == NULL || handle->hfdcan == NULL) { + if (handle == NULL) { return HAL_ERROR; } - if (HAL_FDCAN_Start(handle->hfdcan) != HAL_OK) { - return HAL_ERROR; - } + HAL_StatusTypeDef status = HAL_ERROR; CRITICAL_SECTION { - handle->started = true; + if (handle->hfdcan != NULL && !handle->started) { + status = HAL_FDCAN_Start(handle->hfdcan); + if (status == HAL_OK) { + handle->started = true; + } + } } - return HAL_OK; + return status; } -HAL_StatusTypeDef CubeMXCan_Stop(CubeMXCan_Handle *handle) +HAL_StatusTypeDef CubeMXCan_Stop(CubeMXCan_Handle *const handle) { - if (handle == NULL || handle->hfdcan == NULL) { + if (handle == NULL) { return HAL_ERROR; } - if (HAL_FDCAN_Stop(handle->hfdcan) != HAL_OK) { - return HAL_ERROR; - } + HAL_StatusTypeDef status = HAL_ERROR; CRITICAL_SECTION { - handle->started = false; + if (handle->hfdcan != NULL && handle->started) { + status = HAL_FDCAN_Stop(handle->hfdcan); + if (status == HAL_OK) { + handle->started = false; + } + } } - return HAL_OK; + return status; } diff --git a/Lib/Peripherals/CubeCAN/Src/can_rx.c b/Lib/Peripherals/CubeCAN/Src/can_rx.c index a786d6c2f..0ebf7676e 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_rx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_rx.c @@ -11,34 +11,53 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) { - UNUSED(RxFifo0ITs); + if (RxFifo0ITs & FDCAN_IT_RX_FIFO0_MESSAGE_LOST) { + LOGOMATIC("WARNING: CAN Rx FIFO is overflowing, messages are being lost!\n"); + } if (hfdcan == NULL) { return; } - CubeMXCan_Handle *handle = NULL; - for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { - if (handles[i].hfdcan == hfdcan) { - handle = &handles[i]; - break; + const void* user_ctx = NULL; + CubeCAN_RxCallback rx_callback = NULL; + bool is_started = false; + + CRITICAL_SECTION + { + for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { + if (handles[i].hfdcan == hfdcan) { + user_ctx = handles[i].config.user_ctx; + rx_callback = handles[i].config.rx_callback; + is_started = handles[i].started; + break; + } } } - if (handle == NULL || handle->config.rx_callback == NULL) { - FDCAN_RxHeaderTypeDef rx_header; - uint8_t rx_data[FDCAN_MAX_DATA_BYTES]; - (void)HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &rx_header, rx_data); - LOGOMATIC("Rx Callback missing for instance\n"); + if (!is_started || rx_callback == NULL) { + FDCAN_RxHeaderTypeDef dump_header; + uint8_t dump_data[FDCAN_MAX_DATA_BYTES]; + + while (HAL_FDCAN_GetRxFifoFillLevel(hfdcan, FDCAN_RX_FIFO0) > 0U) { + (void)HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &dump_header, dump_data); + } + + LOGOMATIC("HAL_FDCAN_RxFifo0Callback: Message dropped, unmapped handle or instance stopped\n"); return; } FDCAN_RxHeaderTypeDef rx_header; uint8_t rx_data[FDCAN_MAX_DATA_BYTES]; - if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &rx_header, rx_data) == HAL_OK) { - CAN_Identifier id = Deconstruct_CAN_Identifier(rx_header.Identifier); - uint8_t size = CubeMXCan_Private_DlcToBytes(rx_header.DataLength); - handle->config.rx_callback(handle->config.user_ctx, &id, rx_data, size); + while (HAL_FDCAN_GetRxFifoFillLevel(hfdcan, FDCAN_RX_FIFO0) > 0U) { + if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &rx_header, rx_data) == HAL_OK) { + CAN_Identifier id = Deconstruct_CAN_Identifier(rx_header.Identifier); + uint8_t size = CubeMXCan_Private_DlcToBytes(rx_header.DataLength); + rx_callback(user_ctx, &id, rx_data, size); + } else { + LOGOMATIC("HAL_FDCAN_RxFifo0Callback: Failed to get Rx message from FIFO\n"); + break; + } } } diff --git a/Lib/Peripherals/CubeCAN/Src/can_tx.c b/Lib/Peripherals/CubeCAN/Src/can_tx.c index 9346df5b0..2179ffb94 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_tx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_tx.c @@ -39,13 +39,13 @@ HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *handle, const GRCAN_TxMess CRITICAL_SECTION { - uint32_t tail = atomic_load_explicit(&handle->tx_tail, memory_order_relaxed); + const uint32_t tail = atomic_load_explicit(&handle->tx_tail, memory_order_relaxed); uint32_t head = atomic_load_explicit(&handle->tx_head, memory_order_relaxed); if ((tail - head) >= CUBEMX_CAN_TX_QUEUE_SIZE) { head++; // Drop oldest message to make room for the new one atomic_store_explicit(&handle->tx_head, head, memory_order_relaxed); - status = HAL_TIMEOUT; + status = HAL_BUSY; } handle->tx_queue[tail & TX_QUEUE_MASK] = *message; @@ -55,23 +55,28 @@ HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *handle, const GRCAN_TxMess return status; } -HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(CubeMXCan_Handle *handle) +HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(const CubeMXCan_Handle *const handle) { if (handle == NULL || handle->hfdcan == NULL) { LOGOMATIC("CubeMXCan_Private_SendQueuedMessage: invalid null parameter\n"); return HAL_ERROR; } - uint32_t current_head = atomic_load_explicit(&handle->tx_head, memory_order_relaxed); - uint32_t current_tail = atomic_load_explicit(&handle->tx_tail, memory_order_acquire); + if (HAL_FDCAN_GetTxFifoFreeLevel(handle->hfdcan) == 0U) { + LOGOMATIC("CubeMXCan_Private_SendQueuedMessage: Tx FIFO full, cannot send message\n"); + return HAL_BUSY; + } + + const uint32_t current_head = atomic_load_explicit(&handle->tx_head, memory_order_relaxed); + const uint32_t current_tail = atomic_load_explicit(&handle->tx_tail, memory_order_acquire); if (current_head == current_tail) { return HAL_OK; } - GRCAN_TxMessage message_copy = handle->tx_queue[current_head & TX_QUEUE_MASK]; + const GRCAN_TxMessage *const message_ptr = &handle->tx_queue[current_head & TX_QUEUE_MASK]; - if (HAL_FDCAN_AddMessageToTxFifoQ(handle->hfdcan, &message_copy.tx_header, message_copy.data) != HAL_OK) { + if (HAL_FDCAN_AddMessageToTxFifoQ(handle->hfdcan, &message_ptr->tx_header, message_ptr->data) != HAL_OK) { return HAL_ERROR; } diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index c0ff274ef..ef2fd46cf 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -22,25 +22,23 @@ uint32_t Construct_CAN_Identifier(const CAN_Identifier *identifier) return 0U; } - return // Transmitting node - ((uint32_t)(identifier->tx_node_id & CAN_NODE_MASK) << CAN_TX_NODE_SHIFT) - // Message ID - | ((uint32_t)(identifier->msg_id & CAN_MSG_MASK) << CAN_MSG_SHIFT) - // Receiving node - | ((uint32_t)(identifier->rx_node_id & CAN_NODE_MASK) << CAN_RX_NODE_SHIFT); + const uint32_t tx_node_id = identifier->tx_node_id & CAN_NODE_MASK; + const uint32_t msg_id = identifier->msg_id & CAN_MSG_MASK; + const uint32_t rx_node_id = identifier->rx_node_id & CAN_NODE_MASK; + + return (tx_node_id << CAN_TX_NODE_SHIFT) | (msg_id << CAN_MSG_SHIFT) | (rx_node_id << CAN_RX_NODE_SHIFT); } -CAN_Identifier Deconstruct_CAN_Identifier(uint32_t message_id) +CAN_Identifier Deconstruct_CAN_Identifier(const uint32_t message_id) { - return (CAN_Identifier){// Transmitting node - .tx_node_id = (GRCAN_NODE_ID)((message_id >> CAN_TX_NODE_SHIFT) & CAN_NODE_MASK), - // Message ID - .msg_id = (GRCAN_MSG_ID)((message_id >> CAN_MSG_SHIFT) & CAN_MSG_MASK), - // Receiving node - .rx_node_id = (GRCAN_NODE_ID)(message_id >> CAN_RX_NODE_SHIFT) & CAN_NODE_MASK}; + const GRCAN_NODE_ID tx_node_id = (message_id >> CAN_TX_NODE_SHIFT) & CAN_NODE_MASK; + const GRCAN_MSG_ID msg_id = (message_id >> CAN_MSG_SHIFT) & CAN_MSG_MASK; + const GRCAN_NODE_ID rx_node_id = (message_id >> CAN_RX_NODE_SHIFT) & CAN_NODE_MASK; + + return (CAN_Identifier){.tx_node_id = tx_node_id, .msg_id = msg_id, .rx_node_id = rx_node_id}; } -HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *identifier, uint32_t filter_index, uint32_t fifo, FDCAN_FilterTypeDef *filter) +HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *const identifier, const uint32_t filter_index, const uint32_t fifo, FDCAN_FilterTypeDef *const filter) { if (identifier == NULL || filter == NULL) { return HAL_ERROR; @@ -56,64 +54,107 @@ HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *identifie return HAL_OK; } -HAL_StatusTypeDef CubeMXCan_AddFilter(CubeMXCan_Handle *handle, const FDCAN_FilterTypeDef *filter) +HAL_StatusTypeDef CubeMXCan_AddFilter(const CubeMXCan_Handle *const handle, const FDCAN_FilterTypeDef *filter) { - if (handle == NULL || handle->hfdcan == NULL || filter == NULL) { + if (handle == NULL || filter == NULL) { return HAL_ERROR; } - return HAL_FDCAN_ConfigFilter(handle->hfdcan, filter); + HAL_StatusTypeDef status = HAL_ERROR; + + CRITICAL_SECTION + { + if (handle->hfdcan != NULL) { + status = HAL_FDCAN_ConfigFilter(handle->hfdcan, filter); + } + } + + return status; } -uint8_t CubeMXCan_Private_DlcToBytes(uint32_t dlc) +uint8_t CubeMXCan_Private_DlcToBytes(const uint32_t dlc) { - static const uint8_t dlc_to_bytes[] = {0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 12U, 16U, 20U, 24U, 32U, 48U, 64U}; + uint32_t dlc_index = (dlc >> 16U) & 0x0FU; + + if (dlc <= 8U) { + return (uint8_t)dlc; + } + + if (dlc_index == 0U) { + dlc_index = dlc & 0x0FU; + } - static_assert((sizeof(dlc_to_bytes) / sizeof(dlc_to_bytes[0])) == 16, "dlc_to_bytes array must have 16 elements"); + static const uint8_t dlc_to_bytes[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64}; - return (dlc > 15U) ? 64U : dlc_to_bytes[dlc]; + return (dlc_index > 15U) ? 0U : dlc_to_bytes[dlc_index]; } -bool CubeMXCan_Private_IsDisabled(CubeMXCan_Handle *handle) +bool CubeMXCan_Private_IsDisabled(const CubeMXCan_Handle *const handle) { - if (handle == NULL || handle->hfdcan == NULL) { + if (handle == NULL) { return true; } - HAL_FDCAN_StateTypeDef state = HAL_FDCAN_GetState(handle->hfdcan); - FDCAN_ProtocolStatusTypeDef protocol_status = {0}; + bool disabled = true; - return // HAL states - state == HAL_FDCAN_STATE_ERROR || - state == HAL_FDCAN_STATE_READY - // Check for bus off condition - || (HAL_FDCAN_GetProtocolStatus(handle->hfdcan, &protocol_status) == HAL_OK && protocol_status.BusOff); -} + CRITICAL_SECTION + { + if (handle->hfdcan != NULL) { + const HAL_FDCAN_StateTypeDef state = HAL_FDCAN_GetState(handle->hfdcan); + FDCAN_ProtocolStatusTypeDef protocol_status = {0}; -HAL_StatusTypeDef CubeMXCan_Private_RecoverPeripheral(CubeMXCan_Handle *handle) -{ - FDCAN_ProtocolStatusTypeDef protocol_status = {0}; + bool is_bus_off = false; - if (HAL_FDCAN_GetProtocolStatus(handle->hfdcan, &protocol_status) == HAL_OK && protocol_status.BusOff) { - LOGOMATIC("CubeMXCan_Private_RecoverPeripheral: bus off detected, attempting recovery\n"); + if (HAL_FDCAN_GetProtocolStatus(handle->hfdcan, &protocol_status) == HAL_OK) { + is_bus_off = protocol_status.BusOff; + } - if (HAL_FDCAN_Stop(handle->hfdcan) != HAL_OK) { - LOGOMATIC("CubeMXCan_Private_RecoverPeripheral: failed to stop FDCAN peripheral during bus off recovery\n"); - return HAL_ERROR; + disabled = (state == HAL_FDCAN_STATE_ERROR || state == HAL_FDCAN_STATE_READY || is_bus_off); } + } - HAL_FDCAN_AbortTxRequest(handle->hfdcan, FDCAN_TX_BUFFER0 | FDCAN_TX_BUFFER1 | FDCAN_TX_BUFFER2); + return disabled; +} - if (HAL_FDCAN_Start(handle->hfdcan) != HAL_OK) { - LOGOMATIC("CubeMXCan_Private_RecoverPeripheral: failed to restart FDCAN peripheral during bus off recovery\n"); - return HAL_ERROR; - } +HAL_StatusTypeDef CubeMXCan_Private_RecoverPeripheral(const CubeMXCan_Handle *const handle) +{ + if (handle == NULL) { + return HAL_ERROR; } - if (HAL_FDCAN_IsRestrictedOperationMode(handle->hfdcan)) { - LOGOMATIC("CubeMXCan_Private_RecoverPeripheral: currently in restricted operation mode\n"); - HAL_FDCAN_ExitRestrictedOperationMode(handle->hfdcan); + HAL_StatusTypeDef status = HAL_OK; + + CRITICAL_SECTION + { + if (handle->hfdcan != NULL && handle->started) { + FDCAN_ProtocolStatusTypeDef protocol_status = {0}; + + if (HAL_FDCAN_GetProtocolStatus(handle->hfdcan, &protocol_status) == HAL_OK && protocol_status.BusOff) { + LOGOMATIC("CubeMXCan_Private_RecoverPeripheral: CRITICAL BUS-OFF DETECTED. Forcing instant hardware reset...\n"); + + HAL_FDCAN_Stop(handle->hfdcan); + + status = HAL_FDCAN_Init(handle->hfdcan); + + if (status == HAL_OK) { + status = HAL_FDCAN_ActivateNotification(handle->hfdcan, rx_events, 0U); + } + + if (status == HAL_OK) { + status = HAL_FDCAN_Start(handle->hfdcan); + } + + if (status != HAL_OK) { + LOGOMATIC("CubeMXCan_Private_RecoverPeripheral: Aggressive hardware start failed!\n"); + } + } + + if (HAL_FDCAN_IsRestrictedOperationMode(handle->hfdcan)) { + LOGOMATIC("CubeMXCan_Private_RecoverPeripheral: Forcing exit from restricted operation mode\n"); + HAL_FDCAN_ExitRestrictedOperationMode(handle->hfdcan); + } + } } - return HAL_OK; + return status; } From c1fc7294c78c61986b9737ef1f487a8b2d9f5b8a Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 31 Jul 2026 04:15:23 -0700 Subject: [PATCH 036/125] Tweak CUBEMXTESTING to align with new pattern Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Application/Inc/CANdler.h | 8 ++ CUBEMXTESTING/Application/Src/CANdler.c | 9 ++ CUBEMXTESTING/Autogen/Inc/can_cfg.h | 147 ------------------------ CUBEMXTESTING/Core/Inc/tim.h | 35 +++--- CUBEMXTESTING/Core/Src/main.c | 12 +- 5 files changed, 41 insertions(+), 170 deletions(-) create mode 100644 CUBEMXTESTING/Application/Inc/CANdler.h create mode 100644 CUBEMXTESTING/Application/Src/CANdler.c delete mode 100644 CUBEMXTESTING/Autogen/Inc/can_cfg.h diff --git a/CUBEMXTESTING/Application/Inc/CANdler.h b/CUBEMXTESTING/Application/Inc/CANdler.h new file mode 100644 index 000000000..64739c684 --- /dev/null +++ b/CUBEMXTESTING/Application/Inc/CANdler.h @@ -0,0 +1,8 @@ +#include "CubeMXCan.h" + +#ifndef CANDLER_H +#define CANDLER_H + +void CANdler_Callback(CubeMXCan_Handle *const handle, void *const user_ctx); + +#endif diff --git a/CUBEMXTESTING/Application/Src/CANdler.c b/CUBEMXTESTING/Application/Src/CANdler.c new file mode 100644 index 000000000..cfae5c588 --- /dev/null +++ b/CUBEMXTESTING/Application/Src/CANdler.c @@ -0,0 +1,9 @@ +#include "CANdler.h" + +#include "CubeMXCan.h" + +void CANdler_Callback(CubeMXCan_Handle *const handle, void *const user_ctx) +{ + LOGOMATIC("CANdler_Callback: Received CAN message on handle %p with user context %p\n", (void *)handle, user_ctx); + // TODO +} diff --git a/CUBEMXTESTING/Autogen/Inc/can_cfg.h b/CUBEMXTESTING/Autogen/Inc/can_cfg.h deleted file mode 100644 index 0c6609c06..000000000 --- a/CUBEMXTESTING/Autogen/Inc/can_cfg.h +++ /dev/null @@ -1,147 +0,0 @@ - -#ifndef CAN_CFG_H -#define CAN_CFG_H - -/* Generated automatically by STM32CubeMX FreeMarker. */ - -/* - * User-editable CAN runtime configuration. - * - * CAN_TIMER_INDEX: - * Selects the CubeMX-generated timer handle. Example: 5 selects htim5. - * - * CAN_TIMER_TICK_US: - * Duration of one timer counter tick, determined by the CubeMX prescaler. - * For a 160 MHz TIM clock and Prescaler = 15999, one tick is 100 us. - * - * CAN_DEQUEUE_PERIOD_US: - * Time between attempts to dequeue and send one software-queued CAN message. - */ -/* USER CODE BEGIN CAN_USER_CONFIG */ - -#ifndef TX_BUFFER_1_SIZE -#define TX_BUFFER_1_SIZE 20U -#endif - -#ifndef TX_BUFFER_2_SIZE -#define TX_BUFFER_2_SIZE 20U -#endif - -#ifndef TX_BUFFER_3_SIZE -#define TX_BUFFER_3_SIZE 20U -#endif - -#ifndef CAN_TIMER_INDEX -#define CAN_TIMER_INDEX 5 -#endif - -#ifndef CAN_TIMER_TICK_US -#define CAN_TIMER_TICK_US 100U -#endif - -#ifndef CAN_DEQUEUE_PERIOD_US -#define CAN_DEQUEUE_PERIOD_US 500U -#endif - -/* USER CODE END CAN_USER_CONFIG */ - -/* Enabled FDCAN peripherals. */ - -#define USECAN1 - -#define USECAN2 - -#define USECAN3 - -/* Timers enabled in CubeMX. */ - -#define CUBEMX_HAS_TIM5 - -/* Configuration validation. */ - -#if defined(USECAN1) && (TX_BUFFER_1_SIZE == 0U) -#error "TX_BUFFER_1_SIZE must be greater than zero" -#endif - -#if defined(USECAN2) && (TX_BUFFER_2_SIZE == 0U) -#error "TX_BUFFER_2_SIZE must be greater than zero" -#endif - -#if defined(USECAN3) && (TX_BUFFER_3_SIZE == 0U) -#error "TX_BUFFER_3_SIZE must be greater than zero" -#endif - -#if CAN_TIMER_TICK_US == 0U -#error "CAN_TIMER_TICK_US must be greater than zero" -#endif - -#if CAN_DEQUEUE_PERIOD_US == 0U -#error "CAN_DEQUEUE_PERIOD_US must be greater than zero" -#endif - -#if CAN_DEQUEUE_PERIOD_US < CAN_TIMER_TICK_US -#error "CAN_DEQUEUE_PERIOD_US cannot be shorter than one timer tick" -#endif - -#if (CAN_DEQUEUE_PERIOD_US % CAN_TIMER_TICK_US) != 0U -#error "CAN_DEQUEUE_PERIOD_US must be divisible by CAN_TIMER_TICK_US" -#endif - -#if ((CAN_DEQUEUE_PERIOD_US / CAN_TIMER_TICK_US) - 1U) > 0xFFFFFFFFU -#error "CAN dequeue period exceeds the supported timer auto-reload range" -#endif - -#if (CAN_TIMER_INDEX == 1) && !defined(CUBEMX_HAS_TIM1) -#error "CAN_TIMER_INDEX selects TIM1, but TIM1 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 2) && !defined(CUBEMX_HAS_TIM2) -#error "CAN_TIMER_INDEX selects TIM2, but TIM2 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 3) && !defined(CUBEMX_HAS_TIM3) -#error "CAN_TIMER_INDEX selects TIM3, but TIM3 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 4) && !defined(CUBEMX_HAS_TIM4) -#error "CAN_TIMER_INDEX selects TIM4, but TIM4 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 5) && !defined(CUBEMX_HAS_TIM5) -#error "CAN_TIMER_INDEX selects TIM5, but TIM5 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 6) && !defined(CUBEMX_HAS_TIM6) -#error "CAN_TIMER_INDEX selects TIM6, but TIM6 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 7) && !defined(CUBEMX_HAS_TIM7) -#error "CAN_TIMER_INDEX selects TIM7, but TIM7 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 8) && !defined(CUBEMX_HAS_TIM8) -#error "CAN_TIMER_INDEX selects TIM8, but TIM8 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 15) && !defined(CUBEMX_HAS_TIM15) -#error "CAN_TIMER_INDEX selects TIM15, but TIM15 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 16) && !defined(CUBEMX_HAS_TIM16) -#error "CAN_TIMER_INDEX selects TIM16, but TIM16 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX == 17) && !defined(CUBEMX_HAS_TIM17) -#error "CAN_TIMER_INDEX selects TIM17, but TIM17 is not enabled in CubeMX" -#elif (CAN_TIMER_INDEX != 1) && \ - (CAN_TIMER_INDEX != 2) && \ - (CAN_TIMER_INDEX != 3) && \ - (CAN_TIMER_INDEX != 4) && \ - (CAN_TIMER_INDEX != 5) && \ - (CAN_TIMER_INDEX != 6) && \ - (CAN_TIMER_INDEX != 7) && \ - (CAN_TIMER_INDEX != 8) && \ - (CAN_TIMER_INDEX != 15) && \ - (CAN_TIMER_INDEX != 16) && \ - (CAN_TIMER_INDEX != 17) -#error "CAN_TIMER_INDEX selects an unsupported timer" -#endif - -#define CAN_TIMER_PERIOD_COUNTS \ - (CAN_DEQUEUE_PERIOD_US / CAN_TIMER_TICK_US) - -#define CAN_TIMER_AUTORELOAD \ - (CAN_TIMER_PERIOD_COUNTS - 1U) - -/* - * Convert CAN_TIMER_INDEX into CubeMX's generated HAL timer handle. - * - * CAN_TIMER_INDEX = 5 - * CAN_TIMER_HANDLE = htim5 - */ -#define CAN_CFG_JOIN_INNER(a, b) a##b -#define CAN_CFG_JOIN(a, b) CAN_CFG_JOIN_INNER(a, b) -#define CAN_TIMER_HANDLE CAN_CFG_JOIN(htim, CAN_TIMER_INDEX) - -#endif /* CAN_CFG_H */ - diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index 18374feb3..2d20bd560 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file tim.h - * @brief This file contains all the function prototypes for - * the tim.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file tim.h + * @brief This file contains all the function prototypes for + * the tim.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 __TIM_H__ @@ -35,7 +35,7 @@ extern "C" { extern TIM_HandleTypeDef htim5; /* USER CODE BEGIN Private defines */ - +#define CAN_TIMER_HANDLE htim5 /* USER CODE END Private defines */ void MX_TIM5_Init(void); @@ -49,4 +49,3 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ - diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index ae2deaf7b..9f6e59804 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -25,8 +25,12 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ +#include "CANdler.h" +#include "CubeMXCan.h" +#include "CubeMXCanExt.h" #include "Logomatic.h" #include "loop.h" +#include "tim.h" #include "vcp.h" // #include "can.h" @@ -128,11 +132,9 @@ int main(void) Logomatic_Init(&logomaticConfig); VCP_Init(&vcp_config); - GR_CAN_Init(); + CubeCAN_Config can_config = {.rx_callback = CANdler_Callback, .user_ctx = (void *)1}; - if (CAN_Timer_Start() != HAL_OK) { - Error_Handler(); - } + CubeMXCan_Init(&hfdcan1, &can_config); /* USER CODE END 2 */ /* Infinite loop */ @@ -197,7 +199,7 @@ void SystemClock_Config(void) void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { if (htim == &CAN_TIMER_HANDLE) { - CAN_Timer_Tick(); + CubeMXCan_Tick(); } } From f19ee5a67f0993eeec01a7cd1f4d33d74d989188 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 31 Jul 2026 04:29:23 -0700 Subject: [PATCH 037/125] Add helper oneshot functions, harden init Signed-off-by: Daniel Hansen --- Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h | 18 ++++ Lib/Peripherals/CubeCAN/Src/can_init.c | 132 +++++++++++++++++++----- 2 files changed, 126 insertions(+), 24 deletions(-) diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h index 91ed9f493..06206875b 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h @@ -60,6 +60,24 @@ typedef struct { void *user_ctx; } CubeCAN_Config; +/** + * @brief Initializes a CubeMX CAN handle with the given FDCAN handle and configuration, and starts the CAN peripheral. + * @param hfdcan Pointer to the FDCAN handle. + * @param config Pointer to the CubeCAN configuration structure. + * @return Pointer to the initialized CubeMX CAN handle, or NULL if initialization fails. + * @note This functions wraps CubeMXCan_Init and CubeMXCan_Start into a single call. If either of those functions fails, this function will return NULL and the handle will be released. + */ +CubeMXCan_Handle *CubeMXCan_OneShotInitStart(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config); + +/** + * @brief Stops the CubeMX CAN peripheral and releases the associated handle. + * @param handle Pointer to the CubeMX CAN handle. + * @return HAL_StatusTypeDef indicating the success or failure of the operation. + * @note This functions wraps CubeMXCan_Stop and CubeMXCan_Release into a single call. If either of those functions fails, this function will return the error code and the handle will not be released. + * @note This function can be used regardless of if CubeMXCan_OneShotInitStart was used to initialize the handle. +*/ +HAL_StatusTypeDef CubeMXCan_OneShotReleaseStop(CubeMXCan_Handle *handle); + /** * @brief Initializes a CubeMX CAN handle with the given FDCAN handle and configuration. * @param hfdcan Pointer to the FDCAN handle. diff --git a/Lib/Peripherals/CubeCAN/Src/can_init.c b/Lib/Peripherals/CubeCAN/Src/can_init.c index 77d19f8c9..f8af80ca2 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_init.c +++ b/Lib/Peripherals/CubeCAN/Src/can_init.c @@ -10,6 +10,41 @@ #include "Private/PrivateCubeMXCAN.h" #include "main.h" +CubeMXCan_Handle *CubeMXCan_OneShotInitStart(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config) +{ + CubeMXCan_Handle *handle = CubeMXCan_Init(hfdcan, config); + + if (handle == NULL) { + LOGOMATIC("CubeMXCan_OneShotInit: failed to initialize handle\n"); + return NULL; + } + + if (CubeMXCan_Start(handle) != HAL_OK) { + LOGOMATIC("CubeMXCan_OneShotInit: failed to start handle\n"); + CubeMXCan_Release(handle); + return NULL; + } + + return handle; +} + +HAL_StatusTypeDef CubeMXCan_OneShotReleaseStop(CubeMXCan_Handle *handle) +{ + if (handle == NULL) { + LOGOMATIC("CubeMXCan_OneShotReleaseStop: invalid null parameter\n"); + return NULL; + } + + HAL_StatusTypeDef status = CubeMXCan_Stop(handle); + + if (status != HAL_OK) { + LOGOMATIC("CubeMXCan_OneShotReleaseStop: failed to stop FDCAN instance\n"); + return status; + } + + return CubeMXCan_Release(handle); +} + CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config) { if (hfdcan == NULL || config == NULL) { @@ -18,16 +53,24 @@ CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *co } CubeMXCan_Handle *handle = NULL; + uint8_t free_handle_index = (uint8_t)-1; + CRITICAL_SECTION { for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { - if (handles[i].hfdcan == hfdcan || handles[i].hfdcan == NULL) { + if (handles[i].hfdcan == hfdcan) { handle = &handles[i]; break; + } else if (handles[i].hfdcan == NULL && free_handle_index == (uint8_t)-1) { + free_handle_index = i; } } if (handle != NULL) { + LOGOMATIC("CubeMXCan_Init: handle already initialized for this FDCAN instance\n"); + return NULL; + } else if (free_handle_index != (uint8_t)-1) { + handle = &handles[free_handle_index]; memset(handle, 0, sizeof(*handle)); handle->hfdcan = hfdcan; handle->config = *config; @@ -60,27 +103,44 @@ HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *handle) return HAL_ERROR; } - HAL_StatusTypeDef status = HAL_OK; + FDCAN_HandleTypeDef *hfdcan_to_stop = NULL; CRITICAL_SECTION { if (handle->hfdcan != NULL) { - status = HAL_FDCAN_Stop(handle->hfdcan); + hfdcan_to_stop = handle->hfdcan; + handle->hfdcan = NULL; + handle->started = false; + } + } - if (status == HAL_OK) { - status = HAL_FDCAN_DeactivateNotification(handle->hfdcan, rx_events); - } - if (status == HAL_OK) { - memset(handle, 0, sizeof(*handle)); - } else { - LOGOMATIC("CubeMXCan_Release: peripheral deactivation failed\n"); - } + if (hfdcan_to_stop == NULL) { + return HAL_ERROR; + } - return status; - } else { - return HAL_ERROR; + HAL_StatusTypeDef status = HAL_FDCAN_Stop(hfdcan_to_stop); + + if (status == HAL_OK) { + status = HAL_FDCAN_DeactivateNotification(hfdcan_to_stop, rx_events); + } + + if (status != HAL_OK) { + LOGOMATIC("CubeMXCan_Release: peripheral deactivation failed\n"); + + CRITICAL_SECTION + { + handle->hfdcan = hfdcan_to_stop; } + + return status; + } + + CRITICAL_SECTION + { + memset(handle, 0, sizeof(*handle)); } + + return HAL_OK; } HAL_StatusTypeDef CubeMXCan_Start(CubeMXCan_Handle *const handle) @@ -89,15 +149,27 @@ HAL_StatusTypeDef CubeMXCan_Start(CubeMXCan_Handle *const handle) return HAL_ERROR; } - HAL_StatusTypeDef status = HAL_ERROR; + bool dynamic_start = false; + FDCAN_HandleTypeDef *hfdcan = NULL; CRITICAL_SECTION { if (handle->hfdcan != NULL && !handle->started) { - status = HAL_FDCAN_Start(handle->hfdcan); - if (status == HAL_OK) { - handle->started = true; - } + hfdcan = handle->hfdcan; + dynamic_start = true; + } + } + + if (!dynamic_start) { + return HAL_ERROR; + } + + HAL_StatusTypeDef status = HAL_FDCAN_Start(hfdcan); + + if (status == HAL_OK) { + CRITICAL_SECTION + { + handle->started = true; } } @@ -110,15 +182,27 @@ HAL_StatusTypeDef CubeMXCan_Stop(CubeMXCan_Handle *const handle) return HAL_ERROR; } - HAL_StatusTypeDef status = HAL_ERROR; + bool dynamic_stop = false; + FDCAN_HandleTypeDef *hfdcan = NULL; CRITICAL_SECTION { if (handle->hfdcan != NULL && handle->started) { - status = HAL_FDCAN_Stop(handle->hfdcan); - if (status == HAL_OK) { - handle->started = false; - } + hfdcan = handle->hfdcan; + dynamic_stop = true; + } + } + + if (!dynamic_stop) { + return HAL_ERROR; + } + + HAL_StatusTypeDef status = HAL_FDCAN_Stop(hfdcan); + + if (status == HAL_OK) { + CRITICAL_SECTION + { + handle->started = false; } } From 1a62255ea88089eae2855b4d3059fc4ce769e667 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 31 Jul 2026 05:43:40 -0700 Subject: [PATCH 038/125] So much peripheral lockdown Signed-off-by: Daniel Hansen --- Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h | 63 +++++-------- .../CubeCAN/Inc/Private/PrivateCubeMXCAN.h | 59 ++++++++---- Lib/Peripherals/CubeCAN/Src/can_assert.c | 16 ++-- Lib/Peripherals/CubeCAN/Src/can_global.c | 2 +- Lib/Peripherals/CubeCAN/Src/can_init.c | 6 +- Lib/Peripherals/CubeCAN/Src/can_rx.c | 6 +- Lib/Peripherals/CubeCAN/Src/can_tx.c | 55 +++++++++++- Lib/Peripherals/CubeCAN/Src/can_utils.c | 90 ++++++++++++++++--- 8 files changed, 211 insertions(+), 86 deletions(-) diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h index 06206875b..efb93091e 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h @@ -11,39 +11,11 @@ #define FDCAN_MAX_DATA_BYTES 64U -/** - * @brief Received CAN message structure - * - * This structure is used to represent a received CAN message, which consists of a header and data payload. The header contains information about the message, such as its identifier, data length, and - * other relevant parameters. The data payload contains the actual data bytes of the message. - * - * @warning The length of the data array may be longer than the actual CAN message. - */ -typedef struct { - /// @brief The header of the received CAN message, containing information such as the identifier, data length, and other relevant parameters. - FDCAN_RxHeaderTypeDef rx_header; - /// @brief The data payload of the received CAN message, containing the actual data bytes of the message. The length of this array may be longer than the actual CAN message. - uint8_t data[FDCAN_MAX_DATA_BYTES]; -} GRCAN_RxMessage; - -/** - * @brief Transmission CAN message structure - * - * This structure is used to represent a transmission CAN message, which consists of a header and data payload. The header contains information about the message, such as its identifier, data length, - * and other relevant parameters. The data payload contains the actual data bytes of the message. - * - * @warning The length of the data array may be longer than the actual CAN message. - */ -typedef struct { - FDCAN_TxHeaderTypeDef tx_header; - uint8_t data[FDCAN_MAX_DATA_BYTES]; -} GRCAN_TxMessage; - /// @brief CAN handle for CubeMX CAN. @warning Do not access directly, use the provided API functions. -typedef struct CubeMXCan_Handle CubeMXCan_Handle; +typedef struct CubeMXCan_Private_Handle CubeMXCan_Handle; /// @brief Callback function type for receiving CAN messages. @warning Do not call directly, use the provided API functions. -typedef void (*CubeCAN_RxCallback)(const void *const user_ctx, const CAN_Identifier *const identifier, const uint8_t *const data, const uint8_t size); +typedef void (*CubeCAN_RxCallback)(const void *const user_context, const CAN_Identifier *const identifier, const uint8_t *const data, const uint8_t size); /** * @brief Configuration structure for CubeMX CAN. @@ -54,10 +26,12 @@ typedef void (*CubeCAN_RxCallback)(const void *const user_ctx, const CAN_Identif * @warning Do not edit after initialization, as it may lead to undefined behavior. */ typedef struct { + /// @brief User-defined context pointer that can be passed to the receive callback function. This can be used to pass additional data or state information to the callback function. + void *user_context; /// @brief Callback function for receiving CAN messages. This function is called when a CAN message is received. CubeCAN_RxCallback rx_callback; - /// @brief User-defined context pointer that can be passed to the receive callback function. This can be used to pass additional data or state information to the callback function. - void *user_ctx; + /// @brief Node ID of the sending device. This is used to identify the source of the CAN messages and must be unique on the CAN bus. + GRCAN_NODE_ID sending_node_id; } CubeCAN_Config; /** @@ -73,9 +47,10 @@ CubeMXCan_Handle *CubeMXCan_OneShotInitStart(FDCAN_HandleTypeDef *hfdcan, CubeCA * @brief Stops the CubeMX CAN peripheral and releases the associated handle. * @param handle Pointer to the CubeMX CAN handle. * @return HAL_StatusTypeDef indicating the success or failure of the operation. - * @note This functions wraps CubeMXCan_Stop and CubeMXCan_Release into a single call. If either of those functions fails, this function will return the error code and the handle will not be released. + * @note This functions wraps CubeMXCan_Stop and CubeMXCan_Release into a single call. If either of those functions fails, this function will return the error code and the handle will + * not be released. * @note This function can be used regardless of if CubeMXCan_OneShotInitStart was used to initialize the handle. -*/ + */ HAL_StatusTypeDef CubeMXCan_OneShotReleaseStop(CubeMXCan_Handle *handle); /** @@ -115,18 +90,22 @@ HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *const handle); */ HAL_StatusTypeDef CubeMXCan_AddFilter(const CubeMXCan_Handle *const handle, const FDCAN_FilterTypeDef *const filter); -/** - * @brief Queues a transmission message for the CubeMX CAN handle, allowing for asynchronous message transmission. - * @param handle Pointer to the CubeMX CAN handle. - * @param message Pointer to the GRCAN transmission message structure. - * @return HAL_StatusTypeDef if the parameters are non-null or the queue is full. - */ -HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *const handle, const GRCAN_TxMessage *const message); - /** * @brief Processes periodic tasks for the CubeMX CAN handle, such as handling timeouts and managing the transmission queue. * @warning This function sends one can message per configured bus per call. Not calling it will simply not send any messages. */ void CubeMXCan_Tick(void); +/** + * @brief Sends a CAN message using the CubeMX CAN handle, with the specified receive node, message ID, data payload, and size. + * @param handle Pointer to the CubeMX CAN handle. + * @param rx_node The receive node identifier for the message. + * @param msg_id The message ID for the message. + * @param data Pointer to the data payload of the message. + * @param size The size of the data payload in bytes. + * @return HAL_StatusTypeDef indicating the success or failure of the operation. + * @note The size of the data payload must not exceed FDCAN_MAX_DATA_BYTES (64 bytes). If the size exceeds this limit, the function will return HAL_ERROR. + */ +HAL_StatusTypeDef CubeMXCan_Send(CubeMXCan_Handle *const handle, const GRCAN_NODE_ID rx_node, const GRCAN_MSG_ID msg_id, const void *const data, const uint8_t size); + #endif diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h index 53decb535..6b56924fd 100644 --- a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h +++ b/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h @@ -3,7 +3,6 @@ #include #include "CubeCAN_Config.h" -#include "CubeMXCan.h" #include "Logomatic.h" #include "Stringification.h" #include "fdcan.h" @@ -27,7 +26,20 @@ * * This mask is used to enable notifications for new messages, full FIFO, and message lost events in the FDCAN peripheral. */ -static const uint32_t rx_events = FDCAN_IT_RX_FIFO0_NEW_MESSAGE | FDCAN_IT_RX_FIFO0_FULL | FDCAN_IT_RX_FIFO0_MESSAGE_LOST; +#define FDCAN_IT_RX_EVENTS (FDCAN_IT_RX_FIFO0_NEW_MESSAGE | FDCAN_IT_RX_FIFO0_FULL | FDCAN_IT_RX_FIFO0_MESSAGE_LOST) + +/** + * @brief Transmission CAN message structure + * + * This structure is used to represent a transmission CAN message, which consists of a header and data payload. The header contains information about the message, such as its identifier, data length, + * and other relevant parameters. The data payload contains the actual data bytes of the message. + * + * @warning The length of the data array may be longer than the actual CAN message. + */ +typedef struct { + FDCAN_TxHeaderTypeDef tx_header; + uint8_t data[FDCAN_MAX_DATA_BYTES]; +} GRCAN_Private_TxMessage; /** * @brief CubeMX CAN handle structure @@ -37,13 +49,13 @@ static const uint32_t rx_events = FDCAN_IT_RX_FIFO0_NEW_MESSAGE | FDCAN_IT_RX_FI * @warning Use the provided API functions to interact with the CubeMX CAN handle. * @warning The structure is intended for internal use only and should not be accessed directly by user code. */ -struct CubeMXCan_Handle { +struct CubeMXCan_Private_Handle { /// @brief Pointer to the FDCAN handle associated with this CubeMX CAN handle. FDCAN_HandleTypeDef *hfdcan; /// @brief Configuration structure for the CubeMX CAN handle, containing the receive callback and user context. CubeCAN_Config config; /// @brief Transmission queue for the CubeMX CAN handle, containing the messages to be transmitted. - GRCAN_TxMessage tx_queue[CUBEMX_CAN_TX_QUEUE_SIZE]; + GRCAN_Private_TxMessage tx_queue[CUBEMX_CAN_TX_QUEUE_SIZE]; /// @brief Atomic head index for the transmission queue, indicating the next message to be transmitted. _Atomic uint32_t tx_head; /// @brief Atomic tail index for the transmission queue, indicating the next available slot for a new message. @@ -72,24 +84,11 @@ struct CubeMXCan_Handle { */ HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(const CubeMXCan_Handle *const handle); -/** - * @brief Converts a Data Length Code (DLC) to the corresponding number of bytes. - * @param dlc The Data Length Code to be converted. - * @return The number of bytes corresponding to the given DLC. - */ -uint8_t CubeMXCan_Private_DlcToBytes(const uint32_t dlc); - -/** - * @brief Callback function for handling received messages from the FDCAN peripheral. This function is called when a message is received in the RX FIFO 0 of the FDCAN peripheral. - * @param hfdcan Pointer to the FDCAN handle associated with the received message. - */ -void CubeMXCan_OnRxFifo0(FDCAN_HandleTypeDef *const hfdcan); - /** * @brief Array of CubeMX CAN handles, one for each supported instance. * @note The number of instances is defined by CUBEMX_CAN_MAX_INSTANCES. */ -extern struct CubeMXCan_Handle handles[CUBEMX_CAN_MAX_INSTANCES]; +extern struct CubeMXCan_Private_Handle handles[CUBEMX_CAN_MAX_INSTANCES]; /** * @brief Flag indicating whether the CubeMX CAN Tx timer has been started. @@ -114,4 +113,28 @@ HAL_StatusTypeDef CubeMXCan_Private_RecoverPeripheral(const CubeMXCan_Handle *co */ bool CubeMXCan_Private_IsDisabled(const CubeMXCan_Handle *const handle); +/** + * @brief Queues a transmission message for the CubeMX CAN handle, allowing for asynchronous message transmission. + * @param handle Pointer to the CubeMX CAN handle. + * @param message Pointer to the GRCAN transmission message structure. + * @return HAL_StatusTypeDef if the parameters are non-null or the queue is full. + */ +HAL_StatusTypeDef CubeMXCan_Private_QueueTx(CubeMXCan_Handle *const handle, const GRCAN_Private_TxMessage *const message); + +/** + * @brief Converts a Data Length Code (DLC) to the corresponding number of bytes. + * @param dlc The Data Length Code to be converted. + * @return The number of bytes corresponding to the given DLC. + * @warning The DLC value must be between 0 and 15, inclusive. Values outside this range will result in undefined behavior. + */ +uint8_t CubeMXCan_Private_DlcToBytes(const uint32_t dlc); + +/** + * @brief Converts a number of bytes to the corresponding Data Length Code (DLC). + * @param bytes The number of bytes to be converted. + * @return The Data Length Code corresponding to the given number of bytes. + * @warning The number of bytes must be between 0 and 8, inclusive. Values outside this range will result in undefined behavior. + */ +uint8_t CubeMXCan_Private_BytesToDlc(const uint8_t bytes); + #endif diff --git a/Lib/Peripherals/CubeCAN/Src/can_assert.c b/Lib/Peripherals/CubeCAN/Src/can_assert.c index 87440aeb3..594c6ca4e 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_assert.c +++ b/Lib/Peripherals/CubeCAN/Src/can_assert.c @@ -1,5 +1,7 @@ #include +#include #include +#include #include "CriticalSection.h" #include "CubeCAN_Config.h" @@ -8,14 +10,18 @@ #include "Private/PrivateCubeMXCAN.h" #include "main.h" -static_assert(sizeof(((CubeMXCan_Handle *)0)->tx_head) == sizeof(uint32_t), "tx_head must be 32 bits"); -static_assert(sizeof(GRCAN_TxMessage) == (sizeof(FDCAN_TxHeaderTypeDef) + 64), "GRCAN_TxMessage size is incorrect"); +static_assert(sizeof(((struct CubeMXCan_Private_Handle *)0)->tx_head) == sizeof(uint32_t), "tx_head must be 32 bits"); +static_assert(sizeof(GRCAN_Private_TxMessage) == (sizeof(FDCAN_TxHeaderTypeDef) + 64), "GRCAN_Private_TxMessage size is incorrect"); -static_assert(_Alignof(GRCAN_TxMessage) >= 4, "GRCAN_TxMessage must have at least 4-byte alignment"); +static_assert(alignof(GRCAN_Private_TxMessage) >= 4, "GRCAN_Private_TxMessage must have at least 4-byte alignment"); static_assert(ATOMIC_INT_LOCK_FREE == 2, "ATOMIC_INT_LOCK_FREE must be enabled for atomic operations on tx_head and tx_tail"); -static_assert((offsetof(struct CubeMXCan_Handle, tx_head) % 4U) == 0U, "The atomic tx_head is unaligned"); -static_assert((offsetof(struct CubeMXCan_Handle, tx_tail) % 4U) == 0U, "The atomic tx_tail is unaligned"); +static_assert((offsetof(struct CubeMXCan_Private_Handle, tx_head) % 4U) == 0U, "The atomic tx_head is unaligned"); +static_assert((offsetof(struct CubeMXCan_Private_Handle, tx_tail) % 4U) == 0U, "The atomic tx_tail is unaligned"); static_assert((CUBEMX_CAN_TX_QUEUE_SIZE > 0) && !(CUBEMX_CAN_TX_QUEUE_SIZE & (CUBEMX_CAN_TX_QUEUE_SIZE - 1U)), "CUBEMX_CAN_TX_QUEUE_SIZE must be a power of two and greater than zero"); static_assert(CUBEMX_CAN_MAX_INSTANCES >= 1 && CUBEMX_CAN_MAX_INSTANCES <= 3, "CUBEMX_CAN_MAX_INSTANCES must be configured between 1 and 3 inclusive"); + +#ifndef CUBEMX_SENDING_NODE_ID +#error "CUBEMX_SENDING_NODE_ID must be defined in CubeCAN_Config.h. This is the node ID of the sending device and must be unique on the CAN bus." +#endif diff --git a/Lib/Peripherals/CubeCAN/Src/can_global.c b/Lib/Peripherals/CubeCAN/Src/can_global.c index 71f39ff0a..20b10badf 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_global.c +++ b/Lib/Peripherals/CubeCAN/Src/can_global.c @@ -7,5 +7,5 @@ #include "CubeMXCanExt.h" #include "Private/PrivateCubeMXCAN.h" -struct CubeMXCan_Handle handles[CUBEMX_CAN_MAX_INSTANCES] = {0}; +struct CubeMXCan_Private_Handle handles[CUBEMX_CAN_MAX_INSTANCES] = {0}; bool timer_started = false; diff --git a/Lib/Peripherals/CubeCAN/Src/can_init.c b/Lib/Peripherals/CubeCAN/Src/can_init.c index f8af80ca2..f82cd5a20 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_init.c +++ b/Lib/Peripherals/CubeCAN/Src/can_init.c @@ -32,7 +32,7 @@ HAL_StatusTypeDef CubeMXCan_OneShotReleaseStop(CubeMXCan_Handle *handle) { if (handle == NULL) { LOGOMATIC("CubeMXCan_OneShotReleaseStop: invalid null parameter\n"); - return NULL; + return HAL_ERROR; } HAL_StatusTypeDef status = CubeMXCan_Stop(handle); @@ -85,7 +85,7 @@ CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *co return NULL; } - if (HAL_FDCAN_ActivateNotification(hfdcan, rx_events, 0U) != HAL_OK) { + if (HAL_FDCAN_ActivateNotification(hfdcan, FDCAN_IT_RX_EVENTS, 0U) != HAL_OK) { LOGOMATIC("CubeMXCan_Init: failed to activate RX notifications\n"); CRITICAL_SECTION { @@ -121,7 +121,7 @@ HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *handle) HAL_StatusTypeDef status = HAL_FDCAN_Stop(hfdcan_to_stop); if (status == HAL_OK) { - status = HAL_FDCAN_DeactivateNotification(hfdcan_to_stop, rx_events); + status = HAL_FDCAN_DeactivateNotification(hfdcan_to_stop, FDCAN_IT_RX_EVENTS); } if (status != HAL_OK) { diff --git a/Lib/Peripherals/CubeCAN/Src/can_rx.c b/Lib/Peripherals/CubeCAN/Src/can_rx.c index 0ebf7676e..47f908973 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_rx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_rx.c @@ -19,7 +19,7 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) return; } - const void* user_ctx = NULL; + const void *user_context = NULL; CubeCAN_RxCallback rx_callback = NULL; bool is_started = false; @@ -27,7 +27,7 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) { for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { if (handles[i].hfdcan == hfdcan) { - user_ctx = handles[i].config.user_ctx; + user_context = handles[i].config.user_context; rx_callback = handles[i].config.rx_callback; is_started = handles[i].started; break; @@ -54,7 +54,7 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &rx_header, rx_data) == HAL_OK) { CAN_Identifier id = Deconstruct_CAN_Identifier(rx_header.Identifier); uint8_t size = CubeMXCan_Private_DlcToBytes(rx_header.DataLength); - rx_callback(user_ctx, &id, rx_data, size); + rx_callback(user_context, &id, rx_data, size); } else { LOGOMATIC("HAL_FDCAN_RxFifo0Callback: Failed to get Rx message from FIFO\n"); break; diff --git a/Lib/Peripherals/CubeCAN/Src/can_tx.c b/Lib/Peripherals/CubeCAN/Src/can_tx.c index 2179ffb94..012911a3c 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_tx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_tx.c @@ -1,5 +1,6 @@ #include #include +#include #include "CriticalSection.h" #include "CubeMXCan.h" @@ -29,7 +30,57 @@ void CubeMXCan_Tick(void) } } -HAL_StatusTypeDef CubeMXCan_QueueTx(CubeMXCan_Handle *handle, const GRCAN_TxMessage *message) +HAL_StatusTypeDef CubeMXCan_Send(CubeMXCan_Handle *const handle, const GRCAN_NODE_ID rx_node, const GRCAN_MSG_ID msg_id, const void *const data, const uint8_t size) +{ + if (handle == NULL || data == NULL || size > FDCAN_MAX_DATA_BYTES) { + return HAL_ERROR; + } + + const uint32_t dlc = CubeMXCan_Private_BytesToDlc(size); + if (dlc == FDCAN_DLC_BYTES_0 && size != 0) { + LOGOMATIC("CubeMXCan_Send: invalid data length code\n"); + return HAL_ERROR; + } + + uint32_t fdformat = 0; + uint32_t brs = 0; + switch (handle->hfdcan->Init.FrameFormat) { + case FDCAN_FRAME_CLASSIC: + fdformat = FDCAN_CLASSIC_CAN; + brs = FDCAN_BRS_OFF; + break; + case FDCAN_FRAME_FD_NO_BRS: + fdformat = FDCAN_FD_CAN; + brs = FDCAN_BRS_OFF; + break; + case FDCAN_FRAME_FD_BRS: + fdformat = FDCAN_FD_CAN; + brs = FDCAN_BRS_ON; + break; + default: + LOGOMATIC("CubeMXCan_Send: unsupported frame format\n"); + return HAL_ERROR; + } + + const CAN_Identifier identifier_struct = {.tx_node_id = handle->config.sending_node_id, .rx_node_id = rx_node, .msg_id = msg_id}; + + const FDCAN_TxHeaderTypeDef header = {.BitRateSwitch = brs, + .DataLength = CubeMXCan_Private_BytesToDlc(size), + .ErrorStateIndicator = FDCAN_ESI_ACTIVE, + .FDFormat = fdformat, + .Identifier = Construct_CAN_Identifier(&identifier_struct), + .IdType = FDCAN_EXTENDED_ID, + .MessageMarker = 0U, // TODO We can do cool things with this to track transmission queue statistics + .TxEventFifoControl = FDCAN_NO_TX_EVENTS, + .TxFrameType = FDCAN_DATA_FRAME}; + + GRCAN_Private_TxMessage message = {.tx_header = header}; + memcpy(message.data, data, size); + + return CubeMXCan_Private_QueueTx(handle, &message); +} + +HAL_StatusTypeDef CubeMXCan_Private_QueueTx(CubeMXCan_Handle *handle, const GRCAN_Private_TxMessage *message) { if (handle == NULL || message == NULL) { return HAL_ERROR; @@ -74,7 +125,7 @@ HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(const CubeMXCan_Handle *co return HAL_OK; } - const GRCAN_TxMessage *const message_ptr = &handle->tx_queue[current_head & TX_QUEUE_MASK]; + const GRCAN_Private_TxMessage *const message_ptr = &handle->tx_queue[current_head & TX_QUEUE_MASK]; if (HAL_FDCAN_AddMessageToTxFifoQ(handle->hfdcan, &message_ptr->tx_header, message_ptr->data) != HAL_OK) { return HAL_ERROR; diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index ef2fd46cf..17feaf007 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -57,6 +57,7 @@ HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *const ide HAL_StatusTypeDef CubeMXCan_AddFilter(const CubeMXCan_Handle *const handle, const FDCAN_FilterTypeDef *filter) { if (handle == NULL || filter == NULL) { + LOGOMATIC("CubeMXCan_AddFilter: Invalid handle or filter pointer\n"); return HAL_ERROR; } @@ -72,21 +73,86 @@ HAL_StatusTypeDef CubeMXCan_AddFilter(const CubeMXCan_Handle *const handle, cons return status; } -uint8_t CubeMXCan_Private_DlcToBytes(const uint32_t dlc) +uint8_t CubeMXCan_Private_BytesToDlc(const uint8_t bytes) { - uint32_t dlc_index = (dlc >> 16U) & 0x0FU; - - if (dlc <= 8U) { - return (uint8_t)dlc; + switch (bytes) { + case 0U: + return FDCAN_DLC_BYTES_0; + case 1U: + return FDCAN_DLC_BYTES_1; + case 2U: + return FDCAN_DLC_BYTES_2; + case 3U: + return FDCAN_DLC_BYTES_3; + case 4U: + return FDCAN_DLC_BYTES_4; + case 5U: + return FDCAN_DLC_BYTES_5; + case 6U: + return FDCAN_DLC_BYTES_6; + case 7U: + return FDCAN_DLC_BYTES_7; + case 8U: + return FDCAN_DLC_BYTES_8; + case 12U: + return FDCAN_DLC_BYTES_12; + case 16U: + return FDCAN_DLC_BYTES_16; + case 20U: + return FDCAN_DLC_BYTES_20; + case 24U: + return FDCAN_DLC_BYTES_24; + case 32U: + return FDCAN_DLC_BYTES_32; + case 48U: + return FDCAN_DLC_BYTES_48; + case 64U: + return FDCAN_DLC_BYTES_64; + default: + LOGOMATIC("CubeMXCan_Private_BytesToDlc: Invalid byte count\n"); + return FDCAN_DLC_BYTES_0; } +} - if (dlc_index == 0U) { - dlc_index = dlc & 0x0FU; +uint8_t CubeMXCan_Private_DlcToBytes(const uint32_t dlc) +{ + switch (dlc) { + case FDCAN_DLC_BYTES_0: + return 0U; + case FDCAN_DLC_BYTES_1: + return 1U; + case FDCAN_DLC_BYTES_2: + return 2U; + case FDCAN_DLC_BYTES_3: + return 3U; + case FDCAN_DLC_BYTES_4: + return 4U; + case FDCAN_DLC_BYTES_5: + return 5U; + case FDCAN_DLC_BYTES_6: + return 6U; + case FDCAN_DLC_BYTES_7: + return 7U; + case FDCAN_DLC_BYTES_8: + return 8U; + case FDCAN_DLC_BYTES_12: + return 12U; + case FDCAN_DLC_BYTES_16: + return 16U; + case FDCAN_DLC_BYTES_20: + return 20U; + case FDCAN_DLC_BYTES_24: + return 24U; + case FDCAN_DLC_BYTES_32: + return 32U; + case FDCAN_DLC_BYTES_48: + return 48U; + case FDCAN_DLC_BYTES_64: + return 64U; + default: + LOGOMATIC("CubeMXCan_Private_DlcToBytes: Invalid DLC value\n"); + return 0U; } - - static const uint8_t dlc_to_bytes[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64}; - - return (dlc_index > 15U) ? 0U : dlc_to_bytes[dlc_index]; } bool CubeMXCan_Private_IsDisabled(const CubeMXCan_Handle *const handle) @@ -137,7 +203,7 @@ HAL_StatusTypeDef CubeMXCan_Private_RecoverPeripheral(const CubeMXCan_Handle *co status = HAL_FDCAN_Init(handle->hfdcan); if (status == HAL_OK) { - status = HAL_FDCAN_ActivateNotification(handle->hfdcan, rx_events, 0U); + status = HAL_FDCAN_ActivateNotification(handle->hfdcan, FDCAN_IT_RX_EVENTS, 0U); } if (status == HAL_OK) { From 0181bf682b688c85f68ce2122b44ce11e8f1a180 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 31 Jul 2026 06:10:04 -0700 Subject: [PATCH 039/125] Reorganize ownership patterns, finalize api Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 85 ------------------- Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h | 53 +++++++++++- Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h | 52 ------------ .../PrivateInc/internal.h} | 64 +++++++++----- Lib/Peripherals/CubeCAN/Src/can_assert.c | 28 +++--- Lib/Peripherals/CubeCAN/Src/can_global.c | 4 +- Lib/Peripherals/CubeCAN/Src/can_init.c | 3 +- Lib/Peripherals/CubeCAN/Src/can_rx.c | 3 +- Lib/Peripherals/CubeCAN/Src/can_tx.c | 3 +- Lib/Peripherals/CubeCAN/Src/can_utils.c | 3 +- 10 files changed, 117 insertions(+), 181 deletions(-) delete mode 100644 CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c delete mode 100644 Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h rename Lib/Peripherals/CubeCAN/{Inc/Private/PrivateCubeMXCAN.h => Src/PrivateInc/internal.h} (87%) diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c deleted file mode 100644 index d908bd772..000000000 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ /dev/null @@ -1,85 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_msp.c - * @brief This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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*/ - - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); - - /* USER CODE BEGIN MspInit 1 */ - - /* USER CODE END MspInit 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h index efb93091e..b4adc3595 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h @@ -3,13 +3,15 @@ #include #include "CubeCAN_Config.h" -#include "CubeMXCanExt.h" +#include "GRCAN_CUSTOM_ID.h" +#include "GRCAN_MSG_ID.h" +#include "GRCAN_NODE_ID.h" #include "main.h" #ifndef CUBEMX_CAN_H #define CUBEMX_CAN_H -#define FDCAN_MAX_DATA_BYTES 64U +#pragma region Type Definitions /// @brief CAN handle for CubeMX CAN. @warning Do not access directly, use the provided API functions. typedef struct CubeMXCan_Private_Handle CubeMXCan_Handle; @@ -17,6 +19,21 @@ typedef struct CubeMXCan_Private_Handle CubeMXCan_Handle; /// @brief Callback function type for receiving CAN messages. @warning Do not call directly, use the provided API functions. typedef void (*CubeCAN_RxCallback)(const void *const user_context, const CAN_Identifier *const identifier, const uint8_t *const data, const uint8_t size); +/** + * @brief CAN Identifier structure + * + * This structure is used to represent a CAN message identifier, which consists of a transmitting node ID, a receiving node ID, and a message ID. The structure is used in conjunction with the + * Construct_Message_ID and Deconstruct_Message_ID functions to convert between the structure representation and the 32-bit integer representation of the CAN message identifier. + * + * @warning The structure does not represent custom IDs. + * @warning The structure does not represent actual bit depth + */ +typedef struct { + GRCAN_NODE_ID tx_node_id; + GRCAN_NODE_ID rx_node_id; + GRCAN_MSG_ID msg_id; +} CAN_Identifier; + /** * @brief Configuration structure for CubeMX CAN. * @@ -34,6 +51,10 @@ typedef struct { GRCAN_NODE_ID sending_node_id; } CubeCAN_Config; +#pragma endregion + +#pragma region Function Prototypes + /** * @brief Initializes a CubeMX CAN handle with the given FDCAN handle and configuration, and starts the CAN peripheral. * @param hfdcan Pointer to the FDCAN handle. @@ -108,4 +129,32 @@ void CubeMXCan_Tick(void); */ HAL_StatusTypeDef CubeMXCan_Send(CubeMXCan_Handle *const handle, const GRCAN_NODE_ID rx_node, const GRCAN_MSG_ID msg_id, const void *const data, const uint8_t size); +/** + * @brief Constructs a CAN message identifier from the given transmitting node ID, receiving node ID, and message ID. + * + * @param identifier Pointer to the CAN_Identifier structure containing the node and message IDs. + * + * @return The constructed 29-bit CAN message extended identifier. + */ +uint32_t Construct_CAN_Identifier(const CAN_Identifier *const identifier); + +/** + * @brief Deconstructs a 29-bit CAN message extended identifier into its constituent transmitting node ID, receiving node ID, and message ID. + * + * @param message_id The 29-bit CAN message extended identifier to be deconstructed. + * + * @return A CAN_Identifier structure containing the deconstructed node and message IDs. + * + * @warning The function does not guarantee that the returned structure will represent a valid CAN message identifier. + * @warning The function does not support custom IDs. + */ +CAN_Identifier Deconstruct_CAN_Identifier(const uint32_t message_id); + +/** + * @brief Builds an exact-match extended-ID filter for a given CAN identifier. + */ +HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *const identifier, const uint32_t filter_index, const uint32_t fifo, FDCAN_FilterTypeDef *const filter); + +#pragma endregion + #endif diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h b/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h deleted file mode 100644 index 6316e7604..000000000 --- a/Lib/Peripherals/CubeCAN/Inc/CubeMXCanExt.h +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include - -#include "GRCAN_MSG_ID.h" -#include "GRCAN_NODE_ID.h" -#include "main.h" - -#ifndef CUBEMX_CAN_EXT_H -#define CUBEMX_CAN_EXT_H - -/** - * @brief CAN Identifier structure - * - * This structure is used to represent a CAN message identifier, which consists of a transmitting node ID, a receiving node ID, and a message ID. The structure is used in conjunction with the - * Construct_Message_ID and Deconstruct_Message_ID functions to convert between the structure representation and the 32-bit integer representation of the CAN message identifier. - * - * @warning The structure does not represent custom IDs. - * @warning The structure does not represent actual bit depth - */ -typedef struct { - GRCAN_NODE_ID tx_node_id; - GRCAN_NODE_ID rx_node_id; - GRCAN_MSG_ID msg_id; -} CAN_Identifier; - -/** - * @brief Constructs a CAN message identifier from the given transmitting node ID, receiving node ID, and message ID. - * - * @param identifier Pointer to the CAN_Identifier structure containing the node and message IDs. - * - * @return The constructed 29-bit CAN message extended identifier. - */ -uint32_t Construct_CAN_Identifier(const CAN_Identifier *const identifier); - -/** - * @brief Deconstructs a 29-bit CAN message extended identifier into its constituent transmitting node ID, receiving node ID, and message ID. - * - * @param message_id The 29-bit CAN message extended identifier to be deconstructed. - * - * @return A CAN_Identifier structure containing the deconstructed node and message IDs. - * - * @warning The function does not guarantee that the returned structure will represent a valid CAN message identifier. - * @warning The function does not support custom IDs. - */ -CAN_Identifier Deconstruct_CAN_Identifier(const uint32_t message_id); - -/** - * @brief Builds an exact-match extended-ID filter for a given CAN identifier. - */ -HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *const identifier, const uint32_t filter_index, const uint32_t fifo, FDCAN_FilterTypeDef *const filter); - -#endif diff --git a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h b/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h similarity index 87% rename from Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h rename to Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h index 6b56924fd..e0c381632 100644 --- a/Lib/Peripherals/CubeCAN/Inc/Private/PrivateCubeMXCAN.h +++ b/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h @@ -11,6 +11,27 @@ #ifndef PRIVATE_CUBE_MX_CAN_H #define PRIVATE_CUBE_MX_CAN_H +#pragma region Definitions + +/** + * @brief Maximum number of CubeMX CAN instances supported by the library. + * + * This value is determined based on the available FDCAN peripherals in the STM32 microcontroller. + * + * @warning You can override it, but you should only reduce it to a lower value, there is no point to increase it beyond what their is hardware for. + */ +#ifndef CUBEMX_CAN_MAX_INSTANCES +#if (defined(FDCAN3) || defined(CAN3)) && (defined(FDCAN2) || defined(CAN2)) && (defined(FDCAN1) || defined(CAN1)) +#define CUBEMX_CAN_MAX_INSTANCES (3U) +#elif (defined(FDCAN2) || defined(CAN2)) && (defined(FDCAN1) || defined(CAN1)) +#define CUBEMX_CAN_MAX_INSTANCES (2U) +#elif (defined(FDCAN1) || defined(CAN1)) +#define CUBEMX_CAN_MAX_INSTANCES (1U) +#else +#error "No CAN or FDCAN instances defined. Please check your CubeMX configuration." +#endif +#endif + /** * @brief Mask for the transmission queue index, used to wrap around the queue when it reaches its maximum size. * @@ -28,6 +49,17 @@ */ #define FDCAN_IT_RX_EVENTS (FDCAN_IT_RX_FIFO0_NEW_MESSAGE | FDCAN_IT_RX_FIFO0_FULL | FDCAN_IT_RX_FIFO0_MESSAGE_LOST) +/** + * @brief Maximum number of data bytes in an FDCAN message. + * + * This macro defines the maximum number of data bytes that can be included in an FDCAN message. + */ +#define FDCAN_MAX_DATA_BYTES (64U) + +#pragma endregion + +#pragma region Type Definitions + /** * @brief Transmission CAN message structure * @@ -64,25 +96,9 @@ struct CubeMXCan_Private_Handle { bool started; }; -/// @brief Maximum number of CubeMX CAN instances supported by the library. -#ifndef CUBEMX_CAN_MAX_INSTANCES -#if (defined(FDCAN3) || defined(CAN3)) && (defined(FDCAN2) || defined(CAN2)) && (defined(FDCAN1) || defined(CAN1)) -#define CUBEMX_CAN_MAX_INSTANCES 3U -#elif (defined(FDCAN2) || defined(CAN2)) && (defined(FDCAN1) || defined(CAN1)) -#define CUBEMX_CAN_MAX_INSTANCES 2U -#elif (defined(FDCAN1) || defined(CAN1)) -#define CUBEMX_CAN_MAX_INSTANCES 1U -#else -#error "No CAN or FDCAN instances defined. Please check your CubeMX configuration." -#endif -#endif +#pragma endregion -/** - * @brief Sends a queued message from the CubeMX CAN handle. - * @param handle Pointer to the CubeMX CAN handle. - * @return HAL_StatusTypeDef indicating the success or failure of the operation. - */ -HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(const CubeMXCan_Handle *const handle); +#pragma region External Variables /** * @brief Array of CubeMX CAN handles, one for each supported instance. @@ -90,10 +106,16 @@ HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(const CubeMXCan_Handle *co */ extern struct CubeMXCan_Private_Handle handles[CUBEMX_CAN_MAX_INSTANCES]; +#pragma endregion + +#pragma region Function Prototypes + /** - * @brief Flag indicating whether the CubeMX CAN Tx timer has been started. + * @brief Sends a queued message from the CubeMX CAN handle. + * @param handle Pointer to the CubeMX CAN handle. + * @return HAL_StatusTypeDef indicating the success or failure of the operation. */ -extern bool timer_started; +HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(const CubeMXCan_Handle *const handle); /** * @brief Attempts to recover the FDCAN peripheral associated with the given CubeMX CAN handle. @@ -137,4 +159,6 @@ uint8_t CubeMXCan_Private_DlcToBytes(const uint32_t dlc); */ uint8_t CubeMXCan_Private_BytesToDlc(const uint8_t bytes); +#pragma endregion + #endif diff --git a/Lib/Peripherals/CubeCAN/Src/can_assert.c b/Lib/Peripherals/CubeCAN/Src/can_assert.c index 594c6ca4e..379d6df3d 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_assert.c +++ b/Lib/Peripherals/CubeCAN/Src/can_assert.c @@ -6,22 +6,28 @@ #include "CriticalSection.h" #include "CubeCAN_Config.h" #include "CubeMXCan.h" -#include "CubeMXCanExt.h" -#include "Private/PrivateCubeMXCAN.h" +#include "PrivateInc/internal.h" #include "main.h" -static_assert(sizeof(((struct CubeMXCan_Private_Handle *)0)->tx_head) == sizeof(uint32_t), "tx_head must be 32 bits"); -static_assert(sizeof(GRCAN_Private_TxMessage) == (sizeof(FDCAN_TxHeaderTypeDef) + 64), "GRCAN_Private_TxMessage size is incorrect"); +#pragma region Compiler Assertions -static_assert(alignof(GRCAN_Private_TxMessage) >= 4, "GRCAN_Private_TxMessage must have at least 4-byte alignment"); -static_assert(ATOMIC_INT_LOCK_FREE == 2, "ATOMIC_INT_LOCK_FREE must be enabled for atomic operations on tx_head and tx_tail"); +static_assert(sizeof(((struct CubeMXCan_Private_Handle *)0)->tx_head) == sizeof(uint32_t), "CubeMXCan internal tx_head must be 32 bits"); +static_assert(sizeof(((struct CubeMXCan_Private_Handle *)0)->tx_tail) == sizeof(uint32_t), "CubeMXCan internal tx_tail must be 32 bits"); -static_assert((offsetof(struct CubeMXCan_Private_Handle, tx_head) % 4U) == 0U, "The atomic tx_head is unaligned"); -static_assert((offsetof(struct CubeMXCan_Private_Handle, tx_tail) % 4U) == 0U, "The atomic tx_tail is unaligned"); +static_assert(alignof(GRCAN_Private_TxMessage) >= 4, "CubeMXCan internal GRCAN_Private_TxMessage must have at least 4-byte alignment"); +static_assert(alignof(struct CubeMXCan_Private_Handle) >= 4, "CubeMXCan internal CubeMXCan_Private_Handle must have at least 4-byte alignment"); + +static_assert((offsetof(struct CubeMXCan_Private_Handle, tx_head) % 4U) == 0U, "CubeMXCan internal atomic tx_head is unaligned"); +static_assert((offsetof(struct CubeMXCan_Private_Handle, tx_tail) % 4U) == 0U, "CubeMXCan internal atomic tx_tail is unaligned"); + +static_assert(ATOMIC_INT_LOCK_FREE == 2, "CubeMXCan internal ATOMIC_INT_LOCK_FREE must be enabled for atomic operations"); +static_assert(ATOMIC_BOOL_LOCK_FREE == 2, "CubeMXCan internal ATOMIC_BOOL_LOCK_FREE must be enabled for atomic operations"); + +#pragma endregion + +#pragma region Configuration Checks static_assert((CUBEMX_CAN_TX_QUEUE_SIZE > 0) && !(CUBEMX_CAN_TX_QUEUE_SIZE & (CUBEMX_CAN_TX_QUEUE_SIZE - 1U)), "CUBEMX_CAN_TX_QUEUE_SIZE must be a power of two and greater than zero"); static_assert(CUBEMX_CAN_MAX_INSTANCES >= 1 && CUBEMX_CAN_MAX_INSTANCES <= 3, "CUBEMX_CAN_MAX_INSTANCES must be configured between 1 and 3 inclusive"); -#ifndef CUBEMX_SENDING_NODE_ID -#error "CUBEMX_SENDING_NODE_ID must be defined in CubeCAN_Config.h. This is the node ID of the sending device and must be unique on the CAN bus." -#endif +#pragma endregion diff --git a/Lib/Peripherals/CubeCAN/Src/can_global.c b/Lib/Peripherals/CubeCAN/Src/can_global.c index 20b10badf..90921d16c 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_global.c +++ b/Lib/Peripherals/CubeCAN/Src/can_global.c @@ -4,8 +4,6 @@ #include "CriticalSection.h" #include "CubeMXCan.h" -#include "CubeMXCanExt.h" -#include "Private/PrivateCubeMXCAN.h" +#include "PrivateInc/internal.h" struct CubeMXCan_Private_Handle handles[CUBEMX_CAN_MAX_INSTANCES] = {0}; -bool timer_started = false; diff --git a/Lib/Peripherals/CubeCAN/Src/can_init.c b/Lib/Peripherals/CubeCAN/Src/can_init.c index f82cd5a20..053ca8725 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_init.c +++ b/Lib/Peripherals/CubeCAN/Src/can_init.c @@ -5,9 +5,8 @@ #include "CriticalSection.h" #include "CubeMXCan.h" -#include "CubeMXCanExt.h" #include "Logomatic.h" -#include "Private/PrivateCubeMXCAN.h" +#include "PrivateInc/internal.h" #include "main.h" CubeMXCan_Handle *CubeMXCan_OneShotInitStart(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config) diff --git a/Lib/Peripherals/CubeCAN/Src/can_rx.c b/Lib/Peripherals/CubeCAN/Src/can_rx.c index 47f908973..a520b6bac 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_rx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_rx.c @@ -3,9 +3,8 @@ #include "CriticalSection.h" #include "CubeMXCan.h" -#include "CubeMXCanExt.h" #include "Logomatic.h" -#include "Private/PrivateCubeMXCAN.h" +#include "PrivateInc/internal.h" #include "Unused.h" #include "main.h" diff --git a/Lib/Peripherals/CubeCAN/Src/can_tx.c b/Lib/Peripherals/CubeCAN/Src/can_tx.c index 012911a3c..5cf78ae52 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_tx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_tx.c @@ -4,9 +4,8 @@ #include "CriticalSection.h" #include "CubeMXCan.h" -#include "CubeMXCanExt.h" #include "Logomatic.h" -#include "Private/PrivateCubeMXCAN.h" +#include "PrivateInc/internal.h" #include "main.h" void CubeMXCan_Tick(void) diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index 17feaf007..8b66dd76e 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -4,11 +4,10 @@ #include "CriticalSection.h" #include "CubeMXCan.h" -#include "CubeMXCanExt.h" #include "GRCAN_MSG_ID.h" #include "GRCAN_NODE_ID.h" #include "Logomatic.h" -#include "Private/PrivateCubeMXCAN.h" +#include "PrivateInc/internal.h" #define CAN_TX_NODE_SHIFT 20U #define CAN_MSG_SHIFT 8U From af97b1a4ef71e07b14a2c091917d76a524a0aba8 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 31 Jul 2026 06:19:15 -0700 Subject: [PATCH 040/125] Remove tools Signed-off-by: Daniel Hansen --- tools/ConfigureCubeMXPaths.cmake | 220 ----------------------- tools/configure_cubemx_paths.ps1 | 119 ------------- tools/configure_cubemx_paths_linux.sh | 245 -------------------------- tools/configure_cubemx_paths_macos.sh | 245 -------------------------- 4 files changed, 829 deletions(-) delete mode 100644 tools/ConfigureCubeMXPaths.cmake delete mode 100644 tools/configure_cubemx_paths.ps1 delete mode 100644 tools/configure_cubemx_paths_linux.sh delete mode 100644 tools/configure_cubemx_paths_macos.sh diff --git a/tools/ConfigureCubeMXPaths.cmake b/tools/ConfigureCubeMXPaths.cmake deleted file mode 100644 index 767cc4bd9..000000000 --- a/tools/ConfigureCubeMXPaths.cmake +++ /dev/null @@ -1,220 +0,0 @@ -# ConfigureCubeMXPaths.cmake -# -# Cross-platform STM32CubeMX template path configuration. -# -# Expected repository layout: -# -# Firmware/ -# ├── tools/ -# │ └── ConfigureCubeMXPaths.cmake -# ├── CUBEMXTESTING/ -# │ └── CUBEMXTESTING.ioc -# └── Lib/ -# └── CubeMXTemplates/ -# └── Autogen/ -# └── Inc/ -# └── can_cfg_h.ftl -# -# Run manually from the repository root: -# -# cmake -P tools/ConfigureCubeMXPaths.cmake -# -# Optional overrides: -# -# cmake -# -DIOC_FILE=/path/to/project.ioc -# -DTEMPLATE_ROOT=/path/to/CubeMXTemplates -# -DPROJECT_OUTPUT_DIR=/path/to/project -# -P tools/ConfigureCubeMXPaths.cmake -# -# This script writes absolute paths because STM32CubeMX does not reliably -# resolve relative custom-template paths. - -cmake_minimum_required(VERSION 3.20) - -# --------------------------------------------------------------------------- -# Locate repository and default paths -# --------------------------------------------------------------------------- - -get_filename_component(SCRIPT_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY) -get_filename_component(REPOSITORY_ROOT "${SCRIPT_DIR}/.." ABSOLUTE) - -if(NOT DEFINED IOC_FILE) - set(IOC_FILE - "${REPOSITORY_ROOT}/CUBEMXTESTING/CUBEMXTESTING.ioc" - ) -endif() - -if(NOT DEFINED PROJECT_OUTPUT_DIR) - set(PROJECT_OUTPUT_DIR - "${REPOSITORY_ROOT}/CUBEMXTESTING" - ) -endif() - -if(NOT DEFINED TEMPLATE_ROOT) - set(TEMPLATE_ROOT - "${REPOSITORY_ROOT}/Lib/CubeMXTemplates" - ) -endif() - -set(TEMPLATE_RELATIVE_PATH - "Autogen/Inc/can_cfg_h.ftl" -) - -get_filename_component(IOC_FILE "${IOC_FILE}" ABSOLUTE) -get_filename_component(PROJECT_OUTPUT_DIR "${PROJECT_OUTPUT_DIR}" ABSOLUTE) -get_filename_component(TEMPLATE_ROOT "${TEMPLATE_ROOT}" ABSOLUTE) - -set(TEMPLATE_FILE - "${TEMPLATE_ROOT}/${TEMPLATE_RELATIVE_PATH}" -) - -# --------------------------------------------------------------------------- -# Validate inputs -# --------------------------------------------------------------------------- - -if(NOT EXISTS "${IOC_FILE}") - message(FATAL_ERROR - "CubeMX .ioc file was not found:\n" - " ${IOC_FILE}" - ) -endif() - -if(NOT IS_DIRECTORY "${PROJECT_OUTPUT_DIR}") - message(FATAL_ERROR - "CubeMX project output directory was not found:\n" - " ${PROJECT_OUTPUT_DIR}" - ) -endif() - -if(NOT IS_DIRECTORY "${TEMPLATE_ROOT}") - message(FATAL_ERROR - "CubeMX template root was not found:\n" - " ${TEMPLATE_ROOT}" - ) -endif() - -if(NOT EXISTS "${TEMPLATE_FILE}") - message(FATAL_ERROR - "CubeMX FreeMarker template was not found:\n" - " ${TEMPLATE_FILE}" - ) -endif() - -# --------------------------------------------------------------------------- -# Convert paths to the format expected by CubeMX's .ioc property file -# --------------------------------------------------------------------------- - -function(convert_to_cubemx_path INPUT_PATH OUTPUT_VARIABLE) - if(WIN32) - # Convert: - # C:/Users/name/Firmware - # to: - # C\:\\Users\\name\\Firmware - file(TO_NATIVE_PATH "${INPUT_PATH}" NATIVE_PATH) - string(REPLACE "\\" "\\\\" ESCAPED_PATH "${NATIVE_PATH}") - string(REPLACE ":" "\\:" ESCAPED_PATH "${ESCAPED_PATH}") - else() - # macOS/Linux paths use forward slashes and require no drive-letter - # escaping. - file(TO_CMAKE_PATH "${INPUT_PATH}" ESCAPED_PATH) - endif() - - set("${OUTPUT_VARIABLE}" "${ESCAPED_PATH}" PARENT_SCOPE) -endfunction() - -convert_to_cubemx_path( - "${PROJECT_OUTPUT_DIR}" - CUBEMX_PROJECT_OUTPUT_DIR -) - -convert_to_cubemx_path( - "${TEMPLATE_ROOT}" - CUBEMX_TEMPLATE_ROOT -) - -if(WIN32) - set(CUBEMX_TEMPLATE_LIST - "\\\\Autogen\\\\Inc\\\\can_cfg_h.ftl," - ) -else() - set(CUBEMX_TEMPLATE_LIST - "/Autogen/Inc/can_cfg_h.ftl," - ) -endif() - -set(DESTINATION_LINE - "ProjectManager.TemplateDestinationPath=${CUBEMX_PROJECT_OUTPUT_DIR}" -) - -set(SOURCE_LINE - "ProjectManager.TemplateSourcePath=${CUBEMX_TEMPLATE_ROOT}" -) - -set(TEMPLATES_LINE - "ProjectManager.TemplatesList=${CUBEMX_TEMPLATE_LIST}" -) - -# --------------------------------------------------------------------------- -# Rewrite or add the three CubeMX settings -# --------------------------------------------------------------------------- - -file(STRINGS "${IOC_FILE}" IOC_LINES ENCODING UTF-8) - -set(UPDATED_CONTENT "") -set(FOUND_DESTINATION FALSE) -set(FOUND_SOURCE FALSE) -set(FOUND_TEMPLATES FALSE) - -foreach(LINE IN LISTS IOC_LINES) - if(LINE MATCHES "^ProjectManager\\.TemplateDestinationPath=") - string(APPEND UPDATED_CONTENT "${DESTINATION_LINE}\n") - set(FOUND_DESTINATION TRUE) - - elseif(LINE MATCHES "^ProjectManager\\.TemplateSourcePath=") - string(APPEND UPDATED_CONTENT "${SOURCE_LINE}\n") - set(FOUND_SOURCE TRUE) - - elseif(LINE MATCHES "^ProjectManager\\.TemplatesList=") - string(APPEND UPDATED_CONTENT "${TEMPLATES_LINE}\n") - set(FOUND_TEMPLATES TRUE) - - else() - string(APPEND UPDATED_CONTENT "${LINE}\n") - endif() -endforeach() - -if(NOT FOUND_DESTINATION) - string(APPEND UPDATED_CONTENT "${DESTINATION_LINE}\n") -endif() - -if(NOT FOUND_SOURCE) - string(APPEND UPDATED_CONTENT "${SOURCE_LINE}\n") -endif() - -if(NOT FOUND_TEMPLATES) - string(APPEND UPDATED_CONTENT "${TEMPLATES_LINE}\n") -endif() - -# Keep a backup of the current .ioc file before modifying it. -configure_file( - "${IOC_FILE}" - "${IOC_FILE}.bak" - COPYONLY -) - -file(WRITE "${IOC_FILE}" "${UPDATED_CONTENT}") - -# --------------------------------------------------------------------------- -# Report result -# --------------------------------------------------------------------------- - -message(STATUS "") -message(STATUS "CubeMX template configuration updated successfully.") -message(STATUS "") -message(STATUS "${DESTINATION_LINE}") -message(STATUS "${SOURCE_LINE}") -message(STATUS "${TEMPLATES_LINE}") -message(STATUS "") -message(STATUS "Backup created at:") -message(STATUS " ${IOC_FILE}.bak") diff --git a/tools/configure_cubemx_paths.ps1 b/tools/configure_cubemx_paths.ps1 deleted file mode 100644 index 4144b2eba..000000000 --- a/tools/configure_cubemx_paths.ps1 +++ /dev/null @@ -1,119 +0,0 @@ -# configure_cubemx_paths.ps1 -# Updates STM32CubeMX template paths using the current repository location. -# -# Expected repository structure: -# Firmware/ -# ├── tools/configure_cubemx_paths.ps1 -# ├── CUBEMXTESTING/CUBEMXTESTING.ioc -# └── Lib/CubeMXTemplates/Autogen/Inc/can_cfg_h.ftl - -$ErrorActionPreference = "Stop" - -# Script location: Firmware/tools -$toolsDirectory = Split-Path -Parent $MyInvocation.MyCommand.Path - -# Repository root: Firmware -$repoRoot = Split-Path -Parent $toolsDirectory - -$iocPath = Join-Path $repoRoot "CUBEMXTESTING\CUBEMXTESTING.ioc" -$projectPath = Join-Path $repoRoot "CUBEMXTESTING" -$templatePath = Join-Path $repoRoot "Lib\CubeMXTemplates" - -if (!(Test-Path -LiteralPath $iocPath)) { - Write-Error "Could not find CubeMX project file: $iocPath" - exit 1 -} - -if (!(Test-Path -LiteralPath $templatePath)) { - Write-Error "Could not find CubeMX template folder: $templatePath" - exit 1 -} - -$templateFile = Join-Path $templatePath "Autogen\Inc\can_cfg_h.ftl" -if (!(Test-Path -LiteralPath $templateFile)) { - Write-Error "Could not find CubeMX template file: $templateFile" - exit 1 -} - -# CubeMX .ioc escaping: -# C:\Users\... becomes C\:\\Users\\... -function Convert-ToCubeMXPath { - param( - [Parameter(Mandatory = $true)] - [string]$Path - ) - - return $Path.Replace("\", "\\").Replace(":", "\:") -} - -$escapedProjectPath = Convert-ToCubeMXPath -Path $projectPath -$escapedTemplatePath = Convert-ToCubeMXPath -Path $templatePath - -$desiredDestinationLine = "ProjectManager.TemplateDestinationPath=$escapedProjectPath" -$desiredSourceLine = "ProjectManager.TemplateSourcePath=$escapedTemplatePath" - -# CubeMX expects a leading escaped backslash and a trailing comma here. -$desiredTemplatesLine = "ProjectManager.TemplatesList=\\Autogen\\Inc\\can_cfg_h.ftl," - -$content = Get-Content -LiteralPath $iocPath - -function Set-OrAddLine { - param( - [Parameter(Mandatory = $true)] - [string[]]$Content, - - [Parameter(Mandatory = $true)] - [string]$Key, - - [Parameter(Mandatory = $true)] - [string]$Replacement - ) - - $pattern = "^" + [regex]::Escape($Key) + "=.*$" - $found = $false - - $updated = foreach ($line in $Content) { - if ($line -match $pattern) { - $found = $true - $Replacement - } - else { - $line - } - } - - if (!$found) { - $updated += $Replacement - } - - return ,$updated -} - -$content = Set-OrAddLine ` - -Content $content ` - -Key "ProjectManager.TemplateDestinationPath" ` - -Replacement $desiredDestinationLine - -$content = Set-OrAddLine ` - -Content $content ` - -Key "ProjectManager.TemplateSourcePath" ` - -Replacement $desiredSourceLine - -$content = Set-OrAddLine ` - -Content $content ` - -Key "ProjectManager.TemplatesList" ` - -Replacement $desiredTemplatesLine - -# Preserve a normal text encoding without adding a UTF-8 BOM. -[System.IO.File]::WriteAllLines( - $iocPath, - $content, - [System.Text.UTF8Encoding]::new($false) -) - -Write-Host "" -Write-Host "CubeMX template configuration updated successfully." -Write-Host "" -Write-Host $desiredDestinationLine -Write-Host $desiredSourceLine -Write-Host $desiredTemplatesLine \ No newline at end of file diff --git a/tools/configure_cubemx_paths_linux.sh b/tools/configure_cubemx_paths_linux.sh deleted file mode 100644 index fda034ba7..000000000 --- a/tools/configure_cubemx_paths_linux.sh +++ /dev/null @@ -1,245 +0,0 @@ -#!/usr/bin/env bash -# -# Cross-platform Unix STM32CubeMX custom-template path configurator. -# Compatible with macOS Bash 3.2+ and common Linux Bash versions. -# -# Expected repository structure: -# -# Firmware/ -# ├── tools/ -# │ └── configure_cubemx_paths_linux.sh -# ├── CUBEMXTESTING/ -# │ └── CUBEMXTESTING.ioc -# └── Lib/ -# └── CubeMXTemplates/ -# └── Autogen/ -# └── Inc/ -# └── can_cfg_h.ftl -# -# Usage: -# bash tools/configure_cubemx_paths_linux.sh -# -# Optional overrides: -# IOC_FILE=/path/project.ioc \ -# PROJECT_OUTPUT_DIR=/path/project \ -# TEMPLATE_ROOT=/path/CubeMXTemplates \ -# bash tools/configure_cubemx_paths_linux.sh -# -# Behavior: -# - validates all expected paths; -# - removes stale or duplicate CubeMX template properties; -# - writes exactly one correct copy of each property; -# - creates an .ioc.bak backup; -# - writes through a temporary file; -# - verifies the result from disk; -# - is idempotent. - -set -euo pipefail - -EXPECTED_OS="linux" - -die() { - printf 'ERROR: %s\n' "$*" >&2 - exit 1 -} - -info() { - printf '%s\n' "$*" -} - -detect_os() { - case "$(uname -s)" in - Darwin) printf '%s\n' "macos" ;; - Linux) printf '%s\n' "linux" ;; - *) printf '%s\n' "unsupported" ;; - esac -} - -CURRENT_OS="$(detect_os)" -if [ "$CURRENT_OS" != "$EXPECTED_OS" ]; then - die "This script is intended for $EXPECTED_OS, but detected $CURRENT_OS." -fi - -# Resolve the physical directory containing this script without requiring -# realpath, which is not included with older macOS installations. -SCRIPT_DIR="$( - CDPATH= cd -- "$(dirname -- "$0")" >/dev/null 2>&1 - pwd -P -)" -REPOSITORY_ROOT="$( - CDPATH= cd -- "$SCRIPT_DIR/.." >/dev/null 2>&1 - pwd -P -)" - -IOC_FILE="${IOC_FILE:-$REPOSITORY_ROOT/CUBEMXTESTING/CUBEMXTESTING.ioc}" -PROJECT_OUTPUT_DIR="${PROJECT_OUTPUT_DIR:-$REPOSITORY_ROOT/CUBEMXTESTING}" -TEMPLATE_ROOT="${TEMPLATE_ROOT:-$REPOSITORY_ROOT/Lib/CubeMXTemplates}" -TEMPLATE_FILE="$TEMPLATE_ROOT/Autogen/Inc/can_cfg_h.ftl" - -[ -f "$IOC_FILE" ] || - die "CubeMX .ioc file was not found: $IOC_FILE" - -[ -d "$PROJECT_OUTPUT_DIR" ] || - die "CubeMX project output directory was not found: $PROJECT_OUTPUT_DIR" - -[ -d "$TEMPLATE_ROOT" ] || - die "CubeMX template root was not found: $TEMPLATE_ROOT" - -[ -f "$TEMPLATE_FILE" ] || - die "CubeMX FreeMarker template was not found: $TEMPLATE_FILE" - -# Convert directories to physical absolute paths. -PROJECT_OUTPUT_DIR="$( - CDPATH= cd -- "$PROJECT_OUTPUT_DIR" >/dev/null 2>&1 - pwd -P -)" -TEMPLATE_ROOT="$( - CDPATH= cd -- "$TEMPLATE_ROOT" >/dev/null 2>&1 - pwd -P -)" - -DESTINATION_KEY='ProjectManager.TemplateDestinationPath' -SOURCE_KEY='ProjectManager.TemplateSourcePath' -TEMPLATES_KEY='ProjectManager.TemplatesList' - -DESTINATION_LINE="${DESTINATION_KEY}=${PROJECT_OUTPUT_DIR}" -SOURCE_LINE="${SOURCE_KEY}=${TEMPLATE_ROOT}" -TEMPLATES_LINE="${TEMPLATES_KEY}=/Autogen/Inc/can_cfg_h.ftl," - -IOC_DIRECTORY="$(dirname -- "$IOC_FILE")" -IOC_BASENAME="$(basename -- "$IOC_FILE")" -BACKUP_FILE="${IOC_FILE}.bak" -TEMP_FILE="$(mktemp "${IOC_DIRECTORY}/.${IOC_BASENAME}.tmp.XXXXXX")" - -cleanup() { - if [ -n "${TEMP_FILE:-}" ] && [ -f "$TEMP_FILE" ]; then - rm -f -- "$TEMP_FILE" - fi -} -trap cleanup EXIT HUP INT TERM - -# Back up the current file before any modification. -cp -p -- "$IOC_FILE" "$BACKUP_FILE" - -# Remove every existing copy of the three properties and append one stable, -# complete block. awk preserves all unrelated lines verbatim at the text level, -# including semicolons and similarly named properties. -awk \ - -v destination_key="$DESTINATION_KEY" \ - -v source_key="$SOURCE_KEY" \ - -v templates_key="$TEMPLATES_KEY" \ - -v destination_line="$DESTINATION_LINE" \ - -v source_line="$SOURCE_LINE" \ - -v templates_line="$TEMPLATES_LINE" ' -BEGIN { - destination_prefix = destination_key "=" - source_prefix = source_key "=" - templates_prefix = templates_key "=" -} -{ - # Remove a possible CR from CRLF input so Unix output is consistently LF. - sub(/\r$/, "", $0) - - if (index($0, destination_prefix) == 1) { - next - } - - if (index($0, source_prefix) == 1) { - next - } - - if (index($0, templates_prefix) == 1) { - next - } - - lines[++count] = $0 -} -END { - # Remove trailing blank lines before appending the generated block. - while (count > 0 && lines[count] == "") { - count-- - } - - for (i = 1; i <= count; i++) { - print lines[i] - } - - if (count > 0) { - print "" - } - - print destination_line - print source_line - print templates_line -} -' "$IOC_FILE" > "$TEMP_FILE" - -[ -s "$TEMP_FILE" ] || - die "Generated temporary .ioc file is empty: $TEMP_FILE" - -verify_exact_line_once() { - expected_line="$1" - description="$2" - - # grep -F treats the path as literal text. -x requires the full line. - count="$( - grep -Fxc -- "$expected_line" "$TEMP_FILE" 2>/dev/null || true - )" - - [ "$count" -eq 1 ] || - die "$description verification failed; expected exactly once, found $count." -} - -verify_key_once() { - key="$1" - description="$2" - - count="$( - awk -v prefix="${key}=" ' - index($0, prefix) == 1 { count++ } - END { print count + 0 } - ' "$TEMP_FILE" - )" - - [ "$count" -eq 1 ] || - die "$description key verification failed; expected exactly one property, found $count." -} - -verify_key_once "$DESTINATION_KEY" "Destination path" -verify_key_once "$SOURCE_KEY" "Source path" -verify_key_once "$TEMPLATES_KEY" "Template list" - -verify_exact_line_once "$DESTINATION_LINE" "Destination path" -verify_exact_line_once "$SOURCE_LINE" "Source path" -verify_exact_line_once "$TEMPLATES_LINE" "Template list" - -# Replace the original only after all temporary-file checks pass. -mv -f -- "$TEMP_FILE" "$IOC_FILE" -TEMP_FILE="" - -# Verify the file again after it has been moved into place. -verify_disk_line_once() { - expected_line="$1" - description="$2" - - count="$( - grep -Fxc -- "$expected_line" "$IOC_FILE" 2>/dev/null || true - )" - - [ "$count" -eq 1 ] || - die "Post-write $description verification failed; found $count copies." -} - -verify_disk_line_once "$DESTINATION_LINE" "destination path" -verify_disk_line_once "$SOURCE_LINE" "source path" -verify_disk_line_once "$TEMPLATES_LINE" "template list" - -info "" -info "CubeMX template configuration updated and verified." -info "" -info "$DESTINATION_LINE" -info "$SOURCE_LINE" -info "$TEMPLATES_LINE" -info "" -info "Backup:" -info " $BACKUP_FILE" diff --git a/tools/configure_cubemx_paths_macos.sh b/tools/configure_cubemx_paths_macos.sh deleted file mode 100644 index f7c0bafde..000000000 --- a/tools/configure_cubemx_paths_macos.sh +++ /dev/null @@ -1,245 +0,0 @@ -#!/usr/bin/env bash -# -# Cross-platform Unix STM32CubeMX custom-template path configurator. -# Compatible with macOS Bash 3.2+ and common Linux Bash versions. -# -# Expected repository structure: -# -# Firmware/ -# ├── tools/ -# │ └── configure_cubemx_paths_macos.sh -# ├── CUBEMXTESTING/ -# │ └── CUBEMXTESTING.ioc -# └── Lib/ -# └── CubeMXTemplates/ -# └── Autogen/ -# └── Inc/ -# └── can_cfg_h.ftl -# -# Usage: -# bash tools/configure_cubemx_paths_macos.sh -# -# Optional overrides: -# IOC_FILE=/path/project.ioc \ -# PROJECT_OUTPUT_DIR=/path/project \ -# TEMPLATE_ROOT=/path/CubeMXTemplates \ -# bash tools/configure_cubemx_paths_macos.sh -# -# Behavior: -# - validates all expected paths; -# - removes stale or duplicate CubeMX template properties; -# - writes exactly one correct copy of each property; -# - creates an .ioc.bak backup; -# - writes through a temporary file; -# - verifies the result from disk; -# - is idempotent. - -set -euo pipefail - -EXPECTED_OS="macos" - -die() { - printf 'ERROR: %s\n' "$*" >&2 - exit 1 -} - -info() { - printf '%s\n' "$*" -} - -detect_os() { - case "$(uname -s)" in - Darwin) printf '%s\n' "macos" ;; - Linux) printf '%s\n' "linux" ;; - *) printf '%s\n' "unsupported" ;; - esac -} - -CURRENT_OS="$(detect_os)" -if [ "$CURRENT_OS" != "$EXPECTED_OS" ]; then - die "This script is intended for $EXPECTED_OS, but detected $CURRENT_OS." -fi - -# Resolve the physical directory containing this script without requiring -# realpath, which is not included with older macOS installations. -SCRIPT_DIR="$( - CDPATH= cd -- "$(dirname -- "$0")" >/dev/null 2>&1 - pwd -P -)" -REPOSITORY_ROOT="$( - CDPATH= cd -- "$SCRIPT_DIR/.." >/dev/null 2>&1 - pwd -P -)" - -IOC_FILE="${IOC_FILE:-$REPOSITORY_ROOT/CUBEMXTESTING/CUBEMXTESTING.ioc}" -PROJECT_OUTPUT_DIR="${PROJECT_OUTPUT_DIR:-$REPOSITORY_ROOT/CUBEMXTESTING}" -TEMPLATE_ROOT="${TEMPLATE_ROOT:-$REPOSITORY_ROOT/Lib/CubeMXTemplates}" -TEMPLATE_FILE="$TEMPLATE_ROOT/Autogen/Inc/can_cfg_h.ftl" - -[ -f "$IOC_FILE" ] || - die "CubeMX .ioc file was not found: $IOC_FILE" - -[ -d "$PROJECT_OUTPUT_DIR" ] || - die "CubeMX project output directory was not found: $PROJECT_OUTPUT_DIR" - -[ -d "$TEMPLATE_ROOT" ] || - die "CubeMX template root was not found: $TEMPLATE_ROOT" - -[ -f "$TEMPLATE_FILE" ] || - die "CubeMX FreeMarker template was not found: $TEMPLATE_FILE" - -# Convert directories to physical absolute paths. -PROJECT_OUTPUT_DIR="$( - CDPATH= cd -- "$PROJECT_OUTPUT_DIR" >/dev/null 2>&1 - pwd -P -)" -TEMPLATE_ROOT="$( - CDPATH= cd -- "$TEMPLATE_ROOT" >/dev/null 2>&1 - pwd -P -)" - -DESTINATION_KEY='ProjectManager.TemplateDestinationPath' -SOURCE_KEY='ProjectManager.TemplateSourcePath' -TEMPLATES_KEY='ProjectManager.TemplatesList' - -DESTINATION_LINE="${DESTINATION_KEY}=${PROJECT_OUTPUT_DIR}" -SOURCE_LINE="${SOURCE_KEY}=${TEMPLATE_ROOT}" -TEMPLATES_LINE="${TEMPLATES_KEY}=/Autogen/Inc/can_cfg_h.ftl," - -IOC_DIRECTORY="$(dirname -- "$IOC_FILE")" -IOC_BASENAME="$(basename -- "$IOC_FILE")" -BACKUP_FILE="${IOC_FILE}.bak" -TEMP_FILE="$(mktemp "${IOC_DIRECTORY}/.${IOC_BASENAME}.tmp.XXXXXX")" - -cleanup() { - if [ -n "${TEMP_FILE:-}" ] && [ -f "$TEMP_FILE" ]; then - rm -f -- "$TEMP_FILE" - fi -} -trap cleanup EXIT HUP INT TERM - -# Back up the current file before any modification. -cp -p -- "$IOC_FILE" "$BACKUP_FILE" - -# Remove every existing copy of the three properties and append one stable, -# complete block. awk preserves all unrelated lines verbatim at the text level, -# including semicolons and similarly named properties. -awk \ - -v destination_key="$DESTINATION_KEY" \ - -v source_key="$SOURCE_KEY" \ - -v templates_key="$TEMPLATES_KEY" \ - -v destination_line="$DESTINATION_LINE" \ - -v source_line="$SOURCE_LINE" \ - -v templates_line="$TEMPLATES_LINE" ' -BEGIN { - destination_prefix = destination_key "=" - source_prefix = source_key "=" - templates_prefix = templates_key "=" -} -{ - # Remove a possible CR from CRLF input so Unix output is consistently LF. - sub(/\r$/, "", $0) - - if (index($0, destination_prefix) == 1) { - next - } - - if (index($0, source_prefix) == 1) { - next - } - - if (index($0, templates_prefix) == 1) { - next - } - - lines[++count] = $0 -} -END { - # Remove trailing blank lines before appending the generated block. - while (count > 0 && lines[count] == "") { - count-- - } - - for (i = 1; i <= count; i++) { - print lines[i] - } - - if (count > 0) { - print "" - } - - print destination_line - print source_line - print templates_line -} -' "$IOC_FILE" > "$TEMP_FILE" - -[ -s "$TEMP_FILE" ] || - die "Generated temporary .ioc file is empty: $TEMP_FILE" - -verify_exact_line_once() { - expected_line="$1" - description="$2" - - # grep -F treats the path as literal text. -x requires the full line. - count="$( - grep -Fxc -- "$expected_line" "$TEMP_FILE" 2>/dev/null || true - )" - - [ "$count" -eq 1 ] || - die "$description verification failed; expected exactly once, found $count." -} - -verify_key_once() { - key="$1" - description="$2" - - count="$( - awk -v prefix="${key}=" ' - index($0, prefix) == 1 { count++ } - END { print count + 0 } - ' "$TEMP_FILE" - )" - - [ "$count" -eq 1 ] || - die "$description key verification failed; expected exactly one property, found $count." -} - -verify_key_once "$DESTINATION_KEY" "Destination path" -verify_key_once "$SOURCE_KEY" "Source path" -verify_key_once "$TEMPLATES_KEY" "Template list" - -verify_exact_line_once "$DESTINATION_LINE" "Destination path" -verify_exact_line_once "$SOURCE_LINE" "Source path" -verify_exact_line_once "$TEMPLATES_LINE" "Template list" - -# Replace the original only after all temporary-file checks pass. -mv -f -- "$TEMP_FILE" "$IOC_FILE" -TEMP_FILE="" - -# Verify the file again after it has been moved into place. -verify_disk_line_once() { - expected_line="$1" - description="$2" - - count="$( - grep -Fxc -- "$expected_line" "$IOC_FILE" 2>/dev/null || true - )" - - [ "$count" -eq 1 ] || - die "Post-write $description verification failed; found $count copies." -} - -verify_disk_line_once "$DESTINATION_LINE" "destination path" -verify_disk_line_once "$SOURCE_LINE" "source path" -verify_disk_line_once "$TEMPLATES_LINE" "template list" - -info "" -info "CubeMX template configuration updated and verified." -info "" -info "$DESTINATION_LINE" -info "$SOURCE_LINE" -info "$TEMPLATES_LINE" -info "" -info "Backup:" -info " $BACKUP_FILE" From b2a275f7e23ba5fc33d1d57598ca67cfc09c522d Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 31 Jul 2026 06:19:37 -0700 Subject: [PATCH 041/125] Peripheral schema rename Signed-off-by: Daniel Hansen --- CMakeLists.txt | 2 +- CUBEMXTESTING/Application/Inc/CANdler.h | 4 +- .../Application/Inc/CubeCAN_Config.h | 4 +- CUBEMXTESTING/Application/Src/CANdler.c | 6 +- CUBEMXTESTING/CMakeLists.txt | 1 + CUBEMXTESTING/Core/Src/main.c | 9 +- .../CubeCAN/Inc/{CubeMXCan.h => CubeCAN.h} | 89 ++++++++++--------- .../CubeCAN/Src/PrivateInc/internal.h | 66 ++++++-------- Lib/Peripherals/CubeCAN/Src/can_assert.c | 26 ++---- Lib/Peripherals/CubeCAN/Src/can_global.c | 4 +- Lib/Peripherals/CubeCAN/Src/can_init.c | 44 ++++----- Lib/Peripherals/CubeCAN/Src/can_rx.c | 4 +- Lib/Peripherals/CubeCAN/Src/can_tx.c | 36 ++++---- Lib/Peripherals/CubeCAN/Src/can_utils.c | 24 ++--- .../{cubemx_can.cmake => cube_can.cmake} | 0 15 files changed, 148 insertions(+), 171 deletions(-) rename Lib/Peripherals/CubeCAN/Inc/{CubeMXCan.h => CubeCAN.h} (55%) rename Lib/Peripherals/CubeCAN/{cubemx_can.cmake => cube_can.cmake} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 86537662b..46b377ddb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,7 +142,7 @@ include("Autogen/CAN/CANfigurator.cmake") include("${lib_path}/Peripherals/USART/common.cmake") include("${lib_path}/Peripherals/TimedCAN/common.cmake") include("${lib_path}/Peripherals/CAN/common.cmake") -include("${lib_path}/Peripherals/CubeCAN/cubemx_can.cmake") +include("${lib_path}/Peripherals/CubeCAN/cube_can.cmake") include("${lib_path}/FancyLayers-RENAME/GRCAN/grcan_fancylayer.cmake") include("${lib_path}/FancyLayers-RENAME/ADC/adc.cmake") diff --git a/CUBEMXTESTING/Application/Inc/CANdler.h b/CUBEMXTESTING/Application/Inc/CANdler.h index 64739c684..bd67e5959 100644 --- a/CUBEMXTESTING/Application/Inc/CANdler.h +++ b/CUBEMXTESTING/Application/Inc/CANdler.h @@ -1,8 +1,8 @@ -#include "CubeMXCan.h" +#include "CubeCAN.h" #ifndef CANDLER_H #define CANDLER_H -void CANdler_Callback(CubeMXCan_Handle *const handle, void *const user_ctx); +void CANdler_Callback(CubeCAN_Handle *const handle, void *const user_context); #endif diff --git a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h index bd5e39a5a..db74ce3b5 100644 --- a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h +++ b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h @@ -1,10 +1,10 @@ #ifndef CUBE_CAN_CONFIG_H #define CUBE_CAN_CONFIG_H -// TODO Add a template to the library - +#include "GRCAN_NODE_ID.h" #include "main.h" #define CUBEMX_CAN_TX_QUEUE_SIZE 32U +#define CUBEMX_SENDING_NODE_ID GRCAN_ECU #endif diff --git a/CUBEMXTESTING/Application/Src/CANdler.c b/CUBEMXTESTING/Application/Src/CANdler.c index cfae5c588..524b95617 100644 --- a/CUBEMXTESTING/Application/Src/CANdler.c +++ b/CUBEMXTESTING/Application/Src/CANdler.c @@ -1,9 +1,9 @@ #include "CANdler.h" -#include "CubeMXCan.h" +#include "CubeCAN.h" -void CANdler_Callback(CubeMXCan_Handle *const handle, void *const user_ctx) +void CANdler_Callback(CubeCAN_Handle *const handle, void *const user_context) { - LOGOMATIC("CANdler_Callback: Received CAN message on handle %p with user context %p\n", (void *)handle, user_ctx); + LOGOMATIC("CANdler_Callback: Received CAN message on handle %p with user context %p\n", (void *)handle, user_context); // TODO } diff --git a/CUBEMXTESTING/CMakeLists.txt b/CUBEMXTESTING/CMakeLists.txt index c8fcc8050..81566a37d 100644 --- a/CUBEMXTESTING/CMakeLists.txt +++ b/CUBEMXTESTING/CMakeLists.txt @@ -31,6 +31,7 @@ target_sources( Core/Src/gpio.c Core/Src/main.c Core/Src/stm32g4xx_it.c + Core/Src/tim.c ) target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE VCP_LIB CUBEMX_CAN_LIB LOGOMATIC_LIB) diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 9f6e59804..ab6643b56 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -26,8 +26,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "CANdler.h" -#include "CubeMXCan.h" -#include "CubeMXCanExt.h" +#include "CubeCAN.h" #include "Logomatic.h" #include "loop.h" #include "tim.h" @@ -132,9 +131,9 @@ int main(void) Logomatic_Init(&logomaticConfig); VCP_Init(&vcp_config); - CubeCAN_Config can_config = {.rx_callback = CANdler_Callback, .user_ctx = (void *)1}; + CubeCAN_Config can_config = {.rx_callback = CANdler_Callback, .user_context = (void *)1}; - CubeMXCan_Init(&hfdcan1, &can_config); + CubeCAN_Init(&hfdcan1, &can_config); /* USER CODE END 2 */ /* Infinite loop */ @@ -199,7 +198,7 @@ void SystemClock_Config(void) void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { if (htim == &CAN_TIMER_HANDLE) { - CubeMXCan_Tick(); + CubeCAN_Tick(); } } diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h b/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h similarity index 55% rename from Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h rename to Lib/Peripherals/CubeCAN/Inc/CubeCAN.h index b4adc3595..9b0eddd6e 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeMXCan.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h @@ -11,13 +11,11 @@ #ifndef CUBEMX_CAN_H #define CUBEMX_CAN_H -#pragma region Type Definitions - -/// @brief CAN handle for CubeMX CAN. @warning Do not access directly, use the provided API functions. -typedef struct CubeMXCan_Private_Handle CubeMXCan_Handle; - -/// @brief Callback function type for receiving CAN messages. @warning Do not call directly, use the provided API functions. -typedef void (*CubeCAN_RxCallback)(const void *const user_context, const CAN_Identifier *const identifier, const uint8_t *const data, const uint8_t size); +/** + * @brief CAN handle for CubeCAN CAN. + * @warning Do not access directly, use the provided API functions. + */ +typedef struct CubeCAN_Private_Handle CubeCAN_Handle; /** * @brief CAN Identifier structure @@ -35,9 +33,18 @@ typedef struct { } CAN_Identifier; /** - * @brief Configuration structure for CubeMX CAN. + * @brief Callback function type for receiving CAN messages. * - * This structure is used to configure the CubeMX CAN handle, including the receive callback function and user context. The receive callback function is called when a CAN message is received, and the + * @warning The callback function should not perform blocking operations or take too long to execute. + * @warning The callback function should not call any CubeCAN functions, as it may lead to undefined behavior. + * @warning It is the responsibility of the callback function to verify the integrity of the received data and handle any errors or null inputs. + */ +typedef void (*CubeCAN_RxCallback)(const void *const user_context, const CAN_Identifier *const identifier, const uint8_t *const data, const uint8_t size); + +/** + * @brief Configuration structure for CubeCAN CAN. + * + * This structure is used to configure the CubeCAN CAN handle, including the receive callback function and user context. The receive callback function is called when a CAN message is received, and the * user context is a pointer to user-defined data that can be passed to the callback function. * * @warning Do not edit after initialization, as it may lead to undefined behavior. @@ -51,75 +58,71 @@ typedef struct { GRCAN_NODE_ID sending_node_id; } CubeCAN_Config; -#pragma endregion - -#pragma region Function Prototypes - /** - * @brief Initializes a CubeMX CAN handle with the given FDCAN handle and configuration, and starts the CAN peripheral. + * @brief Initializes a CubeCAN CAN handle with the given FDCAN handle and configuration, and starts the CAN peripheral. * @param hfdcan Pointer to the FDCAN handle. * @param config Pointer to the CubeCAN configuration structure. - * @return Pointer to the initialized CubeMX CAN handle, or NULL if initialization fails. - * @note This functions wraps CubeMXCan_Init and CubeMXCan_Start into a single call. If either of those functions fails, this function will return NULL and the handle will be released. + * @return Pointer to the initialized CubeCAN CAN handle, or NULL if initialization fails. + * @note This functions wraps CubeCAN_Init and CubeCAN_Start into a single call. If either of those functions fails, this function will return NULL and the handle will be released. */ -CubeMXCan_Handle *CubeMXCan_OneShotInitStart(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config); +CubeCAN_Handle *CubeCAN_OneShotInitStart(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config); /** - * @brief Stops the CubeMX CAN peripheral and releases the associated handle. - * @param handle Pointer to the CubeMX CAN handle. + * @brief Stops the CubeCAN CAN peripheral and releases the associated handle. + * @param handle Pointer to the CubeCAN CAN handle. * @return HAL_StatusTypeDef indicating the success or failure of the operation. - * @note This functions wraps CubeMXCan_Stop and CubeMXCan_Release into a single call. If either of those functions fails, this function will return the error code and the handle will + * @note This functions wraps CubeCAN_Stop and CubeCAN_Release into a single call. If either of those functions fails, this function will return the error code and the handle will * not be released. - * @note This function can be used regardless of if CubeMXCan_OneShotInitStart was used to initialize the handle. + * @note This function can be used regardless of if CubeCAN_OneShotInitStart was used to initialize the handle. */ -HAL_StatusTypeDef CubeMXCan_OneShotReleaseStop(CubeMXCan_Handle *handle); +HAL_StatusTypeDef CubeCAN_OneShotReleaseStop(CubeCAN_Handle *handle); /** - * @brief Initializes a CubeMX CAN handle with the given FDCAN handle and configuration. + * @brief Initializes a CubeCAN CAN handle with the given FDCAN handle and configuration. * @param hfdcan Pointer to the FDCAN handle. * @param config Pointer to the CubeCAN configuration structure. - * @return Pointer to the initialized CubeMX CAN handle, or NULL if initialization fails. + * @return Pointer to the initialized CubeCAN CAN handle, or NULL if initialization fails. */ -CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config); +CubeCAN_Handle *CubeCAN_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config); /** - * @brief Starts the CubeMX CAN handle, enabling message transmission and reception. - * @param handle Pointer to the CubeMX CAN handle. + * @brief Starts the CubeCAN CAN handle, enabling message transmission and reception. + * @param handle Pointer to the CubeCAN CAN handle. * @return HAL_StatusTypeDef indicating the success or failure of the operation. */ -HAL_StatusTypeDef CubeMXCan_Start(CubeMXCan_Handle *const handle); +HAL_StatusTypeDef CubeCAN_Start(CubeCAN_Handle *const handle); /** - * @brief Stops the CubeMX CAN handle, disabling message transmission and reception. - * @param handle Pointer to the CubeMX CAN handle. + * @brief Stops the CubeCAN CAN handle, disabling message transmission and reception. + * @param handle Pointer to the CubeCAN CAN handle. * @return HAL_StatusTypeDef indicating the success or failure of the operation. */ -HAL_StatusTypeDef CubeMXCan_Stop(CubeMXCan_Handle *const handle); +HAL_StatusTypeDef CubeCAN_Stop(CubeCAN_Handle *const handle); /** - * @brief Releases the resources associated with the CubeMX CAN handle. - * @param handle Pointer to the CubeMX CAN handle. + * @brief Releases the resources associated with the CubeCAN CAN handle. + * @param handle Pointer to the CubeCAN CAN handle. * @return HAL_StatusTypeDef indicating the success or failure of the operation. */ -HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *const handle); +HAL_StatusTypeDef CubeCAN_Release(CubeCAN_Handle *const handle); /** - * @brief Adds a filter to the CubeMX CAN handle, allowing for selective message reception based on the specified filter criteria. - * @param handle Pointer to the CubeMX CAN handle. + * @brief Adds a filter to the CubeCAN CAN handle, allowing for selective message reception based on the specified filter criteria. + * @param handle Pointer to the CubeCAN CAN handle. * @param filter Pointer to the FDCAN filter configuration structure. * @return HAL_StatusTypeDef indicating the success or failure of the operation. */ -HAL_StatusTypeDef CubeMXCan_AddFilter(const CubeMXCan_Handle *const handle, const FDCAN_FilterTypeDef *const filter); +HAL_StatusTypeDef CubeCAN_AddFilter(const CubeCAN_Handle *const handle, const FDCAN_FilterTypeDef *const filter); /** - * @brief Processes periodic tasks for the CubeMX CAN handle, such as handling timeouts and managing the transmission queue. + * @brief Processes periodic tasks for the CubeCAN CAN handle, such as handling timeouts and managing the transmission queue. * @warning This function sends one can message per configured bus per call. Not calling it will simply not send any messages. */ -void CubeMXCan_Tick(void); +void CubeCAN_Tick(void); /** - * @brief Sends a CAN message using the CubeMX CAN handle, with the specified receive node, message ID, data payload, and size. - * @param handle Pointer to the CubeMX CAN handle. + * @brief Sends a CAN message using the CubeCAN CAN handle, with the specified receive node, message ID, data payload, and size. + * @param handle Pointer to the CubeCAN CAN handle. * @param rx_node The receive node identifier for the message. * @param msg_id The message ID for the message. * @param data Pointer to the data payload of the message. @@ -127,7 +130,7 @@ void CubeMXCan_Tick(void); * @return HAL_StatusTypeDef indicating the success or failure of the operation. * @note The size of the data payload must not exceed FDCAN_MAX_DATA_BYTES (64 bytes). If the size exceeds this limit, the function will return HAL_ERROR. */ -HAL_StatusTypeDef CubeMXCan_Send(CubeMXCan_Handle *const handle, const GRCAN_NODE_ID rx_node, const GRCAN_MSG_ID msg_id, const void *const data, const uint8_t size); +HAL_StatusTypeDef CubeCAN_Send(CubeCAN_Handle *const handle, const GRCAN_NODE_ID rx_node, const GRCAN_MSG_ID msg_id, const void *const data, const uint8_t size); /** * @brief Constructs a CAN message identifier from the given transmitting node ID, receiving node ID, and message ID. @@ -155,6 +158,4 @@ CAN_Identifier Deconstruct_CAN_Identifier(const uint32_t message_id); */ HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *const identifier, const uint32_t filter_index, const uint32_t fifo, FDCAN_FilterTypeDef *const filter); -#pragma endregion - #endif diff --git a/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h b/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h index e0c381632..93e15d892 100644 --- a/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h +++ b/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h @@ -11,10 +11,8 @@ #ifndef PRIVATE_CUBE_MX_CAN_H #define PRIVATE_CUBE_MX_CAN_H -#pragma region Definitions - /** - * @brief Maximum number of CubeMX CAN instances supported by the library. + * @brief Maximum number of CubeCAN CAN instances supported by the library. * * This value is determined based on the available FDCAN peripherals in the STM32 microcontroller. * @@ -28,7 +26,7 @@ #elif (defined(FDCAN1) || defined(CAN1)) #define CUBEMX_CAN_MAX_INSTANCES (1U) #else -#error "No CAN or FDCAN instances defined. Please check your CubeMX configuration." +#error "No CAN or FDCAN instances defined. Please check your CubeCAN configuration." #endif #endif @@ -38,7 +36,7 @@ * Application code should not use this macro directly. It is intended for internal use only * * @warning The transmission queue size must be a power of two for this mask to work correctly - * @warning The transmission queue size must be defined as CUBEMX_CAN_TX_QUEUE_SIZE in the CubeMX CAN configuration header file + * @warning The transmission queue size must be defined as CUBEMX_CAN_TX_QUEUE_SIZE in the CubeCAN CAN configuration header file */ #define TX_QUEUE_MASK (CUBEMX_CAN_TX_QUEUE_SIZE - 1U) @@ -56,10 +54,6 @@ */ #define FDCAN_MAX_DATA_BYTES (64U) -#pragma endregion - -#pragma region Type Definitions - /** * @brief Transmission CAN message structure * @@ -74,58 +68,50 @@ typedef struct { } GRCAN_Private_TxMessage; /** - * @brief CubeMX CAN handle structure + * @brief CubeCAN CAN handle structure * - * This structure is used to represent a CubeMX CAN handle, which consists of a pointer to the FDCAN handle, a configuration structure, a transmission queue, and other relevant parameters. + * This structure is used to represent a CubeCAN CAN handle, which consists of a pointer to the FDCAN handle, a configuration structure, a transmission queue, and other relevant parameters. * - * @warning Use the provided API functions to interact with the CubeMX CAN handle. + * @warning Use the provided API functions to interact with the CubeCAN CAN handle. * @warning The structure is intended for internal use only and should not be accessed directly by user code. */ -struct CubeMXCan_Private_Handle { - /// @brief Pointer to the FDCAN handle associated with this CubeMX CAN handle. +struct CubeCAN_Private_Handle { + /// @brief Pointer to the FDCAN handle associated with this CubeCAN CAN handle. FDCAN_HandleTypeDef *hfdcan; - /// @brief Configuration structure for the CubeMX CAN handle, containing the receive callback and user context. + /// @brief Configuration structure for the CubeCAN CAN handle, containing the receive callback and user context. CubeCAN_Config config; - /// @brief Transmission queue for the CubeMX CAN handle, containing the messages to be transmitted. + /// @brief Transmission queue for the CubeCAN CAN handle, containing the messages to be transmitted. GRCAN_Private_TxMessage tx_queue[CUBEMX_CAN_TX_QUEUE_SIZE]; /// @brief Atomic head index for the transmission queue, indicating the next message to be transmitted. _Atomic uint32_t tx_head; /// @brief Atomic tail index for the transmission queue, indicating the next available slot for a new message. _Atomic uint32_t tx_tail; - /// @brief Flag indicating whether the CubeMX CAN handle has been started. + /// @brief Flag indicating whether the CubeCAN CAN handle has been started. bool started; }; -#pragma endregion - -#pragma region External Variables - /** - * @brief Array of CubeMX CAN handles, one for each supported instance. + * @brief Array of CubeCAN CAN handles, one for each supported instance. * @note The number of instances is defined by CUBEMX_CAN_MAX_INSTANCES. */ -extern struct CubeMXCan_Private_Handle handles[CUBEMX_CAN_MAX_INSTANCES]; - -#pragma endregion - -#pragma region Function Prototypes +extern struct CubeCAN_Private_Handle handles[CUBEMX_CAN_MAX_INSTANCES]; /** - * @brief Sends a queued message from the CubeMX CAN handle. - * @param handle Pointer to the CubeMX CAN handle. + * @brief Sends a queued message from the CubeCAN CAN handle. + * @param handle Pointer to the CubeCAN CAN handle. * @return HAL_StatusTypeDef indicating the success or failure of the operation. */ -HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(const CubeMXCan_Handle *const handle); +HAL_StatusTypeDef CubeCAN_Private_SendQueuedMessage(const CubeCAN_Handle *const handle); /** - * @brief Attempts to recover the FDCAN peripheral associated with the given CubeMX CAN handle. + * @brief Attempts to recover the FDCAN peripheral associated with the given CubeCAN CAN handle. * * Handles recovery from bus off or restricted operation mode by reinitializing the FDCAN peripheral and restoring its configuration. * - * @param handle Pointer to the CubeMX CAN handle associated with the FDCAN peripheral to be recovered. + * @param handle Pointer to the CubeCAN CAN handle associated with the FDCAN peripheral to be recovered. * @return HAL_StatusTypeDef indicating the success or failure of the recovery operation. */ -HAL_StatusTypeDef CubeMXCan_Private_RecoverPeripheral(const CubeMXCan_Handle *const handle); +HAL_StatusTypeDef CubeCAN_Private_RecoverPeripheral(const CubeCAN_Handle *const handle); /** * @brief Converts a Data Length Code (DLC) to the corresponding number of data bytes. @@ -133,15 +119,15 @@ HAL_StatusTypeDef CubeMXCan_Private_RecoverPeripheral(const CubeMXCan_Handle *co * @return The number of data bytes corresponding to the given DLC. * @warning The DLC value must be between 0 and 15, inclusive. Values outside this range will result in undefined behavior. */ -bool CubeMXCan_Private_IsDisabled(const CubeMXCan_Handle *const handle); +bool CubeCAN_Private_IsDisabled(const CubeCAN_Handle *const handle); /** - * @brief Queues a transmission message for the CubeMX CAN handle, allowing for asynchronous message transmission. - * @param handle Pointer to the CubeMX CAN handle. + * @brief Queues a transmission message for the CubeCAN CAN handle, allowing for asynchronous message transmission. + * @param handle Pointer to the CubeCAN CAN handle. * @param message Pointer to the GRCAN transmission message structure. * @return HAL_StatusTypeDef if the parameters are non-null or the queue is full. */ -HAL_StatusTypeDef CubeMXCan_Private_QueueTx(CubeMXCan_Handle *const handle, const GRCAN_Private_TxMessage *const message); +HAL_StatusTypeDef CubeCAN_Private_QueueTx(CubeCAN_Handle *const handle, const GRCAN_Private_TxMessage *const message); /** * @brief Converts a Data Length Code (DLC) to the corresponding number of bytes. @@ -149,7 +135,7 @@ HAL_StatusTypeDef CubeMXCan_Private_QueueTx(CubeMXCan_Handle *const handle, cons * @return The number of bytes corresponding to the given DLC. * @warning The DLC value must be between 0 and 15, inclusive. Values outside this range will result in undefined behavior. */ -uint8_t CubeMXCan_Private_DlcToBytes(const uint32_t dlc); +uint8_t CubeCAN_Private_DlcToBytes(const uint32_t dlc); /** * @brief Converts a number of bytes to the corresponding Data Length Code (DLC). @@ -157,8 +143,6 @@ uint8_t CubeMXCan_Private_DlcToBytes(const uint32_t dlc); * @return The Data Length Code corresponding to the given number of bytes. * @warning The number of bytes must be between 0 and 8, inclusive. Values outside this range will result in undefined behavior. */ -uint8_t CubeMXCan_Private_BytesToDlc(const uint8_t bytes); - -#pragma endregion +uint8_t CubeCAN_Private_BytesToDlc(const uint8_t bytes); #endif diff --git a/Lib/Peripherals/CubeCAN/Src/can_assert.c b/Lib/Peripherals/CubeCAN/Src/can_assert.c index 379d6df3d..05d94fa2b 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_assert.c +++ b/Lib/Peripherals/CubeCAN/Src/can_assert.c @@ -4,30 +4,22 @@ #include #include "CriticalSection.h" +#include "CubeCAN.h" #include "CubeCAN_Config.h" -#include "CubeMXCan.h" #include "PrivateInc/internal.h" #include "main.h" -#pragma region Compiler Assertions +static_assert(sizeof(((struct CubeCAN_Private_Handle *)0)->tx_head) == sizeof(uint32_t), "CubeCAN internal tx_head must be 32 bits"); +static_assert(sizeof(((struct CubeCAN_Private_Handle *)0)->tx_tail) == sizeof(uint32_t), "CubeCAN internal tx_tail must be 32 bits"); -static_assert(sizeof(((struct CubeMXCan_Private_Handle *)0)->tx_head) == sizeof(uint32_t), "CubeMXCan internal tx_head must be 32 bits"); -static_assert(sizeof(((struct CubeMXCan_Private_Handle *)0)->tx_tail) == sizeof(uint32_t), "CubeMXCan internal tx_tail must be 32 bits"); +static_assert(alignof(GRCAN_Private_TxMessage) >= 4, "CubeCAN internal GRCAN_Private_TxMessage must have at least 4-byte alignment"); +static_assert(alignof(struct CubeCAN_Private_Handle) >= 4, "CubeCAN internal CubeCAN_Private_Handle must have at least 4-byte alignment"); -static_assert(alignof(GRCAN_Private_TxMessage) >= 4, "CubeMXCan internal GRCAN_Private_TxMessage must have at least 4-byte alignment"); -static_assert(alignof(struct CubeMXCan_Private_Handle) >= 4, "CubeMXCan internal CubeMXCan_Private_Handle must have at least 4-byte alignment"); +static_assert((offsetof(struct CubeCAN_Private_Handle, tx_head) % 4U) == 0U, "CubeCAN internal atomic tx_head is unaligned"); +static_assert((offsetof(struct CubeCAN_Private_Handle, tx_tail) % 4U) == 0U, "CubeCAN internal atomic tx_tail is unaligned"); -static_assert((offsetof(struct CubeMXCan_Private_Handle, tx_head) % 4U) == 0U, "CubeMXCan internal atomic tx_head is unaligned"); -static_assert((offsetof(struct CubeMXCan_Private_Handle, tx_tail) % 4U) == 0U, "CubeMXCan internal atomic tx_tail is unaligned"); - -static_assert(ATOMIC_INT_LOCK_FREE == 2, "CubeMXCan internal ATOMIC_INT_LOCK_FREE must be enabled for atomic operations"); -static_assert(ATOMIC_BOOL_LOCK_FREE == 2, "CubeMXCan internal ATOMIC_BOOL_LOCK_FREE must be enabled for atomic operations"); - -#pragma endregion - -#pragma region Configuration Checks +static_assert(ATOMIC_INT_LOCK_FREE == 2, "CubeCAN internal ATOMIC_INT_LOCK_FREE must be enabled for atomic operations"); +static_assert(ATOMIC_BOOL_LOCK_FREE == 2, "CubeCAN internal ATOMIC_BOOL_LOCK_FREE must be enabled for atomic operations"); static_assert((CUBEMX_CAN_TX_QUEUE_SIZE > 0) && !(CUBEMX_CAN_TX_QUEUE_SIZE & (CUBEMX_CAN_TX_QUEUE_SIZE - 1U)), "CUBEMX_CAN_TX_QUEUE_SIZE must be a power of two and greater than zero"); static_assert(CUBEMX_CAN_MAX_INSTANCES >= 1 && CUBEMX_CAN_MAX_INSTANCES <= 3, "CUBEMX_CAN_MAX_INSTANCES must be configured between 1 and 3 inclusive"); - -#pragma endregion diff --git a/Lib/Peripherals/CubeCAN/Src/can_global.c b/Lib/Peripherals/CubeCAN/Src/can_global.c index 90921d16c..254508f25 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_global.c +++ b/Lib/Peripherals/CubeCAN/Src/can_global.c @@ -3,7 +3,7 @@ #include #include "CriticalSection.h" -#include "CubeMXCan.h" +#include "CubeCAN.h" #include "PrivateInc/internal.h" -struct CubeMXCan_Private_Handle handles[CUBEMX_CAN_MAX_INSTANCES] = {0}; +struct CubeCAN_Private_Handle handles[CUBEMX_CAN_MAX_INSTANCES] = {0}; diff --git a/Lib/Peripherals/CubeCAN/Src/can_init.c b/Lib/Peripherals/CubeCAN/Src/can_init.c index 053ca8725..469118e5a 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_init.c +++ b/Lib/Peripherals/CubeCAN/Src/can_init.c @@ -4,54 +4,54 @@ #include #include "CriticalSection.h" -#include "CubeMXCan.h" +#include "CubeCAN.h" #include "Logomatic.h" #include "PrivateInc/internal.h" #include "main.h" -CubeMXCan_Handle *CubeMXCan_OneShotInitStart(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config) +CubeCAN_Handle *CubeCAN_OneShotInitStart(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config) { - CubeMXCan_Handle *handle = CubeMXCan_Init(hfdcan, config); + CubeCAN_Handle *handle = CubeCAN_Init(hfdcan, config); if (handle == NULL) { - LOGOMATIC("CubeMXCan_OneShotInit: failed to initialize handle\n"); + LOGOMATIC("CubeCAN_OneShotInit: failed to initialize handle\n"); return NULL; } - if (CubeMXCan_Start(handle) != HAL_OK) { - LOGOMATIC("CubeMXCan_OneShotInit: failed to start handle\n"); - CubeMXCan_Release(handle); + if (CubeCAN_Start(handle) != HAL_OK) { + LOGOMATIC("CubeCAN_OneShotInit: failed to start handle\n"); + CubeCAN_Release(handle); return NULL; } return handle; } -HAL_StatusTypeDef CubeMXCan_OneShotReleaseStop(CubeMXCan_Handle *handle) +HAL_StatusTypeDef CubeCAN_OneShotReleaseStop(CubeCAN_Handle *handle) { if (handle == NULL) { - LOGOMATIC("CubeMXCan_OneShotReleaseStop: invalid null parameter\n"); + LOGOMATIC("CubeCAN_OneShotReleaseStop: invalid null parameter\n"); return HAL_ERROR; } - HAL_StatusTypeDef status = CubeMXCan_Stop(handle); + HAL_StatusTypeDef status = CubeCAN_Stop(handle); if (status != HAL_OK) { - LOGOMATIC("CubeMXCan_OneShotReleaseStop: failed to stop FDCAN instance\n"); + LOGOMATIC("CubeCAN_OneShotReleaseStop: failed to stop FDCAN instance\n"); return status; } - return CubeMXCan_Release(handle); + return CubeCAN_Release(handle); } -CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config) +CubeCAN_Handle *CubeCAN_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config) { if (hfdcan == NULL || config == NULL) { - LOGOMATIC("CubeMXCan_Init: invalid null parameters\n"); + LOGOMATIC("CubeCAN_Init: invalid null parameters\n"); return NULL; } - CubeMXCan_Handle *handle = NULL; + CubeCAN_Handle *handle = NULL; uint8_t free_handle_index = (uint8_t)-1; CRITICAL_SECTION @@ -66,7 +66,7 @@ CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *co } if (handle != NULL) { - LOGOMATIC("CubeMXCan_Init: handle already initialized for this FDCAN instance\n"); + LOGOMATIC("CubeCAN_Init: handle already initialized for this FDCAN instance\n"); return NULL; } else if (free_handle_index != (uint8_t)-1) { handle = &handles[free_handle_index]; @@ -80,12 +80,12 @@ CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *co } if (handle == NULL) { - LOGOMATIC("CubeMXCan_Init: no free handle slots\n"); + LOGOMATIC("CubeCAN_Init: no free handle slots\n"); return NULL; } if (HAL_FDCAN_ActivateNotification(hfdcan, FDCAN_IT_RX_EVENTS, 0U) != HAL_OK) { - LOGOMATIC("CubeMXCan_Init: failed to activate RX notifications\n"); + LOGOMATIC("CubeCAN_Init: failed to activate RX notifications\n"); CRITICAL_SECTION { memset(handle, 0, sizeof(*handle)); @@ -96,7 +96,7 @@ CubeMXCan_Handle *CubeMXCan_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *co return handle; } -HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *handle) +HAL_StatusTypeDef CubeCAN_Release(CubeCAN_Handle *handle) { if (handle == NULL) { return HAL_ERROR; @@ -124,7 +124,7 @@ HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *handle) } if (status != HAL_OK) { - LOGOMATIC("CubeMXCan_Release: peripheral deactivation failed\n"); + LOGOMATIC("CubeCAN_Release: peripheral deactivation failed\n"); CRITICAL_SECTION { @@ -142,7 +142,7 @@ HAL_StatusTypeDef CubeMXCan_Release(CubeMXCan_Handle *handle) return HAL_OK; } -HAL_StatusTypeDef CubeMXCan_Start(CubeMXCan_Handle *const handle) +HAL_StatusTypeDef CubeCAN_Start(CubeCAN_Handle *const handle) { if (handle == NULL) { return HAL_ERROR; @@ -175,7 +175,7 @@ HAL_StatusTypeDef CubeMXCan_Start(CubeMXCan_Handle *const handle) return status; } -HAL_StatusTypeDef CubeMXCan_Stop(CubeMXCan_Handle *const handle) +HAL_StatusTypeDef CubeCAN_Stop(CubeCAN_Handle *const handle) { if (handle == NULL) { return HAL_ERROR; diff --git a/Lib/Peripherals/CubeCAN/Src/can_rx.c b/Lib/Peripherals/CubeCAN/Src/can_rx.c index a520b6bac..19c8f2899 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_rx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_rx.c @@ -2,7 +2,7 @@ #include #include "CriticalSection.h" -#include "CubeMXCan.h" +#include "CubeCAN.h" #include "Logomatic.h" #include "PrivateInc/internal.h" #include "Unused.h" @@ -52,7 +52,7 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) while (HAL_FDCAN_GetRxFifoFillLevel(hfdcan, FDCAN_RX_FIFO0) > 0U) { if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &rx_header, rx_data) == HAL_OK) { CAN_Identifier id = Deconstruct_CAN_Identifier(rx_header.Identifier); - uint8_t size = CubeMXCan_Private_DlcToBytes(rx_header.DataLength); + uint8_t size = CubeCAN_Private_DlcToBytes(rx_header.DataLength); rx_callback(user_context, &id, rx_data, size); } else { LOGOMATIC("HAL_FDCAN_RxFifo0Callback: Failed to get Rx message from FIFO\n"); diff --git a/Lib/Peripherals/CubeCAN/Src/can_tx.c b/Lib/Peripherals/CubeCAN/Src/can_tx.c index 5cf78ae52..4ed3c207b 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_tx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_tx.c @@ -3,41 +3,41 @@ #include #include "CriticalSection.h" -#include "CubeMXCan.h" +#include "CubeCAN.h" #include "Logomatic.h" #include "PrivateInc/internal.h" #include "main.h" -void CubeMXCan_Tick(void) +void CubeCAN_Tick(void) { for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { - CubeMXCan_Handle *handle = &handles[i]; + CubeCAN_Handle *handle = &handles[i]; if (handle->hfdcan == NULL || !handle->started) { continue; } - if (CubeMXCan_Private_IsDisabled(handle)) { - LOGOMATIC("CubeMXCan_Tick: currently in restricted operation mode\n"); - if (CubeMXCan_Private_RecoverPeripheral(handle) != HAL_OK) { - LOGOMATIC("CubeMXCan_Tick %d: failed to recover peripheral\n", (int)i); + if (CubeCAN_Private_IsDisabled(handle)) { + LOGOMATIC("CubeCAN_Tick: currently in restricted operation mode\n"); + if (CubeCAN_Private_RecoverPeripheral(handle) != HAL_OK) { + LOGOMATIC("CubeCAN_Tick %d: failed to recover peripheral\n", (int)i); continue; } } - (void)CubeMXCan_Private_SendQueuedMessage(handle); + (void)CubeCAN_Private_SendQueuedMessage(handle); } } -HAL_StatusTypeDef CubeMXCan_Send(CubeMXCan_Handle *const handle, const GRCAN_NODE_ID rx_node, const GRCAN_MSG_ID msg_id, const void *const data, const uint8_t size) +HAL_StatusTypeDef CubeCAN_Send(CubeCAN_Handle *const handle, const GRCAN_NODE_ID rx_node, const GRCAN_MSG_ID msg_id, const void *const data, const uint8_t size) { if (handle == NULL || data == NULL || size > FDCAN_MAX_DATA_BYTES) { return HAL_ERROR; } - const uint32_t dlc = CubeMXCan_Private_BytesToDlc(size); + const uint32_t dlc = CubeCAN_Private_BytesToDlc(size); if (dlc == FDCAN_DLC_BYTES_0 && size != 0) { - LOGOMATIC("CubeMXCan_Send: invalid data length code\n"); + LOGOMATIC("CubeCAN_Send: invalid data length code\n"); return HAL_ERROR; } @@ -57,14 +57,14 @@ HAL_StatusTypeDef CubeMXCan_Send(CubeMXCan_Handle *const handle, const GRCAN_NOD brs = FDCAN_BRS_ON; break; default: - LOGOMATIC("CubeMXCan_Send: unsupported frame format\n"); + LOGOMATIC("CubeCAN_Send: unsupported frame format\n"); return HAL_ERROR; } const CAN_Identifier identifier_struct = {.tx_node_id = handle->config.sending_node_id, .rx_node_id = rx_node, .msg_id = msg_id}; const FDCAN_TxHeaderTypeDef header = {.BitRateSwitch = brs, - .DataLength = CubeMXCan_Private_BytesToDlc(size), + .DataLength = CubeCAN_Private_BytesToDlc(size), .ErrorStateIndicator = FDCAN_ESI_ACTIVE, .FDFormat = fdformat, .Identifier = Construct_CAN_Identifier(&identifier_struct), @@ -76,10 +76,10 @@ HAL_StatusTypeDef CubeMXCan_Send(CubeMXCan_Handle *const handle, const GRCAN_NOD GRCAN_Private_TxMessage message = {.tx_header = header}; memcpy(message.data, data, size); - return CubeMXCan_Private_QueueTx(handle, &message); + return CubeCAN_Private_QueueTx(handle, &message); } -HAL_StatusTypeDef CubeMXCan_Private_QueueTx(CubeMXCan_Handle *handle, const GRCAN_Private_TxMessage *message) +HAL_StatusTypeDef CubeCAN_Private_QueueTx(CubeCAN_Handle *handle, const GRCAN_Private_TxMessage *message) { if (handle == NULL || message == NULL) { return HAL_ERROR; @@ -105,15 +105,15 @@ HAL_StatusTypeDef CubeMXCan_Private_QueueTx(CubeMXCan_Handle *handle, const GRCA return status; } -HAL_StatusTypeDef CubeMXCan_Private_SendQueuedMessage(const CubeMXCan_Handle *const handle) +HAL_StatusTypeDef CubeCAN_Private_SendQueuedMessage(const CubeCAN_Handle *const handle) { if (handle == NULL || handle->hfdcan == NULL) { - LOGOMATIC("CubeMXCan_Private_SendQueuedMessage: invalid null parameter\n"); + LOGOMATIC("CubeCAN_Private_SendQueuedMessage: invalid null parameter\n"); return HAL_ERROR; } if (HAL_FDCAN_GetTxFifoFreeLevel(handle->hfdcan) == 0U) { - LOGOMATIC("CubeMXCan_Private_SendQueuedMessage: Tx FIFO full, cannot send message\n"); + LOGOMATIC("CubeCAN_Private_SendQueuedMessage: Tx FIFO full, cannot send message\n"); return HAL_BUSY; } diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index 8b66dd76e..b0233e1d6 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -3,7 +3,7 @@ #include #include "CriticalSection.h" -#include "CubeMXCan.h" +#include "CubeCAN.h" #include "GRCAN_MSG_ID.h" #include "GRCAN_NODE_ID.h" #include "Logomatic.h" @@ -53,10 +53,10 @@ HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *const ide return HAL_OK; } -HAL_StatusTypeDef CubeMXCan_AddFilter(const CubeMXCan_Handle *const handle, const FDCAN_FilterTypeDef *filter) +HAL_StatusTypeDef CubeCAN_AddFilter(const CubeCAN_Handle *const handle, const FDCAN_FilterTypeDef *filter) { if (handle == NULL || filter == NULL) { - LOGOMATIC("CubeMXCan_AddFilter: Invalid handle or filter pointer\n"); + LOGOMATIC("CubeCAN_AddFilter: Invalid handle or filter pointer\n"); return HAL_ERROR; } @@ -72,7 +72,7 @@ HAL_StatusTypeDef CubeMXCan_AddFilter(const CubeMXCan_Handle *const handle, cons return status; } -uint8_t CubeMXCan_Private_BytesToDlc(const uint8_t bytes) +uint8_t CubeCAN_Private_BytesToDlc(const uint8_t bytes) { switch (bytes) { case 0U: @@ -108,12 +108,12 @@ uint8_t CubeMXCan_Private_BytesToDlc(const uint8_t bytes) case 64U: return FDCAN_DLC_BYTES_64; default: - LOGOMATIC("CubeMXCan_Private_BytesToDlc: Invalid byte count\n"); + LOGOMATIC("CubeCAN_Private_BytesToDlc: Invalid byte count\n"); return FDCAN_DLC_BYTES_0; } } -uint8_t CubeMXCan_Private_DlcToBytes(const uint32_t dlc) +uint8_t CubeCAN_Private_DlcToBytes(const uint32_t dlc) { switch (dlc) { case FDCAN_DLC_BYTES_0: @@ -149,12 +149,12 @@ uint8_t CubeMXCan_Private_DlcToBytes(const uint32_t dlc) case FDCAN_DLC_BYTES_64: return 64U; default: - LOGOMATIC("CubeMXCan_Private_DlcToBytes: Invalid DLC value\n"); + LOGOMATIC("CubeCAN_Private_DlcToBytes: Invalid DLC value\n"); return 0U; } } -bool CubeMXCan_Private_IsDisabled(const CubeMXCan_Handle *const handle) +bool CubeCAN_Private_IsDisabled(const CubeCAN_Handle *const handle) { if (handle == NULL) { return true; @@ -181,7 +181,7 @@ bool CubeMXCan_Private_IsDisabled(const CubeMXCan_Handle *const handle) return disabled; } -HAL_StatusTypeDef CubeMXCan_Private_RecoverPeripheral(const CubeMXCan_Handle *const handle) +HAL_StatusTypeDef CubeCAN_Private_RecoverPeripheral(const CubeCAN_Handle *const handle) { if (handle == NULL) { return HAL_ERROR; @@ -195,7 +195,7 @@ HAL_StatusTypeDef CubeMXCan_Private_RecoverPeripheral(const CubeMXCan_Handle *co FDCAN_ProtocolStatusTypeDef protocol_status = {0}; if (HAL_FDCAN_GetProtocolStatus(handle->hfdcan, &protocol_status) == HAL_OK && protocol_status.BusOff) { - LOGOMATIC("CubeMXCan_Private_RecoverPeripheral: CRITICAL BUS-OFF DETECTED. Forcing instant hardware reset...\n"); + LOGOMATIC("CubeCAN_Private_RecoverPeripheral: CRITICAL BUS-OFF DETECTED. Forcing instant hardware reset...\n"); HAL_FDCAN_Stop(handle->hfdcan); @@ -210,12 +210,12 @@ HAL_StatusTypeDef CubeMXCan_Private_RecoverPeripheral(const CubeMXCan_Handle *co } if (status != HAL_OK) { - LOGOMATIC("CubeMXCan_Private_RecoverPeripheral: Aggressive hardware start failed!\n"); + LOGOMATIC("CubeCAN_Private_RecoverPeripheral: Aggressive hardware start failed!\n"); } } if (HAL_FDCAN_IsRestrictedOperationMode(handle->hfdcan)) { - LOGOMATIC("CubeMXCan_Private_RecoverPeripheral: Forcing exit from restricted operation mode\n"); + LOGOMATIC("CubeCAN_Private_RecoverPeripheral: Forcing exit from restricted operation mode\n"); HAL_FDCAN_ExitRestrictedOperationMode(handle->hfdcan); } } diff --git a/Lib/Peripherals/CubeCAN/cubemx_can.cmake b/Lib/Peripherals/CubeCAN/cube_can.cmake similarity index 100% rename from Lib/Peripherals/CubeCAN/cubemx_can.cmake rename to Lib/Peripherals/CubeCAN/cube_can.cmake From d8d1f7252757db7ca6ec3c1242492f811e0c27ea Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 14 Aug 2026 04:03:56 -0700 Subject: [PATCH 042/125] Cleanup names and CUBEMXTESTING Signed-off-by: Daniel Hansen --- .../Application/Inc/CubeCAN_Config.h | 4 ++-- CUBEMXTESTING/CMakeLists.txt | 2 +- CUBEMXTESTING/Core/Inc/main.h | 1 + CUBEMXTESTING/Core/Src/main.c | 20 +++---------------- Lib/Peripherals/CubeCAN/Inc/CubeCAN.h | 6 +++--- Lib/Peripherals/CubeCAN/Src/can_rx.c | 2 +- Lib/Peripherals/CubeCAN/Src/can_tx.c | 2 +- Lib/Peripherals/CubeCAN/Src/can_utils.c | 8 ++++---- 8 files changed, 16 insertions(+), 29 deletions(-) diff --git a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h index db74ce3b5..ca7e395e1 100644 --- a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h +++ b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h @@ -4,7 +4,7 @@ #include "GRCAN_NODE_ID.h" #include "main.h" -#define CUBEMX_CAN_TX_QUEUE_SIZE 32U -#define CUBEMX_SENDING_NODE_ID GRCAN_ECU +#define CUBEMX_CAN_TX_QUEUE_SIZE 16U +#define CUBEMX_CAN_MAX_INSTANCES 1U #endif diff --git a/CUBEMXTESTING/CMakeLists.txt b/CUBEMXTESTING/CMakeLists.txt index 81566a37d..cef556784 100644 --- a/CUBEMXTESTING/CMakeLists.txt +++ b/CUBEMXTESTING/CMakeLists.txt @@ -34,7 +34,7 @@ target_sources( Core/Src/tim.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE VCP_LIB CUBEMX_CAN_LIB LOGOMATIC_LIB) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE CUBEMX_CAN_LIB LOGOMATIC_LIB) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index 2ca19b1c6..50f780d60 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -44,6 +44,7 @@ extern "C" { #include "stm32g4xx_ll_lpuart.h" #include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_usart.h" +#include "CubeCAN.h" /* USER CODE END Includes */ /* Exported types ------------------------------------------------------------*/ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index ab6643b56..04eb5e22d 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -30,7 +30,6 @@ #include "Logomatic.h" #include "loop.h" #include "tim.h" -#include "vcp.h" // #include "can.h" // #include "can_cfg.h" @@ -68,19 +67,6 @@ LogomaticConfig logomaticConfig = {.clock_source = LOGOMATIC_PCLK1, .prescaler = LOGOMATIC_PRESCALER_DIV1, .tx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8, .rx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8}; - -VCP_Config vcp_config = {.baud_rate = 2000000, - .clock_source = VCP_CLOCK_PCLK, - .gpio_tx_rx_pin_mask = LL_GPIO_PIN_2 | LL_GPIO_PIN_3, - .bus_port = VCP_Port_A, - .parity = VCP_Parity_None, - .prescaler = VCP_Prescalar_Div2, - .stop_bits = VCP_StopBits_1, - .oversampling = VCP_Oversampling_16, - .tx_fifo_threshold = VCP_Threshold_1_8, - .rx_fifo_threshold = VCP_Threshold_1_8, - .alternate_function = LL_GPIO_AF_7, - .rx_callback = NULL}; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -128,8 +114,7 @@ int main(void) MX_TIM5_Init(); MX_FDCAN3_Init(); /* USER CODE BEGIN 2 */ - Logomatic_Init(&logomaticConfig); - VCP_Init(&vcp_config); + Setup_Logomatic(&logomaticConfig); CubeCAN_Config can_config = {.rx_callback = CANdler_Callback, .user_context = (void *)1}; @@ -141,7 +126,8 @@ int main(void) LOGOMATIC("Hello World!\n"); while (1) { /* USER CODE END WHILE */ - + MainLoop(); + LL_mDelay(250); /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h b/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h index 9b0eddd6e..2727db147 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h @@ -139,7 +139,7 @@ HAL_StatusTypeDef CubeCAN_Send(CubeCAN_Handle *const handle, const GRCAN_NODE_ID * * @return The constructed 29-bit CAN message extended identifier. */ -uint32_t Construct_CAN_Identifier(const CAN_Identifier *const identifier); +uint32_t CubeCAN_Construct_Identifier(const CAN_Identifier *const identifier); /** * @brief Deconstructs a 29-bit CAN message extended identifier into its constituent transmitting node ID, receiving node ID, and message ID. @@ -151,11 +151,11 @@ uint32_t Construct_CAN_Identifier(const CAN_Identifier *const identifier); * @warning The function does not guarantee that the returned structure will represent a valid CAN message identifier. * @warning The function does not support custom IDs. */ -CAN_Identifier Deconstruct_CAN_Identifier(const uint32_t message_id); +CAN_Identifier CubeCAN_Deconstruct_Identifier(const uint32_t message_id); /** * @brief Builds an exact-match extended-ID filter for a given CAN identifier. */ -HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *const identifier, const uint32_t filter_index, const uint32_t fifo, FDCAN_FilterTypeDef *const filter); +HAL_StatusTypeDef CubeCAN_BuildExtendedFilter(const CAN_Identifier *const identifier, const uint32_t filter_index, const uint32_t fifo, FDCAN_FilterTypeDef *const filter); #endif diff --git a/Lib/Peripherals/CubeCAN/Src/can_rx.c b/Lib/Peripherals/CubeCAN/Src/can_rx.c index 19c8f2899..da833491f 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_rx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_rx.c @@ -51,7 +51,7 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) while (HAL_FDCAN_GetRxFifoFillLevel(hfdcan, FDCAN_RX_FIFO0) > 0U) { if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &rx_header, rx_data) == HAL_OK) { - CAN_Identifier id = Deconstruct_CAN_Identifier(rx_header.Identifier); + CAN_Identifier id = CubeCAN_Deconstruct_Identifier(rx_header.Identifier); uint8_t size = CubeCAN_Private_DlcToBytes(rx_header.DataLength); rx_callback(user_context, &id, rx_data, size); } else { diff --git a/Lib/Peripherals/CubeCAN/Src/can_tx.c b/Lib/Peripherals/CubeCAN/Src/can_tx.c index 4ed3c207b..752167563 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_tx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_tx.c @@ -67,7 +67,7 @@ HAL_StatusTypeDef CubeCAN_Send(CubeCAN_Handle *const handle, const GRCAN_NODE_ID .DataLength = CubeCAN_Private_BytesToDlc(size), .ErrorStateIndicator = FDCAN_ESI_ACTIVE, .FDFormat = fdformat, - .Identifier = Construct_CAN_Identifier(&identifier_struct), + .Identifier = CubeCAN_Construct_Identifier(&identifier_struct), .IdType = FDCAN_EXTENDED_ID, .MessageMarker = 0U, // TODO We can do cool things with this to track transmission queue statistics .TxEventFifoControl = FDCAN_NO_TX_EVENTS, diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index b0233e1d6..44e26e61a 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -15,7 +15,7 @@ #define CAN_NODE_MASK 0xFFU #define CAN_MSG_MASK 0xFFFU -uint32_t Construct_CAN_Identifier(const CAN_Identifier *identifier) +uint32_t CubeCAN_Construct_Identifier(const CAN_Identifier *identifier) { if (identifier == NULL) { return 0U; @@ -28,7 +28,7 @@ uint32_t Construct_CAN_Identifier(const CAN_Identifier *identifier) return (tx_node_id << CAN_TX_NODE_SHIFT) | (msg_id << CAN_MSG_SHIFT) | (rx_node_id << CAN_RX_NODE_SHIFT); } -CAN_Identifier Deconstruct_CAN_Identifier(const uint32_t message_id) +CAN_Identifier CubeCAN_Deconstruct_Identifier(const uint32_t message_id) { const GRCAN_NODE_ID tx_node_id = (message_id >> CAN_TX_NODE_SHIFT) & CAN_NODE_MASK; const GRCAN_MSG_ID msg_id = (message_id >> CAN_MSG_SHIFT) & CAN_MSG_MASK; @@ -37,7 +37,7 @@ CAN_Identifier Deconstruct_CAN_Identifier(const uint32_t message_id) return (CAN_Identifier){.tx_node_id = tx_node_id, .msg_id = msg_id, .rx_node_id = rx_node_id}; } -HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *const identifier, const uint32_t filter_index, const uint32_t fifo, FDCAN_FilterTypeDef *const filter) +HAL_StatusTypeDef CubeCAN_BuildExtendedFilter(const CAN_Identifier *const identifier, const uint32_t filter_index, const uint32_t fifo, FDCAN_FilterTypeDef *const filter) { if (identifier == NULL || filter == NULL) { return HAL_ERROR; @@ -47,7 +47,7 @@ HAL_StatusTypeDef CubeCANExt_BuildExtendedFilter(const CAN_Identifier *const ide filter->FilterIndex = filter_index; filter->FilterType = FDCAN_FILTER_MASK; filter->FilterConfig = fifo; - filter->FilterID1 = Construct_CAN_Identifier(identifier); + filter->FilterID1 = CubeCAN_Construct_Identifier(identifier); filter->FilterID2 = 0x1FFFFFFFU; return HAL_OK; From 987b8ff9a27c2feb56f90c545720e29226794edf Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 14 Aug 2026 04:04:14 -0700 Subject: [PATCH 043/125] Reorganize context and setup CUBEMXTESTING for testing Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Application/Inc/CANdler.h | 2 +- CUBEMXTESTING/Application/Src/CANdler.c | 19 ++++++++++++++++--- CUBEMXTESTING/Application/Src/loop.c | 12 ++++-------- CUBEMXTESTING/CMakeLists.txt | 1 + CUBEMXTESTING/Core/Inc/main.h | 2 +- CUBEMXTESTING/Core/Src/main.c | 13 ++++++++++--- Lib/Peripherals/CubeCAN/Inc/CubeCAN.h | 23 ++++++++++++++++++++--- Lib/Peripherals/CubeCAN/Src/can_assert.c | 3 +++ Lib/Peripherals/CubeCAN/Src/can_rx.c | 6 +++--- 9 files changed, 59 insertions(+), 22 deletions(-) diff --git a/CUBEMXTESTING/Application/Inc/CANdler.h b/CUBEMXTESTING/Application/Inc/CANdler.h index bd67e5959..5c4a98ab6 100644 --- a/CUBEMXTESTING/Application/Inc/CANdler.h +++ b/CUBEMXTESTING/Application/Inc/CANdler.h @@ -3,6 +3,6 @@ #ifndef CANDLER_H #define CANDLER_H -void CANdler_Callback(CubeCAN_Handle *const handle, void *const user_context); +void CANdler_Callback(const CubeCAN_Config_Context *const context, const CAN_Identifier *const identifier, const uint8_t *const data, const uint8_t size); #endif diff --git a/CUBEMXTESTING/Application/Src/CANdler.c b/CUBEMXTESTING/Application/Src/CANdler.c index 524b95617..942698bdb 100644 --- a/CUBEMXTESTING/Application/Src/CANdler.c +++ b/CUBEMXTESTING/Application/Src/CANdler.c @@ -1,9 +1,22 @@ #include "CANdler.h" #include "CubeCAN.h" +#include "GRCAN_BUS_ID.h" +#include "GRCAN_MSG_ID.h" +#include "GRCAN_NODE_ID.h" +#include "Logomatic.h" -void CANdler_Callback(CubeCAN_Handle *const handle, void *const user_context) +void CANdler_Callback(const CubeCAN_Config_Context *const context, const CAN_Identifier *const identifier, const uint8_t *const data, const uint8_t size) { - LOGOMATIC("CANdler_Callback: Received CAN message on handle %p with user context %p\n", (void *)handle, user_context); - // TODO + if (context == NULL || identifier == NULL || data == NULL || size == 0) { + LOGOMATIC("CANdler_Callback: Invalid parameters received. context: %u, identifier: %p, data: %p, size: %u\n", context->busid_user_context, (void* const)identifier, (void* const)data, size); + return; + } + + const GRCAN_BUS_ID busid = context->busid_user_context; + const GRCAN_NODE_ID tx_node = identifier->tx_node_id; + const GRCAN_NODE_ID rx_node = identifier->rx_node_id; + const GRCAN_MSG_ID msg_id = identifier->msg_id; + + LOGOMATIC("Received on bus %d with node %d -> %d with message %d and size %u\t%.*s\n", busid, tx_node, rx_node, msg_id, size, size, (const char *const)data); } diff --git a/CUBEMXTESTING/Application/Src/loop.c b/CUBEMXTESTING/Application/Src/loop.c index 5e1d17751..8bcc98306 100644 --- a/CUBEMXTESTING/Application/Src/loop.c +++ b/CUBEMXTESTING/Application/Src/loop.c @@ -1,17 +1,13 @@ #include "loop.h" #include "Logomatic.h" +#include "CubeCAN.h" #include "main.h" +#include "GRCAN_NODE_ID.h" +#include "GRCAN_MSG_ID.h" void MainLoop(void) { LL_GPIO_TogglePin(USER_LED_GPIO_Port, USER_LED_Pin); - - if (LL_GPIO_IsInputPinSet(USER_BUTTON_GPIO_Port, USER_BUTTON_Pin)) { - LL_GPIO_SetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - } else { - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - } - - LOGOMATIC("Doing things!\n"); + CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello!", 6); } diff --git a/CUBEMXTESTING/CMakeLists.txt b/CUBEMXTESTING/CMakeLists.txt index cef556784..4c1cda4dc 100644 --- a/CUBEMXTESTING/CMakeLists.txt +++ b/CUBEMXTESTING/CMakeLists.txt @@ -26,6 +26,7 @@ add_library(${PROJECT_NAME}_USER_CODE INTERFACE) target_sources( ${PROJECT_NAME}_USER_CODE INTERFACE + Application/Src/CANdler.c Application/Src/loop.c Core/Src/fdcan.c Core/Src/gpio.c diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index 50f780d60..1124cc1de 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -49,7 +49,7 @@ extern "C" { /* Exported types ------------------------------------------------------------*/ /* USER CODE BEGIN ET */ - +extern CubeCAN_Handle *primaryHandle; /* USER CODE END ET */ /* Exported constants --------------------------------------------------------*/ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 04eb5e22d..1292223c6 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -27,6 +27,8 @@ /* USER CODE BEGIN Includes */ #include "CANdler.h" #include "CubeCAN.h" +#include "GRCAN_BUS_ID.h" +#include "GRCAN_NODE_ID.h" #include "Logomatic.h" #include "loop.h" #include "tim.h" @@ -54,6 +56,8 @@ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ +CubeCAN_Handle *primaryHandle = NULL; + LogomaticConfig logomaticConfig = {.clock_source = LOGOMATIC_PCLK1, .bus = LOGOMATIC_BUS, .gpio_port = LOGOMATIC_GPIOA, @@ -116,9 +120,12 @@ int main(void) /* USER CODE BEGIN 2 */ Setup_Logomatic(&logomaticConfig); - CubeCAN_Config can_config = {.rx_callback = CANdler_Callback, .user_context = (void *)1}; - - CubeCAN_Init(&hfdcan1, &can_config); + CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; + primaryHandle = CubeCAN_Init(&hfdcan1, &primaryCanConfig); + if (primaryHandle == NULL) { + LOGOMATIC("Failed to initialize primary CAN handle\n"); + Error_Handler(); + } /* USER CODE END 2 */ /* Infinite loop */ diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h b/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h index 2727db147..a85658c2e 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h @@ -3,6 +3,7 @@ #include #include "CubeCAN_Config.h" +#include "GRCAN_BUS_ID.h" #include "GRCAN_CUSTOM_ID.h" #include "GRCAN_MSG_ID.h" #include "GRCAN_NODE_ID.h" @@ -32,6 +33,22 @@ typedef struct { GRCAN_MSG_ID msg_id; } CAN_Identifier; +/** + * @brief Union for user-defined context data in CubeCAN configuration. + * + * This union allows for flexible user-defined context data to be passed to the receive callback function. It can hold either a pointer to any user-defined data or a specific GRCAN_BUS_ID value. + * + * @warning The union should be used carefully to ensure that the correct type of data is accessed in the callback function. + * + * @note Compile time checks verify that GRCAN_BUS_ID is the same size or smaller than the pointer, ensuring safe usage of the union. + */ +typedef union { + /// @brief Pointer to user-defined context data. This can be used to pass additional data or state information to the receive callback function. + void *full_user_context; + /// @brief GRCAN_BUS_ID value for user-defined context data. This can be used to pass the bus ID to the receive callback function. + GRCAN_BUS_ID busid_user_context; +} CubeCAN_Config_Context; + /** * @brief Callback function type for receiving CAN messages. * @@ -39,7 +56,7 @@ typedef struct { * @warning The callback function should not call any CubeCAN functions, as it may lead to undefined behavior. * @warning It is the responsibility of the callback function to verify the integrity of the received data and handle any errors or null inputs. */ -typedef void (*CubeCAN_RxCallback)(const void *const user_context, const CAN_Identifier *const identifier, const uint8_t *const data, const uint8_t size); +typedef void (*CubeCAN_RxCallback)(const CubeCAN_Config_Context *const context, const CAN_Identifier *const identifier, const uint8_t *const data, const uint8_t size); /** * @brief Configuration structure for CubeCAN CAN. @@ -50,8 +67,8 @@ typedef void (*CubeCAN_RxCallback)(const void *const user_context, const CAN_Ide * @warning Do not edit after initialization, as it may lead to undefined behavior. */ typedef struct { - /// @brief User-defined context pointer that can be passed to the receive callback function. This can be used to pass additional data or state information to the callback function. - void *user_context; + /// @brief Union for user-defined context data. This can be used to pass additional data or state information to the receive callback function. + CubeCAN_Config_Context context; /// @brief Callback function for receiving CAN messages. This function is called when a CAN message is received. CubeCAN_RxCallback rx_callback; /// @brief Node ID of the sending device. This is used to identify the source of the CAN messages and must be unique on the CAN bus. diff --git a/Lib/Peripherals/CubeCAN/Src/can_assert.c b/Lib/Peripherals/CubeCAN/Src/can_assert.c index 05d94fa2b..107db57b6 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_assert.c +++ b/Lib/Peripherals/CubeCAN/Src/can_assert.c @@ -6,6 +6,7 @@ #include "CriticalSection.h" #include "CubeCAN.h" #include "CubeCAN_Config.h" +#include "GRCAN_BUS_ID.h" #include "PrivateInc/internal.h" #include "main.h" @@ -23,3 +24,5 @@ static_assert(ATOMIC_BOOL_LOCK_FREE == 2, "CubeCAN internal ATOMIC_BOOL_LOCK_FRE static_assert((CUBEMX_CAN_TX_QUEUE_SIZE > 0) && !(CUBEMX_CAN_TX_QUEUE_SIZE & (CUBEMX_CAN_TX_QUEUE_SIZE - 1U)), "CUBEMX_CAN_TX_QUEUE_SIZE must be a power of two and greater than zero"); static_assert(CUBEMX_CAN_MAX_INSTANCES >= 1 && CUBEMX_CAN_MAX_INSTANCES <= 3, "CUBEMX_CAN_MAX_INSTANCES must be configured between 1 and 3 inclusive"); + +static_assert(sizeof(GRCAN_BUS_ID) <= sizeof(void *), "GRCAN_BUS_ID must fit within a pointer-sized type to support being unioned with a pointer in CubeCAN_Config"); diff --git a/Lib/Peripherals/CubeCAN/Src/can_rx.c b/Lib/Peripherals/CubeCAN/Src/can_rx.c index da833491f..f37912f01 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_rx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_rx.c @@ -18,7 +18,7 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) return; } - const void *user_context = NULL; + CubeCAN_Config_Context context; CubeCAN_RxCallback rx_callback = NULL; bool is_started = false; @@ -26,7 +26,7 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) { for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { if (handles[i].hfdcan == hfdcan) { - user_context = handles[i].config.user_context; + context = handles[i].config.context; rx_callback = handles[i].config.rx_callback; is_started = handles[i].started; break; @@ -53,7 +53,7 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &rx_header, rx_data) == HAL_OK) { CAN_Identifier id = CubeCAN_Deconstruct_Identifier(rx_header.Identifier); uint8_t size = CubeCAN_Private_DlcToBytes(rx_header.DataLength); - rx_callback(user_context, &id, rx_data, size); + rx_callback(&context, &id, rx_data, size); } else { LOGOMATIC("HAL_FDCAN_RxFifo0Callback: Failed to get Rx message from FIFO\n"); break; From d1536618ecf701b752c3ac215fb57aef48fb759a Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 14 Aug 2026 04:04:49 -0700 Subject: [PATCH 044/125] Remove last bit of VCP Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Application/Inc/vcp_config.h | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 CUBEMXTESTING/Application/Inc/vcp_config.h diff --git a/CUBEMXTESTING/Application/Inc/vcp_config.h b/CUBEMXTESTING/Application/Inc/vcp_config.h deleted file mode 100644 index 77a62a7f7..000000000 --- a/CUBEMXTESTING/Application/Inc/vcp_config.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef VCP_CONFIG -#define VCP_CONFIG - -#define VCP_CONFIG_CLAIM_USART2 - -#define VCP_TX_BUFFER_SIZE 128 - -#endif From 6334fe9fe1e980aa2ab795d7cb16c4cf32f3e2e8 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 14 Aug 2026 04:05:34 -0700 Subject: [PATCH 045/125] Rename loop file Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Application/Inc/{loop.h => Loop.h} | 0 CUBEMXTESTING/Application/Src/{loop.c => Loop.c} | 8 ++++---- CUBEMXTESTING/CMakeLists.txt | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) rename CUBEMXTESTING/Application/Inc/{loop.h => Loop.h} (100%) rename CUBEMXTESTING/Application/Src/{loop.c => Loop.c} (93%) diff --git a/CUBEMXTESTING/Application/Inc/loop.h b/CUBEMXTESTING/Application/Inc/Loop.h similarity index 100% rename from CUBEMXTESTING/Application/Inc/loop.h rename to CUBEMXTESTING/Application/Inc/Loop.h diff --git a/CUBEMXTESTING/Application/Src/loop.c b/CUBEMXTESTING/Application/Src/Loop.c similarity index 93% rename from CUBEMXTESTING/Application/Src/loop.c rename to CUBEMXTESTING/Application/Src/Loop.c index 8bcc98306..fc19148fc 100644 --- a/CUBEMXTESTING/Application/Src/loop.c +++ b/CUBEMXTESTING/Application/Src/Loop.c @@ -1,10 +1,10 @@ -#include "loop.h" +#include "Loop.h" -#include "Logomatic.h" #include "CubeCAN.h" -#include "main.h" -#include "GRCAN_NODE_ID.h" #include "GRCAN_MSG_ID.h" +#include "GRCAN_NODE_ID.h" +#include "Logomatic.h" +#include "main.h" void MainLoop(void) { diff --git a/CUBEMXTESTING/CMakeLists.txt b/CUBEMXTESTING/CMakeLists.txt index 4c1cda4dc..138e7c9ea 100644 --- a/CUBEMXTESTING/CMakeLists.txt +++ b/CUBEMXTESTING/CMakeLists.txt @@ -27,7 +27,8 @@ target_sources( ${PROJECT_NAME}_USER_CODE INTERFACE Application/Src/CANdler.c - Application/Src/loop.c + Application/Src/Loop.c + Core/Src/fdcan.c Core/Src/gpio.c Core/Src/main.c From e7e54eb5196dcde6ea6cf784b6b301f6450bacc5 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 14 Aug 2026 04:05:52 -0700 Subject: [PATCH 046/125] Missed a loop rename Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Core/Src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 1292223c6..bb8bc3eff 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -30,7 +30,7 @@ #include "GRCAN_BUS_ID.h" #include "GRCAN_NODE_ID.h" #include "Logomatic.h" -#include "loop.h" +#include "Loop.h" #include "tim.h" // #include "can.h" From 9660bf3a7890ee3a1790ad607dd7f960582d4579 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 14 Aug 2026 06:01:13 -0700 Subject: [PATCH 047/125] Documentation Signed-off-by: Daniel Hansen --- .../Application/Inc/CubeCAN_Config.h | 3 - CUBEMXTESTING/Core/Src/main.c | 2 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 191 +++++++++--------- Lib/Peripherals/CubeCAN/Inc/CubeCAN.h | 53 +---- Lib/Peripherals/CubeCAN/README.md | 133 ++++++++++++ .../CubeCAN/Src/PrivateInc/internal.h | 29 +++ Lib/Peripherals/CubeCAN/Src/can_global.c | 2 + Lib/Peripherals/CubeCAN/Src/can_init.c | 38 ++-- Lib/Peripherals/CubeCAN/Src/can_utils.c | 35 ---- Lib/Peripherals/CubeCAN/cube_can.cmake | 4 - 10 files changed, 282 insertions(+), 208 deletions(-) create mode 100644 Lib/Peripherals/CubeCAN/README.md diff --git a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h index ca7e395e1..b582cbc55 100644 --- a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h +++ b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h @@ -1,9 +1,6 @@ #ifndef CUBE_CAN_CONFIG_H #define CUBE_CAN_CONFIG_H -#include "GRCAN_NODE_ID.h" -#include "main.h" - #define CUBEMX_CAN_TX_QUEUE_SIZE 16U #define CUBEMX_CAN_MAX_INSTANCES 1U diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index bb8bc3eff..8c0ec79a2 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -121,7 +121,7 @@ int main(void) Setup_Logomatic(&logomaticConfig); CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; - primaryHandle = CubeCAN_Init(&hfdcan1, &primaryCanConfig); + primaryHandle = CubeCAN_Entrance(&hfdcan1, &primaryCanConfig); if (primaryHandle == NULL) { LOGOMATIC("Failed to initialize primary CAN handle\n"); Error_Handler(); diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index b4fb77dff..d941a1d07 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -1,25 +1,26 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file stm32g4xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file stm32g4xx_it.c + * @brief Interrupt Service Routines. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "stm32g4xx_it.h" + +#include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -64,131 +65,125 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @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 */ + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -199,17 +194,17 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + CubeCAN_Tick(); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h b/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h index a85658c2e..9af5ece36 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h @@ -80,56 +80,18 @@ typedef struct { * @param hfdcan Pointer to the FDCAN handle. * @param config Pointer to the CubeCAN configuration structure. * @return Pointer to the initialized CubeCAN CAN handle, or NULL if initialization fails. - * @note This functions wraps CubeCAN_Init and CubeCAN_Start into a single call. If either of those functions fails, this function will return NULL and the handle will be released. + * @note This functions wraps CubeCAN_Private_Init and CubeCAN_Private_Start into a single call. If either of those functions fails, this function will return NULL and the handle will be + * released. */ -CubeCAN_Handle *CubeCAN_OneShotInitStart(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config); +CubeCAN_Handle *CubeCAN_Entrance(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config); /** * @brief Stops the CubeCAN CAN peripheral and releases the associated handle. * @param handle Pointer to the CubeCAN CAN handle. * @return HAL_StatusTypeDef indicating the success or failure of the operation. - * @note This functions wraps CubeCAN_Stop and CubeCAN_Release into a single call. If either of those functions fails, this function will return the error code and the handle will - * not be released. - * @note This function can be used regardless of if CubeCAN_OneShotInitStart was used to initialize the handle. + * @note This function can be used regardless of if CubeCAN_Entrance was used to initialize the handle. */ -HAL_StatusTypeDef CubeCAN_OneShotReleaseStop(CubeCAN_Handle *handle); - -/** - * @brief Initializes a CubeCAN CAN handle with the given FDCAN handle and configuration. - * @param hfdcan Pointer to the FDCAN handle. - * @param config Pointer to the CubeCAN configuration structure. - * @return Pointer to the initialized CubeCAN CAN handle, or NULL if initialization fails. - */ -CubeCAN_Handle *CubeCAN_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config); - -/** - * @brief Starts the CubeCAN CAN handle, enabling message transmission and reception. - * @param handle Pointer to the CubeCAN CAN handle. - * @return HAL_StatusTypeDef indicating the success or failure of the operation. - */ -HAL_StatusTypeDef CubeCAN_Start(CubeCAN_Handle *const handle); - -/** - * @brief Stops the CubeCAN CAN handle, disabling message transmission and reception. - * @param handle Pointer to the CubeCAN CAN handle. - * @return HAL_StatusTypeDef indicating the success or failure of the operation. - */ -HAL_StatusTypeDef CubeCAN_Stop(CubeCAN_Handle *const handle); - -/** - * @brief Releases the resources associated with the CubeCAN CAN handle. - * @param handle Pointer to the CubeCAN CAN handle. - * @return HAL_StatusTypeDef indicating the success or failure of the operation. - */ -HAL_StatusTypeDef CubeCAN_Release(CubeCAN_Handle *const handle); - -/** - * @brief Adds a filter to the CubeCAN CAN handle, allowing for selective message reception based on the specified filter criteria. - * @param handle Pointer to the CubeCAN CAN handle. - * @param filter Pointer to the FDCAN filter configuration structure. - * @return HAL_StatusTypeDef indicating the success or failure of the operation. - */ -HAL_StatusTypeDef CubeCAN_AddFilter(const CubeCAN_Handle *const handle, const FDCAN_FilterTypeDef *const filter); +HAL_StatusTypeDef CubeCAN_Exit(CubeCAN_Handle *handle); /** * @brief Processes periodic tasks for the CubeCAN CAN handle, such as handling timeouts and managing the transmission queue. @@ -170,9 +132,4 @@ uint32_t CubeCAN_Construct_Identifier(const CAN_Identifier *const identifier); */ CAN_Identifier CubeCAN_Deconstruct_Identifier(const uint32_t message_id); -/** - * @brief Builds an exact-match extended-ID filter for a given CAN identifier. - */ -HAL_StatusTypeDef CubeCAN_BuildExtendedFilter(const CAN_Identifier *const identifier, const uint32_t filter_index, const uint32_t fifo, FDCAN_FilterTypeDef *const filter); - #endif diff --git a/Lib/Peripherals/CubeCAN/README.md b/Lib/Peripherals/CubeCAN/README.md new file mode 100644 index 000000000..f8f69122c --- /dev/null +++ b/Lib/Peripherals/CubeCAN/README.md @@ -0,0 +1,133 @@ +# Cube CAN + +Support for STM32CubeMX and CAN. See [`CUBEMX.md`](../../../CUBEMX.md) for background. + +## Overview + +Use STM32CubeMX to setup the CAN peripheral, then call `CubeCAN_Entrance` on it after HAL initializes the peripheral. +Save the handle that function returns and use that to send messages. Recieve messages on your function callback. + +> [!IMPORTANT] +> It is recommended to have your Rx callback function primarily be a switch case off of the message ID. +> +> Your `CubeCAN_RxCallback` function must run quickly, it is inside of a low level ISR. + +## Setup + +### 1. CMake + +Add `CUBEMX_CAN_LIB` as an interface target link library within your project. + +### 2. Configuration + +Add a file named `CubeCAN_Config.h` to your project (generally `Application/Inc/CubeCAN_Config.h`) that has the following symbols defined + +```c +#ifndef CUBE_CAN_CONFIG_H +#define CUBE_CAN_CONFIG_H + +#define CUBEMX_CAN_TX_QUEUE_SIZE 16U +#define CUBEMX_CAN_MAX_INSTANCES 1U + +#endif +``` + +Note that `CUBEMX_CAN_TX_QUEUE_SIZE` must be a multiple of two and `CUBEMX_CAN_MAX_INSTANCES` must be valid for that chip. + +From there just ensure that you have configured CAN through STM32CubeMX and setup a global variable for each `CubeCAN_Handle` you wish to use. + +### 3. Entrance + +Make sure to `#include "CubeCAN.h"` where needed. Do not include `PrivateInc\internal.h` outside of the peripheral source files. + +At the end of your STM32CubeMX-generated `MX_FDCAN#_Init` function configure your filters as needed with `HAL_FDCAN_ConfigFilter` + +Within `main` after `MX_FDCAN#_Init` and `LOGOMATIC` are setup (see [Logomatic](../../Utils/Logomatic/README.md)) call `CubeCAN_Entrance` saving the handle for global use later (one entrance and handle per peripheral) + +Double check you have setup some manner to call `CubeCAN_Tick` often (a STM32CubeMX timer is recommended), it can start running at any point in execution + +### 4. Transmission / Reception + +If you are frequently calling `CubeCAN_Tick` then as you call `CubeCAN_Send` messages will be transmitted once per bus per tick + +Your provided callback `CubeCAN_RxCallback` will be triggered with messages that pass any filters you setup + +## Architecture + +```mermaid +flowchart TD + classDef lib fill:#1e40af,stroke:#bfdbfe,color:#ffffff; + classDef cubemx fill:#5b21b6,stroke:#ddd6fe,color:#ffffff; + classDef internal fill:#F0E442,stroke:#333,color:#333; + classDef other fill:#c2410c,stroke:#fed7aa,color:#ffffff; + + MXInit(["MX_FDCAN#_Init"]) -->Entrance("CubeCAN_Entrance") + MXInit --> Filter("HAL_FDCAN_\nConfigFilter") + Filter --> Filter + Filter --> Entrance + Entrance --> Choice{"Functions"} + Choice --> Exit(["CubeCAN_Exit"]) + Exit -.-> |"AVOID"| Entrance + Choice --> Send(["CubeCAN_Send"]) + Choice --> |"Call Often\n(User Setup)"| Tick(["CubeCAN_Tick"]) + Send -.-> Queue("CubeCAN_Private_QueueTx") + Data -.-> Tick + Queue -.-> Data{"Internal Queue"} + Tick -.-> Tx(["CubeCAN_Private\n_SendQueuedMessage"]) + Data -.-> Tx + Tx -.->|"HAL_FDCAN_\nAddMessageToTxFifoQ"| Sent(["Transmitted over bus!"]) + Choice -.->|"HAL Interrupt"| Recieved + Recieved(["Recieved over bus!"]) -.->|"HAL_FDCAN_\nRxFifo0Callback\n\nHAL_FDCAN_\nGetRxMessage"| Get(["CubeCAN_RxCallback"]) + + class MXInit cubemx; + class Filter cubemx; + class Entrance lib; + class Exit lib; + class Send lib; + class Queue internal; + class Tick lib; + class Tx internal; + class Choice other; + class Data other; + class Sent other; + class Recieved other; + class Get lib; +``` + +## Advanced + +### Rx Callback Context + +You may find it helpful to have just one Rx callback function instead of one per handle + +You can do this by providing the same `CubeCAN_RxCallback` function pointer for each handle and specifying a `CubeCAN_Config_Context` per handle. + +`CubeCAN_Config_Context` supports both `GRCAN_BUS_ID` and arbitrary void pointers thanks to a unioned field which is type checked at compile time + +Note that it is your responsibility to use either the void pointers or `GRCAN_BUS_ID` values, the peripheral treats this as a magic +32-bit value, the union is provided for your convenience for common cases (recieving messages from both a subnet and the proper bus +OR recieving messages from multiple buses) + +### Tx Message Marker + +TODO + +Currently we do not do anything cool with this, but we could! + +### Assertions + +We currently provide compile time static assertions to validate: + +- Memory alignment of 32 bits for `tx_head` and `tx_tail` +- Struct alignment of >=4 bytes for `GRCAN_Private_TxMessage` and `CubeCAN_Private_Handle` +- Union compatibility for types `GRCAN_BUS_ID` and `void*` +- Lock free atomic operations for integers and booleans guaranteed by the compiler +- `CUBEMX_CAN_TX_QUEUE_SIZE` is a power of two and non-zero (allows faster ring-buffer wrapping) +- `CUBEMX_CAN_MAX_INSTANCES` requires management of 1 to 3 interfaces (optional parameter, otherwise automatically chooses the maximum possible) + +### Globals + +We store a global private array of CubeCAN handles (sized to `CUBEMX_CAN_MAX_INSTANCES`) + +Main point of allowing user provided `CUBEMX_CAN_MAX_INSTANCES` values is that each handle is 28 bytes not including the queue size, +but if you add a large queue on a chip that supports three CANFD peripherals and only need one peripherals that is a lot of wasted memory. diff --git a/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h b/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h index 93e15d892..84afa706c 100644 --- a/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h +++ b/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h @@ -145,4 +145,33 @@ uint8_t CubeCAN_Private_DlcToBytes(const uint32_t dlc); */ uint8_t CubeCAN_Private_BytesToDlc(const uint8_t bytes); +/** + * @brief Initializes a CubeCAN CAN handle with the given FDCAN handle and configuration. + * @param hfdcan Pointer to the FDCAN handle. + * @param config Pointer to the CubeCAN configuration structure. + * @return Pointer to the initialized CubeCAN CAN handle, or NULL if initialization fails. + */ +CubeCAN_Handle *CubeCAN_Private_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config); + +/** + * @brief Starts the CubeCAN CAN handle, enabling message transmission and reception. + * @param handle Pointer to the CubeCAN CAN handle. + * @return HAL_StatusTypeDef indicating the success or failure of the operation. + */ +HAL_StatusTypeDef CubeCAN_Private_Start(CubeCAN_Handle *const handle); + +/** + * @brief Stops the CubeCAN CAN handle, disabling message transmission and reception. + * @param handle Pointer to the CubeCAN CAN handle. + * @return HAL_StatusTypeDef indicating the success or failure of the operation. + */ +HAL_StatusTypeDef CubeCAN_Private_Stop(CubeCAN_Handle *const handle); + +/** + * @brief Releases the resources associated with the CubeCAN CAN handle. + * @param handle Pointer to the CubeCAN CAN handle. + * @return HAL_StatusTypeDef indicating the success or failure of the operation. + */ +HAL_StatusTypeDef CubeCAN_Private_Release(CubeCAN_Handle *const handle); + #endif diff --git a/Lib/Peripherals/CubeCAN/Src/can_global.c b/Lib/Peripherals/CubeCAN/Src/can_global.c index 254508f25..c573f8f67 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_global.c +++ b/Lib/Peripherals/CubeCAN/Src/can_global.c @@ -7,3 +7,5 @@ #include "PrivateInc/internal.h" struct CubeCAN_Private_Handle handles[CUBEMX_CAN_MAX_INSTANCES] = {0}; + +int five = sizeof(handles); diff --git a/Lib/Peripherals/CubeCAN/Src/can_init.c b/Lib/Peripherals/CubeCAN/Src/can_init.c index 469118e5a..f10e27711 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_init.c +++ b/Lib/Peripherals/CubeCAN/Src/can_init.c @@ -9,45 +9,45 @@ #include "PrivateInc/internal.h" #include "main.h" -CubeCAN_Handle *CubeCAN_OneShotInitStart(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config) +CubeCAN_Handle *CubeCAN_Entrance(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config) { - CubeCAN_Handle *handle = CubeCAN_Init(hfdcan, config); + CubeCAN_Handle *handle = CubeCAN_Private_Init(hfdcan, config); if (handle == NULL) { - LOGOMATIC("CubeCAN_OneShotInit: failed to initialize handle\n"); + LOGOMATIC("CubeCAN_Entrance: failed to initialize handle\n"); return NULL; } - if (CubeCAN_Start(handle) != HAL_OK) { - LOGOMATIC("CubeCAN_OneShotInit: failed to start handle\n"); - CubeCAN_Release(handle); + if (CubeCAN_Private_Start(handle) != HAL_OK) { + LOGOMATIC("CubeCAN_Entrance: failed to start handle\n"); + CubeCAN_Private_Release(handle); return NULL; } return handle; } -HAL_StatusTypeDef CubeCAN_OneShotReleaseStop(CubeCAN_Handle *handle) +HAL_StatusTypeDef CubeCAN_Exit(CubeCAN_Handle *handle) { if (handle == NULL) { - LOGOMATIC("CubeCAN_OneShotReleaseStop: invalid null parameter\n"); + LOGOMATIC("CubeCAN_Exit: invalid null parameter\n"); return HAL_ERROR; } - HAL_StatusTypeDef status = CubeCAN_Stop(handle); + HAL_StatusTypeDef status = CubeCAN_Private_Stop(handle); if (status != HAL_OK) { - LOGOMATIC("CubeCAN_OneShotReleaseStop: failed to stop FDCAN instance\n"); + LOGOMATIC("CubeCAN_Exit: failed to stop FDCAN instance\n"); return status; } - return CubeCAN_Release(handle); + return CubeCAN_Private_Release(handle); } -CubeCAN_Handle *CubeCAN_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config) +CubeCAN_Handle *CubeCAN_Private_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config) { if (hfdcan == NULL || config == NULL) { - LOGOMATIC("CubeCAN_Init: invalid null parameters\n"); + LOGOMATIC("CubeCAN_Private_Init: invalid null parameters\n"); return NULL; } @@ -66,7 +66,7 @@ CubeCAN_Handle *CubeCAN_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config } if (handle != NULL) { - LOGOMATIC("CubeCAN_Init: handle already initialized for this FDCAN instance\n"); + LOGOMATIC("CubeCAN_Private_Init: handle already initialized for this FDCAN instance\n"); return NULL; } else if (free_handle_index != (uint8_t)-1) { handle = &handles[free_handle_index]; @@ -80,12 +80,12 @@ CubeCAN_Handle *CubeCAN_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config } if (handle == NULL) { - LOGOMATIC("CubeCAN_Init: no free handle slots\n"); + LOGOMATIC("CubeCAN_Private_Init: no free handle slots\n"); return NULL; } if (HAL_FDCAN_ActivateNotification(hfdcan, FDCAN_IT_RX_EVENTS, 0U) != HAL_OK) { - LOGOMATIC("CubeCAN_Init: failed to activate RX notifications\n"); + LOGOMATIC("CubeCAN_Private_Init: failed to activate RX notifications\n"); CRITICAL_SECTION { memset(handle, 0, sizeof(*handle)); @@ -96,7 +96,7 @@ CubeCAN_Handle *CubeCAN_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config return handle; } -HAL_StatusTypeDef CubeCAN_Release(CubeCAN_Handle *handle) +HAL_StatusTypeDef CubeCAN_Private_Release(CubeCAN_Handle *handle) { if (handle == NULL) { return HAL_ERROR; @@ -142,7 +142,7 @@ HAL_StatusTypeDef CubeCAN_Release(CubeCAN_Handle *handle) return HAL_OK; } -HAL_StatusTypeDef CubeCAN_Start(CubeCAN_Handle *const handle) +HAL_StatusTypeDef CubeCAN_Private_Start(CubeCAN_Handle *const handle) { if (handle == NULL) { return HAL_ERROR; @@ -175,7 +175,7 @@ HAL_StatusTypeDef CubeCAN_Start(CubeCAN_Handle *const handle) return status; } -HAL_StatusTypeDef CubeCAN_Stop(CubeCAN_Handle *const handle) +HAL_StatusTypeDef CubeCAN_Private_Stop(CubeCAN_Handle *const handle) { if (handle == NULL) { return HAL_ERROR; diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index 44e26e61a..69dbc3018 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -37,41 +37,6 @@ CAN_Identifier CubeCAN_Deconstruct_Identifier(const uint32_t message_id) return (CAN_Identifier){.tx_node_id = tx_node_id, .msg_id = msg_id, .rx_node_id = rx_node_id}; } -HAL_StatusTypeDef CubeCAN_BuildExtendedFilter(const CAN_Identifier *const identifier, const uint32_t filter_index, const uint32_t fifo, FDCAN_FilterTypeDef *const filter) -{ - if (identifier == NULL || filter == NULL) { - return HAL_ERROR; - } - - filter->IdType = FDCAN_EXTENDED_ID; - filter->FilterIndex = filter_index; - filter->FilterType = FDCAN_FILTER_MASK; - filter->FilterConfig = fifo; - filter->FilterID1 = CubeCAN_Construct_Identifier(identifier); - filter->FilterID2 = 0x1FFFFFFFU; - - return HAL_OK; -} - -HAL_StatusTypeDef CubeCAN_AddFilter(const CubeCAN_Handle *const handle, const FDCAN_FilterTypeDef *filter) -{ - if (handle == NULL || filter == NULL) { - LOGOMATIC("CubeCAN_AddFilter: Invalid handle or filter pointer\n"); - return HAL_ERROR; - } - - HAL_StatusTypeDef status = HAL_ERROR; - - CRITICAL_SECTION - { - if (handle->hfdcan != NULL) { - status = HAL_FDCAN_ConfigFilter(handle->hfdcan, filter); - } - } - - return status; -} - uint8_t CubeCAN_Private_BytesToDlc(const uint8_t bytes) { switch (bytes) { diff --git a/Lib/Peripherals/CubeCAN/cube_can.cmake b/Lib/Peripherals/CubeCAN/cube_can.cmake index 998f3da0c..64b201d7d 100644 --- a/Lib/Peripherals/CubeCAN/cube_can.cmake +++ b/Lib/Peripherals/CubeCAN/cube_can.cmake @@ -23,7 +23,3 @@ target_link_libraries( CANfigurator LOGOMATIC_LIB ) - -if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") - # FIXME Add HOOTL tests -endif() From f4a287bd3458d5fc231a42da331aea475b69fbfa Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 14 Aug 2026 06:07:11 -0700 Subject: [PATCH 048/125] Documentation tweaks Signed-off-by: Daniel Hansen --- Lib/Peripherals/CubeCAN/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/Peripherals/CubeCAN/README.md b/Lib/Peripherals/CubeCAN/README.md index f8f69122c..b47976009 100644 --- a/Lib/Peripherals/CubeCAN/README.md +++ b/Lib/Peripherals/CubeCAN/README.md @@ -8,7 +8,7 @@ Use STM32CubeMX to setup the CAN peripheral, then call `CubeCAN_Entrance` on it Save the handle that function returns and use that to send messages. Recieve messages on your function callback. > [!IMPORTANT] -> It is recommended to have your Rx callback function primarily be a switch case off of the message ID. +> We recommend that your recieved message callback function is a switch-case off of the message ID that does nothing more than writing to memory. > > Your `CubeCAN_RxCallback` function must run quickly, it is inside of a low level ISR. @@ -96,6 +96,12 @@ flowchart TD ## Advanced +### Filters + +Filters are on the user to setup and manage, it is recommended to setup a filter to ignore messsages not intended for your bord + +You have direct access to define `HAL_FDCAN_RxFifo1Callback` as you like as well, the peripheral only uses `HAL_FDCAN_RxFifo0Callback` for all buses + ### Rx Callback Context You may find it helpful to have just one Rx callback function instead of one per handle From cede426bcce67fa39e415f819ee386ba584e5df8 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 14 Aug 2026 06:08:59 -0700 Subject: [PATCH 049/125] Fix tx message marker doc Signed-off-by: Daniel Hansen --- Lib/Peripherals/CubeCAN/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/Peripherals/CubeCAN/README.md b/Lib/Peripherals/CubeCAN/README.md index b47976009..22de4b72b 100644 --- a/Lib/Peripherals/CubeCAN/README.md +++ b/Lib/Peripherals/CubeCAN/README.md @@ -116,10 +116,10 @@ OR recieving messages from multiple buses) ### Tx Message Marker -TODO - Currently we do not do anything cool with this, but we could! +If you would like to see this do something please open an Issue (and if you want to code it, a PR as well) + ### Assertions We currently provide compile time static assertions to validate: From f5df570f0e52f2c880922835f717a46aef7cca79 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Fri, 14 Aug 2026 06:19:56 -0700 Subject: [PATCH 050/125] Interrupt safety docs Signed-off-by: Daniel Hansen --- Lib/Peripherals/CubeCAN/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Lib/Peripherals/CubeCAN/README.md b/Lib/Peripherals/CubeCAN/README.md index 22de4b72b..730a9faf0 100644 --- a/Lib/Peripherals/CubeCAN/README.md +++ b/Lib/Peripherals/CubeCAN/README.md @@ -96,6 +96,20 @@ flowchart TD ## Advanced +### Interrupt Safety + +We use atomic operations and locks to ensure that we do not operate on broken data. + +Locks are handled through [`CriticalSection.h`](../../GlobalShare/Inc/CriticalSection.h) which block interrupts from running for a +scope and automatically clean themselves up nicely if something strange happens internally thanks to the GCC cleanup attribute. + +Currently the only atomic variables are `tx_head` and `tx_tail` as members of the handle, these manage the transmission queue and +need to be quite robust in case someone decides they want to send a CAN message inside a `CubeCAN_RxCallback` ISR (nobody should be +doing that, but if they do it needs to work) + +Since we have atomic variables we require `CUBEMX_CAN_TX_QUEUE_SIZE` to be a power of two so that we can do quick bitwise math on it +instead of waiting for a slower compare and swap (CAS) loop to handle the modulus operations for us to wrap around the ring-buffer + ### Filters Filters are on the user to setup and manage, it is recommended to setup a filter to ignore messsages not intended for your bord From 4447a7c4c2575ddc91b4c3435c47a2ae511287f7 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 15:49:47 -0700 Subject: [PATCH 051/125] Setup VSCode for CUBEMXTESTING Signed-off-by: Daniel Hansen --- .vscode/launch.json | 31 +++++++++++++++++++++++++++++++ .vscode/tasks.json | 9 +++++++++ 2 files changed, 40 insertions(+) diff --git a/.vscode/launch.json b/.vscode/launch.json index fc890b664..d7ec434ff 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -32,6 +32,37 @@ ] } }, + { + "cwd": "${workspaceFolder}", + "executable": "${command:cmake.buildDirectory}/CUBEMXTESTING.elf", + "name": "CUBEMXTESTING", + "request": "launch", + "type": "cortex-debug", + "servertype": "openocd", + "configFiles": [ + "interface/stlink.cfg", + "target/stm32g4x.cfg" + ], + "searchDir": [], + "preLaunchTask": "CMake: configure and build CUBEMXTESTING", + "showDevDebugOutput": "raw", + "svdPath": "${workspaceFolder}/Lib/Vendor/CMSIS_5/SVD/STM32G474.svd", + "swoConfig": { + "enabled": true, + "cpuFrequency": 160000000, + "swoFrequency": 2000000, + "source": "probe", + "decoders": [ + { + "type": "console", + "label": "ITM", + "showOnStartup": true, + "port": 0, + "encoding": "ascii" + } + ] + } + }, { "cwd": "${workspaceFolder}", "executable": "${command:cmake.buildDirectory}/CCU.elf", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index bf2d6e115..dd3358969 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -38,6 +38,15 @@ ], "command": "cmake --build --preset ${command:cmake.activeBuildPresetName} --target ECU" }, + { + "label": "CMake: configure and build CUBEMXTESTING", + "type": "shell", + "dependsOrder": "sequence", + "dependsOn": [ + "CMake: configure" + ], + "command": "cmake --build --preset ${command:cmake.activeBuildPresetName} --target CUBEMXTESTING" + }, { "label": "CMake: configure and build CCU", "type": "shell", From c8ef73b456808ecc3baaff782787da5cf5c315ec Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 16:54:00 -0700 Subject: [PATCH 052/125] Forgot to enable interrupts Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Application/Src/CANdler.c | 7 +- CUBEMXTESTING/Application/Src/Loop.c | 5 +- CUBEMXTESTING/CMakeLists.txt | 1 + CUBEMXTESTING/CUBEMXTESTING.ioc | 60 ++++-- CUBEMXTESTING/Core/Inc/main.h | 13 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 2 +- CUBEMXTESTING/Core/Inc/stm32g4xx_it.h | 3 + CUBEMXTESTING/Core/Inc/tim.h | 1 + CUBEMXTESTING/Core/Inc/usart.h | 52 +++++ CUBEMXTESTING/Core/Src/fdcan.c | 49 +++-- CUBEMXTESTING/Core/Src/gpio.c | 39 +--- CUBEMXTESTING/Core/Src/main.c | 175 +++++++++-------- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 85 +++++++++ CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 200 ++++++++++++-------- CUBEMXTESTING/Core/Src/tim.c | 34 ++-- CUBEMXTESTING/Core/Src/usart.c | 131 +++++++++++++ Lib/Peripherals/CubeCAN/Src/can_rx.c | 2 + 17 files changed, 607 insertions(+), 252 deletions(-) create mode 100644 CUBEMXTESTING/Core/Inc/usart.h create mode 100644 CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c create mode 100644 CUBEMXTESTING/Core/Src/usart.c diff --git a/CUBEMXTESTING/Application/Src/CANdler.c b/CUBEMXTESTING/Application/Src/CANdler.c index 942698bdb..8d16b7c36 100644 --- a/CUBEMXTESTING/Application/Src/CANdler.c +++ b/CUBEMXTESTING/Application/Src/CANdler.c @@ -6,10 +6,15 @@ #include "GRCAN_NODE_ID.h" #include "Logomatic.h" +int value; + void CANdler_Callback(const CubeCAN_Config_Context *const context, const CAN_Identifier *const identifier, const uint8_t *const data, const uint8_t size) { + value++; + if (context == NULL || identifier == NULL || data == NULL || size == 0) { - LOGOMATIC("CANdler_Callback: Invalid parameters received. context: %u, identifier: %p, data: %p, size: %u\n", context->busid_user_context, (void* const)identifier, (void* const)data, size); + LOGOMATIC("CANdler_Callback: Invalid parameters received. context: %u, identifier: %p, data: %p, size: %u\n", context->busid_user_context, (void *const)identifier, (void *const)data, + size); return; } diff --git a/CUBEMXTESTING/Application/Src/Loop.c b/CUBEMXTESTING/Application/Src/Loop.c index fc19148fc..d870eb4e7 100644 --- a/CUBEMXTESTING/Application/Src/Loop.c +++ b/CUBEMXTESTING/Application/Src/Loop.c @@ -6,8 +6,11 @@ #include "Logomatic.h" #include "main.h" +extern int value; + void MainLoop(void) { LL_GPIO_TogglePin(USER_LED_GPIO_Port, USER_LED_Pin); - CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello!", 6); + LOGOMATIC("Main Loop %d\n", value); + HAL_StatusTypeDef status = CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello!", 6); } diff --git a/CUBEMXTESTING/CMakeLists.txt b/CUBEMXTESTING/CMakeLists.txt index 138e7c9ea..ce6c86e0d 100644 --- a/CUBEMXTESTING/CMakeLists.txt +++ b/CUBEMXTESTING/CMakeLists.txt @@ -34,6 +34,7 @@ target_sources( Core/Src/main.c Core/Src/stm32g4xx_it.c Core/Src/tim.c + Core/Src/usart.c ) target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE CUBEMX_CAN_LIB LOGOMATIC_LIB) diff --git a/CUBEMXTESTING/CUBEMXTESTING.ioc b/CUBEMXTESTING/CUBEMXTESTING.ioc index 098aab57a..b5c76181d 100644 --- a/CUBEMXTESTING/CUBEMXTESTING.ioc +++ b/CUBEMXTESTING/CUBEMXTESTING.ioc @@ -11,7 +11,8 @@ FDCAN1.DataSyncJumpWidth=16 FDCAN1.DataTimeSeg1=14 FDCAN1.DataTimeSeg2=5 FDCAN1.ExtFiltersNbr=2 -FDCAN1.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal,NominalSyncJumpWidth,AutoRetransmission,ProtocolException,DataPrescaler,DataSyncJumpWidth,DataTimeSeg1,DataTimeSeg2,ExtFiltersNbr,NominalPrescaler,NominalTimeSeg1,NominalTimeSeg2 +FDCAN1.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal,NominalSyncJumpWidth,AutoRetransmission,ProtocolException,DataPrescaler,DataSyncJumpWidth,DataTimeSeg1,DataTimeSeg2,ExtFiltersNbr,NominalPrescaler,NominalTimeSeg1,NominalTimeSeg2,Mode +FDCAN1.Mode=FDCAN_MODE_INTERNAL_LOOPBACK FDCAN1.NominalPrescaler=1 FDCAN1.NominalSyncJumpWidth=16 FDCAN1.NominalTimeSeg1=119 @@ -39,37 +40,48 @@ FDCAN3.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,Calculat File.Version=6 GPIO.groupedBy=Group By Peripherals KeepUserPlacement=false +LPUART1.BaudRate=115200 +LPUART1.IPParameters=BaudRate Mcu.CPN=STM32G474RET6 Mcu.Family=STM32G4 Mcu.IP0=FDCAN1 Mcu.IP1=FDCAN2 Mcu.IP2=FDCAN3 -Mcu.IP3=NVIC -Mcu.IP4=RCC -Mcu.IP5=SYS -Mcu.IP6=TIM5 -Mcu.IPNb=7 +Mcu.IP3=LPUART1 +Mcu.IP4=NVIC +Mcu.IP5=RCC +Mcu.IP6=SYS +Mcu.IP7=TIM5 +Mcu.IPNb=8 Mcu.Name=STM32G474R(B-C-E)Tx Mcu.Package=LQFP64 Mcu.Pin0=PC13 -Mcu.Pin1=PA5 -Mcu.Pin10=VP_TIM5_VS_ClockSourceINT -Mcu.Pin2=PB12 -Mcu.Pin3=PB13 -Mcu.Pin4=PA8 -Mcu.Pin5=PA15 -Mcu.Pin6=PB8-BOOT0 -Mcu.Pin7=PB9 -Mcu.Pin8=VP_SYS_VS_Systick -Mcu.Pin9=VP_SYS_VS_DBSignals -Mcu.PinsNb=11 +Mcu.Pin1=PC0 +Mcu.Pin10=PB3 +Mcu.Pin11=PB8-BOOT0 +Mcu.Pin12=PB9 +Mcu.Pin13=VP_SYS_VS_Systick +Mcu.Pin14=VP_SYS_VS_DBSignals +Mcu.Pin15=VP_TIM5_VS_ClockSourceINT +Mcu.Pin2=PC1 +Mcu.Pin3=PA5 +Mcu.Pin4=PB12 +Mcu.Pin5=PB13 +Mcu.Pin6=PA8 +Mcu.Pin7=PA13 +Mcu.Pin8=PA14 +Mcu.Pin9=PA15 +Mcu.PinsNb=16 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32G474RETx -MxCube.Version=6.18.0 -MxDb.Version=DB.6.0.180 +MxCube.Version=6.18.1 +MxDb.Version=DB.6.0.181 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.FDCAN1_IT0_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true +NVIC.FDCAN2_IT0_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true +NVIC.FDCAN3_IT0_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true NVIC.ForceEnableDMAVector=false NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false @@ -80,6 +92,10 @@ NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false NVIC.TIM5_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +PA13.Mode=Trace_Asynchronous_SW +PA13.Signal=SYS_JTMS-SWDIO +PA14.Mode=Trace_Asynchronous_SW +PA14.Signal=SYS_JTCK-SWCLK PA15.Mode=FDCAN_Activate PA15.Signal=FDCAN3_TX PA5.GPIOParameters=GPIO_Label @@ -92,10 +108,16 @@ PB12.Mode=FDCAN_Activate PB12.Signal=FDCAN2_RX PB13.Mode=FDCAN_Activate PB13.Signal=FDCAN2_TX +PB3.Mode=Trace_Asynchronous_SW +PB3.Signal=SYS_JTDO-SWO PB8-BOOT0.Mode=FDCAN_Activate PB8-BOOT0.Signal=FDCAN1_RX PB9.Mode=FDCAN_Activate PB9.Signal=FDCAN1_TX +PC0.Mode=Asynchronous +PC0.Signal=LPUART1_RX +PC1.Mode=Asynchronous +PC1.Signal=LPUART1_TX PC13.GPIOParameters=GPIO_Label PC13.GPIO_Label=USER_BUTTON PC13.Locked=true diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index 1124cc1de..eb26dd516 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,16 +28,17 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" + +#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_dma.h" -#include "stm32g4xx_ll_exti.h" -#include "stm32g4xx_ll_gpio.h" -#include "stm32g4xx_ll_pwr.h" -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_exti.h" +#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_utils.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index 33793dda8..d2eb7e85b 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -63,7 +63,7 @@ /*#define HAL_SPI_MODULE_ENABLED */ /*#define HAL_SRAM_MODULE_ENABLED */ #define HAL_TIM_MODULE_ENABLED -/*#define HAL_UART_MODULE_ENABLED */ +#define HAL_UART_MODULE_ENABLED /*#define HAL_USART_MODULE_ENABLED */ /*#define HAL_WWDG_MODULE_ENABLED */ #define HAL_GPIO_MODULE_ENABLED diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h index 980377814..be4e088db 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h @@ -55,7 +55,10 @@ void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); +void FDCAN1_IT0_IRQHandler(void); void TIM5_IRQHandler(void); +void FDCAN2_IT0_IRQHandler(void); +void FDCAN3_IT0_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index 2d20bd560..b90657cf4 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,3 +49,4 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/CUBEMXTESTING/Core/Inc/usart.h new file mode 100644 index 000000000..c259dc52a --- /dev/null +++ b/CUBEMXTESTING/Core/Inc/usart.h @@ -0,0 +1,52 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file usart.h + * @brief This file contains all the function prototypes for + * the usart.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 __USART_H__ +#define __USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern UART_HandleTypeDef hlpuart1; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_LPUART1_UART_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USART_H__ */ + diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index d1f107673..1f6984c70 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file fdcan.c - * @brief This file provides code for the configuration - * of the FDCAN instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file fdcan.c + * @brief This file provides code for the configuration + * of the FDCAN instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "fdcan.h" @@ -42,7 +42,7 @@ void MX_FDCAN1_Init(void) hfdcan1.Instance = FDCAN1; hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_NORMAL; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; hfdcan1.Init.AutoRetransmission = ENABLE; hfdcan1.Init.TransmitPause = DISABLE; hfdcan1.Init.ProtocolException = ENABLE; @@ -174,6 +174,9 @@ void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); /* USER CODE BEGIN FDCAN1_MspInit 1 */ /* USER CODE END FDCAN1_MspInit 1 */ @@ -204,6 +207,9 @@ void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); /* USER CODE BEGIN FDCAN2_MspInit 1 */ /* USER CODE END FDCAN2_MspInit 1 */ @@ -234,6 +240,9 @@ void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); /* USER CODE BEGIN FDCAN3_MspInit 1 */ /* USER CODE END FDCAN3_MspInit 1 */ @@ -260,6 +269,8 @@ void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) */ HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ /* USER CODE END FDCAN1_MspDeInit 1 */ @@ -281,6 +292,8 @@ void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) */ HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ /* USER CODE END FDCAN2_MspDeInit 1 */ @@ -302,6 +315,8 @@ void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ /* USER CODE END FDCAN3_MspDeInit 1 */ diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index 5d1912e85..990f7d6b5 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -32,7 +32,14 @@ /* USER CODE END 1 */ -/** Configure pins +/** Configure pins as + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) */ void MX_GPIO_Init(void) { @@ -86,18 +93,6 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - /**/ GPIO_InitStruct.Pin = LL_GPIO_PIN_2; GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; @@ -262,18 +257,6 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_13; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /**/ GPIO_InitStruct.Pin = LL_GPIO_PIN_10; GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; @@ -298,12 +281,6 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - /**/ GPIO_InitStruct.Pin = LL_GPIO_PIN_4; GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 8c0ec79a2..ad9a9a2d2 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,10 +18,10 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" - #include "fdcan.h" -#include "gpio.h" +#include "usart.h" #include "tim.h" +#include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -85,39 +85,40 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + MX_LPUART1_UART_Init(); + /* USER CODE BEGIN 2 */ Setup_Logomatic(&logomaticConfig); CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; @@ -126,59 +127,68 @@ int main(void) LOGOMATIC("Failed to initialize primary CAN handle\n"); Error_Handler(); } - /* USER CODE END 2 */ - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ LOGOMATIC("Hello World!\n"); + /* USER CODE END 2 */ + + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ + + /* USER CODE BEGIN 3 */ MainLoop(); - LL_mDelay(250); - /* USER CODE BEGIN 3 */ + HAL_Delay(1000); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) + { + } + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while(LL_RCC_HSI_IsReady() != 1) + { + } + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while(LL_RCC_PLL_IsReady() != 1) + { + } + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) + { + } + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i !=0; i--); + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) + { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -190,37 +200,36 @@ void SystemClock_Config(void) */ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { - if (htim == &CAN_TIMER_HANDLE) { - CubeCAN_Tick(); - } + LOGOMATIC("HAL_TIM_PeriodElapsedCallback: Timer %p elapsed\n", (void *const)htim); + CubeCAN_Tick(); } /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ printf("Assert failed! File %s on line %ld\n", file, line); - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c new file mode 100644 index 000000000..d908bd772 --- /dev/null +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -0,0 +1,85 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g4xx_hal_msp.c + * @brief This file provides code for the MSP Initialization + * and de-Initialization codes. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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*/ + + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); + + /* USER CODE BEGIN MspInit 1 */ + + /* USER CODE END MspInit 1 */ +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index d941a1d07..78d6b9cd9 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,9 +18,8 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "stm32g4xx_it.h" - #include "main.h" +#include "stm32g4xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -56,6 +55,9 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ +extern FDCAN_HandleTypeDef hfdcan1; +extern FDCAN_HandleTypeDef hfdcan2; +extern FDCAN_HandleTypeDef hfdcan3; extern TIM_HandleTypeDef htim5; /* USER CODE BEGIN EV */ @@ -65,125 +67,129 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -194,17 +200,59 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ +void FDCAN1_IT0_IRQHandler(void) +{ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + + /* USER CODE END FDCAN1_IT0_IRQn 1 */ +} + +/** + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ + + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ + + /* USER CODE END TIM5_IRQn 1 */ +} + +/** + * @brief This function handles FDCAN2 interrupt 0. + */ +void FDCAN2_IT0_IRQHandler(void) +{ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + + /* USER CODE END FDCAN2_IT0_IRQn 1 */ +} + +/** + * @brief This function handles FDCAN3 interrupt 0. + */ +void FDCAN3_IT0_IRQHandler(void) +{ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - CubeCAN_Tick(); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index d1aa2063a..3e421fc66 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file tim.c - * @brief This file provides code for the configuration - * of the TIM instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file tim.c + * @brief This file provides code for the configuration + * of the TIM instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "tim.h" @@ -62,7 +62,7 @@ void MX_TIM5_Init(void) Error_Handler(); } /* USER CODE BEGIN TIM5_Init 2 */ - + HAL_TIM_Base_Start_IT(&htim5); /* USER CODE END TIM5_Init 2 */ } diff --git a/CUBEMXTESTING/Core/Src/usart.c b/CUBEMXTESTING/Core/Src/usart.c new file mode 100644 index 000000000..7a7967363 --- /dev/null +++ b/CUBEMXTESTING/Core/Src/usart.c @@ -0,0 +1,131 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file usart.c + * @brief This file provides code for the configuration + * of the USART instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "usart.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +UART_HandleTypeDef hlpuart1; + +/* LPUART1 init function */ + +void MX_LPUART1_UART_Init(void) +{ + + /* USER CODE BEGIN LPUART1_Init 0 */ + + /* USER CODE END LPUART1_Init 0 */ + + /* USER CODE BEGIN LPUART1_Init 1 */ + + /* USER CODE END LPUART1_Init 1 */ + hlpuart1.Instance = LPUART1; + hlpuart1.Init.BaudRate = 115200; + hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; + hlpuart1.Init.StopBits = UART_STOPBITS_1; + hlpuart1.Init.Parity = UART_PARITY_NONE; + hlpuart1.Init.Mode = UART_MODE_TX_RX; + hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&hlpuart1) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN LPUART1_Init 2 */ + + /* USER CODE END LPUART1_Init 2 */ + +} + +void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(uartHandle->Instance==LPUART1) + { + /* USER CODE BEGIN LPUART1_MspInit 0 */ + + /* USER CODE END LPUART1_MspInit 0 */ + LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); + + /* LPUART1 clock enable */ + __HAL_RCC_LPUART1_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**LPUART1 GPIO Configuration + PC0 ------> LPUART1_RX + PC1 ------> LPUART1_TX + */ + 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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /* USER CODE BEGIN LPUART1_MspInit 1 */ + + /* USER CODE END LPUART1_MspInit 1 */ + } +} + +void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) +{ + + if(uartHandle->Instance==LPUART1) + { + /* USER CODE BEGIN LPUART1_MspDeInit 0 */ + + /* USER CODE END LPUART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_LPUART1_CLK_DISABLE(); + + /**LPUART1 GPIO Configuration + PC0 ------> LPUART1_RX + PC1 ------> LPUART1_TX + */ + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1); + + /* USER CODE BEGIN LPUART1_MspDeInit 1 */ + + /* USER CODE END LPUART1_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + diff --git a/Lib/Peripherals/CubeCAN/Src/can_rx.c b/Lib/Peripherals/CubeCAN/Src/can_rx.c index f37912f01..ddf6cfd11 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_rx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_rx.c @@ -10,6 +10,8 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) { + LOGOMATIC("HAL_FDCAN_RxFifo0Callback: FDCAN instance %p received interrupt with flags 0x%08lX\n", (void *const)hfdcan, RxFifo0ITs); + if (RxFifo0ITs & FDCAN_IT_RX_FIFO0_MESSAGE_LOST) { LOGOMATIC("WARNING: CAN Rx FIFO is overflowing, messages are being lost!\n"); } From 412dd52e6bb1e03a95f92fc51ff67e4646d0b14d Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 15 Aug 2026 23:55:41 +0000 Subject: [PATCH 053/125] Automatic CMake Format: Standardized formatting automatically --- CUBEMXTESTING/CMakeLists.txt | 8 ++++++-- Lib/GlobalShare/common.cmake | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CUBEMXTESTING/CMakeLists.txt b/CUBEMXTESTING/CMakeLists.txt index ce6c86e0d..5ee46ef0f 100644 --- a/CUBEMXTESTING/CMakeLists.txt +++ b/CUBEMXTESTING/CMakeLists.txt @@ -28,7 +28,6 @@ target_sources( INTERFACE Application/Src/CANdler.c Application/Src/Loop.c - Core/Src/fdcan.c Core/Src/gpio.c Core/Src/main.c @@ -37,7 +36,12 @@ target_sources( Core/Src/usart.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE CUBEMX_CAN_LIB LOGOMATIC_LIB) +target_link_libraries( + ${PROJECT_NAME}_USER_CODE + INTERFACE + CUBEMX_CAN_LIB + LOGOMATIC_LIB +) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/Lib/GlobalShare/common.cmake b/Lib/GlobalShare/common.cmake index 116b5485b..f2fd1b082 100644 --- a/Lib/GlobalShare/common.cmake +++ b/Lib/GlobalShare/common.cmake @@ -59,6 +59,11 @@ if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Test/criticalsection.c ) - target_link_libraries(criticalsection PRIVATE GLOBALSHARE_LIB Threads::Threads) + target_link_libraries( + criticalsection + PRIVATE + GLOBALSHARE_LIB + Threads::Threads + ) add_test(criticalsection_test criticalsection) endif() From 56334542f17a467d262848195188e4aac6552975 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 15 Aug 2026 23:57:17 +0000 Subject: [PATCH 054/125] Automatic Clang-Format: Standardized formatting automatically --- CUBEMXTESTING/Core/Inc/fdcan.h | 33 +- CUBEMXTESTING/Core/Inc/gpio.h | 33 +- CUBEMXTESTING/Core/Inc/main.h | 15 +- CUBEMXTESTING/Core/Inc/stm32_assert.h | 49 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 245 ++++----- CUBEMXTESTING/Core/Inc/stm32g4xx_it.h | 30 +- CUBEMXTESTING/Core/Inc/tim.h | 1 - CUBEMXTESTING/Core/Inc/usart.h | 33 +- CUBEMXTESTING/Core/Src/fdcan.c | 525 +++++++++--------- CUBEMXTESTING/Core/Src/gpio.c | 569 ++++++++++---------- CUBEMXTESTING/Core/Src/main.c | 167 +++--- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 56 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 197 ++++--- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- CUBEMXTESTING/Core/Src/usart.c | 186 +++---- 15 files changed, 1102 insertions(+), 1150 deletions(-) diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 4b2cb4094..3597c6476 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file fdcan.h - * @brief This file contains all the function prototypes for - * the fdcan.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file fdcan.h + * @brief This file contains all the function prototypes for + * the fdcan.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 __FDCAN_H__ @@ -55,4 +55,3 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 3c91c4dd6..37dcc0a5c 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file gpio.h - * @brief This file contains all the function prototypes for - * the gpio.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file gpio.h + * @brief This file contains all the function prototypes for + * the gpio.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 __GPIO_H__ @@ -46,4 +46,3 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index eb26dd516..c796cd49a 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,24 +28,23 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" - -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_system.h" -#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_utils.h" -#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_crs.h" #include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_gpio.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_rcc.h" +#include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_utils.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ +#include "CubeCAN.h" #include "stm32g4xx_ll_lpuart.h" #include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_usart.h" -#include "CubeCAN.h" /* USER CODE END Includes */ /* Exported types ------------------------------------------------------------*/ diff --git a/CUBEMXTESTING/Core/Inc/stm32_assert.h b/CUBEMXTESTING/Core/Inc/stm32_assert.h index 61631c41e..92460620f 100644 --- a/CUBEMXTESTING/Core/Inc/stm32_assert.h +++ b/CUBEMXTESTING/Core/Inc/stm32_assert.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file stm32_assert.h - * @author MCD Application Team - * @brief STM32 assert file. - ****************************************************************************** - * @attention - * - * Copyright (c) 2019 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file stm32_assert.h + * @author MCD Application Team + * @brief STM32 assert file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2019 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 __STM32_ASSERT_H @@ -29,15 +29,15 @@ extern "C" { /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); @@ -50,4 +50,3 @@ void assert_failed(uint8_t *file, uint32_t line); #endif #endif /* __STM32_ASSERT_H */ - diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index d2eb7e85b..d12d585bd 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file stm32g4xx_hal_conf.h - * @author MCD Application Team - * @brief HAL configuration file - ****************************************************************************** + ****************************************************************************** + * @file stm32g4xx_hal_conf.h + * @author MCD Application Team + * @brief HAL configuration file + ****************************************************************************** * @attention - * - * Copyright (c) 2019 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. - * - ****************************************************************************** - */ + * + * Copyright (c) 2019 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 -------------------------------------*/ @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED - /*#define HAL_ADC_MODULE_ENABLED */ +/*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -76,123 +76,124 @@ /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined(HSE_STARTUP_TIMEOUT) +#define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined (HSI48_VALUE) - #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined(HSI48_VALUE) +#define HSI48_VALUE \ + (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined(LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined (LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined(LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined (LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined(LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined (EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined(EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ - #define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +#define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -201,12 +202,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -357,15 +358,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h index be4e088db..f7508212b 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h @@ -1,20 +1,20 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file stm32g4xx_it.h - * @brief This file contains the headers of the interrupt handlers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file stm32g4xx_it.h + * @brief This file contains the headers of the interrupt handlers. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 -------------------------------------*/ diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index b90657cf4..2d20bd560 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,4 +49,3 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/CUBEMXTESTING/Core/Inc/usart.h index c259dc52a..bdec0c9cb 100644 --- a/CUBEMXTESTING/Core/Inc/usart.h +++ b/CUBEMXTESTING/Core/Inc/usart.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file usart.h - * @brief This file contains all the function prototypes for - * the usart.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file usart.h + * @brief This file contains all the function prototypes for + * the usart.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 __USART_H__ @@ -49,4 +49,3 @@ void MX_LPUART1_UART_Init(void); #endif #endif /* __USART_H__ */ - diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 1f6984c70..359327d14 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,298 +32,281 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ - + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_NORMAL; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ - + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_NORMAL; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_NORMAL; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ - + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_NORMAL; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) { - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index 990f7d6b5..d0d390b5b 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file gpio.c - * @brief This file provides code for the configuration - * of all used GPIO pins. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file gpio.c + * @brief This file provides code for the configuration + * of all used GPIO pins. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 ------------------------------------------------------------------*/ @@ -33,278 +33,277 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) -*/ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) + */ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index ad9a9a2d2..2b517366c 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,10 +18,11 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" + #include "fdcan.h" -#include "usart.h" -#include "tim.h" #include "gpio.h" +#include "tim.h" +#include "usart.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -85,40 +86,40 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - MX_LPUART1_UART_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + MX_LPUART1_UART_Init(); + /* USER CODE BEGIN 2 */ Setup_Logomatic(&logomaticConfig); CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; @@ -128,67 +129,59 @@ int main(void) Error_Handler(); } LOGOMATIC("Hello World!\n"); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); HAL_Delay(1000); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) - { - } - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while(LL_RCC_HSI_IsReady() != 1) - { - } - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while(LL_RCC_PLL_IsReady() != 1) - { - } - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) - { - } - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i !=0; i--); - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) - { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while (LL_RCC_HSI_IsReady() != 1) {} + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while (LL_RCC_PLL_IsReady() != 1) {} + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i != 0; i--) + ; + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -207,29 +200,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ printf("Assert failed! File %s on line %ld\n", file, line); - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index d908bd772..4668755ab 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file stm32g4xx_hal_msp.c - * @brief This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file stm32g4xx_hal_msp.c + * @brief This file provides code for the MSP Initialization + * and de-Initialization codes. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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" @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index 78d6b9cd9..fd2ad329f 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,8 +18,9 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "main.h" #include "stm32g4xx_it.h" + +#include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -67,129 +68,125 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -200,59 +197,59 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index 3e421fc66..e31e60c88 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,83 +30,76 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 15999; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 999; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) - { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) - { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 15999; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 999; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ - + /* USER CODE END TIM5_Init 2 */ } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/usart.c b/CUBEMXTESTING/Core/Src/usart.c index 7a7967363..4e3f96e17 100644 --- a/CUBEMXTESTING/Core/Src/usart.c +++ b/CUBEMXTESTING/Core/Src/usart.c @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file usart.c - * @brief This file provides code for the configuration - * of the USART instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file usart.c + * @brief This file provides code for the configuration + * of the USART instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "usart.h" @@ -31,101 +31,93 @@ UART_HandleTypeDef hlpuart1; void MX_LPUART1_UART_Init(void) { - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - hlpuart1.Instance = LPUART1; - hlpuart1.Init.BaudRate = 115200; - hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; - hlpuart1.Init.StopBits = UART_STOPBITS_1; - hlpuart1.Init.Parity = UART_PARITY_NONE; - hlpuart1.Init.Mode = UART_MODE_TX_RX; - hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&hlpuart1) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ - + /* USER CODE BEGIN LPUART1_Init 0 */ + + /* USER CODE END LPUART1_Init 0 */ + + /* USER CODE BEGIN LPUART1_Init 1 */ + + /* USER CODE END LPUART1_Init 1 */ + hlpuart1.Instance = LPUART1; + hlpuart1.Init.BaudRate = 115200; + hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; + hlpuart1.Init.StopBits = UART_STOPBITS_1; + hlpuart1.Init.Parity = UART_PARITY_NONE; + hlpuart1.Init.Mode = UART_MODE_TX_RX; + hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&hlpuart1) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN LPUART1_Init 2 */ + + /* USER CODE END LPUART1_Init 2 */ } -void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) +void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(uartHandle->Instance==LPUART1) - { - /* USER CODE BEGIN LPUART1_MspInit 0 */ - - /* USER CODE END LPUART1_MspInit 0 */ - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* LPUART1 clock enable */ - __HAL_RCC_LPUART1_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**LPUART1 GPIO Configuration - PC0 ------> LPUART1_RX - PC1 ------> LPUART1_TX - */ - 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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN LPUART1_MspInit 1 */ - - /* USER CODE END LPUART1_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (uartHandle->Instance == LPUART1) { + /* USER CODE BEGIN LPUART1_MspInit 0 */ + + /* USER CODE END LPUART1_MspInit 0 */ + LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); + + /* LPUART1 clock enable */ + __HAL_RCC_LPUART1_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**LPUART1 GPIO Configuration + PC0 ------> LPUART1_RX + PC1 ------> LPUART1_TX + */ + 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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /* USER CODE BEGIN LPUART1_MspInit 1 */ + + /* USER CODE END LPUART1_MspInit 1 */ + } } -void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) +void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle) { - if(uartHandle->Instance==LPUART1) - { - /* USER CODE BEGIN LPUART1_MspDeInit 0 */ + if (uartHandle->Instance == LPUART1) { + /* USER CODE BEGIN LPUART1_MspDeInit 0 */ - /* USER CODE END LPUART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_LPUART1_CLK_DISABLE(); + /* USER CODE END LPUART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_LPUART1_CLK_DISABLE(); - /**LPUART1 GPIO Configuration - PC0 ------> LPUART1_RX - PC1 ------> LPUART1_TX - */ - HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1); + /**LPUART1 GPIO Configuration + PC0 ------> LPUART1_RX + PC1 ------> LPUART1_TX + */ + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0 | GPIO_PIN_1); - /* USER CODE BEGIN LPUART1_MspDeInit 1 */ + /* USER CODE BEGIN LPUART1_MspDeInit 1 */ - /* USER CODE END LPUART1_MspDeInit 1 */ - } + /* USER CODE END LPUART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - From e46adda819ea194aac764bb91c161030218fb771 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 17:10:07 -0700 Subject: [PATCH 055/125] Fix compile error Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Application/Src/Loop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CUBEMXTESTING/Application/Src/Loop.c b/CUBEMXTESTING/Application/Src/Loop.c index d870eb4e7..f7250b60c 100644 --- a/CUBEMXTESTING/Application/Src/Loop.c +++ b/CUBEMXTESTING/Application/Src/Loop.c @@ -12,5 +12,5 @@ void MainLoop(void) { LL_GPIO_TogglePin(USER_LED_GPIO_Port, USER_LED_Pin); LOGOMATIC("Main Loop %d\n", value); - HAL_StatusTypeDef status = CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello!", 6); + (void)CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello!", 6); } From eef305c6916e463e933189d32874fb562c6b34bb Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 17:25:59 -0700 Subject: [PATCH 056/125] Fix codeql warning on failed asserts Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Core/Src/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 2b517366c..0c3167a2e 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -193,7 +193,6 @@ void SystemClock_Config(void) */ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { - LOGOMATIC("HAL_TIM_PeriodElapsedCallback: Timer %p elapsed\n", (void *const)htim); CubeCAN_Tick(); } @@ -222,7 +221,7 @@ void Error_Handler(void) void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ - printf("Assert failed! File %s on line %ld\n", file, line); + printf("Assert failed! File %s on line %lu\n", file, line); /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ From 60dc0cb8eb6d5ec44a6c0d0b57aead7aa43c58b7 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 17:26:27 -0700 Subject: [PATCH 057/125] Add unused for timer handle Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Core/Src/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 0c3167a2e..f72928de2 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -193,6 +193,7 @@ void SystemClock_Config(void) */ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { + UNUSED(htim); CubeCAN_Tick(); } From f6d7b28ddcc51518949392df5a3930a7dd434c2c Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 17:50:42 -0700 Subject: [PATCH 058/125] Increase can tick timer speed Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Application/Src/CANdler.c | 8 +- CUBEMXTESTING/CUBEMXTESTING.ioc | 6 +- CUBEMXTESTING/Core/Inc/fdcan.h | 1 + CUBEMXTESTING/Core/Inc/gpio.h | 1 + CUBEMXTESTING/Core/Inc/main.h | 13 +- CUBEMXTESTING/Core/Inc/stm32_assert.h | 17 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 215 ++++---- CUBEMXTESTING/Core/Inc/tim.h | 1 + CUBEMXTESTING/Core/Inc/usart.h | 1 + CUBEMXTESTING/Core/Src/fdcan.c | 525 ++++++++++--------- CUBEMXTESTING/Core/Src/gpio.c | 537 ++++++++++---------- CUBEMXTESTING/Core/Src/main.c | 167 +++--- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 24 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 197 +++---- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- CUBEMXTESTING/Core/Src/usart.c | 154 +++--- Lib/Peripherals/CubeCAN/Src/can_global.c | 2 - Lib/Peripherals/CubeCAN/Src/can_rx.c | 2 - 18 files changed, 1017 insertions(+), 967 deletions(-) diff --git a/CUBEMXTESTING/Application/Src/CANdler.c b/CUBEMXTESTING/Application/Src/CANdler.c index 8d16b7c36..ff41e5326 100644 --- a/CUBEMXTESTING/Application/Src/CANdler.c +++ b/CUBEMXTESTING/Application/Src/CANdler.c @@ -23,5 +23,11 @@ void CANdler_Callback(const CubeCAN_Config_Context *const context, const CAN_Ide const GRCAN_NODE_ID rx_node = identifier->rx_node_id; const GRCAN_MSG_ID msg_id = identifier->msg_id; - LOGOMATIC("Received on bus %d with node %d -> %d with message %d and size %u\t%.*s\n", busid, tx_node, rx_node, msg_id, size, size, (const char *const)data); + // LOGOMATIC("Received on bus %d with node %d -> %d with message %d and size %u\t%.*s\n", busid, tx_node, rx_node, msg_id, size, size, (const char *const)data); + + // Uncomment to spam the bus + // (void)CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Bye0", 4); + // (void)CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Bye1", 4); + // (void)CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Bye2", 4); + // (void)CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Bye3", 4); } diff --git a/CUBEMXTESTING/CUBEMXTESTING.ioc b/CUBEMXTESTING/CUBEMXTESTING.ioc index b5c76181d..736997455 100644 --- a/CUBEMXTESTING/CUBEMXTESTING.ioc +++ b/CUBEMXTESTING/CUBEMXTESTING.ioc @@ -160,7 +160,7 @@ ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=false ProjectManager.UseDefaultDestinationPath=true ProjectManager.UseDefaultSourcePath=true -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_TIM5_Init-TIM5-false-HAL-true,6-MX_FDCAN3_Init-FDCAN3-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_TIM5_Init-TIM5-false-HAL-true,6-MX_FDCAN3_Init-FDCAN3-false-HAL-true,7-MX_LPUART1_UART_Init-LPUART1-false-HAL-true RCC.ADC12Freq_Value=160000000 RCC.ADC345Freq_Value=160000000 RCC.AHBFreq_Value=160000000 @@ -210,8 +210,8 @@ RCC.USBFreq_Value=160000000 RCC.VCOInputFreq_Value=16000000 RCC.VCOOutputFreq_Value=320000000 TIM5.IPParameters=Prescaler,PeriodNoDither -TIM5.PeriodNoDither=999 -TIM5.Prescaler=15999 +TIM5.PeriodNoDither=499 +TIM5.Prescaler=159 VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals VP_SYS_VS_Systick.Mode=SysTick diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 3597c6476..21271cf64 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -55,3 +55,4 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 37dcc0a5c..03c2faca5 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -46,3 +46,4 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index c796cd49a..200fcd7eb 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,16 +28,17 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" + +#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_dma.h" -#include "stm32g4xx_ll_exti.h" -#include "stm32g4xx_ll_gpio.h" -#include "stm32g4xx_ll_pwr.h" -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_exti.h" +#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_utils.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/CUBEMXTESTING/Core/Inc/stm32_assert.h b/CUBEMXTESTING/Core/Inc/stm32_assert.h index 92460620f..e645b21ee 100644 --- a/CUBEMXTESTING/Core/Inc/stm32_assert.h +++ b/CUBEMXTESTING/Core/Inc/stm32_assert.h @@ -29,15 +29,15 @@ extern "C" { /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); @@ -50,3 +50,4 @@ void assert_failed(uint8_t *file, uint32_t line); #endif #endif /* __STM32_ASSERT_H */ + diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index d12d585bd..e4db34d37 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus -extern "C" { + extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ extern "C" { /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED -/*#define HAL_ADC_MODULE_ENABLED */ + /*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -76,124 +76,123 @@ extern "C" { /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(HSE_STARTUP_TIMEOUT) -#define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined(HSI48_VALUE) -#define HSI48_VALUE \ - (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined (HSI48_VALUE) + #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined(LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined(LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined(LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined (LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined(EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -#define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ + #define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -202,12 +201,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -358,15 +357,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index 2d20bd560..b90657cf4 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,3 +49,4 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/CUBEMXTESTING/Core/Inc/usart.h index bdec0c9cb..49dd0cccc 100644 --- a/CUBEMXTESTING/Core/Inc/usart.h +++ b/CUBEMXTESTING/Core/Inc/usart.h @@ -49,3 +49,4 @@ void MX_LPUART1_UART_Init(void); #endif #endif /* __USART_H__ */ + diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 359327d14..1f6984c70 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,281 +32,298 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ + } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_NORMAL; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_NORMAL; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ + } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_NORMAL; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_NORMAL; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ + } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN3) { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) { - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN3) { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index d0d390b5b..d4094cc2b 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -33,277 +33,278 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) - */ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) +*/ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index f72928de2..e29a8b405 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,11 +18,10 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" - #include "fdcan.h" -#include "gpio.h" -#include "tim.h" #include "usart.h" +#include "tim.h" +#include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -86,40 +85,40 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - MX_LPUART1_UART_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + MX_LPUART1_UART_Init(); + /* USER CODE BEGIN 2 */ Setup_Logomatic(&logomaticConfig); CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; @@ -129,59 +128,67 @@ int main(void) Error_Handler(); } LOGOMATIC("Hello World!\n"); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); HAL_Delay(1000); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) + { + } + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while(LL_RCC_HSI_IsReady() != 1) + { + } + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while(LL_RCC_PLL_IsReady() != 1) + { + } + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) + { + } + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i !=0; i--); + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) + { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -200,29 +207,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ printf("Assert failed! File %s on line %lu\n", file, line); - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index 4668755ab..2cc7d8296 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index fd2ad329f..78d6b9cd9 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,9 +18,8 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "stm32g4xx_it.h" - #include "main.h" +#include "stm32g4xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -68,125 +67,129 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -197,59 +200,59 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index e31e60c88..cc6e6a92e 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,76 +30,83 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 15999; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 999; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 159; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 499; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) + { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ + /* USER CODE END TIM5_Init 2 */ + } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) { - if (tim_baseHandle->Instance == TIM5) { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) { - if (tim_baseHandle->Instance == TIM5) { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/Core/Src/usart.c b/CUBEMXTESTING/Core/Src/usart.c index 4e3f96e17..53d379951 100644 --- a/CUBEMXTESTING/Core/Src/usart.c +++ b/CUBEMXTESTING/Core/Src/usart.c @@ -31,93 +31,101 @@ UART_HandleTypeDef hlpuart1; void MX_LPUART1_UART_Init(void) { - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - hlpuart1.Instance = LPUART1; - hlpuart1.Init.BaudRate = 115200; - hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; - hlpuart1.Init.StopBits = UART_STOPBITS_1; - hlpuart1.Init.Parity = UART_PARITY_NONE; - hlpuart1.Init.Mode = UART_MODE_TX_RX; - hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&hlpuart1) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ + /* USER CODE BEGIN LPUART1_Init 0 */ + + /* USER CODE END LPUART1_Init 0 */ + + /* USER CODE BEGIN LPUART1_Init 1 */ + + /* USER CODE END LPUART1_Init 1 */ + hlpuart1.Instance = LPUART1; + hlpuart1.Init.BaudRate = 115200; + hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; + hlpuart1.Init.StopBits = UART_STOPBITS_1; + hlpuart1.Init.Parity = UART_PARITY_NONE; + hlpuart1.Init.Mode = UART_MODE_TX_RX; + hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&hlpuart1) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN LPUART1_Init 2 */ + + /* USER CODE END LPUART1_Init 2 */ + } -void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle) +void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (uartHandle->Instance == LPUART1) { - /* USER CODE BEGIN LPUART1_MspInit 0 */ - - /* USER CODE END LPUART1_MspInit 0 */ - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* LPUART1 clock enable */ - __HAL_RCC_LPUART1_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**LPUART1 GPIO Configuration - PC0 ------> LPUART1_RX - PC1 ------> LPUART1_TX - */ - 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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN LPUART1_MspInit 1 */ - - /* USER CODE END LPUART1_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(uartHandle->Instance==LPUART1) + { + /* USER CODE BEGIN LPUART1_MspInit 0 */ + + /* USER CODE END LPUART1_MspInit 0 */ + LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); + + /* LPUART1 clock enable */ + __HAL_RCC_LPUART1_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**LPUART1 GPIO Configuration + PC0 ------> LPUART1_RX + PC1 ------> LPUART1_TX + */ + 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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /* USER CODE BEGIN LPUART1_MspInit 1 */ + + /* USER CODE END LPUART1_MspInit 1 */ + } } -void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle) +void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { - if (uartHandle->Instance == LPUART1) { - /* USER CODE BEGIN LPUART1_MspDeInit 0 */ + if(uartHandle->Instance==LPUART1) + { + /* USER CODE BEGIN LPUART1_MspDeInit 0 */ - /* USER CODE END LPUART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_LPUART1_CLK_DISABLE(); + /* USER CODE END LPUART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_LPUART1_CLK_DISABLE(); - /**LPUART1 GPIO Configuration - PC0 ------> LPUART1_RX - PC1 ------> LPUART1_TX - */ - HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0 | GPIO_PIN_1); + /**LPUART1 GPIO Configuration + PC0 ------> LPUART1_RX + PC1 ------> LPUART1_TX + */ + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1); - /* USER CODE BEGIN LPUART1_MspDeInit 1 */ + /* USER CODE BEGIN LPUART1_MspDeInit 1 */ - /* USER CODE END LPUART1_MspDeInit 1 */ - } + /* USER CODE END LPUART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/Lib/Peripherals/CubeCAN/Src/can_global.c b/Lib/Peripherals/CubeCAN/Src/can_global.c index c573f8f67..254508f25 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_global.c +++ b/Lib/Peripherals/CubeCAN/Src/can_global.c @@ -7,5 +7,3 @@ #include "PrivateInc/internal.h" struct CubeCAN_Private_Handle handles[CUBEMX_CAN_MAX_INSTANCES] = {0}; - -int five = sizeof(handles); diff --git a/Lib/Peripherals/CubeCAN/Src/can_rx.c b/Lib/Peripherals/CubeCAN/Src/can_rx.c index ddf6cfd11..f37912f01 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_rx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_rx.c @@ -10,8 +10,6 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) { - LOGOMATIC("HAL_FDCAN_RxFifo0Callback: FDCAN instance %p received interrupt with flags 0x%08lX\n", (void *const)hfdcan, RxFifo0ITs); - if (RxFifo0ITs & FDCAN_IT_RX_FIFO0_MESSAGE_LOST) { LOGOMATIC("WARNING: CAN Rx FIFO is overflowing, messages are being lost!\n"); } From 00032880e2705160a8f44779c7e380760aebf423 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2026 00:51:58 +0000 Subject: [PATCH 059/125] Automatic Clang-Format: Standardized formatting automatically --- CUBEMXTESTING/Core/Inc/fdcan.h | 1 - CUBEMXTESTING/Core/Inc/gpio.h | 1 - CUBEMXTESTING/Core/Inc/main.h | 13 +- CUBEMXTESTING/Core/Inc/stm32_assert.h | 17 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 215 ++++---- CUBEMXTESTING/Core/Inc/tim.h | 1 - CUBEMXTESTING/Core/Inc/usart.h | 1 - CUBEMXTESTING/Core/Src/fdcan.c | 525 +++++++++---------- CUBEMXTESTING/Core/Src/gpio.c | 537 ++++++++++---------- CUBEMXTESTING/Core/Src/main.c | 167 +++--- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 24 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 197 ++++--- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- CUBEMXTESTING/Core/Src/usart.c | 154 +++--- 14 files changed, 959 insertions(+), 1007 deletions(-) diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 21271cf64..3597c6476 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -55,4 +55,3 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 03c2faca5..37dcc0a5c 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -46,4 +46,3 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index 200fcd7eb..c796cd49a 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,17 +28,16 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" - -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_system.h" -#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_utils.h" -#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_crs.h" #include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_gpio.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_rcc.h" +#include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_utils.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/CUBEMXTESTING/Core/Inc/stm32_assert.h b/CUBEMXTESTING/Core/Inc/stm32_assert.h index e645b21ee..92460620f 100644 --- a/CUBEMXTESTING/Core/Inc/stm32_assert.h +++ b/CUBEMXTESTING/Core/Inc/stm32_assert.h @@ -29,15 +29,15 @@ extern "C" { /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); @@ -50,4 +50,3 @@ void assert_failed(uint8_t *file, uint32_t line); #endif #endif /* __STM32_ASSERT_H */ - diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index e4db34d37..d12d585bd 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED - /*#define HAL_ADC_MODULE_ENABLED */ +/*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -76,123 +76,124 @@ /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined(HSE_STARTUP_TIMEOUT) +#define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined (HSI48_VALUE) - #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined(HSI48_VALUE) +#define HSI48_VALUE \ + (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined(LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined (LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined(LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined (LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined(LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined (EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined(EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ - #define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +#define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -201,12 +202,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -357,15 +358,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index b90657cf4..2d20bd560 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,4 +49,3 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/CUBEMXTESTING/Core/Inc/usart.h index 49dd0cccc..bdec0c9cb 100644 --- a/CUBEMXTESTING/Core/Inc/usart.h +++ b/CUBEMXTESTING/Core/Inc/usart.h @@ -49,4 +49,3 @@ void MX_LPUART1_UART_Init(void); #endif #endif /* __USART_H__ */ - diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 1f6984c70..359327d14 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,298 +32,281 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ - + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_NORMAL; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ - + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_NORMAL; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_NORMAL; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ - + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_NORMAL; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) { - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index d4094cc2b..d0d390b5b 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -33,278 +33,277 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) -*/ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) + */ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index e29a8b405..f72928de2 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,10 +18,11 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" + #include "fdcan.h" -#include "usart.h" -#include "tim.h" #include "gpio.h" +#include "tim.h" +#include "usart.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -85,40 +86,40 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - MX_LPUART1_UART_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + MX_LPUART1_UART_Init(); + /* USER CODE BEGIN 2 */ Setup_Logomatic(&logomaticConfig); CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; @@ -128,67 +129,59 @@ int main(void) Error_Handler(); } LOGOMATIC("Hello World!\n"); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); HAL_Delay(1000); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) - { - } - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while(LL_RCC_HSI_IsReady() != 1) - { - } - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while(LL_RCC_PLL_IsReady() != 1) - { - } - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) - { - } - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i !=0; i--); - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) - { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while (LL_RCC_HSI_IsReady() != 1) {} + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while (LL_RCC_PLL_IsReady() != 1) {} + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i != 0; i--) + ; + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -207,29 +200,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ printf("Assert failed! File %s on line %lu\n", file, line); - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index 2cc7d8296..4668755ab 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index 78d6b9cd9..fd2ad329f 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,8 +18,9 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "main.h" #include "stm32g4xx_it.h" + +#include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -67,129 +68,125 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -200,59 +197,59 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index cc6e6a92e..1f6110e86 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,83 +30,76 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 159; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 499; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) - { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) - { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 159; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 499; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ - + /* USER CODE END TIM5_Init 2 */ } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/usart.c b/CUBEMXTESTING/Core/Src/usart.c index 53d379951..4e3f96e17 100644 --- a/CUBEMXTESTING/Core/Src/usart.c +++ b/CUBEMXTESTING/Core/Src/usart.c @@ -31,101 +31,93 @@ UART_HandleTypeDef hlpuart1; void MX_LPUART1_UART_Init(void) { - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - hlpuart1.Instance = LPUART1; - hlpuart1.Init.BaudRate = 115200; - hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; - hlpuart1.Init.StopBits = UART_STOPBITS_1; - hlpuart1.Init.Parity = UART_PARITY_NONE; - hlpuart1.Init.Mode = UART_MODE_TX_RX; - hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&hlpuart1) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ - + /* USER CODE BEGIN LPUART1_Init 0 */ + + /* USER CODE END LPUART1_Init 0 */ + + /* USER CODE BEGIN LPUART1_Init 1 */ + + /* USER CODE END LPUART1_Init 1 */ + hlpuart1.Instance = LPUART1; + hlpuart1.Init.BaudRate = 115200; + hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; + hlpuart1.Init.StopBits = UART_STOPBITS_1; + hlpuart1.Init.Parity = UART_PARITY_NONE; + hlpuart1.Init.Mode = UART_MODE_TX_RX; + hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&hlpuart1) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN LPUART1_Init 2 */ + + /* USER CODE END LPUART1_Init 2 */ } -void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) +void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(uartHandle->Instance==LPUART1) - { - /* USER CODE BEGIN LPUART1_MspInit 0 */ - - /* USER CODE END LPUART1_MspInit 0 */ - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* LPUART1 clock enable */ - __HAL_RCC_LPUART1_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**LPUART1 GPIO Configuration - PC0 ------> LPUART1_RX - PC1 ------> LPUART1_TX - */ - 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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN LPUART1_MspInit 1 */ - - /* USER CODE END LPUART1_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (uartHandle->Instance == LPUART1) { + /* USER CODE BEGIN LPUART1_MspInit 0 */ + + /* USER CODE END LPUART1_MspInit 0 */ + LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); + + /* LPUART1 clock enable */ + __HAL_RCC_LPUART1_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**LPUART1 GPIO Configuration + PC0 ------> LPUART1_RX + PC1 ------> LPUART1_TX + */ + 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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /* USER CODE BEGIN LPUART1_MspInit 1 */ + + /* USER CODE END LPUART1_MspInit 1 */ + } } -void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) +void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle) { - if(uartHandle->Instance==LPUART1) - { - /* USER CODE BEGIN LPUART1_MspDeInit 0 */ + if (uartHandle->Instance == LPUART1) { + /* USER CODE BEGIN LPUART1_MspDeInit 0 */ - /* USER CODE END LPUART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_LPUART1_CLK_DISABLE(); + /* USER CODE END LPUART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_LPUART1_CLK_DISABLE(); - /**LPUART1 GPIO Configuration - PC0 ------> LPUART1_RX - PC1 ------> LPUART1_TX - */ - HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1); + /**LPUART1 GPIO Configuration + PC0 ------> LPUART1_RX + PC1 ------> LPUART1_TX + */ + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0 | GPIO_PIN_1); - /* USER CODE BEGIN LPUART1_MspDeInit 1 */ + /* USER CODE BEGIN LPUART1_MspDeInit 1 */ - /* USER CODE END LPUART1_MspDeInit 1 */ - } + /* USER CODE END LPUART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - From d19044263dfee528364dd26d5a5920917fe4240f Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 17:52:15 -0700 Subject: [PATCH 060/125] Add back logomatic message on rx Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Application/Src/CANdler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CUBEMXTESTING/Application/Src/CANdler.c b/CUBEMXTESTING/Application/Src/CANdler.c index ff41e5326..46ba32506 100644 --- a/CUBEMXTESTING/Application/Src/CANdler.c +++ b/CUBEMXTESTING/Application/Src/CANdler.c @@ -23,7 +23,7 @@ void CANdler_Callback(const CubeCAN_Config_Context *const context, const CAN_Ide const GRCAN_NODE_ID rx_node = identifier->rx_node_id; const GRCAN_MSG_ID msg_id = identifier->msg_id; - // LOGOMATIC("Received on bus %d with node %d -> %d with message %d and size %u\t%.*s\n", busid, tx_node, rx_node, msg_id, size, size, (const char *const)data); + LOGOMATIC("Received on bus %d with node %d -> %d with message %d and size %u\t%.*s\n", busid, tx_node, rx_node, msg_id, size, size, (const char *const)data); // Uncomment to spam the bus // (void)CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Bye0", 4); From 449cbf245edd80f889fa34b5ec10bb2bc383300e Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 18:17:27 -0700 Subject: [PATCH 061/125] Update docs Signed-off-by: Daniel Hansen --- Lib/Peripherals/CubeCAN/README.md | 135 ++++++++++++++++++++---------- 1 file changed, 91 insertions(+), 44 deletions(-) diff --git a/Lib/Peripherals/CubeCAN/README.md b/Lib/Peripherals/CubeCAN/README.md index 730a9faf0..097a69ace 100644 --- a/Lib/Peripherals/CubeCAN/README.md +++ b/Lib/Peripherals/CubeCAN/README.md @@ -2,15 +2,17 @@ Support for STM32CubeMX and CAN. See [`CUBEMX.md`](../../../CUBEMX.md) for background. -## Overview +## Summary -Use STM32CubeMX to setup the CAN peripheral, then call `CubeCAN_Entrance` on it after HAL initializes the peripheral. -Save the handle that function returns and use that to send messages. Recieve messages on your function callback. +Use STM32CubeMX to setup the CAN peripheral, then call `CubeCAN_Entrance()` on it after HAL initializes the peripheral. + +Save the handle that function returns and use that to send messages. Receive messages on your function callback. > [!IMPORTANT] -> We recommend that your recieved message callback function is a switch-case off of the message ID that does nothing more than writing to memory. +> We recommend that your received message callback function is a switch-case off of the message ID that does nothing more than writing to memory. > -> Your `CubeCAN_RxCallback` function must run quickly, it is inside of a low level ISR. +> Your `CubeCAN_RxCallback()` function must run quickly, it is inside of a low level ISR. +> Read the library code yourself if you wish to call a CubeCAN function from within an ISR, but you really should not. ## Setup @@ -20,7 +22,7 @@ Add `CUBEMX_CAN_LIB` as an interface target link library within your project. ### 2. Configuration -Add a file named `CubeCAN_Config.h` to your project (generally `Application/Inc/CubeCAN_Config.h`) that has the following symbols defined +Add a file named `CubeCAN_Config.h` to your project, generally `Application/Inc/CubeCAN_Config.h`, that looks something like: ```c #ifndef CUBE_CAN_CONFIG_H @@ -32,25 +34,46 @@ Add a file named `CubeCAN_Config.h` to your project (generally `Application/Inc/ #endif ``` -Note that `CUBEMX_CAN_TX_QUEUE_SIZE` must be a multiple of two and `CUBEMX_CAN_MAX_INSTANCES` must be valid for that chip. +**Configuration Requirements:** + +- `CUBEMX_CAN_TX_QUEUE_SIZE`: Must be a power of two. Defines the transmission queue depth; when the queue fills, the oldest message is dropped and `CubeCAN_Send()` returns `HAL_BUSY`. +- `CUBEMX_CAN_MAX_INSTANCES`: Must be 1-3 depending on your chip's available FDCAN peripherals. Omit this definition to automatically select the maximum supported by your MCU. From there just ensure that you have configured CAN through STM32CubeMX and setup a global variable for each `CubeCAN_Handle` you wish to use. ### 3. Entrance -Make sure to `#include "CubeCAN.h"` where needed. Do not include `PrivateInc\internal.h` outside of the peripheral source files. +Make sure to `#include "CubeCAN.h"` where needed. Do not include `PrivateInc/internal.h` outside of the peripheral source files. + +At the end of your STM32CubeMX-generated `MX_FDCAN#_Init()` function, configure your filters as needed with `HAL_FDCAN_ConfigFilter()`. It is recommended to setup a filter to ignore messages not intended for your board. + +Within `main` after `MX_FDCAN#_Init()` and `LOGOMATIC()` are setup (see [Logomatic](../../Utils/Logomatic/README.md)), call `CubeCAN_Entrance()` saving the handle for global use later (one entrance and handle per peripheral). + +Ensure you have setup some mechanism to call `CubeCAN_Tick()` frequently (a STM32CubeMX timer interrupt is recommended). This function: + +- Sends one CAN message per bus per call (limiting to one prevents overwhelming the ISR) +- Must be called regularly for messages to be transmitted +- Can start running at any point in execution -At the end of your STM32CubeMX-generated `MX_FDCAN#_Init` function configure your filters as needed with `HAL_FDCAN_ConfigFilter` +### 4. Operation -Within `main` after `MX_FDCAN#_Init` and `LOGOMATIC` are setup (see [Logomatic](../../Utils/Logomatic/README.md)) call `CubeCAN_Entrance` saving the handle for global use later (one entrance and handle per peripheral) +#### Transmission -Double check you have setup some manner to call `CubeCAN_Tick` often (a STM32CubeMX timer is recommended), it can start running at any point in execution +Call `CubeCAN_Send()` to queue a message for transmission. Messages are queued in a lock-free ring buffer and processed in FIFO order. -### 4. Transmission / Reception +- **Returns `HAL_OK`**: Message successfully queued +- **Returns `HAL_BUSY`**: Transmission queue is full; the oldest queued message was dropped to make room for the new one +- **Returns `HAL_ERROR`**: Invalid parameters (null handle/data, size > 64 bytes, invalid frame format) -If you are frequently calling `CubeCAN_Tick` then as you call `CubeCAN_Send` messages will be transmitted once per bus per tick +Each call to `CubeCAN_Tick()` transmits one message from the queue per peripheral. If you need higher throughput, call `CubeCAN_Tick()` more frequently or increase `CUBEMX_CAN_TX_QUEUE_SIZE`. -Your provided callback `CubeCAN_RxCallback` will be triggered with messages that pass any filters you setup +#### Reception + +Your provided callback `CubeCAN_RxCallback()` is triggered for messages that pass your configured filters. + +- Keep execution time minimal, you are in a hardware ISR +- Avoid calling CubeCAN functions or performing blocking operations +- Typical pattern is to decode the message and write results to shared memory (protected with atomic operations or critical sections as needed) ## Architecture @@ -61,23 +84,23 @@ flowchart TD classDef internal fill:#F0E442,stroke:#333,color:#333; classDef other fill:#c2410c,stroke:#fed7aa,color:#ffffff; - MXInit(["MX_FDCAN#_Init"]) -->Entrance("CubeCAN_Entrance") - MXInit --> Filter("HAL_FDCAN_\nConfigFilter") + MXInit(["MX_FDCAN#_Init()"]) -->Entrance("CubeCAN_Entrance()") + MXInit --> Filter("HAL_FDCAN_\nConfigFilter()") Filter --> Filter Filter --> Entrance Entrance --> Choice{"Functions"} - Choice --> Exit(["CubeCAN_Exit"]) + Choice --> Exit(["CubeCAN_Exit()"]) Exit -.-> |"AVOID"| Entrance - Choice --> Send(["CubeCAN_Send"]) - Choice --> |"Call Often\n(User Setup)"| Tick(["CubeCAN_Tick"]) - Send -.-> Queue("CubeCAN_Private_QueueTx") + Choice --> Send(["CubeCAN_Send()"]) + Choice --> |"Call Often\n(User Setup)"| Tick(["CubeCAN_Tick()"]) + Send -.-> Queue("CubeCAN_Private_QueueTx()") Data -.-> Tick Queue -.-> Data{"Internal Queue"} - Tick -.-> Tx(["CubeCAN_Private\n_SendQueuedMessage"]) + Tick -.-> Tx(["CubeCAN_Private\n_SendQueuedMessage()"]) Data -.-> Tx - Tx -.->|"HAL_FDCAN_\nAddMessageToTxFifoQ"| Sent(["Transmitted over bus!"]) + Tx -.->|"HAL_FDCAN_\nAddMessageToTxFifoQ()"| Sent(["Transmitted over bus!"]) Choice -.->|"HAL Interrupt"| Recieved - Recieved(["Recieved over bus!"]) -.->|"HAL_FDCAN_\nRxFifo0Callback\n\nHAL_FDCAN_\nGetRxMessage"| Get(["CubeCAN_RxCallback"]) + Recieved(["Recieved over bus!"]) -.->|"HAL_FDCAN_\nRxFifo0Callback()\n\nHAL_FDCAN_\nGetRxMessage()"| Get(["CubeCAN_RxCallback()"]) class MXInit cubemx; class Filter cubemx; @@ -98,41 +121,57 @@ flowchart TD ### Interrupt Safety -We use atomic operations and locks to ensure that we do not operate on broken data. +CubeCAN is designed to handle concurrent access from multiple execution contexts (main loop and ISR). + +#### Overview + +- `tx_head` and `tx_tail` are atomic `uint32_t` variables that implement a lock-free ring buffer +- `CubeCAN_Send()` and `CubeCAN_Tick()` use critical sections (interrupt blocking) when necessary +- Atomic operations use `memory_order_relaxed` within ISRs and `memory_order_release`/`memory_order_acquire` for inter-context synchronization +- The queue size must be a power of two, allowing fast wraparound via bitwise AND instead of expensive modulo operations + +#### Critical Sections -Locks are handled through [`CriticalSection.h`](../../GlobalShare/Inc/CriticalSection.h) which block interrupts from running for a -scope and automatically clean themselves up nicely if something strange happens internally thanks to the GCC cleanup attribute. +Interrupt protection is used only in: -Currently the only atomic variables are `tx_head` and `tx_tail` as members of the handle, these manage the transmission queue and -need to be quite robust in case someone decides they want to send a CAN message inside a `CubeCAN_RxCallback` ISR (nobody should be -doing that, but if they do it needs to work) +- `CubeCAN_Private_QueueTx()` while updating the queue +- `HAL_FDCAN_RxFifo0Callback` while reading handle state -Since we have atomic variables we require `CUBEMX_CAN_TX_QUEUE_SIZE` to be a power of two so that we can do quick bitwise math on it -instead of waiting for a slower compare and swap (CAS) loop to handle the modulus operations for us to wrap around the ring-buffer +#### ISR Interaction + +- Safe to call `CubeCAN_Send()` from `main()` or any ISR +- Safe to call `CubeCAN_Tick()` from `main()` or any ISR +- Do not call any CubeCAN function from `CubeCAN_RxCallback()`, use it only to write data to shared memory (with concurrency safety as needed) ### Filters -Filters are on the user to setup and manage, it is recommended to setup a filter to ignore messsages not intended for your bord +You are responsible for configuring CAN filters. -You have direct access to define `HAL_FDCAN_RxFifo1Callback` as you like as well, the peripheral only uses `HAL_FDCAN_RxFifo0Callback` for all buses +Use `HAL_FDCAN_ConfigFilter()` in `MX_FDCAN#_Init()` to setup any filters you need. Configure the number and type of filters in STM32CubeMX. -### Rx Callback Context +#### Best Practices + +Create a filter to accept only messages intended for your board -You may find it helpful to have just one Rx callback function instead of one per handle +The library uses only `HAL_FDCAN_RxFifo0Callback()` for message reception, you can define your own `HAL_FDCAN_RxFifo1Callback()` for additional needs -You can do this by providing the same `CubeCAN_RxCallback` function pointer for each handle and specifying a `CubeCAN_Config_Context` per handle. +#### Message Overflow -`CubeCAN_Config_Context` supports both `GRCAN_BUS_ID` and arbitrary void pointers thanks to a unioned field which is type checked at compile time +If your received message FIFO overflows (messages arrive faster than they're processed), the library logs a warning and drops the oldest messages. + +Improve this by increasing callback efficiency or adding more CAN filters to reduce unwanted messages. + +### Rx Callback Context -Note that it is your responsibility to use either the void pointers or `GRCAN_BUS_ID` values, the peripheral treats this as a magic -32-bit value, the union is provided for your convenience for common cases (recieving messages from both a subnet and the proper bus -OR recieving messages from multiple buses) +You may consolidate multiple receive callbacks into a single function by passing different context data to each handle. + +Use the context union for this, it can point to arbitrary data or to a bus ID. It is your responsibility to be consistent the peripheral will just return input. ### Tx Message Marker Currently we do not do anything cool with this, but we could! -If you would like to see this do something please open an Issue (and if you want to code it, a PR as well) +If you would like to see this do something please open an Issue (and if you want to code it, a Pull Request as well) ### Assertions @@ -147,7 +186,15 @@ We currently provide compile time static assertions to validate: ### Globals -We store a global private array of CubeCAN handles (sized to `CUBEMX_CAN_MAX_INSTANCES`) +CubeCAN maintains a global private array of handles (sized to `CUBEMX_CAN_MAX_INSTANCES`). + +- Each handle is 28 bytes (overhead) +- Plus transmission queue: `CUBEMX_CAN_TX_QUEUE_SIZE` times `sizeof(GRCAN_Private_TxMessage)` (4 byte header and 64 bytes of data, at print time) + +If your chip supports multiple FDCAN peripherals but you need fewer, set `CUBEMX_CAN_MAX_INSTANCES` lower to avoid wasting memory on unused handles. Similarly, reduce `CUBEMX_CAN_TX_QUEUE_SIZE` if you send infrequently and have frequent ticks. + +## Troubleshooting + +TODO -Main point of allowing user provided `CUBEMX_CAN_MAX_INSTANCES` values is that each handle is 28 bytes not including the queue size, -but if you add a large queue on a chip that supports three CANFD peripherals and only need one peripherals that is a lot of wasted memory. +As issues are found we will extend this section. For now, please contact the Firmware Manager if you are unable to get this working. From 9a3b793abd5c3f2e08138c3d611d3348a30debfb Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 18:22:02 -0700 Subject: [PATCH 062/125] Fix stm32 assert header Signed-off-by: Daniel Hansen --- .gitignore | 2 ++ CUBEMXTESTING/Core/Inc/stm32_assert.h | 52 --------------------------- G4SPITESTING/Core/Inc/stm32_assert.h | 52 --------------------------- 3 files changed, 2 insertions(+), 104 deletions(-) delete mode 100644 CUBEMXTESTING/Core/Inc/stm32_assert.h delete mode 100644 G4SPITESTING/Core/Inc/stm32_assert.h diff --git a/.gitignore b/.gitignore index 29c4d66d5..fbae0bc9a 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,5 @@ EWARM .mxproject */Core/Src/system_stm32*xx.c */*/Core/Src/system_stm32*xx.c +*/Core/Inc/stm32_assert.h +*/*/Core/Inc/stm32_assert.h diff --git a/CUBEMXTESTING/Core/Inc/stm32_assert.h b/CUBEMXTESTING/Core/Inc/stm32_assert.h deleted file mode 100644 index 92460620f..000000000 --- a/CUBEMXTESTING/Core/Inc/stm32_assert.h +++ /dev/null @@ -1,52 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32_assert.h - * @author MCD Application Team - * @brief STM32 assert file. - ****************************************************************************** - * @attention - * - * Copyright (c) 2019 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 __STM32_ASSERT_H -#define __STM32_ASSERT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Includes ------------------------------------------------------------------*/ -/* 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 /* __STM32_ASSERT_H */ diff --git a/G4SPITESTING/Core/Inc/stm32_assert.h b/G4SPITESTING/Core/Inc/stm32_assert.h deleted file mode 100644 index 92460620f..000000000 --- a/G4SPITESTING/Core/Inc/stm32_assert.h +++ /dev/null @@ -1,52 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32_assert.h - * @author MCD Application Team - * @brief STM32 assert file. - ****************************************************************************** - * @attention - * - * Copyright (c) 2019 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 __STM32_ASSERT_H -#define __STM32_ASSERT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Includes ------------------------------------------------------------------*/ -/* 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 /* __STM32_ASSERT_H */ From 8cc568e2f19940bd3de855309adf4bbed492be67 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 18:24:05 -0700 Subject: [PATCH 063/125] Fix assert failed message Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Core/Src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index f72928de2..88a5add0c 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -222,7 +222,7 @@ void Error_Handler(void) void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ - printf("Assert failed! File %s on line %lu\n", file, line); + LOGOMATIC("Assert failed! File %s on line %u\n", file, line); /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ From 0d83071756306c0e74cf09024510870c360f4285 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 18:30:40 -0700 Subject: [PATCH 064/125] Setup more handles Signed-off-by: Daniel Hansen --- .../Application/Inc/CubeCAN_Config.h | 2 +- CUBEMXTESTING/Application/Src/CANdler.c | 6 - CUBEMXTESTING/Application/Src/Loop.c | 4 +- CUBEMXTESTING/CUBEMXTESTING.ioc | 6 +- CUBEMXTESTING/Core/Inc/fdcan.h | 1 + CUBEMXTESTING/Core/Inc/gpio.h | 1 + CUBEMXTESTING/Core/Inc/main.h | 15 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 215 ++++--- CUBEMXTESTING/Core/Inc/tim.h | 1 + CUBEMXTESTING/Core/Inc/usart.h | 1 + CUBEMXTESTING/Core/Src/fdcan.c | 525 ++++++++--------- CUBEMXTESTING/Core/Src/gpio.c | 537 +++++++++--------- CUBEMXTESTING/Core/Src/main.c | 189 +++--- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 24 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 197 +++---- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- CUBEMXTESTING/Core/Src/usart.c | 154 ++--- Lib/Peripherals/CubeCAN/Src/can_utils.c | 2 +- 18 files changed, 1030 insertions(+), 963 deletions(-) diff --git a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h index b582cbc55..e8345d49a 100644 --- a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h +++ b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h @@ -2,6 +2,6 @@ #define CUBE_CAN_CONFIG_H #define CUBEMX_CAN_TX_QUEUE_SIZE 16U -#define CUBEMX_CAN_MAX_INSTANCES 1U +#define CUBEMX_CAN_MAX_INSTANCES 3U #endif diff --git a/CUBEMXTESTING/Application/Src/CANdler.c b/CUBEMXTESTING/Application/Src/CANdler.c index 46ba32506..8d16b7c36 100644 --- a/CUBEMXTESTING/Application/Src/CANdler.c +++ b/CUBEMXTESTING/Application/Src/CANdler.c @@ -24,10 +24,4 @@ void CANdler_Callback(const CubeCAN_Config_Context *const context, const CAN_Ide const GRCAN_MSG_ID msg_id = identifier->msg_id; LOGOMATIC("Received on bus %d with node %d -> %d with message %d and size %u\t%.*s\n", busid, tx_node, rx_node, msg_id, size, size, (const char *const)data); - - // Uncomment to spam the bus - // (void)CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Bye0", 4); - // (void)CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Bye1", 4); - // (void)CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Bye2", 4); - // (void)CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Bye3", 4); } diff --git a/CUBEMXTESTING/Application/Src/Loop.c b/CUBEMXTESTING/Application/Src/Loop.c index f7250b60c..3461ceedb 100644 --- a/CUBEMXTESTING/Application/Src/Loop.c +++ b/CUBEMXTESTING/Application/Src/Loop.c @@ -12,5 +12,7 @@ void MainLoop(void) { LL_GPIO_TogglePin(USER_LED_GPIO_Port, USER_LED_Pin); LOGOMATIC("Main Loop %d\n", value); - (void)CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello!", 6); + (void)CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello0", 6); + (void)CubeCAN_Send(dataHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello1", 6); + (void)CubeCAN_Send(chargerHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello2", 6); } diff --git a/CUBEMXTESTING/CUBEMXTESTING.ioc b/CUBEMXTESTING/CUBEMXTESTING.ioc index 736997455..fdc2d8cba 100644 --- a/CUBEMXTESTING/CUBEMXTESTING.ioc +++ b/CUBEMXTESTING/CUBEMXTESTING.ioc @@ -27,7 +27,8 @@ FDCAN2.DataSyncJumpWidth=16 FDCAN2.DataTimeSeg1=14 FDCAN2.DataTimeSeg2=5 FDCAN2.ExtFiltersNbr=2 -FDCAN2.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal,AutoRetransmission,ProtocolException,NominalSyncJumpWidth,DataPrescaler,DataSyncJumpWidth,DataTimeSeg1,DataTimeSeg2,ExtFiltersNbr,NominalPrescaler,NominalTimeSeg1,NominalTimeSeg2 +FDCAN2.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal,AutoRetransmission,ProtocolException,NominalSyncJumpWidth,DataPrescaler,DataSyncJumpWidth,DataTimeSeg1,DataTimeSeg2,ExtFiltersNbr,NominalPrescaler,NominalTimeSeg1,NominalTimeSeg2,Mode +FDCAN2.Mode=FDCAN_MODE_INTERNAL_LOOPBACK FDCAN2.NominalPrescaler=1 FDCAN2.NominalSyncJumpWidth=16 FDCAN2.NominalTimeSeg1=119 @@ -36,7 +37,8 @@ FDCAN2.ProtocolException=ENABLE FDCAN3.CalculateBaudRateNominal=3333333 FDCAN3.CalculateTimeBitNominal=300 FDCAN3.CalculateTimeQuantumNominal=100.0 -FDCAN3.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal +FDCAN3.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal,Mode +FDCAN3.Mode=FDCAN_MODE_INTERNAL_LOOPBACK File.Version=6 GPIO.groupedBy=Group By Peripherals KeepUserPlacement=false diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 3597c6476..21271cf64 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -55,3 +55,4 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 37dcc0a5c..03c2faca5 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -46,3 +46,4 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index c796cd49a..2b50abc31 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,16 +28,17 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" + +#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_dma.h" -#include "stm32g4xx_ll_exti.h" -#include "stm32g4xx_ll_gpio.h" -#include "stm32g4xx_ll_pwr.h" -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_exti.h" +#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_utils.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -50,6 +51,8 @@ extern "C" { /* Exported types ------------------------------------------------------------*/ /* USER CODE BEGIN ET */ extern CubeCAN_Handle *primaryHandle; +extern CubeCAN_Handle *dataHandle; +extern CubeCAN_Handle *chargerHandle; /* USER CODE END ET */ /* Exported constants --------------------------------------------------------*/ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index d12d585bd..e4db34d37 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus -extern "C" { + extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ extern "C" { /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED -/*#define HAL_ADC_MODULE_ENABLED */ + /*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -76,124 +76,123 @@ extern "C" { /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(HSE_STARTUP_TIMEOUT) -#define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined(HSI48_VALUE) -#define HSI48_VALUE \ - (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined (HSI48_VALUE) + #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined(LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined(LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined(LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined (LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined(EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -#define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ + #define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -202,12 +201,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -358,15 +357,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index 2d20bd560..b90657cf4 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,3 +49,4 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/CUBEMXTESTING/Core/Inc/usart.h index bdec0c9cb..49dd0cccc 100644 --- a/CUBEMXTESTING/Core/Inc/usart.h +++ b/CUBEMXTESTING/Core/Inc/usart.h @@ -49,3 +49,4 @@ void MX_LPUART1_UART_Init(void); #endif #endif /* __USART_H__ */ + diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 359327d14..08b2a1b8a 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,281 +32,298 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ + } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_NORMAL; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ + } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_NORMAL; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ + } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN3) { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) { - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN3) { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index d0d390b5b..d4094cc2b 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -33,277 +33,278 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) - */ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) +*/ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 88a5add0c..a992d9c24 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,14 +18,15 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" - #include "fdcan.h" -#include "gpio.h" -#include "tim.h" #include "usart.h" +#include "tim.h" +#include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ +#include + #include "CANdler.h" #include "CubeCAN.h" #include "GRCAN_BUS_ID.h" @@ -58,6 +59,8 @@ /* USER CODE BEGIN PV */ CubeCAN_Handle *primaryHandle = NULL; +CubeCAN_Handle *dataHandle = NULL; +CubeCAN_Handle *chargerHandle = NULL; LogomaticConfig logomaticConfig = {.clock_source = LOGOMATIC_PCLK1, .bus = LOGOMATIC_BUS, @@ -86,102 +89,126 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - MX_LPUART1_UART_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + MX_LPUART1_UART_Init(); + /* USER CODE BEGIN 2 */ Setup_Logomatic(&logomaticConfig); CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; + CubeCAN_Config dataCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_DATA, .sending_node_id = GRCAN_Debugger}; + CubeCAN_Config chargerCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_CHARGER, .sending_node_id = GRCAN_Debugger}; + primaryHandle = CubeCAN_Entrance(&hfdcan1, &primaryCanConfig); if (primaryHandle == NULL) { LOGOMATIC("Failed to initialize primary CAN handle\n"); Error_Handler(); } + + dataHandle = CubeCAN_Entrance(&hfdcan2, &dataCanConfig); + if (dataHandle == NULL) { + LOGOMATIC("Failed to initialize data CAN handle\n"); + Error_Handler(); + } + + chargerHandle = CubeCAN_Entrance(&hfdcan3, &chargerCanConfig); + if (chargerHandle == NULL) { + LOGOMATIC("Failed to initialize charger CAN handle\n"); + Error_Handler(); + } + LOGOMATIC("Hello World!\n"); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); HAL_Delay(1000); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) + { + } + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while(LL_RCC_HSI_IsReady() != 1) + { + } + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while(LL_RCC_PLL_IsReady() != 1) + { + } + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) + { + } + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i !=0; i--); + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) + { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -200,29 +227,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ - LOGOMATIC("Assert failed! File %s on line %u\n", file, line); - /* USER CODE END 6 */ + /* USER CODE BEGIN 6 */ + LOGOMATIC("Assert failed! File %s on line %" PRIu32 "\n", file, line); + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index 4668755ab..2cc7d8296 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index fd2ad329f..78d6b9cd9 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,9 +18,8 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "stm32g4xx_it.h" - #include "main.h" +#include "stm32g4xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -68,125 +67,129 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -197,59 +200,59 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index 1f6110e86..cc6e6a92e 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,76 +30,83 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 159; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 499; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 159; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 499; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) + { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ + /* USER CODE END TIM5_Init 2 */ + } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) { - if (tim_baseHandle->Instance == TIM5) { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) { - if (tim_baseHandle->Instance == TIM5) { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/Core/Src/usart.c b/CUBEMXTESTING/Core/Src/usart.c index 4e3f96e17..53d379951 100644 --- a/CUBEMXTESTING/Core/Src/usart.c +++ b/CUBEMXTESTING/Core/Src/usart.c @@ -31,93 +31,101 @@ UART_HandleTypeDef hlpuart1; void MX_LPUART1_UART_Init(void) { - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - hlpuart1.Instance = LPUART1; - hlpuart1.Init.BaudRate = 115200; - hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; - hlpuart1.Init.StopBits = UART_STOPBITS_1; - hlpuart1.Init.Parity = UART_PARITY_NONE; - hlpuart1.Init.Mode = UART_MODE_TX_RX; - hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&hlpuart1) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ + /* USER CODE BEGIN LPUART1_Init 0 */ + + /* USER CODE END LPUART1_Init 0 */ + + /* USER CODE BEGIN LPUART1_Init 1 */ + + /* USER CODE END LPUART1_Init 1 */ + hlpuart1.Instance = LPUART1; + hlpuart1.Init.BaudRate = 115200; + hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; + hlpuart1.Init.StopBits = UART_STOPBITS_1; + hlpuart1.Init.Parity = UART_PARITY_NONE; + hlpuart1.Init.Mode = UART_MODE_TX_RX; + hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&hlpuart1) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN LPUART1_Init 2 */ + + /* USER CODE END LPUART1_Init 2 */ + } -void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle) +void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (uartHandle->Instance == LPUART1) { - /* USER CODE BEGIN LPUART1_MspInit 0 */ - - /* USER CODE END LPUART1_MspInit 0 */ - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* LPUART1 clock enable */ - __HAL_RCC_LPUART1_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**LPUART1 GPIO Configuration - PC0 ------> LPUART1_RX - PC1 ------> LPUART1_TX - */ - 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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN LPUART1_MspInit 1 */ - - /* USER CODE END LPUART1_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(uartHandle->Instance==LPUART1) + { + /* USER CODE BEGIN LPUART1_MspInit 0 */ + + /* USER CODE END LPUART1_MspInit 0 */ + LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); + + /* LPUART1 clock enable */ + __HAL_RCC_LPUART1_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**LPUART1 GPIO Configuration + PC0 ------> LPUART1_RX + PC1 ------> LPUART1_TX + */ + 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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /* USER CODE BEGIN LPUART1_MspInit 1 */ + + /* USER CODE END LPUART1_MspInit 1 */ + } } -void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle) +void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { - if (uartHandle->Instance == LPUART1) { - /* USER CODE BEGIN LPUART1_MspDeInit 0 */ + if(uartHandle->Instance==LPUART1) + { + /* USER CODE BEGIN LPUART1_MspDeInit 0 */ - /* USER CODE END LPUART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_LPUART1_CLK_DISABLE(); + /* USER CODE END LPUART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_LPUART1_CLK_DISABLE(); - /**LPUART1 GPIO Configuration - PC0 ------> LPUART1_RX - PC1 ------> LPUART1_TX - */ - HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0 | GPIO_PIN_1); + /**LPUART1 GPIO Configuration + PC0 ------> LPUART1_RX + PC1 ------> LPUART1_TX + */ + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1); - /* USER CODE BEGIN LPUART1_MspDeInit 1 */ + /* USER CODE BEGIN LPUART1_MspDeInit 1 */ - /* USER CODE END LPUART1_MspDeInit 1 */ - } + /* USER CODE END LPUART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index 69dbc3018..f1959b8dc 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -160,7 +160,7 @@ HAL_StatusTypeDef CubeCAN_Private_RecoverPeripheral(const CubeCAN_Handle *const FDCAN_ProtocolStatusTypeDef protocol_status = {0}; if (HAL_FDCAN_GetProtocolStatus(handle->hfdcan, &protocol_status) == HAL_OK && protocol_status.BusOff) { - LOGOMATIC("CubeCAN_Private_RecoverPeripheral: CRITICAL BUS-OFF DETECTED. Forcing instant hardware reset...\n"); + LOGOMATIC("CubeCAN_Private_RecoverPeripheral: CRITICAL BUS-OFF DETECTED. Forcing hardware reset...\n"); HAL_FDCAN_Stop(handle->hfdcan); From 079097edba6dc6505d09826a59e7e9b57bd169be Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2026 01:32:00 +0000 Subject: [PATCH 065/125] Automatic Clang-Format: Standardized formatting automatically --- CUBEMXTESTING/Core/Inc/fdcan.h | 1 - CUBEMXTESTING/Core/Inc/gpio.h | 1 - CUBEMXTESTING/Core/Inc/main.h | 13 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 215 ++++---- CUBEMXTESTING/Core/Inc/tim.h | 1 - CUBEMXTESTING/Core/Inc/usart.h | 1 - CUBEMXTESTING/Core/Src/fdcan.c | 525 +++++++++---------- CUBEMXTESTING/Core/Src/gpio.c | 537 ++++++++++---------- CUBEMXTESTING/Core/Src/main.c | 169 +++--- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 24 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 197 ++++--- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- CUBEMXTESTING/Core/Src/usart.c | 154 +++--- 13 files changed, 952 insertions(+), 999 deletions(-) diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 21271cf64..3597c6476 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -55,4 +55,3 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 03c2faca5..37dcc0a5c 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -46,4 +46,3 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index 2b50abc31..cbeced83f 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,17 +28,16 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" - -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_system.h" -#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_utils.h" -#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_crs.h" #include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_gpio.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_rcc.h" +#include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_utils.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index e4db34d37..d12d585bd 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED - /*#define HAL_ADC_MODULE_ENABLED */ +/*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -76,123 +76,124 @@ /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined(HSE_STARTUP_TIMEOUT) +#define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined (HSI48_VALUE) - #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined(HSI48_VALUE) +#define HSI48_VALUE \ + (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined(LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined (LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined(LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined (LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined(LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined (EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined(EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ - #define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +#define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -201,12 +202,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -357,15 +358,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index b90657cf4..2d20bd560 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,4 +49,3 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/CUBEMXTESTING/Core/Inc/usart.h index 49dd0cccc..bdec0c9cb 100644 --- a/CUBEMXTESTING/Core/Inc/usart.h +++ b/CUBEMXTESTING/Core/Inc/usart.h @@ -49,4 +49,3 @@ void MX_LPUART1_UART_Init(void); #endif #endif /* __USART_H__ */ - diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 08b2a1b8a..30b3c9dc1 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,298 +32,281 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ - + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ - + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ - + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) { - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index d4094cc2b..d0d390b5b 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -33,278 +33,277 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) -*/ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) + */ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index a992d9c24..80b878dcd 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,10 +18,11 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" + #include "fdcan.h" -#include "usart.h" -#include "tim.h" #include "gpio.h" +#include "tim.h" +#include "usart.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -89,40 +90,40 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - MX_LPUART1_UART_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + MX_LPUART1_UART_Init(); + /* USER CODE BEGIN 2 */ Setup_Logomatic(&logomaticConfig); CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; @@ -146,69 +147,61 @@ int main(void) LOGOMATIC("Failed to initialize charger CAN handle\n"); Error_Handler(); } - + LOGOMATIC("Hello World!\n"); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); HAL_Delay(1000); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) - { - } - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while(LL_RCC_HSI_IsReady() != 1) - { - } - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while(LL_RCC_PLL_IsReady() != 1) - { - } - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) - { - } - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i !=0; i--); - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) - { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while (LL_RCC_HSI_IsReady() != 1) {} + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while (LL_RCC_PLL_IsReady() != 1) {} + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i != 0; i--) + ; + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -227,29 +220,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ LOGOMATIC("Assert failed! File %s on line %" PRIu32 "\n", file, line); - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index 2cc7d8296..4668755ab 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index 78d6b9cd9..fd2ad329f 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,8 +18,9 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "main.h" #include "stm32g4xx_it.h" + +#include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -67,129 +68,125 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -200,59 +197,59 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index cc6e6a92e..1f6110e86 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,83 +30,76 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 159; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 499; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) - { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) - { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 159; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 499; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ - + /* USER CODE END TIM5_Init 2 */ } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/usart.c b/CUBEMXTESTING/Core/Src/usart.c index 53d379951..4e3f96e17 100644 --- a/CUBEMXTESTING/Core/Src/usart.c +++ b/CUBEMXTESTING/Core/Src/usart.c @@ -31,101 +31,93 @@ UART_HandleTypeDef hlpuart1; void MX_LPUART1_UART_Init(void) { - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - hlpuart1.Instance = LPUART1; - hlpuart1.Init.BaudRate = 115200; - hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; - hlpuart1.Init.StopBits = UART_STOPBITS_1; - hlpuart1.Init.Parity = UART_PARITY_NONE; - hlpuart1.Init.Mode = UART_MODE_TX_RX; - hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&hlpuart1) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ - + /* USER CODE BEGIN LPUART1_Init 0 */ + + /* USER CODE END LPUART1_Init 0 */ + + /* USER CODE BEGIN LPUART1_Init 1 */ + + /* USER CODE END LPUART1_Init 1 */ + hlpuart1.Instance = LPUART1; + hlpuart1.Init.BaudRate = 115200; + hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; + hlpuart1.Init.StopBits = UART_STOPBITS_1; + hlpuart1.Init.Parity = UART_PARITY_NONE; + hlpuart1.Init.Mode = UART_MODE_TX_RX; + hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&hlpuart1) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN LPUART1_Init 2 */ + + /* USER CODE END LPUART1_Init 2 */ } -void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) +void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(uartHandle->Instance==LPUART1) - { - /* USER CODE BEGIN LPUART1_MspInit 0 */ - - /* USER CODE END LPUART1_MspInit 0 */ - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* LPUART1 clock enable */ - __HAL_RCC_LPUART1_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**LPUART1 GPIO Configuration - PC0 ------> LPUART1_RX - PC1 ------> LPUART1_TX - */ - 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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN LPUART1_MspInit 1 */ - - /* USER CODE END LPUART1_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (uartHandle->Instance == LPUART1) { + /* USER CODE BEGIN LPUART1_MspInit 0 */ + + /* USER CODE END LPUART1_MspInit 0 */ + LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); + + /* LPUART1 clock enable */ + __HAL_RCC_LPUART1_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**LPUART1 GPIO Configuration + PC0 ------> LPUART1_RX + PC1 ------> LPUART1_TX + */ + 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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /* USER CODE BEGIN LPUART1_MspInit 1 */ + + /* USER CODE END LPUART1_MspInit 1 */ + } } -void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) +void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle) { - if(uartHandle->Instance==LPUART1) - { - /* USER CODE BEGIN LPUART1_MspDeInit 0 */ + if (uartHandle->Instance == LPUART1) { + /* USER CODE BEGIN LPUART1_MspDeInit 0 */ - /* USER CODE END LPUART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_LPUART1_CLK_DISABLE(); + /* USER CODE END LPUART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_LPUART1_CLK_DISABLE(); - /**LPUART1 GPIO Configuration - PC0 ------> LPUART1_RX - PC1 ------> LPUART1_TX - */ - HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1); + /**LPUART1 GPIO Configuration + PC0 ------> LPUART1_RX + PC1 ------> LPUART1_TX + */ + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0 | GPIO_PIN_1); - /* USER CODE BEGIN LPUART1_MspDeInit 1 */ + /* USER CODE BEGIN LPUART1_MspDeInit 1 */ - /* USER CODE END LPUART1_MspDeInit 1 */ - } + /* USER CODE END LPUART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - From d4ff2c48de13a595a73b454d4c4de546e61e74b5 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 18:32:58 -0700 Subject: [PATCH 066/125] Speedup Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Core/Src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 80b878dcd..1378cb0e5 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -158,7 +158,7 @@ int main(void) /* USER CODE BEGIN 3 */ MainLoop(); - HAL_Delay(1000); + HAL_Delay(1); } /* USER CODE END 3 */ } From ba817ae01f5ea32478d136a7842966a8d9935881 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 23:14:46 -0700 Subject: [PATCH 067/125] Timer safety! Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Application/Src/CANdler.c | 2 +- CUBEMXTESTING/Application/Src/Loop.c | 4 +- CUBEMXTESTING/CUBEMXTESTING.ioc | 7 +- CUBEMXTESTING/Core/Inc/fdcan.h | 1 + CUBEMXTESTING/Core/Inc/gpio.h | 1 + CUBEMXTESTING/Core/Inc/main.h | 13 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 215 ++++--- CUBEMXTESTING/Core/Inc/tim.h | 1 + CUBEMXTESTING/Core/Inc/usart.h | 1 + CUBEMXTESTING/Core/Src/fdcan.c | 525 ++++++++--------- CUBEMXTESTING/Core/Src/gpio.c | 537 +++++++++--------- CUBEMXTESTING/Core/Src/main.c | 169 +++--- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 24 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 197 +++---- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- CUBEMXTESTING/Core/Src/usart.c | 154 ++--- Lib/Peripherals/CubeCAN/Inc/CubeCAN.h | 7 +- .../CubeCAN/Src/PrivateInc/internal.h | 10 + Lib/Peripherals/CubeCAN/Src/can_init.c | 2 +- Lib/Peripherals/CubeCAN/Src/can_tx.c | 36 ++ 20 files changed, 1060 insertions(+), 959 deletions(-) diff --git a/CUBEMXTESTING/Application/Src/CANdler.c b/CUBEMXTESTING/Application/Src/CANdler.c index 8d16b7c36..45b5a64fd 100644 --- a/CUBEMXTESTING/Application/Src/CANdler.c +++ b/CUBEMXTESTING/Application/Src/CANdler.c @@ -23,5 +23,5 @@ void CANdler_Callback(const CubeCAN_Config_Context *const context, const CAN_Ide const GRCAN_NODE_ID rx_node = identifier->rx_node_id; const GRCAN_MSG_ID msg_id = identifier->msg_id; - LOGOMATIC("Received on bus %d with node %d -> %d with message %d and size %u\t%.*s\n", busid, tx_node, rx_node, msg_id, size, size, (const char *const)data); + // LOGOMATIC("Received on bus %d with node %d -> %d with message %d and size %u\t%.*s\n", busid, tx_node, rx_node, msg_id, size, size, (const char *const)data); } diff --git a/CUBEMXTESTING/Application/Src/Loop.c b/CUBEMXTESTING/Application/Src/Loop.c index 3461ceedb..f4125d3b5 100644 --- a/CUBEMXTESTING/Application/Src/Loop.c +++ b/CUBEMXTESTING/Application/Src/Loop.c @@ -1,5 +1,7 @@ #include "Loop.h" +#include + #include "CubeCAN.h" #include "GRCAN_MSG_ID.h" #include "GRCAN_NODE_ID.h" @@ -11,7 +13,7 @@ extern int value; void MainLoop(void) { LL_GPIO_TogglePin(USER_LED_GPIO_Port, USER_LED_Pin); - LOGOMATIC("Main Loop %d\n", value); + LOGOMATIC("Main Loop %d %" PRIu32 "\n", value, HAL_GetTick()); (void)CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello0", 6); (void)CubeCAN_Send(dataHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello1", 6); (void)CubeCAN_Send(chargerHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello2", 6); diff --git a/CUBEMXTESTING/CUBEMXTESTING.ioc b/CUBEMXTESTING/CUBEMXTESTING.ioc index fdc2d8cba..fac4bcf68 100644 --- a/CUBEMXTESTING/CUBEMXTESTING.ioc +++ b/CUBEMXTESTING/CUBEMXTESTING.ioc @@ -211,9 +211,10 @@ RCC.USART3Freq_Value=160000000 RCC.USBFreq_Value=160000000 RCC.VCOInputFreq_Value=16000000 RCC.VCOOutputFreq_Value=320000000 -TIM5.IPParameters=Prescaler,PeriodNoDither -TIM5.PeriodNoDither=499 -TIM5.Prescaler=159 +TIM5.Dithering=Disable +TIM5.IPParameters=Prescaler,PeriodNoDither,Dithering +TIM5.PeriodNoDither=49 +TIM5.Prescaler=1599 VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals VP_SYS_VS_Systick.Mode=SysTick diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 3597c6476..21271cf64 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -55,3 +55,4 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 37dcc0a5c..03c2faca5 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -46,3 +46,4 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index cbeced83f..2b50abc31 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,16 +28,17 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" + +#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_dma.h" -#include "stm32g4xx_ll_exti.h" -#include "stm32g4xx_ll_gpio.h" -#include "stm32g4xx_ll_pwr.h" -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_exti.h" +#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_utils.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index d12d585bd..e4db34d37 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus -extern "C" { + extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ extern "C" { /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED -/*#define HAL_ADC_MODULE_ENABLED */ + /*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -76,124 +76,123 @@ extern "C" { /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(HSE_STARTUP_TIMEOUT) -#define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined(HSI48_VALUE) -#define HSI48_VALUE \ - (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined (HSI48_VALUE) + #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined(LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined(LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined(LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined (LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined(EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -#define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ + #define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -202,12 +201,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -358,15 +357,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index 2d20bd560..b90657cf4 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,3 +49,4 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/CUBEMXTESTING/Core/Inc/usart.h index bdec0c9cb..49dd0cccc 100644 --- a/CUBEMXTESTING/Core/Inc/usart.h +++ b/CUBEMXTESTING/Core/Inc/usart.h @@ -49,3 +49,4 @@ void MX_LPUART1_UART_Init(void); #endif #endif /* __USART_H__ */ + diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 30b3c9dc1..08b2a1b8a 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,281 +32,298 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ + } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ + } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ + } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN3) { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) { - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN3) { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index d0d390b5b..d4094cc2b 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -33,277 +33,278 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) - */ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) +*/ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 1378cb0e5..6fd9381ed 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,11 +18,10 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" - #include "fdcan.h" -#include "gpio.h" -#include "tim.h" #include "usart.h" +#include "tim.h" +#include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -90,40 +89,40 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - MX_LPUART1_UART_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + MX_LPUART1_UART_Init(); + /* USER CODE BEGIN 2 */ Setup_Logomatic(&logomaticConfig); CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; @@ -149,59 +148,67 @@ int main(void) } LOGOMATIC("Hello World!\n"); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); - HAL_Delay(1); + HAL_Delay(0); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) + { + } + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while(LL_RCC_HSI_IsReady() != 1) + { + } + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while(LL_RCC_PLL_IsReady() != 1) + { + } + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) + { + } + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i !=0; i--); + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) + { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -220,29 +227,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ LOGOMATIC("Assert failed! File %s on line %" PRIu32 "\n", file, line); - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index 4668755ab..2cc7d8296 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index fd2ad329f..78d6b9cd9 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,9 +18,8 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "stm32g4xx_it.h" - #include "main.h" +#include "stm32g4xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -68,125 +67,129 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -197,59 +200,59 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index 1f6110e86..aa26dcf71 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,76 +30,83 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 159; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 499; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 1599; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 49; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) + { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ + /* USER CODE END TIM5_Init 2 */ + } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) { - if (tim_baseHandle->Instance == TIM5) { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) { - if (tim_baseHandle->Instance == TIM5) { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/Core/Src/usart.c b/CUBEMXTESTING/Core/Src/usart.c index 4e3f96e17..53d379951 100644 --- a/CUBEMXTESTING/Core/Src/usart.c +++ b/CUBEMXTESTING/Core/Src/usart.c @@ -31,93 +31,101 @@ UART_HandleTypeDef hlpuart1; void MX_LPUART1_UART_Init(void) { - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - hlpuart1.Instance = LPUART1; - hlpuart1.Init.BaudRate = 115200; - hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; - hlpuart1.Init.StopBits = UART_STOPBITS_1; - hlpuart1.Init.Parity = UART_PARITY_NONE; - hlpuart1.Init.Mode = UART_MODE_TX_RX; - hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&hlpuart1) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ + /* USER CODE BEGIN LPUART1_Init 0 */ + + /* USER CODE END LPUART1_Init 0 */ + + /* USER CODE BEGIN LPUART1_Init 1 */ + + /* USER CODE END LPUART1_Init 1 */ + hlpuart1.Instance = LPUART1; + hlpuart1.Init.BaudRate = 115200; + hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; + hlpuart1.Init.StopBits = UART_STOPBITS_1; + hlpuart1.Init.Parity = UART_PARITY_NONE; + hlpuart1.Init.Mode = UART_MODE_TX_RX; + hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&hlpuart1) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN LPUART1_Init 2 */ + + /* USER CODE END LPUART1_Init 2 */ + } -void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle) +void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (uartHandle->Instance == LPUART1) { - /* USER CODE BEGIN LPUART1_MspInit 0 */ - - /* USER CODE END LPUART1_MspInit 0 */ - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* LPUART1 clock enable */ - __HAL_RCC_LPUART1_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**LPUART1 GPIO Configuration - PC0 ------> LPUART1_RX - PC1 ------> LPUART1_TX - */ - 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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN LPUART1_MspInit 1 */ - - /* USER CODE END LPUART1_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(uartHandle->Instance==LPUART1) + { + /* USER CODE BEGIN LPUART1_MspInit 0 */ + + /* USER CODE END LPUART1_MspInit 0 */ + LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); + + /* LPUART1 clock enable */ + __HAL_RCC_LPUART1_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**LPUART1 GPIO Configuration + PC0 ------> LPUART1_RX + PC1 ------> LPUART1_TX + */ + 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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /* USER CODE BEGIN LPUART1_MspInit 1 */ + + /* USER CODE END LPUART1_MspInit 1 */ + } } -void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle) +void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { - if (uartHandle->Instance == LPUART1) { - /* USER CODE BEGIN LPUART1_MspDeInit 0 */ + if(uartHandle->Instance==LPUART1) + { + /* USER CODE BEGIN LPUART1_MspDeInit 0 */ - /* USER CODE END LPUART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_LPUART1_CLK_DISABLE(); + /* USER CODE END LPUART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_LPUART1_CLK_DISABLE(); - /**LPUART1 GPIO Configuration - PC0 ------> LPUART1_RX - PC1 ------> LPUART1_TX - */ - HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0 | GPIO_PIN_1); + /**LPUART1 GPIO Configuration + PC0 ------> LPUART1_RX + PC1 ------> LPUART1_TX + */ + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1); - /* USER CODE BEGIN LPUART1_MspDeInit 1 */ + /* USER CODE BEGIN LPUART1_MspDeInit 1 */ - /* USER CODE END LPUART1_MspDeInit 1 */ - } + /* USER CODE END LPUART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h b/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h index 9af5ece36..df16b5a82 100644 --- a/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h +++ b/Lib/Peripherals/CubeCAN/Inc/CubeCAN.h @@ -95,7 +95,12 @@ HAL_StatusTypeDef CubeCAN_Exit(CubeCAN_Handle *handle); /** * @brief Processes periodic tasks for the CubeCAN CAN handle, such as handling timeouts and managing the transmission queue. - * @warning This function sends one can message per configured bus per call. Not calling it will simply not send any messages. + * + * For each configured bus, this function will send one CAN message per call. It is recommended to call this function at a regular interval to ensure timely processing of CAN messages. + * + * @note This function sends one can message per configured bus per call. Not calling it will simply not send any messages. + * @warning It is recommended to call this function no more than and no less than once every 625 us. + * @warning This function checks during early boot that it is not called more than ABSOLUTE_MAX_INVOCATIONS_PER_TICK times per millisecond, failing if so */ void CubeCAN_Tick(void); diff --git a/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h b/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h index 84afa706c..840f01660 100644 --- a/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h +++ b/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h @@ -54,6 +54,16 @@ */ #define FDCAN_MAX_DATA_BYTES (64U) +/** + * @brief Absolute maximum number of CubeCAN_Tick invocations per millisecond. + * + * This value is used to detect if the CubeCAN_Tick function is being called too frequently, which could indicate a problem with the invocation method. + * + * @note If you need to think about increasing this, you need to evaluate + * @warning If this value is exceeded, the system will trigger an error handler to prevent potential issues but this is checked only during a short duration starting after early boot and ending after a few seconds + */ +#define ABSOLUTE_MAX_INVOCATIONS_PER_TICK 2U + /** * @brief Transmission CAN message structure * diff --git a/Lib/Peripherals/CubeCAN/Src/can_init.c b/Lib/Peripherals/CubeCAN/Src/can_init.c index f10e27711..c3ef59e68 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_init.c +++ b/Lib/Peripherals/CubeCAN/Src/can_init.c @@ -206,4 +206,4 @@ HAL_StatusTypeDef CubeCAN_Private_Stop(CubeCAN_Handle *const handle) } return status; -} +} \ No newline at end of file diff --git a/Lib/Peripherals/CubeCAN/Src/can_tx.c b/Lib/Peripherals/CubeCAN/Src/can_tx.c index 752167563..a8d555179 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_tx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_tx.c @@ -1,15 +1,51 @@ +#include #include #include #include #include "CriticalSection.h" #include "CubeCAN.h" +#include "CubeCAN_Config.h" #include "Logomatic.h" #include "PrivateInc/internal.h" #include "main.h" +void CubeCAN_Private_RateChecker(void) +{ + static uint32_t last_tick = 0; + static uint32_t call_count_in_tick = 0; + static uint32_t violations = 0; + + const uint32_t current_tick = HAL_GetTick(); + + if (current_tick == last_tick) { + call_count_in_tick++; + } else { + last_tick = current_tick; + call_count_in_tick = 1; + } + + if (current_tick > 10U && call_count_in_tick > ABSOLUTE_MAX_INVOCATIONS_PER_TICK) { + LOGOMATIC("CubeCAN_Tick: called too frequently (%" PRIu32 " times in 1 ms), you NEED to fix your timers!\tViolation %" PRIu32 "\n", call_count_in_tick, ++violations); +#ifdef RELAXED_TIMER_GATE // Hidden feature flag if you REALLY know what you are doing but you should fix your timers instead +#warning "CubeCAN_Tick: Compiled with RELAXED_TIMER_GATE, this is a hidden feature flag that allows you to ignore the timer violation but you really should fix your timers" +#else + Error_Handler(); +#endif + } +} + void CubeCAN_Tick(void) { + static bool rate_checker_gate = false; + if (__builtin_expect(!rate_checker_gate, 0)) { + CubeCAN_Private_RateChecker(); + + if (HAL_GetTick() > 10000U) { // Disable check after 10 sec + rate_checker_gate = true; + } + } + for (uint8_t i = 0U; i < CUBEMX_CAN_MAX_INSTANCES; ++i) { CubeCAN_Handle *handle = &handles[i]; From 972cd1a832b4a36ba4916326352cf9613799283b Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2026 06:16:09 +0000 Subject: [PATCH 068/125] Automatic Clang-Format: Standardized formatting automatically --- CUBEMXTESTING/Core/Inc/fdcan.h | 1 - CUBEMXTESTING/Core/Inc/gpio.h | 1 - CUBEMXTESTING/Core/Inc/main.h | 13 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 215 +++---- CUBEMXTESTING/Core/Inc/tim.h | 1 - CUBEMXTESTING/Core/Inc/usart.h | 1 - CUBEMXTESTING/Core/Src/fdcan.c | 525 +++++++++-------- CUBEMXTESTING/Core/Src/gpio.c | 537 +++++++++--------- CUBEMXTESTING/Core/Src/main.c | 167 +++--- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 24 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 197 ++++--- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- CUBEMXTESTING/Core/Src/usart.c | 154 +++-- .../CubeCAN/Src/PrivateInc/internal.h | 3 +- 14 files changed, 953 insertions(+), 999 deletions(-) diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 21271cf64..3597c6476 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -55,4 +55,3 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 03c2faca5..37dcc0a5c 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -46,4 +46,3 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index 2b50abc31..cbeced83f 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,17 +28,16 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" - -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_system.h" -#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_utils.h" -#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_crs.h" #include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_gpio.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_rcc.h" +#include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_utils.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index e4db34d37..d12d585bd 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED - /*#define HAL_ADC_MODULE_ENABLED */ +/*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -76,123 +76,124 @@ /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined(HSE_STARTUP_TIMEOUT) +#define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined (HSI48_VALUE) - #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined(HSI48_VALUE) +#define HSI48_VALUE \ + (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined(LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined (LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined(LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined (LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined(LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined (EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined(EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ - #define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +#define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -201,12 +202,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -357,15 +358,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index b90657cf4..2d20bd560 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,4 +49,3 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/CUBEMXTESTING/Core/Inc/usart.h index 49dd0cccc..bdec0c9cb 100644 --- a/CUBEMXTESTING/Core/Inc/usart.h +++ b/CUBEMXTESTING/Core/Inc/usart.h @@ -49,4 +49,3 @@ void MX_LPUART1_UART_Init(void); #endif #endif /* __USART_H__ */ - diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 08b2a1b8a..30b3c9dc1 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,298 +32,281 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ - + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ - + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ - + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) { - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index d4094cc2b..d0d390b5b 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -33,278 +33,277 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) -*/ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) + */ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 6fd9381ed..5552d7761 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,10 +18,11 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" + #include "fdcan.h" -#include "usart.h" -#include "tim.h" #include "gpio.h" +#include "tim.h" +#include "usart.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -89,40 +90,40 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - MX_LPUART1_UART_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + MX_LPUART1_UART_Init(); + /* USER CODE BEGIN 2 */ Setup_Logomatic(&logomaticConfig); CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; @@ -148,67 +149,59 @@ int main(void) } LOGOMATIC("Hello World!\n"); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); HAL_Delay(0); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) - { - } - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while(LL_RCC_HSI_IsReady() != 1) - { - } - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while(LL_RCC_PLL_IsReady() != 1) - { - } - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) - { - } - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i !=0; i--); - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) - { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while (LL_RCC_HSI_IsReady() != 1) {} + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while (LL_RCC_PLL_IsReady() != 1) {} + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i != 0; i--) + ; + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -227,29 +220,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ LOGOMATIC("Assert failed! File %s on line %" PRIu32 "\n", file, line); - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index 2cc7d8296..4668755ab 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index 78d6b9cd9..fd2ad329f 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,8 +18,9 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "main.h" #include "stm32g4xx_it.h" + +#include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -67,129 +68,125 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -200,59 +197,59 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index aa26dcf71..e77341bf2 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,83 +30,76 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 1599; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 49; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) - { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) - { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 1599; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 49; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ - + /* USER CODE END TIM5_Init 2 */ } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/usart.c b/CUBEMXTESTING/Core/Src/usart.c index 53d379951..4e3f96e17 100644 --- a/CUBEMXTESTING/Core/Src/usart.c +++ b/CUBEMXTESTING/Core/Src/usart.c @@ -31,101 +31,93 @@ UART_HandleTypeDef hlpuart1; void MX_LPUART1_UART_Init(void) { - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - hlpuart1.Instance = LPUART1; - hlpuart1.Init.BaudRate = 115200; - hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; - hlpuart1.Init.StopBits = UART_STOPBITS_1; - hlpuart1.Init.Parity = UART_PARITY_NONE; - hlpuart1.Init.Mode = UART_MODE_TX_RX; - hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&hlpuart1) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ - + /* USER CODE BEGIN LPUART1_Init 0 */ + + /* USER CODE END LPUART1_Init 0 */ + + /* USER CODE BEGIN LPUART1_Init 1 */ + + /* USER CODE END LPUART1_Init 1 */ + hlpuart1.Instance = LPUART1; + hlpuart1.Init.BaudRate = 115200; + hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; + hlpuart1.Init.StopBits = UART_STOPBITS_1; + hlpuart1.Init.Parity = UART_PARITY_NONE; + hlpuart1.Init.Mode = UART_MODE_TX_RX; + hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&hlpuart1) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN LPUART1_Init 2 */ + + /* USER CODE END LPUART1_Init 2 */ } -void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) +void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(uartHandle->Instance==LPUART1) - { - /* USER CODE BEGIN LPUART1_MspInit 0 */ - - /* USER CODE END LPUART1_MspInit 0 */ - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* LPUART1 clock enable */ - __HAL_RCC_LPUART1_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**LPUART1 GPIO Configuration - PC0 ------> LPUART1_RX - PC1 ------> LPUART1_TX - */ - 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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN LPUART1_MspInit 1 */ - - /* USER CODE END LPUART1_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (uartHandle->Instance == LPUART1) { + /* USER CODE BEGIN LPUART1_MspInit 0 */ + + /* USER CODE END LPUART1_MspInit 0 */ + LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); + + /* LPUART1 clock enable */ + __HAL_RCC_LPUART1_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**LPUART1 GPIO Configuration + PC0 ------> LPUART1_RX + PC1 ------> LPUART1_TX + */ + 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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /* USER CODE BEGIN LPUART1_MspInit 1 */ + + /* USER CODE END LPUART1_MspInit 1 */ + } } -void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) +void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle) { - if(uartHandle->Instance==LPUART1) - { - /* USER CODE BEGIN LPUART1_MspDeInit 0 */ + if (uartHandle->Instance == LPUART1) { + /* USER CODE BEGIN LPUART1_MspDeInit 0 */ - /* USER CODE END LPUART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_LPUART1_CLK_DISABLE(); + /* USER CODE END LPUART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_LPUART1_CLK_DISABLE(); - /**LPUART1 GPIO Configuration - PC0 ------> LPUART1_RX - PC1 ------> LPUART1_TX - */ - HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0|GPIO_PIN_1); + /**LPUART1 GPIO Configuration + PC0 ------> LPUART1_RX + PC1 ------> LPUART1_TX + */ + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0 | GPIO_PIN_1); - /* USER CODE BEGIN LPUART1_MspDeInit 1 */ + /* USER CODE BEGIN LPUART1_MspDeInit 1 */ - /* USER CODE END LPUART1_MspDeInit 1 */ - } + /* USER CODE END LPUART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h b/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h index 840f01660..b19618756 100644 --- a/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h +++ b/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h @@ -60,7 +60,8 @@ * This value is used to detect if the CubeCAN_Tick function is being called too frequently, which could indicate a problem with the invocation method. * * @note If you need to think about increasing this, you need to evaluate - * @warning If this value is exceeded, the system will trigger an error handler to prevent potential issues but this is checked only during a short duration starting after early boot and ending after a few seconds + * @warning If this value is exceeded, the system will trigger an error handler to prevent potential issues but this is checked only during a short duration starting after early boot and ending after + * a few seconds */ #define ABSOLUTE_MAX_INVOCATIONS_PER_TICK 2U From 3ea3a5d2ca3e35e312bd78fd0b07fc2903fac299 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 23:24:11 -0700 Subject: [PATCH 069/125] Documentation! Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Core/Src/main.c | 2 +- Lib/Peripherals/CubeCAN/README.md | 12 ++++++++++++ Lib/Peripherals/CubeCAN/Src/can_tx.c | 8 +++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 5552d7761..6cf7fb03a 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -158,7 +158,7 @@ int main(void) /* USER CODE BEGIN 3 */ MainLoop(); - HAL_Delay(0); + HAL_Delay(100); } /* USER CODE END 3 */ } diff --git a/Lib/Peripherals/CubeCAN/README.md b/Lib/Peripherals/CubeCAN/README.md index 097a69ace..599138c77 100644 --- a/Lib/Peripherals/CubeCAN/README.md +++ b/Lib/Peripherals/CubeCAN/README.md @@ -193,6 +193,18 @@ CubeCAN maintains a global private array of handles (sized to `CUBEMX_CAN_MAX_IN If your chip supports multiple FDCAN peripherals but you need fewer, set `CUBEMX_CAN_MAX_INSTANCES` lower to avoid wasting memory on unused handles. Similarly, reduce `CUBEMX_CAN_TX_QUEUE_SIZE` if you send infrequently and have frequent ticks. +### Timer Rate Checker + +In the interest of preventing improper bus actions, during a period after early boot and ending a few seconds later we monitor how often `CubeCAN_Tick()` is callled to verify the sender is not going to bring down the bus. + +Ideally, you should call `CubeCAN_Tick()` about every `625 us` and you will not run into any issues with it. + +If for some reason you wish to go past that, such as some extreme debugging case, then you may define `RELAXED_TIMER_GATE` inside of your `CubeCAN_Config.h` file and this will turn the error handler call into a logged violation. + +If for some reason you wish to go even farther pas that, such as some extreme debugging case where you do not want to even check for violations, then you may define `DISABLED_TIMER_GATE` inside of your `CubeCAN_Config.h` file and this will skip running the violation check at all. + +However, you really should fix your timers so that it is not possible to spam the bus, needing to use either of these flags means you should reevaluate other settings, try sending larger messages instead of many smaller ones and increasing `CUBEMX_CAN_TX_QUEUE_SIZE`. + ## Troubleshooting TODO diff --git a/Lib/Peripherals/CubeCAN/Src/can_tx.c b/Lib/Peripherals/CubeCAN/Src/can_tx.c index a8d555179..cff1bdce0 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_tx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_tx.c @@ -37,11 +37,17 @@ void CubeCAN_Private_RateChecker(void) void CubeCAN_Tick(void) { +#ifdef DISABLED_TIMER_GATE +#warning "CubeCAN_Tick: Compiled with DISABLED_TIMER_GATE, this is a hidden feature flag that disables the timer violation check but you really should fix your timers" + static bool rate_checker_gate = true; +#else static bool rate_checker_gate = false; +#endif + if (__builtin_expect(!rate_checker_gate, 0)) { CubeCAN_Private_RateChecker(); - if (HAL_GetTick() > 10000U) { // Disable check after 10 sec + if (HAL_GetTick() > 5000U) { // Disable check after 5 seconds rate_checker_gate = true; } } From 7beba21850e9bc553ca0743b14d60f47f67cb276 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 23:27:08 -0700 Subject: [PATCH 070/125] Make things slightly easier Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Application/Src/CANdler.c | 2 +- Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CUBEMXTESTING/Application/Src/CANdler.c b/CUBEMXTESTING/Application/Src/CANdler.c index 45b5a64fd..8d16b7c36 100644 --- a/CUBEMXTESTING/Application/Src/CANdler.c +++ b/CUBEMXTESTING/Application/Src/CANdler.c @@ -23,5 +23,5 @@ void CANdler_Callback(const CubeCAN_Config_Context *const context, const CAN_Ide const GRCAN_NODE_ID rx_node = identifier->rx_node_id; const GRCAN_MSG_ID msg_id = identifier->msg_id; - // LOGOMATIC("Received on bus %d with node %d -> %d with message %d and size %u\t%.*s\n", busid, tx_node, rx_node, msg_id, size, size, (const char *const)data); + LOGOMATIC("Received on bus %d with node %d -> %d with message %d and size %u\t%.*s\n", busid, tx_node, rx_node, msg_id, size, size, (const char *const)data); } diff --git a/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h b/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h index b19618756..7abb7899d 100644 --- a/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h +++ b/Lib/Peripherals/CubeCAN/Src/PrivateInc/internal.h @@ -63,7 +63,7 @@ * @warning If this value is exceeded, the system will trigger an error handler to prevent potential issues but this is checked only during a short duration starting after early boot and ending after * a few seconds */ -#define ABSOLUTE_MAX_INVOCATIONS_PER_TICK 2U +#define ABSOLUTE_MAX_INVOCATIONS_PER_TICK 3U /** * @brief Transmission CAN message structure From b4508cdabb811af6ef5fe8ded280da75ab7787b9 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 23:39:54 -0700 Subject: [PATCH 071/125] Mark `PERIPHERAL_TIMEDCAN_LIB` as deprecated and rename `CUBE_CAN_LIB` Signed-off-by: Daniel Hansen --- CUBEMXTESTING/CMakeLists.txt | 2 +- Lib/Peripherals/CubeCAN/README.md | 2 +- Lib/Peripherals/CubeCAN/cube_can.cmake | 8 ++++---- Lib/Peripherals/TimedCAN/common.cmake | 4 ++++ 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CUBEMXTESTING/CMakeLists.txt b/CUBEMXTESTING/CMakeLists.txt index 5ee46ef0f..2f24cb5e5 100644 --- a/CUBEMXTESTING/CMakeLists.txt +++ b/CUBEMXTESTING/CMakeLists.txt @@ -39,7 +39,7 @@ target_sources( target_link_libraries( ${PROJECT_NAME}_USER_CODE INTERFACE - CUBEMX_CAN_LIB + CUBE_CAN_LIB LOGOMATIC_LIB ) diff --git a/Lib/Peripherals/CubeCAN/README.md b/Lib/Peripherals/CubeCAN/README.md index 599138c77..8b03ca245 100644 --- a/Lib/Peripherals/CubeCAN/README.md +++ b/Lib/Peripherals/CubeCAN/README.md @@ -18,7 +18,7 @@ Save the handle that function returns and use that to send messages. Receive mes ### 1. CMake -Add `CUBEMX_CAN_LIB` as an interface target link library within your project. +Add `CUBE_CAN_LIB` as an interface target link library within your project. ### 2. Configuration diff --git a/Lib/Peripherals/CubeCAN/cube_can.cmake b/Lib/Peripherals/CubeCAN/cube_can.cmake index 64b201d7d..0793d8684 100644 --- a/Lib/Peripherals/CubeCAN/cube_can.cmake +++ b/Lib/Peripherals/CubeCAN/cube_can.cmake @@ -1,13 +1,13 @@ -add_library(CUBEMX_CAN_LIB INTERFACE) +add_library(CUBE_CAN_LIB INTERFACE) target_include_directories( - CUBEMX_CAN_LIB + CUBE_CAN_LIB INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Inc ) target_sources( - CUBEMX_CAN_LIB + CUBE_CAN_LIB INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Src/can_assert.c ${CMAKE_CURRENT_LIST_DIR}/Src/can_global.c @@ -18,7 +18,7 @@ target_sources( ) target_link_libraries( - CUBEMX_CAN_LIB + CUBE_CAN_LIB INTERFACE CANfigurator LOGOMATIC_LIB diff --git a/Lib/Peripherals/TimedCAN/common.cmake b/Lib/Peripherals/TimedCAN/common.cmake index f2b227054..178dc130f 100644 --- a/Lib/Peripherals/TimedCAN/common.cmake +++ b/Lib/Peripherals/TimedCAN/common.cmake @@ -11,3 +11,7 @@ target_sources( INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Src/can.c ) + +set_target_properties(PERIPHERAL_TIMEDCAN_LIB PROPERTIES + DEPRECATION "PERIPHERAL_TIMEDCAN_LIB is deprecated and should be replaced by CUBE_CAN_LIB." +) From 1bdda51a6936f558fab1cd72b05e507d573a8f35 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2026 06:40:26 +0000 Subject: [PATCH 072/125] Automatic CMake Format: Standardized formatting automatically --- Lib/Peripherals/CubeCAN/cube_can.cmake | 6 +----- Lib/Peripherals/TimedCAN/common.cmake | 7 +++++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Lib/Peripherals/CubeCAN/cube_can.cmake b/Lib/Peripherals/CubeCAN/cube_can.cmake index 0793d8684..0168d0d8c 100644 --- a/Lib/Peripherals/CubeCAN/cube_can.cmake +++ b/Lib/Peripherals/CubeCAN/cube_can.cmake @@ -1,10 +1,6 @@ add_library(CUBE_CAN_LIB INTERFACE) -target_include_directories( - CUBE_CAN_LIB - INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/Inc -) +target_include_directories(CUBE_CAN_LIB INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Inc) target_sources( CUBE_CAN_LIB diff --git a/Lib/Peripherals/TimedCAN/common.cmake b/Lib/Peripherals/TimedCAN/common.cmake index 178dc130f..12a7334dd 100644 --- a/Lib/Peripherals/TimedCAN/common.cmake +++ b/Lib/Peripherals/TimedCAN/common.cmake @@ -12,6 +12,9 @@ target_sources( ${CMAKE_CURRENT_LIST_DIR}/Src/can.c ) -set_target_properties(PERIPHERAL_TIMEDCAN_LIB PROPERTIES - DEPRECATION "PERIPHERAL_TIMEDCAN_LIB is deprecated and should be replaced by CUBE_CAN_LIB." +set_target_properties( + PERIPHERAL_TIMEDCAN_LIB + PROPERTIES + DEPRECATION + "PERIPHERAL_TIMEDCAN_LIB is deprecated and should be replaced by CUBE_CAN_LIB." ) From 85ecf175ba498ce9b516dc3ead9a1ce4db968005 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 23:40:30 -0700 Subject: [PATCH 073/125] Mark `PERIPHERAL_CAN_LIB` as deprecated as well Signed-off-by: Daniel Hansen --- Lib/Peripherals/CAN/common.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/Peripherals/CAN/common.cmake b/Lib/Peripherals/CAN/common.cmake index ad9709a07..a3c1e97b5 100644 --- a/Lib/Peripherals/CAN/common.cmake +++ b/Lib/Peripherals/CAN/common.cmake @@ -58,3 +58,7 @@ target_include_directories( # PERIPHERAL_CAN_LIB_init_test # ) #endif() + +set_target_properties(PERIPHERAL_CAN_LIB PROPERTIES + DEPRECATION "PERIPHERAL_CAN_LIB is deprecated and should be replaced by CUBE_CAN_LIB." +) From ebcab7042b378014ba5b142d6513fe4501972458 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2026 06:41:08 +0000 Subject: [PATCH 074/125] Automatic CMake Format: Standardized formatting automatically --- Lib/Peripherals/CAN/common.cmake | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/Peripherals/CAN/common.cmake b/Lib/Peripherals/CAN/common.cmake index a3c1e97b5..61aacaf39 100644 --- a/Lib/Peripherals/CAN/common.cmake +++ b/Lib/Peripherals/CAN/common.cmake @@ -59,6 +59,9 @@ target_include_directories( # ) #endif() -set_target_properties(PERIPHERAL_CAN_LIB PROPERTIES - DEPRECATION "PERIPHERAL_CAN_LIB is deprecated and should be replaced by CUBE_CAN_LIB." +set_target_properties( + PERIPHERAL_CAN_LIB + PROPERTIES + DEPRECATION + "PERIPHERAL_CAN_LIB is deprecated and should be replaced by CUBE_CAN_LIB." ) From 7b2c764f8665e85a28007ebdaf698388ee2b3a68 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sat, 15 Aug 2026 23:44:32 -0700 Subject: [PATCH 075/125] Add fancy mon get rid of ftl extension Signed-off-by: Daniel Hansen --- .vscode/extensions.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 3e5fd3c28..5e67db949 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -9,7 +9,6 @@ "github.vscode-pull-request-github", "eamodio.gitlens", "davidanson.vscode-markdownlint", - "ms-vscode.vscode-serial-monitor", - "dcortes92.freemarker" + "wombat.fancymon" ] } From 757601f7c84f72683a9e9d4dab0d3e8eb3ecfff0 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 00:05:53 -0700 Subject: [PATCH 076/125] Remove USART from CUBEMXTESTING Signed-off-by: Daniel Hansen --- CUBEMXTESTING/CMakeLists.txt | 1 - CUBEMXTESTING/CUBEMXTESTING.ioc | 47 +- CUBEMXTESTING/Core/Inc/fdcan.h | 1 + CUBEMXTESTING/Core/Inc/gpio.h | 1 + CUBEMXTESTING/Core/Inc/main.h | 13 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 217 ++++---- CUBEMXTESTING/Core/Inc/tim.h | 1 + CUBEMXTESTING/Core/Src/fdcan.c | 525 ++++++++++--------- CUBEMXTESTING/Core/Src/gpio.c | 549 ++++++++++---------- CUBEMXTESTING/Core/Src/main.c | 165 +++--- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 24 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 197 +++---- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- 13 files changed, 946 insertions(+), 908 deletions(-) diff --git a/CUBEMXTESTING/CMakeLists.txt b/CUBEMXTESTING/CMakeLists.txt index 2f24cb5e5..fe140a251 100644 --- a/CUBEMXTESTING/CMakeLists.txt +++ b/CUBEMXTESTING/CMakeLists.txt @@ -33,7 +33,6 @@ target_sources( Core/Src/main.c Core/Src/stm32g4xx_it.c Core/Src/tim.c - Core/Src/usart.c ) target_link_libraries( diff --git a/CUBEMXTESTING/CUBEMXTESTING.ioc b/CUBEMXTESTING/CUBEMXTESTING.ioc index fac4bcf68..c57595183 100644 --- a/CUBEMXTESTING/CUBEMXTESTING.ioc +++ b/CUBEMXTESTING/CUBEMXTESTING.ioc @@ -42,38 +42,33 @@ FDCAN3.Mode=FDCAN_MODE_INTERNAL_LOOPBACK File.Version=6 GPIO.groupedBy=Group By Peripherals KeepUserPlacement=false -LPUART1.BaudRate=115200 -LPUART1.IPParameters=BaudRate Mcu.CPN=STM32G474RET6 Mcu.Family=STM32G4 Mcu.IP0=FDCAN1 Mcu.IP1=FDCAN2 Mcu.IP2=FDCAN3 -Mcu.IP3=LPUART1 -Mcu.IP4=NVIC -Mcu.IP5=RCC -Mcu.IP6=SYS -Mcu.IP7=TIM5 -Mcu.IPNb=8 +Mcu.IP3=NVIC +Mcu.IP4=RCC +Mcu.IP5=SYS +Mcu.IP6=TIM5 +Mcu.IPNb=7 Mcu.Name=STM32G474R(B-C-E)Tx Mcu.Package=LQFP64 Mcu.Pin0=PC13 -Mcu.Pin1=PC0 -Mcu.Pin10=PB3 -Mcu.Pin11=PB8-BOOT0 -Mcu.Pin12=PB9 -Mcu.Pin13=VP_SYS_VS_Systick -Mcu.Pin14=VP_SYS_VS_DBSignals -Mcu.Pin15=VP_TIM5_VS_ClockSourceINT -Mcu.Pin2=PC1 -Mcu.Pin3=PA5 -Mcu.Pin4=PB12 -Mcu.Pin5=PB13 -Mcu.Pin6=PA8 -Mcu.Pin7=PA13 -Mcu.Pin8=PA14 -Mcu.Pin9=PA15 -Mcu.PinsNb=16 +Mcu.Pin1=PA5 +Mcu.Pin10=PB9 +Mcu.Pin11=VP_SYS_VS_Systick +Mcu.Pin12=VP_SYS_VS_DBSignals +Mcu.Pin13=VP_TIM5_VS_ClockSourceINT +Mcu.Pin2=PB12 +Mcu.Pin3=PB13 +Mcu.Pin4=PA8 +Mcu.Pin5=PA13 +Mcu.Pin6=PA14 +Mcu.Pin7=PA15 +Mcu.Pin8=PB3 +Mcu.Pin9=PB8-BOOT0 +Mcu.PinsNb=14 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32G474RETx @@ -116,10 +111,6 @@ PB8-BOOT0.Mode=FDCAN_Activate PB8-BOOT0.Signal=FDCAN1_RX PB9.Mode=FDCAN_Activate PB9.Signal=FDCAN1_TX -PC0.Mode=Asynchronous -PC0.Signal=LPUART1_RX -PC1.Mode=Asynchronous -PC1.Signal=LPUART1_TX PC13.GPIOParameters=GPIO_Label PC13.GPIO_Label=USER_BUTTON PC13.Locked=true diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 3597c6476..21271cf64 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -55,3 +55,4 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 37dcc0a5c..03c2faca5 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -46,3 +46,4 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index cbeced83f..2b50abc31 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,16 +28,17 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" + +#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_dma.h" -#include "stm32g4xx_ll_exti.h" -#include "stm32g4xx_ll_gpio.h" -#include "stm32g4xx_ll_pwr.h" -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_exti.h" +#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_utils.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index d12d585bd..92ba77d88 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus -extern "C" { + extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ extern "C" { /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED -/*#define HAL_ADC_MODULE_ENABLED */ + /*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -63,7 +63,7 @@ extern "C" { /*#define HAL_SPI_MODULE_ENABLED */ /*#define HAL_SRAM_MODULE_ENABLED */ #define HAL_TIM_MODULE_ENABLED -#define HAL_UART_MODULE_ENABLED +/*#define HAL_UART_MODULE_ENABLED */ /*#define HAL_USART_MODULE_ENABLED */ /*#define HAL_WWDG_MODULE_ENABLED */ #define HAL_GPIO_MODULE_ENABLED @@ -76,124 +76,123 @@ extern "C" { /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(HSE_STARTUP_TIMEOUT) -#define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined(HSI48_VALUE) -#define HSI48_VALUE \ - (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined (HSI48_VALUE) + #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined(LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined(LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined(LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined (LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined(EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -#define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ + #define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -202,12 +201,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -358,15 +357,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index 2d20bd560..b90657cf4 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,3 +49,4 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ + diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 30b3c9dc1..08b2a1b8a 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,281 +32,298 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ + } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ + } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ + } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN3) { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) { - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN3) { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index d0d390b5b..e2ffb942c 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -33,277 +33,290 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) - */ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) +*/ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 6cf7fb03a..70419b88c 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,11 +18,9 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" - #include "fdcan.h" -#include "gpio.h" #include "tim.h" -#include "usart.h" +#include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -90,40 +88,39 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - MX_LPUART1_UART_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + /* USER CODE BEGIN 2 */ Setup_Logomatic(&logomaticConfig); CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; @@ -149,59 +146,67 @@ int main(void) } LOGOMATIC("Hello World!\n"); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); HAL_Delay(100); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) + { + } + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while(LL_RCC_HSI_IsReady() != 1) + { + } + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while(LL_RCC_PLL_IsReady() != 1) + { + } + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) + { + } + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i !=0; i--); + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) + { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -220,29 +225,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ LOGOMATIC("Assert failed! File %s on line %" PRIu32 "\n", file, line); - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index 4668755ab..2cc7d8296 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index fd2ad329f..78d6b9cd9 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,9 +18,8 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "stm32g4xx_it.h" - #include "main.h" +#include "stm32g4xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -68,125 +67,129 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -197,59 +200,59 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index e77341bf2..aa26dcf71 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,76 +30,83 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 1599; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 49; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 1599; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 49; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) + { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ + /* USER CODE END TIM5_Init 2 */ + } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) { - if (tim_baseHandle->Instance == TIM5) { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) { - if (tim_baseHandle->Instance == TIM5) { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + From 36aa379a774d67aa5ddd449a73c9dc25a195c298 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 00:12:06 -0700 Subject: [PATCH 077/125] Make logomatic marked old Signed-off-by: Daniel Hansen --- .vscode/launch.json | 2 +- CCU/CMakeLists.txt | 2 +- CMakeLists.txt | 2 +- CUBEMXTESTING/CMakeLists.txt | 2 +- ECU/CMakeLists.txt | 2 +- .../GRCAN/grcan_fancylayer.cmake | 13 +++++++--- Lib/Peripherals/CubeCAN/cube_can.cmake | 2 +- .../Inc/Logomatic.h | 0 .../{Logomatic => OldLogomatic}/README.md | 0 .../Src/Logomatic.c | 0 .../Test/Inc/main.h | 0 .../Test/Src/logomatic_float_print.c | 0 .../Test/Src/logomatic_simple_print.c | 0 .../logomatic.cmake | 25 ++++++++++++------- Lib/Utils/VirtualComPort/vcp.cmake | 2 +- Lib/cmake/gr-lib.cmake | 2 +- 16 files changed, 34 insertions(+), 20 deletions(-) rename Lib/Utils/{Logomatic => OldLogomatic}/Inc/Logomatic.h (100%) rename Lib/Utils/{Logomatic => OldLogomatic}/README.md (100%) rename Lib/Utils/{Logomatic => OldLogomatic}/Src/Logomatic.c (100%) rename Lib/Utils/{Logomatic => OldLogomatic}/Test/Inc/main.h (100%) rename Lib/Utils/{Logomatic => OldLogomatic}/Test/Src/logomatic_float_print.c (100%) rename Lib/Utils/{Logomatic => OldLogomatic}/Test/Src/logomatic_simple_print.c (100%) rename Lib/Utils/{Logomatic => OldLogomatic}/logomatic.cmake (70%) diff --git a/.vscode/launch.json b/.vscode/launch.json index d7ec434ff..727fae9fd 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -50,7 +50,7 @@ "swoConfig": { "enabled": true, "cpuFrequency": 160000000, - "swoFrequency": 2000000, + "swoFrequency": 1152000, "source": "probe", "decoders": [ { diff --git a/CCU/CMakeLists.txt b/CCU/CMakeLists.txt index 6ecaa5312..700b5923a 100644 --- a/CCU/CMakeLists.txt +++ b/CCU/CMakeLists.txt @@ -35,7 +35,7 @@ if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") CCUStateTicksTests PRIVATE GLOBALSHARE_LIB - LOGOMATIC_LIB + LOGOMATIC_OLD_LIB BitManipulations_Lib ) add_test(CCUStateTicksTests CCUStateTicksTests) diff --git a/CMakeLists.txt b/CMakeLists.txt index 46b377ddb..1836602fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,7 +128,7 @@ include("${platform_path}/STM32H523xE/chip.cmake") # Utils include("${lib_path}/GlobalShare/common.cmake") -include("${lib_path}/Utils/Logomatic/logomatic.cmake") +include("${lib_path}/Utils/OldLogomatic/logomatic.cmake") include("${lib_path}/Utils/VirtualComPort/vcp.cmake") include("${lib_path}/Utils/CircularBuffer/circular-buffer-lib.cmake") include("${lib_path}/Utils/MsgBuffer/msg-buffer-lib.cmake") diff --git a/CUBEMXTESTING/CMakeLists.txt b/CUBEMXTESTING/CMakeLists.txt index fe140a251..fe3307711 100644 --- a/CUBEMXTESTING/CMakeLists.txt +++ b/CUBEMXTESTING/CMakeLists.txt @@ -39,7 +39,7 @@ target_link_libraries( ${PROJECT_NAME}_USER_CODE INTERFACE CUBE_CAN_LIB - LOGOMATIC_LIB + LOGOMATIC_OLD_LIB ) target_include_directories( diff --git a/ECU/CMakeLists.txt b/ECU/CMakeLists.txt index 2ea28460a..b63573e3a 100644 --- a/ECU/CMakeLists.txt +++ b/ECU/CMakeLists.txt @@ -38,7 +38,7 @@ if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") PRIVATE GLOBALSHARE_LIB CANfigurator - LOGOMATIC_LIB + LOGOMATIC_OLD_LIB m # GR_ADC # PERIPHERAL_CAN_LIB diff --git a/Lib/FancyLayers-RENAME/GRCAN/grcan_fancylayer.cmake b/Lib/FancyLayers-RENAME/GRCAN/grcan_fancylayer.cmake index eb82067ff..c972fdf3b 100644 --- a/Lib/FancyLayers-RENAME/GRCAN/grcan_fancylayer.cmake +++ b/Lib/FancyLayers-RENAME/GRCAN/grcan_fancylayer.cmake @@ -30,7 +30,7 @@ target_link_libraries( ) if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") - # target_compile_definitions(LOGOMATIC_LIB INTERFACE LOGOMATIC_ENABLED) + # target_compile_definitions(LOGOMATIC_OLD_LIB INTERFACE LOGOMATIC_ENABLED) # add_executable(logomatic_simple) # target_sources( @@ -43,7 +43,7 @@ if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") # PRIVATE # ${CMAKE_CURRENT_LIST_DIR}/Test/Inc # ) - # target_link_libraries(logomatic_simple PRIVATE LOGOMATIC_LIB) + # target_link_libraries(logomatic_simple PRIVATE LOGOMATIC_OLD_LIB) # add_test(logomatic_simple_test logomatic_simple) # add_executable(logomatic_float) @@ -57,6 +57,13 @@ if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") # PRIVATE # ${CMAKE_CURRENT_LIST_DIR}/Test/Inc # ) - # target_link_libraries(logomatic_float PRIVATE LOGOMATIC_LIB) + # target_link_libraries(logomatic_float PRIVATE LOGOMATIC_OLD_LIB) # add_test(logomatic_float_test logomatic_float) endif() + +set_target_properties( + GRCAN_FANCYLAYER + PROPERTIES + DEPRECATION + "GRCAN_FANCYLAYER is deprecated and should be replaced by CUBE_CAN_LIB." +) diff --git a/Lib/Peripherals/CubeCAN/cube_can.cmake b/Lib/Peripherals/CubeCAN/cube_can.cmake index 0168d0d8c..4d6095b5a 100644 --- a/Lib/Peripherals/CubeCAN/cube_can.cmake +++ b/Lib/Peripherals/CubeCAN/cube_can.cmake @@ -17,5 +17,5 @@ target_link_libraries( CUBE_CAN_LIB INTERFACE CANfigurator - LOGOMATIC_LIB + LOGOMATIC_OLD_LIB ) diff --git a/Lib/Utils/Logomatic/Inc/Logomatic.h b/Lib/Utils/OldLogomatic/Inc/Logomatic.h similarity index 100% rename from Lib/Utils/Logomatic/Inc/Logomatic.h rename to Lib/Utils/OldLogomatic/Inc/Logomatic.h diff --git a/Lib/Utils/Logomatic/README.md b/Lib/Utils/OldLogomatic/README.md similarity index 100% rename from Lib/Utils/Logomatic/README.md rename to Lib/Utils/OldLogomatic/README.md diff --git a/Lib/Utils/Logomatic/Src/Logomatic.c b/Lib/Utils/OldLogomatic/Src/Logomatic.c similarity index 100% rename from Lib/Utils/Logomatic/Src/Logomatic.c rename to Lib/Utils/OldLogomatic/Src/Logomatic.c diff --git a/Lib/Utils/Logomatic/Test/Inc/main.h b/Lib/Utils/OldLogomatic/Test/Inc/main.h similarity index 100% rename from Lib/Utils/Logomatic/Test/Inc/main.h rename to Lib/Utils/OldLogomatic/Test/Inc/main.h diff --git a/Lib/Utils/Logomatic/Test/Src/logomatic_float_print.c b/Lib/Utils/OldLogomatic/Test/Src/logomatic_float_print.c similarity index 100% rename from Lib/Utils/Logomatic/Test/Src/logomatic_float_print.c rename to Lib/Utils/OldLogomatic/Test/Src/logomatic_float_print.c diff --git a/Lib/Utils/Logomatic/Test/Src/logomatic_simple_print.c b/Lib/Utils/OldLogomatic/Test/Src/logomatic_simple_print.c similarity index 100% rename from Lib/Utils/Logomatic/Test/Src/logomatic_simple_print.c rename to Lib/Utils/OldLogomatic/Test/Src/logomatic_simple_print.c diff --git a/Lib/Utils/Logomatic/logomatic.cmake b/Lib/Utils/OldLogomatic/logomatic.cmake similarity index 70% rename from Lib/Utils/Logomatic/logomatic.cmake rename to Lib/Utils/OldLogomatic/logomatic.cmake index 0b8144e06..b5afa0e0b 100644 --- a/Lib/Utils/Logomatic/logomatic.cmake +++ b/Lib/Utils/OldLogomatic/logomatic.cmake @@ -1,17 +1,17 @@ -add_library(LOGOMATIC_LIB INTERFACE) +add_library(LOGOMATIC_OLD_LIB INTERFACE) # Include directories and source files for the logomatic library target_include_directories( - LOGOMATIC_LIB + LOGOMATIC_OLD_LIB INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Inc ) target_sources( - LOGOMATIC_LIB + LOGOMATIC_OLD_LIB INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Src/Logomatic.c ) -target_link_libraries(LOGOMATIC_LIB INTERFACE GLOBALSHARE_LIB) +target_link_libraries(LOGOMATIC_OLD_LIB INTERFACE GLOBALSHARE_LIB) # Default logomatic to be disabled if(NOT DEFINED CMAKE_LOGOMATIC_ENABLED) @@ -21,7 +21,7 @@ endif() # Main compilation flag to enable logomatic if(CMAKE_LOGOMATIC_ENABLED) message(STATUS "Logomatic enabled") - target_compile_definitions(LOGOMATIC_LIB INTERFACE LOGOMATIC_ENABLED) + target_compile_definitions(LOGOMATIC_OLD_LIB INTERFACE LOGOMATIC_ENABLED) endif() if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") @@ -36,7 +36,7 @@ if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Test/Inc ) - target_link_libraries(logomatic_simple PRIVATE LOGOMATIC_LIB) + target_link_libraries(logomatic_simple PRIVATE LOGOMATIC_OLD_LIB) add_test(logomatic_simple_test logomatic_simple) add_executable(logomatic_float) @@ -50,20 +50,27 @@ if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Test/Inc ) - target_link_libraries(logomatic_float PRIVATE LOGOMATIC_LIB) + target_link_libraries(logomatic_float PRIVATE LOGOMATIC_OLD_LIB) add_test(logomatic_float_test logomatic_float) else() # Add floating point support for printf, which goes unused on MacOS hootl builds and throws a warning target_compile_options( - LOGOMATIC_LIB + LOGOMATIC_OLD_LIB INTERFACE -u _printf_float ) target_link_options( - LOGOMATIC_LIB + LOGOMATIC_OLD_LIB INTERFACE -u _printf_float ) endif() + +set_target_properties( + LOGOMATIC_OLD_LIB + PROPERTIES + DEPRECATION + "LOGOMATIC_OLD_LIB is deprecated and should be replaced by LOGOMATIC_LIB." +) diff --git a/Lib/Utils/VirtualComPort/vcp.cmake b/Lib/Utils/VirtualComPort/vcp.cmake index 71c25df4e..fb200f096 100644 --- a/Lib/Utils/VirtualComPort/vcp.cmake +++ b/Lib/Utils/VirtualComPort/vcp.cmake @@ -16,5 +16,5 @@ target_link_libraries( VCP_LIB INTERFACE GLOBALSHARE_LIB - LOGOMATIC_LIB + LOGOMATIC_OLD_LIB ) diff --git a/Lib/cmake/gr-lib.cmake b/Lib/cmake/gr-lib.cmake index cc1c29762..8eaa5cd72 100644 --- a/Lib/cmake/gr-lib.cmake +++ b/Lib/cmake/gr-lib.cmake @@ -34,7 +34,7 @@ function(add_gr_project) ${TARGET_NAME} PRIVATE ${TARGET_NAME}_USER_CODE # Blame Owen - LOGOMATIC_LIB + LOGOMATIC_OLD_LIB GLOBALSHARE_LIB m ) From fd1795e8e55e83abdce9411ef0a4a9842bb4376b Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 00:15:02 -0700 Subject: [PATCH 078/125] Skeleton peripheral Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/Inc/Logomatic.h | 0 Lib/Utils/Logomatic/README.md | 0 Lib/Utils/Logomatic/Src/log_levels.c | 0 Lib/Utils/Logomatic/Src/log_putchar.c | 0 Lib/Utils/Logomatic/common.cmake | 41 +++++++++++++++++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 Lib/Utils/Logomatic/Inc/Logomatic.h create mode 100644 Lib/Utils/Logomatic/README.md create mode 100644 Lib/Utils/Logomatic/Src/log_levels.c create mode 100644 Lib/Utils/Logomatic/Src/log_putchar.c create mode 100644 Lib/Utils/Logomatic/common.cmake diff --git a/Lib/Utils/Logomatic/Inc/Logomatic.h b/Lib/Utils/Logomatic/Inc/Logomatic.h new file mode 100644 index 000000000..e69de29bb diff --git a/Lib/Utils/Logomatic/README.md b/Lib/Utils/Logomatic/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/Lib/Utils/Logomatic/Src/log_levels.c b/Lib/Utils/Logomatic/Src/log_levels.c new file mode 100644 index 000000000..e69de29bb diff --git a/Lib/Utils/Logomatic/Src/log_putchar.c b/Lib/Utils/Logomatic/Src/log_putchar.c new file mode 100644 index 000000000..e69de29bb diff --git a/Lib/Utils/Logomatic/common.cmake b/Lib/Utils/Logomatic/common.cmake new file mode 100644 index 000000000..7e901f39c --- /dev/null +++ b/Lib/Utils/Logomatic/common.cmake @@ -0,0 +1,41 @@ +add_library(LOGOMATIC_LIB INTERFACE) + +target_include_directories( + LOGOMATIC_LIB + INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/Inc +) + +target_sources( + LOGOMATIC_LIB + INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/Src/Logomatic.c +) + +target_link_libraries(LOGOMATIC_LIB INTERFACE GLOBALSHARE_LIB) + +if(NOT DEFINED CMAKE_LOGOMATIC_ENABLED) + set(CMAKE_LOGOMATIC_ENABLED OFF) +endif() + +if(CMAKE_LOGOMATIC_ENABLED) + message(STATUS "Logomatic enabled") + target_compile_definitions(LOGOMATIC_LIB INTERFACE LOGOMATIC_ENABLED) +endif() + +if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") + # TODO +else() + target_compile_options( + LOGOMATIC_LIB + INTERFACE + -u + _printf_float + ) + target_link_options( + LOGOMATIC_LIB + INTERFACE + -u + _printf_float + ) +endif() From fbfdc68d169390a115d2bd9534036b74eb4b7ba0 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 01:57:26 -0700 Subject: [PATCH 079/125] Compilable version of LOGOMATIC (with log levels) Signed-off-by: Daniel Hansen --- BLINKY/G4BLINKY/CMakeLists.txt | 2 +- BLINKY/G4ECHO/CMakeLists.txt | 2 +- BLINKY/G4HELLO/CMakeLists.txt | 2 +- BLINKY/L4BLINKY/CMakeLists.txt | 2 +- BLINKY/L4HELLO/CMakeLists.txt | 2 +- BLINKY/U5BLINKY/CMakeLists.txt | 2 +- CANine/CMakeLists.txt | 2 +- CMakeLists.txt | 1 + CUBEMXTESTING/Application/Src/CANdler.c | 6 +- CUBEMXTESTING/Application/Src/Loop.c | 2 +- CUBEMXTESTING/CMakeLists.txt | 2 +- CUBEMXTESTING/Core/Src/main.c | 189 ++++++++---------- .../G431x8_CAN_BASIC_TEST/CMakeLists.txt | 2 +- .../CAN_BASIC_TEST/CMakeLists.txt | 2 +- .../CAN_FILTER_TEST/CMakeLists.txt | 2 +- .../CAN_INTERNAL_TEST/CMakeLists.txt | 2 +- .../CAN_LOST_RX_TEST/CMakeLists.txt | 2 +- .../CAN_RELEASE_TEST/CMakeLists.txt | 2 +- .../CAN_STRESS_TEST/CMakeLists.txt | 2 +- .../PROFILER_TEST/CMakeLists.txt | 2 +- G4ADCTESTING/CMakeLists.txt | 2 +- .../CAN_LOOPBACK_TEST/CMakeLists.txt | 2 +- G4NEOTESTING/CMakeLists.txt | 2 +- G4PERTESTING/CMakeLists.txt | 2 +- G4SPITESTING/CMakeLists.txt | 2 +- Lib/Peripherals/CubeCAN/README.md | 2 +- Lib/Peripherals/CubeCAN/Src/can_init.c | 20 +- Lib/Peripherals/CubeCAN/Src/can_rx.c | 6 +- Lib/Peripherals/CubeCAN/Src/can_tx.c | 14 +- Lib/Peripherals/CubeCAN/Src/can_utils.c | 16 +- Lib/Peripherals/CubeCAN/cube_can.cmake | 2 +- Lib/Utils/Logomatic/Inc/Logomatic.h | 182 +++++++++++++++++ Lib/Utils/Logomatic/Src/log_global.c | 12 ++ Lib/Utils/Logomatic/Src/log_levels.c | 0 Lib/Utils/Logomatic/Src/log_putchar.c | 169 ++++++++++++++++ .../Logomatic/{common.cmake => log.cmake} | 3 +- Lib/cmake/gr-lib.cmake | 1 - OutboardSensors/BrakeTemp/CMakeLists.txt | 1 + OutboardSensors/TireTemp/CMakeLists.txt | 1 + 39 files changed, 508 insertions(+), 161 deletions(-) create mode 100644 Lib/Utils/Logomatic/Src/log_global.c delete mode 100644 Lib/Utils/Logomatic/Src/log_levels.c rename Lib/Utils/Logomatic/{common.cmake => log.cmake} (88%) diff --git a/BLINKY/G4BLINKY/CMakeLists.txt b/BLINKY/G4BLINKY/CMakeLists.txt index 5e27c8df8..544603aba 100644 --- a/BLINKY/G4BLINKY/CMakeLists.txt +++ b/BLINKY/G4BLINKY/CMakeLists.txt @@ -40,7 +40,7 @@ target_sources( Core/Src/stm32g4xx_hal_msp.c ) -target_link_libraries(${GR_PROJECT_NAME}_USER_CODE INTERFACE) +target_link_libraries(${GR_PROJECT_NAME}_USER_CODE INTERFACE LOGOMATIC_OLD_LIB) target_include_directories( ${GR_PROJECT_NAME}_USER_CODE diff --git a/BLINKY/G4ECHO/CMakeLists.txt b/BLINKY/G4ECHO/CMakeLists.txt index 3410dbbb7..1edb59380 100644 --- a/BLINKY/G4ECHO/CMakeLists.txt +++ b/BLINKY/G4ECHO/CMakeLists.txt @@ -35,6 +35,6 @@ target_sources( Core/Src/stm32g4xx_hal_msp.c ) -target_link_libraries(${GR_PROJECT_NAME}_USER_CODE INTERFACE VCP_LIB) +target_link_libraries(${GR_PROJECT_NAME}_USER_CODE INTERFACE VCP_LIB LOGOMATIC_OLD_LIB) target_include_directories(${GR_PROJECT_NAME}_USER_CODE INTERFACE Core/Inc) diff --git a/BLINKY/G4HELLO/CMakeLists.txt b/BLINKY/G4HELLO/CMakeLists.txt index 954f68470..979a5c93f 100644 --- a/BLINKY/G4HELLO/CMakeLists.txt +++ b/BLINKY/G4HELLO/CMakeLists.txt @@ -35,6 +35,6 @@ target_sources( Core/Src/stm32g4xx_hal_msp.c ) -target_link_libraries(${GR_PROJECT_NAME}_USER_CODE INTERFACE) +target_link_libraries(${GR_PROJECT_NAME}_USER_CODE INTERFACE LOGOMATIC_OLD_LIB) target_include_directories(${GR_PROJECT_NAME}_USER_CODE INTERFACE Core/Inc) diff --git a/BLINKY/L4BLINKY/CMakeLists.txt b/BLINKY/L4BLINKY/CMakeLists.txt index 4a081c49e..48d5d63fa 100644 --- a/BLINKY/L4BLINKY/CMakeLists.txt +++ b/BLINKY/L4BLINKY/CMakeLists.txt @@ -35,7 +35,7 @@ target_sources( Core/Src/usart.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE LOGOMATIC_OLD_LIB) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/BLINKY/L4HELLO/CMakeLists.txt b/BLINKY/L4HELLO/CMakeLists.txt index 4a081c49e..48d5d63fa 100644 --- a/BLINKY/L4HELLO/CMakeLists.txt +++ b/BLINKY/L4HELLO/CMakeLists.txt @@ -35,7 +35,7 @@ target_sources( Core/Src/usart.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE LOGOMATIC_OLD_LIB) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/BLINKY/U5BLINKY/CMakeLists.txt b/BLINKY/U5BLINKY/CMakeLists.txt index 377f139de..57d43ca09 100644 --- a/BLINKY/U5BLINKY/CMakeLists.txt +++ b/BLINKY/U5BLINKY/CMakeLists.txt @@ -31,7 +31,7 @@ target_sources( Core/Src/stm32u5xx_hal_msp.c ) -target_link_libraries(${GR_PROJECT_NAME}_USER_CODE INTERFACE) +target_link_libraries(${GR_PROJECT_NAME}_USER_CODE INTERFACE LOGOMATIC_OLD_LIB) target_include_directories( ${GR_PROJECT_NAME}_USER_CODE diff --git a/CANine/CMakeLists.txt b/CANine/CMakeLists.txt index 954f68470..979a5c93f 100644 --- a/CANine/CMakeLists.txt +++ b/CANine/CMakeLists.txt @@ -35,6 +35,6 @@ target_sources( Core/Src/stm32g4xx_hal_msp.c ) -target_link_libraries(${GR_PROJECT_NAME}_USER_CODE INTERFACE) +target_link_libraries(${GR_PROJECT_NAME}_USER_CODE INTERFACE LOGOMATIC_OLD_LIB) target_include_directories(${GR_PROJECT_NAME}_USER_CODE INTERFACE Core/Inc) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1836602fb..4b062bc9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,6 +129,7 @@ include("${platform_path}/STM32H523xE/chip.cmake") # Utils include("${lib_path}/GlobalShare/common.cmake") include("${lib_path}/Utils/OldLogomatic/logomatic.cmake") +include("${lib_path}/Utils/Logomatic/log.cmake") include("${lib_path}/Utils/VirtualComPort/vcp.cmake") include("${lib_path}/Utils/CircularBuffer/circular-buffer-lib.cmake") include("${lib_path}/Utils/MsgBuffer/msg-buffer-lib.cmake") diff --git a/CUBEMXTESTING/Application/Src/CANdler.c b/CUBEMXTESTING/Application/Src/CANdler.c index 8d16b7c36..f1d9b3580 100644 --- a/CUBEMXTESTING/Application/Src/CANdler.c +++ b/CUBEMXTESTING/Application/Src/CANdler.c @@ -13,8 +13,8 @@ void CANdler_Callback(const CubeCAN_Config_Context *const context, const CAN_Ide value++; if (context == NULL || identifier == NULL || data == NULL || size == 0) { - LOGOMATIC("CANdler_Callback: Invalid parameters received. context: %u, identifier: %p, data: %p, size: %u\n", context->busid_user_context, (void *const)identifier, (void *const)data, - size); + LOGOMATIC_ERROR("CANdler_Callback: Invalid parameters received. context: %u, identifier: %p, data: %p, size: %u\n", context->busid_user_context, (void *const)identifier, + (void *const)data, size); return; } @@ -23,5 +23,5 @@ void CANdler_Callback(const CubeCAN_Config_Context *const context, const CAN_Ide const GRCAN_NODE_ID rx_node = identifier->rx_node_id; const GRCAN_MSG_ID msg_id = identifier->msg_id; - LOGOMATIC("Received on bus %d with node %d -> %d with message %d and size %u\t%.*s\n", busid, tx_node, rx_node, msg_id, size, size, (const char *const)data); + LOGOMATIC_VERBOSE("Received on bus %d with node %d -> %d with message %d and size %u\t%.*s\n", busid, tx_node, rx_node, msg_id, size, size, (const char *const)data); } diff --git a/CUBEMXTESTING/Application/Src/Loop.c b/CUBEMXTESTING/Application/Src/Loop.c index f4125d3b5..47e6d9403 100644 --- a/CUBEMXTESTING/Application/Src/Loop.c +++ b/CUBEMXTESTING/Application/Src/Loop.c @@ -13,7 +13,7 @@ extern int value; void MainLoop(void) { LL_GPIO_TogglePin(USER_LED_GPIO_Port, USER_LED_Pin); - LOGOMATIC("Main Loop %d %" PRIu32 "\n", value, HAL_GetTick()); + LOGOMATIC_DEBUG("Main Loop %d %" PRIu32 "\n", value, HAL_GetTick()); (void)CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello0", 6); (void)CubeCAN_Send(dataHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello1", 6); (void)CubeCAN_Send(chargerHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello2", 6); diff --git a/CUBEMXTESTING/CMakeLists.txt b/CUBEMXTESTING/CMakeLists.txt index fe3307711..fe140a251 100644 --- a/CUBEMXTESTING/CMakeLists.txt +++ b/CUBEMXTESTING/CMakeLists.txt @@ -39,7 +39,7 @@ target_link_libraries( ${PROJECT_NAME}_USER_CODE INTERFACE CUBE_CAN_LIB - LOGOMATIC_OLD_LIB + LOGOMATIC_LIB ) target_include_directories( diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 70419b88c..0047a391d 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,9 +18,10 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" + #include "fdcan.h" -#include "tim.h" #include "gpio.h" +#include "tim.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -60,20 +61,6 @@ CubeCAN_Handle *primaryHandle = NULL; CubeCAN_Handle *dataHandle = NULL; CubeCAN_Handle *chargerHandle = NULL; - -LogomaticConfig logomaticConfig = {.clock_source = LOGOMATIC_PCLK1, - .bus = LOGOMATIC_BUS, - .gpio_port = LOGOMATIC_GPIOA, - .gpio_pin_rx_tx_mask = LL_GPIO_PIN_9 | LL_GPIO_PIN_10, - .baud_rate = 115200, - .data_width = LOGOMATIC_DATAWIDTH_8B, - .stop_bits = LOGOMATIC_STOPBITS_1, - .parity = LOGOMATIC_PARITY_NONE, - .transfer_direction = LOGOMATIC_DIRECTION_TX, - .hardware_flow_control = LOGOMATIC_HWCONTROL_NONE, - .prescaler = LOGOMATIC_PRESCALER_DIV1, - .tx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8, - .rx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8}; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -88,125 +75,115 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ + /* USER CODE BEGIN 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* USER CODE END 1 */ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* MCU Configuration--------------------------------------------------------*/ - /* USER CODE BEGIN Init */ + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE END Init */ + /* USER CODE BEGIN Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* USER CODE END Init */ - /* USER CODE BEGIN SysInit */ + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE END SysInit */ + /* USER CODE BEGIN SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - /* USER CODE BEGIN 2 */ - Setup_Logomatic(&logomaticConfig); + /* USER CODE END SysInit */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + /* USER CODE BEGIN 2 */ CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config dataCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_DATA, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config chargerCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_CHARGER, .sending_node_id = GRCAN_Debugger}; primaryHandle = CubeCAN_Entrance(&hfdcan1, &primaryCanConfig); if (primaryHandle == NULL) { - LOGOMATIC("Failed to initialize primary CAN handle\n"); + LOGOMATIC_CRITICAL("Failed to initialize primary CAN handle\n"); Error_Handler(); } dataHandle = CubeCAN_Entrance(&hfdcan2, &dataCanConfig); if (dataHandle == NULL) { - LOGOMATIC("Failed to initialize data CAN handle\n"); + LOGOMATIC_CRITICAL("Failed to initialize data CAN handle\n"); Error_Handler(); } chargerHandle = CubeCAN_Entrance(&hfdcan3, &chargerCanConfig); if (chargerHandle == NULL) { - LOGOMATIC("Failed to initialize charger CAN handle\n"); + LOGOMATIC_CRITICAL("Failed to initialize charger CAN handle\n"); Error_Handler(); } - LOGOMATIC("Hello World!\n"); - /* USER CODE END 2 */ + LOGOMATIC_DEBUG("Hello World!\n"); + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); HAL_Delay(100); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) - { - } - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while(LL_RCC_HSI_IsReady() != 1) - { - } - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while(LL_RCC_PLL_IsReady() != 1) - { - } - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) - { - } - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i !=0; i--); - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) - { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while (LL_RCC_HSI_IsReady() != 1) {} + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while (LL_RCC_PLL_IsReady() != 1) {} + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i != 0; i--) + ; + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -225,29 +202,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ - LOGOMATIC("Assert failed! File %s on line %" PRIu32 "\n", file, line); - /* USER CODE END 6 */ + /* USER CODE BEGIN 6 */ + LOGOMATIC_CRITICAL("Assert failed! File %s on line %" PRIu32 "\n", file, line); + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/CMakeLists.txt b/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/CMakeLists.txt index ccedc8c6d..b350d6f82 100644 --- a/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/CMakeLists.txt +++ b/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/CMakeLists.txt @@ -50,7 +50,7 @@ set_target_properties( "CAN_${NAME}" ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB LOGOMATIC_OLD_LIB) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/G474xE_CAN_TESTING/CAN_BASIC_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_BASIC_TEST/CMakeLists.txt index ccedc8c6d..b350d6f82 100644 --- a/G474xE_CAN_TESTING/CAN_BASIC_TEST/CMakeLists.txt +++ b/G474xE_CAN_TESTING/CAN_BASIC_TEST/CMakeLists.txt @@ -50,7 +50,7 @@ set_target_properties( "CAN_${NAME}" ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB LOGOMATIC_OLD_LIB) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/G474xE_CAN_TESTING/CAN_FILTER_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_FILTER_TEST/CMakeLists.txt index 3be5c86bd..cb4d9f904 100644 --- a/G474xE_CAN_TESTING/CAN_FILTER_TEST/CMakeLists.txt +++ b/G474xE_CAN_TESTING/CAN_FILTER_TEST/CMakeLists.txt @@ -43,7 +43,7 @@ target_sources( ../Core/Src/usart.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB LOGOMATIC_OLD_LIB) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/CMakeLists.txt index ccedc8c6d..b350d6f82 100644 --- a/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/CMakeLists.txt +++ b/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/CMakeLists.txt @@ -50,7 +50,7 @@ set_target_properties( "CAN_${NAME}" ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB LOGOMATIC_OLD_LIB) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/CMakeLists.txt index 3be5c86bd..cb4d9f904 100644 --- a/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/CMakeLists.txt +++ b/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/CMakeLists.txt @@ -43,7 +43,7 @@ target_sources( ../Core/Src/usart.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB LOGOMATIC_OLD_LIB) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/G474xE_CAN_TESTING/CAN_RELEASE_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_RELEASE_TEST/CMakeLists.txt index ccedc8c6d..b350d6f82 100644 --- a/G474xE_CAN_TESTING/CAN_RELEASE_TEST/CMakeLists.txt +++ b/G474xE_CAN_TESTING/CAN_RELEASE_TEST/CMakeLists.txt @@ -50,7 +50,7 @@ set_target_properties( "CAN_${NAME}" ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB LOGOMATIC_OLD_LIB) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/G474xE_CAN_TESTING/CAN_STRESS_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_STRESS_TEST/CMakeLists.txt index 3be5c86bd..cb4d9f904 100644 --- a/G474xE_CAN_TESTING/CAN_STRESS_TEST/CMakeLists.txt +++ b/G474xE_CAN_TESTING/CAN_STRESS_TEST/CMakeLists.txt @@ -43,7 +43,7 @@ target_sources( ../Core/Src/usart.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB LOGOMATIC_OLD_LIB) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/G474xE_CAN_TESTING/PROFILER_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/PROFILER_TEST/CMakeLists.txt index 3be5c86bd..cb4d9f904 100644 --- a/G474xE_CAN_TESTING/PROFILER_TEST/CMakeLists.txt +++ b/G474xE_CAN_TESTING/PROFILER_TEST/CMakeLists.txt @@ -43,7 +43,7 @@ target_sources( ../Core/Src/usart.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB LOGOMATIC_OLD_LIB) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/G4ADCTESTING/CMakeLists.txt b/G4ADCTESTING/CMakeLists.txt index 103c4e3d9..17f218644 100644 --- a/G4ADCTESTING/CMakeLists.txt +++ b/G4ADCTESTING/CMakeLists.txt @@ -43,6 +43,6 @@ target_sources( Core/Src/usart.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE GR_ADC) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE GR_ADC LOGOMATIC_OLD_LIB) target_include_directories(${PROJECT_NAME}_USER_CODE INTERFACE Core/Inc) diff --git a/G4FANCYCANTESTING/CAN_LOOPBACK_TEST/CMakeLists.txt b/G4FANCYCANTESTING/CAN_LOOPBACK_TEST/CMakeLists.txt index fdf940e7b..affdc3b64 100644 --- a/G4FANCYCANTESTING/CAN_LOOPBACK_TEST/CMakeLists.txt +++ b/G4FANCYCANTESTING/CAN_LOOPBACK_TEST/CMakeLists.txt @@ -51,6 +51,6 @@ set_target_properties( "CAN_${NAME}" ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE GRCAN_FANCYLAYER) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE GRCAN_FANCYLAYER LOGOMATIC_OLD_LIB) target_include_directories(${PROJECT_NAME}_USER_CODE INTERFACE ../Core/Inc) diff --git a/G4NEOTESTING/CMakeLists.txt b/G4NEOTESTING/CMakeLists.txt index 21af9929e..dba0d0e1d 100644 --- a/G4NEOTESTING/CMakeLists.txt +++ b/G4NEOTESTING/CMakeLists.txt @@ -34,6 +34,6 @@ target_sources( Core/Src/stm32g4xx_it.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE GR_NEOPIXEL) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE GR_NEOPIXEL LOGOMATIC_OLD_LIB) target_include_directories(${PROJECT_NAME}_USER_CODE INTERFACE Core/Inc) diff --git a/G4PERTESTING/CMakeLists.txt b/G4PERTESTING/CMakeLists.txt index 6a3e34d42..e9af49b58 100644 --- a/G4PERTESTING/CMakeLists.txt +++ b/G4PERTESTING/CMakeLists.txt @@ -43,6 +43,6 @@ target_sources( Core/Src/usart.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE LOGOMATIC_OLD_LIB) target_include_directories(${PROJECT_NAME}_USER_CODE INTERFACE Core/Inc) diff --git a/G4SPITESTING/CMakeLists.txt b/G4SPITESTING/CMakeLists.txt index d965f1c66..5e1f4547f 100644 --- a/G4SPITESTING/CMakeLists.txt +++ b/G4SPITESTING/CMakeLists.txt @@ -34,6 +34,6 @@ target_sources( Core/Src/stm32g4xx_it.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE SPI_Lib) +target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE SPI_Lib LOGOMATIC_OLD_LIB) target_include_directories(${PROJECT_NAME}_USER_CODE INTERFACE Core/Inc) diff --git a/Lib/Peripherals/CubeCAN/README.md b/Lib/Peripherals/CubeCAN/README.md index 8b03ca245..0e11299df 100644 --- a/Lib/Peripherals/CubeCAN/README.md +++ b/Lib/Peripherals/CubeCAN/README.md @@ -47,7 +47,7 @@ Make sure to `#include "CubeCAN.h"` where needed. Do not include `PrivateInc/int At the end of your STM32CubeMX-generated `MX_FDCAN#_Init()` function, configure your filters as needed with `HAL_FDCAN_ConfigFilter()`. It is recommended to setup a filter to ignore messages not intended for your board. -Within `main` after `MX_FDCAN#_Init()` and `LOGOMATIC()` are setup (see [Logomatic](../../Utils/Logomatic/README.md)), call `CubeCAN_Entrance()` saving the handle for global use later (one entrance and handle per peripheral). +Within `main` after `MX_FDCAN#_Init()` and Logomatic are setup (see [Logomatic](../../Utils/Logomatic/README.md)), call `CubeCAN_Entrance()` saving the handle for global use later (one entrance and handle per peripheral). Ensure you have setup some mechanism to call `CubeCAN_Tick()` frequently (a STM32CubeMX timer interrupt is recommended). This function: diff --git a/Lib/Peripherals/CubeCAN/Src/can_init.c b/Lib/Peripherals/CubeCAN/Src/can_init.c index c3ef59e68..ec86c7bef 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_init.c +++ b/Lib/Peripherals/CubeCAN/Src/can_init.c @@ -14,12 +14,12 @@ CubeCAN_Handle *CubeCAN_Entrance(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *co CubeCAN_Handle *handle = CubeCAN_Private_Init(hfdcan, config); if (handle == NULL) { - LOGOMATIC("CubeCAN_Entrance: failed to initialize handle\n"); + LOGOMATIC_ERROR("CubeCAN_Entrance: failed to initialize handle\n"); return NULL; } if (CubeCAN_Private_Start(handle) != HAL_OK) { - LOGOMATIC("CubeCAN_Entrance: failed to start handle\n"); + LOGOMATIC_ERROR("CubeCAN_Entrance: failed to start handle\n"); CubeCAN_Private_Release(handle); return NULL; } @@ -30,14 +30,14 @@ CubeCAN_Handle *CubeCAN_Entrance(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *co HAL_StatusTypeDef CubeCAN_Exit(CubeCAN_Handle *handle) { if (handle == NULL) { - LOGOMATIC("CubeCAN_Exit: invalid null parameter\n"); + LOGOMATIC_ERROR("CubeCAN_Exit: invalid null parameter\n"); return HAL_ERROR; } HAL_StatusTypeDef status = CubeCAN_Private_Stop(handle); if (status != HAL_OK) { - LOGOMATIC("CubeCAN_Exit: failed to stop FDCAN instance\n"); + LOGOMATIC_ERROR("CubeCAN_Exit: failed to stop FDCAN instance\n"); return status; } @@ -47,7 +47,7 @@ HAL_StatusTypeDef CubeCAN_Exit(CubeCAN_Handle *handle) CubeCAN_Handle *CubeCAN_Private_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config *config) { if (hfdcan == NULL || config == NULL) { - LOGOMATIC("CubeCAN_Private_Init: invalid null parameters\n"); + LOGOMATIC_ERROR("CubeCAN_Private_Init: invalid null parameters\n"); return NULL; } @@ -66,7 +66,7 @@ CubeCAN_Handle *CubeCAN_Private_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config } if (handle != NULL) { - LOGOMATIC("CubeCAN_Private_Init: handle already initialized for this FDCAN instance\n"); + LOGOMATIC_WARNING("CubeCAN_Private_Init: handle already initialized for this FDCAN instance\n"); return NULL; } else if (free_handle_index != (uint8_t)-1) { handle = &handles[free_handle_index]; @@ -80,12 +80,12 @@ CubeCAN_Handle *CubeCAN_Private_Init(FDCAN_HandleTypeDef *hfdcan, CubeCAN_Config } if (handle == NULL) { - LOGOMATIC("CubeCAN_Private_Init: no free handle slots\n"); + LOGOMATIC_ERROR("CubeCAN_Private_Init: no free handle slots\n"); return NULL; } if (HAL_FDCAN_ActivateNotification(hfdcan, FDCAN_IT_RX_EVENTS, 0U) != HAL_OK) { - LOGOMATIC("CubeCAN_Private_Init: failed to activate RX notifications\n"); + LOGOMATIC_ERROR("CubeCAN_Private_Init: failed to activate RX notifications\n"); CRITICAL_SECTION { memset(handle, 0, sizeof(*handle)); @@ -124,7 +124,7 @@ HAL_StatusTypeDef CubeCAN_Private_Release(CubeCAN_Handle *handle) } if (status != HAL_OK) { - LOGOMATIC("CubeCAN_Release: peripheral deactivation failed\n"); + LOGOMATIC_ERROR("CubeCAN_Release: peripheral deactivation failed\n"); CRITICAL_SECTION { @@ -206,4 +206,4 @@ HAL_StatusTypeDef CubeCAN_Private_Stop(CubeCAN_Handle *const handle) } return status; -} \ No newline at end of file +} diff --git a/Lib/Peripherals/CubeCAN/Src/can_rx.c b/Lib/Peripherals/CubeCAN/Src/can_rx.c index f37912f01..c330e26a4 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_rx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_rx.c @@ -11,7 +11,7 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) { if (RxFifo0ITs & FDCAN_IT_RX_FIFO0_MESSAGE_LOST) { - LOGOMATIC("WARNING: CAN Rx FIFO is overflowing, messages are being lost!\n"); + LOGOMATIC_ERROR("CAN Rx FIFO is overflowing, messages are being lost!\n"); } if (hfdcan == NULL) { @@ -42,7 +42,7 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) (void)HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &dump_header, dump_data); } - LOGOMATIC("HAL_FDCAN_RxFifo0Callback: Message dropped, unmapped handle or instance stopped\n"); + LOGOMATIC_WARNING("HAL_FDCAN_RxFifo0Callback: Message dropped, unmapped handle or instance stopped\n"); return; } @@ -55,7 +55,7 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) uint8_t size = CubeCAN_Private_DlcToBytes(rx_header.DataLength); rx_callback(&context, &id, rx_data, size); } else { - LOGOMATIC("HAL_FDCAN_RxFifo0Callback: Failed to get Rx message from FIFO\n"); + LOGOMATIC_ERROR("HAL_FDCAN_RxFifo0Callback: Failed to get Rx message from FIFO\n"); break; } } diff --git a/Lib/Peripherals/CubeCAN/Src/can_tx.c b/Lib/Peripherals/CubeCAN/Src/can_tx.c index cff1bdce0..c14b5311c 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_tx.c +++ b/Lib/Peripherals/CubeCAN/Src/can_tx.c @@ -26,7 +26,7 @@ void CubeCAN_Private_RateChecker(void) } if (current_tick > 10U && call_count_in_tick > ABSOLUTE_MAX_INVOCATIONS_PER_TICK) { - LOGOMATIC("CubeCAN_Tick: called too frequently (%" PRIu32 " times in 1 ms), you NEED to fix your timers!\tViolation %" PRIu32 "\n", call_count_in_tick, ++violations); + LOGOMATIC_ERROR("CubeCAN_Tick: called too frequently (%" PRIu32 " times in 1 ms), you NEED to fix your timers!\tViolation %" PRIu32 "\n", call_count_in_tick, ++violations); #ifdef RELAXED_TIMER_GATE // Hidden feature flag if you REALLY know what you are doing but you should fix your timers instead #warning "CubeCAN_Tick: Compiled with RELAXED_TIMER_GATE, this is a hidden feature flag that allows you to ignore the timer violation but you really should fix your timers" #else @@ -60,9 +60,9 @@ void CubeCAN_Tick(void) } if (CubeCAN_Private_IsDisabled(handle)) { - LOGOMATIC("CubeCAN_Tick: currently in restricted operation mode\n"); + LOGOMATIC_WARNING("CubeCAN_Tick: currently in restricted operation mode\n"); if (CubeCAN_Private_RecoverPeripheral(handle) != HAL_OK) { - LOGOMATIC("CubeCAN_Tick %d: failed to recover peripheral\n", (int)i); + LOGOMATIC_ERROR("CubeCAN_Tick %d: failed to recover peripheral\n", (int)i); continue; } } @@ -79,7 +79,7 @@ HAL_StatusTypeDef CubeCAN_Send(CubeCAN_Handle *const handle, const GRCAN_NODE_ID const uint32_t dlc = CubeCAN_Private_BytesToDlc(size); if (dlc == FDCAN_DLC_BYTES_0 && size != 0) { - LOGOMATIC("CubeCAN_Send: invalid data length code\n"); + LOGOMATIC_ERROR("CubeCAN_Send: invalid data length code\n"); return HAL_ERROR; } @@ -99,7 +99,7 @@ HAL_StatusTypeDef CubeCAN_Send(CubeCAN_Handle *const handle, const GRCAN_NODE_ID brs = FDCAN_BRS_ON; break; default: - LOGOMATIC("CubeCAN_Send: unsupported frame format\n"); + LOGOMATIC_ERROR("CubeCAN_Send: unsupported frame format\n"); return HAL_ERROR; } @@ -150,12 +150,12 @@ HAL_StatusTypeDef CubeCAN_Private_QueueTx(CubeCAN_Handle *handle, const GRCAN_Pr HAL_StatusTypeDef CubeCAN_Private_SendQueuedMessage(const CubeCAN_Handle *const handle) { if (handle == NULL || handle->hfdcan == NULL) { - LOGOMATIC("CubeCAN_Private_SendQueuedMessage: invalid null parameter\n"); + LOGOMATIC_ERROR("CubeCAN_Private_SendQueuedMessage: invalid null parameter\n"); return HAL_ERROR; } if (HAL_FDCAN_GetTxFifoFreeLevel(handle->hfdcan) == 0U) { - LOGOMATIC("CubeCAN_Private_SendQueuedMessage: Tx FIFO full, cannot send message\n"); + LOGOMATIC_ERROR("CubeCAN_Private_SendQueuedMessage: Tx FIFO full, cannot send message\n"); return HAL_BUSY; } diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index f1959b8dc..bfa641dcc 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -73,7 +73,7 @@ uint8_t CubeCAN_Private_BytesToDlc(const uint8_t bytes) case 64U: return FDCAN_DLC_BYTES_64; default: - LOGOMATIC("CubeCAN_Private_BytesToDlc: Invalid byte count\n"); + LOGOMATIC_ERROR("CubeCAN_Private_BytesToDlc: Invalid byte count\n"); return FDCAN_DLC_BYTES_0; } } @@ -114,7 +114,7 @@ uint8_t CubeCAN_Private_DlcToBytes(const uint32_t dlc) case FDCAN_DLC_BYTES_64: return 64U; default: - LOGOMATIC("CubeCAN_Private_DlcToBytes: Invalid DLC value\n"); + LOGOMATIC_ERROR("CubeCAN_Private_DlcToBytes: Invalid DLC value\n"); return 0U; } } @@ -160,7 +160,7 @@ HAL_StatusTypeDef CubeCAN_Private_RecoverPeripheral(const CubeCAN_Handle *const FDCAN_ProtocolStatusTypeDef protocol_status = {0}; if (HAL_FDCAN_GetProtocolStatus(handle->hfdcan, &protocol_status) == HAL_OK && protocol_status.BusOff) { - LOGOMATIC("CubeCAN_Private_RecoverPeripheral: CRITICAL BUS-OFF DETECTED. Forcing hardware reset...\n"); + LOGOMATIC_ERROR("CubeCAN_Private_RecoverPeripheral: CRITICAL BUS-OFF DETECTED. Forcing hardware reset...\n"); HAL_FDCAN_Stop(handle->hfdcan); @@ -175,13 +175,17 @@ HAL_StatusTypeDef CubeCAN_Private_RecoverPeripheral(const CubeCAN_Handle *const } if (status != HAL_OK) { - LOGOMATIC("CubeCAN_Private_RecoverPeripheral: Aggressive hardware start failed!\n"); + LOGOMATIC_ERROR("CubeCAN_Private_RecoverPeripheral: Aggressive hardware start failed!\n"); } } if (HAL_FDCAN_IsRestrictedOperationMode(handle->hfdcan)) { - LOGOMATIC("CubeCAN_Private_RecoverPeripheral: Forcing exit from restricted operation mode\n"); - HAL_FDCAN_ExitRestrictedOperationMode(handle->hfdcan); + LOGOMATIC_WARNING("CubeCAN_Private_RecoverPeripheral: Forcing exit from restricted operation mode\n"); + status = HAL_FDCAN_ExitRestrictedOperationMode(handle->hfdcan); + + if (status != HAL_OK) { + LOGOMATIC_ERROR("CubeCAN_Private_RecoverPeripheral: Failed to recover peripheral\n"); + } } } } diff --git a/Lib/Peripherals/CubeCAN/cube_can.cmake b/Lib/Peripherals/CubeCAN/cube_can.cmake index 4d6095b5a..0168d0d8c 100644 --- a/Lib/Peripherals/CubeCAN/cube_can.cmake +++ b/Lib/Peripherals/CubeCAN/cube_can.cmake @@ -17,5 +17,5 @@ target_link_libraries( CUBE_CAN_LIB INTERFACE CANfigurator - LOGOMATIC_OLD_LIB + LOGOMATIC_LIB ) diff --git a/Lib/Utils/Logomatic/Inc/Logomatic.h b/Lib/Utils/Logomatic/Inc/Logomatic.h index e69de29bb..7452dbae9 100644 --- a/Lib/Utils/Logomatic/Inc/Logomatic.h +++ b/Lib/Utils/Logomatic/Inc/Logomatic.h @@ -0,0 +1,182 @@ +#include +#include "main.h" + +#ifndef LOGOMATIC_H +#define LOGOMATIC_H + +/** + * @brief Logomatic log levels + * + * These are the different log levels available in Logomatic + * + * @note To turn off logging, you must use CMAKE_LOGOMATIC_ENABLED + * @warning Strictly ordered in increasing severity, changing this order will break filters + */ +typedef enum { + /// @brief Verbose log level, used for detailed debugging information + LogLevel_Verbose, + /// @brief Debug log level, used for debugging information + LogLevel_Debug, + /// @brief Info log level, used for general information + LogLevel_Info, + /// @brief Warning log level, used for warnings + LogLevel_Warning, + /// @brief Error log level, used for errors + LogLevel_Error, + /// @brief Critical log level, used for critical errors + LogLevel_Critical, + /// @brief Disabled log level, used to turn off logging + LogLevel_Off +} Logomatic_LogLevel; + +/** + * @brief Logomatic driver function pointer type + * + * This is used to define the log driver function that will be used to output log messages + * + * @note Default log drivers are provided for you but you can implement your own log driver by defining a function that matches this signature and assigning it to the global_logomatic_driver variable + */ +typedef int (*Logomatic_Driver)(int); + +/** + * @brief Global log level variable + * + * Store the global log level in this variable. It is used to determine which log messages should be printed based on their severity. + * + * @warning This variable should not be modified once setup by the user. + */ +extern Logomatic_LogLevel global_logomatic_level; + +/** + * @brief Logomatic driver function pointer + * + * This function pointer is used to point to the appropriate log driver function based on the selected log output method (e.g., ITM, UART, etc.) + * + * @note This variable should not be modified once setup by the user. + */ +extern Logomatic_Driver global_logomatic_driver; + +/** + * @brief Logomatic log level implementation macro + * + * This macro is used to implement the log level functionality to give fancy names + * + * @param level The log level of the message + * @param ... The log message format and arguments + */ +#define LOGOMATIC_PRIVATE_LEVEL(level, ...) \ + do { \ + if (global_logomatic_level <= (level) && (level) != LogLevel_Off && global_logomatic_level != LogLevel_Off) { \ + _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdouble-promotion\"") printf(__VA_ARGS__); \ + _Pragma("GCC diagnostic pop") \ + } \ + } while (0) + +#if defined(LOGOMATIC_ENABLED) + +#define LOGOMATIC_CRITICAL(...) LOGOMATIC_PRIVATE_LEVEL(LogLevel_Critical, __VA_ARGS__) +#define LOGOMATIC_ERROR(...) LOGOMATIC_PRIVATE_LEVEL(LogLevel_Error, __VA_ARGS__) +#define LOGOMATIC_WARNING(...) LOGOMATIC_PRIVATE_LEVEL(LogLevel_Warning, __VA_ARGS__) +#define LOGOMATIC_INFO(...) LOGOMATIC_PRIVATE_LEVEL(LogLevel_Info, __VA_ARGS__) +#define LOGOMATIC_DEBUG(...) LOGOMATIC_PRIVATE_LEVEL(LogLevel_Debug, __VA_ARGS__) +#define LOGOMATIC_VERBOSE(...) LOGOMATIC_PRIVATE_LEVEL(LogLevel_Verbose, __VA_ARGS__) + +#else + +#define LOGOMATIC_OFF(...) \ + do { \ + if (0) { \ + printf(__VA_ARGS__); \ + } \ + } while (0) + +#define LOGOMATIC_CRITICAL(...) LOGOMATIC_OFF(__VA_ARGS__) +#define LOGOMATIC_ERROR(...) LOGOMATIC_OFF(__VA_ARGS__) +#define LOGOMATIC_WARNING(...) LOGOMATIC_OFF(__VA_ARGS__) +#define LOGOMATIC_INFO(...) LOGOMATIC_OFF(__VA_ARGS__) +#define LOGOMATIC_DEBUG(...) LOGOMATIC_OFF(__VA_ARGS__) +#define LOGOMATIC_VERBOSE(...) LOGOMATIC_OFF(__VA_ARGS__) + +#endif + +#if defined(ITM) +int Logomatic_Driver_ITM(int ch); +#endif + +#if defined(LPUART1) +int Logomatic_Driver_LPUART1(int ch); +#endif + +#if defined(LPUART2) +int Logomatic_Driver_LPUART2(int ch); +#endif + +#if defined(LPUART3) +int Logomatic_Driver_LPUART3(int ch); +#endif + +#if defined(USART1) +int Logomatic_Driver_USART1(int ch); +#endif + +#if defined(USART2) +int Logomatic_Driver_USART2(int ch); +#endif + +#if defined(USART3) +int Logomatic_Driver_USART3(int ch); +#endif + +#if defined(USART4) +int Logomatic_Driver_USART4(int ch); +#endif + +#if defined(USART5) +int Logomatic_Driver_USART5(int ch); +#endif + +#if defined(USART6) +int Logomatic_Driver_USART6(int ch); +#endif + +#if defined(USART7) +int Logomatic_Driver_USART7(int ch); +#endif + +#if defined(USART8) +int Logomatic_Driver_USART8(int ch); +#endif + +#if defined(UART1) +int Logomatic_Driver_UART1(int ch); +#endif + +#if defined(UART2) +int Logomatic_Driver_UART2(int ch); +#endif + +#if defined(UART3) +int Logomatic_Driver_UART3(int ch); +#endif + +#if defined(UART4) +int Logomatic_Driver_UART4(int ch); +#endif + +#if defined(UART5) +int Logomatic_Driver_UART5(int ch); +#endif + +#if defined(UART6) +int Logomatic_Driver_UART6(int ch); +#endif + +#if defined(UART7) +int Logomatic_Driver_UART7(int ch); +#endif + +#if defined(UART8) +int Logomatic_Driver_UART8(int ch); +#endif + +#endif diff --git a/Lib/Utils/Logomatic/Src/log_global.c b/Lib/Utils/Logomatic/Src/log_global.c new file mode 100644 index 000000000..cb6622099 --- /dev/null +++ b/Lib/Utils/Logomatic/Src/log_global.c @@ -0,0 +1,12 @@ +#include "Logomatic.h" +#include "main.h" + +Logomatic_LogLevel global_logomatic_level = LogLevel_Info; + +#if defined(ITM) +Logomatic_Driver global_logomatic_driver = Logomatic_Driver_ITM; +#elif defined(LPUART1) +Logomatic_Driver global_logomatic_driver = Logomatic_Driver_LPUART1; +#else +Logomatic_Driver global_logomatic_driver = NULL; +#endif diff --git a/Lib/Utils/Logomatic/Src/log_levels.c b/Lib/Utils/Logomatic/Src/log_levels.c deleted file mode 100644 index e69de29bb..000000000 diff --git a/Lib/Utils/Logomatic/Src/log_putchar.c b/Lib/Utils/Logomatic/Src/log_putchar.c index e69de29bb..7c6f16043 100644 --- a/Lib/Utils/Logomatic/Src/log_putchar.c +++ b/Lib/Utils/Logomatic/Src/log_putchar.c @@ -0,0 +1,169 @@ +#include "Logomatic.h" +#include "main.h" + +__attribute__((weak)) int __io_putchar(int ch) +{ + if (global_logomatic_driver != NULL) { + return global_logomatic_driver(ch); + } + return ch; +} + +#if defined(ITM) +int Logomatic_Driver_ITM(int ch) +{ + ITM_SendChar(ch); + return ch; +} +#endif + +#if defined(LPUART1) || defined(LPUART2) || defined(LPUART3) || defined(USART1) || defined(USART2) || defined(USART3) || defined(USART4) || defined(USART5) || defined(USART6) || defined(USART7) || \ + defined(USART8) || defined(UART1) || defined(UART2) || defined(UART3) || defined(UART4) || defined(UART5) || defined(UART6) || defined(UART7) || defined(UART8) +int Logomatic_Private_UART(USART_TypeDef *uart, int ch) +{ +#if defined(USART_ISR_TXE_TXFNF) + while (!(uart->ISR & USART_ISR_TXE_TXFNF)) {} + uart->TDR = (uint8_t)ch; +#elif defined(USART_ISR_TXE) + while (!(uart->ISR & USART_ISR_TXE)) {} + uart->TDR = (uint8_t)ch; +#else + while (!(uart->SR & USART_SR_TXE)) {} + uart->DR = (uint8_t)ch; +#endif + return ch; +} +#endif + +#if defined(LPUART1) +int Logomatic_Driver_LPUART1(int ch) +{ + return Logomatic_Private_UART(LPUART1, ch); +} +#endif + +#if defined(LPUART2) +int Logomatic_Driver_LPUART2(int ch) +{ + return Logomatic_Private_UART(LPUART2, ch); +} +#endif + +#if defined(LPUART3) +int Logomatic_Driver_LPUART3(int ch) +{ + return Logomatic_Private_UART(LPUART3, ch); +} +#endif + +#if defined(USART1) +int Logomatic_Driver_USART1(int ch) +{ + return Logomatic_Private_UART(USART1, ch); +} +#endif + +#if defined(USART2) +int Logomatic_Driver_USART2(int ch) +{ + return Logomatic_Private_UART(USART2, ch); +} +#endif + +#if defined(USART3) +int Logomatic_Driver_USART3(int ch) +{ + return Logomatic_Private_UART(USART3, ch); +} +#endif + +#if defined(USART4) +int Logomatic_Driver_USART4(int ch) +{ + return Logomatic_Private_UART(USART4, ch); +} +#endif + +#if defined(USART5) +int Logomatic_Driver_USART5(int ch) +{ + return Logomatic_Private_UART(USART5, ch); +} +#endif + +#if defined(USART6) +int Logomatic_Driver_USART6(int ch) +{ + return Logomatic_Private_UART(USART6, ch); +} +#endif + +#if defined(USART7) +int Logomatic_Driver_USART7(int ch) +{ + return Logomatic_Private_UART(USART7, ch); +} +#endif + +#if defined(USART8) +int Logomatic_Driver_USART8(int ch) +{ + return Logomatic_Private_UART(USART8, ch); +} +#endif + +#if defined(UART1) +int Logomatic_Driver_UART1(int ch) +{ + return Logomatic_Private_UART(UART1, ch); +} +#endif + +#if defined(UART2) +int Logomatic_Driver_UART2(int ch) +{ + return Logomatic_Private_UART(UART2, ch); +} +#endif + +#if defined(UART3) +int Logomatic_Driver_UART3(int ch) +{ + return Logomatic_Private_UART(UART3, ch); +} +#endif + +#if defined(UART4) +int Logomatic_Driver_UART4(int ch) +{ + return Logomatic_Private_UART(UART4, ch); +} +#endif + +#if defined(UART5) +int Logomatic_Driver_UART5(int ch) +{ + return Logomatic_Private_UART(UART5, ch); +} +#endif + +#if defined(UART6) +int Logomatic_Driver_UART6(int ch) +{ + return Logomatic_Private_UART(UART6, ch); +} +#endif + +#if defined(UART7) +int Logomatic_Driver_UART7(int ch) +{ + return Logomatic_Private_UART(UART7, ch); +} +#endif + +#if defined(UART8) +int Logomatic_Driver_UART8(int ch) +{ + return Logomatic_Private_UART(UART8, ch); +} +#endif diff --git a/Lib/Utils/Logomatic/common.cmake b/Lib/Utils/Logomatic/log.cmake similarity index 88% rename from Lib/Utils/Logomatic/common.cmake rename to Lib/Utils/Logomatic/log.cmake index 7e901f39c..cf1d612c9 100644 --- a/Lib/Utils/Logomatic/common.cmake +++ b/Lib/Utils/Logomatic/log.cmake @@ -9,7 +9,8 @@ target_include_directories( target_sources( LOGOMATIC_LIB INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/Src/Logomatic.c + ${CMAKE_CURRENT_LIST_DIR}/Src/log_putchar.c + ${CMAKE_CURRENT_LIST_DIR}/Src/log_global.c ) target_link_libraries(LOGOMATIC_LIB INTERFACE GLOBALSHARE_LIB) diff --git a/Lib/cmake/gr-lib.cmake b/Lib/cmake/gr-lib.cmake index 8eaa5cd72..619031bd6 100644 --- a/Lib/cmake/gr-lib.cmake +++ b/Lib/cmake/gr-lib.cmake @@ -34,7 +34,6 @@ function(add_gr_project) ${TARGET_NAME} PRIVATE ${TARGET_NAME}_USER_CODE # Blame Owen - LOGOMATIC_OLD_LIB GLOBALSHARE_LIB m ) diff --git a/OutboardSensors/BrakeTemp/CMakeLists.txt b/OutboardSensors/BrakeTemp/CMakeLists.txt index 88485311c..4b63816c1 100644 --- a/OutboardSensors/BrakeTemp/CMakeLists.txt +++ b/OutboardSensors/BrakeTemp/CMakeLists.txt @@ -50,6 +50,7 @@ target_link_libraries( BitManipulations_Lib MLX90614_LIB PERIPHERAL_TIMEDCAN_LIB + LOGOMATIC_OLD_LIB ) target_include_directories( diff --git a/OutboardSensors/TireTemp/CMakeLists.txt b/OutboardSensors/TireTemp/CMakeLists.txt index 4d7126fea..933e1d4a5 100644 --- a/OutboardSensors/TireTemp/CMakeLists.txt +++ b/OutboardSensors/TireTemp/CMakeLists.txt @@ -49,6 +49,7 @@ target_link_libraries( BitManipulations_Lib MLX90640_LIB PERIPHERAL_TIMEDCAN_LIB + LOGOMATIC_OLD_LIB ) target_include_directories( From 5d55342a84c9e6fd6c6593922e2bf8d68ab169e7 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 03:29:16 -0700 Subject: [PATCH 080/125] Wrap out logging levels in logs Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Application/Src/Loop.c | 2 + CUBEMXTESTING/CUBEMXTESTING.ioc | 2 +- CUBEMXTESTING/Core/Src/main.c | 165 +++++++++--------- Lib/Utils/Logomatic/Inc/Logomatic.h | 62 ++++--- Lib/Utils/Logomatic/Src/log_config.c | 30 ++++ .../Src/{log_putchar.c => log_driver.c} | 2 +- Lib/Utils/Logomatic/Src/log_global.c | 12 -- Lib/Utils/Logomatic/Test/main.h | 6 + Lib/Utils/Logomatic/Test/print.c | 160 +++++++++++++++++ Lib/Utils/Logomatic/log.cmake | 18 +- 10 files changed, 340 insertions(+), 119 deletions(-) create mode 100644 Lib/Utils/Logomatic/Src/log_config.c rename Lib/Utils/Logomatic/Src/{log_putchar.c => log_driver.c} (98%) delete mode 100644 Lib/Utils/Logomatic/Src/log_global.c create mode 100644 Lib/Utils/Logomatic/Test/main.h create mode 100644 Lib/Utils/Logomatic/Test/print.c diff --git a/CUBEMXTESTING/Application/Src/Loop.c b/CUBEMXTESTING/Application/Src/Loop.c index 47e6d9403..fcf545e5b 100644 --- a/CUBEMXTESTING/Application/Src/Loop.c +++ b/CUBEMXTESTING/Application/Src/Loop.c @@ -17,4 +17,6 @@ void MainLoop(void) (void)CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello0", 6); (void)CubeCAN_Send(dataHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello1", 6); (void)CubeCAN_Send(chargerHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello2", 6); + + LOGOMATIC_VERBOSE("Main Loop %d %" PRIu32 "\n", value, HAL_GetTick()); } diff --git a/CUBEMXTESTING/CUBEMXTESTING.ioc b/CUBEMXTESTING/CUBEMXTESTING.ioc index c57595183..f677d27ec 100644 --- a/CUBEMXTESTING/CUBEMXTESTING.ioc +++ b/CUBEMXTESTING/CUBEMXTESTING.ioc @@ -153,7 +153,7 @@ ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=false ProjectManager.UseDefaultDestinationPath=true ProjectManager.UseDefaultSourcePath=true -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_TIM5_Init-TIM5-false-HAL-true,6-MX_FDCAN3_Init-FDCAN3-false-HAL-true,7-MX_LPUART1_UART_Init-LPUART1-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_TIM5_Init-TIM5-false-HAL-true,6-MX_FDCAN3_Init-FDCAN3-false-HAL-true RCC.ADC12Freq_Value=160000000 RCC.ADC345Freq_Value=160000000 RCC.AHBFreq_Value=160000000 diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 0047a391d..4815d76e2 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,10 +18,9 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" - #include "fdcan.h" -#include "gpio.h" #include "tim.h" +#include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -75,39 +74,39 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + /* USER CODE BEGIN 2 */ CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config dataCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_DATA, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config chargerCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_CHARGER, .sending_node_id = GRCAN_Debugger}; @@ -130,60 +129,68 @@ int main(void) Error_Handler(); } - LOGOMATIC_DEBUG("Hello World!\n"); - /* USER CODE END 2 */ + LOGOMATIC_INFO("Hello World!\n"); + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); HAL_Delay(100); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) + { + } + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while(LL_RCC_HSI_IsReady() != 1) + { + } + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while(LL_RCC_PLL_IsReady() != 1) + { + } + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) + { + } + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i !=0; i--); + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) + { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -202,29 +209,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ LOGOMATIC_CRITICAL("Assert failed! File %s on line %" PRIu32 "\n", file, line); - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/Lib/Utils/Logomatic/Inc/Logomatic.h b/Lib/Utils/Logomatic/Inc/Logomatic.h index 7452dbae9..5e4df50c8 100644 --- a/Lib/Utils/Logomatic/Inc/Logomatic.h +++ b/Lib/Utils/Logomatic/Inc/Logomatic.h @@ -1,33 +1,44 @@ #include + #include "main.h" #ifndef LOGOMATIC_H #define LOGOMATIC_H +/// @brief Logomatic log level type, used to define the severity of log messages +#define _LOGOMATIC_LOGLEVEL_X_LIST \ + X(LogLevel_Off, 0, "OFF") \ + X(LogLevel_Critical, 1, "CRITICAL") \ + X(LogLevel_Error, 2, "ERROR") \ + X(LogLevel_Warning, 3, "WARNING") \ + X(LogLevel_Info, 4, "INFO") \ + X(LogLevel_Debug, 5, "DEBUG") \ + X(LogLevel_Verbose, 6, "VERBOSE") + +typedef enum { +#define X(name, val, str) name = val, + _LOGOMATIC_LOGLEVEL_X_LIST +#undef X +} Logomatic_LogLevel; + /** - * @brief Logomatic log levels + * @brief Set the global log level * - * These are the different log levels available in Logomatic + * Only logs with a higher or equal severity than the global log level will be printed. * - * @note To turn off logging, you must use CMAKE_LOGOMATIC_ENABLED - * @warning Strictly ordered in increasing severity, changing this order will break filters + * @param level The log level to set as the global log level. This should be one of the values from the Logomatic_LogLevel enum. + * @return true if the log level was successfully set, false if the provided log level is invalid. */ -typedef enum { - /// @brief Verbose log level, used for detailed debugging information - LogLevel_Verbose, - /// @brief Debug log level, used for debugging information - LogLevel_Debug, - /// @brief Info log level, used for general information - LogLevel_Info, - /// @brief Warning log level, used for warnings - LogLevel_Warning, - /// @brief Error log level, used for errors - LogLevel_Error, - /// @brief Critical log level, used for critical errors - LogLevel_Critical, - /// @brief Disabled log level, used to turn off logging - LogLevel_Off -} Logomatic_LogLevel; +bool Logomatic_SetLogLevel(Logomatic_LogLevel level); + +/** + * @brief Logomatic log level strings + * + * This array is used to map the log level enum values to their corresponding string representations for printing log messages. + * + * @note The order of the strings in this array must match the order of the enum values in Logomatic_LogLevel. + */ +extern const char *Logomatic_Private_LogLevelStrings[]; /** * @brief Logomatic driver function pointer type @@ -45,7 +56,7 @@ typedef int (*Logomatic_Driver)(int); * * @warning This variable should not be modified once setup by the user. */ -extern Logomatic_LogLevel global_logomatic_level; +extern Logomatic_LogLevel _logomatic_loglevel; /** * @brief Logomatic driver function pointer @@ -54,7 +65,7 @@ extern Logomatic_LogLevel global_logomatic_level; * * @note This variable should not be modified once setup by the user. */ -extern Logomatic_Driver global_logomatic_driver; +extern const Logomatic_Driver global_logomatic_driver; /** * @brief Logomatic log level implementation macro @@ -66,7 +77,12 @@ extern Logomatic_Driver global_logomatic_driver; */ #define LOGOMATIC_PRIVATE_LEVEL(level, ...) \ do { \ - if (global_logomatic_level <= (level) && (level) != LogLevel_Off && global_logomatic_level != LogLevel_Off) { \ + if (_logomatic_loglevel >= (level) && (level) != LogLevel_Off && _logomatic_loglevel != LogLevel_Off) { \ + if (level == LogLevel_Verbose) { \ + printf("[%s - %s:%d] ", Logomatic_Private_LogLevelStrings[(level)], __FILE_NAME__, __LINE__); \ + } else { \ + printf("[%s] ", Logomatic_Private_LogLevelStrings[(level)]); \ + } \ _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdouble-promotion\"") printf(__VA_ARGS__); \ _Pragma("GCC diagnostic pop") \ } \ diff --git a/Lib/Utils/Logomatic/Src/log_config.c b/Lib/Utils/Logomatic/Src/log_config.c new file mode 100644 index 000000000..435fb3357 --- /dev/null +++ b/Lib/Utils/Logomatic/Src/log_config.c @@ -0,0 +1,30 @@ +#include "Logomatic.h" +#include "main.h" + +__weak Logomatic_LogLevel _logomatic_loglevel = LogLevel_Debug; + +#if defined(ITM) +__weak const Logomatic_Driver global_logomatic_driver = Logomatic_Driver_ITM; +#elif defined(LPUART1) +__weak const Logomatic_Driver global_logomatic_driver = Logomatic_Driver_LPUART1; +#else +__weak const Logomatic_Driver global_logomatic_driver = NULL; +#endif + +const char *Logomatic_Private_LogLevelStrings[] = { +#define X(name, val, str) [val] = str, + _LOGOMATIC_LOGLEVEL_X_LIST +#undef X +}; + +bool Logomatic_SetLogLevel(Logomatic_LogLevel level) +{ +#define X(name, val, string) \ + if (level == val) { \ + _logomatic_loglevel = level; \ + return true; \ + } + _LOGOMATIC_LOGLEVEL_X_LIST +#undef X + return false; +} diff --git a/Lib/Utils/Logomatic/Src/log_putchar.c b/Lib/Utils/Logomatic/Src/log_driver.c similarity index 98% rename from Lib/Utils/Logomatic/Src/log_putchar.c rename to Lib/Utils/Logomatic/Src/log_driver.c index 7c6f16043..80cfc6b3d 100644 --- a/Lib/Utils/Logomatic/Src/log_putchar.c +++ b/Lib/Utils/Logomatic/Src/log_driver.c @@ -1,7 +1,7 @@ #include "Logomatic.h" #include "main.h" -__attribute__((weak)) int __io_putchar(int ch) +int __io_putchar(int ch) { if (global_logomatic_driver != NULL) { return global_logomatic_driver(ch); diff --git a/Lib/Utils/Logomatic/Src/log_global.c b/Lib/Utils/Logomatic/Src/log_global.c deleted file mode 100644 index cb6622099..000000000 --- a/Lib/Utils/Logomatic/Src/log_global.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "Logomatic.h" -#include "main.h" - -Logomatic_LogLevel global_logomatic_level = LogLevel_Info; - -#if defined(ITM) -Logomatic_Driver global_logomatic_driver = Logomatic_Driver_ITM; -#elif defined(LPUART1) -Logomatic_Driver global_logomatic_driver = Logomatic_Driver_LPUART1; -#else -Logomatic_Driver global_logomatic_driver = NULL; -#endif diff --git a/Lib/Utils/Logomatic/Test/main.h b/Lib/Utils/Logomatic/Test/main.h new file mode 100644 index 000000000..2d58e80e5 --- /dev/null +++ b/Lib/Utils/Logomatic/Test/main.h @@ -0,0 +1,6 @@ +#ifndef MAIN_H +#define MAIN_H + +#define __weak __attribute__((weak)) + +#endif diff --git a/Lib/Utils/Logomatic/Test/print.c b/Lib/Utils/Logomatic/Test/print.c new file mode 100644 index 000000000..81e80c3c7 --- /dev/null +++ b/Lib/Utils/Logomatic/Test/print.c @@ -0,0 +1,160 @@ +#include +#include +#include +#include + +#include "ComparatorMacros.h" +#include "Logomatic.h" +#include "Stringification.h" + +const char *expected_output_critical = "%sThis is a critical message.\n"; +const char *expected_output_error = "%sThis is an error message.\n"; +const char *expected_output_warning = "%sThis is a warning message.\n"; +const char *expected_output_info = "%sThis is an info message.\n"; +const char *expected_output_debug = "%sThis is a debug message.\n"; +const char *expected_output_verbose = "%sThis is a verbose message.\n"; + +bool verification(void (*print_func)(void), const char *expected_content) +{ + char formatted[100]; + char *buffer = NULL; + size_t size = 0; + + FILE *original_stdout = stdout; + + FILE *mem_stream = open_memstream(&buffer, &size); + if (!mem_stream) { + perror("Failed to create memory stream"); + return false; + } + + stdout = mem_stream; + + print_func(); + + fflush(stdout); + fclose(mem_stream); + + stdout = original_stdout; + + switch (_logomatic_loglevel) { + case LogLevel_Critical: + snprintf(formatted, sizeof(formatted), expected_content, "[CRIT] "); + break; + case LogLevel_Error: + snprintf(formatted, sizeof(formatted), expected_content, "[ERROR] "); + break; + case LogLevel_Warning: + snprintf(formatted, sizeof(formatted), expected_content, "[WARN] "); + break; + case LogLevel_Info: + snprintf(formatted, sizeof(formatted), expected_content, "[INFO] "); + break; + case LogLevel_Debug: + snprintf(formatted, sizeof(formatted), expected_content, "[DBG] "); + break; + case LogLevel_Verbose: + snprintf(formatted, sizeof(formatted), expected_content, "[V - " __FILE_NAME__ ":117] "); + break; + default: + snprintf(formatted, sizeof(formatted), expected_content, ""); + break; + } + + bool match = strncmp(buffer, formatted, MIN_WITH_TYPES(size, strlen(formatted))) == 0; + + if (!match) { + printf("Mismatch detected.\n"); + printf(" Expected: \"%s\"\n", formatted); + printf(" Captured: \"%s\"\n", buffer); + } else { + printf("Output matches expected content for level %d with %s", _logomatic_loglevel, formatted); + } + + free(buffer); + + return match; +} + +void print_all(void) +{ + + LOGOMATIC_CRITICAL(expected_output_critical); + LOGOMATIC_ERROR(expected_output_error); + LOGOMATIC_WARNING(expected_output_warning); + LOGOMATIC_INFO(expected_output_info); + LOGOMATIC_DEBUG(expected_output_debug); + LOGOMATIC_VERBOSE(expected_output_verbose); +} + +void printf_critical(void) +{ + LOGOMATIC_CRITICAL(expected_output_critical, ""); +} + +void printf_error(void) +{ + LOGOMATIC_ERROR(expected_output_error, ""); +} + +void printf_warning(void) +{ + LOGOMATIC_WARNING(expected_output_warning, ""); +} + +void printf_info(void) +{ + LOGOMATIC_INFO(expected_output_info, ""); +} + +void printf_debug(void) +{ + LOGOMATIC_DEBUG(expected_output_debug, ""); +} + +void printf_verbose(void) +{ + LOGOMATIC_VERBOSE(expected_output_verbose, ""); +} + +int main(void) +{ + _logomatic_loglevel = LogLevel_Off; + if (!verification(print_all, "")) { + return 1; + } + _logomatic_loglevel = LogLevel_Critical; + if (!verification(printf_critical, expected_output_critical)) { + return 2; + } + _logomatic_loglevel = LogLevel_Error; + if (!verification(printf_critical, "")) { + return 3; + } + _logomatic_loglevel = LogLevel_Error; + if (!verification(printf_error, expected_output_error)) { + return 4; + } + _logomatic_loglevel = LogLevel_Warning; + if (!verification(printf_warning, expected_output_warning)) { + return 5; + } + _logomatic_loglevel = LogLevel_Info; + if (!verification(printf_info, expected_output_info)) { + return 6; + } + _logomatic_loglevel = LogLevel_Info; + if (!verification(printf_debug, "")) { + return 7; + } + _logomatic_loglevel = LogLevel_Debug; + if (!verification(printf_debug, expected_output_debug)) { + return 8; + } + _logomatic_loglevel = LogLevel_Verbose; + if (!verification(printf_verbose, expected_output_verbose)) { + return 9; + } + + return 0; +} diff --git a/Lib/Utils/Logomatic/log.cmake b/Lib/Utils/Logomatic/log.cmake index cf1d612c9..7d3ee053a 100644 --- a/Lib/Utils/Logomatic/log.cmake +++ b/Lib/Utils/Logomatic/log.cmake @@ -9,8 +9,8 @@ target_include_directories( target_sources( LOGOMATIC_LIB INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/Src/log_putchar.c - ${CMAKE_CURRENT_LIST_DIR}/Src/log_global.c + ${CMAKE_CURRENT_LIST_DIR}/Src/log_config.c + ${CMAKE_CURRENT_LIST_DIR}/Src/log_driver.c ) target_link_libraries(LOGOMATIC_LIB INTERFACE GLOBALSHARE_LIB) @@ -25,7 +25,19 @@ if(CMAKE_LOGOMATIC_ENABLED) endif() if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") - # TODO + add_executable(logomatic) + target_sources( + logomatic + PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/Test/print.c + ) + target_include_directories( + logomatic + PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/Test + ) + target_link_libraries(logomatic PRIVATE LOGOMATIC_LIB GLOBALSHARE_LIB) + add_test(logomatic_test logomatic) else() target_compile_options( LOGOMATIC_LIB From fa286872444817debe741febfef5a12e843c1a88 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2026 10:32:37 +0000 Subject: [PATCH 081/125] Automatic CMake Format: Standardized formatting automatically --- BLINKY/G4ECHO/CMakeLists.txt | 7 ++++++- .../G431x8_CAN_BASIC_TEST/CMakeLists.txt | 7 ++++++- G474xE_CAN_TESTING/CAN_BASIC_TEST/CMakeLists.txt | 7 ++++++- G474xE_CAN_TESTING/CAN_FILTER_TEST/CMakeLists.txt | 7 ++++++- G474xE_CAN_TESTING/CAN_INTERNAL_TEST/CMakeLists.txt | 7 ++++++- G474xE_CAN_TESTING/CAN_LOST_RX_TEST/CMakeLists.txt | 7 ++++++- G474xE_CAN_TESTING/CAN_RELEASE_TEST/CMakeLists.txt | 7 ++++++- G474xE_CAN_TESTING/CAN_STRESS_TEST/CMakeLists.txt | 7 ++++++- G474xE_CAN_TESTING/PROFILER_TEST/CMakeLists.txt | 7 ++++++- G4ADCTESTING/CMakeLists.txt | 7 ++++++- G4FANCYCANTESTING/CAN_LOOPBACK_TEST/CMakeLists.txt | 7 ++++++- G4NEOTESTING/CMakeLists.txt | 7 ++++++- G4SPITESTING/CMakeLists.txt | 7 ++++++- Lib/Utils/Logomatic/log.cmake | 13 +++++-------- 14 files changed, 83 insertions(+), 21 deletions(-) diff --git a/BLINKY/G4ECHO/CMakeLists.txt b/BLINKY/G4ECHO/CMakeLists.txt index 1edb59380..e8eb97182 100644 --- a/BLINKY/G4ECHO/CMakeLists.txt +++ b/BLINKY/G4ECHO/CMakeLists.txt @@ -35,6 +35,11 @@ target_sources( Core/Src/stm32g4xx_hal_msp.c ) -target_link_libraries(${GR_PROJECT_NAME}_USER_CODE INTERFACE VCP_LIB LOGOMATIC_OLD_LIB) +target_link_libraries( + ${GR_PROJECT_NAME}_USER_CODE + INTERFACE + VCP_LIB + LOGOMATIC_OLD_LIB +) target_include_directories(${GR_PROJECT_NAME}_USER_CODE INTERFACE Core/Inc) diff --git a/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/CMakeLists.txt b/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/CMakeLists.txt index b350d6f82..c1a4f180b 100644 --- a/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/CMakeLists.txt +++ b/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/CMakeLists.txt @@ -50,7 +50,12 @@ set_target_properties( "CAN_${NAME}" ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB LOGOMATIC_OLD_LIB) +target_link_libraries( + ${PROJECT_NAME}_USER_CODE + INTERFACE + PERIPHERAL_CAN_LIB + LOGOMATIC_OLD_LIB +) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/G474xE_CAN_TESTING/CAN_BASIC_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_BASIC_TEST/CMakeLists.txt index b350d6f82..c1a4f180b 100644 --- a/G474xE_CAN_TESTING/CAN_BASIC_TEST/CMakeLists.txt +++ b/G474xE_CAN_TESTING/CAN_BASIC_TEST/CMakeLists.txt @@ -50,7 +50,12 @@ set_target_properties( "CAN_${NAME}" ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB LOGOMATIC_OLD_LIB) +target_link_libraries( + ${PROJECT_NAME}_USER_CODE + INTERFACE + PERIPHERAL_CAN_LIB + LOGOMATIC_OLD_LIB +) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/G474xE_CAN_TESTING/CAN_FILTER_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_FILTER_TEST/CMakeLists.txt index cb4d9f904..e3c0515e4 100644 --- a/G474xE_CAN_TESTING/CAN_FILTER_TEST/CMakeLists.txt +++ b/G474xE_CAN_TESTING/CAN_FILTER_TEST/CMakeLists.txt @@ -43,7 +43,12 @@ target_sources( ../Core/Src/usart.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB LOGOMATIC_OLD_LIB) +target_link_libraries( + ${PROJECT_NAME}_USER_CODE + INTERFACE + PERIPHERAL_CAN_LIB + LOGOMATIC_OLD_LIB +) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/CMakeLists.txt index b350d6f82..c1a4f180b 100644 --- a/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/CMakeLists.txt +++ b/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/CMakeLists.txt @@ -50,7 +50,12 @@ set_target_properties( "CAN_${NAME}" ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB LOGOMATIC_OLD_LIB) +target_link_libraries( + ${PROJECT_NAME}_USER_CODE + INTERFACE + PERIPHERAL_CAN_LIB + LOGOMATIC_OLD_LIB +) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/CMakeLists.txt index cb4d9f904..e3c0515e4 100644 --- a/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/CMakeLists.txt +++ b/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/CMakeLists.txt @@ -43,7 +43,12 @@ target_sources( ../Core/Src/usart.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB LOGOMATIC_OLD_LIB) +target_link_libraries( + ${PROJECT_NAME}_USER_CODE + INTERFACE + PERIPHERAL_CAN_LIB + LOGOMATIC_OLD_LIB +) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/G474xE_CAN_TESTING/CAN_RELEASE_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_RELEASE_TEST/CMakeLists.txt index b350d6f82..c1a4f180b 100644 --- a/G474xE_CAN_TESTING/CAN_RELEASE_TEST/CMakeLists.txt +++ b/G474xE_CAN_TESTING/CAN_RELEASE_TEST/CMakeLists.txt @@ -50,7 +50,12 @@ set_target_properties( "CAN_${NAME}" ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB LOGOMATIC_OLD_LIB) +target_link_libraries( + ${PROJECT_NAME}_USER_CODE + INTERFACE + PERIPHERAL_CAN_LIB + LOGOMATIC_OLD_LIB +) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/G474xE_CAN_TESTING/CAN_STRESS_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_STRESS_TEST/CMakeLists.txt index cb4d9f904..e3c0515e4 100644 --- a/G474xE_CAN_TESTING/CAN_STRESS_TEST/CMakeLists.txt +++ b/G474xE_CAN_TESTING/CAN_STRESS_TEST/CMakeLists.txt @@ -43,7 +43,12 @@ target_sources( ../Core/Src/usart.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB LOGOMATIC_OLD_LIB) +target_link_libraries( + ${PROJECT_NAME}_USER_CODE + INTERFACE + PERIPHERAL_CAN_LIB + LOGOMATIC_OLD_LIB +) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/G474xE_CAN_TESTING/PROFILER_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/PROFILER_TEST/CMakeLists.txt index cb4d9f904..e3c0515e4 100644 --- a/G474xE_CAN_TESTING/PROFILER_TEST/CMakeLists.txt +++ b/G474xE_CAN_TESTING/PROFILER_TEST/CMakeLists.txt @@ -43,7 +43,12 @@ target_sources( ../Core/Src/usart.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE PERIPHERAL_CAN_LIB LOGOMATIC_OLD_LIB) +target_link_libraries( + ${PROJECT_NAME}_USER_CODE + INTERFACE + PERIPHERAL_CAN_LIB + LOGOMATIC_OLD_LIB +) target_include_directories( ${PROJECT_NAME}_USER_CODE diff --git a/G4ADCTESTING/CMakeLists.txt b/G4ADCTESTING/CMakeLists.txt index 17f218644..64f36cea2 100644 --- a/G4ADCTESTING/CMakeLists.txt +++ b/G4ADCTESTING/CMakeLists.txt @@ -43,6 +43,11 @@ target_sources( Core/Src/usart.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE GR_ADC LOGOMATIC_OLD_LIB) +target_link_libraries( + ${PROJECT_NAME}_USER_CODE + INTERFACE + GR_ADC + LOGOMATIC_OLD_LIB +) target_include_directories(${PROJECT_NAME}_USER_CODE INTERFACE Core/Inc) diff --git a/G4FANCYCANTESTING/CAN_LOOPBACK_TEST/CMakeLists.txt b/G4FANCYCANTESTING/CAN_LOOPBACK_TEST/CMakeLists.txt index affdc3b64..c7ecb6fa4 100644 --- a/G4FANCYCANTESTING/CAN_LOOPBACK_TEST/CMakeLists.txt +++ b/G4FANCYCANTESTING/CAN_LOOPBACK_TEST/CMakeLists.txt @@ -51,6 +51,11 @@ set_target_properties( "CAN_${NAME}" ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE GRCAN_FANCYLAYER LOGOMATIC_OLD_LIB) +target_link_libraries( + ${PROJECT_NAME}_USER_CODE + INTERFACE + GRCAN_FANCYLAYER + LOGOMATIC_OLD_LIB +) target_include_directories(${PROJECT_NAME}_USER_CODE INTERFACE ../Core/Inc) diff --git a/G4NEOTESTING/CMakeLists.txt b/G4NEOTESTING/CMakeLists.txt index dba0d0e1d..e01d41704 100644 --- a/G4NEOTESTING/CMakeLists.txt +++ b/G4NEOTESTING/CMakeLists.txt @@ -34,6 +34,11 @@ target_sources( Core/Src/stm32g4xx_it.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE GR_NEOPIXEL LOGOMATIC_OLD_LIB) +target_link_libraries( + ${PROJECT_NAME}_USER_CODE + INTERFACE + GR_NEOPIXEL + LOGOMATIC_OLD_LIB +) target_include_directories(${PROJECT_NAME}_USER_CODE INTERFACE Core/Inc) diff --git a/G4SPITESTING/CMakeLists.txt b/G4SPITESTING/CMakeLists.txt index 5e1f4547f..20c0a6194 100644 --- a/G4SPITESTING/CMakeLists.txt +++ b/G4SPITESTING/CMakeLists.txt @@ -34,6 +34,11 @@ target_sources( Core/Src/stm32g4xx_it.c ) -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE SPI_Lib LOGOMATIC_OLD_LIB) +target_link_libraries( + ${PROJECT_NAME}_USER_CODE + INTERFACE + SPI_Lib + LOGOMATIC_OLD_LIB +) target_include_directories(${PROJECT_NAME}_USER_CODE INTERFACE Core/Inc) diff --git a/Lib/Utils/Logomatic/log.cmake b/Lib/Utils/Logomatic/log.cmake index 7d3ee053a..a9562f2a6 100644 --- a/Lib/Utils/Logomatic/log.cmake +++ b/Lib/Utils/Logomatic/log.cmake @@ -26,17 +26,14 @@ endif() if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") add_executable(logomatic) - target_sources( + target_sources(logomatic PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Test/print.c) + target_include_directories(logomatic PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Test) + target_link_libraries( logomatic PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/Test/print.c + LOGOMATIC_LIB + GLOBALSHARE_LIB ) - target_include_directories( - logomatic - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/Test - ) - target_link_libraries(logomatic PRIVATE LOGOMATIC_LIB GLOBALSHARE_LIB) add_test(logomatic_test logomatic) else() target_compile_options( From 2bf7c160dd93f7b130cb54e366664dc4414a5a31 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2026 10:34:13 +0000 Subject: [PATCH 082/125] Automatic Clang-Format: Standardized formatting automatically --- CUBEMXTESTING/Core/Inc/fdcan.h | 1 - CUBEMXTESTING/Core/Inc/gpio.h | 1 - CUBEMXTESTING/Core/Inc/main.h | 13 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 215 ++++---- CUBEMXTESTING/Core/Inc/tim.h | 1 - CUBEMXTESTING/Core/Src/fdcan.c | 525 +++++++++--------- CUBEMXTESTING/Core/Src/gpio.c | 561 ++++++++++---------- CUBEMXTESTING/Core/Src/main.c | 163 +++--- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 24 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 197 ++++--- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- Lib/Utils/Logomatic/Src/log_config.c | 4 +- 12 files changed, 890 insertions(+), 928 deletions(-) diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 21271cf64..3597c6476 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -55,4 +55,3 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 03c2faca5..37dcc0a5c 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -46,4 +46,3 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index 2b50abc31..cbeced83f 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,17 +28,16 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" - -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_system.h" -#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_utils.h" -#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_crs.h" #include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_gpio.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_rcc.h" +#include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_utils.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index 92ba77d88..aa097ab4c 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED - /*#define HAL_ADC_MODULE_ENABLED */ +/*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -76,123 +76,124 @@ /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined(HSE_STARTUP_TIMEOUT) +#define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined (HSI48_VALUE) - #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined(HSI48_VALUE) +#define HSI48_VALUE \ + (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined(LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined (LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined(LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined (LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined(LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined (EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined(EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ - #define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +#define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -201,12 +202,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -357,15 +358,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index b90657cf4..2d20bd560 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,4 +49,3 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ - diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 08b2a1b8a..30b3c9dc1 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,298 +32,281 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ - + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ - + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ - + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) { - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index e2ffb942c..48af4489a 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -33,290 +33,289 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) -*/ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) + */ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 4815d76e2..93100e131 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,9 +18,10 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" + #include "fdcan.h" -#include "tim.h" #include "gpio.h" +#include "tim.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -74,39 +75,39 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + /* USER CODE BEGIN 2 */ CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config dataCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_DATA, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config chargerCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_CHARGER, .sending_node_id = GRCAN_Debugger}; @@ -130,67 +131,59 @@ int main(void) } LOGOMATIC_INFO("Hello World!\n"); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); HAL_Delay(100); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) - { - } - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while(LL_RCC_HSI_IsReady() != 1) - { - } - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while(LL_RCC_PLL_IsReady() != 1) - { - } - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) - { - } - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i !=0; i--); - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) - { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while (LL_RCC_HSI_IsReady() != 1) {} + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while (LL_RCC_PLL_IsReady() != 1) {} + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i != 0; i--) + ; + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -209,29 +202,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ LOGOMATIC_CRITICAL("Assert failed! File %s on line %" PRIu32 "\n", file, line); - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index 2cc7d8296..4668755ab 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index 78d6b9cd9..fd2ad329f 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,8 +18,9 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "main.h" #include "stm32g4xx_it.h" + +#include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -67,129 +68,125 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -200,59 +197,59 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index aa26dcf71..e77341bf2 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,83 +30,76 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 1599; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 49; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) - { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) - { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 1599; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 49; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ - + /* USER CODE END TIM5_Init 2 */ } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/Lib/Utils/Logomatic/Src/log_config.c b/Lib/Utils/Logomatic/Src/log_config.c index 435fb3357..cc06d6385 100644 --- a/Lib/Utils/Logomatic/Src/log_config.c +++ b/Lib/Utils/Logomatic/Src/log_config.c @@ -21,8 +21,8 @@ bool Logomatic_SetLogLevel(Logomatic_LogLevel level) { #define X(name, val, string) \ if (level == val) { \ - _logomatic_loglevel = level; \ - return true; \ + _logomatic_loglevel = level; \ + return true; \ } _LOGOMATIC_LOGLEVEL_X_LIST #undef X From afb8eba25e3456718d94874040b592cce58d8b0e Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 03:35:58 -0700 Subject: [PATCH 083/125] Make sure to wait as needed Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/Src/log_driver.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Lib/Utils/Logomatic/Src/log_driver.c b/Lib/Utils/Logomatic/Src/log_driver.c index 80cfc6b3d..c7e8d64d6 100644 --- a/Lib/Utils/Logomatic/Src/log_driver.c +++ b/Lib/Utils/Logomatic/Src/log_driver.c @@ -22,13 +22,16 @@ int Logomatic_Driver_ITM(int ch) int Logomatic_Private_UART(USART_TypeDef *uart, int ch) { #if defined(USART_ISR_TXE_TXFNF) - while (!(uart->ISR & USART_ISR_TXE_TXFNF)) {} + while (!(uart->ISR & USART_ISR_TXE_TXFNF)) { /* Wait*/ + } uart->TDR = (uint8_t)ch; #elif defined(USART_ISR_TXE) - while (!(uart->ISR & USART_ISR_TXE)) {} + while (!(uart->ISR & USART_ISR_TXE)) { /* Wait */ + } uart->TDR = (uint8_t)ch; #else - while (!(uart->SR & USART_SR_TXE)) {} + while (!(uart->SR & USART_SR_TXE)) { /* Wait */ + } uart->DR = (uint8_t)ch; #endif return ch; From 0d689a2f6e1fd227c61014260010a2b0a7dbdd8e Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 03:36:09 -0700 Subject: [PATCH 084/125] Missing space Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/Src/log_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/Utils/Logomatic/Src/log_driver.c b/Lib/Utils/Logomatic/Src/log_driver.c index c7e8d64d6..607672de5 100644 --- a/Lib/Utils/Logomatic/Src/log_driver.c +++ b/Lib/Utils/Logomatic/Src/log_driver.c @@ -22,7 +22,7 @@ int Logomatic_Driver_ITM(int ch) int Logomatic_Private_UART(USART_TypeDef *uart, int ch) { #if defined(USART_ISR_TXE_TXFNF) - while (!(uart->ISR & USART_ISR_TXE_TXFNF)) { /* Wait*/ + while (!(uart->ISR & USART_ISR_TXE_TXFNF)) { /* Wait */ } uart->TDR = (uint8_t)ch; #elif defined(USART_ISR_TXE) From 06d576dde6d899c948c15bcaec703f1b819294e1 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 03:39:04 -0700 Subject: [PATCH 085/125] Rename to handle for clarity Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/Src/log_driver.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Lib/Utils/Logomatic/Src/log_driver.c b/Lib/Utils/Logomatic/Src/log_driver.c index 607672de5..4efc2ac8a 100644 --- a/Lib/Utils/Logomatic/Src/log_driver.c +++ b/Lib/Utils/Logomatic/Src/log_driver.c @@ -19,20 +19,20 @@ int Logomatic_Driver_ITM(int ch) #if defined(LPUART1) || defined(LPUART2) || defined(LPUART3) || defined(USART1) || defined(USART2) || defined(USART3) || defined(USART4) || defined(USART5) || defined(USART6) || defined(USART7) || \ defined(USART8) || defined(UART1) || defined(UART2) || defined(UART3) || defined(UART4) || defined(UART5) || defined(UART6) || defined(UART7) || defined(UART8) -int Logomatic_Private_UART(USART_TypeDef *uart, int ch) +int Logomatic_Private_UART(USART_TypeDef *handle, int ch) { #if defined(USART_ISR_TXE_TXFNF) - while (!(uart->ISR & USART_ISR_TXE_TXFNF)) { /* Wait */ + while (!(handle->ISR & USART_ISR_TXE_TXFNF)) { /* Wait */ } - uart->TDR = (uint8_t)ch; + handle->TDR = (uint8_t)ch; #elif defined(USART_ISR_TXE) - while (!(uart->ISR & USART_ISR_TXE)) { /* Wait */ + while (!(handle->ISR & USART_ISR_TXE)) { /* Wait */ } - uart->TDR = (uint8_t)ch; + handle->TDR = (uint8_t)ch; #else - while (!(uart->SR & USART_SR_TXE)) { /* Wait */ + while (!(handle->SR & USART_SR_TXE)) { /* Wait */ } - uart->DR = (uint8_t)ch; + handle->DR = (uint8_t)ch; #endif return ch; } From 2a3b422471e8cc3f8936296f61c0133408b29bef Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 03:49:51 -0700 Subject: [PATCH 086/125] Forgot to include `stdbool.h` Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/Inc/Logomatic.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/Utils/Logomatic/Inc/Logomatic.h b/Lib/Utils/Logomatic/Inc/Logomatic.h index 5e4df50c8..09de8cc29 100644 --- a/Lib/Utils/Logomatic/Inc/Logomatic.h +++ b/Lib/Utils/Logomatic/Inc/Logomatic.h @@ -1,3 +1,4 @@ +#include #include #include "main.h" From 5a3ae0b566d89d60fb1354b55eebe15ea27a4cb1 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 05:07:28 -0700 Subject: [PATCH 087/125] Documentation fixes Signed-off-by: Daniel Hansen --- Lib/GlobalShare/README.md | 13 ++-- Lib/Peripherals/CubeCAN/README.md | 4 +- Lib/Utils/Logomatic/Inc/Logomatic.h | 30 ++++---- Lib/Utils/Logomatic/README.md | 111 +++++++++++++++++++++++++++ Lib/Utils/Logomatic/Src/log_config.c | 15 +++- Lib/Utils/Logomatic/Test/print.c | 10 ++- Lib/Utils/Logomatic/log.cmake | 2 + 7 files changed, 155 insertions(+), 30 deletions(-) diff --git a/Lib/GlobalShare/README.md b/Lib/GlobalShare/README.md index 9d3505f87..6750bbc43 100644 --- a/Lib/GlobalShare/README.md +++ b/Lib/GlobalShare/README.md @@ -6,7 +6,7 @@ This directory contains shared definitions and interfaces used across multiple p Please do not add source files to this directory, this is intended for only header files. -**Important**: All files in this directory are **manually maintained and hand-written**. Nothing here is auto-generated. For auto-generated files please see [Autogen](../../Autogen/). +**Important**: All files in this directory are **manually maintained and hand-written**. Nothing here is auto-generated. For auto-generated files please see [Autogen](/Autogen). Please ensure everything is clearly doc-commented and a markdown section is present for each file as relevant. @@ -21,7 +21,7 @@ When adding new shared types or constants: ## State Machine -This is an enum corresponding to [`STATE_MACHINE.md`](../../STATE_MACHINE.md) exactly, no change should be made to this enum without modifying the state machine diagram and vice versa. +This is an enum corresponding to [`STATE_MACHINE.md`](/STATE_MACHINE.md) exactly, no change should be made to this enum without modifying the state machine diagram and vice versa. It is critical that every board runs the same version of this enum so as to have correct state machine numerical definitions. @@ -40,15 +40,16 @@ No warnings: ```c { - int thing = 42; - UNUSED(thing); + int thing = 42; + UNUSED(thing); } ``` Will have a warning that will become promoted to an error for release builds: + ```c { - int thing = 42; + int thing = 42; } ``` @@ -58,7 +59,7 @@ This macro converts the name of any type or variable into the corresponding quot This is helpful for cases where you need the explicit name of a variable -### Example +### String Example ```c int input = 42; diff --git a/Lib/Peripherals/CubeCAN/README.md b/Lib/Peripherals/CubeCAN/README.md index 0e11299df..814265ee8 100644 --- a/Lib/Peripherals/CubeCAN/README.md +++ b/Lib/Peripherals/CubeCAN/README.md @@ -1,6 +1,6 @@ # Cube CAN -Support for STM32CubeMX and CAN. See [`CUBEMX.md`](../../../CUBEMX.md) for background. +Support for STM32CubeMX and CAN. See [`CUBEMX.md`](/CUBEMX.md) for background. ## Summary @@ -47,7 +47,7 @@ Make sure to `#include "CubeCAN.h"` where needed. Do not include `PrivateInc/int At the end of your STM32CubeMX-generated `MX_FDCAN#_Init()` function, configure your filters as needed with `HAL_FDCAN_ConfigFilter()`. It is recommended to setup a filter to ignore messages not intended for your board. -Within `main` after `MX_FDCAN#_Init()` and Logomatic are setup (see [Logomatic](../../Utils/Logomatic/README.md)), call `CubeCAN_Entrance()` saving the handle for global use later (one entrance and handle per peripheral). +Within `main` after `MX_FDCAN#_Init()` and Logomatic are setup (see [Logomatic](/Lib/Utils/Logomatic/README.md)), call `CubeCAN_Entrance()` saving the handle for global use later (one entrance and handle per peripheral). Ensure you have setup some mechanism to call `CubeCAN_Tick()` frequently (a STM32CubeMX timer interrupt is recommended). This function: diff --git a/Lib/Utils/Logomatic/Inc/Logomatic.h b/Lib/Utils/Logomatic/Inc/Logomatic.h index 09de8cc29..9fa978044 100644 --- a/Lib/Utils/Logomatic/Inc/Logomatic.h +++ b/Lib/Utils/Logomatic/Inc/Logomatic.h @@ -7,18 +7,18 @@ #define LOGOMATIC_H /// @brief Logomatic log level type, used to define the severity of log messages -#define _LOGOMATIC_LOGLEVEL_X_LIST \ - X(LogLevel_Off, 0, "OFF") \ - X(LogLevel_Critical, 1, "CRITICAL") \ - X(LogLevel_Error, 2, "ERROR") \ - X(LogLevel_Warning, 3, "WARNING") \ - X(LogLevel_Info, 4, "INFO") \ - X(LogLevel_Debug, 5, "DEBUG") \ +#define _LOGOMATIC_LOGLEVEL_PRIVATE_LIST \ + X(LogLevel_Off, 0, "OFF") \ + X(LogLevel_Critical, 1, "CRITICAL") \ + X(LogLevel_Error, 2, "ERROR") \ + X(LogLevel_Warning, 3, "WARNING") \ + X(LogLevel_Info, 4, "INFO") \ + X(LogLevel_Debug, 5, "DEBUG") \ X(LogLevel_Verbose, 6, "VERBOSE") typedef enum { #define X(name, val, str) name = val, - _LOGOMATIC_LOGLEVEL_X_LIST + _LOGOMATIC_LOGLEVEL_PRIVATE_LIST #undef X } Logomatic_LogLevel; @@ -76,7 +76,7 @@ extern const Logomatic_Driver global_logomatic_driver; * @param level The log level of the message * @param ... The log message format and arguments */ -#define LOGOMATIC_PRIVATE_LEVEL(level, ...) \ +#define _LOGOMATIC_PRIVATE_LOG(level, ...) \ do { \ if (_logomatic_loglevel >= (level) && (level) != LogLevel_Off && _logomatic_loglevel != LogLevel_Off) { \ if (level == LogLevel_Verbose) { \ @@ -91,12 +91,12 @@ extern const Logomatic_Driver global_logomatic_driver; #if defined(LOGOMATIC_ENABLED) -#define LOGOMATIC_CRITICAL(...) LOGOMATIC_PRIVATE_LEVEL(LogLevel_Critical, __VA_ARGS__) -#define LOGOMATIC_ERROR(...) LOGOMATIC_PRIVATE_LEVEL(LogLevel_Error, __VA_ARGS__) -#define LOGOMATIC_WARNING(...) LOGOMATIC_PRIVATE_LEVEL(LogLevel_Warning, __VA_ARGS__) -#define LOGOMATIC_INFO(...) LOGOMATIC_PRIVATE_LEVEL(LogLevel_Info, __VA_ARGS__) -#define LOGOMATIC_DEBUG(...) LOGOMATIC_PRIVATE_LEVEL(LogLevel_Debug, __VA_ARGS__) -#define LOGOMATIC_VERBOSE(...) LOGOMATIC_PRIVATE_LEVEL(LogLevel_Verbose, __VA_ARGS__) +#define LOGOMATIC_CRITICAL(...) _LOGOMATIC_PRIVATE_LOG(LogLevel_Critical, __VA_ARGS__) +#define LOGOMATIC_ERROR(...) _LOGOMATIC_PRIVATE_LOG(LogLevel_Error, __VA_ARGS__) +#define LOGOMATIC_WARNING(...) _LOGOMATIC_PRIVATE_LOG(LogLevel_Warning, __VA_ARGS__) +#define LOGOMATIC_INFO(...) _LOGOMATIC_PRIVATE_LOG(LogLevel_Info, __VA_ARGS__) +#define LOGOMATIC_DEBUG(...) _LOGOMATIC_PRIVATE_LOG(LogLevel_Debug, __VA_ARGS__) +#define LOGOMATIC_VERBOSE(...) _LOGOMATIC_PRIVATE_LOG(LogLevel_Verbose, __VA_ARGS__) #else diff --git a/Lib/Utils/Logomatic/README.md b/Lib/Utils/Logomatic/README.md index e69de29bb..b00d986b3 100644 --- a/Lib/Utils/Logomatic/README.md +++ b/Lib/Utils/Logomatic/README.md @@ -0,0 +1,111 @@ +# Logomatic + +## Quick Start + +In STM32CubeMX configure `SYS` Debug to be "Trace Asynchronous Sw". Other settings will require you to set `TPI` settings as needed. + +By default logomatic will use ITM with your clock-configured baud rate on port 0. You can configure this trivially if you want. + +1. Link against `LOGOMATIC_LIB` as another library in your CMake project +2. Add `#include "Logomatic.h"` to your files and add calls to `LOGOMATIC_()` as appopriate +3. Call `Logomatic_SetLogLevel()` to configure your global verbosity logging level +4. Add the `swoConfig` key to your [`launch.json](/.vscode/launch.json) entry for your project, see the default below + +> ```json +> "swoConfig": { +> "enabled": true, +> "cpuFrequency": 160000000, +> "swoFrequency": 115, +> "source": "probe", +> "decoders": [ +> { +> "type": "console", +> "label": "ITM", +> "showOnStartup": true, +> "port": 0, +> "encoding": "ascii" +> } +> ] +> } +> ``` + +## Drivers + +You may configure any LPUART, UART, or USART to serve as your dedicated channel as well (almost) out of the box. + +To do that, you must define a strong symbol for `global_logomatic_driver` setting it to your own function, defaults are provided in the form `Logomatic_Driver_`. + +You can setup your own as well. Any you setup should have the same function signature and should + +- On success return the written character +- On failure return `EOF` +- Be very quick, as logomatic is often used inside ISRs for debugging + +## Log Levels + +Logs are defined in a X-Macro list `_LOGOMATIC_LOGLEVEL_X_LIST` where a higher number means more output + +| Status | Level | Description | +| --- | --- | --- | +| :zipper_mouth_face: | Off | Nothing will be printed, less performant than using `CMAKE_LOGOMATIC_ENABLED` | +| :rotating_light: | Critical | An important operation is failing and the car will not behave correctly | +| :x: | Error | An operation is failing but the car as a whole may be able to recover on its own | +| :warning: | Warning | An operation is not proceeding as expected but may recover on its own | +| :bell: | Info | An operation updates the status of the car, but nothing bad has happened | +| :bug: | Debug | An operation would like to report diagnostics that may be helpful | +| :loudspeaker: | Verbose | An operation has generated information and later inspection of the logs could be helpful, spammy | + +## Advanced + +It is strongly suggested to use ITM and the default settings, it will compile out fully on release builds with no overhead. + +### CMake + +Logomatic is exposed to others as an interface library called `LOGOMATIC_LIB`. From here you can include `Logomatic.h` which will automagically try and find a working peripheral to attach to. + +The CMake file for the library is [`log.cmake`](log.cmake) and uses the symbol `CMAKE_LOGOMATIC_ENABLED` to allow [`CMakePresets.json`](/CMakePresets.json) to enable or disable logging based on if the build is a debug or release build. If it is enabled then we add the compiler definition `LOGOMATIC_ENABLED`. + +By default, we also enable printing floats which adds significant memory and CPU overhead. It is strongly recommend to never print raw floating point values. + +If we are building for testing then [`CMakePresets.json`](/CMakePresets.json) ensures that logomatic is enabled and we attempt to signal the library to default to a verbose log level, see [log levels](#log-levels) + +### Macros + +#### Log Levels X-Macro + +See [log levels](#log-levels) for more. + +We define `_LOGOMATIC_LOGLEVEL_PRIVATE_LIST` which consists of [X-Macros](https://wikipedia.org/wiki/X_macro) for the enum name, value, and text label. It is recommended to understand the nuances of the X-Macro pattern before continuing reading. + +We define `X` operations to translate that list into different forms, namely an enum, an array for value to text lookups, and type checking on the enum. + +It is required that more verbose log levels have a higher value than less verbose log levels. + +#### Logging Macros + +We provide macros, manually made, for each log level to simplify calling. These are in the form `LOGOMATIC_` and they take a single format string to print (exactly `printf`). + +These macros are variants of `_LOGOMATIC_PRIVATE_LOG()` which does runtime checks of the configured global log level against the requested log level, only printing if it is equal or higher. +This function also prints the log level in front of them, verbose logs also get the file and line number it was invoked on for easier debugging. + +As we have warnings for double promotion, since STM32 chips support FPU-accelerated operations only for 32-bit floats, we also have to push and pop a diagnostic to ignore that warning for that specific line. + +If logomatic is not enabled then each of the user-callable macros compiles to nothing, while not changing the used/unused status of the variables and not affecting the vardic variable. + +### Color Codes + +If you really want to, you can print colors using ANSI color codes. Be aware that this will tank performance with lots of unneeded data and is not supported. + +We also ask that you do not use color codes because different setups on different computers may behave differently. + +### HOOTL Testing + +Calls to logomatic functions inside of HOOTLTest configurations will work as you expect, following the same logging level filter. + +Note that by default the logging level for embedded is informational, but for HOOTL testing it defaults to verbose and calls to change the logging level are ignored by default. + +## Troubleshooting + +TODO + +As issues are found we will extend this section. For now, please contact the Firmware Manager if you are unable to get this working. Be aware that specific hardware is required to use Logomatic diff --git a/Lib/Utils/Logomatic/Src/log_config.c b/Lib/Utils/Logomatic/Src/log_config.c index cc06d6385..44227b331 100644 --- a/Lib/Utils/Logomatic/Src/log_config.c +++ b/Lib/Utils/Logomatic/Src/log_config.c @@ -1,7 +1,11 @@ #include "Logomatic.h" #include "main.h" -__weak Logomatic_LogLevel _logomatic_loglevel = LogLevel_Debug; +#if defined(LOGOMATIC_HOOTLTEST) +Logomatic_LogLevel _logomatic_loglevel = LogLevel_Verbose; +#else +Logomatic_LogLevel _logomatic_loglevel = LogLevel_Debug; +#endif #if defined(ITM) __weak const Logomatic_Driver global_logomatic_driver = Logomatic_Driver_ITM; @@ -13,18 +17,23 @@ __weak const Logomatic_Driver global_logomatic_driver = NULL; const char *Logomatic_Private_LogLevelStrings[] = { #define X(name, val, str) [val] = str, - _LOGOMATIC_LOGLEVEL_X_LIST + _LOGOMATIC_LOGLEVEL_PRIVATE_LIST #undef X }; bool Logomatic_SetLogLevel(Logomatic_LogLevel level) { +#if defined(LOGOMATIC_HOOTLTEST) + _logomatic_loglevel = LogLevel_Verbose; + return true; +#endif + #define X(name, val, string) \ if (level == val) { \ _logomatic_loglevel = level; \ return true; \ } - _LOGOMATIC_LOGLEVEL_X_LIST + _LOGOMATIC_LOGLEVEL_PRIVATE_LIST #undef X return false; } diff --git a/Lib/Utils/Logomatic/Test/print.c b/Lib/Utils/Logomatic/Test/print.c index 81e80c3c7..c03196e84 100644 --- a/Lib/Utils/Logomatic/Test/print.c +++ b/Lib/Utils/Logomatic/Test/print.c @@ -39,22 +39,22 @@ bool verification(void (*print_func)(void), const char *expected_content) switch (_logomatic_loglevel) { case LogLevel_Critical: - snprintf(formatted, sizeof(formatted), expected_content, "[CRIT] "); + snprintf(formatted, sizeof(formatted), expected_content, "[CRITICAL] "); break; case LogLevel_Error: snprintf(formatted, sizeof(formatted), expected_content, "[ERROR] "); break; case LogLevel_Warning: - snprintf(formatted, sizeof(formatted), expected_content, "[WARN] "); + snprintf(formatted, sizeof(formatted), expected_content, "[WARNING] "); break; case LogLevel_Info: snprintf(formatted, sizeof(formatted), expected_content, "[INFO] "); break; case LogLevel_Debug: - snprintf(formatted, sizeof(formatted), expected_content, "[DBG] "); + snprintf(formatted, sizeof(formatted), expected_content, "[DEBUG] "); break; case LogLevel_Verbose: - snprintf(formatted, sizeof(formatted), expected_content, "[V - " __FILE_NAME__ ":117] "); + snprintf(formatted, sizeof(formatted), expected_content, "[VERBOSE - " __FILE_NAME__ ":117] "); break; default: snprintf(formatted, sizeof(formatted), expected_content, ""); @@ -156,5 +156,7 @@ int main(void) return 9; } + LOGOMATIC_INFO("Works as expected!\n"); + return 0; } diff --git a/Lib/Utils/Logomatic/log.cmake b/Lib/Utils/Logomatic/log.cmake index a9562f2a6..dfb6d99e6 100644 --- a/Lib/Utils/Logomatic/log.cmake +++ b/Lib/Utils/Logomatic/log.cmake @@ -25,6 +25,8 @@ if(CMAKE_LOGOMATIC_ENABLED) endif() if(CMAKE_PRESET_NAME STREQUAL "HOOTLTest") + target_compile_definitions(LOGOMATIC_LIB INTERFACE LOGOMATIC_HOOTLTEST) + add_executable(logomatic) target_sources(logomatic PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Test/print.c) target_include_directories(logomatic PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Test) From f23b01750f6711781fafeb3b5b1617b6977d81a5 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2026 12:08:48 +0000 Subject: [PATCH 088/125] Automatic Clang-Format: Standardized formatting automatically --- Lib/Utils/Logomatic/Inc/Logomatic.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Lib/Utils/Logomatic/Inc/Logomatic.h b/Lib/Utils/Logomatic/Inc/Logomatic.h index 9fa978044..8f43a3021 100644 --- a/Lib/Utils/Logomatic/Inc/Logomatic.h +++ b/Lib/Utils/Logomatic/Inc/Logomatic.h @@ -8,12 +8,12 @@ /// @brief Logomatic log level type, used to define the severity of log messages #define _LOGOMATIC_LOGLEVEL_PRIVATE_LIST \ - X(LogLevel_Off, 0, "OFF") \ - X(LogLevel_Critical, 1, "CRITICAL") \ - X(LogLevel_Error, 2, "ERROR") \ - X(LogLevel_Warning, 3, "WARNING") \ - X(LogLevel_Info, 4, "INFO") \ - X(LogLevel_Debug, 5, "DEBUG") \ + X(LogLevel_Off, 0, "OFF") \ + X(LogLevel_Critical, 1, "CRITICAL") \ + X(LogLevel_Error, 2, "ERROR") \ + X(LogLevel_Warning, 3, "WARNING") \ + X(LogLevel_Info, 4, "INFO") \ + X(LogLevel_Debug, 5, "DEBUG") \ X(LogLevel_Verbose, 6, "VERBOSE") typedef enum { From fd7bc92c43d1f75f342c9d657dc9d1bc82679915 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 05:12:16 -0700 Subject: [PATCH 089/125] Add CAN message doc Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/Utils/Logomatic/README.md b/Lib/Utils/Logomatic/README.md index b00d986b3..caaccfc5d 100644 --- a/Lib/Utils/Logomatic/README.md +++ b/Lib/Utils/Logomatic/README.md @@ -69,6 +69,14 @@ By default, we also enable printing floats which adds significant memory and CPU If we are building for testing then [`CMakePresets.json`](/CMakePresets.json) ensures that logomatic is enabled and we attempt to signal the library to default to a verbose log level, see [log levels](#log-levels) +### CAN Messages + +Currently we do not do anything cool with CAN specifically, but we could! + +It can also be configured as a driver (queuing to fill a packet) within this library or by providing a strong `_write()` definition (dividing a buffer into messages). + +If you would like to see this do something please open an Issue (and if you want to code it, a Pull Request as well) + ### Macros #### Log Levels X-Macro From 471457383a0a9d1815754c6a8b12f72edb873b33 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 05:43:55 -0700 Subject: [PATCH 090/125] Fix hootl testing Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/Inc/Logomatic.h | 65 ++++++---- Lib/Utils/Logomatic/README.md | 4 +- Lib/Utils/Logomatic/Test/print.c | 179 +++++++--------------------- Lib/cmake/HOOTL.cmake | 1 - 4 files changed, 87 insertions(+), 162 deletions(-) diff --git a/Lib/Utils/Logomatic/Inc/Logomatic.h b/Lib/Utils/Logomatic/Inc/Logomatic.h index 8f43a3021..33bd3489a 100644 --- a/Lib/Utils/Logomatic/Inc/Logomatic.h +++ b/Lib/Utils/Logomatic/Inc/Logomatic.h @@ -68,14 +68,42 @@ extern Logomatic_LogLevel _logomatic_loglevel; */ extern const Logomatic_Driver global_logomatic_driver; -/** - * @brief Logomatic log level implementation macro - * - * This macro is used to implement the log level functionality to give fancy names - * - * @param level The log level of the message - * @param ... The log message format and arguments - */ +#ifdef LOGOMATIC_HOOTLTEST + +#define LOGOMATIC_CRITICAL(...) \ + do { \ + printf("[CRITICAL] "); \ + printf(__VA_ARGS__); \ + } while (0) +#define LOGOMATIC_ERROR(...) \ + do { \ + printf("[ERROR] "); \ + printf(__VA_ARGS__); \ + } while (0) +#define LOGOMATIC_WARNING(...) \ + do { \ + printf("[WARNING] "); \ + printf(__VA_ARGS__); \ + } while (0) +#define LOGOMATIC_INFO(...) \ + do { \ + printf("[INFO] "); \ + printf(__VA_ARGS__); \ + } while (0) +#define LOGOMATIC_DEBUG(...) \ + do { \ + printf("[DEBUG] "); \ + printf(__VA_ARGS__); \ + } while (0) +#define LOGOMATIC_VERBOSE(...) \ + do { \ + printf("[VERBOSE - %s:%d] ", __FILE_NAME__, __LINE__); \ + printf(__VA_ARGS__); \ + } while (0) + +#else + +#if defined(LOGOMATIC_ENABLED) #define _LOGOMATIC_PRIVATE_LOG(level, ...) \ do { \ if (_logomatic_loglevel >= (level) && (level) != LogLevel_Off && _logomatic_loglevel != LogLevel_Off) { \ @@ -88,31 +116,26 @@ extern const Logomatic_Driver global_logomatic_driver; _Pragma("GCC diagnostic pop") \ } \ } while (0) - -#if defined(LOGOMATIC_ENABLED) - #define LOGOMATIC_CRITICAL(...) _LOGOMATIC_PRIVATE_LOG(LogLevel_Critical, __VA_ARGS__) #define LOGOMATIC_ERROR(...) _LOGOMATIC_PRIVATE_LOG(LogLevel_Error, __VA_ARGS__) #define LOGOMATIC_WARNING(...) _LOGOMATIC_PRIVATE_LOG(LogLevel_Warning, __VA_ARGS__) #define LOGOMATIC_INFO(...) _LOGOMATIC_PRIVATE_LOG(LogLevel_Info, __VA_ARGS__) #define LOGOMATIC_DEBUG(...) _LOGOMATIC_PRIVATE_LOG(LogLevel_Debug, __VA_ARGS__) #define LOGOMATIC_VERBOSE(...) _LOGOMATIC_PRIVATE_LOG(LogLevel_Verbose, __VA_ARGS__) - #else - -#define LOGOMATIC_OFF(...) \ +#define _LOGOMATIC_PRIVATE_LOG(...) \ do { \ if (0) { \ printf(__VA_ARGS__); \ } \ } while (0) - -#define LOGOMATIC_CRITICAL(...) LOGOMATIC_OFF(__VA_ARGS__) -#define LOGOMATIC_ERROR(...) LOGOMATIC_OFF(__VA_ARGS__) -#define LOGOMATIC_WARNING(...) LOGOMATIC_OFF(__VA_ARGS__) -#define LOGOMATIC_INFO(...) LOGOMATIC_OFF(__VA_ARGS__) -#define LOGOMATIC_DEBUG(...) LOGOMATIC_OFF(__VA_ARGS__) -#define LOGOMATIC_VERBOSE(...) LOGOMATIC_OFF(__VA_ARGS__) +#define LOGOMATIC_CRITICAL(...) _LOGOMATIC_PRIVATE_LOG(__VA_ARGS__) +#define LOGOMATIC_ERROR(...) _LOGOMATIC_PRIVATE_LOG(__VA_ARGS__) +#define LOGOMATIC_WARNING(...) _LOGOMATIC_PRIVATE_LOG(__VA_ARGS__) +#define LOGOMATIC_INFO(...) _LOGOMATIC_PRIVATE_LOG(__VA_ARGS__) +#define LOGOMATIC_DEBUG(...) _LOGOMATIC_PRIVATE_LOG(__VA_ARGS__) +#define LOGOMATIC_VERBOSE(...) _LOGOMATIC_PRIVATE_LOG(__VA_ARGS__) +#endif #endif diff --git a/Lib/Utils/Logomatic/README.md b/Lib/Utils/Logomatic/README.md index caaccfc5d..9f2e89322 100644 --- a/Lib/Utils/Logomatic/README.md +++ b/Lib/Utils/Logomatic/README.md @@ -108,9 +108,9 @@ We also ask that you do not use color codes because different setups on differen ### HOOTL Testing -Calls to logomatic functions inside of HOOTLTest configurations will work as you expect, following the same logging level filter. +Calls to logomatic functions inside of HOOTLTest configurations will work as you expect, except there is no more logging level filter. -Note that by default the logging level for embedded is informational, but for HOOTL testing it defaults to verbose and calls to change the logging level are ignored by default. +Note that by default the logging level for embedded is informational. You cannot set a logging level for HOOTL. ## Troubleshooting diff --git a/Lib/Utils/Logomatic/Test/print.c b/Lib/Utils/Logomatic/Test/print.c index c03196e84..30cfbb2d7 100644 --- a/Lib/Utils/Logomatic/Test/print.c +++ b/Lib/Utils/Logomatic/Test/print.c @@ -2,161 +2,64 @@ #include #include #include +#include -#include "ComparatorMacros.h" #include "Logomatic.h" -#include "Stringification.h" -const char *expected_output_critical = "%sThis is a critical message.\n"; -const char *expected_output_error = "%sThis is an error message.\n"; -const char *expected_output_warning = "%sThis is a warning message.\n"; -const char *expected_output_info = "%sThis is an info message.\n"; -const char *expected_output_debug = "%sThis is a debug message.\n"; -const char *expected_output_verbose = "%sThis is a verbose message.\n"; - -bool verification(void (*print_func)(void), const char *expected_content) +int main() { - char formatted[100]; - char *buffer = NULL; - size_t size = 0; - - FILE *original_stdout = stdout; - - FILE *mem_stream = open_memstream(&buffer, &size); - if (!mem_stream) { - perror("Failed to create memory stream"); - return false; + const char expected[] = "[CRITICAL] Critical log message\n" + "[ERROR] Error log message\n" + "[WARNING] Warning log message\n" + "[INFO] Informational log message\n" + "[DEBUG] Debug log message\n" + "[VERBOSE - print.c:34] Verbose log message\n"; + + int pipefd[2]; + char buffer[sizeof(expected) + 50] = {0}; + + if (pipe(pipefd) == -1) { + perror("Pipe failed"); + return 1; } - stdout = mem_stream; + int saved_stdout = dup(STDOUT_FILENO); + dup2(pipefd[1], STDOUT_FILENO); - print_func(); + LOGOMATIC_CRITICAL("Critical log message\n"); + LOGOMATIC_ERROR("Error log message\n"); + LOGOMATIC_WARNING("Warning log message\n"); + LOGOMATIC_INFO("Informational log message\n"); + LOGOMATIC_DEBUG("Debug log message\n"); + LOGOMATIC_VERBOSE("Verbose log message\n"); fflush(stdout); - fclose(mem_stream); + close(pipefd[1]); - stdout = original_stdout; + dup2(saved_stdout, STDOUT_FILENO); + close(saved_stdout); - switch (_logomatic_loglevel) { - case LogLevel_Critical: - snprintf(formatted, sizeof(formatted), expected_content, "[CRITICAL] "); - break; - case LogLevel_Error: - snprintf(formatted, sizeof(formatted), expected_content, "[ERROR] "); - break; - case LogLevel_Warning: - snprintf(formatted, sizeof(formatted), expected_content, "[WARNING] "); - break; - case LogLevel_Info: - snprintf(formatted, sizeof(formatted), expected_content, "[INFO] "); - break; - case LogLevel_Debug: - snprintf(formatted, sizeof(formatted), expected_content, "[DEBUG] "); - break; - case LogLevel_Verbose: - snprintf(formatted, sizeof(formatted), expected_content, "[VERBOSE - " __FILE_NAME__ ":117] "); - break; - default: - snprintf(formatted, sizeof(formatted), expected_content, ""); - break; + ssize_t bytes_read = read(pipefd[0], buffer, sizeof(buffer) - 1); + if (bytes_read >= 0) { + buffer[bytes_read] = '\0'; } + close(pipefd[0]); - bool match = strncmp(buffer, formatted, MIN_WITH_TYPES(size, strlen(formatted))) == 0; - - if (!match) { - printf("Mismatch detected.\n"); - printf(" Expected: \"%s\"\n", formatted); - printf(" Captured: \"%s\"\n", buffer); + if (strcmp(buffer, expected) == 0) { + printf("Test passed: Log output matches expected output.\n"); } else { - printf("Output matches expected content for level %d with %s", _logomatic_loglevel, formatted); - } - - free(buffer); - - return match; -} - -void print_all(void) -{ - - LOGOMATIC_CRITICAL(expected_output_critical); - LOGOMATIC_ERROR(expected_output_error); - LOGOMATIC_WARNING(expected_output_warning); - LOGOMATIC_INFO(expected_output_info); - LOGOMATIC_DEBUG(expected_output_debug); - LOGOMATIC_VERBOSE(expected_output_verbose); -} - -void printf_critical(void) -{ - LOGOMATIC_CRITICAL(expected_output_critical, ""); -} - -void printf_error(void) -{ - LOGOMATIC_ERROR(expected_output_error, ""); -} - -void printf_warning(void) -{ - LOGOMATIC_WARNING(expected_output_warning, ""); -} - -void printf_info(void) -{ - LOGOMATIC_INFO(expected_output_info, ""); -} - -void printf_debug(void) -{ - LOGOMATIC_DEBUG(expected_output_debug, ""); -} - -void printf_verbose(void) -{ - LOGOMATIC_VERBOSE(expected_output_verbose, ""); -} - -int main(void) -{ - _logomatic_loglevel = LogLevel_Off; - if (!verification(print_all, "")) { + printf("Test failed: Log output does not match expected output.\n"); + printf("\nExpected:\n%s", expected); + printf("\nGot:\n%s", buffer); return 1; } - _logomatic_loglevel = LogLevel_Critical; - if (!verification(printf_critical, expected_output_critical)) { - return 2; - } - _logomatic_loglevel = LogLevel_Error; - if (!verification(printf_critical, "")) { - return 3; - } - _logomatic_loglevel = LogLevel_Error; - if (!verification(printf_error, expected_output_error)) { - return 4; - } - _logomatic_loglevel = LogLevel_Warning; - if (!verification(printf_warning, expected_output_warning)) { - return 5; - } - _logomatic_loglevel = LogLevel_Info; - if (!verification(printf_info, expected_output_info)) { - return 6; - } - _logomatic_loglevel = LogLevel_Info; - if (!verification(printf_debug, "")) { - return 7; - } - _logomatic_loglevel = LogLevel_Debug; - if (!verification(printf_debug, expected_output_debug)) { - return 8; - } - _logomatic_loglevel = LogLevel_Verbose; - if (!verification(printf_verbose, expected_output_verbose)) { - return 9; - } - LOGOMATIC_INFO("Works as expected!\n"); + LOGOMATIC_CRITICAL("Critical log message again\n"); + LOGOMATIC_ERROR("Error log message again\n"); + LOGOMATIC_WARNING("Warning log message again\n"); + LOGOMATIC_INFO("Informational log message again\n"); + LOGOMATIC_DEBUG("Debug log message again\n"); + LOGOMATIC_VERBOSE("Verbose log message again\n"); return 0; } diff --git a/Lib/cmake/HOOTL.cmake b/Lib/cmake/HOOTL.cmake index 5689d4ce9..bd3858b2a 100644 --- a/Lib/cmake/HOOTL.cmake +++ b/Lib/cmake/HOOTL.cmake @@ -27,7 +27,6 @@ add_compile_options( -Werror -Wpedantic -Wvla - -Wdouble-promotion -g -DHOOTL_TEST ) From 0fcaebfd8d7832a4f80154e9bcc526c9b5fd9071 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2026 12:45:03 +0000 Subject: [PATCH 091/125] Automatic Clang-Format: Standardized formatting automatically --- Lib/Utils/Logomatic/Inc/Logomatic.h | 4 ++-- Lib/Utils/Logomatic/Test/print.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Lib/Utils/Logomatic/Inc/Logomatic.h b/Lib/Utils/Logomatic/Inc/Logomatic.h index 33bd3489a..e73795664 100644 --- a/Lib/Utils/Logomatic/Inc/Logomatic.h +++ b/Lib/Utils/Logomatic/Inc/Logomatic.h @@ -97,7 +97,7 @@ extern const Logomatic_Driver global_logomatic_driver; } while (0) #define LOGOMATIC_VERBOSE(...) \ do { \ - printf("[VERBOSE - %s:%d] ", __FILE_NAME__, __LINE__); \ + printf("[VERBOSE - %s:%d] ", __FILE_NAME__, __LINE__); \ printf(__VA_ARGS__); \ } while (0) @@ -123,7 +123,7 @@ extern const Logomatic_Driver global_logomatic_driver; #define LOGOMATIC_DEBUG(...) _LOGOMATIC_PRIVATE_LOG(LogLevel_Debug, __VA_ARGS__) #define LOGOMATIC_VERBOSE(...) _LOGOMATIC_PRIVATE_LOG(LogLevel_Verbose, __VA_ARGS__) #else -#define _LOGOMATIC_PRIVATE_LOG(...) \ +#define _LOGOMATIC_PRIVATE_LOG(...) \ do { \ if (0) { \ printf(__VA_ARGS__); \ diff --git a/Lib/Utils/Logomatic/Test/print.c b/Lib/Utils/Logomatic/Test/print.c index 30cfbb2d7..8493f42bc 100644 --- a/Lib/Utils/Logomatic/Test/print.c +++ b/Lib/Utils/Logomatic/Test/print.c @@ -9,11 +9,11 @@ int main() { const char expected[] = "[CRITICAL] Critical log message\n" - "[ERROR] Error log message\n" - "[WARNING] Warning log message\n" - "[INFO] Informational log message\n" - "[DEBUG] Debug log message\n" - "[VERBOSE - print.c:34] Verbose log message\n"; + "[ERROR] Error log message\n" + "[WARNING] Warning log message\n" + "[INFO] Informational log message\n" + "[DEBUG] Debug log message\n" + "[VERBOSE - print.c:34] Verbose log message\n"; int pipefd[2]; char buffer[sizeof(expected) + 50] = {0}; From c10b5a57b3e79c26e23350ad6e224de2a9fd9048 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 05:52:53 -0700 Subject: [PATCH 092/125] MacOS already defines `__weak`, adds a check before defining `__weak` Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/Test/main.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/Utils/Logomatic/Test/main.h b/Lib/Utils/Logomatic/Test/main.h index 2d58e80e5..76d64ed3d 100644 --- a/Lib/Utils/Logomatic/Test/main.h +++ b/Lib/Utils/Logomatic/Test/main.h @@ -1,6 +1,8 @@ #ifndef MAIN_H #define MAIN_H +#ifndef __weak #define __weak __attribute__((weak)) +#endif #endif From 03b16ead78ba4c7556e1dc0a1dd23601dd8b093a Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 06:01:37 -0700 Subject: [PATCH 093/125] Fix more MacOS gotchas, namely weak extern symbols and strict prototypes Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/Inc/Logomatic.h | 2 +- Lib/Utils/Logomatic/Test/print.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/Utils/Logomatic/Inc/Logomatic.h b/Lib/Utils/Logomatic/Inc/Logomatic.h index e73795664..e2a8d3e8a 100644 --- a/Lib/Utils/Logomatic/Inc/Logomatic.h +++ b/Lib/Utils/Logomatic/Inc/Logomatic.h @@ -66,7 +66,7 @@ extern Logomatic_LogLevel _logomatic_loglevel; * * @note This variable should not be modified once setup by the user. */ -extern const Logomatic_Driver global_logomatic_driver; +extern const __weak Logomatic_Driver global_logomatic_driver; #ifdef LOGOMATIC_HOOTLTEST diff --git a/Lib/Utils/Logomatic/Test/print.c b/Lib/Utils/Logomatic/Test/print.c index 8493f42bc..563704f8a 100644 --- a/Lib/Utils/Logomatic/Test/print.c +++ b/Lib/Utils/Logomatic/Test/print.c @@ -6,7 +6,7 @@ #include "Logomatic.h" -int main() +int main(void) { const char expected[] = "[CRITICAL] Critical log message\n" "[ERROR] Error log message\n" From f812e3218ac97b0948b505799760ec6fcd52eb0e Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 06:25:29 -0700 Subject: [PATCH 094/125] Try windows again after POSIX work arounds Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/Test/print.c | 46 ++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/Lib/Utils/Logomatic/Test/print.c b/Lib/Utils/Logomatic/Test/print.c index 563704f8a..0659dbe97 100644 --- a/Lib/Utils/Logomatic/Test/print.c +++ b/Lib/Utils/Logomatic/Test/print.c @@ -2,8 +2,29 @@ #include #include #include + +#ifdef _WIN32 +#include +#include + +#define sys_pipe(fd) _pipe(fd, 4096, _O_BINARY) +#define sys_dup _dup +#define sys_dup2 _dup2 +#define sys_read _read +#define sys_close _close +#define STDOUT_FILENO _fileno(stdout) + +typedef ptrdiff_t ssize_t; +#else #include +#define sys_pipe(fd) pipe(fd) +#define sys_dup dup +#define sys_dup2 dup2 +#define sys_read read +#define sys_close close +#endif + #include "Logomatic.h" int main(void) @@ -18,13 +39,18 @@ int main(void) int pipefd[2]; char buffer[sizeof(expected) + 50] = {0}; - if (pipe(pipefd) == -1) { + if (sys_pipe(pipefd) == -1) { perror("Pipe failed"); return 1; } - int saved_stdout = dup(STDOUT_FILENO); - dup2(pipefd[1], STDOUT_FILENO); + int saved_stdout = sys_dup(STDOUT_FILENO); + +#ifdef _WIN32 + _setmode(STDOUT_FILENO, _O_BINARY); +#endif + + sys_dup2(pipefd[1], STDOUT_FILENO); LOGOMATIC_CRITICAL("Critical log message\n"); LOGOMATIC_ERROR("Error log message\n"); @@ -34,16 +60,20 @@ int main(void) LOGOMATIC_VERBOSE("Verbose log message\n"); fflush(stdout); - close(pipefd[1]); + sys_close(pipefd[1]); + + sys_dup2(saved_stdout, STDOUT_FILENO); + sys_close(saved_stdout); - dup2(saved_stdout, STDOUT_FILENO); - close(saved_stdout); +#ifdef _WIN32 + _setmode(STDOUT_FILENO, _O_TEXT); +#endif - ssize_t bytes_read = read(pipefd[0], buffer, sizeof(buffer) - 1); + ssize_t bytes_read = sys_read(pipefd[0], buffer, sizeof(buffer) - 1); if (bytes_read >= 0) { buffer[bytes_read] = '\0'; } - close(pipefd[0]); + sys_close(pipefd[0]); if (strcmp(buffer, expected) == 0) { printf("Test passed: Log output matches expected output.\n"); From 3e4cbc3b2dc8257c9d0abb4cc5a2d95a8f9f3360 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 06:31:00 -0700 Subject: [PATCH 095/125] Fix the line of the verbose print Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/Test/print.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/Utils/Logomatic/Test/print.c b/Lib/Utils/Logomatic/Test/print.c index 0659dbe97..e4f50d0d8 100644 --- a/Lib/Utils/Logomatic/Test/print.c +++ b/Lib/Utils/Logomatic/Test/print.c @@ -34,7 +34,7 @@ int main(void) "[WARNING] Warning log message\n" "[INFO] Informational log message\n" "[DEBUG] Debug log message\n" - "[VERBOSE - print.c:34] Verbose log message\n"; + "[VERBOSE - print.c:60] Verbose log message\n"; int pipefd[2]; char buffer[sizeof(expected) + 50] = {0}; From 4f1327330f86078dc8cb52d000842cd424128416 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 06:37:43 -0700 Subject: [PATCH 096/125] Windows has lots of fun with POSIX and not POSIX Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/Test/print.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/Utils/Logomatic/Test/print.c b/Lib/Utils/Logomatic/Test/print.c index e4f50d0d8..447d72a80 100644 --- a/Lib/Utils/Logomatic/Test/print.c +++ b/Lib/Utils/Logomatic/Test/print.c @@ -12,7 +12,10 @@ #define sys_dup2 _dup2 #define sys_read _read #define sys_close _close + +#ifndef STDOUT_FILENO #define STDOUT_FILENO _fileno(stdout) +#endif typedef ptrdiff_t ssize_t; #else From 0ab28157824b3f307a899962baa56c2781afa4f8 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 06:42:05 -0700 Subject: [PATCH 097/125] Insanity is approaching Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/Test/print.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/Utils/Logomatic/Test/print.c b/Lib/Utils/Logomatic/Test/print.c index 447d72a80..d38e9af1f 100644 --- a/Lib/Utils/Logomatic/Test/print.c +++ b/Lib/Utils/Logomatic/Test/print.c @@ -37,7 +37,7 @@ int main(void) "[WARNING] Warning log message\n" "[INFO] Informational log message\n" "[DEBUG] Debug log message\n" - "[VERBOSE - print.c:60] Verbose log message\n"; + "[VERBOSE - print.c:63] Verbose log message\n"; int pipefd[2]; char buffer[sizeof(expected) + 50] = {0}; From 4d51a5661bc4c43883dcebfae3b39da62c6e0c42 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 06:49:44 -0700 Subject: [PATCH 098/125] Provide a strong definition for the global driver since Windows cannot handle weak references it seems Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/Test/print.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/Utils/Logomatic/Test/print.c b/Lib/Utils/Logomatic/Test/print.c index d38e9af1f..0777af0e1 100644 --- a/Lib/Utils/Logomatic/Test/print.c +++ b/Lib/Utils/Logomatic/Test/print.c @@ -30,6 +30,8 @@ typedef ptrdiff_t ssize_t; #include "Logomatic.h" +const Logomatic_Driver global_logomatic_driver = NULL; + int main(void) { const char expected[] = "[CRITICAL] Critical log message\n" @@ -37,7 +39,7 @@ int main(void) "[WARNING] Warning log message\n" "[INFO] Informational log message\n" "[DEBUG] Debug log message\n" - "[VERBOSE - print.c:63] Verbose log message\n"; + "[VERBOSE - print.c:65] Verbose log message\n"; int pipefd[2]; char buffer[sizeof(expected) + 50] = {0}; From 2c3ad7122da5c38c31b6f2d69c42348b3da94e19 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 06:56:12 -0700 Subject: [PATCH 099/125] Going insane 6 7 Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/Test/print.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/Utils/Logomatic/Test/print.c b/Lib/Utils/Logomatic/Test/print.c index 0777af0e1..bcd4a31c4 100644 --- a/Lib/Utils/Logomatic/Test/print.c +++ b/Lib/Utils/Logomatic/Test/print.c @@ -30,7 +30,9 @@ typedef ptrdiff_t ssize_t; #include "Logomatic.h" +#ifdef _WIN32 const Logomatic_Driver global_logomatic_driver = NULL; +#endif int main(void) { @@ -39,7 +41,7 @@ int main(void) "[WARNING] Warning log message\n" "[INFO] Informational log message\n" "[DEBUG] Debug log message\n" - "[VERBOSE - print.c:65] Verbose log message\n"; + "[VERBOSE - print.c:67] Verbose log message\n"; int pipefd[2]; char buffer[sizeof(expected) + 50] = {0}; From c7938b0339bac68f02efee775abf7add276f5a3b Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 07:07:39 -0700 Subject: [PATCH 100/125] Windows apparently has no concept of weak links Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/Inc/Logomatic.h | 4 ++++ Lib/Utils/Logomatic/Test/print.c | 6 ++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Lib/Utils/Logomatic/Inc/Logomatic.h b/Lib/Utils/Logomatic/Inc/Logomatic.h index e2a8d3e8a..8fc7d8361 100644 --- a/Lib/Utils/Logomatic/Inc/Logomatic.h +++ b/Lib/Utils/Logomatic/Inc/Logomatic.h @@ -66,7 +66,11 @@ extern Logomatic_LogLevel _logomatic_loglevel; * * @note This variable should not be modified once setup by the user. */ +#ifdef LOGOMATIC_HOOTLTEST +extern const Logomatic_Driver global_logomatic_driver; +#else extern const __weak Logomatic_Driver global_logomatic_driver; +#endif #ifdef LOGOMATIC_HOOTLTEST diff --git a/Lib/Utils/Logomatic/Test/print.c b/Lib/Utils/Logomatic/Test/print.c index bcd4a31c4..788acb830 100644 --- a/Lib/Utils/Logomatic/Test/print.c +++ b/Lib/Utils/Logomatic/Test/print.c @@ -30,9 +30,7 @@ typedef ptrdiff_t ssize_t; #include "Logomatic.h" -#ifdef _WIN32 -const Logomatic_Driver global_logomatic_driver = NULL; -#endif +const Logomatic_Driver global_logomatic_driver; int main(void) { @@ -41,7 +39,7 @@ int main(void) "[WARNING] Warning log message\n" "[INFO] Informational log message\n" "[DEBUG] Debug log message\n" - "[VERBOSE - print.c:67] Verbose log message\n"; + "[VERBOSE - print.c:65] Verbose log message\n"; int pipefd[2]; char buffer[sizeof(expected) + 50] = {0}; From 3ea699556842cc17edc8214bab04efe1303b899b Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 07:12:18 -0700 Subject: [PATCH 101/125] Completely hide weak references on testing Signed-off-by: Daniel Hansen --- Lib/Utils/Logomatic/Inc/Logomatic.h | 4 +--- Lib/Utils/Logomatic/Src/log_config.c | 4 ---- Lib/Utils/Logomatic/Src/log_driver.c | 5 +++++ Lib/Utils/Logomatic/Test/print.c | 4 +--- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Lib/Utils/Logomatic/Inc/Logomatic.h b/Lib/Utils/Logomatic/Inc/Logomatic.h index 8fc7d8361..1a3a29e21 100644 --- a/Lib/Utils/Logomatic/Inc/Logomatic.h +++ b/Lib/Utils/Logomatic/Inc/Logomatic.h @@ -66,9 +66,7 @@ extern Logomatic_LogLevel _logomatic_loglevel; * * @note This variable should not be modified once setup by the user. */ -#ifdef LOGOMATIC_HOOTLTEST -extern const Logomatic_Driver global_logomatic_driver; -#else +#ifndef LOGOMATIC_HOOTLTEST extern const __weak Logomatic_Driver global_logomatic_driver; #endif diff --git a/Lib/Utils/Logomatic/Src/log_config.c b/Lib/Utils/Logomatic/Src/log_config.c index 44227b331..f74f98006 100644 --- a/Lib/Utils/Logomatic/Src/log_config.c +++ b/Lib/Utils/Logomatic/Src/log_config.c @@ -1,11 +1,7 @@ #include "Logomatic.h" #include "main.h" -#if defined(LOGOMATIC_HOOTLTEST) -Logomatic_LogLevel _logomatic_loglevel = LogLevel_Verbose; -#else Logomatic_LogLevel _logomatic_loglevel = LogLevel_Debug; -#endif #if defined(ITM) __weak const Logomatic_Driver global_logomatic_driver = Logomatic_Driver_ITM; diff --git a/Lib/Utils/Logomatic/Src/log_driver.c b/Lib/Utils/Logomatic/Src/log_driver.c index 4efc2ac8a..ab3d26fe4 100644 --- a/Lib/Utils/Logomatic/Src/log_driver.c +++ b/Lib/Utils/Logomatic/Src/log_driver.c @@ -3,10 +3,15 @@ int __io_putchar(int ch) { +#ifdef LOGOMATIC_HOOTLTEST + return putchar(ch); +#else if (global_logomatic_driver != NULL) { + putchar(ch); return global_logomatic_driver(ch); } return ch; +#endif } #if defined(ITM) diff --git a/Lib/Utils/Logomatic/Test/print.c b/Lib/Utils/Logomatic/Test/print.c index 788acb830..d38e9af1f 100644 --- a/Lib/Utils/Logomatic/Test/print.c +++ b/Lib/Utils/Logomatic/Test/print.c @@ -30,8 +30,6 @@ typedef ptrdiff_t ssize_t; #include "Logomatic.h" -const Logomatic_Driver global_logomatic_driver; - int main(void) { const char expected[] = "[CRITICAL] Critical log message\n" @@ -39,7 +37,7 @@ int main(void) "[WARNING] Warning log message\n" "[INFO] Informational log message\n" "[DEBUG] Debug log message\n" - "[VERBOSE - print.c:65] Verbose log message\n"; + "[VERBOSE - print.c:63] Verbose log message\n"; int pipefd[2]; char buffer[sizeof(expected) + 50] = {0}; From 31b6efe114b439483012db20730002cdff026b71 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 15:49:46 -0700 Subject: [PATCH 102/125] IN PROGRESS - Snapshot of initial VCP attempt with STM32CubeMX Currently breaks ITM / Logomatic... Signed-off-by: Daniel Hansen --- CMakeLists.txt | 1 + CUBEMXTESTING/CMakeLists.txt | 2 + CUBEMXTESTING/CUBEMXTESTING.ioc | 146 +++--- CUBEMXTESTING/Core/Inc/fdcan.h | 1 + CUBEMXTESTING/Core/Inc/gpio.h | 1 + CUBEMXTESTING/Core/Inc/main.h | 13 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 217 ++++---- CUBEMXTESTING/Core/Inc/tim.h | 1 + CUBEMXTESTING/Core/Inc/usart.h | 1 + CUBEMXTESTING/Core/Src/fdcan.c | 525 ++++++++++--------- CUBEMXTESTING/Core/Src/gpio.c | 549 ++++++++++---------- CUBEMXTESTING/Core/Src/main.c | 165 +++--- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 24 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 197 +++---- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- CUBEMXTESTING/Core/Src/usart.c | 154 +++--- Lib/Utils/CubeVCP/Inc/CubeVCP.h | 6 + Lib/Utils/CubeVCP/Src/vcp.c | 3 + Lib/Utils/CubeVCP/vcp.cmake | 19 + 19 files changed, 1109 insertions(+), 1029 deletions(-) create mode 100644 Lib/Utils/CubeVCP/Inc/CubeVCP.h create mode 100644 Lib/Utils/CubeVCP/Src/vcp.c create mode 100644 Lib/Utils/CubeVCP/vcp.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b062bc9d..8c0144a78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,6 +130,7 @@ include("${platform_path}/STM32H523xE/chip.cmake") include("${lib_path}/GlobalShare/common.cmake") include("${lib_path}/Utils/OldLogomatic/logomatic.cmake") include("${lib_path}/Utils/Logomatic/log.cmake") +include("${lib_path}/Utils/CubeVCP/vcp.cmake") include("${lib_path}/Utils/VirtualComPort/vcp.cmake") include("${lib_path}/Utils/CircularBuffer/circular-buffer-lib.cmake") include("${lib_path}/Utils/MsgBuffer/msg-buffer-lib.cmake") diff --git a/CUBEMXTESTING/CMakeLists.txt b/CUBEMXTESTING/CMakeLists.txt index fe140a251..a5341ae8f 100644 --- a/CUBEMXTESTING/CMakeLists.txt +++ b/CUBEMXTESTING/CMakeLists.txt @@ -33,12 +33,14 @@ target_sources( Core/Src/main.c Core/Src/stm32g4xx_it.c Core/Src/tim.c + Core/Src/usart.c ) target_link_libraries( ${PROJECT_NAME}_USER_CODE INTERFACE CUBE_CAN_LIB + CUBE_VCP_LIB LOGOMATIC_LIB ) diff --git a/CUBEMXTESTING/CUBEMXTESTING.ioc b/CUBEMXTESTING/CUBEMXTESTING.ioc index f677d27ec..5c3a9570d 100644 --- a/CUBEMXTESTING/CUBEMXTESTING.ioc +++ b/CUBEMXTESTING/CUBEMXTESTING.ioc @@ -3,9 +3,9 @@ CAD.formats=[] CAD.pinconfig=Dual CAD.provider= FDCAN1.AutoRetransmission=ENABLE -FDCAN1.CalculateBaudRateNominal=1000000 -FDCAN1.CalculateTimeBitNominal=1000 -FDCAN1.CalculateTimeQuantumNominal=6.25 +FDCAN1.CalculateBaudRateNominal=600000 +FDCAN1.CalculateTimeBitNominal=1666 +FDCAN1.CalculateTimeQuantumNominal=10.416666666666666 FDCAN1.DataPrescaler=8 FDCAN1.DataSyncJumpWidth=16 FDCAN1.DataTimeSeg1=14 @@ -19,9 +19,9 @@ FDCAN1.NominalTimeSeg1=119 FDCAN1.NominalTimeSeg2=40 FDCAN1.ProtocolException=ENABLE FDCAN2.AutoRetransmission=ENABLE -FDCAN2.CalculateBaudRateNominal=1000000 -FDCAN2.CalculateTimeBitNominal=1000 -FDCAN2.CalculateTimeQuantumNominal=6.25 +FDCAN2.CalculateBaudRateNominal=600000 +FDCAN2.CalculateTimeBitNominal=1666 +FDCAN2.CalculateTimeQuantumNominal=10.416666666666666 FDCAN2.DataPrescaler=8 FDCAN2.DataSyncJumpWidth=16 FDCAN2.DataTimeSeg1=14 @@ -34,41 +34,46 @@ FDCAN2.NominalSyncJumpWidth=16 FDCAN2.NominalTimeSeg1=119 FDCAN2.NominalTimeSeg2=40 FDCAN2.ProtocolException=ENABLE -FDCAN3.CalculateBaudRateNominal=3333333 -FDCAN3.CalculateTimeBitNominal=300 -FDCAN3.CalculateTimeQuantumNominal=100.0 +FDCAN3.CalculateBaudRateNominal=2000000 +FDCAN3.CalculateTimeBitNominal=500 +FDCAN3.CalculateTimeQuantumNominal=166.66666666666666 FDCAN3.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal,Mode FDCAN3.Mode=FDCAN_MODE_INTERNAL_LOOPBACK File.Version=6 GPIO.groupedBy=Group By Peripherals KeepUserPlacement=false +LPUART1.BaudRate=230400 +LPUART1.IPParameters=BaudRate Mcu.CPN=STM32G474RET6 Mcu.Family=STM32G4 Mcu.IP0=FDCAN1 Mcu.IP1=FDCAN2 Mcu.IP2=FDCAN3 -Mcu.IP3=NVIC -Mcu.IP4=RCC -Mcu.IP5=SYS -Mcu.IP6=TIM5 -Mcu.IPNb=7 +Mcu.IP3=LPUART1 +Mcu.IP4=NVIC +Mcu.IP5=RCC +Mcu.IP6=SYS +Mcu.IP7=TIM5 +Mcu.IPNb=8 Mcu.Name=STM32G474R(B-C-E)Tx Mcu.Package=LQFP64 Mcu.Pin0=PC13 -Mcu.Pin1=PA5 -Mcu.Pin10=PB9 -Mcu.Pin11=VP_SYS_VS_Systick -Mcu.Pin12=VP_SYS_VS_DBSignals -Mcu.Pin13=VP_TIM5_VS_ClockSourceINT -Mcu.Pin2=PB12 -Mcu.Pin3=PB13 -Mcu.Pin4=PA8 -Mcu.Pin5=PA13 -Mcu.Pin6=PA14 -Mcu.Pin7=PA15 -Mcu.Pin8=PB3 -Mcu.Pin9=PB8-BOOT0 -Mcu.PinsNb=14 +Mcu.Pin1=PA2 +Mcu.Pin10=PB3 +Mcu.Pin11=PB8-BOOT0 +Mcu.Pin12=PB9 +Mcu.Pin13=VP_SYS_VS_Systick +Mcu.Pin14=VP_SYS_VS_DBSignals +Mcu.Pin15=VP_TIM5_VS_ClockSourceINT +Mcu.Pin2=PA3 +Mcu.Pin3=PA5 +Mcu.Pin4=PB12 +Mcu.Pin5=PB13 +Mcu.Pin6=PA8 +Mcu.Pin7=PA13 +Mcu.Pin8=PA14 +Mcu.Pin9=PA15 +Mcu.PinsNb=16 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32G474RETx @@ -95,6 +100,12 @@ PA14.Mode=Trace_Asynchronous_SW PA14.Signal=SYS_JTCK-SWCLK PA15.Mode=FDCAN_Activate PA15.Signal=FDCAN3_TX +PA2.Locked=true +PA2.Mode=Asynchronous +PA2.Signal=LPUART1_TX +PA3.Locked=true +PA3.Mode=Asynchronous +PA3.Signal=LPUART1_RX PA5.GPIOParameters=GPIO_Label PA5.GPIO_Label=USER_LED PA5.Locked=true @@ -153,59 +164,60 @@ ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=false ProjectManager.UseDefaultDestinationPath=true ProjectManager.UseDefaultSourcePath=true -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_TIM5_Init-TIM5-false-HAL-true,6-MX_FDCAN3_Init-FDCAN3-false-HAL-true -RCC.ADC12Freq_Value=160000000 -RCC.ADC345Freq_Value=160000000 -RCC.AHBFreq_Value=160000000 -RCC.APB1Freq_Value=160000000 -RCC.APB1TimFreq_Value=160000000 -RCC.APB2Freq_Value=160000000 -RCC.APB2TimFreq_Value=160000000 +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_TIM5_Init-TIM5-false-HAL-true,6-MX_FDCAN3_Init-FDCAN3-false-HAL-true,7-MX_LPUART1_UART_Init-LPUART1-false-HAL-true +RCC.ADC12Freq_Value=96000000 +RCC.ADC345Freq_Value=96000000 +RCC.AHBFreq_Value=96000000 +RCC.APB1Freq_Value=96000000 +RCC.APB1TimFreq_Value=96000000 +RCC.APB2Freq_Value=96000000 +RCC.APB2TimFreq_Value=96000000 RCC.CRSFreq_Value=48000000 -RCC.CortexFreq_Value=160000000 +RCC.CortexFreq_Value=96000000 RCC.EXTERNAL_CLOCK_VALUE=12288000 -RCC.FCLKCortexFreq_Value=160000000 -RCC.FDCANFreq_Value=160000000 +RCC.FCLKCortexFreq_Value=96000000 +RCC.FDCANFreq_Value=96000000 RCC.FamilyName=M -RCC.HCLKFreq_Value=160000000 -RCC.HRTIM1Freq_Value=160000000 +RCC.HCLKFreq_Value=96000000 +RCC.HRTIM1Freq_Value=96000000 RCC.HSE_VALUE=16000000 RCC.HSI48_VALUE=48000000 RCC.HSI_VALUE=16000000 -RCC.I2C1Freq_Value=160000000 -RCC.I2C2Freq_Value=160000000 -RCC.I2C3Freq_Value=160000000 -RCC.I2C4Freq_Value=160000000 -RCC.I2SFreq_Value=160000000 -RCC.IPParameters=ADC12Freq_Value,ADC345Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HRTIM1Freq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PWRFreq_Value,QSPIFreq_Value,RNGFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value -RCC.LPTIM1Freq_Value=160000000 -RCC.LPUART1Freq_Value=160000000 +RCC.I2C1Freq_Value=96000000 +RCC.I2C2Freq_Value=96000000 +RCC.I2C3Freq_Value=96000000 +RCC.I2C4Freq_Value=96000000 +RCC.I2SFreq_Value=96000000 +RCC.IPParameters=ADC12Freq_Value,ADC345Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HRTIM1Freq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,PLLN,PLLPoutputFreq_Value,PLLQ,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PWRFreq_Value,QSPIFreq_Value,RNGFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value +RCC.LPTIM1Freq_Value=96000000 +RCC.LPUART1Freq_Value=96000000 RCC.LSCOPinFreq_Value=32000 RCC.LSE_VALUE=32768 RCC.LSI_VALUE=32000 RCC.MCO1PinFreq_Value=16000000 -RCC.PLLN=20 -RCC.PLLPoutputFreq_Value=160000000 -RCC.PLLQoutputFreq_Value=160000000 -RCC.PLLRCLKFreq_Value=160000000 -RCC.PWRFreq_Value=160000000 -RCC.QSPIFreq_Value=160000000 -RCC.RNGFreq_Value=160000000 -RCC.SAI1Freq_Value=160000000 -RCC.SYSCLKFreq_VALUE=160000000 +RCC.PLLN=12 +RCC.PLLPoutputFreq_Value=96000000 +RCC.PLLQ=RCC_PLLQ_DIV4 +RCC.PLLQoutputFreq_Value=48000000 +RCC.PLLRCLKFreq_Value=96000000 +RCC.PWRFreq_Value=96000000 +RCC.QSPIFreq_Value=96000000 +RCC.RNGFreq_Value=48000000 +RCC.SAI1Freq_Value=96000000 +RCC.SYSCLKFreq_VALUE=96000000 RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK -RCC.UART4Freq_Value=160000000 -RCC.UART5Freq_Value=160000000 -RCC.USART1Freq_Value=160000000 -RCC.USART2Freq_Value=160000000 -RCC.USART3Freq_Value=160000000 -RCC.USBFreq_Value=160000000 +RCC.UART4Freq_Value=96000000 +RCC.UART5Freq_Value=96000000 +RCC.USART1Freq_Value=96000000 +RCC.USART2Freq_Value=96000000 +RCC.USART3Freq_Value=96000000 +RCC.USBFreq_Value=48000000 RCC.VCOInputFreq_Value=16000000 -RCC.VCOOutputFreq_Value=320000000 +RCC.VCOOutputFreq_Value=192000000 TIM5.Dithering=Disable TIM5.IPParameters=Prescaler,PeriodNoDither,Dithering -TIM5.PeriodNoDither=49 -TIM5.Prescaler=1599 +TIM5.PeriodNoDither=2999 +TIM5.Prescaler=15 VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals VP_SYS_VS_Systick.Mode=SysTick diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 3597c6476..21271cf64 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -55,3 +55,4 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 37dcc0a5c..03c2faca5 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -46,3 +46,4 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index cbeced83f..2b50abc31 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,16 +28,17 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" + +#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_dma.h" -#include "stm32g4xx_ll_exti.h" -#include "stm32g4xx_ll_gpio.h" -#include "stm32g4xx_ll_pwr.h" -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_exti.h" +#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_utils.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index aa097ab4c..e4db34d37 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus -extern "C" { + extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ extern "C" { /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED -/*#define HAL_ADC_MODULE_ENABLED */ + /*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -63,7 +63,7 @@ extern "C" { /*#define HAL_SPI_MODULE_ENABLED */ /*#define HAL_SRAM_MODULE_ENABLED */ #define HAL_TIM_MODULE_ENABLED -/*#define HAL_UART_MODULE_ENABLED */ +#define HAL_UART_MODULE_ENABLED /*#define HAL_USART_MODULE_ENABLED */ /*#define HAL_WWDG_MODULE_ENABLED */ #define HAL_GPIO_MODULE_ENABLED @@ -76,124 +76,123 @@ extern "C" { /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(HSE_STARTUP_TIMEOUT) -#define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined(HSI48_VALUE) -#define HSI48_VALUE \ - (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined (HSI48_VALUE) + #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined(LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined(LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined(LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined (LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined(EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -#define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ + #define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -202,12 +201,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -358,15 +357,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index 2d20bd560..b90657cf4 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,3 +49,4 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/CUBEMXTESTING/Core/Inc/usart.h index bdec0c9cb..49dd0cccc 100644 --- a/CUBEMXTESTING/Core/Inc/usart.h +++ b/CUBEMXTESTING/Core/Inc/usart.h @@ -49,3 +49,4 @@ void MX_LPUART1_UART_Init(void); #endif #endif /* __USART_H__ */ + diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 30b3c9dc1..08b2a1b8a 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,281 +32,298 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ + } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ + } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ + } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN3) { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) { - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN3) { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index 48af4489a..96b5c07ab 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -33,289 +33,278 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) - */ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) +*/ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 93100e131..064668363 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,10 +18,10 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" - #include "fdcan.h" -#include "gpio.h" +#include "usart.h" #include "tim.h" +#include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -75,39 +75,40 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + MX_LPUART1_UART_Init(); + /* USER CODE BEGIN 2 */ CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config dataCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_DATA, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config chargerCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_CHARGER, .sending_node_id = GRCAN_Debugger}; @@ -131,59 +132,67 @@ int main(void) } LOGOMATIC_INFO("Hello World!\n"); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); HAL_Delay(100); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_3); + while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_3) + { + } + LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while(LL_RCC_HSI_IsReady() != 1) + { + } + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 12, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while(LL_RCC_PLL_IsReady() != 1) + { + } + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) + { + } + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i !=0; i--); + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(96000000); + + /* Update the time base */ + if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) + { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -202,29 +211,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ LOGOMATIC_CRITICAL("Assert failed! File %s on line %" PRIu32 "\n", file, line); - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index 4668755ab..2cc7d8296 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index fd2ad329f..78d6b9cd9 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,9 +18,8 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "stm32g4xx_it.h" - #include "main.h" +#include "stm32g4xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -68,125 +67,129 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -197,59 +200,59 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index e77341bf2..37275ddf5 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,76 +30,83 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 1599; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 49; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 15; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 2999; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) + { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ + /* USER CODE END TIM5_Init 2 */ + } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) { - if (tim_baseHandle->Instance == TIM5) { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) { - if (tim_baseHandle->Instance == TIM5) { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/Core/Src/usart.c b/CUBEMXTESTING/Core/Src/usart.c index 4e3f96e17..edd2b6912 100644 --- a/CUBEMXTESTING/Core/Src/usart.c +++ b/CUBEMXTESTING/Core/Src/usart.c @@ -31,93 +31,101 @@ UART_HandleTypeDef hlpuart1; void MX_LPUART1_UART_Init(void) { - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - hlpuart1.Instance = LPUART1; - hlpuart1.Init.BaudRate = 115200; - hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; - hlpuart1.Init.StopBits = UART_STOPBITS_1; - hlpuart1.Init.Parity = UART_PARITY_NONE; - hlpuart1.Init.Mode = UART_MODE_TX_RX; - hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&hlpuart1) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ + /* USER CODE BEGIN LPUART1_Init 0 */ + + /* USER CODE END LPUART1_Init 0 */ + + /* USER CODE BEGIN LPUART1_Init 1 */ + + /* USER CODE END LPUART1_Init 1 */ + hlpuart1.Instance = LPUART1; + hlpuart1.Init.BaudRate = 230400; + hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; + hlpuart1.Init.StopBits = UART_STOPBITS_1; + hlpuart1.Init.Parity = UART_PARITY_NONE; + hlpuart1.Init.Mode = UART_MODE_TX_RX; + hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&hlpuart1) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN LPUART1_Init 2 */ + + /* USER CODE END LPUART1_Init 2 */ + } -void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle) +void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (uartHandle->Instance == LPUART1) { - /* USER CODE BEGIN LPUART1_MspInit 0 */ - - /* USER CODE END LPUART1_MspInit 0 */ - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* LPUART1 clock enable */ - __HAL_RCC_LPUART1_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**LPUART1 GPIO Configuration - PC0 ------> LPUART1_RX - PC1 ------> LPUART1_TX - */ - 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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN LPUART1_MspInit 1 */ - - /* USER CODE END LPUART1_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(uartHandle->Instance==LPUART1) + { + /* USER CODE BEGIN LPUART1_MspInit 0 */ + + /* USER CODE END LPUART1_MspInit 0 */ + LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); + + /* LPUART1 clock enable */ + __HAL_RCC_LPUART1_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**LPUART1 GPIO Configuration + PA2 ------> LPUART1_TX + PA3 ------> LPUART1_RX + */ + 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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF12_LPUART1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* USER CODE BEGIN LPUART1_MspInit 1 */ + + /* USER CODE END LPUART1_MspInit 1 */ + } } -void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle) +void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { - if (uartHandle->Instance == LPUART1) { - /* USER CODE BEGIN LPUART1_MspDeInit 0 */ + if(uartHandle->Instance==LPUART1) + { + /* USER CODE BEGIN LPUART1_MspDeInit 0 */ - /* USER CODE END LPUART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_LPUART1_CLK_DISABLE(); + /* USER CODE END LPUART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_LPUART1_CLK_DISABLE(); - /**LPUART1 GPIO Configuration - PC0 ------> LPUART1_RX - PC1 ------> LPUART1_TX - */ - HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0 | GPIO_PIN_1); + /**LPUART1 GPIO Configuration + PA2 ------> LPUART1_TX + PA3 ------> LPUART1_RX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); - /* USER CODE BEGIN LPUART1_MspDeInit 1 */ + /* USER CODE BEGIN LPUART1_MspDeInit 1 */ - /* USER CODE END LPUART1_MspDeInit 1 */ - } + /* USER CODE END LPUART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/Lib/Utils/CubeVCP/Inc/CubeVCP.h b/Lib/Utils/CubeVCP/Inc/CubeVCP.h new file mode 100644 index 000000000..cccb69902 --- /dev/null +++ b/Lib/Utils/CubeVCP/Inc/CubeVCP.h @@ -0,0 +1,6 @@ +#ifndef CUBE_VCP_H +#define CUBE_VCP_H + +// TODO + +#endif diff --git a/Lib/Utils/CubeVCP/Src/vcp.c b/Lib/Utils/CubeVCP/Src/vcp.c new file mode 100644 index 000000000..6c7d98398 --- /dev/null +++ b/Lib/Utils/CubeVCP/Src/vcp.c @@ -0,0 +1,3 @@ +#include "CubeCAN.h" + +// TODO diff --git a/Lib/Utils/CubeVCP/vcp.cmake b/Lib/Utils/CubeVCP/vcp.cmake new file mode 100644 index 000000000..eaec60614 --- /dev/null +++ b/Lib/Utils/CubeVCP/vcp.cmake @@ -0,0 +1,19 @@ +add_library(CUBE_VCP_LIB INTERFACE) + +target_include_directories( + CUBE_VCP_LIB + INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/Inc +) + +target_sources( + CUBE_VCP_LIB + INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/Src/vcp.c +) + +target_link_libraries( + CUBE_VCP_LIB + INTERFACE + LOGOMATIC_LIB +) From 94e0194a5dd3a5b382ad604a5369234cdeed2bf3 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2026 22:52:46 +0000 Subject: [PATCH 103/125] Automatic CMake Format: Standardized formatting automatically --- Lib/Utils/CubeVCP/vcp.cmake | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/Lib/Utils/CubeVCP/vcp.cmake b/Lib/Utils/CubeVCP/vcp.cmake index eaec60614..b06b1ba3e 100644 --- a/Lib/Utils/CubeVCP/vcp.cmake +++ b/Lib/Utils/CubeVCP/vcp.cmake @@ -1,19 +1,7 @@ add_library(CUBE_VCP_LIB INTERFACE) -target_include_directories( - CUBE_VCP_LIB - INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/Inc -) +target_include_directories(CUBE_VCP_LIB INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Inc) -target_sources( - CUBE_VCP_LIB - INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/Src/vcp.c -) +target_sources(CUBE_VCP_LIB INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Src/vcp.c) -target_link_libraries( - CUBE_VCP_LIB - INTERFACE - LOGOMATIC_LIB -) +target_link_libraries(CUBE_VCP_LIB INTERFACE LOGOMATIC_LIB) From 00caad635584b898e8c09cd0d9540974eb87cf6c Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2026 22:54:09 +0000 Subject: [PATCH 104/125] Automatic Clang-Format: Standardized formatting automatically --- CUBEMXTESTING/Core/Inc/fdcan.h | 1 - CUBEMXTESTING/Core/Inc/gpio.h | 1 - CUBEMXTESTING/Core/Inc/main.h | 13 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 215 ++++---- CUBEMXTESTING/Core/Inc/tim.h | 1 - CUBEMXTESTING/Core/Inc/usart.h | 1 - CUBEMXTESTING/Core/Src/fdcan.c | 525 +++++++++---------- CUBEMXTESTING/Core/Src/gpio.c | 537 ++++++++++---------- CUBEMXTESTING/Core/Src/main.c | 167 +++--- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 24 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 197 ++++--- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- CUBEMXTESTING/Core/Src/usart.c | 154 +++--- 13 files changed, 951 insertions(+), 998 deletions(-) diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 21271cf64..3597c6476 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -55,4 +55,3 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 03c2faca5..37dcc0a5c 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -46,4 +46,3 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index 2b50abc31..cbeced83f 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,17 +28,16 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" - -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_system.h" -#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_utils.h" -#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_crs.h" #include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_gpio.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_rcc.h" +#include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_utils.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index e4db34d37..d12d585bd 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED - /*#define HAL_ADC_MODULE_ENABLED */ +/*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -76,123 +76,124 @@ /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined(HSE_STARTUP_TIMEOUT) +#define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined (HSI48_VALUE) - #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined(HSI48_VALUE) +#define HSI48_VALUE \ + (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined(LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined (LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined(LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined (LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined(LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined (EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined(EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ - #define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +#define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -201,12 +202,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -357,15 +358,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index b90657cf4..2d20bd560 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,4 +49,3 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/CUBEMXTESTING/Core/Inc/usart.h index 49dd0cccc..bdec0c9cb 100644 --- a/CUBEMXTESTING/Core/Inc/usart.h +++ b/CUBEMXTESTING/Core/Inc/usart.h @@ -49,4 +49,3 @@ void MX_LPUART1_UART_Init(void); #endif #endif /* __USART_H__ */ - diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 08b2a1b8a..30b3c9dc1 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,298 +32,281 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ - + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ - + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ - + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) { - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index 96b5c07ab..4d07c7993 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -33,278 +33,277 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) -*/ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) + */ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 064668363..9aa9fc444 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,10 +18,11 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" + #include "fdcan.h" -#include "usart.h" -#include "tim.h" #include "gpio.h" +#include "tim.h" +#include "usart.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -75,40 +76,40 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - MX_LPUART1_UART_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + MX_LPUART1_UART_Init(); + /* USER CODE BEGIN 2 */ CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config dataCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_DATA, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config chargerCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_CHARGER, .sending_node_id = GRCAN_Debugger}; @@ -132,67 +133,59 @@ int main(void) } LOGOMATIC_INFO("Hello World!\n"); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); HAL_Delay(100); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_3); - while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_3) - { - } - LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while(LL_RCC_HSI_IsReady() != 1) - { - } - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 12, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while(LL_RCC_PLL_IsReady() != 1) - { - } - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) - { - } - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i !=0; i--); - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(96000000); - - /* Update the time base */ - if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) - { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_3); + while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_3) {} + LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while (LL_RCC_HSI_IsReady() != 1) {} + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 12, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while (LL_RCC_PLL_IsReady() != 1) {} + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i != 0; i--) + ; + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(96000000); + + /* Update the time base */ + if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -211,29 +204,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ LOGOMATIC_CRITICAL("Assert failed! File %s on line %" PRIu32 "\n", file, line); - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index 2cc7d8296..4668755ab 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index 78d6b9cd9..fd2ad329f 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,8 +18,9 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "main.h" #include "stm32g4xx_it.h" + +#include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -67,129 +68,125 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -200,59 +197,59 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index 37275ddf5..ee31cf8b0 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,83 +30,76 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 15; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 2999; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) - { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) - { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 15; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 2999; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ - + /* USER CODE END TIM5_Init 2 */ } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/usart.c b/CUBEMXTESTING/Core/Src/usart.c index edd2b6912..8350fa20b 100644 --- a/CUBEMXTESTING/Core/Src/usart.c +++ b/CUBEMXTESTING/Core/Src/usart.c @@ -31,101 +31,93 @@ UART_HandleTypeDef hlpuart1; void MX_LPUART1_UART_Init(void) { - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - hlpuart1.Instance = LPUART1; - hlpuart1.Init.BaudRate = 230400; - hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; - hlpuart1.Init.StopBits = UART_STOPBITS_1; - hlpuart1.Init.Parity = UART_PARITY_NONE; - hlpuart1.Init.Mode = UART_MODE_TX_RX; - hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&hlpuart1) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ - + /* USER CODE BEGIN LPUART1_Init 0 */ + + /* USER CODE END LPUART1_Init 0 */ + + /* USER CODE BEGIN LPUART1_Init 1 */ + + /* USER CODE END LPUART1_Init 1 */ + hlpuart1.Instance = LPUART1; + hlpuart1.Init.BaudRate = 230400; + hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; + hlpuart1.Init.StopBits = UART_STOPBITS_1; + hlpuart1.Init.Parity = UART_PARITY_NONE; + hlpuart1.Init.Mode = UART_MODE_TX_RX; + hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&hlpuart1) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN LPUART1_Init 2 */ + + /* USER CODE END LPUART1_Init 2 */ } -void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) +void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(uartHandle->Instance==LPUART1) - { - /* USER CODE BEGIN LPUART1_MspInit 0 */ - - /* USER CODE END LPUART1_MspInit 0 */ - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* LPUART1 clock enable */ - __HAL_RCC_LPUART1_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - 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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF12_LPUART1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* USER CODE BEGIN LPUART1_MspInit 1 */ - - /* USER CODE END LPUART1_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (uartHandle->Instance == LPUART1) { + /* USER CODE BEGIN LPUART1_MspInit 0 */ + + /* USER CODE END LPUART1_MspInit 0 */ + LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); + + /* LPUART1 clock enable */ + __HAL_RCC_LPUART1_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**LPUART1 GPIO Configuration + PA2 ------> LPUART1_TX + PA3 ------> LPUART1_RX + */ + 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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF12_LPUART1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* USER CODE BEGIN LPUART1_MspInit 1 */ + + /* USER CODE END LPUART1_MspInit 1 */ + } } -void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) +void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle) { - if(uartHandle->Instance==LPUART1) - { - /* USER CODE BEGIN LPUART1_MspDeInit 0 */ + if (uartHandle->Instance == LPUART1) { + /* USER CODE BEGIN LPUART1_MspDeInit 0 */ - /* USER CODE END LPUART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_LPUART1_CLK_DISABLE(); + /* USER CODE END LPUART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_LPUART1_CLK_DISABLE(); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); + /**LPUART1 GPIO Configuration + PA2 ------> LPUART1_TX + PA3 ------> LPUART1_RX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2 | GPIO_PIN_3); - /* USER CODE BEGIN LPUART1_MspDeInit 1 */ + /* USER CODE BEGIN LPUART1_MspDeInit 1 */ - /* USER CODE END LPUART1_MspDeInit 1 */ - } + /* USER CODE END LPUART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - From 2968f28b9941f40d8d53f078c5ecd848f1403c54 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 18:51:03 -0700 Subject: [PATCH 105/125] Somehow Palpatine returned Logomatic and VCP work... somehow? Not through CubeMX yet and needs heavy cleanup Signed-off-by: Daniel Hansen --- .vscode/launch.json | 4 +- .../Application/Inc/CubeCAN_Config.h | 2 + CUBEMXTESTING/Application/Src/Loop.c | 3 + CUBEMXTESTING/CUBEMXTESTING.ioc | 93 +-- CUBEMXTESTING/Core/Inc/fdcan.h | 1 + CUBEMXTESTING/Core/Inc/gpio.h | 1 + CUBEMXTESTING/Core/Inc/main.h | 13 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 215 ++++--- CUBEMXTESTING/Core/Inc/stm32g4xx_it.h | 1 + CUBEMXTESTING/Core/Inc/tim.h | 1 + CUBEMXTESTING/Core/Inc/usart.h | 33 +- CUBEMXTESTING/Core/Src/fdcan.c | 525 ++++++++--------- CUBEMXTESTING/Core/Src/gpio.c | 537 +++++++++--------- CUBEMXTESTING/Core/Src/main.c | 12 +- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 24 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 212 +++---- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- CUBEMXTESTING/Core/Src/usart.c | 191 ++++--- Lib/Utils/CubeVCP/Inc/CubeVCP.h | 6 +- Lib/Utils/CubeVCP/Src/vcp.c | 103 +++- Lib/Utils/Logomatic/Src/log_driver.c | 1 - 21 files changed, 1130 insertions(+), 961 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 727fae9fd..e1e6440c0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -49,8 +49,8 @@ "svdPath": "${workspaceFolder}/Lib/Vendor/CMSIS_5/SVD/STM32G474.svd", "swoConfig": { "enabled": true, - "cpuFrequency": 160000000, - "swoFrequency": 1152000, + "cpuFrequency": 170000000, + "swoFrequency": 2000000, "source": "probe", "decoders": [ { diff --git a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h index e8345d49a..c7fe4a951 100644 --- a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h +++ b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h @@ -4,4 +4,6 @@ #define CUBEMX_CAN_TX_QUEUE_SIZE 16U #define CUBEMX_CAN_MAX_INSTANCES 3U +#define DISABLED_TIMER_GATE + #endif diff --git a/CUBEMXTESTING/Application/Src/Loop.c b/CUBEMXTESTING/Application/Src/Loop.c index fcf545e5b..e9ce7265b 100644 --- a/CUBEMXTESTING/Application/Src/Loop.c +++ b/CUBEMXTESTING/Application/Src/Loop.c @@ -3,6 +3,7 @@ #include #include "CubeCAN.h" +#include "CubeVCP.h" #include "GRCAN_MSG_ID.h" #include "GRCAN_NODE_ID.h" #include "Logomatic.h" @@ -19,4 +20,6 @@ void MainLoop(void) (void)CubeCAN_Send(chargerHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello2", 6); LOGOMATIC_VERBOSE("Main Loop %d %" PRIu32 "\n", value, HAL_GetTick()); + + VCP_SendString("Hello from VCP\n", sizeof("Hello from VCP\n") - 1); } diff --git a/CUBEMXTESTING/CUBEMXTESTING.ioc b/CUBEMXTESTING/CUBEMXTESTING.ioc index 5c3a9570d..374fc5545 100644 --- a/CUBEMXTESTING/CUBEMXTESTING.ioc +++ b/CUBEMXTESTING/CUBEMXTESTING.ioc @@ -3,9 +3,9 @@ CAD.formats=[] CAD.pinconfig=Dual CAD.provider= FDCAN1.AutoRetransmission=ENABLE -FDCAN1.CalculateBaudRateNominal=600000 -FDCAN1.CalculateTimeBitNominal=1666 -FDCAN1.CalculateTimeQuantumNominal=10.416666666666666 +FDCAN1.CalculateBaudRateNominal=1000000 +FDCAN1.CalculateTimeBitNominal=1000 +FDCAN1.CalculateTimeQuantumNominal=6.25 FDCAN1.DataPrescaler=8 FDCAN1.DataSyncJumpWidth=16 FDCAN1.DataTimeSeg1=14 @@ -19,9 +19,9 @@ FDCAN1.NominalTimeSeg1=119 FDCAN1.NominalTimeSeg2=40 FDCAN1.ProtocolException=ENABLE FDCAN2.AutoRetransmission=ENABLE -FDCAN2.CalculateBaudRateNominal=600000 -FDCAN2.CalculateTimeBitNominal=1666 -FDCAN2.CalculateTimeQuantumNominal=10.416666666666666 +FDCAN2.CalculateBaudRateNominal=1000000 +FDCAN2.CalculateTimeBitNominal=1000 +FDCAN2.CalculateTimeQuantumNominal=6.25 FDCAN2.DataPrescaler=8 FDCAN2.DataSyncJumpWidth=16 FDCAN2.DataTimeSeg1=14 @@ -34,15 +34,15 @@ FDCAN2.NominalSyncJumpWidth=16 FDCAN2.NominalTimeSeg1=119 FDCAN2.NominalTimeSeg2=40 FDCAN2.ProtocolException=ENABLE -FDCAN3.CalculateBaudRateNominal=2000000 -FDCAN3.CalculateTimeBitNominal=500 -FDCAN3.CalculateTimeQuantumNominal=166.66666666666666 +FDCAN3.CalculateBaudRateNominal=3333333 +FDCAN3.CalculateTimeBitNominal=300 +FDCAN3.CalculateTimeQuantumNominal=100.0 FDCAN3.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal,Mode FDCAN3.Mode=FDCAN_MODE_INTERNAL_LOOPBACK File.Version=6 GPIO.groupedBy=Group By Peripherals KeepUserPlacement=false -LPUART1.BaudRate=230400 +LPUART1.BaudRate=115200 LPUART1.IPParameters=BaudRate Mcu.CPN=STM32G474RET6 Mcu.Family=STM32G4 @@ -86,6 +86,7 @@ NVIC.FDCAN2_IT0_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true NVIC.FDCAN3_IT0_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true NVIC.ForceEnableDMAVector=false NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.LPUART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false @@ -164,56 +165,56 @@ ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=false ProjectManager.UseDefaultDestinationPath=true ProjectManager.UseDefaultSourcePath=true -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_TIM5_Init-TIM5-false-HAL-true,6-MX_FDCAN3_Init-FDCAN3-false-HAL-true,7-MX_LPUART1_UART_Init-LPUART1-false-HAL-true -RCC.ADC12Freq_Value=96000000 -RCC.ADC345Freq_Value=96000000 -RCC.AHBFreq_Value=96000000 -RCC.APB1Freq_Value=96000000 -RCC.APB1TimFreq_Value=96000000 -RCC.APB2Freq_Value=96000000 -RCC.APB2TimFreq_Value=96000000 +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_TIM5_Init-TIM5-false-HAL-true,6-MX_FDCAN3_Init-FDCAN3-false-HAL-true +RCC.ADC12Freq_Value=160000000 +RCC.ADC345Freq_Value=160000000 +RCC.AHBFreq_Value=160000000 +RCC.APB1Freq_Value=160000000 +RCC.APB1TimFreq_Value=160000000 +RCC.APB2Freq_Value=160000000 +RCC.APB2TimFreq_Value=160000000 RCC.CRSFreq_Value=48000000 -RCC.CortexFreq_Value=96000000 +RCC.CortexFreq_Value=160000000 RCC.EXTERNAL_CLOCK_VALUE=12288000 -RCC.FCLKCortexFreq_Value=96000000 -RCC.FDCANFreq_Value=96000000 +RCC.FCLKCortexFreq_Value=160000000 +RCC.FDCANFreq_Value=160000000 RCC.FamilyName=M -RCC.HCLKFreq_Value=96000000 -RCC.HRTIM1Freq_Value=96000000 +RCC.HCLKFreq_Value=160000000 +RCC.HRTIM1Freq_Value=160000000 RCC.HSE_VALUE=16000000 RCC.HSI48_VALUE=48000000 RCC.HSI_VALUE=16000000 -RCC.I2C1Freq_Value=96000000 -RCC.I2C2Freq_Value=96000000 -RCC.I2C3Freq_Value=96000000 -RCC.I2C4Freq_Value=96000000 -RCC.I2SFreq_Value=96000000 +RCC.I2C1Freq_Value=160000000 +RCC.I2C2Freq_Value=160000000 +RCC.I2C3Freq_Value=160000000 +RCC.I2C4Freq_Value=160000000 +RCC.I2SFreq_Value=160000000 RCC.IPParameters=ADC12Freq_Value,ADC345Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HRTIM1Freq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,PLLN,PLLPoutputFreq_Value,PLLQ,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PWRFreq_Value,QSPIFreq_Value,RNGFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value -RCC.LPTIM1Freq_Value=96000000 -RCC.LPUART1Freq_Value=96000000 +RCC.LPTIM1Freq_Value=160000000 +RCC.LPUART1Freq_Value=160000000 RCC.LSCOPinFreq_Value=32000 RCC.LSE_VALUE=32768 RCC.LSI_VALUE=32000 RCC.MCO1PinFreq_Value=16000000 -RCC.PLLN=12 -RCC.PLLPoutputFreq_Value=96000000 +RCC.PLLN=20 +RCC.PLLPoutputFreq_Value=160000000 RCC.PLLQ=RCC_PLLQ_DIV4 -RCC.PLLQoutputFreq_Value=48000000 -RCC.PLLRCLKFreq_Value=96000000 -RCC.PWRFreq_Value=96000000 -RCC.QSPIFreq_Value=96000000 -RCC.RNGFreq_Value=48000000 -RCC.SAI1Freq_Value=96000000 -RCC.SYSCLKFreq_VALUE=96000000 +RCC.PLLQoutputFreq_Value=80000000 +RCC.PLLRCLKFreq_Value=160000000 +RCC.PWRFreq_Value=160000000 +RCC.QSPIFreq_Value=160000000 +RCC.RNGFreq_Value=80000000 +RCC.SAI1Freq_Value=160000000 +RCC.SYSCLKFreq_VALUE=160000000 RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK -RCC.UART4Freq_Value=96000000 -RCC.UART5Freq_Value=96000000 -RCC.USART1Freq_Value=96000000 -RCC.USART2Freq_Value=96000000 -RCC.USART3Freq_Value=96000000 -RCC.USBFreq_Value=48000000 +RCC.UART4Freq_Value=160000000 +RCC.UART5Freq_Value=160000000 +RCC.USART1Freq_Value=160000000 +RCC.USART2Freq_Value=160000000 +RCC.USART3Freq_Value=160000000 +RCC.USBFreq_Value=80000000 RCC.VCOInputFreq_Value=16000000 -RCC.VCOOutputFreq_Value=192000000 +RCC.VCOOutputFreq_Value=320000000 TIM5.Dithering=Disable TIM5.IPParameters=Prescaler,PeriodNoDither,Dithering TIM5.PeriodNoDither=2999 diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 3597c6476..21271cf64 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -55,3 +55,4 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 37dcc0a5c..03c2faca5 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -46,3 +46,4 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index cbeced83f..2b50abc31 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,16 +28,17 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" + +#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_dma.h" -#include "stm32g4xx_ll_exti.h" -#include "stm32g4xx_ll_gpio.h" -#include "stm32g4xx_ll_pwr.h" -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_exti.h" +#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_utils.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index d12d585bd..e4db34d37 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus -extern "C" { + extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ extern "C" { /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED -/*#define HAL_ADC_MODULE_ENABLED */ + /*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -76,124 +76,123 @@ extern "C" { /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(HSE_STARTUP_TIMEOUT) -#define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined(HSI48_VALUE) -#define HSI48_VALUE \ - (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined (HSI48_VALUE) + #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined(LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined(LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined(LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined (LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined(EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -#define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ + #define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -202,12 +201,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -358,15 +357,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h index f7508212b..b2d3d042e 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h @@ -59,6 +59,7 @@ void FDCAN1_IT0_IRQHandler(void); void TIM5_IRQHandler(void); void FDCAN2_IT0_IRQHandler(void); void FDCAN3_IT0_IRQHandler(void); +void LPUART1_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index 2d20bd560..b90657cf4 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,3 +49,4 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/CUBEMXTESTING/Core/Inc/usart.h index bdec0c9cb..c259dc52a 100644 --- a/CUBEMXTESTING/Core/Inc/usart.h +++ b/CUBEMXTESTING/Core/Inc/usart.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file usart.h - * @brief This file contains all the function prototypes for - * the usart.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file usart.h + * @brief This file contains all the function prototypes for + * the usart.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 __USART_H__ @@ -49,3 +49,4 @@ void MX_LPUART1_UART_Init(void); #endif #endif /* __USART_H__ */ + diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 30b3c9dc1..08b2a1b8a 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,281 +32,298 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ + } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ + } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ + } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN3) { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) { - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN3) { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index 4d07c7993..96b5c07ab 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -33,277 +33,278 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) - */ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) +*/ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 9aa9fc444..cbeada7a4 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -99,7 +99,7 @@ int main(void) SystemClock_Config(); /* USER CODE BEGIN SysInit */ - + Logomatic_SetLogLevel(LogLevel_Debug); /* USER CODE END SysInit */ /* Initialize all configured peripherals */ @@ -153,15 +153,15 @@ int main(void) */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_3); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_3) {} - LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1); + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} + LL_PWR_EnableRange1BoostMode(); LL_RCC_HSI_Enable(); /* Wait till HSI is ready */ while (LL_RCC_HSI_IsReady() != 1) {} LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 12, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); LL_RCC_PLL_EnableDomain_SYS(); LL_RCC_PLL_Enable(); /* Wait till PLL is ready */ @@ -180,7 +180,7 @@ void SystemClock_Config(void) LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(96000000); + LL_SetSystemCoreClock(170000000); /* Update the time base */ if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index 4668755ab..2cc7d8296 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index fd2ad329f..f02085e66 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,9 +18,8 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "stm32g4xx_it.h" - #include "main.h" +#include "stm32g4xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -59,6 +58,7 @@ extern FDCAN_HandleTypeDef hfdcan1; extern FDCAN_HandleTypeDef hfdcan2; extern FDCAN_HandleTypeDef hfdcan3; +extern UART_HandleTypeDef hlpuart1; extern TIM_HandleTypeDef htim5; /* USER CODE BEGIN EV */ @@ -68,125 +68,129 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -197,59 +201,73 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + + /* USER CODE END FDCAN3_IT0_IRQn 1 */ +} + +/** + * @brief This function handles LPUART1 global interrupt. + */ +void LPUART1_IRQHandler(void) +{ + /* USER CODE BEGIN LPUART1_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END LPUART1_IRQn 0 */ + HAL_UART_IRQHandler(&hlpuart1); + /* USER CODE BEGIN LPUART1_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END LPUART1_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index ee31cf8b0..37275ddf5 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,76 +30,83 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 15; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 2999; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 15; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 2999; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) + { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ + /* USER CODE END TIM5_Init 2 */ + } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) { - if (tim_baseHandle->Instance == TIM5) { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) { - if (tim_baseHandle->Instance == TIM5) { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/Core/Src/usart.c b/CUBEMXTESTING/Core/Src/usart.c index 8350fa20b..65a476df1 100644 --- a/CUBEMXTESTING/Core/Src/usart.c +++ b/CUBEMXTESTING/Core/Src/usart.c @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file usart.c - * @brief This file provides code for the configuration - * of the USART instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file usart.c + * @brief This file provides code for the configuration + * of the USART instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "usart.h" @@ -31,93 +31,106 @@ UART_HandleTypeDef hlpuart1; void MX_LPUART1_UART_Init(void) { - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - hlpuart1.Instance = LPUART1; - hlpuart1.Init.BaudRate = 230400; - hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; - hlpuart1.Init.StopBits = UART_STOPBITS_1; - hlpuart1.Init.Parity = UART_PARITY_NONE; - hlpuart1.Init.Mode = UART_MODE_TX_RX; - hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&hlpuart1) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ + /* USER CODE BEGIN LPUART1_Init 0 */ + + /* USER CODE END LPUART1_Init 0 */ + + /* USER CODE BEGIN LPUART1_Init 1 */ + + /* USER CODE END LPUART1_Init 1 */ + hlpuart1.Instance = LPUART1; + hlpuart1.Init.BaudRate = 115200; + hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; + hlpuart1.Init.StopBits = UART_STOPBITS_1; + hlpuart1.Init.Parity = UART_PARITY_NONE; + hlpuart1.Init.Mode = UART_MODE_TX_RX; + hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&hlpuart1) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN LPUART1_Init 2 */ + + /* USER CODE END LPUART1_Init 2 */ + } -void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle) +void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (uartHandle->Instance == LPUART1) { - /* USER CODE BEGIN LPUART1_MspInit 0 */ - - /* USER CODE END LPUART1_MspInit 0 */ - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* LPUART1 clock enable */ - __HAL_RCC_LPUART1_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - 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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF12_LPUART1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* USER CODE BEGIN LPUART1_MspInit 1 */ - - /* USER CODE END LPUART1_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(uartHandle->Instance==LPUART1) + { + /* USER CODE BEGIN LPUART1_MspInit 0 */ + + /* USER CODE END LPUART1_MspInit 0 */ + LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); + + /* LPUART1 clock enable */ + __HAL_RCC_LPUART1_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**LPUART1 GPIO Configuration + PA2 ------> LPUART1_TX + PA3 ------> LPUART1_RX + */ + 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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF12_LPUART1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* LPUART1 interrupt Init */ + HAL_NVIC_SetPriority(LPUART1_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(LPUART1_IRQn); + /* USER CODE BEGIN LPUART1_MspInit 1 */ + + /* USER CODE END LPUART1_MspInit 1 */ + } } -void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle) +void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { - if (uartHandle->Instance == LPUART1) { - /* USER CODE BEGIN LPUART1_MspDeInit 0 */ + if(uartHandle->Instance==LPUART1) + { + /* USER CODE BEGIN LPUART1_MspDeInit 0 */ - /* USER CODE END LPUART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_LPUART1_CLK_DISABLE(); + /* USER CODE END LPUART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_LPUART1_CLK_DISABLE(); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2 | GPIO_PIN_3); + /**LPUART1 GPIO Configuration + PA2 ------> LPUART1_TX + PA3 ------> LPUART1_RX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); - /* USER CODE BEGIN LPUART1_MspDeInit 1 */ + /* LPUART1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(LPUART1_IRQn); + /* USER CODE BEGIN LPUART1_MspDeInit 1 */ - /* USER CODE END LPUART1_MspDeInit 1 */ - } + /* USER CODE END LPUART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/Lib/Utils/CubeVCP/Inc/CubeVCP.h b/Lib/Utils/CubeVCP/Inc/CubeVCP.h index cccb69902..98c362608 100644 --- a/Lib/Utils/CubeVCP/Inc/CubeVCP.h +++ b/Lib/Utils/CubeVCP/Inc/CubeVCP.h @@ -1,6 +1,10 @@ +#include + +#include "main.h" + #ifndef CUBE_VCP_H #define CUBE_VCP_H -// TODO +void VCP_SendString(const char *const data, uint16_t length); #endif diff --git a/Lib/Utils/CubeVCP/Src/vcp.c b/Lib/Utils/CubeVCP/Src/vcp.c index 6c7d98398..b7fce95f6 100644 --- a/Lib/Utils/CubeVCP/Src/vcp.c +++ b/Lib/Utils/CubeVCP/Src/vcp.c @@ -1,3 +1,102 @@ -#include "CubeCAN.h" +#include +#include +#include -// TODO +#include "CubeVCP.h" +#include "main.h" +#include "usart.h" + +#define CUBE_VCP_BUFFER_SIZE 256 +#define BUFFER_MASK (CUBE_VCP_BUFFER_SIZE - 1) + +static uint8_t ring_buffer[CUBE_VCP_BUFFER_SIZE]; + +static _Atomic uint16_t head = 0; +static _Atomic uint16_t tail = 0; +static _Atomic bool vcp_tx_active = false; + +__weak UART_HandleTypeDef *vcp_uart_handle = &hlpuart1; + +void VCP_SendString(const char *const str, uint16_t length) +{ + if (vcp_uart_handle == NULL || str == NULL || length == 0) { + return; + } + + uint16_t current_head = atomic_load_explicit(&head, memory_order_relaxed); + uint16_t current_tail = atomic_load_explicit(&tail, memory_order_acquire); + uint16_t used_space = current_head - current_tail; + uint16_t free_space = CUBE_VCP_BUFFER_SIZE - used_space; + + if (length > free_space) { + length = free_space; + } + + if (length == 0) { + return; + } + + uint16_t local_head = current_head; + for (uint16_t i = 0; i < length; i++) { + ring_buffer[local_head & BUFFER_MASK] = (uint8_t)str[i]; + local_head++; + } + + atomic_store_explicit(&head, local_head, memory_order_release); + + if (!atomic_load_explicit(&vcp_tx_active, memory_order_relaxed)) { + atomic_thread_fence(memory_order_acquire); + atomic_store_explicit(&vcp_tx_active, true, memory_order_relaxed); + + current_tail = atomic_load_explicit(&tail, memory_order_relaxed); + + uint16_t tail_idx = current_tail & BUFFER_MASK; + uint16_t head_idx = local_head & BUFFER_MASK; + + uint16_t send_size = (head_idx > tail_idx) ? (head_idx - tail_idx) : (CUBE_VCP_BUFFER_SIZE - tail_idx); + + if (HAL_UART_Transmit_IT(vcp_uart_handle, &ring_buffer[tail_idx], send_size) != HAL_OK) { + atomic_store_explicit(&vcp_tx_active, false, memory_order_release); + } + } +} + +void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) +{ + if (vcp_uart_handle == NULL || huart->Instance != vcp_uart_handle->Instance) { + return; + } + + uint16_t current_tail = atomic_load_explicit(&tail, memory_order_relaxed) + huart->TxXferSize; + atomic_store_explicit(&tail, current_tail, memory_order_release); + + uint16_t current_head = atomic_load_explicit(&head, memory_order_acquire); + + if (current_tail != current_head) { + uint16_t tail_idx = current_tail & BUFFER_MASK; + uint16_t head_idx = current_head & BUFFER_MASK; + + uint16_t send_size = (head_idx > tail_idx) ? (head_idx - tail_idx) : (CUBE_VCP_BUFFER_SIZE - tail_idx); + + if (HAL_UART_Transmit_IT(vcp_uart_handle, &ring_buffer[tail_idx], send_size) != HAL_OK) { + atomic_store_explicit(&vcp_tx_active, false, memory_order_release); + } + } else { + atomic_store_explicit(&vcp_tx_active, false, memory_order_release); + + current_head = atomic_load_explicit(&head, memory_order_acquire); + if (current_tail != current_head) { + if (!atomic_load_explicit(&vcp_tx_active, memory_order_relaxed)) { + atomic_store_explicit(&vcp_tx_active, true, memory_order_relaxed); + + uint16_t tail_idx = current_tail & BUFFER_MASK; + uint16_t head_idx = current_head & BUFFER_MASK; + uint16_t send_size = (head_idx > tail_idx) ? (head_idx - tail_idx) : (CUBE_VCP_BUFFER_SIZE - tail_idx); + + if (HAL_UART_Transmit_IT(vcp_uart_handle, &ring_buffer[tail_idx], send_size) != HAL_OK) { + atomic_store_explicit(&vcp_tx_active, false, memory_order_release); + } + } + } + } +} diff --git a/Lib/Utils/Logomatic/Src/log_driver.c b/Lib/Utils/Logomatic/Src/log_driver.c index ab3d26fe4..60406ac84 100644 --- a/Lib/Utils/Logomatic/Src/log_driver.c +++ b/Lib/Utils/Logomatic/Src/log_driver.c @@ -7,7 +7,6 @@ int __io_putchar(int ch) return putchar(ch); #else if (global_logomatic_driver != NULL) { - putchar(ch); return global_logomatic_driver(ch); } return ch; From bb4972d653faceac17fbff1f2913a91f5a95976e Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2026 01:52:52 +0000 Subject: [PATCH 106/125] Automatic Clang-Format: Standardized formatting automatically --- CUBEMXTESTING/Core/Inc/fdcan.h | 1 - CUBEMXTESTING/Core/Inc/gpio.h | 1 - CUBEMXTESTING/Core/Inc/main.h | 13 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 215 ++++---- CUBEMXTESTING/Core/Inc/tim.h | 1 - CUBEMXTESTING/Core/Inc/usart.h | 33 +- CUBEMXTESTING/Core/Src/fdcan.c | 525 +++++++++---------- CUBEMXTESTING/Core/Src/gpio.c | 537 ++++++++++---------- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 24 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 211 ++++---- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- CUBEMXTESTING/Core/Src/usart.c | 196 ++++--- 12 files changed, 915 insertions(+), 955 deletions(-) diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 21271cf64..3597c6476 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -55,4 +55,3 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 03c2faca5..37dcc0a5c 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -46,4 +46,3 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index 2b50abc31..cbeced83f 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,17 +28,16 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" - -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_system.h" -#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_utils.h" -#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_crs.h" #include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_gpio.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_rcc.h" +#include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_utils.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index e4db34d37..d12d585bd 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED - /*#define HAL_ADC_MODULE_ENABLED */ +/*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -76,123 +76,124 @@ /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined(HSE_STARTUP_TIMEOUT) +#define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined (HSI48_VALUE) - #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined(HSI48_VALUE) +#define HSI48_VALUE \ + (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined(LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined (LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined(LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined (LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined(LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined (EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined(EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ - #define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +#define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -201,12 +202,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -357,15 +358,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index b90657cf4..2d20bd560 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,4 +49,3 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/CUBEMXTESTING/Core/Inc/usart.h index c259dc52a..bdec0c9cb 100644 --- a/CUBEMXTESTING/Core/Inc/usart.h +++ b/CUBEMXTESTING/Core/Inc/usart.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file usart.h - * @brief This file contains all the function prototypes for - * the usart.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file usart.h + * @brief This file contains all the function prototypes for + * the usart.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 __USART_H__ @@ -49,4 +49,3 @@ void MX_LPUART1_UART_Init(void); #endif #endif /* __USART_H__ */ - diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 08b2a1b8a..30b3c9dc1 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,298 +32,281 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ - + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ - + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ - + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) { - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index 96b5c07ab..4d07c7993 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -33,278 +33,277 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) -*/ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) + */ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index 2cc7d8296..4668755ab 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index f02085e66..77f85d385 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,8 +18,9 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "main.h" #include "stm32g4xx_it.h" + +#include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -68,129 +69,125 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -201,73 +198,73 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /** - * @brief This function handles LPUART1 global interrupt. - */ + * @brief This function handles LPUART1 global interrupt. + */ void LPUART1_IRQHandler(void) { - /* USER CODE BEGIN LPUART1_IRQn 0 */ + /* USER CODE BEGIN LPUART1_IRQn 0 */ - /* USER CODE END LPUART1_IRQn 0 */ - HAL_UART_IRQHandler(&hlpuart1); - /* USER CODE BEGIN LPUART1_IRQn 1 */ + /* USER CODE END LPUART1_IRQn 0 */ + HAL_UART_IRQHandler(&hlpuart1); + /* USER CODE BEGIN LPUART1_IRQn 1 */ - /* USER CODE END LPUART1_IRQn 1 */ + /* USER CODE END LPUART1_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index 37275ddf5..ee31cf8b0 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,83 +30,76 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 15; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 2999; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) - { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) - { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 15; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 2999; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ - + /* USER CODE END TIM5_Init 2 */ } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/usart.c b/CUBEMXTESTING/Core/Src/usart.c index 65a476df1..a14deb76c 100644 --- a/CUBEMXTESTING/Core/Src/usart.c +++ b/CUBEMXTESTING/Core/Src/usart.c @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file usart.c - * @brief This file provides code for the configuration - * of the USART instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file usart.c + * @brief This file provides code for the configuration + * of the USART instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 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 "usart.h" @@ -31,106 +31,98 @@ UART_HandleTypeDef hlpuart1; void MX_LPUART1_UART_Init(void) { - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - hlpuart1.Instance = LPUART1; - hlpuart1.Init.BaudRate = 115200; - hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; - hlpuart1.Init.StopBits = UART_STOPBITS_1; - hlpuart1.Init.Parity = UART_PARITY_NONE; - hlpuart1.Init.Mode = UART_MODE_TX_RX; - hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&hlpuart1) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ - + /* USER CODE BEGIN LPUART1_Init 0 */ + + /* USER CODE END LPUART1_Init 0 */ + + /* USER CODE BEGIN LPUART1_Init 1 */ + + /* USER CODE END LPUART1_Init 1 */ + hlpuart1.Instance = LPUART1; + hlpuart1.Init.BaudRate = 115200; + hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; + hlpuart1.Init.StopBits = UART_STOPBITS_1; + hlpuart1.Init.Parity = UART_PARITY_NONE; + hlpuart1.Init.Mode = UART_MODE_TX_RX; + hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&hlpuart1) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN LPUART1_Init 2 */ + + /* USER CODE END LPUART1_Init 2 */ } -void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) +void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(uartHandle->Instance==LPUART1) - { - /* USER CODE BEGIN LPUART1_MspInit 0 */ - - /* USER CODE END LPUART1_MspInit 0 */ - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* LPUART1 clock enable */ - __HAL_RCC_LPUART1_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - 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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF12_LPUART1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* LPUART1 interrupt Init */ - HAL_NVIC_SetPriority(LPUART1_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(LPUART1_IRQn); - /* USER CODE BEGIN LPUART1_MspInit 1 */ - - /* USER CODE END LPUART1_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (uartHandle->Instance == LPUART1) { + /* USER CODE BEGIN LPUART1_MspInit 0 */ + + /* USER CODE END LPUART1_MspInit 0 */ + LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); + + /* LPUART1 clock enable */ + __HAL_RCC_LPUART1_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**LPUART1 GPIO Configuration + PA2 ------> LPUART1_TX + PA3 ------> LPUART1_RX + */ + 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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF12_LPUART1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* LPUART1 interrupt Init */ + HAL_NVIC_SetPriority(LPUART1_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(LPUART1_IRQn); + /* USER CODE BEGIN LPUART1_MspInit 1 */ + + /* USER CODE END LPUART1_MspInit 1 */ + } } -void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) +void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle) { - if(uartHandle->Instance==LPUART1) - { - /* USER CODE BEGIN LPUART1_MspDeInit 0 */ + if (uartHandle->Instance == LPUART1) { + /* USER CODE BEGIN LPUART1_MspDeInit 0 */ - /* USER CODE END LPUART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_LPUART1_CLK_DISABLE(); + /* USER CODE END LPUART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_LPUART1_CLK_DISABLE(); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); + /**LPUART1 GPIO Configuration + PA2 ------> LPUART1_TX + PA3 ------> LPUART1_RX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2 | GPIO_PIN_3); - /* LPUART1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(LPUART1_IRQn); - /* USER CODE BEGIN LPUART1_MspDeInit 1 */ + /* LPUART1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(LPUART1_IRQn); + /* USER CODE BEGIN LPUART1_MspDeInit 1 */ - /* USER CODE END LPUART1_MspDeInit 1 */ - } + /* USER CODE END LPUART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - From 267388713eba039546ea147af9fcdc5c01566d36 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Sun, 16 Aug 2026 23:19:26 -0700 Subject: [PATCH 107/125] Validate CubeMX configured setup with regeneration Also back to 160 MHz since it is a nicer number Signed-off-by: Daniel Hansen --- .vscode/launch.json | 2 +- CUBEMXTESTING/CUBEMXTESTING.ioc | 2 +- CUBEMXTESTING/Core/Inc/fdcan.h | 1 + CUBEMXTESTING/Core/Inc/gpio.h | 1 + CUBEMXTESTING/Core/Inc/main.h | 13 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 215 ++++---- CUBEMXTESTING/Core/Inc/tim.h | 1 + CUBEMXTESTING/Core/Inc/usart.h | 1 + CUBEMXTESTING/Core/Src/fdcan.c | 525 ++++++++++--------- CUBEMXTESTING/Core/Src/gpio.c | 537 ++++++++++---------- CUBEMXTESTING/Core/Src/main.c | 169 +++--- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 24 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 211 ++++---- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- CUBEMXTESTING/Core/Src/usart.c | 164 +++--- 15 files changed, 1013 insertions(+), 966 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index e1e6440c0..d7ec434ff 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -49,7 +49,7 @@ "svdPath": "${workspaceFolder}/Lib/Vendor/CMSIS_5/SVD/STM32G474.svd", "swoConfig": { "enabled": true, - "cpuFrequency": 170000000, + "cpuFrequency": 160000000, "swoFrequency": 2000000, "source": "probe", "decoders": [ diff --git a/CUBEMXTESTING/CUBEMXTESTING.ioc b/CUBEMXTESTING/CUBEMXTESTING.ioc index 374fc5545..0220c85df 100644 --- a/CUBEMXTESTING/CUBEMXTESTING.ioc +++ b/CUBEMXTESTING/CUBEMXTESTING.ioc @@ -165,7 +165,7 @@ ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=false ProjectManager.UseDefaultDestinationPath=true ProjectManager.UseDefaultSourcePath=true -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_TIM5_Init-TIM5-false-HAL-true,6-MX_FDCAN3_Init-FDCAN3-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_FDCAN1_Init-FDCAN1-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_TIM5_Init-TIM5-false-HAL-true,6-MX_FDCAN3_Init-FDCAN3-false-HAL-true,7-MX_LPUART1_UART_Init-LPUART1-false-HAL-true RCC.ADC12Freq_Value=160000000 RCC.ADC345Freq_Value=160000000 RCC.AHBFreq_Value=160000000 diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 3597c6476..21271cf64 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -55,3 +55,4 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 37dcc0a5c..03c2faca5 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -46,3 +46,4 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index cbeced83f..2b50abc31 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,16 +28,17 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" + +#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_dma.h" -#include "stm32g4xx_ll_exti.h" -#include "stm32g4xx_ll_gpio.h" -#include "stm32g4xx_ll_pwr.h" -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_exti.h" +#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_utils.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index d12d585bd..e4db34d37 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus -extern "C" { + extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ extern "C" { /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED -/*#define HAL_ADC_MODULE_ENABLED */ + /*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -76,124 +76,123 @@ extern "C" { /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(HSE_STARTUP_TIMEOUT) -#define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined(HSI48_VALUE) -#define HSI48_VALUE \ - (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined (HSI48_VALUE) + #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined(LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined(LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined(LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined (LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined(EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -#define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ + #define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -202,12 +201,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -358,15 +357,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index 2d20bd560..b90657cf4 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,3 +49,4 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/CUBEMXTESTING/Core/Inc/usart.h index bdec0c9cb..49dd0cccc 100644 --- a/CUBEMXTESTING/Core/Inc/usart.h +++ b/CUBEMXTESTING/Core/Inc/usart.h @@ -49,3 +49,4 @@ void MX_LPUART1_UART_Init(void); #endif #endif /* __USART_H__ */ + diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 30b3c9dc1..08b2a1b8a 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,281 +32,298 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ + } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ + } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ + } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN3) { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) { - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN3) { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index 4d07c7993..96b5c07ab 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -33,277 +33,278 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) - */ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) +*/ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index cbeada7a4..73a706138 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,11 +18,10 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" - #include "fdcan.h" -#include "gpio.h" -#include "tim.h" #include "usart.h" +#include "tim.h" +#include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -76,40 +75,40 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ Logomatic_SetLogLevel(LogLevel_Debug); - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - MX_LPUART1_UART_Init(); - /* USER CODE BEGIN 2 */ + /* USER CODE END SysInit */ + + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + MX_LPUART1_UART_Init(); + /* USER CODE BEGIN 2 */ CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config dataCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_DATA, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config chargerCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_CHARGER, .sending_node_id = GRCAN_Debugger}; @@ -133,59 +132,67 @@ int main(void) } LOGOMATIC_INFO("Hello World!\n"); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); HAL_Delay(100); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(170000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) + { + } + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while(LL_RCC_HSI_IsReady() != 1) + { + } + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while(LL_RCC_PLL_IsReady() != 1) + { + } + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) + { + } + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i !=0; i--); + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) + { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -204,29 +211,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ LOGOMATIC_CRITICAL("Assert failed! File %s on line %" PRIu32 "\n", file, line); - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index 4668755ab..2cc7d8296 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index 77f85d385..f02085e66 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,9 +18,8 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "stm32g4xx_it.h" - #include "main.h" +#include "stm32g4xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -69,125 +68,129 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -198,73 +201,73 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /** - * @brief This function handles LPUART1 global interrupt. - */ + * @brief This function handles LPUART1 global interrupt. + */ void LPUART1_IRQHandler(void) { - /* USER CODE BEGIN LPUART1_IRQn 0 */ + /* USER CODE BEGIN LPUART1_IRQn 0 */ - /* USER CODE END LPUART1_IRQn 0 */ - HAL_UART_IRQHandler(&hlpuart1); - /* USER CODE BEGIN LPUART1_IRQn 1 */ + /* USER CODE END LPUART1_IRQn 0 */ + HAL_UART_IRQHandler(&hlpuart1); + /* USER CODE BEGIN LPUART1_IRQn 1 */ - /* USER CODE END LPUART1_IRQn 1 */ + /* USER CODE END LPUART1_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index ee31cf8b0..37275ddf5 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,76 +30,83 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 15; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 2999; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 15; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 2999; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) + { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ + /* USER CODE END TIM5_Init 2 */ + } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) { - if (tim_baseHandle->Instance == TIM5) { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) { - if (tim_baseHandle->Instance == TIM5) { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/Core/Src/usart.c b/CUBEMXTESTING/Core/Src/usart.c index a14deb76c..836ce8d48 100644 --- a/CUBEMXTESTING/Core/Src/usart.c +++ b/CUBEMXTESTING/Core/Src/usart.c @@ -31,98 +31,106 @@ UART_HandleTypeDef hlpuart1; void MX_LPUART1_UART_Init(void) { - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - hlpuart1.Instance = LPUART1; - hlpuart1.Init.BaudRate = 115200; - hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; - hlpuart1.Init.StopBits = UART_STOPBITS_1; - hlpuart1.Init.Parity = UART_PARITY_NONE; - hlpuart1.Init.Mode = UART_MODE_TX_RX; - hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&hlpuart1) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ + /* USER CODE BEGIN LPUART1_Init 0 */ + + /* USER CODE END LPUART1_Init 0 */ + + /* USER CODE BEGIN LPUART1_Init 1 */ + + /* USER CODE END LPUART1_Init 1 */ + hlpuart1.Instance = LPUART1; + hlpuart1.Init.BaudRate = 115200; + hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; + hlpuart1.Init.StopBits = UART_STOPBITS_1; + hlpuart1.Init.Parity = UART_PARITY_NONE; + hlpuart1.Init.Mode = UART_MODE_TX_RX; + hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&hlpuart1) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN LPUART1_Init 2 */ + + /* USER CODE END LPUART1_Init 2 */ + } -void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle) +void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (uartHandle->Instance == LPUART1) { - /* USER CODE BEGIN LPUART1_MspInit 0 */ - - /* USER CODE END LPUART1_MspInit 0 */ - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* LPUART1 clock enable */ - __HAL_RCC_LPUART1_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - 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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF12_LPUART1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* LPUART1 interrupt Init */ - HAL_NVIC_SetPriority(LPUART1_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(LPUART1_IRQn); - /* USER CODE BEGIN LPUART1_MspInit 1 */ - - /* USER CODE END LPUART1_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(uartHandle->Instance==LPUART1) + { + /* USER CODE BEGIN LPUART1_MspInit 0 */ + + /* USER CODE END LPUART1_MspInit 0 */ + LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); + + /* LPUART1 clock enable */ + __HAL_RCC_LPUART1_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**LPUART1 GPIO Configuration + PA2 ------> LPUART1_TX + PA3 ------> LPUART1_RX + */ + 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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF12_LPUART1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* LPUART1 interrupt Init */ + HAL_NVIC_SetPriority(LPUART1_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(LPUART1_IRQn); + /* USER CODE BEGIN LPUART1_MspInit 1 */ + + /* USER CODE END LPUART1_MspInit 1 */ + } } -void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle) +void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { - if (uartHandle->Instance == LPUART1) { - /* USER CODE BEGIN LPUART1_MspDeInit 0 */ + if(uartHandle->Instance==LPUART1) + { + /* USER CODE BEGIN LPUART1_MspDeInit 0 */ - /* USER CODE END LPUART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_LPUART1_CLK_DISABLE(); + /* USER CODE END LPUART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_LPUART1_CLK_DISABLE(); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2 | GPIO_PIN_3); + /**LPUART1 GPIO Configuration + PA2 ------> LPUART1_TX + PA3 ------> LPUART1_RX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); - /* LPUART1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(LPUART1_IRQn); - /* USER CODE BEGIN LPUART1_MspDeInit 1 */ + /* LPUART1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(LPUART1_IRQn); + /* USER CODE BEGIN LPUART1_MspDeInit 1 */ - /* USER CODE END LPUART1_MspDeInit 1 */ - } + /* USER CODE END LPUART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + From f3f9f917db19dd746e5f3c0f73886ac1154ce1f4 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2026 06:25:14 +0000 Subject: [PATCH 108/125] Automatic Clang-Format: Standardized formatting automatically --- CUBEMXTESTING/Core/Inc/fdcan.h | 1 - CUBEMXTESTING/Core/Inc/gpio.h | 1 - CUBEMXTESTING/Core/Inc/main.h | 13 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 215 ++++---- CUBEMXTESTING/Core/Inc/tim.h | 1 - CUBEMXTESTING/Core/Inc/usart.h | 1 - CUBEMXTESTING/Core/Src/fdcan.c | 525 +++++++++---------- CUBEMXTESTING/Core/Src/gpio.c | 537 ++++++++++---------- CUBEMXTESTING/Core/Src/main.c | 169 +++--- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 24 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 211 ++++---- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- CUBEMXTESTING/Core/Src/usart.c | 164 +++--- 13 files changed, 964 insertions(+), 1011 deletions(-) diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 21271cf64..3597c6476 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -55,4 +55,3 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 03c2faca5..37dcc0a5c 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -46,4 +46,3 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index 2b50abc31..cbeced83f 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,17 +28,16 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" - -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_system.h" -#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_utils.h" -#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_crs.h" #include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_gpio.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_rcc.h" +#include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_utils.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index e4db34d37..d12d585bd 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED - /*#define HAL_ADC_MODULE_ENABLED */ +/*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -76,123 +76,124 @@ /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined(HSE_STARTUP_TIMEOUT) +#define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined (HSI48_VALUE) - #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined(HSI48_VALUE) +#define HSI48_VALUE \ + (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined(LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined (LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined(LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined (LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined(LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined (EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined(EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ - #define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +#define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -201,12 +202,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -357,15 +358,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index b90657cf4..2d20bd560 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,4 +49,3 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/CUBEMXTESTING/Core/Inc/usart.h index 49dd0cccc..bdec0c9cb 100644 --- a/CUBEMXTESTING/Core/Inc/usart.h +++ b/CUBEMXTESTING/Core/Inc/usart.h @@ -49,4 +49,3 @@ void MX_LPUART1_UART_Init(void); #endif #endif /* __USART_H__ */ - diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 08b2a1b8a..30b3c9dc1 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,298 +32,281 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ - + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ - + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ - + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) { - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index 96b5c07ab..4d07c7993 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -33,278 +33,277 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) -*/ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) + */ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 73a706138..2e4ebafd3 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,10 +18,11 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" + #include "fdcan.h" -#include "usart.h" -#include "tim.h" #include "gpio.h" +#include "tim.h" +#include "usart.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -75,40 +76,40 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ Logomatic_SetLogLevel(LogLevel_Debug); - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - MX_LPUART1_UART_Init(); - /* USER CODE BEGIN 2 */ + /* USER CODE END SysInit */ + + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + MX_LPUART1_UART_Init(); + /* USER CODE BEGIN 2 */ CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config dataCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_DATA, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config chargerCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_CHARGER, .sending_node_id = GRCAN_Debugger}; @@ -132,67 +133,59 @@ int main(void) } LOGOMATIC_INFO("Hello World!\n"); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); HAL_Delay(100); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) - { - } - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while(LL_RCC_HSI_IsReady() != 1) - { - } - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while(LL_RCC_PLL_IsReady() != 1) - { - } - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) - { - } - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i !=0; i--); - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) - { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while (LL_RCC_HSI_IsReady() != 1) {} + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while (LL_RCC_PLL_IsReady() != 1) {} + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i != 0; i--) + ; + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -211,29 +204,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ LOGOMATIC_CRITICAL("Assert failed! File %s on line %" PRIu32 "\n", file, line); - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index 2cc7d8296..4668755ab 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index f02085e66..77f85d385 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,8 +18,9 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "main.h" #include "stm32g4xx_it.h" + +#include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -68,129 +69,125 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -201,73 +198,73 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /** - * @brief This function handles LPUART1 global interrupt. - */ + * @brief This function handles LPUART1 global interrupt. + */ void LPUART1_IRQHandler(void) { - /* USER CODE BEGIN LPUART1_IRQn 0 */ + /* USER CODE BEGIN LPUART1_IRQn 0 */ - /* USER CODE END LPUART1_IRQn 0 */ - HAL_UART_IRQHandler(&hlpuart1); - /* USER CODE BEGIN LPUART1_IRQn 1 */ + /* USER CODE END LPUART1_IRQn 0 */ + HAL_UART_IRQHandler(&hlpuart1); + /* USER CODE BEGIN LPUART1_IRQn 1 */ - /* USER CODE END LPUART1_IRQn 1 */ + /* USER CODE END LPUART1_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index 37275ddf5..ee31cf8b0 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,83 +30,76 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 15; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 2999; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) - { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) - { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 15; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 2999; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ - + /* USER CODE END TIM5_Init 2 */ } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/usart.c b/CUBEMXTESTING/Core/Src/usart.c index 836ce8d48..a14deb76c 100644 --- a/CUBEMXTESTING/Core/Src/usart.c +++ b/CUBEMXTESTING/Core/Src/usart.c @@ -31,106 +31,98 @@ UART_HandleTypeDef hlpuart1; void MX_LPUART1_UART_Init(void) { - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - hlpuart1.Instance = LPUART1; - hlpuart1.Init.BaudRate = 115200; - hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; - hlpuart1.Init.StopBits = UART_STOPBITS_1; - hlpuart1.Init.Parity = UART_PARITY_NONE; - hlpuart1.Init.Mode = UART_MODE_TX_RX; - hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&hlpuart1) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ - + /* USER CODE BEGIN LPUART1_Init 0 */ + + /* USER CODE END LPUART1_Init 0 */ + + /* USER CODE BEGIN LPUART1_Init 1 */ + + /* USER CODE END LPUART1_Init 1 */ + hlpuart1.Instance = LPUART1; + hlpuart1.Init.BaudRate = 115200; + hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; + hlpuart1.Init.StopBits = UART_STOPBITS_1; + hlpuart1.Init.Parity = UART_PARITY_NONE; + hlpuart1.Init.Mode = UART_MODE_TX_RX; + hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&hlpuart1) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN LPUART1_Init 2 */ + + /* USER CODE END LPUART1_Init 2 */ } -void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) +void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(uartHandle->Instance==LPUART1) - { - /* USER CODE BEGIN LPUART1_MspInit 0 */ - - /* USER CODE END LPUART1_MspInit 0 */ - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* LPUART1 clock enable */ - __HAL_RCC_LPUART1_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - 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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF12_LPUART1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* LPUART1 interrupt Init */ - HAL_NVIC_SetPriority(LPUART1_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(LPUART1_IRQn); - /* USER CODE BEGIN LPUART1_MspInit 1 */ - - /* USER CODE END LPUART1_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (uartHandle->Instance == LPUART1) { + /* USER CODE BEGIN LPUART1_MspInit 0 */ + + /* USER CODE END LPUART1_MspInit 0 */ + LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); + + /* LPUART1 clock enable */ + __HAL_RCC_LPUART1_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**LPUART1 GPIO Configuration + PA2 ------> LPUART1_TX + PA3 ------> LPUART1_RX + */ + 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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF12_LPUART1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* LPUART1 interrupt Init */ + HAL_NVIC_SetPriority(LPUART1_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(LPUART1_IRQn); + /* USER CODE BEGIN LPUART1_MspInit 1 */ + + /* USER CODE END LPUART1_MspInit 1 */ + } } -void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) +void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle) { - if(uartHandle->Instance==LPUART1) - { - /* USER CODE BEGIN LPUART1_MspDeInit 0 */ + if (uartHandle->Instance == LPUART1) { + /* USER CODE BEGIN LPUART1_MspDeInit 0 */ - /* USER CODE END LPUART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_LPUART1_CLK_DISABLE(); + /* USER CODE END LPUART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_LPUART1_CLK_DISABLE(); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); + /**LPUART1 GPIO Configuration + PA2 ------> LPUART1_TX + PA3 ------> LPUART1_RX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2 | GPIO_PIN_3); - /* LPUART1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(LPUART1_IRQn); - /* USER CODE BEGIN LPUART1_MspDeInit 1 */ + /* LPUART1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(LPUART1_IRQn); + /* USER CODE BEGIN LPUART1_MspDeInit 1 */ - /* USER CODE END LPUART1_MspDeInit 1 */ - } + /* USER CODE END LPUART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - From 3bca88c2fb0f305d6392a2c24828b72d0a0ab606 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Mon, 17 Aug 2026 01:21:18 -0700 Subject: [PATCH 109/125] Succesful VCP Tx/Rx with logomatic! Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Application/Inc/CANdler.h | 1 + .../Application/Inc/CubeVCP_Config.h | 7 ++ CUBEMXTESTING/Application/Src/CANdler.c | 10 ++ CUBEMXTESTING/Core/Src/main.c | 7 +- Lib/Peripherals/CubeCAN/Src/can_utils.c | 1 - Lib/Utils/CubeVCP/Inc/CubeVCP.h | 73 ++++++++++++- Lib/Utils/CubeVCP/Src/PrivateInc/internal.h | 97 +++++++++++++++++ Lib/Utils/CubeVCP/Src/vcp.c | 102 ------------------ Lib/Utils/CubeVCP/Src/vcp_assert.c | 9 ++ Lib/Utils/CubeVCP/Src/vcp_global.c | 18 ++++ Lib/Utils/CubeVCP/Src/vcp_rx.c | 72 +++++++++++++ Lib/Utils/CubeVCP/Src/vcp_tx.c | 99 +++++++++++++++++ Lib/Utils/CubeVCP/vcp.cmake | 11 +- Lib/Utils/Logomatic/Inc/Logomatic.h | 2 +- 14 files changed, 398 insertions(+), 111 deletions(-) create mode 100644 CUBEMXTESTING/Application/Inc/CubeVCP_Config.h create mode 100644 Lib/Utils/CubeVCP/Src/PrivateInc/internal.h delete mode 100644 Lib/Utils/CubeVCP/Src/vcp.c create mode 100644 Lib/Utils/CubeVCP/Src/vcp_assert.c create mode 100644 Lib/Utils/CubeVCP/Src/vcp_global.c create mode 100644 Lib/Utils/CubeVCP/Src/vcp_rx.c create mode 100644 Lib/Utils/CubeVCP/Src/vcp_tx.c diff --git a/CUBEMXTESTING/Application/Inc/CANdler.h b/CUBEMXTESTING/Application/Inc/CANdler.h index 5c4a98ab6..4950e32d2 100644 --- a/CUBEMXTESTING/Application/Inc/CANdler.h +++ b/CUBEMXTESTING/Application/Inc/CANdler.h @@ -4,5 +4,6 @@ #define CANDLER_H void CANdler_Callback(const CubeCAN_Config_Context *const context, const CAN_Identifier *const identifier, const uint8_t *const data, const uint8_t size); +void CANdler_VCP_Callback(const uint8_t *const data, const uint16_t size); #endif diff --git a/CUBEMXTESTING/Application/Inc/CubeVCP_Config.h b/CUBEMXTESTING/Application/Inc/CubeVCP_Config.h new file mode 100644 index 000000000..a5b4a2b8e --- /dev/null +++ b/CUBEMXTESTING/Application/Inc/CubeVCP_Config.h @@ -0,0 +1,7 @@ +#ifndef CUBE_VCP_CONFIG_H +#define CUBE_VCP_CONFIG_H + +#define CUBE_VCP_TX_BUFFER_SIZE 256 +#define CUBE_VCP_RX_BUFFER_SIZE 8 + +#endif diff --git a/CUBEMXTESTING/Application/Src/CANdler.c b/CUBEMXTESTING/Application/Src/CANdler.c index f1d9b3580..54ab86a99 100644 --- a/CUBEMXTESTING/Application/Src/CANdler.c +++ b/CUBEMXTESTING/Application/Src/CANdler.c @@ -25,3 +25,13 @@ void CANdler_Callback(const CubeCAN_Config_Context *const context, const CAN_Ide LOGOMATIC_VERBOSE("Received on bus %d with node %d -> %d with message %d and size %u\t%.*s\n", busid, tx_node, rx_node, msg_id, size, size, (const char *const)data); } + +void CANdler_VCP_Callback(const uint8_t *const data, const uint16_t size) +{ + if (data == NULL || size == 0) { + LOGOMATIC_ERROR("CANdler_VCP_Callback: Invalid parameters received. data: %p, size: %u\n", (void *const)data, size); + return; + } + + LOGOMATIC_DEBUG("Received on VCP with size %u\t%.*s\n", size, size, (const char *const)data); +} diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 2e4ebafd3..d9224a18f 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -30,15 +30,12 @@ #include "CANdler.h" #include "CubeCAN.h" +#include "CubeVCP.h" #include "GRCAN_BUS_ID.h" #include "GRCAN_NODE_ID.h" #include "Logomatic.h" #include "Loop.h" #include "tim.h" - -// #include "can.h" -// #include "can_cfg.h" -// #include "gr_can_init.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -62,6 +59,7 @@ CubeCAN_Handle *primaryHandle = NULL; CubeCAN_Handle *dataHandle = NULL; CubeCAN_Handle *chargerHandle = NULL; +UART_HandleTypeDef *const vcp_uart_handle = &hlpuart1; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -133,6 +131,7 @@ int main(void) } LOGOMATIC_INFO("Hello World!\n"); + CubeVCP_EnableRx(CANdler_VCP_Callback); /* USER CODE END 2 */ /* Infinite loop */ diff --git a/Lib/Peripherals/CubeCAN/Src/can_utils.c b/Lib/Peripherals/CubeCAN/Src/can_utils.c index bfa641dcc..4a3e79567 100644 --- a/Lib/Peripherals/CubeCAN/Src/can_utils.c +++ b/Lib/Peripherals/CubeCAN/Src/can_utils.c @@ -1,4 +1,3 @@ -#include #include #include diff --git a/Lib/Utils/CubeVCP/Inc/CubeVCP.h b/Lib/Utils/CubeVCP/Inc/CubeVCP.h index 98c362608..aad423a84 100644 --- a/Lib/Utils/CubeVCP/Inc/CubeVCP.h +++ b/Lib/Utils/CubeVCP/Inc/CubeVCP.h @@ -5,6 +5,77 @@ #ifndef CUBE_VCP_H #define CUBE_VCP_H -void VCP_SendString(const char *const data, uint16_t length); +/** + * @brief Callback function type for UART transmission complete events in CubeVCP. + * @param huart Pointer to the UART handle. + */ +typedef void (*CubeVCP_UART_TxCpltCallback)(UART_HandleTypeDef *huart); + +/** + * @brief Callback function type for UART reception complete events in CubeVCP. + * @param huart Pointer to the UART handle. + */ +typedef void (*CubeVCP_UART_RxCpltCallback)(UART_HandleTypeDef *huart); + +/** + * @brief Callback function type for handling received data in CubeVCP. + * @param buffer Pointer to the received data buffer. + * @param length Length of the received data in bytes. + */ +typedef void (*CubeVCP_Rx_Callback)(const uint8_t *const buffer, const uint16_t length); + +/** + * @brief Pointer to the UART handle used for VCP transmission. + * + * This pointer should be set to the UART handle that is used for VCP transmission. + * It is used internally by CubeVCP to manage the transmission of data over the VCP interface. + * This can be LPUART, USART, or any other UART peripheral that is configured for VCP transmission. + * + * @note This variable should not be modified once setup by the user. + * @warning The UART handle should be properly initialized and configured before using CubeVCP functions by STM32CubeMX. + */ +extern __weak UART_HandleTypeDef *const vcp_uart_handle; + +/** + * @brief Callback function pointer for handling UART transmission complete events in CubeVCP that are not related to the VCP transmission + * + * This function pointer allows users to define their own callback function to handle UART transmission complete events that are not related to the VCP transmission. + * It is called when a UART transmission complete event occurs for a UART instance that is not the one used for VCP transmission. + * + * @note This variable should not be modified once setup by the user. + * @warning The callback function should be thread-safe and should not block for long periods of time + */ +extern __weak CubeVCP_UART_TxCpltCallback const vcp_uart_tx_cplt_callback_other; + +/** + * @brief Callback function pointer for handling UART reception complete events in CubeVCP that are not related to the VCP transmission + * + * This function pointer allows users to define their own callback function to handle UART reception complete events that are not related to the VCP transmission. + * It is called when a UART reception complete event occurs for a UART instance that is not the one used for VCP transmission. + * + * @note This variable should not be modified once setup by the user. + * @warning The callback function should be thread-safe and should not block for long periods of time + */ +extern __weak CubeVCP_UART_RxCpltCallback const vcp_uart_rx_cplt_callback_other; + +/** + * @brief Enable reception of data over the VCP interface and set the callback function to handle received data. + * @param callback Pointer to the callback function that will be called when data is received over the VCP interface. + * @retval HAL_StatusTypeDef HAL_OK if the reception was successfully enabled, HAL_ERROR if there was an error, or HAL_BUSY if the reception is already enabled. + * @note This function should be called after the UART handle has been properly initialized and configured by STM32CubeMX. + */ +HAL_StatusTypeDef CubeVCP_EnableRx(CubeVCP_Rx_Callback callback); + +/** + * @brief Send a string over the VCP interface + * @param data Pointer to the string data to be sent + * @param length Length of the string data to be sent + * @retval HAL_StatusTypeDef HAL_OK if the string was successfully queued for transmission, HAL_ERROR if there was an error, or HAL_BUSY if the internal buffer is full + * @note This function is non-blocking and will return immediately. The data will be sent in the background using interrupts. + * @note The data buffer does not have to remain valdid after the function returns, as the data will be copied into an internal buffer for transmission. + * @note The maximum length of the data that can be sent is defined by CUBE_VCP_TX_BUFFER_SIZE. If the length of the data exceeds this value, only the first CUBE_VCP_TX_BUFFER_SIZE bytes will be + * sent. + */ +HAL_StatusTypeDef VCP_SendString(const char *const data, uint16_t length); #endif diff --git a/Lib/Utils/CubeVCP/Src/PrivateInc/internal.h b/Lib/Utils/CubeVCP/Src/PrivateInc/internal.h new file mode 100644 index 000000000..0257b70f1 --- /dev/null +++ b/Lib/Utils/CubeVCP/Src/PrivateInc/internal.h @@ -0,0 +1,97 @@ +#include +#include +#include + +#include "CubeVCP_Config.h" + +#ifndef CUBE_VCP_INTERNAL_H +#define CUBE_VCP_INTERNAL_H + +/** + * @brief Callback function pointer for handling received data in CubeVCP. + * + * This function pointer allows users to define their own callback function to handle received data in CubeVCP. + * The callback function will be invoked either off of buffers or off of individual bytes, depending on the configuration of CubeVCP. + * + * @warning The callback function should be thread-safe and should not block for long periods of time + */ +extern CubeVCP_Rx_Callback vcp_rx_callback; + +/** + * @brief Mask for the ring buffer used in VCP transmission. + * + * This mask is used to wrap the head and tail indices of the ring buffer to ensure they stay within the bounds of the buffer size. + * + * @note The size of the ring buffer must be a power of two for this mask to work correctly + */ +#define VCP_TX_BUFFER_MASK (CUBE_VCP_TX_BUFFER_SIZE - 1) + + /** + * @brief Head of the ring buffer for VCP transmission. + * + * This atomic variable keeps track of the current head index in the ring buffer + * It is used to determine where new data should be written in the buffer + * + * @warning Requires atomic operations to ensure thread safety when accessed from multiple contexts + */ + extern _Atomic uint16_t vcp_ring_head; + +/** + * @brief Tail of the ring buffer for VCP transmission. + * + * This atomic variable keeps track of the current tail index in the ring buffer + * It is used to determine where data should be read from the buffer for transmission + * + * @warning Requires atomic operations to ensure thread safety when accessed from multiple contexts + */ +extern _Atomic uint16_t vcp_ring_tail; + +/** + * @brief Flag indicating whether a VCP transmission is currently active + * + * This atomic boolean variable is set to true when a transmission is in progress and false when the transmission is complete + * + * @warning Requires atomic operations to ensure thread safety when accessed from multiple contexts + */ +extern _Atomic bool vcp_tx_active; + +/** + * @brief Ring buffer for VCP transmission. + * + * This buffer is used to store data that is to be transmitted over the VCP interface + * + * @note Access only through atomic operations to ensure thread safety when accessed from multiple contexts + * @warning The size of this buffer is defined by CUBE_VCP_TX_BUFFER_SIZE and must be a power of two for proper operation + */ +extern uint8_t vcp_tx_buffer[]; + +/** + * @brief The next byte to be received in the VCP reception buffer. + * + * This variable is used to store the byte that has just been received from the UART interface before it is placed into the reception buffer. + * + * @warning Only the UART interrupt handler should modify this variable to ensure correct operation. + */ +extern uint8_t vcp_rx_byte; + +/** + * @brief Reception buffer for VCP. + * + * This buffer is used to store incoming data received over the VCP interface. + * + * @note This is a simple buffer and does not implement a ring buffer mechanism. It is the responsibility of the user to manage the data in this buffer appropriately. + * @remark Access only through atomic operations to ensure thread safety when accessed from multiple contexts + * @warning The size of this buffer is defined by CUBE_VCP_RX_BUFFER_SIZE but it does not have to be since it is not a ring buffer + */ +extern uint8_t vcp_rx_buffer[]; + +/** + * @brief Index of the next byte to be written in the VCP reception buffer. + * + * This atomic variable is used to keep track of the index where the next byte should be written in the VCP reception buffer. + * + * @warning Requires atomic operations to ensure thread safety when accessed from multiple contexts + */ +extern _Atomic uint16_t vcp_rx_index; + +#endif diff --git a/Lib/Utils/CubeVCP/Src/vcp.c b/Lib/Utils/CubeVCP/Src/vcp.c deleted file mode 100644 index b7fce95f6..000000000 --- a/Lib/Utils/CubeVCP/Src/vcp.c +++ /dev/null @@ -1,102 +0,0 @@ -#include -#include -#include - -#include "CubeVCP.h" -#include "main.h" -#include "usart.h" - -#define CUBE_VCP_BUFFER_SIZE 256 -#define BUFFER_MASK (CUBE_VCP_BUFFER_SIZE - 1) - -static uint8_t ring_buffer[CUBE_VCP_BUFFER_SIZE]; - -static _Atomic uint16_t head = 0; -static _Atomic uint16_t tail = 0; -static _Atomic bool vcp_tx_active = false; - -__weak UART_HandleTypeDef *vcp_uart_handle = &hlpuart1; - -void VCP_SendString(const char *const str, uint16_t length) -{ - if (vcp_uart_handle == NULL || str == NULL || length == 0) { - return; - } - - uint16_t current_head = atomic_load_explicit(&head, memory_order_relaxed); - uint16_t current_tail = atomic_load_explicit(&tail, memory_order_acquire); - uint16_t used_space = current_head - current_tail; - uint16_t free_space = CUBE_VCP_BUFFER_SIZE - used_space; - - if (length > free_space) { - length = free_space; - } - - if (length == 0) { - return; - } - - uint16_t local_head = current_head; - for (uint16_t i = 0; i < length; i++) { - ring_buffer[local_head & BUFFER_MASK] = (uint8_t)str[i]; - local_head++; - } - - atomic_store_explicit(&head, local_head, memory_order_release); - - if (!atomic_load_explicit(&vcp_tx_active, memory_order_relaxed)) { - atomic_thread_fence(memory_order_acquire); - atomic_store_explicit(&vcp_tx_active, true, memory_order_relaxed); - - current_tail = atomic_load_explicit(&tail, memory_order_relaxed); - - uint16_t tail_idx = current_tail & BUFFER_MASK; - uint16_t head_idx = local_head & BUFFER_MASK; - - uint16_t send_size = (head_idx > tail_idx) ? (head_idx - tail_idx) : (CUBE_VCP_BUFFER_SIZE - tail_idx); - - if (HAL_UART_Transmit_IT(vcp_uart_handle, &ring_buffer[tail_idx], send_size) != HAL_OK) { - atomic_store_explicit(&vcp_tx_active, false, memory_order_release); - } - } -} - -void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) -{ - if (vcp_uart_handle == NULL || huart->Instance != vcp_uart_handle->Instance) { - return; - } - - uint16_t current_tail = atomic_load_explicit(&tail, memory_order_relaxed) + huart->TxXferSize; - atomic_store_explicit(&tail, current_tail, memory_order_release); - - uint16_t current_head = atomic_load_explicit(&head, memory_order_acquire); - - if (current_tail != current_head) { - uint16_t tail_idx = current_tail & BUFFER_MASK; - uint16_t head_idx = current_head & BUFFER_MASK; - - uint16_t send_size = (head_idx > tail_idx) ? (head_idx - tail_idx) : (CUBE_VCP_BUFFER_SIZE - tail_idx); - - if (HAL_UART_Transmit_IT(vcp_uart_handle, &ring_buffer[tail_idx], send_size) != HAL_OK) { - atomic_store_explicit(&vcp_tx_active, false, memory_order_release); - } - } else { - atomic_store_explicit(&vcp_tx_active, false, memory_order_release); - - current_head = atomic_load_explicit(&head, memory_order_acquire); - if (current_tail != current_head) { - if (!atomic_load_explicit(&vcp_tx_active, memory_order_relaxed)) { - atomic_store_explicit(&vcp_tx_active, true, memory_order_relaxed); - - uint16_t tail_idx = current_tail & BUFFER_MASK; - uint16_t head_idx = current_head & BUFFER_MASK; - uint16_t send_size = (head_idx > tail_idx) ? (head_idx - tail_idx) : (CUBE_VCP_BUFFER_SIZE - tail_idx); - - if (HAL_UART_Transmit_IT(vcp_uart_handle, &ring_buffer[tail_idx], send_size) != HAL_OK) { - atomic_store_explicit(&vcp_tx_active, false, memory_order_release); - } - } - } - } -} diff --git a/Lib/Utils/CubeVCP/Src/vcp_assert.c b/Lib/Utils/CubeVCP/Src/vcp_assert.c new file mode 100644 index 000000000..8ca932f37 --- /dev/null +++ b/Lib/Utils/CubeVCP/Src/vcp_assert.c @@ -0,0 +1,9 @@ +#include + +#include "CubeVCP.h" +#include "CubeVCP_Config.h" +#include "main.h" + +static_assert(ATOMIC_SHORT_LOCK_FREE == 2, "CubeVCP internal ATOMIC_SHORT_LOCK_FREE must be enabled for atomic operations"); +static_assert(ATOMIC_BOOL_LOCK_FREE == 2, "CubeVCP internal ATOMIC_BOOL_LOCK_FREE must be enabled for atomic operations"); +static_assert((CUBE_VCP_TX_BUFFER_SIZE > 0) && !(CUBE_VCP_TX_BUFFER_SIZE & (CUBE_VCP_TX_BUFFER_SIZE - 1U)), "CUBE_VCP_TX_BUFFER_SIZE must be a power of two and greater than zero"); diff --git a/Lib/Utils/CubeVCP/Src/vcp_global.c b/Lib/Utils/CubeVCP/Src/vcp_global.c new file mode 100644 index 000000000..fd646a0b4 --- /dev/null +++ b/Lib/Utils/CubeVCP/Src/vcp_global.c @@ -0,0 +1,18 @@ +#include "CubeVCP.h" +#include "PrivateInc/internal.h" + +__weak UART_HandleTypeDef *const vcp_uart_handle = NULL; + +__weak CubeVCP_UART_TxCpltCallback const vcp_uart_tx_cplt_callback_other = NULL; + +CubeVCP_Rx_Callback vcp_rx_callback = NULL; + +uint8_t vcp_tx_buffer[CUBE_VCP_TX_BUFFER_SIZE]; + +_Atomic uint16_t vcp_ring_head = 0; +_Atomic uint16_t vcp_ring_tail = 0; +_Atomic bool vcp_tx_active = false; + +_Atomic uint16_t vcp_rx_index = 0; +uint8_t vcp_rx_byte; +uint8_t vcp_rx_buffer[CUBE_VCP_RX_BUFFER_SIZE]; diff --git a/Lib/Utils/CubeVCP/Src/vcp_rx.c b/Lib/Utils/CubeVCP/Src/vcp_rx.c new file mode 100644 index 000000000..617d99724 --- /dev/null +++ b/Lib/Utils/CubeVCP/Src/vcp_rx.c @@ -0,0 +1,72 @@ +#include +#include + +#include "CriticalSection.h" +#include "CubeVCP.h" +#include "CubeVCP_Config.h" +#include "Logomatic.h" +#include "PrivateInc/internal.h" +#include "main.h" + +HAL_StatusTypeDef CubeVCP_EnableRx(CubeVCP_Rx_Callback callback) +{ + static bool enabled = false; + if (enabled) { + LOGOMATIC_ERROR("CubeVCP_EnableRx: already enabled"); + return HAL_BUSY; + } + + if (vcp_uart_handle == NULL) { + LOGOMATIC_ERROR("CubeVCP_EnableRx: vcp_uart_handle is NULL"); + return HAL_ERROR; + } + + if (callback == NULL) { + LOGOMATIC_ERROR("CubeVCP_EnableRx: callback is NULL"); + return HAL_ERROR; + } + + vcp_rx_callback = callback; + + atomic_store_explicit(&vcp_rx_index, 0, memory_order_relaxed); + + HAL_StatusTypeDef status = HAL_UART_Receive_IT(vcp_uart_handle, &vcp_rx_byte, 1); + + if (status != HAL_OK) { + LOGOMATIC_ERROR("CubeVCP_EnableRx: HAL_UART_Receive_IT failed"); + return status; + } + + return HAL_OK; +} + +void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) +{ + if (huart->Instance != vcp_uart_handle->Instance) { + if (vcp_uart_rx_cplt_callback_other != NULL) { + vcp_uart_rx_cplt_callback_other(huart); + } + return; + } + + uint16_t index = atomic_load_explicit(&vcp_rx_index, memory_order_relaxed); + if (index >= CUBE_VCP_RX_BUFFER_SIZE) { + index = 0; + } + + vcp_rx_buffer[index++] = vcp_rx_byte; + + atomic_store_explicit(&vcp_rx_index, index, memory_order_release); + + if (vcp_rx_byte == '\n' || index >= CUBE_VCP_RX_BUFFER_SIZE) { + CRITICAL_SECTION + { + if (vcp_rx_callback != NULL) { + vcp_rx_callback(vcp_rx_buffer, index); + } + atomic_store_explicit(&vcp_rx_index, 0, memory_order_relaxed); + } + } + + HAL_UART_Receive_IT(vcp_uart_handle, &vcp_rx_byte, 1); +} diff --git a/Lib/Utils/CubeVCP/Src/vcp_tx.c b/Lib/Utils/CubeVCP/Src/vcp_tx.c new file mode 100644 index 000000000..045321cea --- /dev/null +++ b/Lib/Utils/CubeVCP/Src/vcp_tx.c @@ -0,0 +1,99 @@ +#include +#include +#include + +#include "CubeVCP.h" +#include "PrivateInc/internal.h" +#include "main.h" +#include "usart.h" + +HAL_StatusTypeDef VCP_SendString(const char *const str, uint16_t length) +{ + if (vcp_uart_handle == NULL || str == NULL || length == 0) { + return HAL_ERROR; + } + + uint16_t current_head = atomic_load_explicit(&vcp_ring_head, memory_order_relaxed); + uint16_t current_tail = atomic_load_explicit(&vcp_ring_tail, memory_order_acquire); + uint16_t used_space = current_head - current_tail; + uint16_t free_space = CUBE_VCP_TX_BUFFER_SIZE - used_space; + + if (length > free_space) { + length = free_space; + } + + if (length == 0) { + return HAL_BUSY; + } + + uint16_t local_head = current_head; + for (uint16_t i = 0; i < length; i++) { + vcp_tx_buffer[local_head & VCP_TX_BUFFER_MASK] = (uint8_t)str[i]; + local_head++; + } + + atomic_store_explicit(&vcp_ring_head, local_head, memory_order_release); + + if (!atomic_load_explicit(&vcp_tx_active, memory_order_relaxed)) { + atomic_thread_fence(memory_order_acquire); + atomic_store_explicit(&vcp_tx_active, true, memory_order_relaxed); + + current_tail = atomic_load_explicit(&vcp_ring_tail, memory_order_relaxed); + + uint16_t tail_idx = current_tail & VCP_TX_BUFFER_MASK; + uint16_t head_idx = local_head & VCP_TX_BUFFER_MASK; + + uint16_t send_size = (head_idx > tail_idx) ? (head_idx - tail_idx) : (CUBE_VCP_TX_BUFFER_SIZE - tail_idx); + + HAL_StatusTypeDef status = HAL_UART_Transmit_IT(vcp_uart_handle, &vcp_tx_buffer[tail_idx], send_size); + if (status != HAL_OK) { + atomic_store_explicit(&vcp_tx_active, false, memory_order_release); + return status; + } + } + + return HAL_OK; +} + +void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) +{ + if (vcp_uart_handle == NULL || huart->Instance != vcp_uart_handle->Instance) { + if (vcp_uart_tx_cplt_callback_other != NULL) { + vcp_uart_tx_cplt_callback_other(huart); + } + return; + } + + uint16_t current_tail = atomic_load_explicit(&vcp_ring_tail, memory_order_relaxed) + huart->TxXferSize; + atomic_store_explicit(&vcp_ring_tail, current_tail, memory_order_release); + + uint16_t current_head = atomic_load_explicit(&vcp_ring_head, memory_order_acquire); + + if (current_tail != current_head) { + uint16_t tail_idx = current_tail & VCP_TX_BUFFER_MASK; + uint16_t head_idx = current_head & VCP_TX_BUFFER_MASK; + + uint16_t send_size = (head_idx > tail_idx) ? (head_idx - tail_idx) : (CUBE_VCP_TX_BUFFER_SIZE - tail_idx); + + if (HAL_UART_Transmit_IT(vcp_uart_handle, &vcp_tx_buffer[tail_idx], send_size) != HAL_OK) { + atomic_store_explicit(&vcp_tx_active, false, memory_order_release); + } + } else { + atomic_store_explicit(&vcp_tx_active, false, memory_order_release); + + current_head = atomic_load_explicit(&vcp_ring_head, memory_order_acquire); + if (current_tail != current_head) { + if (!atomic_load_explicit(&vcp_tx_active, memory_order_relaxed)) { + atomic_store_explicit(&vcp_tx_active, true, memory_order_relaxed); + + uint16_t tail_idx = current_tail & VCP_TX_BUFFER_MASK; + uint16_t head_idx = current_head & VCP_TX_BUFFER_MASK; + uint16_t send_size = (head_idx > tail_idx) ? (head_idx - tail_idx) : (CUBE_VCP_TX_BUFFER_SIZE - tail_idx); + + if (HAL_UART_Transmit_IT(vcp_uart_handle, &vcp_tx_buffer[tail_idx], send_size) != HAL_OK) { + atomic_store_explicit(&vcp_tx_active, false, memory_order_release); + } + } + } + } +} diff --git a/Lib/Utils/CubeVCP/vcp.cmake b/Lib/Utils/CubeVCP/vcp.cmake index b06b1ba3e..65e3d959c 100644 --- a/Lib/Utils/CubeVCP/vcp.cmake +++ b/Lib/Utils/CubeVCP/vcp.cmake @@ -1,7 +1,14 @@ add_library(CUBE_VCP_LIB INTERFACE) -target_include_directories(CUBE_VCP_LIB INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Inc) +target_include_directories(CUBE_VCP_LIB INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/Inc +) -target_sources(CUBE_VCP_LIB INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Src/vcp.c) +target_sources(CUBE_VCP_LIB INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_assert.c + ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_global.c + ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_rx.c + ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_tx.c +) target_link_libraries(CUBE_VCP_LIB INTERFACE LOGOMATIC_LIB) diff --git a/Lib/Utils/Logomatic/Inc/Logomatic.h b/Lib/Utils/Logomatic/Inc/Logomatic.h index 1a3a29e21..061fd76d1 100644 --- a/Lib/Utils/Logomatic/Inc/Logomatic.h +++ b/Lib/Utils/Logomatic/Inc/Logomatic.h @@ -67,7 +67,7 @@ extern Logomatic_LogLevel _logomatic_loglevel; * @note This variable should not be modified once setup by the user. */ #ifndef LOGOMATIC_HOOTLTEST -extern const __weak Logomatic_Driver global_logomatic_driver; +extern __weak Logomatic_Driver const global_logomatic_driver; #endif #ifdef LOGOMATIC_HOOTLTEST From 0b43d00d9a1b9486940c32c9a55e420041390741 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Mon, 17 Aug 2026 01:30:33 -0700 Subject: [PATCH 110/125] More internal VCP configurations Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Core/Src/main.c | 2 +- Lib/Utils/CubeVCP/Inc/CubeVCP.h | 12 --------- Lib/Utils/CubeVCP/Src/PrivateInc/internal.h | 30 ++++++++++++++------- Lib/Utils/CubeVCP/Src/vcp_global.c | 3 ++- Lib/Utils/CubeVCP/Src/vcp_init.c | 30 +++++++++++++++++++++ Lib/Utils/CubeVCP/Src/vcp_rx.c | 2 ++ Lib/Utils/CubeVCP/vcp.cmake | 1 + 7 files changed, 57 insertions(+), 23 deletions(-) create mode 100644 Lib/Utils/CubeVCP/Src/vcp_init.c diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index d9224a18f..77d4691c0 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -59,7 +59,6 @@ CubeCAN_Handle *primaryHandle = NULL; CubeCAN_Handle *dataHandle = NULL; CubeCAN_Handle *chargerHandle = NULL; -UART_HandleTypeDef *const vcp_uart_handle = &hlpuart1; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -131,6 +130,7 @@ int main(void) } LOGOMATIC_INFO("Hello World!\n"); + CubeVCP_Setup(&hlpuart1); CubeVCP_EnableRx(CANdler_VCP_Callback); /* USER CODE END 2 */ diff --git a/Lib/Utils/CubeVCP/Inc/CubeVCP.h b/Lib/Utils/CubeVCP/Inc/CubeVCP.h index aad423a84..e897ab432 100644 --- a/Lib/Utils/CubeVCP/Inc/CubeVCP.h +++ b/Lib/Utils/CubeVCP/Inc/CubeVCP.h @@ -24,18 +24,6 @@ typedef void (*CubeVCP_UART_RxCpltCallback)(UART_HandleTypeDef *huart); */ typedef void (*CubeVCP_Rx_Callback)(const uint8_t *const buffer, const uint16_t length); -/** - * @brief Pointer to the UART handle used for VCP transmission. - * - * This pointer should be set to the UART handle that is used for VCP transmission. - * It is used internally by CubeVCP to manage the transmission of data over the VCP interface. - * This can be LPUART, USART, or any other UART peripheral that is configured for VCP transmission. - * - * @note This variable should not be modified once setup by the user. - * @warning The UART handle should be properly initialized and configured before using CubeVCP functions by STM32CubeMX. - */ -extern __weak UART_HandleTypeDef *const vcp_uart_handle; - /** * @brief Callback function pointer for handling UART transmission complete events in CubeVCP that are not related to the VCP transmission * diff --git a/Lib/Utils/CubeVCP/Src/PrivateInc/internal.h b/Lib/Utils/CubeVCP/Src/PrivateInc/internal.h index 0257b70f1..2a166363e 100644 --- a/Lib/Utils/CubeVCP/Src/PrivateInc/internal.h +++ b/Lib/Utils/CubeVCP/Src/PrivateInc/internal.h @@ -17,6 +17,18 @@ */ extern CubeVCP_Rx_Callback vcp_rx_callback; +/** + * @brief Pointer to the UART handle used for VCP transmission. + * + * This pointer should be set to the UART handle that is used for VCP transmission. + * It is used internally by CubeVCP to manage the transmission of data over the VCP interface. + * This can be LPUART, USART, or any other UART peripheral that is configured for VCP transmission. + * + * @note This variable should not be modified once setup by the user. + * @warning The UART handle should be properly initialized and configured before using CubeVCP functions by STM32CubeMX. + */ +extern UART_HandleTypeDef *vcp_uart_handle; + /** * @brief Mask for the ring buffer used in VCP transmission. * @@ -26,15 +38,15 @@ extern CubeVCP_Rx_Callback vcp_rx_callback; */ #define VCP_TX_BUFFER_MASK (CUBE_VCP_TX_BUFFER_SIZE - 1) - /** - * @brief Head of the ring buffer for VCP transmission. - * - * This atomic variable keeps track of the current head index in the ring buffer - * It is used to determine where new data should be written in the buffer - * - * @warning Requires atomic operations to ensure thread safety when accessed from multiple contexts - */ - extern _Atomic uint16_t vcp_ring_head; +/** + * @brief Head of the ring buffer for VCP transmission. + * + * This atomic variable keeps track of the current head index in the ring buffer + * It is used to determine where new data should be written in the buffer + * + * @warning Requires atomic operations to ensure thread safety when accessed from multiple contexts + */ +extern _Atomic uint16_t vcp_ring_head; /** * @brief Tail of the ring buffer for VCP transmission. diff --git a/Lib/Utils/CubeVCP/Src/vcp_global.c b/Lib/Utils/CubeVCP/Src/vcp_global.c index fd646a0b4..70c5ebb82 100644 --- a/Lib/Utils/CubeVCP/Src/vcp_global.c +++ b/Lib/Utils/CubeVCP/Src/vcp_global.c @@ -1,9 +1,10 @@ #include "CubeVCP.h" #include "PrivateInc/internal.h" -__weak UART_HandleTypeDef *const vcp_uart_handle = NULL; +UART_HandleTypeDef *vcp_uart_handle = NULL; __weak CubeVCP_UART_TxCpltCallback const vcp_uart_tx_cplt_callback_other = NULL; +__weak CubeVCP_UART_TxCpltCallback const vcp_uart_rx_cplt_callback_other = NULL; CubeVCP_Rx_Callback vcp_rx_callback = NULL; diff --git a/Lib/Utils/CubeVCP/Src/vcp_init.c b/Lib/Utils/CubeVCP/Src/vcp_init.c new file mode 100644 index 000000000..548aa7541 --- /dev/null +++ b/Lib/Utils/CubeVCP/Src/vcp_init.c @@ -0,0 +1,30 @@ +#include "CubeVCP.h" +#include "CubeVCP_Config.h" +#include "Logomatic.h" +#include "PrivateInc/internal.h" +#include "main.h" +#include "usart.h" + +HAL_StatusTypeDef CubeVCP_Setup(UART_HandleTypeDef *huart) +{ + static bool initialized = false; + if (initialized) { + LOGOMATIC_ERROR("CubeVCP_Setup: already initialized"); + return HAL_BUSY; + } else { + initialized = true; + } + + if (huart == NULL) { + LOGOMATIC_ERROR("CubeVCP_Setup: huart is NULL"); + return HAL_ERROR; + } + + vcp_uart_handle = huart; + + atomic_store_explicit(&vcp_ring_head, 0, memory_order_relaxed); + atomic_store_explicit(&vcp_ring_tail, 0, memory_order_relaxed); + atomic_store_explicit(&vcp_tx_active, false, memory_order_relaxed); + + return HAL_OK; +} diff --git a/Lib/Utils/CubeVCP/Src/vcp_rx.c b/Lib/Utils/CubeVCP/Src/vcp_rx.c index 617d99724..ef5388961 100644 --- a/Lib/Utils/CubeVCP/Src/vcp_rx.c +++ b/Lib/Utils/CubeVCP/Src/vcp_rx.c @@ -14,6 +14,8 @@ HAL_StatusTypeDef CubeVCP_EnableRx(CubeVCP_Rx_Callback callback) if (enabled) { LOGOMATIC_ERROR("CubeVCP_EnableRx: already enabled"); return HAL_BUSY; + } else { + enabled = true; } if (vcp_uart_handle == NULL) { diff --git a/Lib/Utils/CubeVCP/vcp.cmake b/Lib/Utils/CubeVCP/vcp.cmake index 65e3d959c..079e0468d 100644 --- a/Lib/Utils/CubeVCP/vcp.cmake +++ b/Lib/Utils/CubeVCP/vcp.cmake @@ -7,6 +7,7 @@ target_include_directories(CUBE_VCP_LIB INTERFACE target_sources(CUBE_VCP_LIB INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_assert.c ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_global.c + ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_init.c ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_rx.c ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_tx.c ) From 82c2a9c61073572058b99dff83342a6c59fa784e Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Mon, 17 Aug 2026 02:38:41 -0700 Subject: [PATCH 111/125] Improve sending half and setup and docs Signed-off-by: Daniel Hansen --- .../Application/Inc/CubeVCP_Config.h | 2 +- CUBEMXTESTING/Application/Src/Loop.c | 2 +- Lib/Utils/CubeVCP/Inc/CubeVCP.h | 15 +++++++-- Lib/Utils/CubeVCP/README.md | 3 ++ Lib/Utils/CubeVCP/Src/vcp_global.c | 2 +- Lib/Utils/CubeVCP/Src/vcp_tx.c | 31 +++++++++++-------- 6 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 Lib/Utils/CubeVCP/README.md diff --git a/CUBEMXTESTING/Application/Inc/CubeVCP_Config.h b/CUBEMXTESTING/Application/Inc/CubeVCP_Config.h index a5b4a2b8e..d843f495d 100644 --- a/CUBEMXTESTING/Application/Inc/CubeVCP_Config.h +++ b/CUBEMXTESTING/Application/Inc/CubeVCP_Config.h @@ -2,6 +2,6 @@ #define CUBE_VCP_CONFIG_H #define CUBE_VCP_TX_BUFFER_SIZE 256 -#define CUBE_VCP_RX_BUFFER_SIZE 8 +#define CUBE_VCP_RX_BUFFER_SIZE 64 #endif diff --git a/CUBEMXTESTING/Application/Src/Loop.c b/CUBEMXTESTING/Application/Src/Loop.c index e9ce7265b..7d6ff664d 100644 --- a/CUBEMXTESTING/Application/Src/Loop.c +++ b/CUBEMXTESTING/Application/Src/Loop.c @@ -21,5 +21,5 @@ void MainLoop(void) LOGOMATIC_VERBOSE("Main Loop %d %" PRIu32 "\n", value, HAL_GetTick()); - VCP_SendString("Hello from VCP\n", sizeof("Hello from VCP\n") - 1); + CubeVCP_SendString("Hello from VCP\n", sizeof("Hello from VCP\n") - 1); } diff --git a/Lib/Utils/CubeVCP/Inc/CubeVCP.h b/Lib/Utils/CubeVCP/Inc/CubeVCP.h index e897ab432..ad7a6bfcb 100644 --- a/Lib/Utils/CubeVCP/Inc/CubeVCP.h +++ b/Lib/Utils/CubeVCP/Inc/CubeVCP.h @@ -46,11 +46,20 @@ extern __weak CubeVCP_UART_TxCpltCallback const vcp_uart_tx_cplt_callback_other; */ extern __weak CubeVCP_UART_RxCpltCallback const vcp_uart_rx_cplt_callback_other; +/** + * @brief Initialize CubeVCP with the UART handle to be used for VCP communication. + * @param huart Pointer to the UART handle that will be used for VCP transmission and reception. + * @retval HAL_StatusTypeDef HAL_OK if initialization was successful, HAL_ERROR if huart is NULL, or HAL_BUSY if already initialized. + * @note This function MUST be called first before any other CubeVCP functions. + * @note The UART handle must be properly initialized and configured by STM32CubeMX before calling this function. + */ +HAL_StatusTypeDef CubeVCP_Setup(UART_HandleTypeDef *huart); + /** * @brief Enable reception of data over the VCP interface and set the callback function to handle received data. * @param callback Pointer to the callback function that will be called when data is received over the VCP interface. * @retval HAL_StatusTypeDef HAL_OK if the reception was successfully enabled, HAL_ERROR if there was an error, or HAL_BUSY if the reception is already enabled. - * @note This function should be called after the UART handle has been properly initialized and configured by STM32CubeMX. + * @note This function should be called after CubeVCP_Setup() and after the UART handle has been properly initialized and configured by STM32CubeMX. */ HAL_StatusTypeDef CubeVCP_EnableRx(CubeVCP_Rx_Callback callback); @@ -60,10 +69,10 @@ HAL_StatusTypeDef CubeVCP_EnableRx(CubeVCP_Rx_Callback callback); * @param length Length of the string data to be sent * @retval HAL_StatusTypeDef HAL_OK if the string was successfully queued for transmission, HAL_ERROR if there was an error, or HAL_BUSY if the internal buffer is full * @note This function is non-blocking and will return immediately. The data will be sent in the background using interrupts. - * @note The data buffer does not have to remain valdid after the function returns, as the data will be copied into an internal buffer for transmission. + * @note The data buffer does not have to remain valid after the function returns, as the data will be copied into an internal buffer for transmission. * @note The maximum length of the data that can be sent is defined by CUBE_VCP_TX_BUFFER_SIZE. If the length of the data exceeds this value, only the first CUBE_VCP_TX_BUFFER_SIZE bytes will be * sent. */ -HAL_StatusTypeDef VCP_SendString(const char *const data, uint16_t length); +HAL_StatusTypeDef CubeVCP_SendString(const char *const data, uint16_t length); #endif diff --git a/Lib/Utils/CubeVCP/README.md b/Lib/Utils/CubeVCP/README.md new file mode 100644 index 000000000..d8f73f935 --- /dev/null +++ b/Lib/Utils/CubeVCP/README.md @@ -0,0 +1,3 @@ +# Virtual COM Port + +TODO diff --git a/Lib/Utils/CubeVCP/Src/vcp_global.c b/Lib/Utils/CubeVCP/Src/vcp_global.c index 70c5ebb82..800392753 100644 --- a/Lib/Utils/CubeVCP/Src/vcp_global.c +++ b/Lib/Utils/CubeVCP/Src/vcp_global.c @@ -4,7 +4,7 @@ UART_HandleTypeDef *vcp_uart_handle = NULL; __weak CubeVCP_UART_TxCpltCallback const vcp_uart_tx_cplt_callback_other = NULL; -__weak CubeVCP_UART_TxCpltCallback const vcp_uart_rx_cplt_callback_other = NULL; +__weak CubeVCP_UART_RxCpltCallback const vcp_uart_rx_cplt_callback_other = NULL; CubeVCP_Rx_Callback vcp_rx_callback = NULL; diff --git a/Lib/Utils/CubeVCP/Src/vcp_tx.c b/Lib/Utils/CubeVCP/Src/vcp_tx.c index 045321cea..d0261cf7f 100644 --- a/Lib/Utils/CubeVCP/Src/vcp_tx.c +++ b/Lib/Utils/CubeVCP/Src/vcp_tx.c @@ -7,7 +7,7 @@ #include "main.h" #include "usart.h" -HAL_StatusTypeDef VCP_SendString(const char *const str, uint16_t length) +HAL_StatusTypeDef CubeVCP_SendString(const char *const str, uint16_t length) { if (vcp_uart_handle == NULL || str == NULL || length == 0) { return HAL_ERROR; @@ -35,20 +35,25 @@ HAL_StatusTypeDef VCP_SendString(const char *const str, uint16_t length) atomic_store_explicit(&vcp_ring_head, local_head, memory_order_release); if (!atomic_load_explicit(&vcp_tx_active, memory_order_relaxed)) { - atomic_thread_fence(memory_order_acquire); - atomic_store_explicit(&vcp_tx_active, true, memory_order_relaxed); + if (!atomic_exchange_explicit(&vcp_tx_active, true, memory_order_acquire)) { + /* We successfully set tx_active to true */ + uint16_t current_tail = atomic_load_explicit(&vcp_ring_tail, memory_order_acquire); + uint16_t current_head = atomic_load_explicit(&vcp_ring_head, memory_order_acquire); - current_tail = atomic_load_explicit(&vcp_ring_tail, memory_order_relaxed); - - uint16_t tail_idx = current_tail & VCP_TX_BUFFER_MASK; - uint16_t head_idx = local_head & VCP_TX_BUFFER_MASK; - - uint16_t send_size = (head_idx > tail_idx) ? (head_idx - tail_idx) : (CUBE_VCP_TX_BUFFER_SIZE - tail_idx); + if (current_tail != current_head) { + uint16_t tail_idx = current_tail & VCP_TX_BUFFER_MASK; + uint16_t head_idx = current_head & VCP_TX_BUFFER_MASK; + uint16_t send_size = (head_idx > tail_idx) ? (head_idx - tail_idx) : (CUBE_VCP_TX_BUFFER_SIZE - tail_idx); - HAL_StatusTypeDef status = HAL_UART_Transmit_IT(vcp_uart_handle, &vcp_tx_buffer[tail_idx], send_size); - if (status != HAL_OK) { - atomic_store_explicit(&vcp_tx_active, false, memory_order_release); - return status; + HAL_StatusTypeDef status = HAL_UART_Transmit_IT(vcp_uart_handle, &vcp_tx_buffer[tail_idx], send_size); + if (status != HAL_OK) { + atomic_store_explicit(&vcp_tx_active, false, memory_order_release); + return status; + } + } else { + /* No data to send, clear the active flag */ + atomic_store_explicit(&vcp_tx_active, false, memory_order_release); + } } } From 127dc0776f4f5503b01317c893c4b19be828336a Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Mon, 17 Aug 2026 02:44:41 -0700 Subject: [PATCH 112/125] Revamp vcp rx Signed-off-by: Daniel Hansen --- .../Application/Inc/CubeVCP_Config.h | 5 +- CUBEMXTESTING/Application/Src/CANdler.c | 2 +- CUBEMXTESTING/Application/Src/Loop.c | 2 +- CUBEMXTESTING/Core/Src/main.c | 1 + Lib/Utils/CubeVCP/Inc/CubeVCP.h | 2 + Lib/Utils/CubeVCP/Src/PrivateInc/internal.h | 55 +++++++++++++------ Lib/Utils/CubeVCP/Src/vcp_assert.c | 4 +- Lib/Utils/CubeVCP/Src/vcp_global.c | 9 +-- Lib/Utils/CubeVCP/Src/vcp_rx.c | 45 +++++++++++---- 9 files changed, 88 insertions(+), 37 deletions(-) diff --git a/CUBEMXTESTING/Application/Inc/CubeVCP_Config.h b/CUBEMXTESTING/Application/Inc/CubeVCP_Config.h index d843f495d..0dcf9fd11 100644 --- a/CUBEMXTESTING/Application/Inc/CubeVCP_Config.h +++ b/CUBEMXTESTING/Application/Inc/CubeVCP_Config.h @@ -1,7 +1,10 @@ #ifndef CUBE_VCP_CONFIG_H #define CUBE_VCP_CONFIG_H -#define CUBE_VCP_TX_BUFFER_SIZE 256 +// Maximum size of a message you can send over VCP +#define CUBE_VCP_TX_BUFFER_SIZE 16 + +// Maximum size of a message you can receive over VCP #define CUBE_VCP_RX_BUFFER_SIZE 64 #endif diff --git a/CUBEMXTESTING/Application/Src/CANdler.c b/CUBEMXTESTING/Application/Src/CANdler.c index 54ab86a99..5e573cdb7 100644 --- a/CUBEMXTESTING/Application/Src/CANdler.c +++ b/CUBEMXTESTING/Application/Src/CANdler.c @@ -33,5 +33,5 @@ void CANdler_VCP_Callback(const uint8_t *const data, const uint16_t size) return; } - LOGOMATIC_DEBUG("Received on VCP with size %u\t%.*s\n", size, size, (const char *const)data); + LOGOMATIC_DEBUG("VCP Rx with size %u\t%.*s\n", size, size, (const char *const)data); } diff --git a/CUBEMXTESTING/Application/Src/Loop.c b/CUBEMXTESTING/Application/Src/Loop.c index 7d6ff664d..0f805c9d3 100644 --- a/CUBEMXTESTING/Application/Src/Loop.c +++ b/CUBEMXTESTING/Application/Src/Loop.c @@ -14,7 +14,7 @@ extern int value; void MainLoop(void) { LL_GPIO_TogglePin(USER_LED_GPIO_Port, USER_LED_Pin); - LOGOMATIC_DEBUG("Main Loop %d %" PRIu32 "\n", value, HAL_GetTick()); + (void)CubeCAN_Send(primaryHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello0", 6); (void)CubeCAN_Send(dataHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello1", 6); (void)CubeCAN_Send(chargerHandle, GRCAN_Debugger, GRCAN_DEBUG_2_0, "Hello2", 6); diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 77d4691c0..2dfe6dc0d 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -132,6 +132,7 @@ int main(void) LOGOMATIC_INFO("Hello World!\n"); CubeVCP_Setup(&hlpuart1); CubeVCP_EnableRx(CANdler_VCP_Callback); + CubeVCP_SendString("Hello World!\n", sizeof("Hello World!\n") - 1); /* USER CODE END 2 */ /* Infinite loop */ diff --git a/Lib/Utils/CubeVCP/Inc/CubeVCP.h b/Lib/Utils/CubeVCP/Inc/CubeVCP.h index ad7a6bfcb..052485587 100644 --- a/Lib/Utils/CubeVCP/Inc/CubeVCP.h +++ b/Lib/Utils/CubeVCP/Inc/CubeVCP.h @@ -60,6 +60,8 @@ HAL_StatusTypeDef CubeVCP_Setup(UART_HandleTypeDef *huart); * @param callback Pointer to the callback function that will be called when data is received over the VCP interface. * @retval HAL_StatusTypeDef HAL_OK if the reception was successfully enabled, HAL_ERROR if there was an error, or HAL_BUSY if the reception is already enabled. * @note This function should be called after CubeVCP_Setup() and after the UART handle has been properly initialized and configured by STM32CubeMX. + * @note RX uses double buffering, so data reception continues uninterrupted while the callback processes data. + * @warning The callback function should be thread-safe and should not block for long periods of time, you easily can lose data on long messages if not properly configured. */ HAL_StatusTypeDef CubeVCP_EnableRx(CubeVCP_Rx_Callback callback); diff --git a/Lib/Utils/CubeVCP/Src/PrivateInc/internal.h b/Lib/Utils/CubeVCP/Src/PrivateInc/internal.h index 2a166363e..71e88bb52 100644 --- a/Lib/Utils/CubeVCP/Src/PrivateInc/internal.h +++ b/Lib/Utils/CubeVCP/Src/PrivateInc/internal.h @@ -7,6 +7,15 @@ #ifndef CUBE_VCP_INTERNAL_H #define CUBE_VCP_INTERNAL_H +/** + * @brief Mask for the ring buffer used in VCP transmission. + * + * This mask is used to wrap the head and tail indices of the ring buffer to ensure they stay within the bounds of the buffer size. + * + * @note The size of the ring buffer must be a power of two for this mask to work correctly + */ +#define VCP_TX_BUFFER_MASK (CUBE_VCP_TX_BUFFER_SIZE - 1) + /** * @brief Callback function pointer for handling received data in CubeVCP. * @@ -29,15 +38,6 @@ extern CubeVCP_Rx_Callback vcp_rx_callback; */ extern UART_HandleTypeDef *vcp_uart_handle; -/** - * @brief Mask for the ring buffer used in VCP transmission. - * - * This mask is used to wrap the head and tail indices of the ring buffer to ensure they stay within the bounds of the buffer size. - * - * @note The size of the ring buffer must be a power of two for this mask to work correctly - */ -#define VCP_TX_BUFFER_MASK (CUBE_VCP_TX_BUFFER_SIZE - 1) - /** * @brief Head of the ring buffer for VCP transmission. * @@ -87,23 +87,44 @@ extern uint8_t vcp_tx_buffer[]; extern uint8_t vcp_rx_byte; /** - * @brief Reception buffer for VCP. + * @brief Staging buffer for VCP reception. + * + * This buffer is used to temporarily store received data before it is processed by the application. + * + * @note The size of this buffer is defined by CUBE_VCP_RX_BUFFER_SIZE + */ +extern uint8_t vcp_callback_staging[]; + +/** + * @brief Double reception buffers for VCP (2 buffers for seamless RX without pauses). * - * This buffer is used to store incoming data received over the VCP interface. + * These buffers are used for double-buffering: one buffer fills while the ISR processes and swaps to the other. + * This allows continuous RX reception without data loss or pauses. * - * @note This is a simple buffer and does not implement a ring buffer mechanism. It is the responsibility of the user to manage the data in this buffer appropriately. - * @remark Access only through atomic operations to ensure thread safety when accessed from multiple contexts - * @warning The size of this buffer is defined by CUBE_VCP_RX_BUFFER_SIZE but it does not have to be since it is not a ring buffer + * @note The size of each buffer is defined by CUBE_VCP_RX_BUFFER_SIZE + * @remark Access only from ISR context to ensure thread safety */ extern uint8_t vcp_rx_buffer[]; /** - * @brief Index of the next byte to be written in the VCP reception buffer. + * @brief Index of the next byte to be written in the current VCP reception buffer. + * + * This atomic variable is used to keep track of the index where the next byte should be written in the current VCP reception buffer. + * When the buffer fills or a newline is received, the callback is invoked and this index is reset to 0. + * + * @warning Requires atomic operations to ensure thread safety when accessed from multiple contexts + */ +extern uint16_t vcp_rx_index; + +/** + * @brief Index of the current RX buffer (0 or 1) being written to by the ISR. * - * This atomic variable is used to keep track of the index where the next byte should be written in the VCP reception buffer. + * This atomic variable tracks which of the two receive buffers is currently being filled. + * When a buffer fills or a newline is received, the callback is invoked with that buffer's contents, + * and the index automatically switches to the other buffer. This allows continuous RX without data loss. * * @warning Requires atomic operations to ensure thread safety when accessed from multiple contexts */ -extern _Atomic uint16_t vcp_rx_index; +extern uint8_t vcp_rx_current_buffer; #endif diff --git a/Lib/Utils/CubeVCP/Src/vcp_assert.c b/Lib/Utils/CubeVCP/Src/vcp_assert.c index 8ca932f37..fa1519972 100644 --- a/Lib/Utils/CubeVCP/Src/vcp_assert.c +++ b/Lib/Utils/CubeVCP/Src/vcp_assert.c @@ -4,6 +4,8 @@ #include "CubeVCP_Config.h" #include "main.h" -static_assert(ATOMIC_SHORT_LOCK_FREE == 2, "CubeVCP internal ATOMIC_SHORT_LOCK_FREE must be enabled for atomic operations"); static_assert(ATOMIC_BOOL_LOCK_FREE == 2, "CubeVCP internal ATOMIC_BOOL_LOCK_FREE must be enabled for atomic operations"); +static_assert(ATOMIC_SHORT_LOCK_FREE == 2, "CubeVCP internal ATOMIC_SHORT_LOCK_FREE must be enabled for atomic operations"); + static_assert((CUBE_VCP_TX_BUFFER_SIZE > 0) && !(CUBE_VCP_TX_BUFFER_SIZE & (CUBE_VCP_TX_BUFFER_SIZE - 1U)), "CUBE_VCP_TX_BUFFER_SIZE must be a power of two and greater than zero"); +static_assert(CUBE_VCP_RX_BUFFER_SIZE > 8, "CUBE_VCP_RX_BUFFER_SIZE must be greater than 8 bytes to ensure useful command input is possible. It is recommended to set this to at least 32 bytes for practical use cases."); diff --git a/Lib/Utils/CubeVCP/Src/vcp_global.c b/Lib/Utils/CubeVCP/Src/vcp_global.c index 800392753..cc1f0755e 100644 --- a/Lib/Utils/CubeVCP/Src/vcp_global.c +++ b/Lib/Utils/CubeVCP/Src/vcp_global.c @@ -10,10 +10,11 @@ CubeVCP_Rx_Callback vcp_rx_callback = NULL; uint8_t vcp_tx_buffer[CUBE_VCP_TX_BUFFER_SIZE]; -_Atomic uint16_t vcp_ring_head = 0; -_Atomic uint16_t vcp_ring_tail = 0; -_Atomic bool vcp_tx_active = false; +_Atomic uint16_t vcp_ring_head; +_Atomic uint16_t vcp_ring_tail; +_Atomic bool vcp_tx_active; -_Atomic uint16_t vcp_rx_index = 0; +uint16_t vcp_rx_index; uint8_t vcp_rx_byte; uint8_t vcp_rx_buffer[CUBE_VCP_RX_BUFFER_SIZE]; +uint8_t vcp_callback_staging[CUBE_VCP_RX_BUFFER_SIZE]; diff --git a/Lib/Utils/CubeVCP/Src/vcp_rx.c b/Lib/Utils/CubeVCP/Src/vcp_rx.c index ef5388961..9255db438 100644 --- a/Lib/Utils/CubeVCP/Src/vcp_rx.c +++ b/Lib/Utils/CubeVCP/Src/vcp_rx.c @@ -51,24 +51,45 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) return; } - uint16_t index = atomic_load_explicit(&vcp_rx_index, memory_order_relaxed); - if (index >= CUBE_VCP_RX_BUFFER_SIZE) { - index = 0; - } + uint8_t received_byte = vcp_rx_byte; + uint16_t index = vcp_rx_index; - vcp_rx_buffer[index++] = vcp_rx_byte; + vcp_rx_buffer[index++] = received_byte; - atomic_store_explicit(&vcp_rx_index, index, memory_order_release); + if (received_byte == '\n' || index >= CUBE_VCP_RX_BUFFER_SIZE) { + uint16_t filled_len = index; - if (vcp_rx_byte == '\n' || index >= CUBE_VCP_RX_BUFFER_SIZE) { CRITICAL_SECTION { - if (vcp_rx_callback != NULL) { - vcp_rx_callback(vcp_rx_buffer, index); + for (uint16_t i = 0; i < filled_len; i++) { + vcp_callback_staging[i] = vcp_rx_buffer[i]; } - atomic_store_explicit(&vcp_rx_index, 0, memory_order_relaxed); + vcp_rx_index = 0; + } + + __HAL_UART_CLEAR_OREFLAG(huart); + __HAL_UART_CLEAR_NEFLAG(huart); + __HAL_UART_CLEAR_FEFLAG(huart); + + if (HAL_UART_Receive_IT(vcp_uart_handle, &vcp_rx_byte, 1) != HAL_OK) { + huart->RxState = HAL_UART_STATE_READY; + HAL_UART_Receive_IT(vcp_uart_handle, &vcp_rx_byte, 1); + } + + if (vcp_rx_callback != NULL) { + vcp_rx_callback(vcp_callback_staging, filled_len); } - } - HAL_UART_Receive_IT(vcp_uart_handle, &vcp_rx_byte, 1); + } else { + CRITICAL_SECTION + { + vcp_rx_index = index; + } + + __HAL_UART_CLEAR_OREFLAG(huart); + if (HAL_UART_Receive_IT(vcp_uart_handle, &vcp_rx_byte, 1) != HAL_OK) { + huart->RxState = HAL_UART_STATE_READY; + HAL_UART_Receive_IT(vcp_uart_handle, &vcp_rx_byte, 1); + } + } } From c3700cb957c65e3a64d3ad514fcfa1f46cb39818 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2026 09:45:13 +0000 Subject: [PATCH 113/125] Automatic CMake Format: Standardized formatting automatically --- Lib/Utils/CubeVCP/vcp.cmake | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Lib/Utils/CubeVCP/vcp.cmake b/Lib/Utils/CubeVCP/vcp.cmake index 079e0468d..e79b445b0 100644 --- a/Lib/Utils/CubeVCP/vcp.cmake +++ b/Lib/Utils/CubeVCP/vcp.cmake @@ -1,15 +1,15 @@ add_library(CUBE_VCP_LIB INTERFACE) -target_include_directories(CUBE_VCP_LIB INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/Inc -) +target_include_directories(CUBE_VCP_LIB INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Inc) -target_sources(CUBE_VCP_LIB INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_assert.c - ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_global.c - ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_init.c - ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_rx.c - ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_tx.c +target_sources( + CUBE_VCP_LIB + INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_assert.c + ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_global.c + ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_init.c + ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_rx.c + ${CMAKE_CURRENT_LIST_DIR}/Src/vcp_tx.c ) target_link_libraries(CUBE_VCP_LIB INTERFACE LOGOMATIC_LIB) From 4768c5989b13a53a7514ccc66385fe71b42f9d67 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2026 09:46:57 +0000 Subject: [PATCH 114/125] Automatic Clang-Format: Standardized formatting automatically --- CUBEMXTESTING/Core/Src/main.c | 4 ++-- Lib/Utils/CubeVCP/Src/vcp_assert.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 2dfe6dc0d..7344dd05d 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -130,9 +130,9 @@ int main(void) } LOGOMATIC_INFO("Hello World!\n"); - CubeVCP_Setup(&hlpuart1); + CubeVCP_Setup(&hlpuart1); CubeVCP_EnableRx(CANdler_VCP_Callback); - CubeVCP_SendString("Hello World!\n", sizeof("Hello World!\n") - 1); + CubeVCP_SendString("Hello World!\n", sizeof("Hello World!\n") - 1); /* USER CODE END 2 */ /* Infinite loop */ diff --git a/Lib/Utils/CubeVCP/Src/vcp_assert.c b/Lib/Utils/CubeVCP/Src/vcp_assert.c index fa1519972..927f04be6 100644 --- a/Lib/Utils/CubeVCP/Src/vcp_assert.c +++ b/Lib/Utils/CubeVCP/Src/vcp_assert.c @@ -8,4 +8,5 @@ static_assert(ATOMIC_BOOL_LOCK_FREE == 2, "CubeVCP internal ATOMIC_BOOL_LOCK_FRE static_assert(ATOMIC_SHORT_LOCK_FREE == 2, "CubeVCP internal ATOMIC_SHORT_LOCK_FREE must be enabled for atomic operations"); static_assert((CUBE_VCP_TX_BUFFER_SIZE > 0) && !(CUBE_VCP_TX_BUFFER_SIZE & (CUBE_VCP_TX_BUFFER_SIZE - 1U)), "CUBE_VCP_TX_BUFFER_SIZE must be a power of two and greater than zero"); -static_assert(CUBE_VCP_RX_BUFFER_SIZE > 8, "CUBE_VCP_RX_BUFFER_SIZE must be greater than 8 bytes to ensure useful command input is possible. It is recommended to set this to at least 32 bytes for practical use cases."); +static_assert(CUBE_VCP_RX_BUFFER_SIZE > 8, + "CUBE_VCP_RX_BUFFER_SIZE must be greater than 8 bytes to ensure useful command input is possible. It is recommended to set this to at least 32 bytes for practical use cases."); From 718f7ba591c0fb691ae4668abe77b6b8fa3906b5 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Mon, 17 Aug 2026 03:01:58 -0700 Subject: [PATCH 115/125] Re-enable CAN timer gate Signed-off-by: Daniel Hansen --- CUBEMXTESTING/Application/Inc/CubeCAN_Config.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h index c7fe4a951..e8345d49a 100644 --- a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h +++ b/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h @@ -4,6 +4,4 @@ #define CUBEMX_CAN_TX_QUEUE_SIZE 16U #define CUBEMX_CAN_MAX_INSTANCES 3U -#define DISABLED_TIMER_GATE - #endif From 3db6ac2eee63956caf6b1b3a9e516e40e939dab0 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Mon, 17 Aug 2026 03:04:34 -0700 Subject: [PATCH 116/125] Fix CubeMX timer values off of new clock settings Signed-off-by: Daniel Hansen --- CUBEMXTESTING/CUBEMXTESTING.ioc | 4 +- CUBEMXTESTING/Core/Inc/fdcan.h | 1 + CUBEMXTESTING/Core/Inc/gpio.h | 1 + CUBEMXTESTING/Core/Inc/main.h | 13 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 215 ++++---- CUBEMXTESTING/Core/Inc/tim.h | 1 + CUBEMXTESTING/Core/Inc/usart.h | 1 + CUBEMXTESTING/Core/Src/fdcan.c | 525 ++++++++++--------- CUBEMXTESTING/Core/Src/gpio.c | 537 ++++++++++---------- CUBEMXTESTING/Core/Src/main.c | 169 +++--- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 24 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 211 ++++---- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- CUBEMXTESTING/Core/Src/usart.c | 164 +++--- 14 files changed, 1013 insertions(+), 966 deletions(-) diff --git a/CUBEMXTESTING/CUBEMXTESTING.ioc b/CUBEMXTESTING/CUBEMXTESTING.ioc index 0220c85df..eb06b6e12 100644 --- a/CUBEMXTESTING/CUBEMXTESTING.ioc +++ b/CUBEMXTESTING/CUBEMXTESTING.ioc @@ -217,8 +217,8 @@ RCC.VCOInputFreq_Value=16000000 RCC.VCOOutputFreq_Value=320000000 TIM5.Dithering=Disable TIM5.IPParameters=Prescaler,PeriodNoDither,Dithering -TIM5.PeriodNoDither=2999 -TIM5.Prescaler=15 +TIM5.PeriodNoDither=499 +TIM5.Prescaler=159 VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals VP_SYS_VS_Systick.Mode=SysTick diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 3597c6476..21271cf64 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -55,3 +55,4 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 37dcc0a5c..03c2faca5 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -46,3 +46,4 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index cbeced83f..2b50abc31 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,16 +28,17 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" + +#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_dma.h" -#include "stm32g4xx_ll_exti.h" -#include "stm32g4xx_ll_gpio.h" -#include "stm32g4xx_ll_pwr.h" -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_exti.h" +#include "stm32g4xx_ll_cortex.h" #include "stm32g4xx_ll_utils.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index d12d585bd..e4db34d37 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus -extern "C" { + extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ extern "C" { /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED -/*#define HAL_ADC_MODULE_ENABLED */ + /*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -76,124 +76,123 @@ extern "C" { /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(HSE_STARTUP_TIMEOUT) -#define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined(HSI48_VALUE) -#define HSI48_VALUE \ - (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined (HSI48_VALUE) + #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined(LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined(LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined (LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined(LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined (LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined(EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -#define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ + #define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -202,12 +201,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -358,15 +357,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index 2d20bd560..b90657cf4 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,3 +49,4 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ + diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/CUBEMXTESTING/Core/Inc/usart.h index bdec0c9cb..49dd0cccc 100644 --- a/CUBEMXTESTING/Core/Inc/usart.h +++ b/CUBEMXTESTING/Core/Inc/usart.h @@ -49,3 +49,4 @@ void MX_LPUART1_UART_Init(void); #endif #endif /* __USART_H__ */ + diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 30b3c9dc1..08b2a1b8a 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,281 +32,298 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ + } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ + } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ + } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } else if (fdcanHandle->Instance == FDCAN3) { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if(HAL_RCC_FDCAN_CLK_ENABLED==1){ + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) { - if (fdcanHandle->Instance == FDCAN1) { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } else if (fdcanHandle->Instance == FDCAN3) { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if(fdcanHandle->Instance==FDCAN1) + { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN2) + { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } + else if(fdcanHandle->Instance==FDCAN3) + { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if(HAL_RCC_FDCAN_CLK_ENABLED==0){ + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index 4d07c7993..96b5c07ab 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -33,277 +33,278 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) - */ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) +*/ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index 7344dd05d..d201e4a35 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,11 +18,10 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" - #include "fdcan.h" -#include "gpio.h" -#include "tim.h" #include "usart.h" +#include "tim.h" +#include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -73,40 +72,40 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ Logomatic_SetLogLevel(LogLevel_Debug); - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - MX_LPUART1_UART_Init(); - /* USER CODE BEGIN 2 */ + /* USER CODE END SysInit */ + + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + MX_LPUART1_UART_Init(); + /* USER CODE BEGIN 2 */ CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config dataCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_DATA, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config chargerCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_CHARGER, .sending_node_id = GRCAN_Debugger}; @@ -133,59 +132,67 @@ int main(void) CubeVCP_Setup(&hlpuart1); CubeVCP_EnableRx(CANdler_VCP_Callback); CubeVCP_SendString("Hello World!\n", sizeof("Hello World!\n") - 1); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); HAL_Delay(100); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) + { + } + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while(LL_RCC_HSI_IsReady() != 1) + { + } + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while(LL_RCC_PLL_IsReady() != 1) + { + } + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) + { + } + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i !=0; i--); + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) + { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -204,29 +211,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ LOGOMATIC_CRITICAL("Assert failed! File %s on line %" PRIu32 "\n", file, line); - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index 4668755ab..2cc7d8296 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index 77f85d385..f02085e66 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,9 +18,8 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "stm32g4xx_it.h" - #include "main.h" +#include "stm32g4xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -69,125 +68,129 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -198,73 +201,73 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /** - * @brief This function handles LPUART1 global interrupt. - */ + * @brief This function handles LPUART1 global interrupt. + */ void LPUART1_IRQHandler(void) { - /* USER CODE BEGIN LPUART1_IRQn 0 */ + /* USER CODE BEGIN LPUART1_IRQn 0 */ - /* USER CODE END LPUART1_IRQn 0 */ - HAL_UART_IRQHandler(&hlpuart1); - /* USER CODE BEGIN LPUART1_IRQn 1 */ + /* USER CODE END LPUART1_IRQn 0 */ + HAL_UART_IRQHandler(&hlpuart1); + /* USER CODE BEGIN LPUART1_IRQn 1 */ - /* USER CODE END LPUART1_IRQn 1 */ + /* USER CODE END LPUART1_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index ee31cf8b0..cc6e6a92e 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,76 +30,83 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 15; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 2999; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 159; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 499; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) + { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ + /* USER CODE END TIM5_Init 2 */ + } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) { - if (tim_baseHandle->Instance == TIM5) { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) { - if (tim_baseHandle->Instance == TIM5) { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if(tim_baseHandle->Instance==TIM5) + { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + diff --git a/CUBEMXTESTING/Core/Src/usart.c b/CUBEMXTESTING/Core/Src/usart.c index a14deb76c..836ce8d48 100644 --- a/CUBEMXTESTING/Core/Src/usart.c +++ b/CUBEMXTESTING/Core/Src/usart.c @@ -31,98 +31,106 @@ UART_HandleTypeDef hlpuart1; void MX_LPUART1_UART_Init(void) { - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - hlpuart1.Instance = LPUART1; - hlpuart1.Init.BaudRate = 115200; - hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; - hlpuart1.Init.StopBits = UART_STOPBITS_1; - hlpuart1.Init.Parity = UART_PARITY_NONE; - hlpuart1.Init.Mode = UART_MODE_TX_RX; - hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&hlpuart1) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ + /* USER CODE BEGIN LPUART1_Init 0 */ + + /* USER CODE END LPUART1_Init 0 */ + + /* USER CODE BEGIN LPUART1_Init 1 */ + + /* USER CODE END LPUART1_Init 1 */ + hlpuart1.Instance = LPUART1; + hlpuart1.Init.BaudRate = 115200; + hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; + hlpuart1.Init.StopBits = UART_STOPBITS_1; + hlpuart1.Init.Parity = UART_PARITY_NONE; + hlpuart1.Init.Mode = UART_MODE_TX_RX; + hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&hlpuart1) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN LPUART1_Init 2 */ + + /* USER CODE END LPUART1_Init 2 */ + } -void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle) +void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (uartHandle->Instance == LPUART1) { - /* USER CODE BEGIN LPUART1_MspInit 0 */ - - /* USER CODE END LPUART1_MspInit 0 */ - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* LPUART1 clock enable */ - __HAL_RCC_LPUART1_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - 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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF12_LPUART1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* LPUART1 interrupt Init */ - HAL_NVIC_SetPriority(LPUART1_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(LPUART1_IRQn); - /* USER CODE BEGIN LPUART1_MspInit 1 */ - - /* USER CODE END LPUART1_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(uartHandle->Instance==LPUART1) + { + /* USER CODE BEGIN LPUART1_MspInit 0 */ + + /* USER CODE END LPUART1_MspInit 0 */ + LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); + + /* LPUART1 clock enable */ + __HAL_RCC_LPUART1_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**LPUART1 GPIO Configuration + PA2 ------> LPUART1_TX + PA3 ------> LPUART1_RX + */ + 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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF12_LPUART1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* LPUART1 interrupt Init */ + HAL_NVIC_SetPriority(LPUART1_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(LPUART1_IRQn); + /* USER CODE BEGIN LPUART1_MspInit 1 */ + + /* USER CODE END LPUART1_MspInit 1 */ + } } -void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle) +void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { - if (uartHandle->Instance == LPUART1) { - /* USER CODE BEGIN LPUART1_MspDeInit 0 */ + if(uartHandle->Instance==LPUART1) + { + /* USER CODE BEGIN LPUART1_MspDeInit 0 */ - /* USER CODE END LPUART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_LPUART1_CLK_DISABLE(); + /* USER CODE END LPUART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_LPUART1_CLK_DISABLE(); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2 | GPIO_PIN_3); + /**LPUART1 GPIO Configuration + PA2 ------> LPUART1_TX + PA3 ------> LPUART1_RX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); - /* LPUART1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(LPUART1_IRQn); - /* USER CODE BEGIN LPUART1_MspDeInit 1 */ + /* LPUART1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(LPUART1_IRQn); + /* USER CODE BEGIN LPUART1_MspDeInit 1 */ - /* USER CODE END LPUART1_MspDeInit 1 */ - } + /* USER CODE END LPUART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ + From 749a9073f0b1725521f17a63a2959f9d7e4ad54f Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2026 10:05:53 +0000 Subject: [PATCH 117/125] Automatic Clang-Format: Standardized formatting automatically --- CUBEMXTESTING/Core/Inc/fdcan.h | 1 - CUBEMXTESTING/Core/Inc/gpio.h | 1 - CUBEMXTESTING/Core/Inc/main.h | 13 +- CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h | 215 ++++---- CUBEMXTESTING/Core/Inc/tim.h | 1 - CUBEMXTESTING/Core/Inc/usart.h | 1 - CUBEMXTESTING/Core/Src/fdcan.c | 525 +++++++++---------- CUBEMXTESTING/Core/Src/gpio.c | 537 ++++++++++---------- CUBEMXTESTING/Core/Src/main.c | 169 +++--- CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c | 24 +- CUBEMXTESTING/Core/Src/stm32g4xx_it.c | 211 ++++---- CUBEMXTESTING/Core/Src/tim.c | 113 ++-- CUBEMXTESTING/Core/Src/usart.c | 164 +++--- 13 files changed, 964 insertions(+), 1011 deletions(-) diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/CUBEMXTESTING/Core/Inc/fdcan.h index 21271cf64..3597c6476 100644 --- a/CUBEMXTESTING/Core/Inc/fdcan.h +++ b/CUBEMXTESTING/Core/Inc/fdcan.h @@ -55,4 +55,3 @@ void MX_FDCAN3_Init(void); #endif #endif /* __FDCAN_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/CUBEMXTESTING/Core/Inc/gpio.h index 03c2faca5..37dcc0a5c 100644 --- a/CUBEMXTESTING/Core/Inc/gpio.h +++ b/CUBEMXTESTING/Core/Inc/gpio.h @@ -46,4 +46,3 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/main.h b/CUBEMXTESTING/Core/Inc/main.h index 2b50abc31..cbeced83f 100644 --- a/CUBEMXTESTING/Core/Inc/main.h +++ b/CUBEMXTESTING/Core/Inc/main.h @@ -28,17 +28,16 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" - -#include "stm32g4xx_ll_rcc.h" #include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_system.h" -#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_utils.h" -#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_crs.h" #include "stm32g4xx_ll_dma.h" +#include "stm32g4xx_ll_exti.h" #include "stm32g4xx_ll_gpio.h" +#include "stm32g4xx_ll_pwr.h" +#include "stm32g4xx_ll_rcc.h" +#include "stm32g4xx_ll_system.h" +#include "stm32g4xx_ll_utils.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h index e4db34d37..d12d585bd 100644 --- a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ b/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h @@ -23,7 +23,7 @@ #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Exported types ------------------------------------------------------------*/ @@ -31,12 +31,12 @@ /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED - /*#define HAL_ADC_MODULE_ENABLED */ +/*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ /*#define HAL_CRC_MODULE_ENABLED */ @@ -76,123 +76,124 @@ /* ########################## Register Callbacks selection ############################## */ /** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U + * @brief This is the list of modules where register callback can be used + */ +#define USE_HAL_ADC_REGISTER_CALLBACKS 0U +#define USE_HAL_COMP_REGISTER_CALLBACKS 0U +#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U +#define USE_HAL_DAC_REGISTER_CALLBACKS 0U +#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U +#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U +#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_I2C_REGISTER_CALLBACKS 0U +#define USE_HAL_I2S_REGISTER_CALLBACKS 0U +#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U +#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U +#define USE_HAL_NAND_REGISTER_CALLBACKS 0U +#define USE_HAL_NOR_REGISTER_CALLBACKS 0U +#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U +#define USE_HAL_PCD_REGISTER_CALLBACKS 0U +#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U +#define USE_HAL_RNG_REGISTER_CALLBACKS 0U +#define USE_HAL_RTC_REGISTER_CALLBACKS 0U +#define USE_HAL_SAI_REGISTER_CALLBACKS 0U +#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U +#define USE_HAL_SPI_REGISTER_CALLBACKS 0U +#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U +#define USE_HAL_TIM_REGISTER_CALLBACKS 0U +#define USE_HAL_UART_REGISTER_CALLBACKS 0U +#define USE_HAL_USART_REGISTER_CALLBACKS 0U +#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined (HSE_STARTUP_TIMEOUT) - #define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ -#endif /* HSE_STARTUP_TIMEOUT */ + * @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 (16000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined(HSE_STARTUP_TIMEOUT) +#define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ + * @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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high precision clock to - * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. - * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency - * which is subject to manufacturing process variations. - */ -#if !defined (HSI48_VALUE) - #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. - The real value my vary depending on manufacturing process variations.*/ -#endif /* HSI48_VALUE */ + * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. + * This internal oscillator is mainly dedicated to provide a high precision clock to + * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. + * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency + * which is subject to manufacturing process variations. + */ +#if !defined(HSI48_VALUE) +#define HSI48_VALUE \ + (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. \ + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined(LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system frequency - */ -#if !defined (LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ + * @brief External Low Speed oscillator (LSE) value. + * This value is used by the UART, RTC HAL module to compute the system frequency + */ +#if !defined(LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ -#if !defined (LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ +#if !defined(LSE_STARTUP_TIMEOUT) +#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ /** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source - * frequency, this source is inserted directly through I2S_CKIN pad. - */ -#if !defined (EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ -#endif /* EXTERNAL_CLOCK_VALUE */ + * @brief External clock source for I2S and SAI peripherals + * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined(EXTERNAL_CLOCK_VALUE) +#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 - */ + * @brief This is the HAL system configuration section + */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define INSTRUCTION_CACHE_ENABLE 1U +#define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ - #define USE_FULL_ASSERT 1U + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +#define USE_FULL_ASSERT 1U /* ################## SPI peripheral configuration ########################## */ @@ -201,12 +202,12 @@ The real value may vary depending on the variations in voltage and temperature.* * Deactivated: CRC code cleaned from driver */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** - * @brief Include module's header file - */ + * @brief Include module's header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" @@ -357,15 +358,15 @@ The real value may vary depending on the variations in voltage and temperature.* #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ -#ifdef USE_FULL_ASSERT +#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 - */ + * @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); diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/CUBEMXTESTING/Core/Inc/tim.h index b90657cf4..2d20bd560 100644 --- a/CUBEMXTESTING/Core/Inc/tim.h +++ b/CUBEMXTESTING/Core/Inc/tim.h @@ -49,4 +49,3 @@ void MX_TIM5_Init(void); #endif #endif /* __TIM_H__ */ - diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/CUBEMXTESTING/Core/Inc/usart.h index 49dd0cccc..bdec0c9cb 100644 --- a/CUBEMXTESTING/Core/Inc/usart.h +++ b/CUBEMXTESTING/Core/Inc/usart.h @@ -49,4 +49,3 @@ void MX_LPUART1_UART_Init(void); #endif #endif /* __USART_H__ */ - diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/CUBEMXTESTING/Core/Src/fdcan.c index 08b2a1b8a..30b3c9dc1 100644 --- a/CUBEMXTESTING/Core/Src/fdcan.c +++ b/CUBEMXTESTING/Core/Src/fdcan.c @@ -32,298 +32,281 @@ FDCAN_HandleTypeDef hfdcan3; void MX_FDCAN1_Init(void) { - /* USER CODE BEGIN FDCAN1_Init 0 */ - - /* USER CODE END FDCAN1_Init 0 */ - - /* USER CODE BEGIN FDCAN1_Init 1 */ - - /* USER CODE END FDCAN1_Init 1 */ - hfdcan1.Instance = FDCAN1; - hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan1.Init.AutoRetransmission = ENABLE; - hfdcan1.Init.TransmitPause = DISABLE; - hfdcan1.Init.ProtocolException = ENABLE; - hfdcan1.Init.NominalPrescaler = 1; - hfdcan1.Init.NominalSyncJumpWidth = 16; - hfdcan1.Init.NominalTimeSeg1 = 119; - hfdcan1.Init.NominalTimeSeg2 = 40; - hfdcan1.Init.DataPrescaler = 8; - hfdcan1.Init.DataSyncJumpWidth = 16; - hfdcan1.Init.DataTimeSeg1 = 14; - hfdcan1.Init.DataTimeSeg2 = 5; - hfdcan1.Init.StdFiltersNbr = 0; - hfdcan1.Init.ExtFiltersNbr = 2; - hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN1_Init 2 */ - - /* USER CODE END FDCAN1_Init 2 */ - + /* USER CODE BEGIN FDCAN1_Init 0 */ + + /* USER CODE END FDCAN1_Init 0 */ + + /* USER CODE BEGIN FDCAN1_Init 1 */ + + /* USER CODE END FDCAN1_Init 1 */ + hfdcan1.Instance = FDCAN1; + hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan1.Init.AutoRetransmission = ENABLE; + hfdcan1.Init.TransmitPause = DISABLE; + hfdcan1.Init.ProtocolException = ENABLE; + hfdcan1.Init.NominalPrescaler = 1; + hfdcan1.Init.NominalSyncJumpWidth = 16; + hfdcan1.Init.NominalTimeSeg1 = 119; + hfdcan1.Init.NominalTimeSeg2 = 40; + hfdcan1.Init.DataPrescaler = 8; + hfdcan1.Init.DataSyncJumpWidth = 16; + hfdcan1.Init.DataTimeSeg1 = 14; + hfdcan1.Init.DataTimeSeg2 = 5; + hfdcan1.Init.StdFiltersNbr = 0; + hfdcan1.Init.ExtFiltersNbr = 2; + hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN1_Init 2 */ + + /* USER CODE END FDCAN1_Init 2 */ } /* FDCAN2 init function */ void MX_FDCAN2_Init(void) { - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ - + /* USER CODE BEGIN FDCAN2_Init 0 */ + + /* USER CODE END FDCAN2_Init 0 */ + + /* USER CODE BEGIN FDCAN2_Init 1 */ + + /* USER CODE END FDCAN2_Init 1 */ + hfdcan2.Instance = FDCAN2; + hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan2.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan2.Init.AutoRetransmission = ENABLE; + hfdcan2.Init.TransmitPause = DISABLE; + hfdcan2.Init.ProtocolException = ENABLE; + hfdcan2.Init.NominalPrescaler = 1; + hfdcan2.Init.NominalSyncJumpWidth = 16; + hfdcan2.Init.NominalTimeSeg1 = 119; + hfdcan2.Init.NominalTimeSeg2 = 40; + hfdcan2.Init.DataPrescaler = 8; + hfdcan2.Init.DataSyncJumpWidth = 16; + hfdcan2.Init.DataTimeSeg1 = 14; + hfdcan2.Init.DataTimeSeg2 = 5; + hfdcan2.Init.StdFiltersNbr = 0; + hfdcan2.Init.ExtFiltersNbr = 2; + hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN2_Init 2 */ + + /* USER CODE END FDCAN2_Init 2 */ } /* FDCAN3 init function */ void MX_FDCAN3_Init(void) { - /* USER CODE BEGIN FDCAN3_Init 0 */ - - /* USER CODE END FDCAN3_Init 0 */ - - /* USER CODE BEGIN FDCAN3_Init 1 */ - - /* USER CODE END FDCAN3_Init 1 */ - hfdcan3.Instance = FDCAN3; - hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; - hfdcan3.Init.AutoRetransmission = DISABLE; - hfdcan3.Init.TransmitPause = DISABLE; - hfdcan3.Init.ProtocolException = DISABLE; - hfdcan3.Init.NominalPrescaler = 16; - hfdcan3.Init.NominalSyncJumpWidth = 1; - hfdcan3.Init.NominalTimeSeg1 = 1; - hfdcan3.Init.NominalTimeSeg2 = 1; - hfdcan3.Init.DataPrescaler = 1; - hfdcan3.Init.DataSyncJumpWidth = 1; - hfdcan3.Init.DataTimeSeg1 = 1; - hfdcan3.Init.DataTimeSeg2 = 1; - hfdcan3.Init.StdFiltersNbr = 0; - hfdcan3.Init.ExtFiltersNbr = 0; - hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN3_Init 2 */ - - /* USER CODE END FDCAN3_Init 2 */ - + /* USER CODE BEGIN FDCAN3_Init 0 */ + + /* USER CODE END FDCAN3_Init 0 */ + + /* USER CODE BEGIN FDCAN3_Init 1 */ + + /* USER CODE END FDCAN3_Init 1 */ + hfdcan3.Instance = FDCAN3; + hfdcan3.Init.ClockDivider = FDCAN_CLOCK_DIV1; + hfdcan3.Init.FrameFormat = FDCAN_FRAME_CLASSIC; + hfdcan3.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; + hfdcan3.Init.AutoRetransmission = DISABLE; + hfdcan3.Init.TransmitPause = DISABLE; + hfdcan3.Init.ProtocolException = DISABLE; + hfdcan3.Init.NominalPrescaler = 16; + hfdcan3.Init.NominalSyncJumpWidth = 1; + hfdcan3.Init.NominalTimeSeg1 = 1; + hfdcan3.Init.NominalTimeSeg2 = 1; + hfdcan3.Init.DataPrescaler = 1; + hfdcan3.Init.DataSyncJumpWidth = 1; + hfdcan3.Init.DataTimeSeg1 = 1; + hfdcan3.Init.DataTimeSeg2 = 1; + hfdcan3.Init.StdFiltersNbr = 0; + hfdcan3.Init.ExtFiltersNbr = 0; + hfdcan3.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; + if (HAL_FDCAN_Init(&hfdcan3) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN FDCAN3_Init 2 */ + + /* USER CODE END FDCAN3_Init 2 */ } -static uint32_t HAL_RCC_FDCAN_CLK_ENABLED=0; +static uint32_t HAL_RCC_FDCAN_CLK_ENABLED = 0; -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspInit 0 */ - - /* USER CODE END FDCAN1_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN1 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN1 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspInit 1 */ - - /* USER CODE END FDCAN1_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspInit 0 */ - - /* USER CODE END FDCAN3_MspInit 0 */ - - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN3 clock enable */ - HAL_RCC_FDCAN_CLK_ENABLED++; - if(HAL_RCC_FDCAN_CLK_ENABLED==1){ - __HAL_RCC_FDCAN_CLK_ENABLE(); - } - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* FDCAN3 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspInit 1 */ - - /* USER CODE END FDCAN3_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspInit 0 */ + + /* USER CODE END FDCAN1_MspInit 0 */ + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN1 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN1 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspInit 1 */ + + /* USER CODE END FDCAN1_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspInit 0 */ + + /* USER CODE END FDCAN2_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN2 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* FDCAN2 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspInit 1 */ + + /* USER CODE END FDCAN2_MspInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspInit 0 */ + + /* USER CODE END FDCAN3_MspInit 0 */ + + LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); + + /* FDCAN3 clock enable */ + HAL_RCC_FDCAN_CLK_ENABLED++; + if (HAL_RCC_FDCAN_CLK_ENABLED == 1) { + __HAL_RCC_FDCAN_CLK_ENABLE(); + } + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF11_FDCAN3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* FDCAN3 interrupt Init */ + HAL_NVIC_SetPriority(FDCAN3_IT0_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspInit 1 */ + + /* USER CODE END FDCAN3_MspInit 1 */ + } } -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* fdcanHandle) +void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) { - if(fdcanHandle->Instance==FDCAN1) - { - /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ - - /* USER CODE END FDCAN1_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN1 GPIO Configuration - PB8-BOOT0 ------> FDCAN1_RX - PB9 ------> FDCAN1_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); - - /* FDCAN1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); - /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ - - /* USER CODE END FDCAN1_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN2) - { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12|GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } - else if(fdcanHandle->Instance==FDCAN3) - { - /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ - - /* USER CODE END FDCAN3_MspDeInit 0 */ - /* Peripheral clock disable */ - HAL_RCC_FDCAN_CLK_ENABLED--; - if(HAL_RCC_FDCAN_CLK_ENABLED==0){ - __HAL_RCC_FDCAN_CLK_DISABLE(); - } - - /**FDCAN3 GPIO Configuration - PA8 ------> FDCAN3_RX - PA15 ------> FDCAN3_TX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_15); - - /* FDCAN3 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); - /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ - - /* USER CODE END FDCAN3_MspDeInit 1 */ - } + if (fdcanHandle->Instance == FDCAN1) { + /* USER CODE BEGIN FDCAN1_MspDeInit 0 */ + + /* USER CODE END FDCAN1_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN1 GPIO Configuration + PB8-BOOT0 ------> FDCAN1_RX + PB9 ------> FDCAN1_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8 | GPIO_PIN_9); + + /* FDCAN1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn); + /* USER CODE BEGIN FDCAN1_MspDeInit 1 */ + + /* USER CODE END FDCAN1_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN2) { + /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ + + /* USER CODE END FDCAN2_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN2 GPIO Configuration + PB12 ------> FDCAN2_RX + PB13 ------> FDCAN2_TX + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); + + /* FDCAN2 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); + /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ + + /* USER CODE END FDCAN2_MspDeInit 1 */ + } else if (fdcanHandle->Instance == FDCAN3) { + /* USER CODE BEGIN FDCAN3_MspDeInit 0 */ + + /* USER CODE END FDCAN3_MspDeInit 0 */ + /* Peripheral clock disable */ + HAL_RCC_FDCAN_CLK_ENABLED--; + if (HAL_RCC_FDCAN_CLK_ENABLED == 0) { + __HAL_RCC_FDCAN_CLK_DISABLE(); + } + + /**FDCAN3 GPIO Configuration + PA8 ------> FDCAN3_RX + PA15 ------> FDCAN3_TX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8 | GPIO_PIN_15); + + /* FDCAN3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(FDCAN3_IT0_IRQn); + /* USER CODE BEGIN FDCAN3_MspDeInit 1 */ + + /* USER CODE END FDCAN3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/CUBEMXTESTING/Core/Src/gpio.c index 96b5c07ab..4d07c7993 100644 --- a/CUBEMXTESTING/Core/Src/gpio.c +++ b/CUBEMXTESTING/Core/Src/gpio.c @@ -33,278 +33,277 @@ /* USER CODE END 1 */ /** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) -*/ + * Analog + * Input + * Output + * EVENT_OUT + * EXTI + * Free pins are configured automatically as Analog (this feature is enabled through + * the Code Generation settings) + */ void MX_GPIO_Init(void) { - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); - - /**/ - GPIO_InitStruct.Pin = USER_BUTTON_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = USER_LED_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - + LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); + + /**/ + LL_GPIO_ResetOutputPin(USER_LED_GPIO_Port, USER_LED_Pin); + + /**/ + GPIO_InitStruct.Pin = USER_BUTTON_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_BUTTON_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = USER_LED_Pin; + GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_1; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_14; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_15; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_8; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_9; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_12; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_4; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_6; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_7; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOB, &GPIO_InitStruct); } /* USER CODE BEGIN 2 */ diff --git a/CUBEMXTESTING/Core/Src/main.c b/CUBEMXTESTING/Core/Src/main.c index d201e4a35..7344dd05d 100644 --- a/CUBEMXTESTING/Core/Src/main.c +++ b/CUBEMXTESTING/Core/Src/main.c @@ -18,10 +18,11 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" + #include "fdcan.h" -#include "usart.h" -#include "tim.h" #include "gpio.h" +#include "tim.h" +#include "usart.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -72,40 +73,40 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ Logomatic_SetLogLevel(LogLevel_Debug); - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_FDCAN1_Init(); - MX_FDCAN2_Init(); - MX_TIM5_Init(); - MX_FDCAN3_Init(); - MX_LPUART1_UART_Init(); - /* USER CODE BEGIN 2 */ + /* USER CODE END SysInit */ + + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_FDCAN1_Init(); + MX_FDCAN2_Init(); + MX_TIM5_Init(); + MX_FDCAN3_Init(); + MX_LPUART1_UART_Init(); + /* USER CODE BEGIN 2 */ CubeCAN_Config primaryCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_PRIMARY, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config dataCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_DATA, .sending_node_id = GRCAN_Debugger}; CubeCAN_Config chargerCanConfig = {.rx_callback = CANdler_Callback, .context.busid_user_context = GRCAN_BUS_CHARGER, .sending_node_id = GRCAN_Debugger}; @@ -132,67 +133,59 @@ int main(void) CubeVCP_Setup(&hlpuart1); CubeVCP_EnableRx(CANdler_VCP_Callback); CubeVCP_SendString("Hello World!\n", sizeof("Hello World!\n") - 1); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ MainLoop(); HAL_Delay(100); } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) - { - } - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while(LL_RCC_HSI_IsReady() != 1) - { - } - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while(LL_RCC_PLL_IsReady() != 1) - { - } - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) - { - } - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i !=0; i--); - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK) - { - Error_Handler(); - } + LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); + while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} + LL_PWR_EnableRange1BoostMode(); + LL_RCC_HSI_Enable(); + /* Wait till HSI is ready */ + while (LL_RCC_HSI_IsReady() != 1) {} + + LL_RCC_HSI_SetCalibTrimming(64); + LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); + LL_RCC_PLL_EnableDomain_SYS(); + LL_RCC_PLL_Enable(); + /* Wait till PLL is ready */ + while (LL_RCC_PLL_IsReady() != 1) {} + + LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); + /* Wait till System clock is ready */ + while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} + + /* Insure 1us transition state at intermediate medium speed clock*/ + for (__IO uint32_t i = (170 >> 1); i != 0; i--) + ; + + /* Set AHB prescaler*/ + LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); + LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); + LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); + LL_SetSystemCoreClock(160000000); + + /* Update the time base */ + if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -211,29 +204,29 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) {} - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ LOGOMATIC_CRITICAL("Assert failed! File %s on line %" PRIu32 "\n", file, line); - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c index 2cc7d8296..4668755ab 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c @@ -57,27 +57,27 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ + * Initializes the Global MSP. + */ void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + /* USER CODE BEGIN MspInit 0 */ - /* USER CODE END MspInit 0 */ + /* USER CODE END MspInit 0 */ - __HAL_RCC_SYSCFG_CLK_ENABLE(); - __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); - /* System interrupt init*/ + /* System interrupt init*/ - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_PWREx_DisableUCPDDeadBattery(); - /* USER CODE BEGIN MspInit 1 */ + /* USER CODE BEGIN MspInit 1 */ - /* USER CODE END MspInit 1 */ + /* USER CODE END MspInit 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c index f02085e66..77f85d385 100644 --- a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c +++ b/CUBEMXTESTING/Core/Src/stm32g4xx_it.c @@ -18,8 +18,9 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "main.h" #include "stm32g4xx_it.h" + +#include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -68,129 +69,125 @@ extern TIM_HandleTypeDef htim5; /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** - * @brief This function handles Non maskable interrupt. - */ + * @brief This function handles Non maskable interrupt. + */ void NMI_Handler(void) { - /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ - /* USER CODE END NonMaskableInt_IRQn 0 */ - /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 0 */ + /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) {} - /* USER CODE END NonMaskableInt_IRQn 1 */ + /* USER CODE END NonMaskableInt_IRQn 1 */ } /** - * @brief This function handles Hard fault interrupt. - */ + * @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 */ - } + /* 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. - */ + * @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 */ - } + /* 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 Prefetch fault, memory access fault. - */ + * @brief This function handles Prefetch 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 */ - } + /* 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. - */ + * @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 */ - } + /* 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. - */ + * @brief This function handles System service call via SWI instruction. + */ void SVC_Handler(void) { - /* USER CODE BEGIN SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 0 */ - /* USER CODE END SVCall_IRQn 0 */ - /* USER CODE BEGIN SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 0 */ + /* USER CODE BEGIN SVCall_IRQn 1 */ - /* USER CODE END SVCall_IRQn 1 */ + /* USER CODE END SVCall_IRQn 1 */ } /** - * @brief This function handles Debug monitor. - */ + * @brief This function handles Debug monitor. + */ void DebugMon_Handler(void) { - /* USER CODE BEGIN DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 0 */ - /* USER CODE END DebugMonitor_IRQn 0 */ - /* USER CODE BEGIN DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 0 */ + /* USER CODE BEGIN DebugMonitor_IRQn 1 */ - /* USER CODE END DebugMonitor_IRQn 1 */ + /* USER CODE END DebugMonitor_IRQn 1 */ } /** - * @brief This function handles Pendable request for system service. - */ + * @brief This function handles Pendable request for system service. + */ void PendSV_Handler(void) { - /* USER CODE BEGIN PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 0 */ - /* USER CODE END PendSV_IRQn 0 */ - /* USER CODE BEGIN PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 0 */ + /* USER CODE BEGIN PendSV_IRQn 1 */ - /* USER CODE END PendSV_IRQn 1 */ + /* USER CODE END PendSV_IRQn 1 */ } /** - * @brief This function handles System tick timer. - */ + * @brief This function handles System tick timer. + */ void SysTick_Handler(void) { - /* USER CODE BEGIN SysTick_IRQn 0 */ + /* 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 0 */ + HAL_IncTick(); + /* USER CODE BEGIN SysTick_IRQn 1 */ - /* USER CODE END SysTick_IRQn 1 */ + /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ @@ -201,73 +198,73 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles FDCAN1 interrupt 0. - */ + * @brief This function handles FDCAN1 interrupt 0. + */ void FDCAN1_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */ - /* USER CODE END FDCAN1_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan1); - /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan1); + /* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */ - /* USER CODE END FDCAN1_IT0_IRQn 1 */ + /* USER CODE END FDCAN1_IT0_IRQn 1 */ } /** - * @brief This function handles TIM5 global interrupt. - */ + * @brief This function handles TIM5 global interrupt. + */ void TIM5_IRQHandler(void) { - /* USER CODE BEGIN TIM5_IRQn 0 */ + /* USER CODE BEGIN TIM5_IRQn 0 */ - /* USER CODE END TIM5_IRQn 0 */ - HAL_TIM_IRQHandler(&htim5); - /* USER CODE BEGIN TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 0 */ + HAL_TIM_IRQHandler(&htim5); + /* USER CODE BEGIN TIM5_IRQn 1 */ - /* USER CODE END TIM5_IRQn 1 */ + /* USER CODE END TIM5_IRQn 1 */ } /** - * @brief This function handles FDCAN2 interrupt 0. - */ + * @brief This function handles FDCAN2 interrupt 0. + */ void FDCAN2_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan2); + /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - /* USER CODE END FDCAN2_IT0_IRQn 1 */ + /* USER CODE END FDCAN2_IT0_IRQn 1 */ } /** - * @brief This function handles FDCAN3 interrupt 0. - */ + * @brief This function handles FDCAN3 interrupt 0. + */ void FDCAN3_IT0_IRQHandler(void) { - /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ + /* USER CODE BEGIN FDCAN3_IT0_IRQn 0 */ - /* USER CODE END FDCAN3_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan3); - /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 0 */ + HAL_FDCAN_IRQHandler(&hfdcan3); + /* USER CODE BEGIN FDCAN3_IT0_IRQn 1 */ - /* USER CODE END FDCAN3_IT0_IRQn 1 */ + /* USER CODE END FDCAN3_IT0_IRQn 1 */ } /** - * @brief This function handles LPUART1 global interrupt. - */ + * @brief This function handles LPUART1 global interrupt. + */ void LPUART1_IRQHandler(void) { - /* USER CODE BEGIN LPUART1_IRQn 0 */ + /* USER CODE BEGIN LPUART1_IRQn 0 */ - /* USER CODE END LPUART1_IRQn 0 */ - HAL_UART_IRQHandler(&hlpuart1); - /* USER CODE BEGIN LPUART1_IRQn 1 */ + /* USER CODE END LPUART1_IRQn 0 */ + HAL_UART_IRQHandler(&hlpuart1); + /* USER CODE BEGIN LPUART1_IRQn 1 */ - /* USER CODE END LPUART1_IRQn 1 */ + /* USER CODE END LPUART1_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/CUBEMXTESTING/Core/Src/tim.c b/CUBEMXTESTING/Core/Src/tim.c index cc6e6a92e..1f6110e86 100644 --- a/CUBEMXTESTING/Core/Src/tim.c +++ b/CUBEMXTESTING/Core/Src/tim.c @@ -30,83 +30,76 @@ TIM_HandleTypeDef htim5; void MX_TIM5_Init(void) { - /* USER CODE BEGIN TIM5_Init 0 */ - - /* USER CODE END TIM5_Init 0 */ - - TIM_ClockConfigTypeDef sClockSourceConfig = {0}; - TIM_MasterConfigTypeDef sMasterConfig = {0}; - - /* USER CODE BEGIN TIM5_Init 1 */ - - /* USER CODE END TIM5_Init 1 */ - htim5.Instance = TIM5; - htim5.Init.Prescaler = 159; - htim5.Init.CounterMode = TIM_COUNTERMODE_UP; - htim5.Init.Period = 499; - htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - if (HAL_TIM_Base_Init(&htim5) != HAL_OK) - { - Error_Handler(); - } - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) - { - Error_Handler(); - } - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN TIM5_Init 2 */ + /* USER CODE BEGIN TIM5_Init 0 */ + + /* USER CODE END TIM5_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM5_Init 1 */ + + /* USER CODE END TIM5_Init 1 */ + htim5.Instance = TIM5; + htim5.Init.Prescaler = 159; + htim5.Init.CounterMode = TIM_COUNTERMODE_UP; + htim5.Init.Period = 499; + htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN TIM5_Init 2 */ HAL_TIM_Base_Start_IT(&htim5); - /* USER CODE END TIM5_Init 2 */ - + /* USER CODE END TIM5_Init 2 */ } -void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspInit 0 */ - /* USER CODE END TIM5_MspInit 0 */ - /* TIM5 clock enable */ - __HAL_RCC_TIM5_CLK_ENABLE(); + /* USER CODE END TIM5_MspInit 0 */ + /* TIM5 clock enable */ + __HAL_RCC_TIM5_CLK_ENABLE(); - /* TIM5 interrupt Init */ - HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspInit 1 */ + /* TIM5 interrupt Init */ + HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspInit 1 */ - /* USER CODE END TIM5_MspInit 1 */ - } + /* USER CODE END TIM5_MspInit 1 */ + } } -void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *tim_baseHandle) { - if(tim_baseHandle->Instance==TIM5) - { - /* USER CODE BEGIN TIM5_MspDeInit 0 */ + if (tim_baseHandle->Instance == TIM5) { + /* USER CODE BEGIN TIM5_MspDeInit 0 */ - /* USER CODE END TIM5_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_TIM5_CLK_DISABLE(); + /* USER CODE END TIM5_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM5_CLK_DISABLE(); - /* TIM5 interrupt Deinit */ - HAL_NVIC_DisableIRQ(TIM5_IRQn); - /* USER CODE BEGIN TIM5_MspDeInit 1 */ + /* TIM5 interrupt Deinit */ + HAL_NVIC_DisableIRQ(TIM5_IRQn); + /* USER CODE BEGIN TIM5_MspDeInit 1 */ - /* USER CODE END TIM5_MspDeInit 1 */ - } + /* USER CODE END TIM5_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/CUBEMXTESTING/Core/Src/usart.c b/CUBEMXTESTING/Core/Src/usart.c index 836ce8d48..a14deb76c 100644 --- a/CUBEMXTESTING/Core/Src/usart.c +++ b/CUBEMXTESTING/Core/Src/usart.c @@ -31,106 +31,98 @@ UART_HandleTypeDef hlpuart1; void MX_LPUART1_UART_Init(void) { - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - hlpuart1.Instance = LPUART1; - hlpuart1.Init.BaudRate = 115200; - hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; - hlpuart1.Init.StopBits = UART_STOPBITS_1; - hlpuart1.Init.Parity = UART_PARITY_NONE; - hlpuart1.Init.Mode = UART_MODE_TX_RX; - hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&hlpuart1) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ - + /* USER CODE BEGIN LPUART1_Init 0 */ + + /* USER CODE END LPUART1_Init 0 */ + + /* USER CODE BEGIN LPUART1_Init 1 */ + + /* USER CODE END LPUART1_Init 1 */ + hlpuart1.Instance = LPUART1; + hlpuart1.Init.BaudRate = 115200; + hlpuart1.Init.WordLength = UART_WORDLENGTH_8B; + hlpuart1.Init.StopBits = UART_STOPBITS_1; + hlpuart1.Init.Parity = UART_PARITY_NONE; + hlpuart1.Init.Mode = UART_MODE_TX_RX; + hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&hlpuart1) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&hlpuart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&hlpuart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&hlpuart1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN LPUART1_Init 2 */ + + /* USER CODE END LPUART1_Init 2 */ } -void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) +void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(uartHandle->Instance==LPUART1) - { - /* USER CODE BEGIN LPUART1_MspInit 0 */ - - /* USER CODE END LPUART1_MspInit 0 */ - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* LPUART1 clock enable */ - __HAL_RCC_LPUART1_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - 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_LOW; - GPIO_InitStruct.Alternate = GPIO_AF12_LPUART1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* LPUART1 interrupt Init */ - HAL_NVIC_SetPriority(LPUART1_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(LPUART1_IRQn); - /* USER CODE BEGIN LPUART1_MspInit 1 */ - - /* USER CODE END LPUART1_MspInit 1 */ - } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (uartHandle->Instance == LPUART1) { + /* USER CODE BEGIN LPUART1_MspInit 0 */ + + /* USER CODE END LPUART1_MspInit 0 */ + LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); + + /* LPUART1 clock enable */ + __HAL_RCC_LPUART1_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**LPUART1 GPIO Configuration + PA2 ------> LPUART1_TX + PA3 ------> LPUART1_RX + */ + 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_LOW; + GPIO_InitStruct.Alternate = GPIO_AF12_LPUART1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* LPUART1 interrupt Init */ + HAL_NVIC_SetPriority(LPUART1_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(LPUART1_IRQn); + /* USER CODE BEGIN LPUART1_MspInit 1 */ + + /* USER CODE END LPUART1_MspInit 1 */ + } } -void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) +void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle) { - if(uartHandle->Instance==LPUART1) - { - /* USER CODE BEGIN LPUART1_MspDeInit 0 */ + if (uartHandle->Instance == LPUART1) { + /* USER CODE BEGIN LPUART1_MspDeInit 0 */ - /* USER CODE END LPUART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_LPUART1_CLK_DISABLE(); + /* USER CODE END LPUART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_LPUART1_CLK_DISABLE(); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); + /**LPUART1 GPIO Configuration + PA2 ------> LPUART1_TX + PA3 ------> LPUART1_RX + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2 | GPIO_PIN_3); - /* LPUART1 interrupt Deinit */ - HAL_NVIC_DisableIRQ(LPUART1_IRQn); - /* USER CODE BEGIN LPUART1_MspDeInit 1 */ + /* LPUART1 interrupt Deinit */ + HAL_NVIC_DisableIRQ(LPUART1_IRQn); + /* USER CODE BEGIN LPUART1_MspDeInit 1 */ - /* USER CODE END LPUART1_MspDeInit 1 */ - } + /* USER CODE END LPUART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - From 76dbf96e357daaac6126e5f54fc5108c9f714e2a Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Mon, 17 Aug 2026 22:27:48 -0700 Subject: [PATCH 118/125] Cleanup unused test/dev projects Nuke - `G4PERTESTING` - `G4SPITESTING` - `G4ADCTESTING` - `G474xE_CAN_TESTING` - `G4FANCYCANTESTING` Signed-off-by: Daniel Hansen --- CMakeLists.txt | 18 +- G431x8_CAN_TESTING/Core/Inc/adc.h | 49 -- G431x8_CAN_TESTING/Core/Inc/crc.h | 51 --- G431x8_CAN_TESTING/Core/Inc/dma.h | 51 --- G431x8_CAN_TESTING/Core/Inc/fdcan.h | 51 --- G431x8_CAN_TESTING/Core/Inc/gpio.h | 48 -- G431x8_CAN_TESTING/Core/Inc/i2c.h | 49 -- G431x8_CAN_TESTING/Core/Inc/main.h | 115 ----- G431x8_CAN_TESTING/Core/Inc/spi.h | 49 -- G431x8_CAN_TESTING/Core/Inc/tim.h | 49 -- G431x8_CAN_TESTING/Core/Inc/usart.h | 50 --- G431x8_CAN_TESTING/Core/Src/adc.c | 186 -------- G431x8_CAN_TESTING/Core/Src/crc.c | 86 ---- G431x8_CAN_TESTING/Core/Src/dma.c | 50 --- G431x8_CAN_TESTING/Core/Src/fdcan.c | 135 ------ G431x8_CAN_TESTING/Core/Src/gpio.c | 260 ----------- G431x8_CAN_TESTING/Core/Src/i2c.c | 92 ---- G431x8_CAN_TESTING/Core/Src/spi.c | 95 ---- G431x8_CAN_TESTING/Core/Src/stm32g4xx_it.c | 194 -------- G431x8_CAN_TESTING/Core/Src/tim.c | 79 ---- G431x8_CAN_TESTING/Core/Src/usart.c | 184 -------- .../G431x8_CAN_BASIC_TEST/CMakeLists.txt | 65 --- .../G431x8_CAN_BASIC_TEST/can_cfg.h | 7 - .../can_external_test_cfg.h | 6 - .../G431x8_CAN_BASIC_TEST/main.c | 274 ------------ G431x8_CAN_TESTING/G4PERTESTING.ioc | 382 ---------------- G431x8_CAN_TESTING/README.md | 5 - .../CAN_BASIC_TEST/CMakeLists.txt | 65 --- G474xE_CAN_TESTING/CAN_BASIC_TEST/can_cfg.h | 10 - .../CAN_BASIC_TEST/can_external_test_cfg.h | 6 - G474xE_CAN_TESTING/CAN_BASIC_TEST/main.c | 274 ------------ .../CAN_FILTER_TEST/CMakeLists.txt | 58 --- G474xE_CAN_TESTING/CAN_FILTER_TEST/can_cfg.h | 11 - G474xE_CAN_TESTING/CAN_FILTER_TEST/main.c | 274 ------------ .../CAN_INTERNAL_TEST/CMakeLists.txt | 65 --- .../CAN_INTERNAL_TEST/can_cfg.h | 10 - G474xE_CAN_TESTING/CAN_INTERNAL_TEST/main.c | 274 ------------ .../CAN_LOST_RX_TEST/CMakeLists.txt | 58 --- G474xE_CAN_TESTING/CAN_LOST_RX_TEST/can_cfg.h | 23 - G474xE_CAN_TESTING/CAN_LOST_RX_TEST/main.c | 274 ------------ .../CAN_RELEASE_TEST/CMakeLists.txt | 65 --- G474xE_CAN_TESTING/CAN_RELEASE_TEST/can_cfg.h | 11 - G474xE_CAN_TESTING/CAN_RELEASE_TEST/main.c | 274 ------------ .../CAN_STRESS_TEST/CMakeLists.txt | 58 --- G474xE_CAN_TESTING/CAN_STRESS_TEST/can_cfg.h | 11 - G474xE_CAN_TESTING/CAN_STRESS_TEST/main.c | 275 ------------ G474xE_CAN_TESTING/Core/Inc/adc.h | 49 -- G474xE_CAN_TESTING/Core/Inc/crc.h | 51 --- G474xE_CAN_TESTING/Core/Inc/dma.h | 51 --- G474xE_CAN_TESTING/Core/Inc/fdcan.h | 51 --- G474xE_CAN_TESTING/Core/Inc/gpio.h | 48 -- G474xE_CAN_TESTING/Core/Inc/i2c.h | 49 -- G474xE_CAN_TESTING/Core/Inc/main.h | 115 ----- G474xE_CAN_TESTING/Core/Inc/spi.h | 49 -- .../Core/Inc/stm32g4xx_hal_conf.h | 390 ---------------- G474xE_CAN_TESTING/Core/Inc/stm32g4xx_it.h | 67 --- G474xE_CAN_TESTING/Core/Inc/tim.h | 49 -- G474xE_CAN_TESTING/Core/Inc/usart.h | 50 --- G474xE_CAN_TESTING/Core/Src/adc.c | 186 -------- G474xE_CAN_TESTING/Core/Src/crc.c | 86 ---- G474xE_CAN_TESTING/Core/Src/dma.c | 50 --- G474xE_CAN_TESTING/Core/Src/fdcan.c | 135 ------ G474xE_CAN_TESTING/Core/Src/gpio.c | 260 ----------- G474xE_CAN_TESTING/Core/Src/i2c.c | 92 ---- G474xE_CAN_TESTING/Core/Src/spi.c | 95 ---- .../Core/Src/stm32g4xx_hal_msp.c | 86 ---- G474xE_CAN_TESTING/Core/Src/stm32g4xx_it.c | 194 -------- G474xE_CAN_TESTING/Core/Src/tim.c | 79 ---- G474xE_CAN_TESTING/Core/Src/usart.c | 184 -------- G474xE_CAN_TESTING/G4PERTESTING.ioc | 382 ---------------- .../PROFILER_TEST/CMakeLists.txt | 58 --- G474xE_CAN_TESTING/PROFILER_TEST/can_cfg.h | 20 - G474xE_CAN_TESTING/PROFILER_TEST/main.c | 275 ------------ G474xE_CAN_TESTING/README.md | 5 - G4ADCTESTING/CMakeLists.txt | 53 --- G4ADCTESTING/Core/Inc/adc.h | 49 -- G4ADCTESTING/Core/Inc/crc.h | 51 --- G4ADCTESTING/Core/Inc/dma.h | 51 --- G4ADCTESTING/Core/Inc/fdcan.h | 51 --- G4ADCTESTING/Core/Inc/gpio.h | 48 -- G4ADCTESTING/Core/Inc/i2c.h | 49 -- G4ADCTESTING/Core/Inc/main.h | 115 ----- G4ADCTESTING/Core/Inc/spi.h | 49 -- G4ADCTESTING/Core/Inc/stm32g4xx_hal_conf.h | 390 ---------------- G4ADCTESTING/Core/Inc/stm32g4xx_it.h | 67 --- G4ADCTESTING/Core/Inc/tim.h | 49 -- G4ADCTESTING/Core/Inc/usart.h | 50 --- G4ADCTESTING/Core/Src/adc.c | 186 -------- G4ADCTESTING/Core/Src/crc.c | 86 ---- G4ADCTESTING/Core/Src/dma.c | 50 --- G4ADCTESTING/Core/Src/fdcan.c | 133 ------ G4ADCTESTING/Core/Src/gpio.c | 260 ----------- G4ADCTESTING/Core/Src/i2c.c | 92 ---- G4ADCTESTING/Core/Src/main.c | 276 ------------ G4ADCTESTING/Core/Src/spi.c | 95 ---- G4ADCTESTING/Core/Src/stm32g4xx_hal_msp.c | 86 ---- G4ADCTESTING/Core/Src/stm32g4xx_it.c | 212 --------- G4ADCTESTING/Core/Src/tim.c | 79 ---- G4ADCTESTING/Core/Src/usart.c | 184 -------- G4ADCTESTING/G4PERTESTING.ioc | 382 ---------------- G4ADCTESTING/README.md | 5 - .../CAN_LOOPBACK_TEST/CMakeLists.txt | 61 --- G4FANCYCANTESTING/CAN_LOOPBACK_TEST/main.c | 305 ------------- .../Core/Inc/FancyCAN_LoopbackTest.h | 6 - G4FANCYCANTESTING/Core/Inc/adc.h | 49 -- G4FANCYCANTESTING/Core/Inc/can_cfg.h | 9 - G4FANCYCANTESTING/Core/Inc/crc.h | 51 --- G4FANCYCANTESTING/Core/Inc/dma.h | 51 --- G4FANCYCANTESTING/Core/Inc/gpio.h | 48 -- G4FANCYCANTESTING/Core/Inc/i2c.h | 49 -- G4FANCYCANTESTING/Core/Inc/main.h | 115 ----- G4FANCYCANTESTING/Core/Inc/spi.h | 49 -- .../Core/Inc/stm32g4xx_hal_conf.h | 390 ---------------- G4FANCYCANTESTING/Core/Inc/stm32g4xx_it.h | 67 --- G4FANCYCANTESTING/Core/Inc/tim.h | 49 -- G4FANCYCANTESTING/Core/Inc/usart.h | 50 --- .../Core/Src/FancyCAN_LoopbackTest.c | 419 ------------------ G4FANCYCANTESTING/Core/Src/adc.c | 186 -------- G4FANCYCANTESTING/Core/Src/crc.c | 86 ---- G4FANCYCANTESTING/Core/Src/dma.c | 50 --- G4FANCYCANTESTING/Core/Src/gpio.c | 260 ----------- G4FANCYCANTESTING/Core/Src/i2c.c | 92 ---- G4FANCYCANTESTING/Core/Src/spi.c | 95 ---- .../Core/Src/stm32g4xx_hal_msp.c | 86 ---- G4FANCYCANTESTING/Core/Src/stm32g4xx_it.c | 194 -------- G4FANCYCANTESTING/Core/Src/tim.c | 79 ---- G4FANCYCANTESTING/Core/Src/usart.c | 184 -------- G4NEOTESTING/Core/Inc/stm32g4xx_hal_conf.h | 390 ---------------- G4NEOTESTING/Core/Inc/stm32g4xx_it.h | 67 --- G4NEOTESTING/Core/Src/stm32g4xx_hal_msp.c | 86 ---- G4PERTESTING/CMakeLists.txt | 48 -- G4PERTESTING/Core/Inc/adc.h | 49 -- G4PERTESTING/Core/Inc/crc.h | 51 --- G4PERTESTING/Core/Inc/dma.h | 51 --- G4PERTESTING/Core/Inc/fdcan.h | 51 --- G4PERTESTING/Core/Inc/gpio.h | 48 -- G4PERTESTING/Core/Inc/i2c.h | 49 -- G4PERTESTING/Core/Inc/main.h | 115 ----- G4PERTESTING/Core/Inc/spi.h | 49 -- G4PERTESTING/Core/Inc/stm32g4xx_hal_conf.h | 390 ---------------- G4PERTESTING/Core/Inc/stm32g4xx_it.h | 67 --- G4PERTESTING/Core/Inc/tim.h | 49 -- G4PERTESTING/Core/Inc/usart.h | 50 --- G4PERTESTING/Core/Src/adc.c | 186 -------- G4PERTESTING/Core/Src/crc.c | 86 ---- G4PERTESTING/Core/Src/dma.c | 50 --- G4PERTESTING/Core/Src/fdcan.c | 133 ------ G4PERTESTING/Core/Src/gpio.c | 260 ----------- G4PERTESTING/Core/Src/i2c.c | 92 ---- G4PERTESTING/Core/Src/main.c | 199 --------- G4PERTESTING/Core/Src/spi.c | 95 ---- G4PERTESTING/Core/Src/stm32g4xx_hal_msp.c | 86 ---- G4PERTESTING/Core/Src/stm32g4xx_it.c | 212 --------- G4PERTESTING/Core/Src/tim.c | 79 ---- G4PERTESTING/Core/Src/usart.c | 184 -------- G4PERTESTING/G4PERTESTING.ioc | 382 ---------------- G4PERTESTING/README.md | 5 - G4SPITESTING/CMakeLists.txt | 44 -- G4SPITESTING/Core/Inc/main.h | 116 ----- G4SPITESTING/Core/Inc/stm32g4xx_hal_conf.h | 390 ---------------- G4SPITESTING/Core/Inc/stm32g4xx_it.h | 67 --- G4SPITESTING/Core/Src/main.c | 298 ------------- G4SPITESTING/Core/Src/stm32g4xx_hal_msp.c | 86 ---- G4SPITESTING/Core/Src/stm32g4xx_it.c | 198 --------- G4SPITESTING/README.md | 10 - .../CUBEMXTESTING}/Application/Inc/CANdler.h | 0 .../Application/Inc/CubeCAN_Config.h | 0 .../Application/Inc/CubeVCP_Config.h | 0 .../CUBEMXTESTING}/Application/Inc/Loop.h | 0 .../CUBEMXTESTING}/Application/Src/CANdler.c | 0 .../CUBEMXTESTING}/Application/Src/Loop.c | 0 .../CUBEMXTESTING}/CMakeLists.txt | 0 .../CUBEMXTESTING}/CUBEMXTESTING.ioc | 0 .../CUBEMXTESTING}/Core/Inc/fdcan.h | 0 .../CUBEMXTESTING}/Core/Inc/gpio.h | 0 .../CUBEMXTESTING}/Core/Inc/main.h | 0 .../Core/Inc/stm32g4xx_hal_conf.h | 0 .../CUBEMXTESTING}/Core/Inc/stm32g4xx_it.h | 0 .../CUBEMXTESTING}/Core/Inc/tim.h | 0 .../CUBEMXTESTING}/Core/Inc/usart.h | 0 .../CUBEMXTESTING}/Core/Src/fdcan.c | 0 .../CUBEMXTESTING}/Core/Src/gpio.c | 0 .../CUBEMXTESTING}/Core/Src/main.c | 0 .../Core/Src/stm32g4xx_hal_msp.c | 0 .../CUBEMXTESTING}/Core/Src/stm32g4xx_it.c | 0 .../CUBEMXTESTING}/Core/Src/tim.c | 0 .../CUBEMXTESTING}/Core/Src/usart.c | 0 .../README_CAN_Timer_Configuration.md | 0 .../G4NEOTESTING}/CMakeLists.txt | 0 .../G4NEOTESTING}/Core/Inc/main.h | 0 .../Core/Inc/stm32g4xx_hal_conf.h | 0 .../G4NEOTESTING}/Core/Inc/stm32g4xx_it.h | 0 .../G4NEOTESTING}/Core/Src/main.c | 0 .../Core/Src/stm32g4xx_hal_msp.c | 0 .../G4NEOTESTING}/Core/Src/stm32g4xx_it.c | 0 .../G4NEOTESTING}/README.md | 0 196 files changed, 2 insertions(+), 19126 deletions(-) delete mode 100644 G431x8_CAN_TESTING/Core/Inc/adc.h delete mode 100644 G431x8_CAN_TESTING/Core/Inc/crc.h delete mode 100644 G431x8_CAN_TESTING/Core/Inc/dma.h delete mode 100644 G431x8_CAN_TESTING/Core/Inc/fdcan.h delete mode 100644 G431x8_CAN_TESTING/Core/Inc/gpio.h delete mode 100644 G431x8_CAN_TESTING/Core/Inc/i2c.h delete mode 100644 G431x8_CAN_TESTING/Core/Inc/main.h delete mode 100644 G431x8_CAN_TESTING/Core/Inc/spi.h delete mode 100644 G431x8_CAN_TESTING/Core/Inc/tim.h delete mode 100644 G431x8_CAN_TESTING/Core/Inc/usart.h delete mode 100644 G431x8_CAN_TESTING/Core/Src/adc.c delete mode 100644 G431x8_CAN_TESTING/Core/Src/crc.c delete mode 100644 G431x8_CAN_TESTING/Core/Src/dma.c delete mode 100644 G431x8_CAN_TESTING/Core/Src/fdcan.c delete mode 100644 G431x8_CAN_TESTING/Core/Src/gpio.c delete mode 100644 G431x8_CAN_TESTING/Core/Src/i2c.c delete mode 100644 G431x8_CAN_TESTING/Core/Src/spi.c delete mode 100644 G431x8_CAN_TESTING/Core/Src/stm32g4xx_it.c delete mode 100644 G431x8_CAN_TESTING/Core/Src/tim.c delete mode 100644 G431x8_CAN_TESTING/Core/Src/usart.c delete mode 100644 G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/CMakeLists.txt delete mode 100644 G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/can_cfg.h delete mode 100644 G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/can_external_test_cfg.h delete mode 100644 G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/main.c delete mode 100644 G431x8_CAN_TESTING/G4PERTESTING.ioc delete mode 100644 G431x8_CAN_TESTING/README.md delete mode 100644 G474xE_CAN_TESTING/CAN_BASIC_TEST/CMakeLists.txt delete mode 100644 G474xE_CAN_TESTING/CAN_BASIC_TEST/can_cfg.h delete mode 100644 G474xE_CAN_TESTING/CAN_BASIC_TEST/can_external_test_cfg.h delete mode 100644 G474xE_CAN_TESTING/CAN_BASIC_TEST/main.c delete mode 100644 G474xE_CAN_TESTING/CAN_FILTER_TEST/CMakeLists.txt delete mode 100644 G474xE_CAN_TESTING/CAN_FILTER_TEST/can_cfg.h delete mode 100644 G474xE_CAN_TESTING/CAN_FILTER_TEST/main.c delete mode 100644 G474xE_CAN_TESTING/CAN_INTERNAL_TEST/CMakeLists.txt delete mode 100644 G474xE_CAN_TESTING/CAN_INTERNAL_TEST/can_cfg.h delete mode 100644 G474xE_CAN_TESTING/CAN_INTERNAL_TEST/main.c delete mode 100644 G474xE_CAN_TESTING/CAN_LOST_RX_TEST/CMakeLists.txt delete mode 100644 G474xE_CAN_TESTING/CAN_LOST_RX_TEST/can_cfg.h delete mode 100644 G474xE_CAN_TESTING/CAN_LOST_RX_TEST/main.c delete mode 100644 G474xE_CAN_TESTING/CAN_RELEASE_TEST/CMakeLists.txt delete mode 100644 G474xE_CAN_TESTING/CAN_RELEASE_TEST/can_cfg.h delete mode 100644 G474xE_CAN_TESTING/CAN_RELEASE_TEST/main.c delete mode 100644 G474xE_CAN_TESTING/CAN_STRESS_TEST/CMakeLists.txt delete mode 100644 G474xE_CAN_TESTING/CAN_STRESS_TEST/can_cfg.h delete mode 100644 G474xE_CAN_TESTING/CAN_STRESS_TEST/main.c delete mode 100644 G474xE_CAN_TESTING/Core/Inc/adc.h delete mode 100644 G474xE_CAN_TESTING/Core/Inc/crc.h delete mode 100644 G474xE_CAN_TESTING/Core/Inc/dma.h delete mode 100644 G474xE_CAN_TESTING/Core/Inc/fdcan.h delete mode 100644 G474xE_CAN_TESTING/Core/Inc/gpio.h delete mode 100644 G474xE_CAN_TESTING/Core/Inc/i2c.h delete mode 100644 G474xE_CAN_TESTING/Core/Inc/main.h delete mode 100644 G474xE_CAN_TESTING/Core/Inc/spi.h delete mode 100644 G474xE_CAN_TESTING/Core/Inc/stm32g4xx_hal_conf.h delete mode 100644 G474xE_CAN_TESTING/Core/Inc/stm32g4xx_it.h delete mode 100644 G474xE_CAN_TESTING/Core/Inc/tim.h delete mode 100644 G474xE_CAN_TESTING/Core/Inc/usart.h delete mode 100644 G474xE_CAN_TESTING/Core/Src/adc.c delete mode 100644 G474xE_CAN_TESTING/Core/Src/crc.c delete mode 100644 G474xE_CAN_TESTING/Core/Src/dma.c delete mode 100644 G474xE_CAN_TESTING/Core/Src/fdcan.c delete mode 100644 G474xE_CAN_TESTING/Core/Src/gpio.c delete mode 100644 G474xE_CAN_TESTING/Core/Src/i2c.c delete mode 100644 G474xE_CAN_TESTING/Core/Src/spi.c delete mode 100644 G474xE_CAN_TESTING/Core/Src/stm32g4xx_hal_msp.c delete mode 100644 G474xE_CAN_TESTING/Core/Src/stm32g4xx_it.c delete mode 100644 G474xE_CAN_TESTING/Core/Src/tim.c delete mode 100644 G474xE_CAN_TESTING/Core/Src/usart.c delete mode 100644 G474xE_CAN_TESTING/G4PERTESTING.ioc delete mode 100644 G474xE_CAN_TESTING/PROFILER_TEST/CMakeLists.txt delete mode 100644 G474xE_CAN_TESTING/PROFILER_TEST/can_cfg.h delete mode 100644 G474xE_CAN_TESTING/PROFILER_TEST/main.c delete mode 100644 G474xE_CAN_TESTING/README.md delete mode 100644 G4ADCTESTING/CMakeLists.txt delete mode 100644 G4ADCTESTING/Core/Inc/adc.h delete mode 100644 G4ADCTESTING/Core/Inc/crc.h delete mode 100644 G4ADCTESTING/Core/Inc/dma.h delete mode 100644 G4ADCTESTING/Core/Inc/fdcan.h delete mode 100644 G4ADCTESTING/Core/Inc/gpio.h delete mode 100644 G4ADCTESTING/Core/Inc/i2c.h delete mode 100644 G4ADCTESTING/Core/Inc/main.h delete mode 100644 G4ADCTESTING/Core/Inc/spi.h delete mode 100644 G4ADCTESTING/Core/Inc/stm32g4xx_hal_conf.h delete mode 100644 G4ADCTESTING/Core/Inc/stm32g4xx_it.h delete mode 100644 G4ADCTESTING/Core/Inc/tim.h delete mode 100644 G4ADCTESTING/Core/Inc/usart.h delete mode 100644 G4ADCTESTING/Core/Src/adc.c delete mode 100644 G4ADCTESTING/Core/Src/crc.c delete mode 100644 G4ADCTESTING/Core/Src/dma.c delete mode 100644 G4ADCTESTING/Core/Src/fdcan.c delete mode 100644 G4ADCTESTING/Core/Src/gpio.c delete mode 100644 G4ADCTESTING/Core/Src/i2c.c delete mode 100644 G4ADCTESTING/Core/Src/main.c delete mode 100644 G4ADCTESTING/Core/Src/spi.c delete mode 100644 G4ADCTESTING/Core/Src/stm32g4xx_hal_msp.c delete mode 100644 G4ADCTESTING/Core/Src/stm32g4xx_it.c delete mode 100644 G4ADCTESTING/Core/Src/tim.c delete mode 100644 G4ADCTESTING/Core/Src/usart.c delete mode 100644 G4ADCTESTING/G4PERTESTING.ioc delete mode 100644 G4ADCTESTING/README.md delete mode 100644 G4FANCYCANTESTING/CAN_LOOPBACK_TEST/CMakeLists.txt delete mode 100644 G4FANCYCANTESTING/CAN_LOOPBACK_TEST/main.c delete mode 100644 G4FANCYCANTESTING/Core/Inc/FancyCAN_LoopbackTest.h delete mode 100644 G4FANCYCANTESTING/Core/Inc/adc.h delete mode 100644 G4FANCYCANTESTING/Core/Inc/can_cfg.h delete mode 100644 G4FANCYCANTESTING/Core/Inc/crc.h delete mode 100644 G4FANCYCANTESTING/Core/Inc/dma.h delete mode 100644 G4FANCYCANTESTING/Core/Inc/gpio.h delete mode 100644 G4FANCYCANTESTING/Core/Inc/i2c.h delete mode 100644 G4FANCYCANTESTING/Core/Inc/main.h delete mode 100644 G4FANCYCANTESTING/Core/Inc/spi.h delete mode 100644 G4FANCYCANTESTING/Core/Inc/stm32g4xx_hal_conf.h delete mode 100644 G4FANCYCANTESTING/Core/Inc/stm32g4xx_it.h delete mode 100644 G4FANCYCANTESTING/Core/Inc/tim.h delete mode 100644 G4FANCYCANTESTING/Core/Inc/usart.h delete mode 100644 G4FANCYCANTESTING/Core/Src/FancyCAN_LoopbackTest.c delete mode 100644 G4FANCYCANTESTING/Core/Src/adc.c delete mode 100644 G4FANCYCANTESTING/Core/Src/crc.c delete mode 100644 G4FANCYCANTESTING/Core/Src/dma.c delete mode 100644 G4FANCYCANTESTING/Core/Src/gpio.c delete mode 100644 G4FANCYCANTESTING/Core/Src/i2c.c delete mode 100644 G4FANCYCANTESTING/Core/Src/spi.c delete mode 100644 G4FANCYCANTESTING/Core/Src/stm32g4xx_hal_msp.c delete mode 100644 G4FANCYCANTESTING/Core/Src/stm32g4xx_it.c delete mode 100644 G4FANCYCANTESTING/Core/Src/tim.c delete mode 100644 G4FANCYCANTESTING/Core/Src/usart.c delete mode 100644 G4NEOTESTING/Core/Inc/stm32g4xx_hal_conf.h delete mode 100644 G4NEOTESTING/Core/Inc/stm32g4xx_it.h delete mode 100644 G4NEOTESTING/Core/Src/stm32g4xx_hal_msp.c delete mode 100644 G4PERTESTING/CMakeLists.txt delete mode 100644 G4PERTESTING/Core/Inc/adc.h delete mode 100644 G4PERTESTING/Core/Inc/crc.h delete mode 100644 G4PERTESTING/Core/Inc/dma.h delete mode 100644 G4PERTESTING/Core/Inc/fdcan.h delete mode 100644 G4PERTESTING/Core/Inc/gpio.h delete mode 100644 G4PERTESTING/Core/Inc/i2c.h delete mode 100644 G4PERTESTING/Core/Inc/main.h delete mode 100644 G4PERTESTING/Core/Inc/spi.h delete mode 100644 G4PERTESTING/Core/Inc/stm32g4xx_hal_conf.h delete mode 100644 G4PERTESTING/Core/Inc/stm32g4xx_it.h delete mode 100644 G4PERTESTING/Core/Inc/tim.h delete mode 100644 G4PERTESTING/Core/Inc/usart.h delete mode 100644 G4PERTESTING/Core/Src/adc.c delete mode 100644 G4PERTESTING/Core/Src/crc.c delete mode 100644 G4PERTESTING/Core/Src/dma.c delete mode 100644 G4PERTESTING/Core/Src/fdcan.c delete mode 100644 G4PERTESTING/Core/Src/gpio.c delete mode 100644 G4PERTESTING/Core/Src/i2c.c delete mode 100644 G4PERTESTING/Core/Src/main.c delete mode 100644 G4PERTESTING/Core/Src/spi.c delete mode 100644 G4PERTESTING/Core/Src/stm32g4xx_hal_msp.c delete mode 100644 G4PERTESTING/Core/Src/stm32g4xx_it.c delete mode 100644 G4PERTESTING/Core/Src/tim.c delete mode 100644 G4PERTESTING/Core/Src/usart.c delete mode 100644 G4PERTESTING/G4PERTESTING.ioc delete mode 100644 G4PERTESTING/README.md delete mode 100644 G4SPITESTING/CMakeLists.txt delete mode 100644 G4SPITESTING/Core/Inc/main.h delete mode 100644 G4SPITESTING/Core/Inc/stm32g4xx_hal_conf.h delete mode 100644 G4SPITESTING/Core/Inc/stm32g4xx_it.h delete mode 100644 G4SPITESTING/Core/Src/main.c delete mode 100644 G4SPITESTING/Core/Src/stm32g4xx_hal_msp.c delete mode 100644 G4SPITESTING/Core/Src/stm32g4xx_it.c delete mode 100644 G4SPITESTING/README.md rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Application/Inc/CANdler.h (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Application/Inc/CubeCAN_Config.h (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Application/Inc/CubeVCP_Config.h (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Application/Inc/Loop.h (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Application/Src/CANdler.c (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Application/Src/Loop.c (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/CMakeLists.txt (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/CUBEMXTESTING.ioc (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Core/Inc/fdcan.h (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Core/Inc/gpio.h (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Core/Inc/main.h (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Core/Inc/stm32g4xx_hal_conf.h (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Core/Inc/stm32g4xx_it.h (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Core/Inc/tim.h (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Core/Inc/usart.h (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Core/Src/fdcan.c (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Core/Src/gpio.c (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Core/Src/main.c (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Core/Src/stm32g4xx_hal_msp.c (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Core/Src/stm32g4xx_it.c (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Core/Src/tim.c (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/Core/Src/usart.c (100%) rename {CUBEMXTESTING => Testbench/CUBEMXTESTING}/README_CAN_Timer_Configuration.md (100%) rename {G4NEOTESTING => Testbench/G4NEOTESTING}/CMakeLists.txt (100%) rename {G4NEOTESTING => Testbench/G4NEOTESTING}/Core/Inc/main.h (100%) rename {G431x8_CAN_TESTING => Testbench/G4NEOTESTING}/Core/Inc/stm32g4xx_hal_conf.h (100%) rename {G431x8_CAN_TESTING => Testbench/G4NEOTESTING}/Core/Inc/stm32g4xx_it.h (100%) rename {G4NEOTESTING => Testbench/G4NEOTESTING}/Core/Src/main.c (100%) rename {G431x8_CAN_TESTING => Testbench/G4NEOTESTING}/Core/Src/stm32g4xx_hal_msp.c (100%) rename {G4NEOTESTING => Testbench/G4NEOTESTING}/Core/Src/stm32g4xx_it.c (100%) rename {G4NEOTESTING => Testbench/G4NEOTESTING}/README.md (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c0144a78..40e5a1cb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,22 +160,8 @@ add_gr_project(STM32G431x8 OutboardSensors TireTemp) add_gr_project(STM32G431x8 OutboardSensors BrakeTemp) # Development -add_gr_project(STM32G474xE G4PERTESTING) -add_gr_project(STM32G474xE G4SPITESTING) -add_gr_project(STM32G474xE G4ADCTESTING) -add_gr_project(STM32G474xE G4NEOTESTING) -add_gr_project(STM32G474xE CUBEMXTESTING) - -# CAN Peripheral Testing -add_gr_project(STM32G474xE G474xE_CAN_TESTING CAN_BASIC_TEST) -add_gr_project(STM32G474xE G474xE_CAN_TESTING CAN_RELEASE_TEST) -add_gr_project(STM32G474xE G474xE_CAN_TESTING CAN_STRESS_TEST) -add_gr_project(STM32G474xE G474xE_CAN_TESTING CAN_LOST_RX_TEST) -add_gr_project(STM32G474xE G474xE_CAN_TESTING CAN_FILTER_TEST) -add_gr_project(STM32G474xE G474xE_CAN_TESTING PROFILER_TEST) -add_gr_project(STM32G431x8 G431x8_CAN_TESTING G431x8_CAN_BASIC_TEST) - -add_gr_project(STM32G474xE G4FANCYCANTESTING CAN_LOOPBACK_TEST) +add_gr_project(STM32G474xE Testbench G4NEOTESTING) +add_gr_project(STM32G474xE Testbench CUBEMXTESTING) # BLINKY Demos add_gr_project(STM32G474xE BLINKY G4BLINKY) diff --git a/G431x8_CAN_TESTING/Core/Inc/adc.h b/G431x8_CAN_TESTING/Core/Inc/adc.h deleted file mode 100644 index 41154538b..000000000 --- a/G431x8_CAN_TESTING/Core/Inc/adc.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file adc.h - * @brief This file contains all the function prototypes for - * the adc.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __ADC_H__ -#define __ADC_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_ADC1_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __ADC_H__ */ diff --git a/G431x8_CAN_TESTING/Core/Inc/crc.h b/G431x8_CAN_TESTING/Core/Inc/crc.h deleted file mode 100644 index 133957e92..000000000 --- a/G431x8_CAN_TESTING/Core/Inc/crc.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file crc.h - * @brief This file contains all the function prototypes for - * the crc.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __CRC_H__ -#define __CRC_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern CRC_HandleTypeDef hcrc; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_CRC_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CRC_H__ */ diff --git a/G431x8_CAN_TESTING/Core/Inc/dma.h b/G431x8_CAN_TESTING/Core/Inc/dma.h deleted file mode 100644 index ae819cab4..000000000 --- a/G431x8_CAN_TESTING/Core/Inc/dma.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file dma.h - * @brief This file contains all the function prototypes for - * the dma.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __DMA_H__ -#define __DMA_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* DMA memory to memory transfer handles -------------------------------------*/ - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_DMA_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __DMA_H__ */ diff --git a/G431x8_CAN_TESTING/Core/Inc/fdcan.h b/G431x8_CAN_TESTING/Core/Inc/fdcan.h deleted file mode 100644 index 56c4a8adb..000000000 --- a/G431x8_CAN_TESTING/Core/Inc/fdcan.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file fdcan.h - * @brief This file contains all the function prototypes for - * the fdcan.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __FDCAN_H__ -#define __FDCAN_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern FDCAN_HandleTypeDef hfdcan2; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_FDCAN2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __FDCAN_H__ */ diff --git a/G431x8_CAN_TESTING/Core/Inc/gpio.h b/G431x8_CAN_TESTING/Core/Inc/gpio.h deleted file mode 100644 index 843d4e9e7..000000000 --- a/G431x8_CAN_TESTING/Core/Inc/gpio.h +++ /dev/null @@ -1,48 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file gpio.h - * @brief This file contains all the function prototypes for - * the gpio.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __GPIO_H__ -#define __GPIO_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_GPIO_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif -#endif /*__ GPIO_H__ */ diff --git a/G431x8_CAN_TESTING/Core/Inc/i2c.h b/G431x8_CAN_TESTING/Core/Inc/i2c.h deleted file mode 100644 index 0a0a50803..000000000 --- a/G431x8_CAN_TESTING/Core/Inc/i2c.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file i2c.h - * @brief This file contains all the function prototypes for - * the i2c.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __I2C_H__ -#define __I2C_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_I2C2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __I2C_H__ */ diff --git a/G431x8_CAN_TESTING/Core/Inc/main.h b/G431x8_CAN_TESTING/Core/Inc/main.h deleted file mode 100644 index 23d7ffce4..000000000 --- a/G431x8_CAN_TESTING/Core/Inc/main.h +++ /dev/null @@ -1,115 +0,0 @@ -/* 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) 2024 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 "stm32g4xx_hal.h" -#include "stm32g4xx_ll_adc.h" -#include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_dma.h" -#include "stm32g4xx_ll_exti.h" -#include "stm32g4xx_ll_gpio.h" -#include "stm32g4xx_ll_i2c.h" -#include "stm32g4xx_ll_lpuart.h" -#include "stm32g4xx_ll_pwr.h" -#include "stm32g4xx_ll_rcc.h" -#include "stm32g4xx_ll_spi.h" -#include "stm32g4xx_ll_system.h" -#include "stm32g4xx_ll_tim.h" -#include "stm32g4xx_ll_usart.h" -#include "stm32g4xx_ll_utils.h" - -/* 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 Error_Handler(void); - -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -/* Private defines -----------------------------------------------------------*/ -#define BSPD_SIGNAL_Pin LL_GPIO_PIN_1 -#define BSPD_SIGNAL_GPIO_Port GPIOC -#define APPS1_SIGNAL_Pin LL_GPIO_PIN_2 -#define APPS1_SIGNAL_GPIO_Port GPIOC -#define APPS2_SIGNAL_Pin LL_GPIO_PIN_3 -#define APPS2_SIGNAL_GPIO_Port GPIOC -#define BLINKY_Pin LL_GPIO_PIN_5 -#define BLINKY_GPIO_Port GPIOA -#define IMD_SENSE_Pin LL_GPIO_PIN_6 -#define IMD_SENSE_GPIO_Port GPIOA -#define AMS_SENSE_Pin LL_GPIO_PIN_7 -#define AMS_SENSE_GPIO_Port GPIOA -#define BRAKE_F_SIGNAL_Pin LL_GPIO_PIN_0 -#define BRAKE_F_SIGNAL_GPIO_Port GPIOB -#define BRAKE_R_SIGNAL_Pin LL_GPIO_PIN_1 -#define BRAKE_R_SIGNAL_GPIO_Port GPIOB -#define LED_TEST_Pin LL_GPIO_PIN_11 -#define LED_TEST_GPIO_Port GPIOB -#define AUX_SIGNAL_Pin LL_GPIO_PIN_14 -#define AUX_SIGNAL_GPIO_Port GPIOB -#define STEERING_ANGLE_Pin LL_GPIO_PIN_15 -#define STEERING_ANGLE_GPIO_Port GPIOB -#define BRAKE_LIGHT_Pin LL_GPIO_PIN_4 -#define BRAKE_LIGHT_GPIO_Port GPIOB -#define TSSI_G_CONTROL_Pin LL_GPIO_PIN_5 -#define TSSI_G_CONTROL_GPIO_Port GPIOB -#define AUX_CONTROL_Pin LL_GPIO_PIN_8 -#define AUX_CONTROL_GPIO_Port GPIOB -#define SOFTWARE_OK_CONTROL_Pin LL_GPIO_PIN_9 -#define SOFTWARE_OK_CONTROL_GPIO_Port GPIOB - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -#ifdef __cplusplus -} -#endif - -#endif /* __MAIN_H */ diff --git a/G431x8_CAN_TESTING/Core/Inc/spi.h b/G431x8_CAN_TESTING/Core/Inc/spi.h deleted file mode 100644 index 74bed003b..000000000 --- a/G431x8_CAN_TESTING/Core/Inc/spi.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file spi.h - * @brief This file contains all the function prototypes for - * the spi.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __SPI_H__ -#define __SPI_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_SPI3_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __SPI_H__ */ diff --git a/G431x8_CAN_TESTING/Core/Inc/tim.h b/G431x8_CAN_TESTING/Core/Inc/tim.h deleted file mode 100644 index c19e6cc71..000000000 --- a/G431x8_CAN_TESTING/Core/Inc/tim.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file tim.h - * @brief This file contains all the function prototypes for - * the tim.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __TIM_H__ -#define __TIM_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_TIM2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __TIM_H__ */ diff --git a/G431x8_CAN_TESTING/Core/Inc/usart.h b/G431x8_CAN_TESTING/Core/Inc/usart.h deleted file mode 100644 index daefd73e6..000000000 --- a/G431x8_CAN_TESTING/Core/Inc/usart.h +++ /dev/null @@ -1,50 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file usart.h - * @brief This file contains all the function prototypes for - * the usart.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __USART_H__ -#define __USART_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_LPUART1_UART_Init(void); -void MX_USART1_UART_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USART_H__ */ diff --git a/G431x8_CAN_TESTING/Core/Src/adc.c b/G431x8_CAN_TESTING/Core/Src/adc.c deleted file mode 100644 index f3dbff8ed..000000000 --- a/G431x8_CAN_TESTING/Core/Src/adc.c +++ /dev/null @@ -1,186 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file adc.c - * @brief This file provides code for the configuration - * of the ADC instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "adc.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* ADC1 init function */ -void MX_ADC1_Init(void) -{ - - /* USER CODE BEGIN ADC1_Init 0 */ - - /* USER CODE END ADC1_Init 0 */ - - LL_ADC_InitTypeDef ADC_InitStruct = {0}; - LL_ADC_REG_InitTypeDef ADC_REG_InitStruct = {0}; - LL_ADC_CommonInitTypeDef ADC_CommonInitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetADCClockSource(LL_RCC_ADC12_CLKSOURCE_SYSCLK); - - /* Peripheral clock enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_ADC12); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - /**ADC1 GPIO Configuration - PC1 ------> ADC1_IN7 - PC2 ------> ADC1_IN8 - PC3 ------> ADC1_IN9 - PB0 ------> ADC1_IN15 - PB1 ------> ADC1_IN12 - PB14 ------> ADC1_IN5 - */ - GPIO_InitStruct.Pin = BSPD_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BSPD_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = APPS1_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(APPS1_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = APPS2_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(APPS2_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = BRAKE_F_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_F_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = BRAKE_R_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_R_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = AUX_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AUX_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - /* ADC1 DMA Init */ - - /* ADC1 Init */ - LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_1, LL_DMAMUX_REQ_ADC1); - - LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_1, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); - - LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PRIORITY_LOW); - - LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_CIRCULAR); - - LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PERIPH_NOINCREMENT); - - LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT); - - LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_HALFWORD); - - LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_HALFWORD); - - /* USER CODE BEGIN ADC1_Init 1 */ - - /* USER CODE END ADC1_Init 1 */ - - /** Common config - */ - ADC_InitStruct.Resolution = LL_ADC_RESOLUTION_12B; - ADC_InitStruct.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT; - ADC_InitStruct.LowPowerMode = LL_ADC_LP_MODE_NONE; - LL_ADC_Init(ADC1, &ADC_InitStruct); - ADC_REG_InitStruct.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE; - ADC_REG_InitStruct.SequencerLength = LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS; - ADC_REG_InitStruct.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE; - ADC_REG_InitStruct.ContinuousMode = LL_ADC_REG_CONV_CONTINUOUS; - ADC_REG_InitStruct.DMATransfer = LL_ADC_REG_DMA_TRANSFER_UNLIMITED; - ADC_REG_InitStruct.Overrun = LL_ADC_REG_OVR_DATA_PRESERVED; - LL_ADC_REG_Init(ADC1, &ADC_REG_InitStruct); - LL_ADC_SetGainCompensation(ADC1, 0); - LL_ADC_SetOverSamplingScope(ADC1, LL_ADC_OVS_DISABLE); - ADC_CommonInitStruct.CommonClock = LL_ADC_CLOCK_ASYNC_DIV256; - ADC_CommonInitStruct.Multimode = LL_ADC_MULTI_INDEPENDENT; - LL_ADC_CommonInit(__LL_ADC_COMMON_INSTANCE(ADC1), &ADC_CommonInitStruct); - - /* Disable ADC deep power down (enabled by default after reset state) */ - LL_ADC_DisableDeepPowerDown(ADC1); - /* Enable ADC internal voltage regulator */ - LL_ADC_EnableInternalRegulator(ADC1); - /* Delay for ADC internal voltage regulator stabilization. */ - /* Compute number of CPU cycles to wait for, from delay in us. */ - /* Note: Variable divided by 2 to compensate partially */ - /* CPU processing cycles (depends on compilation optimization). */ - /* Note: If system core clock frequency is below 200kHz, wait time */ - /* is only a few CPU processing cycles. */ - uint32_t wait_loop_index; - wait_loop_index = ((LL_ADC_DELAY_INTERNAL_REGUL_STAB_US * (SystemCoreClock / (100000 * 2))) / 10); - while (wait_loop_index != 0) { - wait_loop_index--; - } - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_5); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_5, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_5, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_2, LL_ADC_CHANNEL_7); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_7, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_7, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_3, LL_ADC_CHANNEL_8); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_8, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_8, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_4, LL_ADC_CHANNEL_9); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_9, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_9, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_5, LL_ADC_CHANNEL_12); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_12, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_12, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_6, LL_ADC_CHANNEL_15); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_15, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_15, LL_ADC_SINGLE_ENDED); - /* USER CODE BEGIN ADC1_Init 2 */ - - /* USER CODE END ADC1_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G431x8_CAN_TESTING/Core/Src/crc.c b/G431x8_CAN_TESTING/Core/Src/crc.c deleted file mode 100644 index 213510a5d..000000000 --- a/G431x8_CAN_TESTING/Core/Src/crc.c +++ /dev/null @@ -1,86 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file crc.c - * @brief This file provides code for the configuration - * of the CRC instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "crc.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -CRC_HandleTypeDef hcrc; - -/* CRC init function */ -void MX_CRC_Init(void) -{ - - /* USER CODE BEGIN CRC_Init 0 */ - - /* USER CODE END CRC_Init 0 */ - - /* USER CODE BEGIN CRC_Init 1 */ - - /* USER CODE END CRC_Init 1 */ - hcrc.Instance = CRC; - hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE; - hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE; - hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE; - hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE; - hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES; - if (HAL_CRC_Init(&hcrc) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN CRC_Init 2 */ - - /* USER CODE END CRC_Init 2 */ -} - -void HAL_CRC_MspInit(CRC_HandleTypeDef *crcHandle) -{ - - if (crcHandle->Instance == CRC) { - /* USER CODE BEGIN CRC_MspInit 0 */ - - /* USER CODE END CRC_MspInit 0 */ - /* CRC clock enable */ - __HAL_RCC_CRC_CLK_ENABLE(); - /* USER CODE BEGIN CRC_MspInit 1 */ - - /* USER CODE END CRC_MspInit 1 */ - } -} - -void HAL_CRC_MspDeInit(CRC_HandleTypeDef *crcHandle) -{ - - if (crcHandle->Instance == CRC) { - /* USER CODE BEGIN CRC_MspDeInit 0 */ - - /* USER CODE END CRC_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_CRC_CLK_DISABLE(); - /* USER CODE BEGIN CRC_MspDeInit 1 */ - - /* USER CODE END CRC_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G431x8_CAN_TESTING/Core/Src/dma.c b/G431x8_CAN_TESTING/Core/Src/dma.c deleted file mode 100644 index 491e3889d..000000000 --- a/G431x8_CAN_TESTING/Core/Src/dma.c +++ /dev/null @@ -1,50 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file dma.c - * @brief This file provides code for the configuration - * of all the requested memory to memory DMA transfers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "dma.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure DMA */ -/*----------------------------------------------------------------------------*/ - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** - * Enable DMA controller clock - */ -void MX_DMA_Init(void) -{ - - /* Init with LL driver */ - /* DMA controller clock enable */ - LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMAMUX1); - LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1); -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ diff --git a/G431x8_CAN_TESTING/Core/Src/fdcan.c b/G431x8_CAN_TESTING/Core/Src/fdcan.c deleted file mode 100644 index ebc13ea73..000000000 --- a/G431x8_CAN_TESTING/Core/Src/fdcan.c +++ /dev/null @@ -1,135 +0,0 @@ -// #include "unused.h" -// /* USER CODE BEGIN Header */ -// /** -// ****************************************************************************** -// * @file fdcan.c -// * @brief This file provides code for the configuration -// * of the FDCAN instances. -// ****************************************************************************** -// * @attention -// * -// * Copyright (c) 2024 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 "fdcan.h" - -// /* USER CODE BEGIN 0 */ - -// /* USER CODE END 0 */ - -// FDCAN_HandleTypeDef hfdcan2; - -// /* FDCAN2 init function */ -// void MX_FDCAN2_Init(void) -// { - -// /* USER CODE BEGIN FDCAN2_Init 0 */ - -// /* USER CODE END FDCAN2_Init 0 */ - -// /* USER CODE BEGIN FDCAN2_Init 1 */ - -// /* USER CODE END FDCAN2_Init 1 */ -// hfdcan2.Instance = FDCAN2; -// hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; -// hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; -// hfdcan2.Init.Mode = FDCAN_MODE_NORMAL; -// hfdcan2.Init.AutoRetransmission = ENABLE; -// hfdcan2.Init.TransmitPause = DISABLE; -// hfdcan2.Init.ProtocolException = ENABLE; -// hfdcan2.Init.NominalPrescaler = 1; -// hfdcan2.Init.NominalSyncJumpWidth = 16; -// hfdcan2.Init.NominalTimeSeg1 = 119; -// hfdcan2.Init.NominalTimeSeg2 = 40; -// hfdcan2.Init.DataPrescaler = 8; -// hfdcan2.Init.DataSyncJumpWidth = 16; -// hfdcan2.Init.DataTimeSeg1 = 14; -// hfdcan2.Init.DataTimeSeg2 = 5; -// hfdcan2.Init.StdFiltersNbr = 0; -// hfdcan2.Init.ExtFiltersNbr = 2; -// hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; -// if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { -// Error_Handler(); -// } -// /* USER CODE BEGIN FDCAN2_Init 2 */ - -// /* USER CODE END FDCAN2_Init 2 */ -// } - -// void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) -// { - -// GPIO_InitTypeDef GPIO_InitStruct = {0}; -// if (fdcanHandle->Instance == FDCAN2) { -// /* USER CODE BEGIN FDCAN2_MspInit 0 */ - -// /* USER CODE END FDCAN2_MspInit 0 */ -// LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - -// /* FDCAN2 clock enable */ -// __HAL_RCC_FDCAN_CLK_ENABLE(); - -// __HAL_RCC_GPIOB_CLK_ENABLE(); -// /**FDCAN2 GPIO Configuration -// PB12 ------> FDCAN2_RX -// PB13 ------> FDCAN2_TX -// */ -// GPIO_InitStruct.Pin = GPIO_PIN_12; -// GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; -// GPIO_InitStruct.Pull = GPIO_PULLUP; -// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; -// GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; -// HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - -// GPIO_InitStruct.Pin = 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_FDCAN2; -// HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - -// /* FDCAN2 interrupt Init */ -// HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); -// HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); -// /* USER CODE BEGIN FDCAN2_MspInit 1 */ - -// /* USER CODE END FDCAN2_MspInit 1 */ -// } -// } - -// /*void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) -// { - -// if (fdcanHandle->Instance == FDCAN2) { -// /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - -// /* USER CODE END FDCAN2_MspDeInit 0 */ -// /* Peripheral clock disable */ -// __HAL_RCC_FDCAN_CLK_DISABLE(); - -// /**FDCAN2 GPIO Configuration -// PB12 ------> FDCAN2_RX -// PB13 ------> FDCAN2_TX -// */ -// HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); - -// /* FDCAN2 interrupt Deinit */ -// HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); -// /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - -// /* USER CODE END FDCAN2_MspDeInit 1 */ -// } -// } - -// /* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ -// UNUSED(5); diff --git a/G431x8_CAN_TESTING/Core/Src/gpio.c b/G431x8_CAN_TESTING/Core/Src/gpio.c deleted file mode 100644 index d36e6eca6..000000000 --- a/G431x8_CAN_TESTING/Core/Src/gpio.c +++ /dev/null @@ -1,260 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file gpio.c - * @brief This file provides code for the configuration - * of all used GPIO pins. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "gpio.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure GPIO */ -/*----------------------------------------------------------------------------*/ -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is - enabled through - * the Code Generation settings) - PA6 ------> ADC2_IN3 - PA7 ------> ADC2_IN4 - PB15 ------> ADC2_IN15 - PB7 ------> UART4_CTS -*/ -void MX_GPIO_Init(void) -{ - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(BLINKY_GPIO_Port, BLINKY_Pin); - - /**/ - LL_GPIO_ResetOutputPin(LED_TEST_GPIO_Port, LED_TEST_Pin); - - /**/ - LL_GPIO_ResetOutputPin(BRAKE_LIGHT_GPIO_Port, BRAKE_LIGHT_Pin); - - /**/ - LL_GPIO_ResetOutputPin(TSSI_G_CONTROL_GPIO_Port, TSSI_G_CONTROL_Pin); - - /**/ - LL_GPIO_ResetOutputPin(AUX_CONTROL_GPIO_Port, AUX_CONTROL_Pin); - - /**/ - LL_GPIO_ResetOutputPin(SOFTWARE_OK_CONTROL_GPIO_Port, SOFTWARE_OK_CONTROL_Pin); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_13; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = BLINKY_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BLINKY_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = IMD_SENSE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(IMD_SENSE_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = AMS_SENSE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AMS_SENSE_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LED_TEST_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(LED_TEST_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = STEERING_ANGLE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(STEERING_ANGLE_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = BRAKE_LIGHT_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_LIGHT_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = TSSI_G_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(TSSI_G_CONTROL_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_14; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = AUX_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AUX_CONTROL_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = SOFTWARE_OK_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(SOFTWARE_OK_CONTROL_GPIO_Port, &GPIO_InitStruct); -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ diff --git a/G431x8_CAN_TESTING/Core/Src/i2c.c b/G431x8_CAN_TESTING/Core/Src/i2c.c deleted file mode 100644 index bfb4e0153..000000000 --- a/G431x8_CAN_TESTING/Core/Src/i2c.c +++ /dev/null @@ -1,92 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file i2c.c - * @brief This file provides code for the configuration - * of the I2C instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "i2c.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* I2C2 init function */ -void MX_I2C2_Init(void) -{ - - /* USER CODE BEGIN I2C2_Init 0 */ - - /* USER CODE END I2C2_Init 0 */ - - LL_I2C_InitTypeDef I2C_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetI2CClockSource(LL_RCC_I2C2_CLKSOURCE_PCLK1); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - /**I2C2 GPIO Configuration - PC4 ------> I2C2_SCL - PA8 ------> I2C2_SDA - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_4; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_4; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C2); - - /* USER CODE BEGIN I2C2_Init 1 */ - - /* USER CODE END I2C2_Init 1 */ - - /** I2C Initialization - */ - I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; - I2C_InitStruct.Timing = 0x30D29DE4; - I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE; - I2C_InitStruct.DigitalFilter = 0; - I2C_InitStruct.OwnAddress1 = 0; - I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK; - I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT; - LL_I2C_Init(I2C2, &I2C_InitStruct); - LL_I2C_EnableAutoEndMode(I2C2); - LL_I2C_SetOwnAddress2(I2C2, 0, LL_I2C_OWNADDRESS2_NOMASK); - LL_I2C_DisableOwnAddress2(I2C2); - LL_I2C_DisableGeneralCall(I2C2); - LL_I2C_EnableClockStretching(I2C2); - /* USER CODE BEGIN I2C2_Init 2 */ - - /* USER CODE END I2C2_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G431x8_CAN_TESTING/Core/Src/spi.c b/G431x8_CAN_TESTING/Core/Src/spi.c deleted file mode 100644 index 66459f2ec..000000000 --- a/G431x8_CAN_TESTING/Core/Src/spi.c +++ /dev/null @@ -1,95 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file spi.c - * @brief This file provides code for the configuration - * of the SPI instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "spi.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* SPI3 init function */ -void MX_SPI3_Init(void) -{ - - /* USER CODE BEGIN SPI3_Init 0 */ - - /* USER CODE END SPI3_Init 0 */ - - LL_SPI_InitTypeDef SPI_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI3); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - /**SPI3 GPIO Configuration - PC10 ------> SPI3_SCK - PC11 ------> SPI3_MISO - PC12 ------> SPI3_MOSI - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_6; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_6; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_6; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN SPI3_Init 1 */ - - /* USER CODE END SPI3_Init 1 */ - SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; - SPI_InitStruct.Mode = LL_SPI_MODE_MASTER; - SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_4BIT; - SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; - SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE; - SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; - SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV32; - SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST; - SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; - SPI_InitStruct.CRCPoly = 7; - LL_SPI_Init(SPI3, &SPI_InitStruct); - LL_SPI_SetStandard(SPI3, LL_SPI_PROTOCOL_MOTOROLA); - LL_SPI_EnableNSSPulseMgt(SPI3); - /* USER CODE BEGIN SPI3_Init 2 */ - - /* USER CODE END SPI3_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G431x8_CAN_TESTING/Core/Src/stm32g4xx_it.c b/G431x8_CAN_TESTING/Core/Src/stm32g4xx_it.c deleted file mode 100644 index dd322200e..000000000 --- a/G431x8_CAN_TESTING/Core/Src/stm32g4xx_it.c +++ /dev/null @@ -1,194 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "stm32g4xx_it.h" - -#include "main.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 --------------------------------------------------------*/ -// extern FDCAN_HandleTypeDef hfdcan2; -/* 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 Prefetch 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 */ -} - -/******************************************************************************/ -/* STM32G4xx 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_stm32g4xx.s). */ -/******************************************************************************/ diff --git a/G431x8_CAN_TESTING/Core/Src/tim.c b/G431x8_CAN_TESTING/Core/Src/tim.c deleted file mode 100644 index 7f521c3bf..000000000 --- a/G431x8_CAN_TESTING/Core/Src/tim.c +++ /dev/null @@ -1,79 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file tim.c - * @brief This file provides code for the configuration - * of the TIM instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "tim.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* TIM2 init function */ -void MX_TIM2_Init(void) -{ - - /* USER CODE BEGIN TIM2_Init 0 */ - - /* USER CODE END TIM2_Init 0 */ - - LL_TIM_InitTypeDef TIM_InitStruct = {0}; - LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2); - - /* USER CODE BEGIN TIM2_Init 1 */ - - /* USER CODE END TIM2_Init 1 */ - TIM_InitStruct.Prescaler = 0; - TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; - TIM_InitStruct.Autoreload = 4294967295; - TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; - LL_TIM_Init(TIM2, &TIM_InitStruct); - LL_TIM_DisableARRPreload(TIM2); - LL_TIM_SetClockSource(TIM2, LL_TIM_CLOCKSOURCE_INTERNAL); - TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_FORCED_ACTIVE; - TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; - TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; - TIM_OC_InitStruct.CompareValue = 0; - TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; - LL_TIM_OC_Init(TIM2, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct); - LL_TIM_OC_DisableFast(TIM2, LL_TIM_CHANNEL_CH1); - LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_RESET); - LL_TIM_DisableMasterSlaveMode(TIM2); - /* USER CODE BEGIN TIM2_Init 2 */ - - /* USER CODE END TIM2_Init 2 */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - /**TIM2 GPIO Configuration - PA0 ------> TIM2_CH1 - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_1; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G431x8_CAN_TESTING/Core/Src/usart.c b/G431x8_CAN_TESTING/Core/Src/usart.c deleted file mode 100644 index 41561862c..000000000 --- a/G431x8_CAN_TESTING/Core/Src/usart.c +++ /dev/null @@ -1,184 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file usart.c - * @brief This file provides code for the configuration - * of the USART instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "usart.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* LPUART1 init function */ - -void MX_LPUART1_UART_Init(void) -{ - - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - LL_LPUART_InitTypeDef LPUART_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_HSI); - - /* Peripheral clock enable */ - LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_LPUART1); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_12; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_12; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - LPUART_InitStruct.PrescalerValue = LL_LPUART_PRESCALER_DIV1; - LPUART_InitStruct.BaudRate = 115200; - LPUART_InitStruct.DataWidth = LL_LPUART_DATAWIDTH_8B; - LPUART_InitStruct.StopBits = LL_LPUART_STOPBITS_1; - LPUART_InitStruct.Parity = LL_LPUART_PARITY_NONE; - LPUART_InitStruct.TransferDirection = LL_LPUART_DIRECTION_TX_RX; - LPUART_InitStruct.HardwareFlowControl = LL_LPUART_HWCONTROL_NONE; - LL_LPUART_Init(LPUART1, &LPUART_InitStruct); - LL_LPUART_SetTXFIFOThreshold(LPUART1, LL_LPUART_FIFOTHRESHOLD_1_8); - LL_LPUART_SetRXFIFOThreshold(LPUART1, LL_LPUART_FIFOTHRESHOLD_1_8); - LL_LPUART_DisableFIFO(LPUART1); - - /* USER CODE BEGIN WKUPType LPUART1 */ - - /* USER CODE END WKUPType LPUART1 */ - - LL_LPUART_Enable(LPUART1); - - /* Polling LPUART1 initialisation */ - while ((!(LL_LPUART_IsActiveFlag_TEACK(LPUART1))) || (!(LL_LPUART_IsActiveFlag_REACK(LPUART1)))) {} - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ -} -/* USART1 init function */ - -void MX_USART1_UART_Init(void) -{ - - /* USER CODE BEGIN USART1_Init 0 */ - - /* USER CODE END USART1_Init 0 */ - - LL_USART_InitTypeDef USART_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2); - - /* Peripheral clock enable */ - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - /**USART1 GPIO Configuration - PC5 ------> USART1_RX - PA11 ------> USART1_CTS - PA12 ------> USART1_RTS - PB6 ------> USART1_TX - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* USER CODE BEGIN USART1_Init 1 */ - - /* USER CODE END USART1_Init 1 */ - USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1; - USART_InitStruct.BaudRate = 115200; - USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; - USART_InitStruct.StopBits = LL_USART_STOPBITS_1; - USART_InitStruct.Parity = LL_USART_PARITY_NONE; - USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX; - USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_RTS_CTS; - USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16; - LL_USART_Init(USART1, &USART_InitStruct); - LL_USART_SetTXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8); - LL_USART_SetRXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8); - LL_USART_DisableFIFO(USART1); - LL_USART_ConfigAsyncMode(USART1); - - /* USER CODE BEGIN WKUPType USART1 */ - - /* USER CODE END WKUPType USART1 */ - - LL_USART_Enable(USART1); - - /* Polling USART1 initialisation */ - while ((!(LL_USART_IsActiveFlag_TEACK(USART1))) || (!(LL_USART_IsActiveFlag_REACK(USART1)))) {} - /* USER CODE BEGIN USART1_Init 2 */ - - /* USER CODE END USART1_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/CMakeLists.txt b/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/CMakeLists.txt deleted file mode 100644 index c1a4f180b..000000000 --- a/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/CMakeLists.txt +++ /dev/null @@ -1,65 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -# Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) - -# Define the build type -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug") -endif() - -# Enable compile command to ease indexing with e.g. clangd -set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) - -# Enable CMake support for ASM and C languages -enable_language( - C - ASM -) - -# Core project settings -project(${CMAKE_PROJECT_NAME}) - -# what, does in fact not get the filename of somthing but rather the name of the project from the path -get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) - -add_library(${PROJECT_NAME}_USER_CODE INTERFACE) - -target_sources( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Src/adc.c - ../Core/Src/crc.c - ../Core/Src/dma.c - ../Core/Src/gpio.c - ../Core/Src/i2c.c - main.c - ../Core/Src/spi.c - ../Core/Src/stm32g4xx_hal_msp.c - ../Core/Src/stm32g4xx_it.c - ../Core/Src/tim.c - ../Core/Src/usart.c -) - -set_target_properties( - ${NAME} - PROPERTIES - OUTPUT_NAME - "CAN_${NAME}" -) - -target_link_libraries( - ${PROJECT_NAME}_USER_CODE - INTERFACE - PERIPHERAL_CAN_LIB - LOGOMATIC_OLD_LIB -) - -target_include_directories( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Inc - . -) diff --git a/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/can_cfg.h b/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/can_cfg.h deleted file mode 100644 index 0e987b82d..000000000 --- a/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/can_cfg.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef CAN_CFG_H -#define CAN_CFG_H - -#define USECAN1 -#define TX_BUFFER_1_SIZE 10 - -#endif diff --git a/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/can_external_test_cfg.h b/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/can_external_test_cfg.h deleted file mode 100644 index 0b7e7a815..000000000 --- a/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/can_external_test_cfg.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef CAN_BASIC_TEST_CFG_H -#define CAN_BASIC_TEST_CFG_H - -#define NODE_ID 1 - -#endif diff --git a/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/main.c b/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/main.c deleted file mode 100644 index f10f81707..000000000 --- a/G431x8_CAN_TESTING/G431x8_CAN_BASIC_TEST/main.c +++ /dev/null @@ -1,274 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "adc.h" -#include "can.h" // Assume this works -#include "can_tests.h" -#include "dma.h" -#include "fdcan.h" -#include "gpio.h" -#include "i2c.h" -#include "spi.h" -#include "tim.h" -#include "usart.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -#include "Logomatic.h" -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* 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 -----------------------------------------------*/ -void SystemClock_Config(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ -/* Enable ITM for SWO output */ -static void ITM_Enable(void) -{ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_0; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - DBGMCU->CR |= DBGMCU_CR_TRACE_IOEN; - - /* Enable TRC (Trace) */ - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; - - /* Configure TPI for SWO output (set prescaler for 2MHz SWO clock) */ - TPI->SPPR = 2U; /* 2 = Manchester/async UART mode */ - TPI->ACPR = 84U; /* Prescaler: (170 MHz / (84+1) / 2) ≈ 1MHz SWO */ - - ITM->TER |= (1UL << 0); - ITM->TCR |= (ITM_TCR_ITMENA_Msk | ITM_TCR_SWOENA_Msk); -} -// static int toggleze = 0; -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU - * Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the - * Systick. */ - HAL_Init(); - /* USER CODE BEGIN Init */ - ITM_Enable(); - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); - // MX_FDCAN2_Init(); - MX_ADC1_Init(); - MX_LPUART1_UART_Init(); - MX_I2C2_Init(); - MX_USART1_UART_Init(); - MX_SPI3_Init(); - MX_TIM2_Init(); - - /* USER CODE BEGIN 2 */ - - LOGOMATIC("Booted!\n"); - - // LOGOMATIC("running can_basic_test:\n"); - can_basic_test(); - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) { - /* USER CODE END WHILE */ - LOGOMATIC("Main Loop\n"); - LL_mDelay(10000); - - // Receive on GPIOs - // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, toggleze ? GPIO_PIN_SET - // : GPIO_PIN_RESET); HAL_Delay(1000); msg.data[0] = toggleze ? - // 0x00 : 0x80; can_send(data_can, &msg); - - // RCC->CFGR |= RCC_CFGR_SW; - /* USER CODE BEGIN 3 */ - } -} - -/** - * @brief System Clock Configuration - * @retval None - */ - -// void SystemClock_Config(void) -// { -// LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); -// while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) { -// } -// LL_PWR_EnableRange1BoostMode(); -// LL_RCC_HSE_Enable(); - -// /* Wait till HSE is ready */ -// while (LL_RCC_HSE_IsReady() != 1) { -// } - -// LL_RCC_HSE_EnableCSS(); -// LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_1, 20, -// LL_RCC_PLLR_DIV_2); -// //LL_RCC_PLL_ConfigDomain_48M(LL_RCC_PLLSOURCE_HSE, ); -// LL_RCC_PLL_EnableDomain_SYS(); -// LL_RCC_PLL_Enable(); -// /* Wait till PLL is ready */ -// while (LL_RCC_PLL_IsReady() != 1) { -// } - -// LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); -// /* Wait till System clock is ready */ -// while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { -// } - -// /* Insure 1us transition state at intermediate medium speed clock*/ -// for (__IO uint32_t i = (170 >> 1); i != 0; i--) -// ; - -// /* Set AHB prescaler*/ -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); -// LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); -// LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); -// LL_SetSystemCoreClock(160000000); - -// /* Update the time base */ -// if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { -// Error_Handler(); -// } -// }*/ -void SystemClock_Config(void) -{ - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - // LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(170000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return - * state */ - __disable_irq(); - while (1) {} - /* USER CODE END Error_Handler_Debug */ -} -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line - number, ex: printf("Wrong parameters value: file %s on line %d\r\n", - file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ diff --git a/G431x8_CAN_TESTING/G4PERTESTING.ioc b/G431x8_CAN_TESTING/G4PERTESTING.ioc deleted file mode 100644 index 8cf1860b1..000000000 --- a/G431x8_CAN_TESTING/G4PERTESTING.ioc +++ /dev/null @@ -1,382 +0,0 @@ -#MicroXplorer Configuration settings - do not modify -ADC1.Channel-2\#ChannelRegularConversion=ADC_CHANNEL_5 -ADC1.Channel-3\#ChannelRegularConversion=ADC_CHANNEL_7 -ADC1.Channel-4\#ChannelRegularConversion=ADC_CHANNEL_8 -ADC1.Channel-5\#ChannelRegularConversion=ADC_CHANNEL_9 -ADC1.Channel-6\#ChannelRegularConversion=ADC_CHANNEL_12 -ADC1.Channel-7\#ChannelRegularConversion=ADC_CHANNEL_15 -ADC1.ClockPrescaler=ADC_CLOCK_ASYNC_DIV256 -ADC1.CommonPathInternal=null|null|null|null -ADC1.ContinuousConvMode=ENABLE -ADC1.DMAContinuousRequests=ENABLE -ADC1.EOCSelection=ADC_EOC_SEQ_CONV -ADC1.ExternalTrigConv=ADC_SOFTWARE_START -ADC1.IPParameters=Rank-2\#ChannelRegularConversion,Channel-2\#ChannelRegularConversion,SamplingTime-2\#ChannelRegularConversion,OffsetNumber-2\#ChannelRegularConversion,NbrOfConversionFlag,master,Rank-3\#ChannelRegularConversion,Channel-3\#ChannelRegularConversion,SamplingTime-3\#ChannelRegularConversion,OffsetNumber-3\#ChannelRegularConversion,Rank-4\#ChannelRegularConversion,Channel-4\#ChannelRegularConversion,SamplingTime-4\#ChannelRegularConversion,OffsetNumber-4\#ChannelRegularConversion,Rank-5\#ChannelRegularConversion,Channel-5\#ChannelRegularConversion,SamplingTime-5\#ChannelRegularConversion,OffsetNumber-5\#ChannelRegularConversion,Rank-6\#ChannelRegularConversion,Channel-6\#ChannelRegularConversion,SamplingTime-6\#ChannelRegularConversion,OffsetNumber-6\#ChannelRegularConversion,Rank-7\#ChannelRegularConversion,Channel-7\#ChannelRegularConversion,SamplingTime-7\#ChannelRegularConversion,OffsetNumber-7\#ChannelRegularConversion,NbrOfConversion,ContinuousConvMode,DMAContinuousRequests,ClockPrescaler,EOCSelection,ExternalTrigConv,CommonPathInternal -ADC1.NbrOfConversion=6 -ADC1.NbrOfConversionFlag=1 -ADC1.OffsetNumber-2\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-3\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-4\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-5\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-6\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-7\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.Rank-2\#ChannelRegularConversion=1 -ADC1.Rank-3\#ChannelRegularConversion=2 -ADC1.Rank-4\#ChannelRegularConversion=3 -ADC1.Rank-5\#ChannelRegularConversion=4 -ADC1.Rank-6\#ChannelRegularConversion=5 -ADC1.Rank-7\#ChannelRegularConversion=6 -ADC1.SamplingTime-2\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-3\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-4\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-5\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-6\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-7\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.master=1 -CAD.formats=[] -CAD.pinconfig=Dual -CAD.provider= -Dma.ADC1.0.Direction=DMA_PERIPH_TO_MEMORY -Dma.ADC1.0.EventEnable=DISABLE -Dma.ADC1.0.Instance=DMA1_Channel1 -Dma.ADC1.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD -Dma.ADC1.0.MemInc=DMA_MINC_ENABLE -Dma.ADC1.0.Mode=DMA_CIRCULAR -Dma.ADC1.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD -Dma.ADC1.0.PeriphInc=DMA_PINC_DISABLE -Dma.ADC1.0.Polarity=HAL_DMAMUX_REQ_GEN_RISING -Dma.ADC1.0.Priority=DMA_PRIORITY_LOW -Dma.ADC1.0.RequestNumber=1 -Dma.ADC1.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber -Dma.ADC1.0.SignalID=NONE -Dma.ADC1.0.SyncEnable=DISABLE -Dma.ADC1.0.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT -Dma.ADC1.0.SyncRequestNumber=1 -Dma.ADC1.0.SyncSignalID=NONE -Dma.Request0=ADC1 -Dma.RequestsNb=1 -FDCAN2.AutoRetransmission=ENABLE -FDCAN2.CalculateBaudRateNominal=1000000 -FDCAN2.CalculateTimeBitNominal=1000 -FDCAN2.CalculateTimeQuantumNominal=6.25 -FDCAN2.DataPrescaler=8 -FDCAN2.DataSyncJumpWidth=16 -FDCAN2.DataTimeSeg1=14 -FDCAN2.DataTimeSeg2=5 -FDCAN2.ExtFiltersNbr=2 -FDCAN2.FrameFormat=FDCAN_FRAME_CLASSIC -FDCAN2.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal,FrameFormat,NominalTimeSeg1,NominalTimeSeg2,NominalPrescaler,AutoRetransmission,StdFiltersNbr,TransmitPause,NominalSyncJumpWidth,DataTimeSeg1,DataTimeSeg2,DataPrescaler,DataSyncJumpWidth,ExtFiltersNbr,ProtocolException -FDCAN2.NominalPrescaler=1 -FDCAN2.NominalSyncJumpWidth=16 -FDCAN2.NominalTimeSeg1=119 -FDCAN2.NominalTimeSeg2=40 -FDCAN2.ProtocolException=ENABLE -FDCAN2.StdFiltersNbr=0 -FDCAN2.TransmitPause=DISABLE -File.Version=6 -GPIO.groupedBy=Group By Peripherals -I2C2.IPParameters=Timing -I2C2.Timing=0x30D29DE4 -KeepUserPlacement=false -LPUART1.BaudRate=115200 -LPUART1.IPParameters=BaudRate -Mcu.CPN=STM32G474RET6 -Mcu.Family=STM32G4 -Mcu.IP0=ADC1 -Mcu.IP1=DMA -Mcu.IP10=USART1 -Mcu.IP2=FDCAN2 -Mcu.IP3=I2C2 -Mcu.IP4=LPUART1 -Mcu.IP5=NVIC -Mcu.IP6=RCC -Mcu.IP7=SPI3 -Mcu.IP8=SYS -Mcu.IP9=TIM2 -Mcu.IPNb=11 -Mcu.Name=STM32G474R(B-C-E)Tx -Mcu.Package=LQFP64 -Mcu.Pin0=PF0-OSC_IN -Mcu.Pin1=PF1-OSC_OUT -Mcu.Pin10=PA7 -Mcu.Pin11=PC4 -Mcu.Pin12=PC5 -Mcu.Pin13=PB0 -Mcu.Pin14=PB1 -Mcu.Pin15=PB11 -Mcu.Pin16=PB12 -Mcu.Pin17=PB13 -Mcu.Pin18=PB14 -Mcu.Pin19=PB15 -Mcu.Pin2=PC1 -Mcu.Pin20=PA8 -Mcu.Pin21=PA11 -Mcu.Pin22=PA12 -Mcu.Pin23=PA13 -Mcu.Pin24=PA14 -Mcu.Pin25=PC10 -Mcu.Pin26=PC11 -Mcu.Pin27=PC12 -Mcu.Pin28=PB3 -Mcu.Pin29=PB4 -Mcu.Pin3=PC2 -Mcu.Pin30=PB5 -Mcu.Pin31=PB6 -Mcu.Pin32=PB7 -Mcu.Pin33=PB8-BOOT0 -Mcu.Pin34=PB9 -Mcu.Pin35=VP_SYS_VS_Systick -Mcu.Pin36=VP_SYS_VS_DBSignals -Mcu.Pin37=VP_TIM2_VS_ClockSourceINT -Mcu.Pin4=PC3 -Mcu.Pin5=PA0 -Mcu.Pin6=PA2 -Mcu.Pin7=PA3 -Mcu.Pin8=PA5 -Mcu.Pin9=PA6 -Mcu.PinsNb=38 -Mcu.ThirdPartyNb=0 -Mcu.UserConstants= -Mcu.UserName=STM32G474RETx -MxCube.Version=6.15.0 -MxDb.Version=DB.6.0.150 -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.FDCAN2_IT0_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true -NVIC.ForceEnableDMAVector=false -NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:false -NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 -NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false -NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -PA0.Signal=S_TIM2_CH1 -PA11.Locked=true -PA11.Mode=CTS_RTS -PA11.Signal=USART1_CTS -PA12.Locked=true -PA12.Mode=CTS_RTS -PA12.Signal=USART1_RTS -PA13.Locked=true -PA13.Mode=Trace_Asynchronous_SW -PA13.Signal=SYS_JTMS-SWDIO -PA14.Locked=true -PA14.Mode=Trace_Asynchronous_SW -PA14.Signal=SYS_JTCK-SWCLK -PA2.GPIOParameters=GPIO_Speed -PA2.GPIO_Speed=GPIO_SPEED_FREQ_HIGH -PA2.Locked=true -PA2.Mode=Asynchronous -PA2.Signal=LPUART1_TX -PA3.GPIOParameters=GPIO_Speed -PA3.GPIO_Speed=GPIO_SPEED_FREQ_HIGH -PA3.Locked=true -PA3.Mode=Asynchronous -PA3.Signal=LPUART1_RX -PA5.GPIOParameters=GPIO_Label -PA5.GPIO_Label=BLINKY -PA5.Locked=true -PA5.Signal=GPIO_Output -PA6.GPIOParameters=GPIO_Label -PA6.GPIO_Label=IMD_SENSE -PA6.Locked=true -PA6.Signal=ADC2_IN3 -PA7.GPIOParameters=GPIO_Label -PA7.GPIO_Label=AMS_SENSE -PA7.Locked=true -PA7.Signal=ADC2_IN4 -PA8.Mode=I2C -PA8.Signal=I2C2_SDA -PB0.GPIOParameters=GPIO_Label -PB0.GPIO_Label=BRAKE_F_SIGNAL -PB0.Locked=true -PB0.Mode=IN15-Single-Ended -PB0.Signal=ADC1_IN15 -PB1.GPIOParameters=GPIO_Label -PB1.GPIO_Label=BRAKE_R_SIGNAL -PB1.Locked=true -PB1.Mode=IN12-Single-Ended -PB1.Signal=ADC1_IN12 -PB11.GPIOParameters=GPIO_Label -PB11.GPIO_Label=LED_TEST -PB11.Locked=true -PB11.Signal=GPIO_Output -PB12.GPIOParameters=GPIO_Speed,GPIO_PuPd -PB12.GPIO_PuPd=GPIO_PULLUP -PB12.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PB12.Locked=true -PB12.Mode=FDCAN_Activate -PB12.Signal=FDCAN2_RX -PB13.GPIOParameters=GPIO_Speed -PB13.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PB13.Locked=true -PB13.Mode=FDCAN_Activate -PB13.Signal=FDCAN2_TX -PB14.GPIOParameters=GPIO_Label -PB14.GPIO_Label=AUX_SIGNAL -PB14.Locked=true -PB14.Mode=IN5-Single-Ended -PB14.Signal=ADC1_IN5 -PB15.GPIOParameters=GPIO_Label -PB15.GPIO_Label=STEERING_ANGLE -PB15.Locked=true -PB15.Signal=ADC2_IN15 -PB3.Locked=true -PB3.Mode=Trace_Asynchronous_SW -PB3.Signal=SYS_JTDO-SWO -PB4.GPIOParameters=GPIO_Label -PB4.GPIO_Label=BRAKE_LIGHT -PB4.Locked=true -PB4.Signal=GPIO_Output -PB5.GPIOParameters=GPIO_Label -PB5.GPIO_Label=TSSI_G_CONTROL -PB5.Locked=true -PB5.Signal=GPIO_Output -PB6.Locked=true -PB6.Mode=Asynchronous -PB6.Signal=USART1_TX -PB7.Locked=true -PB7.Signal=UART4_CTS -PB8-BOOT0.GPIOParameters=GPIO_Label -PB8-BOOT0.GPIO_Label=AUX_CONTROL -PB8-BOOT0.Locked=true -PB8-BOOT0.Signal=GPIO_Output -PB9.GPIOParameters=GPIO_Label -PB9.GPIO_Label=SOFTWARE_OK_CONTROL -PB9.Locked=true -PB9.Signal=GPIO_Output -PC1.GPIOParameters=GPIO_Label -PC1.GPIO_Label=BSPD_SIGNAL -PC1.Locked=true -PC1.Mode=IN7-Single-Ended -PC1.Signal=ADC1_IN7 -PC10.Mode=Full_Duplex_Master -PC10.Signal=SPI3_SCK -PC11.Mode=Full_Duplex_Master -PC11.Signal=SPI3_MISO -PC12.Mode=Full_Duplex_Master -PC12.Signal=SPI3_MOSI -PC2.GPIOParameters=GPIO_Label -PC2.GPIO_Label=APPS1_SIGNAL -PC2.Locked=true -PC2.Mode=IN8-Single-Ended -PC2.Signal=ADC1_IN8 -PC3.GPIOParameters=GPIO_Label -PC3.GPIO_Label=APPS2_SIGNAL -PC3.Locked=true -PC3.Mode=IN9-Single-Ended -PC3.Signal=ADC1_IN9 -PC4.Mode=I2C -PC4.Signal=I2C2_SCL -PC5.Mode=Asynchronous -PC5.Signal=USART1_RX -PF0-OSC_IN.Locked=true -PF0-OSC_IN.Mode=HSE-External-Oscillator -PF0-OSC_IN.Signal=RCC_OSC_IN -PF1-OSC_OUT.Locked=true -PF1-OSC_OUT.Mode=HSE-External-Oscillator -PF1-OSC_OUT.Signal=RCC_OSC_OUT -PinOutPanel.RotationAngle=180 -ProjectManager.AskForMigrate=true -ProjectManager.BackupPrevious=false -ProjectManager.CompilerLinker=GCC -ProjectManager.CompilerOptimize=6 -ProjectManager.ComputerToolchain=false -ProjectManager.CoupleFile=true -ProjectManager.CustomerFirmwarePackage= -ProjectManager.DefaultFWLocation=true -ProjectManager.DeletePrevious=true -ProjectManager.DeviceId=STM32G474RETx -ProjectManager.FirmwarePackage=STM32Cube FW_G4 V1.6.1 -ProjectManager.FreePins=true -ProjectManager.HalAssertFull=false -ProjectManager.HeapSize=0x200 -ProjectManager.KeepUserCode=true -ProjectManager.LastFirmware=true -ProjectManager.LibraryCopy=0 -ProjectManager.MainLocation=Core/Src -ProjectManager.NoMain=false -ProjectManager.PreviousToolchain= -ProjectManager.ProjectBuild=false -ProjectManager.ProjectFileName=G4PERTESTING.ioc -ProjectManager.ProjectName=G4PERTESTING -ProjectManager.ProjectStructure= -ProjectManager.RegisterCallBack= -ProjectManager.StackSize=0x400 -ProjectManager.TargetToolchain=CMake -ProjectManager.ToolChainLocation= -ProjectManager.UAScriptAfterPath= -ProjectManager.UAScriptBeforePath= -ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_DMA_Init-DMA-false-LL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_ADC1_Init-ADC1-false-LL-true,6-MX_LPUART1_UART_Init-LPUART1-false-LL-true,7-MX_I2C2_Init-I2C2-false-LL-true,8-MX_USART1_UART_Init-USART1-false-LL-true,9-MX_SPI3_Init-SPI3-false-LL-true,10-MX_TIM2_Init-TIM2-false-LL-true -RCC.ADC12Freq_Value=160000000 -RCC.ADC345Freq_Value=160000000 -RCC.AHBFreq_Value=160000000 -RCC.APB1Freq_Value=160000000 -RCC.APB1TimFreq_Value=160000000 -RCC.APB2Freq_Value=160000000 -RCC.APB2TimFreq_Value=160000000 -RCC.CRSFreq_Value=48000000 -RCC.CortexFreq_Value=160000000 -RCC.EXTERNAL_CLOCK_VALUE=12288000 -RCC.EnbaleCSS=true -RCC.FCLKCortexFreq_Value=160000000 -RCC.FDCANFreq_Value=160000000 -RCC.FamilyName=M -RCC.HCLKFreq_Value=160000000 -RCC.HRTIM1Freq_Value=160000000 -RCC.HSE_VALUE=16000000 -RCC.HSI48_VALUE=48000000 -RCC.HSI_VALUE=16000000 -RCC.I2C1Freq_Value=160000000 -RCC.I2C2Freq_Value=160000000 -RCC.I2C3Freq_Value=160000000 -RCC.I2C4Freq_Value=160000000 -RCC.I2SFreq_Value=160000000 -RCC.IPParameters=ADC12Freq_Value,ADC345Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,EnbaleCSS,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HRTIM1Freq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PLLSourceVirtual,PWRFreq_Value,QSPIFreq_Value,RNGFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value -RCC.LPTIM1Freq_Value=160000000 -RCC.LPUART1Freq_Value=160000000 -RCC.LSCOPinFreq_Value=32000 -RCC.LSE_VALUE=32768 -RCC.LSI_VALUE=32000 -RCC.MCO1PinFreq_Value=16000000 -RCC.PLLN=20 -RCC.PLLPoutputFreq_Value=160000000 -RCC.PLLQoutputFreq_Value=160000000 -RCC.PLLRCLKFreq_Value=160000000 -RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE -RCC.PWRFreq_Value=160000000 -RCC.QSPIFreq_Value=160000000 -RCC.RNGFreq_Value=160000000 -RCC.SAI1Freq_Value=160000000 -RCC.SYSCLKFreq_VALUE=160000000 -RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK -RCC.UART4Freq_Value=160000000 -RCC.UART5Freq_Value=160000000 -RCC.USART1Freq_Value=160000000 -RCC.USART2Freq_Value=160000000 -RCC.USART3Freq_Value=160000000 -RCC.USBFreq_Value=160000000 -RCC.VCOInputFreq_Value=16000000 -RCC.VCOOutputFreq_Value=320000000 -SH.S_TIM2_CH1.0=TIM2_CH1,Forced Output1 CH1 -SH.S_TIM2_CH1.ConfNb=1 -SPI3.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_32 -SPI3.CalculateBaudRate=5.0 MBits/s -SPI3.Direction=SPI_DIRECTION_2LINES -SPI3.IPParameters=VirtualType,Mode,Direction,BaudRatePrescaler,CalculateBaudRate -SPI3.Mode=SPI_MODE_MASTER -SPI3.VirtualType=VM_MASTER -TIM2.Channel-Forced\ Output1\ CH1=TIM_CHANNEL_1 -TIM2.IPParameters=Channel-Forced Output1 CH1 -USART1.IPParameters=VirtualMode-Asynchronous -USART1.VirtualMode-Asynchronous=VM_ASYNC -VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals -VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick -VP_TIM2_VS_ClockSourceINT.Mode=Internal -VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT -board=custom diff --git a/G431x8_CAN_TESTING/README.md b/G431x8_CAN_TESTING/README.md deleted file mode 100644 index 558f1c125..000000000 --- a/G431x8_CAN_TESTING/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# STM32G474 CAN -Nucleo-G474RE-C04 - -Plug in the board following ST-LINK pinout -Compile and flash G4CANTESTING.elf diff --git a/G474xE_CAN_TESTING/CAN_BASIC_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_BASIC_TEST/CMakeLists.txt deleted file mode 100644 index c1a4f180b..000000000 --- a/G474xE_CAN_TESTING/CAN_BASIC_TEST/CMakeLists.txt +++ /dev/null @@ -1,65 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -# Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) - -# Define the build type -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug") -endif() - -# Enable compile command to ease indexing with e.g. clangd -set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) - -# Enable CMake support for ASM and C languages -enable_language( - C - ASM -) - -# Core project settings -project(${CMAKE_PROJECT_NAME}) - -# what, does in fact not get the filename of somthing but rather the name of the project from the path -get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) - -add_library(${PROJECT_NAME}_USER_CODE INTERFACE) - -target_sources( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Src/adc.c - ../Core/Src/crc.c - ../Core/Src/dma.c - ../Core/Src/gpio.c - ../Core/Src/i2c.c - main.c - ../Core/Src/spi.c - ../Core/Src/stm32g4xx_hal_msp.c - ../Core/Src/stm32g4xx_it.c - ../Core/Src/tim.c - ../Core/Src/usart.c -) - -set_target_properties( - ${NAME} - PROPERTIES - OUTPUT_NAME - "CAN_${NAME}" -) - -target_link_libraries( - ${PROJECT_NAME}_USER_CODE - INTERFACE - PERIPHERAL_CAN_LIB - LOGOMATIC_OLD_LIB -) - -target_include_directories( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Inc - . -) diff --git a/G474xE_CAN_TESTING/CAN_BASIC_TEST/can_cfg.h b/G474xE_CAN_TESTING/CAN_BASIC_TEST/can_cfg.h deleted file mode 100644 index 8a18e8882..000000000 --- a/G474xE_CAN_TESTING/CAN_BASIC_TEST/can_cfg.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CAN_CFG_H -#define CAN_CFG_H - -#define USECAN1 -#define TX_BUFFER_1_SIZE 10 - -#define USECAN2 -#define TX_BUFFER_2_SIZE 10 - -#endif diff --git a/G474xE_CAN_TESTING/CAN_BASIC_TEST/can_external_test_cfg.h b/G474xE_CAN_TESTING/CAN_BASIC_TEST/can_external_test_cfg.h deleted file mode 100644 index 0b7e7a815..000000000 --- a/G474xE_CAN_TESTING/CAN_BASIC_TEST/can_external_test_cfg.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef CAN_BASIC_TEST_CFG_H -#define CAN_BASIC_TEST_CFG_H - -#define NODE_ID 1 - -#endif diff --git a/G474xE_CAN_TESTING/CAN_BASIC_TEST/main.c b/G474xE_CAN_TESTING/CAN_BASIC_TEST/main.c deleted file mode 100644 index f10f81707..000000000 --- a/G474xE_CAN_TESTING/CAN_BASIC_TEST/main.c +++ /dev/null @@ -1,274 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "adc.h" -#include "can.h" // Assume this works -#include "can_tests.h" -#include "dma.h" -#include "fdcan.h" -#include "gpio.h" -#include "i2c.h" -#include "spi.h" -#include "tim.h" -#include "usart.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -#include "Logomatic.h" -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* 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 -----------------------------------------------*/ -void SystemClock_Config(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ -/* Enable ITM for SWO output */ -static void ITM_Enable(void) -{ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_0; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - DBGMCU->CR |= DBGMCU_CR_TRACE_IOEN; - - /* Enable TRC (Trace) */ - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; - - /* Configure TPI for SWO output (set prescaler for 2MHz SWO clock) */ - TPI->SPPR = 2U; /* 2 = Manchester/async UART mode */ - TPI->ACPR = 84U; /* Prescaler: (170 MHz / (84+1) / 2) ≈ 1MHz SWO */ - - ITM->TER |= (1UL << 0); - ITM->TCR |= (ITM_TCR_ITMENA_Msk | ITM_TCR_SWOENA_Msk); -} -// static int toggleze = 0; -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU - * Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the - * Systick. */ - HAL_Init(); - /* USER CODE BEGIN Init */ - ITM_Enable(); - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); - // MX_FDCAN2_Init(); - MX_ADC1_Init(); - MX_LPUART1_UART_Init(); - MX_I2C2_Init(); - MX_USART1_UART_Init(); - MX_SPI3_Init(); - MX_TIM2_Init(); - - /* USER CODE BEGIN 2 */ - - LOGOMATIC("Booted!\n"); - - // LOGOMATIC("running can_basic_test:\n"); - can_basic_test(); - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) { - /* USER CODE END WHILE */ - LOGOMATIC("Main Loop\n"); - LL_mDelay(10000); - - // Receive on GPIOs - // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, toggleze ? GPIO_PIN_SET - // : GPIO_PIN_RESET); HAL_Delay(1000); msg.data[0] = toggleze ? - // 0x00 : 0x80; can_send(data_can, &msg); - - // RCC->CFGR |= RCC_CFGR_SW; - /* USER CODE BEGIN 3 */ - } -} - -/** - * @brief System Clock Configuration - * @retval None - */ - -// void SystemClock_Config(void) -// { -// LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); -// while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) { -// } -// LL_PWR_EnableRange1BoostMode(); -// LL_RCC_HSE_Enable(); - -// /* Wait till HSE is ready */ -// while (LL_RCC_HSE_IsReady() != 1) { -// } - -// LL_RCC_HSE_EnableCSS(); -// LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_1, 20, -// LL_RCC_PLLR_DIV_2); -// //LL_RCC_PLL_ConfigDomain_48M(LL_RCC_PLLSOURCE_HSE, ); -// LL_RCC_PLL_EnableDomain_SYS(); -// LL_RCC_PLL_Enable(); -// /* Wait till PLL is ready */ -// while (LL_RCC_PLL_IsReady() != 1) { -// } - -// LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); -// /* Wait till System clock is ready */ -// while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { -// } - -// /* Insure 1us transition state at intermediate medium speed clock*/ -// for (__IO uint32_t i = (170 >> 1); i != 0; i--) -// ; - -// /* Set AHB prescaler*/ -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); -// LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); -// LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); -// LL_SetSystemCoreClock(160000000); - -// /* Update the time base */ -// if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { -// Error_Handler(); -// } -// }*/ -void SystemClock_Config(void) -{ - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - // LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(170000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return - * state */ - __disable_irq(); - while (1) {} - /* USER CODE END Error_Handler_Debug */ -} -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line - number, ex: printf("Wrong parameters value: file %s on line %d\r\n", - file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ diff --git a/G474xE_CAN_TESTING/CAN_FILTER_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_FILTER_TEST/CMakeLists.txt deleted file mode 100644 index e3c0515e4..000000000 --- a/G474xE_CAN_TESTING/CAN_FILTER_TEST/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -# Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) - -# Define the build type -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug") -endif() - -# Enable compile command to ease indexing with e.g. clangd -set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) - -# Enable CMake support for ASM and C languages -enable_language( - C - ASM -) - -# Core project settings -project(${CMAKE_PROJECT_NAME}) - -# what, does in fact not get the filename of somthing but rather the name of the project from the path -get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) - -add_library(${PROJECT_NAME}_USER_CODE INTERFACE) - -target_sources( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Src/adc.c - ../Core/Src/crc.c - ../Core/Src/dma.c - ../Core/Src/gpio.c - ../Core/Src/i2c.c - main.c - ../Core/Src/spi.c - ../Core/Src/stm32g4xx_hal_msp.c - ../Core/Src/stm32g4xx_it.c - ../Core/Src/tim.c - ../Core/Src/usart.c -) - -target_link_libraries( - ${PROJECT_NAME}_USER_CODE - INTERFACE - PERIPHERAL_CAN_LIB - LOGOMATIC_OLD_LIB -) - -target_include_directories( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Inc - . -) diff --git a/G474xE_CAN_TESTING/CAN_FILTER_TEST/can_cfg.h b/G474xE_CAN_TESTING/CAN_FILTER_TEST/can_cfg.h deleted file mode 100644 index fc11e3e23..000000000 --- a/G474xE_CAN_TESTING/CAN_FILTER_TEST/can_cfg.h +++ /dev/null @@ -1,11 +0,0 @@ - -#ifndef CAN_CFG_H -#define CAN_CFG_H - -#define USECAN1 -#define TX_BUFFER_1_SIZE 10 - -#define USECAN2 -#define TX_BUFFER_2_SIZE 10 - -#endif diff --git a/G474xE_CAN_TESTING/CAN_FILTER_TEST/main.c b/G474xE_CAN_TESTING/CAN_FILTER_TEST/main.c deleted file mode 100644 index 8fe024424..000000000 --- a/G474xE_CAN_TESTING/CAN_FILTER_TEST/main.c +++ /dev/null @@ -1,274 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "adc.h" -#include "can.h" // Assume this works -#include "can_tests.h" -#include "dma.h" -#include "fdcan.h" -#include "gpio.h" -#include "i2c.h" -#include "spi.h" -#include "tim.h" -#include "usart.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -#include "Logomatic.h" -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* 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 -----------------------------------------------*/ -void SystemClock_Config(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ -/* Enable ITM for SWO output */ -static void ITM_Enable(void) -{ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_0; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - DBGMCU->CR |= DBGMCU_CR_TRACE_IOEN; - - /* Enable TRC (Trace) */ - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; - - /* Configure TPI for SWO output (set prescaler for 2MHz SWO clock) */ - TPI->SPPR = 2U; /* 2 = Manchester/async UART mode */ - TPI->ACPR = 84U; /* Prescaler: (170 MHz / (84+1) / 2) ≈ 1MHz SWO */ - - ITM->TER |= (1UL << 0); - ITM->TCR |= (ITM_TCR_ITMENA_Msk | ITM_TCR_SWOENA_Msk); -} -// static int toggleze = 0; -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU - * Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the - * Systick. */ - HAL_Init(); - /* USER CODE BEGIN Init */ - ITM_Enable(); - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); - // MX_FDCAN2_Init(); - MX_ADC1_Init(); - MX_LPUART1_UART_Init(); - MX_I2C2_Init(); - MX_USART1_UART_Init(); - MX_SPI3_Init(); - MX_TIM2_Init(); - - /* USER CODE BEGIN 2 */ - - LOGOMATIC("Booted!\n"); - - // LOGOMATIC("running can_stress_test:\n"); - can_filter_test(); - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) { - /* USER CODE END WHILE */ - LOGOMATIC("Main Loop\n"); - LL_mDelay(1000); - - // Receive on GPIOs - // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, toggleze ? GPIO_PIN_SET - // : GPIO_PIN_RESET); HAL_Delay(1000); msg.data[0] = toggleze ? - // 0x00 : 0x80; can_send(data_can, &msg); - - // RCC->CFGR |= RCC_CFGR_SW; - /* USER CODE BEGIN 3 */ - } -} - -/** - * @brief System Clock Configuration - * @retval None - */ - -// void SystemClock_Config(void) -// { -// LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); -// while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) { -// } -// LL_PWR_EnableRange1BoostMode(); -// LL_RCC_HSE_Enable(); - -// /* Wait till HSE is ready */ -// while (LL_RCC_HSE_IsReady() != 1) { -// } - -// LL_RCC_HSE_EnableCSS(); -// LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_1, 20, -// LL_RCC_PLLR_DIV_2); -// //LL_RCC_PLL_ConfigDomain_48M(LL_RCC_PLLSOURCE_HSE, ); -// LL_RCC_PLL_EnableDomain_SYS(); -// LL_RCC_PLL_Enable(); -// /* Wait till PLL is ready */ -// while (LL_RCC_PLL_IsReady() != 1) { -// } - -// LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); -// /* Wait till System clock is ready */ -// while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { -// } - -// /* Insure 1us transition state at intermediate medium speed clock*/ -// for (__IO uint32_t i = (170 >> 1); i != 0; i--) -// ; - -// /* Set AHB prescaler*/ -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); -// LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); -// LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); -// LL_SetSystemCoreClock(160000000); - -// /* Update the time base */ -// if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { -// Error_Handler(); -// } -// }*/ -void SystemClock_Config(void) -{ - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - // LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(170000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return - * state */ - __disable_irq(); - while (1) {} - /* USER CODE END Error_Handler_Debug */ -} -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line - number, ex: printf("Wrong parameters value: file %s on line %d\r\n", - file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ diff --git a/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/CMakeLists.txt deleted file mode 100644 index c1a4f180b..000000000 --- a/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/CMakeLists.txt +++ /dev/null @@ -1,65 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -# Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) - -# Define the build type -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug") -endif() - -# Enable compile command to ease indexing with e.g. clangd -set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) - -# Enable CMake support for ASM and C languages -enable_language( - C - ASM -) - -# Core project settings -project(${CMAKE_PROJECT_NAME}) - -# what, does in fact not get the filename of somthing but rather the name of the project from the path -get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) - -add_library(${PROJECT_NAME}_USER_CODE INTERFACE) - -target_sources( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Src/adc.c - ../Core/Src/crc.c - ../Core/Src/dma.c - ../Core/Src/gpio.c - ../Core/Src/i2c.c - main.c - ../Core/Src/spi.c - ../Core/Src/stm32g4xx_hal_msp.c - ../Core/Src/stm32g4xx_it.c - ../Core/Src/tim.c - ../Core/Src/usart.c -) - -set_target_properties( - ${NAME} - PROPERTIES - OUTPUT_NAME - "CAN_${NAME}" -) - -target_link_libraries( - ${PROJECT_NAME}_USER_CODE - INTERFACE - PERIPHERAL_CAN_LIB - LOGOMATIC_OLD_LIB -) - -target_include_directories( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Inc - . -) diff --git a/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/can_cfg.h b/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/can_cfg.h deleted file mode 100644 index 8a18e8882..000000000 --- a/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/can_cfg.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CAN_CFG_H -#define CAN_CFG_H - -#define USECAN1 -#define TX_BUFFER_1_SIZE 10 - -#define USECAN2 -#define TX_BUFFER_2_SIZE 10 - -#endif diff --git a/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/main.c b/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/main.c deleted file mode 100644 index 9c2f2b7a4..000000000 --- a/G474xE_CAN_TESTING/CAN_INTERNAL_TEST/main.c +++ /dev/null @@ -1,274 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "adc.h" -#include "can.h" // Assume this works -#include "can_tests.h" -#include "dma.h" -#include "fdcan.h" -#include "gpio.h" -#include "i2c.h" -#include "spi.h" -#include "tim.h" -#include "usart.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -#include "Logomatic.h" -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* 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 -----------------------------------------------*/ -void SystemClock_Config(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ -/* Enable ITM for SWO output */ -static void ITM_Enable(void) -{ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_0; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - DBGMCU->CR |= DBGMCU_CR_TRACE_IOEN; - - /* Enable TRC (Trace) */ - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; - - /* Configure TPI for SWO output (set prescaler for 2MHz SWO clock) */ - TPI->SPPR = 2U; /* 2 = Manchester/async UART mode */ - TPI->ACPR = 84U; /* Prescaler: (170 MHz / (84+1) / 2) ≈ 1MHz SWO */ - - ITM->TER |= (1UL << 0); - ITM->TCR |= (ITM_TCR_ITMENA_Msk | ITM_TCR_SWOENA_Msk); -} -// static int toggleze = 0; -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU - * Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the - * Systick. */ - HAL_Init(); - /* USER CODE BEGIN Init */ - ITM_Enable(); - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); - // MX_FDCAN2_Init(); - MX_ADC1_Init(); - MX_LPUART1_UART_Init(); - MX_I2C2_Init(); - MX_USART1_UART_Init(); - MX_SPI3_Init(); - MX_TIM2_Init(); - - /* USER CODE BEGIN 2 */ - - LOGOMATIC("Booted!\n"); - - // LOGOMATIC("running can_internal_test:\n"); - can_internal_test(); - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) { - /* USER CODE END WHILE */ - LOGOMATIC("Main Loop\n"); - LL_mDelay(10000); - - // Receive on GPIOs - // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, toggleze ? GPIO_PIN_SET - // : GPIO_PIN_RESET); HAL_Delay(1000); msg.data[0] = toggleze ? - // 0x00 : 0x80; can_send(data_can, &msg); - - // RCC->CFGR |= RCC_CFGR_SW; - /* USER CODE BEGIN 3 */ - } -} - -/** - * @brief System Clock Configuration - * @retval None - */ - -// void SystemClock_Config(void) -// { -// LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); -// while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) { -// } -// LL_PWR_EnableRange1BoostMode(); -// LL_RCC_HSE_Enable(); - -// /* Wait till HSE is ready */ -// while (LL_RCC_HSE_IsReady() != 1) { -// } - -// LL_RCC_HSE_EnableCSS(); -// LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_1, 20, -// LL_RCC_PLLR_DIV_2); -// //LL_RCC_PLL_ConfigDomain_48M(LL_RCC_PLLSOURCE_HSE, ); -// LL_RCC_PLL_EnableDomain_SYS(); -// LL_RCC_PLL_Enable(); -// /* Wait till PLL is ready */ -// while (LL_RCC_PLL_IsReady() != 1) { -// } - -// LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); -// /* Wait till System clock is ready */ -// while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { -// } - -// /* Insure 1us transition state at intermediate medium speed clock*/ -// for (__IO uint32_t i = (170 >> 1); i != 0; i--) -// ; - -// /* Set AHB prescaler*/ -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); -// LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); -// LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); -// LL_SetSystemCoreClock(160000000); - -// /* Update the time base */ -// if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { -// Error_Handler(); -// } -// }*/ -void SystemClock_Config(void) -{ - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - // LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(170000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return - * state */ - __disable_irq(); - while (1) {} - /* USER CODE END Error_Handler_Debug */ -} -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line - number, ex: printf("Wrong parameters value: file %s on line %d\r\n", - file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ diff --git a/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/CMakeLists.txt deleted file mode 100644 index e3c0515e4..000000000 --- a/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -# Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) - -# Define the build type -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug") -endif() - -# Enable compile command to ease indexing with e.g. clangd -set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) - -# Enable CMake support for ASM and C languages -enable_language( - C - ASM -) - -# Core project settings -project(${CMAKE_PROJECT_NAME}) - -# what, does in fact not get the filename of somthing but rather the name of the project from the path -get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) - -add_library(${PROJECT_NAME}_USER_CODE INTERFACE) - -target_sources( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Src/adc.c - ../Core/Src/crc.c - ../Core/Src/dma.c - ../Core/Src/gpio.c - ../Core/Src/i2c.c - main.c - ../Core/Src/spi.c - ../Core/Src/stm32g4xx_hal_msp.c - ../Core/Src/stm32g4xx_it.c - ../Core/Src/tim.c - ../Core/Src/usart.c -) - -target_link_libraries( - ${PROJECT_NAME}_USER_CODE - INTERFACE - PERIPHERAL_CAN_LIB - LOGOMATIC_OLD_LIB -) - -target_include_directories( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Inc - . -) diff --git a/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/can_cfg.h b/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/can_cfg.h deleted file mode 100644 index 4d370d3eb..000000000 --- a/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/can_cfg.h +++ /dev/null @@ -1,23 +0,0 @@ - -#ifndef CAN_CFG_H -#define CAN_CFG_H - -#define USECAN1 -#define TX_BUFFER_1_SIZE 10 - -/*#define CAN1_RX_GPIO -#define CAN1_RX_PIN -#define CAN1_TX_GPIO -#define CAN1_TX_PIN -*/ - -#define USECAN2 -#define TX_BUFFER_2_SIZE 10 - -/*#define CAN1_RX_GPIO -#define CAN1_RX_PIN -#define CAN1_TX_GPIO -#define CAN1_TX_PIN -*/ - -#endif diff --git a/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/main.c b/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/main.c deleted file mode 100644 index c9efe8499..000000000 --- a/G474xE_CAN_TESTING/CAN_LOST_RX_TEST/main.c +++ /dev/null @@ -1,274 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "adc.h" -#include "can.h" // Assume this works -#include "can_tests.h" -#include "dma.h" -#include "fdcan.h" -#include "gpio.h" -#include "i2c.h" -#include "spi.h" -#include "tim.h" -#include "usart.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -#include "Logomatic.h" -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* 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 -----------------------------------------------*/ -void SystemClock_Config(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ -/* Enable ITM for SWO output */ -static void ITM_Enable(void) -{ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_0; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - DBGMCU->CR |= DBGMCU_CR_TRACE_IOEN; - - /* Enable TRC (Trace) */ - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; - - /* Configure TPI for SWO output (set prescaler for 2MHz SWO clock) */ - TPI->SPPR = 2U; /* 2 = Manchester/async UART mode */ - TPI->ACPR = 84U; /* Prescaler: (170 MHz / (84+1) / 2) ≈ 1MHz SWO */ - - ITM->TER |= (1UL << 0); - ITM->TCR |= (ITM_TCR_ITMENA_Msk | ITM_TCR_SWOENA_Msk); -} -// static int toggleze = 0; -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU - * Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the - * Systick. */ - HAL_Init(); - /* USER CODE BEGIN Init */ - ITM_Enable(); - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); - // MX_FDCAN2_Init(); - MX_ADC1_Init(); - MX_LPUART1_UART_Init(); - MX_I2C2_Init(); - MX_USART1_UART_Init(); - MX_SPI3_Init(); - MX_TIM2_Init(); - - /* USER CODE BEGIN 2 */ - - LOGOMATIC("Booted!\n"); - - // LOGOMATIC("running can_stress_test:\n"); - can_lost_rx_test(); - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) { - /* USER CODE END WHILE */ - LOGOMATIC("Main Loop\n"); - LL_mDelay(1000); - - // Receive on GPIOs - // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, toggleze ? GPIO_PIN_SET - // : GPIO_PIN_RESET); HAL_Delay(1000); msg.data[0] = toggleze ? - // 0x00 : 0x80; can_send(data_can, &msg); - - // RCC->CFGR |= RCC_CFGR_SW; - /* USER CODE BEGIN 3 */ - } -} - -/** - * @brief System Clock Configuration - * @retval None - */ - -// void SystemClock_Config(void) -// { -// LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); -// while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) { -// } -// LL_PWR_EnableRange1BoostMode(); -// LL_RCC_HSE_Enable(); - -// /* Wait till HSE is ready */ -// while (LL_RCC_HSE_IsReady() != 1) { -// } - -// LL_RCC_HSE_EnableCSS(); -// LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_1, 20, -// LL_RCC_PLLR_DIV_2); -// //LL_RCC_PLL_ConfigDomain_48M(LL_RCC_PLLSOURCE_HSE, ); -// LL_RCC_PLL_EnableDomain_SYS(); -// LL_RCC_PLL_Enable(); -// /* Wait till PLL is ready */ -// while (LL_RCC_PLL_IsReady() != 1) { -// } - -// LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); -// /* Wait till System clock is ready */ -// while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { -// } - -// /* Insure 1us transition state at intermediate medium speed clock*/ -// for (__IO uint32_t i = (170 >> 1); i != 0; i--) -// ; - -// /* Set AHB prescaler*/ -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); -// LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); -// LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); -// LL_SetSystemCoreClock(160000000); - -// /* Update the time base */ -// if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { -// Error_Handler(); -// } -// }*/ -void SystemClock_Config(void) -{ - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - // LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(170000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return - * state */ - __disable_irq(); - while (1) {} - /* USER CODE END Error_Handler_Debug */ -} -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line - number, ex: printf("Wrong parameters value: file %s on line %d\r\n", - file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ diff --git a/G474xE_CAN_TESTING/CAN_RELEASE_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_RELEASE_TEST/CMakeLists.txt deleted file mode 100644 index c1a4f180b..000000000 --- a/G474xE_CAN_TESTING/CAN_RELEASE_TEST/CMakeLists.txt +++ /dev/null @@ -1,65 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -# Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) - -# Define the build type -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug") -endif() - -# Enable compile command to ease indexing with e.g. clangd -set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) - -# Enable CMake support for ASM and C languages -enable_language( - C - ASM -) - -# Core project settings -project(${CMAKE_PROJECT_NAME}) - -# what, does in fact not get the filename of somthing but rather the name of the project from the path -get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) - -add_library(${PROJECT_NAME}_USER_CODE INTERFACE) - -target_sources( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Src/adc.c - ../Core/Src/crc.c - ../Core/Src/dma.c - ../Core/Src/gpio.c - ../Core/Src/i2c.c - main.c - ../Core/Src/spi.c - ../Core/Src/stm32g4xx_hal_msp.c - ../Core/Src/stm32g4xx_it.c - ../Core/Src/tim.c - ../Core/Src/usart.c -) - -set_target_properties( - ${NAME} - PROPERTIES - OUTPUT_NAME - "CAN_${NAME}" -) - -target_link_libraries( - ${PROJECT_NAME}_USER_CODE - INTERFACE - PERIPHERAL_CAN_LIB - LOGOMATIC_OLD_LIB -) - -target_include_directories( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Inc - . -) diff --git a/G474xE_CAN_TESTING/CAN_RELEASE_TEST/can_cfg.h b/G474xE_CAN_TESTING/CAN_RELEASE_TEST/can_cfg.h deleted file mode 100644 index fc11e3e23..000000000 --- a/G474xE_CAN_TESTING/CAN_RELEASE_TEST/can_cfg.h +++ /dev/null @@ -1,11 +0,0 @@ - -#ifndef CAN_CFG_H -#define CAN_CFG_H - -#define USECAN1 -#define TX_BUFFER_1_SIZE 10 - -#define USECAN2 -#define TX_BUFFER_2_SIZE 10 - -#endif diff --git a/G474xE_CAN_TESTING/CAN_RELEASE_TEST/main.c b/G474xE_CAN_TESTING/CAN_RELEASE_TEST/main.c deleted file mode 100644 index a3197bb29..000000000 --- a/G474xE_CAN_TESTING/CAN_RELEASE_TEST/main.c +++ /dev/null @@ -1,274 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "adc.h" -#include "can.h" // Assume this works -#include "can_tests.h" -#include "dma.h" -#include "fdcan.h" -#include "gpio.h" -#include "i2c.h" -#include "spi.h" -#include "tim.h" -#include "usart.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -#include "Logomatic.h" -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* 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 -----------------------------------------------*/ -void SystemClock_Config(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ -/* Enable ITM for SWO output */ -static void ITM_Enable(void) -{ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_0; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - DBGMCU->CR |= DBGMCU_CR_TRACE_IOEN; - - /* Enable TRC (Trace) */ - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; - - /* Configure TPI for SWO output (set prescaler for 2MHz SWO clock) */ - TPI->SPPR = 2U; /* 2 = Manchester/async UART mode */ - TPI->ACPR = 84U; /* Prescaler: (170 MHz / (84+1) / 2) ≈ 1MHz SWO */ - - ITM->TER |= (1UL << 0); - ITM->TCR |= (ITM_TCR_ITMENA_Msk | ITM_TCR_SWOENA_Msk); -} -// static int toggleze = 0; -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU - * Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the - * Systick. */ - HAL_Init(); - /* USER CODE BEGIN Init */ - ITM_Enable(); - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); - // MX_FDCAN2_Init(); - MX_ADC1_Init(); - MX_LPUART1_UART_Init(); - MX_I2C2_Init(); - MX_USART1_UART_Init(); - MX_SPI3_Init(); - MX_TIM2_Init(); - - /* USER CODE BEGIN 2 */ - - LOGOMATIC("Booted!\n"); - - // LOGOMATIC("running can_release_test:\n"); - can_release_test(); - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) { - /* USER CODE END WHILE */ - LOGOMATIC("Main Loop\n"); - LL_mDelay(1000); - - // Receive on GPIOs - // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, toggleze ? GPIO_PIN_SET - // : GPIO_PIN_RESET); HAL_Delay(1000); msg.data[0] = toggleze ? - // 0x00 : 0x80; can_send(data_can, &msg); - - // RCC->CFGR |= RCC_CFGR_SW; - /* USER CODE BEGIN 3 */ - } -} - -/** - * @brief System Clock Configuration - * @retval None - */ - -// void SystemClock_Config(void) -// { -// LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); -// while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) { -// } -// LL_PWR_EnableRange1BoostMode(); -// LL_RCC_HSE_Enable(); - -// /* Wait till HSE is ready */ -// while (LL_RCC_HSE_IsReady() != 1) { -// } - -// LL_RCC_HSE_EnableCSS(); -// LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_1, 20, -// LL_RCC_PLLR_DIV_2); -// //LL_RCC_PLL_ConfigDomain_48M(LL_RCC_PLLSOURCE_HSE, ); -// LL_RCC_PLL_EnableDomain_SYS(); -// LL_RCC_PLL_Enable(); -// /* Wait till PLL is ready */ -// while (LL_RCC_PLL_IsReady() != 1) { -// } - -// LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); -// /* Wait till System clock is ready */ -// while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { -// } - -// /* Insure 1us transition state at intermediate medium speed clock*/ -// for (__IO uint32_t i = (170 >> 1); i != 0; i--) -// ; - -// /* Set AHB prescaler*/ -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); -// LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); -// LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); -// LL_SetSystemCoreClock(160000000); - -// /* Update the time base */ -// if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { -// Error_Handler(); -// } -// }*/ -void SystemClock_Config(void) -{ - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - // LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(170000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return - * state */ - __disable_irq(); - while (1) {} - /* USER CODE END Error_Handler_Debug */ -} -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line - number, ex: printf("Wrong parameters value: file %s on line %d\r\n", - file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ diff --git a/G474xE_CAN_TESTING/CAN_STRESS_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/CAN_STRESS_TEST/CMakeLists.txt deleted file mode 100644 index e3c0515e4..000000000 --- a/G474xE_CAN_TESTING/CAN_STRESS_TEST/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -# Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) - -# Define the build type -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug") -endif() - -# Enable compile command to ease indexing with e.g. clangd -set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) - -# Enable CMake support for ASM and C languages -enable_language( - C - ASM -) - -# Core project settings -project(${CMAKE_PROJECT_NAME}) - -# what, does in fact not get the filename of somthing but rather the name of the project from the path -get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) - -add_library(${PROJECT_NAME}_USER_CODE INTERFACE) - -target_sources( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Src/adc.c - ../Core/Src/crc.c - ../Core/Src/dma.c - ../Core/Src/gpio.c - ../Core/Src/i2c.c - main.c - ../Core/Src/spi.c - ../Core/Src/stm32g4xx_hal_msp.c - ../Core/Src/stm32g4xx_it.c - ../Core/Src/tim.c - ../Core/Src/usart.c -) - -target_link_libraries( - ${PROJECT_NAME}_USER_CODE - INTERFACE - PERIPHERAL_CAN_LIB - LOGOMATIC_OLD_LIB -) - -target_include_directories( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Inc - . -) diff --git a/G474xE_CAN_TESTING/CAN_STRESS_TEST/can_cfg.h b/G474xE_CAN_TESTING/CAN_STRESS_TEST/can_cfg.h deleted file mode 100644 index fc11e3e23..000000000 --- a/G474xE_CAN_TESTING/CAN_STRESS_TEST/can_cfg.h +++ /dev/null @@ -1,11 +0,0 @@ - -#ifndef CAN_CFG_H -#define CAN_CFG_H - -#define USECAN1 -#define TX_BUFFER_1_SIZE 10 - -#define USECAN2 -#define TX_BUFFER_2_SIZE 10 - -#endif diff --git a/G474xE_CAN_TESTING/CAN_STRESS_TEST/main.c b/G474xE_CAN_TESTING/CAN_STRESS_TEST/main.c deleted file mode 100644 index 591f49aa6..000000000 --- a/G474xE_CAN_TESTING/CAN_STRESS_TEST/main.c +++ /dev/null @@ -1,275 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "adc.h" -#include "can.h" // Assume this works -#include "can_tests.h" -#include "dma.h" -#include "fdcan.h" -#include "gpio.h" -#include "i2c.h" -#include "spi.h" -#include "tim.h" -#include "usart.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -#include "Logomatic.h" -// #include "profile.h" -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* 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 -----------------------------------------------*/ -void SystemClock_Config(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ -/* Enable ITM for SWO output */ -static void ITM_Enable(void) -{ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_0; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - DBGMCU->CR |= DBGMCU_CR_TRACE_IOEN; - - /* Enable TRC (Trace) */ - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; - - /* Configure TPI for SWO output (set prescaler for 2MHz SWO clock) */ - TPI->SPPR = 2U; /* 2 = Manchester/async UART mode */ - TPI->ACPR = 84U; /* Prescaler: (170 MHz / (84+1) / 2) ≈ 1MHz SWO */ - - ITM->TER |= (1UL << 0); - ITM->TCR |= (ITM_TCR_ITMENA_Msk | ITM_TCR_SWOENA_Msk); -} -// static int toggleze = 0; -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU - * Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the - * Systick. */ - HAL_Init(); - /* USER CODE BEGIN Init */ - ITM_Enable(); - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); - // MX_FDCAN2_Init(); - MX_ADC1_Init(); - MX_LPUART1_UART_Init(); - MX_I2C2_Init(); - MX_USART1_UART_Init(); - MX_SPI3_Init(); - MX_TIM2_Init(); - - /* USER CODE BEGIN 2 */ - - LOGOMATIC("Booted!\n"); - - // LOGOMATIC("running can_stress_test:\n"); - can_stress_test(); - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) { - /* USER CODE END WHILE */ - LOGOMATIC("Main Loop\n"); - LL_mDelay(10000); - - // Receive on GPIOs - // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, toggleze ? GPIO_PIN_SET - // : GPIO_PIN_RESET); HAL_Delay(1000); msg.data[0] = toggleze ? - // 0x00 : 0x80; can_send(data_can, &msg); - - // RCC->CFGR |= RCC_CFGR_SW; - /* USER CODE BEGIN 3 */ - } -} - -/** - * @brief System Clock Configuration - * @retval None - */ - -// void SystemClock_Config(void) -// { -// LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); -// while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) { -// } -// LL_PWR_EnableRange1BoostMode(); -// LL_RCC_HSE_Enable(); - -// /* Wait till HSE is ready */ -// while (LL_RCC_HSE_IsReady() != 1) { -// } - -// LL_RCC_HSE_EnableCSS(); -// LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_1, 20, -// LL_RCC_PLLR_DIV_2); -// //LL_RCC_PLL_ConfigDomain_48M(LL_RCC_PLLSOURCE_HSE, ); -// LL_RCC_PLL_EnableDomain_SYS(); -// LL_RCC_PLL_Enable(); -// /* Wait till PLL is ready */ -// while (LL_RCC_PLL_IsReady() != 1) { -// } - -// LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); -// /* Wait till System clock is ready */ -// while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { -// } - -// /* Insure 1us transition state at intermediate medium speed clock*/ -// for (__IO uint32_t i = (170 >> 1); i != 0; i--) -// ; - -// /* Set AHB prescaler*/ -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); -// LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); -// LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); -// LL_SetSystemCoreClock(160000000); - -// /* Update the time base */ -// if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { -// Error_Handler(); -// } -// }*/ -void SystemClock_Config(void) -{ - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - // LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(170000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return - * state */ - __disable_irq(); - while (1) {} - /* USER CODE END Error_Handler_Debug */ -} -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line - number, ex: printf("Wrong parameters value: file %s on line %d\r\n", - file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ diff --git a/G474xE_CAN_TESTING/Core/Inc/adc.h b/G474xE_CAN_TESTING/Core/Inc/adc.h deleted file mode 100644 index 41154538b..000000000 --- a/G474xE_CAN_TESTING/Core/Inc/adc.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file adc.h - * @brief This file contains all the function prototypes for - * the adc.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __ADC_H__ -#define __ADC_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_ADC1_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __ADC_H__ */ diff --git a/G474xE_CAN_TESTING/Core/Inc/crc.h b/G474xE_CAN_TESTING/Core/Inc/crc.h deleted file mode 100644 index 133957e92..000000000 --- a/G474xE_CAN_TESTING/Core/Inc/crc.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file crc.h - * @brief This file contains all the function prototypes for - * the crc.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __CRC_H__ -#define __CRC_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern CRC_HandleTypeDef hcrc; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_CRC_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CRC_H__ */ diff --git a/G474xE_CAN_TESTING/Core/Inc/dma.h b/G474xE_CAN_TESTING/Core/Inc/dma.h deleted file mode 100644 index ae819cab4..000000000 --- a/G474xE_CAN_TESTING/Core/Inc/dma.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file dma.h - * @brief This file contains all the function prototypes for - * the dma.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __DMA_H__ -#define __DMA_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* DMA memory to memory transfer handles -------------------------------------*/ - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_DMA_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __DMA_H__ */ diff --git a/G474xE_CAN_TESTING/Core/Inc/fdcan.h b/G474xE_CAN_TESTING/Core/Inc/fdcan.h deleted file mode 100644 index 56c4a8adb..000000000 --- a/G474xE_CAN_TESTING/Core/Inc/fdcan.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file fdcan.h - * @brief This file contains all the function prototypes for - * the fdcan.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __FDCAN_H__ -#define __FDCAN_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern FDCAN_HandleTypeDef hfdcan2; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_FDCAN2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __FDCAN_H__ */ diff --git a/G474xE_CAN_TESTING/Core/Inc/gpio.h b/G474xE_CAN_TESTING/Core/Inc/gpio.h deleted file mode 100644 index 843d4e9e7..000000000 --- a/G474xE_CAN_TESTING/Core/Inc/gpio.h +++ /dev/null @@ -1,48 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file gpio.h - * @brief This file contains all the function prototypes for - * the gpio.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __GPIO_H__ -#define __GPIO_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_GPIO_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif -#endif /*__ GPIO_H__ */ diff --git a/G474xE_CAN_TESTING/Core/Inc/i2c.h b/G474xE_CAN_TESTING/Core/Inc/i2c.h deleted file mode 100644 index 0a0a50803..000000000 --- a/G474xE_CAN_TESTING/Core/Inc/i2c.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file i2c.h - * @brief This file contains all the function prototypes for - * the i2c.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __I2C_H__ -#define __I2C_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_I2C2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __I2C_H__ */ diff --git a/G474xE_CAN_TESTING/Core/Inc/main.h b/G474xE_CAN_TESTING/Core/Inc/main.h deleted file mode 100644 index 23d7ffce4..000000000 --- a/G474xE_CAN_TESTING/Core/Inc/main.h +++ /dev/null @@ -1,115 +0,0 @@ -/* 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) 2024 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 "stm32g4xx_hal.h" -#include "stm32g4xx_ll_adc.h" -#include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_dma.h" -#include "stm32g4xx_ll_exti.h" -#include "stm32g4xx_ll_gpio.h" -#include "stm32g4xx_ll_i2c.h" -#include "stm32g4xx_ll_lpuart.h" -#include "stm32g4xx_ll_pwr.h" -#include "stm32g4xx_ll_rcc.h" -#include "stm32g4xx_ll_spi.h" -#include "stm32g4xx_ll_system.h" -#include "stm32g4xx_ll_tim.h" -#include "stm32g4xx_ll_usart.h" -#include "stm32g4xx_ll_utils.h" - -/* 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 Error_Handler(void); - -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -/* Private defines -----------------------------------------------------------*/ -#define BSPD_SIGNAL_Pin LL_GPIO_PIN_1 -#define BSPD_SIGNAL_GPIO_Port GPIOC -#define APPS1_SIGNAL_Pin LL_GPIO_PIN_2 -#define APPS1_SIGNAL_GPIO_Port GPIOC -#define APPS2_SIGNAL_Pin LL_GPIO_PIN_3 -#define APPS2_SIGNAL_GPIO_Port GPIOC -#define BLINKY_Pin LL_GPIO_PIN_5 -#define BLINKY_GPIO_Port GPIOA -#define IMD_SENSE_Pin LL_GPIO_PIN_6 -#define IMD_SENSE_GPIO_Port GPIOA -#define AMS_SENSE_Pin LL_GPIO_PIN_7 -#define AMS_SENSE_GPIO_Port GPIOA -#define BRAKE_F_SIGNAL_Pin LL_GPIO_PIN_0 -#define BRAKE_F_SIGNAL_GPIO_Port GPIOB -#define BRAKE_R_SIGNAL_Pin LL_GPIO_PIN_1 -#define BRAKE_R_SIGNAL_GPIO_Port GPIOB -#define LED_TEST_Pin LL_GPIO_PIN_11 -#define LED_TEST_GPIO_Port GPIOB -#define AUX_SIGNAL_Pin LL_GPIO_PIN_14 -#define AUX_SIGNAL_GPIO_Port GPIOB -#define STEERING_ANGLE_Pin LL_GPIO_PIN_15 -#define STEERING_ANGLE_GPIO_Port GPIOB -#define BRAKE_LIGHT_Pin LL_GPIO_PIN_4 -#define BRAKE_LIGHT_GPIO_Port GPIOB -#define TSSI_G_CONTROL_Pin LL_GPIO_PIN_5 -#define TSSI_G_CONTROL_GPIO_Port GPIOB -#define AUX_CONTROL_Pin LL_GPIO_PIN_8 -#define AUX_CONTROL_GPIO_Port GPIOB -#define SOFTWARE_OK_CONTROL_Pin LL_GPIO_PIN_9 -#define SOFTWARE_OK_CONTROL_GPIO_Port GPIOB - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -#ifdef __cplusplus -} -#endif - -#endif /* __MAIN_H */ diff --git a/G474xE_CAN_TESTING/Core/Inc/spi.h b/G474xE_CAN_TESTING/Core/Inc/spi.h deleted file mode 100644 index 74bed003b..000000000 --- a/G474xE_CAN_TESTING/Core/Inc/spi.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file spi.h - * @brief This file contains all the function prototypes for - * the spi.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __SPI_H__ -#define __SPI_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_SPI3_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __SPI_H__ */ diff --git a/G474xE_CAN_TESTING/Core/Inc/stm32g4xx_hal_conf.h b/G474xE_CAN_TESTING/Core/Inc/stm32g4xx_hal_conf.h deleted file mode 100644 index 3e1fcb018..000000000 --- a/G474xE_CAN_TESTING/Core/Inc/stm32g4xx_hal_conf.h +++ /dev/null @@ -1,390 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_conf.h - * @author MCD Application Team - * @brief HAL configuration file - ****************************************************************************** - * @attention - * - * Copyright (c) 2019 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 STM32G4xx_HAL_CONF_H -#define STM32G4xx_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_ADC_MODULE_ENABLED */ -/*#define HAL_COMP_MODULE_ENABLED */ -/*#define HAL_CORDIC_MODULE_ENABLED */ -#define HAL_CRC_MODULE_ENABLED -/*#define HAL_CRYP_MODULE_ENABLED */ -/*#define HAL_DAC_MODULE_ENABLED */ -#define HAL_FDCAN_MODULE_ENABLED -/*#define HAL_FMAC_MODULE_ENABLED */ -/*#define HAL_HRTIM_MODULE_ENABLED */ -/*#define HAL_IRDA_MODULE_ENABLED */ -/*#define HAL_IWDG_MODULE_ENABLED */ -/*#define HAL_I2C_MODULE_ENABLED */ -/*#define HAL_I2S_MODULE_ENABLED */ -/*#define HAL_LPTIM_MODULE_ENABLED */ -/*#define HAL_NAND_MODULE_ENABLED */ -/*#define HAL_NOR_MODULE_ENABLED */ -/*#define HAL_OPAMP_MODULE_ENABLED */ -/*#define HAL_PCD_MODULE_ENABLED */ -/*#define HAL_QSPI_MODULE_ENABLED */ -/*#define HAL_RNG_MODULE_ENABLED */ -/*#define HAL_RTC_MODULE_ENABLED */ -/*#define HAL_SAI_MODULE_ENABLED */ -/*#define HAL_SMARTCARD_MODULE_ENABLED */ -/*#define HAL_SMBUS_MODULE_ENABLED */ -/*#define HAL_SPI_MODULE_ENABLED */ -/*#define HAL_SRAM_MODULE_ENABLED */ -/*#define HAL_TIM_MODULE_ENABLED */ -/*#define HAL_UART_MODULE_ENABLED */ -/*#define HAL_USART_MODULE_ENABLED */ -/*#define HAL_WWDG_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 - -/* ########################## Register Callbacks selection - * ############################## */ -/** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U - -/* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(HSE_STARTUP_TIMEOUT) -#define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ - -/** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high - * precision clock to the USB peripheral by means of a special Clock Recovery - * System (CRS) circuitry. When the CRS is not used, the HSI48 RC oscillator - * runs on it default frequency which is subject to manufacturing process - * variations. - */ -#if !defined(HSI48_VALUE) -#define HSI48_VALUE \ - (48000000UL) /*!< Value of the Internal High Speed oscillator for USB \ - FS/RNG in Hz. The real value my vary depending on \ - manufacturing process variations.*/ -#endif /* HSI48_VALUE */ - -/** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined(LSI_VALUE) -/*!< Value of the Internal Low Speed oscillator in Hz -The real value may vary depending on the variations in voltage and -temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ -/** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system - * frequency - */ -#if !defined(LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ - -#if !defined(LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ - -/** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S - * and SAI clock source frequency, this source is inserted directly through - * I2S_CKIN pad. - */ -#if !defined(EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U - -/* ########################## Assert Selection ############################## */ -/** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -/* #define USE_FULL_ASSERT 1U */ - -/* ################## 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 "stm32g4xx_hal_rcc.h" -#endif /* HAL_RCC_MODULE_ENABLED */ - -#ifdef HAL_GPIO_MODULE_ENABLED -#include "stm32g4xx_hal_gpio.h" -#endif /* HAL_GPIO_MODULE_ENABLED */ - -#ifdef HAL_DMA_MODULE_ENABLED -#include "stm32g4xx_hal_dma.h" -#endif /* HAL_DMA_MODULE_ENABLED */ - -#ifdef HAL_CORTEX_MODULE_ENABLED -#include "stm32g4xx_hal_cortex.h" -#endif /* HAL_CORTEX_MODULE_ENABLED */ - -#ifdef HAL_ADC_MODULE_ENABLED -#include "stm32g4xx_hal_adc.h" -#endif /* HAL_ADC_MODULE_ENABLED */ - -#ifdef HAL_COMP_MODULE_ENABLED -#include "stm32g4xx_hal_comp.h" -#endif /* HAL_COMP_MODULE_ENABLED */ - -#ifdef HAL_CORDIC_MODULE_ENABLED -#include "stm32g4xx_hal_cordic.h" -#endif /* HAL_CORDIC_MODULE_ENABLED */ - -#ifdef HAL_CRC_MODULE_ENABLED -#include "stm32g4xx_hal_crc.h" -#endif /* HAL_CRC_MODULE_ENABLED */ - -#ifdef HAL_CRYP_MODULE_ENABLED -#include "stm32g4xx_hal_cryp.h" -#endif /* HAL_CRYP_MODULE_ENABLED */ - -#ifdef HAL_DAC_MODULE_ENABLED -#include "stm32g4xx_hal_dac.h" -#endif /* HAL_DAC_MODULE_ENABLED */ - -#ifdef HAL_EXTI_MODULE_ENABLED -#include "stm32g4xx_hal_exti.h" -#endif /* HAL_EXTI_MODULE_ENABLED */ - -#ifdef HAL_FDCAN_MODULE_ENABLED -#include "stm32g4xx_hal_fdcan.h" -#endif /* HAL_FDCAN_MODULE_ENABLED */ - -#ifdef HAL_FLASH_MODULE_ENABLED -#include "stm32g4xx_hal_flash.h" -#endif /* HAL_FLASH_MODULE_ENABLED */ - -#ifdef HAL_FMAC_MODULE_ENABLED -#include "stm32g4xx_hal_fmac.h" -#endif /* HAL_FMAC_MODULE_ENABLED */ - -#ifdef HAL_HRTIM_MODULE_ENABLED -#include "stm32g4xx_hal_hrtim.h" -#endif /* HAL_HRTIM_MODULE_ENABLED */ - -#ifdef HAL_IRDA_MODULE_ENABLED -#include "stm32g4xx_hal_irda.h" -#endif /* HAL_IRDA_MODULE_ENABLED */ - -#ifdef HAL_IWDG_MODULE_ENABLED -#include "stm32g4xx_hal_iwdg.h" -#endif /* HAL_IWDG_MODULE_ENABLED */ - -#ifdef HAL_I2C_MODULE_ENABLED -#include "stm32g4xx_hal_i2c.h" -#endif /* HAL_I2C_MODULE_ENABLED */ - -#ifdef HAL_I2S_MODULE_ENABLED -#include "stm32g4xx_hal_i2s.h" -#endif /* HAL_I2S_MODULE_ENABLED */ - -#ifdef HAL_LPTIM_MODULE_ENABLED -#include "stm32g4xx_hal_lptim.h" -#endif /* HAL_LPTIM_MODULE_ENABLED */ - -#ifdef HAL_NAND_MODULE_ENABLED -#include "stm32g4xx_hal_nand.h" -#endif /* HAL_NAND_MODULE_ENABLED */ - -#ifdef HAL_NOR_MODULE_ENABLED -#include "stm32g4xx_hal_nor.h" -#endif /* HAL_NOR_MODULE_ENABLED */ - -#ifdef HAL_OPAMP_MODULE_ENABLED -#include "stm32g4xx_hal_opamp.h" -#endif /* HAL_OPAMP_MODULE_ENABLED */ - -#ifdef HAL_PCD_MODULE_ENABLED -#include "stm32g4xx_hal_pcd.h" -#endif /* HAL_PCD_MODULE_ENABLED */ - -#ifdef HAL_PWR_MODULE_ENABLED -#include "stm32g4xx_hal_pwr.h" -#endif /* HAL_PWR_MODULE_ENABLED */ - -#ifdef HAL_QSPI_MODULE_ENABLED -#include "stm32g4xx_hal_qspi.h" -#endif /* HAL_QSPI_MODULE_ENABLED */ - -#ifdef HAL_RNG_MODULE_ENABLED -#include "stm32g4xx_hal_rng.h" -#endif /* HAL_RNG_MODULE_ENABLED */ - -#ifdef HAL_RTC_MODULE_ENABLED -#include "stm32g4xx_hal_rtc.h" -#endif /* HAL_RTC_MODULE_ENABLED */ - -#ifdef HAL_SAI_MODULE_ENABLED -#include "stm32g4xx_hal_sai.h" -#endif /* HAL_SAI_MODULE_ENABLED */ - -#ifdef HAL_SMARTCARD_MODULE_ENABLED -#include "stm32g4xx_hal_smartcard.h" -#endif /* HAL_SMARTCARD_MODULE_ENABLED */ - -#ifdef HAL_SMBUS_MODULE_ENABLED -#include "stm32g4xx_hal_smbus.h" -#endif /* HAL_SMBUS_MODULE_ENABLED */ - -#ifdef HAL_SPI_MODULE_ENABLED -#include "stm32g4xx_hal_spi.h" -#endif /* HAL_SPI_MODULE_ENABLED */ - -#ifdef HAL_SRAM_MODULE_ENABLED -#include "stm32g4xx_hal_sram.h" -#endif /* HAL_SRAM_MODULE_ENABLED */ - -#ifdef HAL_TIM_MODULE_ENABLED -#include "stm32g4xx_hal_tim.h" -#endif /* HAL_TIM_MODULE_ENABLED */ - -#ifdef HAL_UART_MODULE_ENABLED -#include "stm32g4xx_hal_uart.h" -#endif /* HAL_UART_MODULE_ENABLED */ - -#ifdef HAL_USART_MODULE_ENABLED -#include "stm32g4xx_hal_usart.h" -#endif /* HAL_USART_MODULE_ENABLED */ - -#ifdef HAL_WWDG_MODULE_ENABLED -#include "stm32g4xx_hal_wwdg.h" -#endif /* HAL_WWDG_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 /* STM32G4xx_HAL_CONF_H */ diff --git a/G474xE_CAN_TESTING/Core/Inc/stm32g4xx_it.h b/G474xE_CAN_TESTING/Core/Inc/stm32g4xx_it.h deleted file mode 100644 index b6c3b2f72..000000000 --- a/G474xE_CAN_TESTING/Core/Inc/stm32g4xx_it.h +++ /dev/null @@ -1,67 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_it.h - * @brief This file contains the headers of the interrupt handlers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __STM32G4xx_IT_H -#define __STM32G4xx_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); -void FDCAN2_IT0_IRQHandler(void); -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32G4xx_IT_H */ diff --git a/G474xE_CAN_TESTING/Core/Inc/tim.h b/G474xE_CAN_TESTING/Core/Inc/tim.h deleted file mode 100644 index c19e6cc71..000000000 --- a/G474xE_CAN_TESTING/Core/Inc/tim.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file tim.h - * @brief This file contains all the function prototypes for - * the tim.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __TIM_H__ -#define __TIM_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_TIM2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __TIM_H__ */ diff --git a/G474xE_CAN_TESTING/Core/Inc/usart.h b/G474xE_CAN_TESTING/Core/Inc/usart.h deleted file mode 100644 index daefd73e6..000000000 --- a/G474xE_CAN_TESTING/Core/Inc/usart.h +++ /dev/null @@ -1,50 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file usart.h - * @brief This file contains all the function prototypes for - * the usart.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __USART_H__ -#define __USART_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_LPUART1_UART_Init(void); -void MX_USART1_UART_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USART_H__ */ diff --git a/G474xE_CAN_TESTING/Core/Src/adc.c b/G474xE_CAN_TESTING/Core/Src/adc.c deleted file mode 100644 index f3dbff8ed..000000000 --- a/G474xE_CAN_TESTING/Core/Src/adc.c +++ /dev/null @@ -1,186 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file adc.c - * @brief This file provides code for the configuration - * of the ADC instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "adc.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* ADC1 init function */ -void MX_ADC1_Init(void) -{ - - /* USER CODE BEGIN ADC1_Init 0 */ - - /* USER CODE END ADC1_Init 0 */ - - LL_ADC_InitTypeDef ADC_InitStruct = {0}; - LL_ADC_REG_InitTypeDef ADC_REG_InitStruct = {0}; - LL_ADC_CommonInitTypeDef ADC_CommonInitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetADCClockSource(LL_RCC_ADC12_CLKSOURCE_SYSCLK); - - /* Peripheral clock enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_ADC12); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - /**ADC1 GPIO Configuration - PC1 ------> ADC1_IN7 - PC2 ------> ADC1_IN8 - PC3 ------> ADC1_IN9 - PB0 ------> ADC1_IN15 - PB1 ------> ADC1_IN12 - PB14 ------> ADC1_IN5 - */ - GPIO_InitStruct.Pin = BSPD_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BSPD_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = APPS1_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(APPS1_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = APPS2_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(APPS2_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = BRAKE_F_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_F_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = BRAKE_R_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_R_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = AUX_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AUX_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - /* ADC1 DMA Init */ - - /* ADC1 Init */ - LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_1, LL_DMAMUX_REQ_ADC1); - - LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_1, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); - - LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PRIORITY_LOW); - - LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_CIRCULAR); - - LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PERIPH_NOINCREMENT); - - LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT); - - LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_HALFWORD); - - LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_HALFWORD); - - /* USER CODE BEGIN ADC1_Init 1 */ - - /* USER CODE END ADC1_Init 1 */ - - /** Common config - */ - ADC_InitStruct.Resolution = LL_ADC_RESOLUTION_12B; - ADC_InitStruct.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT; - ADC_InitStruct.LowPowerMode = LL_ADC_LP_MODE_NONE; - LL_ADC_Init(ADC1, &ADC_InitStruct); - ADC_REG_InitStruct.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE; - ADC_REG_InitStruct.SequencerLength = LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS; - ADC_REG_InitStruct.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE; - ADC_REG_InitStruct.ContinuousMode = LL_ADC_REG_CONV_CONTINUOUS; - ADC_REG_InitStruct.DMATransfer = LL_ADC_REG_DMA_TRANSFER_UNLIMITED; - ADC_REG_InitStruct.Overrun = LL_ADC_REG_OVR_DATA_PRESERVED; - LL_ADC_REG_Init(ADC1, &ADC_REG_InitStruct); - LL_ADC_SetGainCompensation(ADC1, 0); - LL_ADC_SetOverSamplingScope(ADC1, LL_ADC_OVS_DISABLE); - ADC_CommonInitStruct.CommonClock = LL_ADC_CLOCK_ASYNC_DIV256; - ADC_CommonInitStruct.Multimode = LL_ADC_MULTI_INDEPENDENT; - LL_ADC_CommonInit(__LL_ADC_COMMON_INSTANCE(ADC1), &ADC_CommonInitStruct); - - /* Disable ADC deep power down (enabled by default after reset state) */ - LL_ADC_DisableDeepPowerDown(ADC1); - /* Enable ADC internal voltage regulator */ - LL_ADC_EnableInternalRegulator(ADC1); - /* Delay for ADC internal voltage regulator stabilization. */ - /* Compute number of CPU cycles to wait for, from delay in us. */ - /* Note: Variable divided by 2 to compensate partially */ - /* CPU processing cycles (depends on compilation optimization). */ - /* Note: If system core clock frequency is below 200kHz, wait time */ - /* is only a few CPU processing cycles. */ - uint32_t wait_loop_index; - wait_loop_index = ((LL_ADC_DELAY_INTERNAL_REGUL_STAB_US * (SystemCoreClock / (100000 * 2))) / 10); - while (wait_loop_index != 0) { - wait_loop_index--; - } - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_5); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_5, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_5, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_2, LL_ADC_CHANNEL_7); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_7, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_7, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_3, LL_ADC_CHANNEL_8); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_8, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_8, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_4, LL_ADC_CHANNEL_9); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_9, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_9, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_5, LL_ADC_CHANNEL_12); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_12, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_12, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_6, LL_ADC_CHANNEL_15); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_15, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_15, LL_ADC_SINGLE_ENDED); - /* USER CODE BEGIN ADC1_Init 2 */ - - /* USER CODE END ADC1_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G474xE_CAN_TESTING/Core/Src/crc.c b/G474xE_CAN_TESTING/Core/Src/crc.c deleted file mode 100644 index 213510a5d..000000000 --- a/G474xE_CAN_TESTING/Core/Src/crc.c +++ /dev/null @@ -1,86 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file crc.c - * @brief This file provides code for the configuration - * of the CRC instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "crc.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -CRC_HandleTypeDef hcrc; - -/* CRC init function */ -void MX_CRC_Init(void) -{ - - /* USER CODE BEGIN CRC_Init 0 */ - - /* USER CODE END CRC_Init 0 */ - - /* USER CODE BEGIN CRC_Init 1 */ - - /* USER CODE END CRC_Init 1 */ - hcrc.Instance = CRC; - hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE; - hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE; - hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE; - hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE; - hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES; - if (HAL_CRC_Init(&hcrc) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN CRC_Init 2 */ - - /* USER CODE END CRC_Init 2 */ -} - -void HAL_CRC_MspInit(CRC_HandleTypeDef *crcHandle) -{ - - if (crcHandle->Instance == CRC) { - /* USER CODE BEGIN CRC_MspInit 0 */ - - /* USER CODE END CRC_MspInit 0 */ - /* CRC clock enable */ - __HAL_RCC_CRC_CLK_ENABLE(); - /* USER CODE BEGIN CRC_MspInit 1 */ - - /* USER CODE END CRC_MspInit 1 */ - } -} - -void HAL_CRC_MspDeInit(CRC_HandleTypeDef *crcHandle) -{ - - if (crcHandle->Instance == CRC) { - /* USER CODE BEGIN CRC_MspDeInit 0 */ - - /* USER CODE END CRC_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_CRC_CLK_DISABLE(); - /* USER CODE BEGIN CRC_MspDeInit 1 */ - - /* USER CODE END CRC_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G474xE_CAN_TESTING/Core/Src/dma.c b/G474xE_CAN_TESTING/Core/Src/dma.c deleted file mode 100644 index 491e3889d..000000000 --- a/G474xE_CAN_TESTING/Core/Src/dma.c +++ /dev/null @@ -1,50 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file dma.c - * @brief This file provides code for the configuration - * of all the requested memory to memory DMA transfers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "dma.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure DMA */ -/*----------------------------------------------------------------------------*/ - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** - * Enable DMA controller clock - */ -void MX_DMA_Init(void) -{ - - /* Init with LL driver */ - /* DMA controller clock enable */ - LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMAMUX1); - LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1); -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ diff --git a/G474xE_CAN_TESTING/Core/Src/fdcan.c b/G474xE_CAN_TESTING/Core/Src/fdcan.c deleted file mode 100644 index ebc13ea73..000000000 --- a/G474xE_CAN_TESTING/Core/Src/fdcan.c +++ /dev/null @@ -1,135 +0,0 @@ -// #include "unused.h" -// /* USER CODE BEGIN Header */ -// /** -// ****************************************************************************** -// * @file fdcan.c -// * @brief This file provides code for the configuration -// * of the FDCAN instances. -// ****************************************************************************** -// * @attention -// * -// * Copyright (c) 2024 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 "fdcan.h" - -// /* USER CODE BEGIN 0 */ - -// /* USER CODE END 0 */ - -// FDCAN_HandleTypeDef hfdcan2; - -// /* FDCAN2 init function */ -// void MX_FDCAN2_Init(void) -// { - -// /* USER CODE BEGIN FDCAN2_Init 0 */ - -// /* USER CODE END FDCAN2_Init 0 */ - -// /* USER CODE BEGIN FDCAN2_Init 1 */ - -// /* USER CODE END FDCAN2_Init 1 */ -// hfdcan2.Instance = FDCAN2; -// hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; -// hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; -// hfdcan2.Init.Mode = FDCAN_MODE_NORMAL; -// hfdcan2.Init.AutoRetransmission = ENABLE; -// hfdcan2.Init.TransmitPause = DISABLE; -// hfdcan2.Init.ProtocolException = ENABLE; -// hfdcan2.Init.NominalPrescaler = 1; -// hfdcan2.Init.NominalSyncJumpWidth = 16; -// hfdcan2.Init.NominalTimeSeg1 = 119; -// hfdcan2.Init.NominalTimeSeg2 = 40; -// hfdcan2.Init.DataPrescaler = 8; -// hfdcan2.Init.DataSyncJumpWidth = 16; -// hfdcan2.Init.DataTimeSeg1 = 14; -// hfdcan2.Init.DataTimeSeg2 = 5; -// hfdcan2.Init.StdFiltersNbr = 0; -// hfdcan2.Init.ExtFiltersNbr = 2; -// hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; -// if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { -// Error_Handler(); -// } -// /* USER CODE BEGIN FDCAN2_Init 2 */ - -// /* USER CODE END FDCAN2_Init 2 */ -// } - -// void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) -// { - -// GPIO_InitTypeDef GPIO_InitStruct = {0}; -// if (fdcanHandle->Instance == FDCAN2) { -// /* USER CODE BEGIN FDCAN2_MspInit 0 */ - -// /* USER CODE END FDCAN2_MspInit 0 */ -// LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - -// /* FDCAN2 clock enable */ -// __HAL_RCC_FDCAN_CLK_ENABLE(); - -// __HAL_RCC_GPIOB_CLK_ENABLE(); -// /**FDCAN2 GPIO Configuration -// PB12 ------> FDCAN2_RX -// PB13 ------> FDCAN2_TX -// */ -// GPIO_InitStruct.Pin = GPIO_PIN_12; -// GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; -// GPIO_InitStruct.Pull = GPIO_PULLUP; -// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; -// GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; -// HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - -// GPIO_InitStruct.Pin = 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_FDCAN2; -// HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - -// /* FDCAN2 interrupt Init */ -// HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); -// HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); -// /* USER CODE BEGIN FDCAN2_MspInit 1 */ - -// /* USER CODE END FDCAN2_MspInit 1 */ -// } -// } - -// /*void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) -// { - -// if (fdcanHandle->Instance == FDCAN2) { -// /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - -// /* USER CODE END FDCAN2_MspDeInit 0 */ -// /* Peripheral clock disable */ -// __HAL_RCC_FDCAN_CLK_DISABLE(); - -// /**FDCAN2 GPIO Configuration -// PB12 ------> FDCAN2_RX -// PB13 ------> FDCAN2_TX -// */ -// HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); - -// /* FDCAN2 interrupt Deinit */ -// HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); -// /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - -// /* USER CODE END FDCAN2_MspDeInit 1 */ -// } -// } - -// /* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ -// UNUSED(5); diff --git a/G474xE_CAN_TESTING/Core/Src/gpio.c b/G474xE_CAN_TESTING/Core/Src/gpio.c deleted file mode 100644 index d36e6eca6..000000000 --- a/G474xE_CAN_TESTING/Core/Src/gpio.c +++ /dev/null @@ -1,260 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file gpio.c - * @brief This file provides code for the configuration - * of all used GPIO pins. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "gpio.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure GPIO */ -/*----------------------------------------------------------------------------*/ -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is - enabled through - * the Code Generation settings) - PA6 ------> ADC2_IN3 - PA7 ------> ADC2_IN4 - PB15 ------> ADC2_IN15 - PB7 ------> UART4_CTS -*/ -void MX_GPIO_Init(void) -{ - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(BLINKY_GPIO_Port, BLINKY_Pin); - - /**/ - LL_GPIO_ResetOutputPin(LED_TEST_GPIO_Port, LED_TEST_Pin); - - /**/ - LL_GPIO_ResetOutputPin(BRAKE_LIGHT_GPIO_Port, BRAKE_LIGHT_Pin); - - /**/ - LL_GPIO_ResetOutputPin(TSSI_G_CONTROL_GPIO_Port, TSSI_G_CONTROL_Pin); - - /**/ - LL_GPIO_ResetOutputPin(AUX_CONTROL_GPIO_Port, AUX_CONTROL_Pin); - - /**/ - LL_GPIO_ResetOutputPin(SOFTWARE_OK_CONTROL_GPIO_Port, SOFTWARE_OK_CONTROL_Pin); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_13; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = BLINKY_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BLINKY_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = IMD_SENSE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(IMD_SENSE_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = AMS_SENSE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AMS_SENSE_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LED_TEST_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(LED_TEST_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = STEERING_ANGLE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(STEERING_ANGLE_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = BRAKE_LIGHT_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_LIGHT_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = TSSI_G_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(TSSI_G_CONTROL_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_14; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = AUX_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AUX_CONTROL_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = SOFTWARE_OK_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(SOFTWARE_OK_CONTROL_GPIO_Port, &GPIO_InitStruct); -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ diff --git a/G474xE_CAN_TESTING/Core/Src/i2c.c b/G474xE_CAN_TESTING/Core/Src/i2c.c deleted file mode 100644 index bfb4e0153..000000000 --- a/G474xE_CAN_TESTING/Core/Src/i2c.c +++ /dev/null @@ -1,92 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file i2c.c - * @brief This file provides code for the configuration - * of the I2C instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "i2c.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* I2C2 init function */ -void MX_I2C2_Init(void) -{ - - /* USER CODE BEGIN I2C2_Init 0 */ - - /* USER CODE END I2C2_Init 0 */ - - LL_I2C_InitTypeDef I2C_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetI2CClockSource(LL_RCC_I2C2_CLKSOURCE_PCLK1); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - /**I2C2 GPIO Configuration - PC4 ------> I2C2_SCL - PA8 ------> I2C2_SDA - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_4; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_4; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C2); - - /* USER CODE BEGIN I2C2_Init 1 */ - - /* USER CODE END I2C2_Init 1 */ - - /** I2C Initialization - */ - I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; - I2C_InitStruct.Timing = 0x30D29DE4; - I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE; - I2C_InitStruct.DigitalFilter = 0; - I2C_InitStruct.OwnAddress1 = 0; - I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK; - I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT; - LL_I2C_Init(I2C2, &I2C_InitStruct); - LL_I2C_EnableAutoEndMode(I2C2); - LL_I2C_SetOwnAddress2(I2C2, 0, LL_I2C_OWNADDRESS2_NOMASK); - LL_I2C_DisableOwnAddress2(I2C2); - LL_I2C_DisableGeneralCall(I2C2); - LL_I2C_EnableClockStretching(I2C2); - /* USER CODE BEGIN I2C2_Init 2 */ - - /* USER CODE END I2C2_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G474xE_CAN_TESTING/Core/Src/spi.c b/G474xE_CAN_TESTING/Core/Src/spi.c deleted file mode 100644 index 66459f2ec..000000000 --- a/G474xE_CAN_TESTING/Core/Src/spi.c +++ /dev/null @@ -1,95 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file spi.c - * @brief This file provides code for the configuration - * of the SPI instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "spi.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* SPI3 init function */ -void MX_SPI3_Init(void) -{ - - /* USER CODE BEGIN SPI3_Init 0 */ - - /* USER CODE END SPI3_Init 0 */ - - LL_SPI_InitTypeDef SPI_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI3); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - /**SPI3 GPIO Configuration - PC10 ------> SPI3_SCK - PC11 ------> SPI3_MISO - PC12 ------> SPI3_MOSI - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_6; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_6; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_6; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN SPI3_Init 1 */ - - /* USER CODE END SPI3_Init 1 */ - SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; - SPI_InitStruct.Mode = LL_SPI_MODE_MASTER; - SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_4BIT; - SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; - SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE; - SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; - SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV32; - SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST; - SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; - SPI_InitStruct.CRCPoly = 7; - LL_SPI_Init(SPI3, &SPI_InitStruct); - LL_SPI_SetStandard(SPI3, LL_SPI_PROTOCOL_MOTOROLA); - LL_SPI_EnableNSSPulseMgt(SPI3); - /* USER CODE BEGIN SPI3_Init 2 */ - - /* USER CODE END SPI3_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G474xE_CAN_TESTING/Core/Src/stm32g4xx_hal_msp.c b/G474xE_CAN_TESTING/Core/Src/stm32g4xx_hal_msp.c deleted file mode 100644 index 69189ef4e..000000000 --- a/G474xE_CAN_TESTING/Core/Src/stm32g4xx_hal_msp.c +++ /dev/null @@ -1,86 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_msp.c - * @brief This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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*/ - - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); - - /* USER CODE BEGIN MspInit 1 */ - - /* USER CODE END MspInit 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G474xE_CAN_TESTING/Core/Src/stm32g4xx_it.c b/G474xE_CAN_TESTING/Core/Src/stm32g4xx_it.c deleted file mode 100644 index dd322200e..000000000 --- a/G474xE_CAN_TESTING/Core/Src/stm32g4xx_it.c +++ /dev/null @@ -1,194 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "stm32g4xx_it.h" - -#include "main.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 --------------------------------------------------------*/ -// extern FDCAN_HandleTypeDef hfdcan2; -/* 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 Prefetch 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 */ -} - -/******************************************************************************/ -/* STM32G4xx 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_stm32g4xx.s). */ -/******************************************************************************/ diff --git a/G474xE_CAN_TESTING/Core/Src/tim.c b/G474xE_CAN_TESTING/Core/Src/tim.c deleted file mode 100644 index 7f521c3bf..000000000 --- a/G474xE_CAN_TESTING/Core/Src/tim.c +++ /dev/null @@ -1,79 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file tim.c - * @brief This file provides code for the configuration - * of the TIM instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "tim.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* TIM2 init function */ -void MX_TIM2_Init(void) -{ - - /* USER CODE BEGIN TIM2_Init 0 */ - - /* USER CODE END TIM2_Init 0 */ - - LL_TIM_InitTypeDef TIM_InitStruct = {0}; - LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2); - - /* USER CODE BEGIN TIM2_Init 1 */ - - /* USER CODE END TIM2_Init 1 */ - TIM_InitStruct.Prescaler = 0; - TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; - TIM_InitStruct.Autoreload = 4294967295; - TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; - LL_TIM_Init(TIM2, &TIM_InitStruct); - LL_TIM_DisableARRPreload(TIM2); - LL_TIM_SetClockSource(TIM2, LL_TIM_CLOCKSOURCE_INTERNAL); - TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_FORCED_ACTIVE; - TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; - TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; - TIM_OC_InitStruct.CompareValue = 0; - TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; - LL_TIM_OC_Init(TIM2, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct); - LL_TIM_OC_DisableFast(TIM2, LL_TIM_CHANNEL_CH1); - LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_RESET); - LL_TIM_DisableMasterSlaveMode(TIM2); - /* USER CODE BEGIN TIM2_Init 2 */ - - /* USER CODE END TIM2_Init 2 */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - /**TIM2 GPIO Configuration - PA0 ------> TIM2_CH1 - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_1; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G474xE_CAN_TESTING/Core/Src/usart.c b/G474xE_CAN_TESTING/Core/Src/usart.c deleted file mode 100644 index 41561862c..000000000 --- a/G474xE_CAN_TESTING/Core/Src/usart.c +++ /dev/null @@ -1,184 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file usart.c - * @brief This file provides code for the configuration - * of the USART instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "usart.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* LPUART1 init function */ - -void MX_LPUART1_UART_Init(void) -{ - - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - LL_LPUART_InitTypeDef LPUART_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_HSI); - - /* Peripheral clock enable */ - LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_LPUART1); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_12; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_12; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - LPUART_InitStruct.PrescalerValue = LL_LPUART_PRESCALER_DIV1; - LPUART_InitStruct.BaudRate = 115200; - LPUART_InitStruct.DataWidth = LL_LPUART_DATAWIDTH_8B; - LPUART_InitStruct.StopBits = LL_LPUART_STOPBITS_1; - LPUART_InitStruct.Parity = LL_LPUART_PARITY_NONE; - LPUART_InitStruct.TransferDirection = LL_LPUART_DIRECTION_TX_RX; - LPUART_InitStruct.HardwareFlowControl = LL_LPUART_HWCONTROL_NONE; - LL_LPUART_Init(LPUART1, &LPUART_InitStruct); - LL_LPUART_SetTXFIFOThreshold(LPUART1, LL_LPUART_FIFOTHRESHOLD_1_8); - LL_LPUART_SetRXFIFOThreshold(LPUART1, LL_LPUART_FIFOTHRESHOLD_1_8); - LL_LPUART_DisableFIFO(LPUART1); - - /* USER CODE BEGIN WKUPType LPUART1 */ - - /* USER CODE END WKUPType LPUART1 */ - - LL_LPUART_Enable(LPUART1); - - /* Polling LPUART1 initialisation */ - while ((!(LL_LPUART_IsActiveFlag_TEACK(LPUART1))) || (!(LL_LPUART_IsActiveFlag_REACK(LPUART1)))) {} - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ -} -/* USART1 init function */ - -void MX_USART1_UART_Init(void) -{ - - /* USER CODE BEGIN USART1_Init 0 */ - - /* USER CODE END USART1_Init 0 */ - - LL_USART_InitTypeDef USART_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2); - - /* Peripheral clock enable */ - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - /**USART1 GPIO Configuration - PC5 ------> USART1_RX - PA11 ------> USART1_CTS - PA12 ------> USART1_RTS - PB6 ------> USART1_TX - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* USER CODE BEGIN USART1_Init 1 */ - - /* USER CODE END USART1_Init 1 */ - USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1; - USART_InitStruct.BaudRate = 115200; - USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; - USART_InitStruct.StopBits = LL_USART_STOPBITS_1; - USART_InitStruct.Parity = LL_USART_PARITY_NONE; - USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX; - USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_RTS_CTS; - USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16; - LL_USART_Init(USART1, &USART_InitStruct); - LL_USART_SetTXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8); - LL_USART_SetRXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8); - LL_USART_DisableFIFO(USART1); - LL_USART_ConfigAsyncMode(USART1); - - /* USER CODE BEGIN WKUPType USART1 */ - - /* USER CODE END WKUPType USART1 */ - - LL_USART_Enable(USART1); - - /* Polling USART1 initialisation */ - while ((!(LL_USART_IsActiveFlag_TEACK(USART1))) || (!(LL_USART_IsActiveFlag_REACK(USART1)))) {} - /* USER CODE BEGIN USART1_Init 2 */ - - /* USER CODE END USART1_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G474xE_CAN_TESTING/G4PERTESTING.ioc b/G474xE_CAN_TESTING/G4PERTESTING.ioc deleted file mode 100644 index 8cf1860b1..000000000 --- a/G474xE_CAN_TESTING/G4PERTESTING.ioc +++ /dev/null @@ -1,382 +0,0 @@ -#MicroXplorer Configuration settings - do not modify -ADC1.Channel-2\#ChannelRegularConversion=ADC_CHANNEL_5 -ADC1.Channel-3\#ChannelRegularConversion=ADC_CHANNEL_7 -ADC1.Channel-4\#ChannelRegularConversion=ADC_CHANNEL_8 -ADC1.Channel-5\#ChannelRegularConversion=ADC_CHANNEL_9 -ADC1.Channel-6\#ChannelRegularConversion=ADC_CHANNEL_12 -ADC1.Channel-7\#ChannelRegularConversion=ADC_CHANNEL_15 -ADC1.ClockPrescaler=ADC_CLOCK_ASYNC_DIV256 -ADC1.CommonPathInternal=null|null|null|null -ADC1.ContinuousConvMode=ENABLE -ADC1.DMAContinuousRequests=ENABLE -ADC1.EOCSelection=ADC_EOC_SEQ_CONV -ADC1.ExternalTrigConv=ADC_SOFTWARE_START -ADC1.IPParameters=Rank-2\#ChannelRegularConversion,Channel-2\#ChannelRegularConversion,SamplingTime-2\#ChannelRegularConversion,OffsetNumber-2\#ChannelRegularConversion,NbrOfConversionFlag,master,Rank-3\#ChannelRegularConversion,Channel-3\#ChannelRegularConversion,SamplingTime-3\#ChannelRegularConversion,OffsetNumber-3\#ChannelRegularConversion,Rank-4\#ChannelRegularConversion,Channel-4\#ChannelRegularConversion,SamplingTime-4\#ChannelRegularConversion,OffsetNumber-4\#ChannelRegularConversion,Rank-5\#ChannelRegularConversion,Channel-5\#ChannelRegularConversion,SamplingTime-5\#ChannelRegularConversion,OffsetNumber-5\#ChannelRegularConversion,Rank-6\#ChannelRegularConversion,Channel-6\#ChannelRegularConversion,SamplingTime-6\#ChannelRegularConversion,OffsetNumber-6\#ChannelRegularConversion,Rank-7\#ChannelRegularConversion,Channel-7\#ChannelRegularConversion,SamplingTime-7\#ChannelRegularConversion,OffsetNumber-7\#ChannelRegularConversion,NbrOfConversion,ContinuousConvMode,DMAContinuousRequests,ClockPrescaler,EOCSelection,ExternalTrigConv,CommonPathInternal -ADC1.NbrOfConversion=6 -ADC1.NbrOfConversionFlag=1 -ADC1.OffsetNumber-2\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-3\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-4\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-5\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-6\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-7\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.Rank-2\#ChannelRegularConversion=1 -ADC1.Rank-3\#ChannelRegularConversion=2 -ADC1.Rank-4\#ChannelRegularConversion=3 -ADC1.Rank-5\#ChannelRegularConversion=4 -ADC1.Rank-6\#ChannelRegularConversion=5 -ADC1.Rank-7\#ChannelRegularConversion=6 -ADC1.SamplingTime-2\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-3\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-4\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-5\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-6\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-7\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.master=1 -CAD.formats=[] -CAD.pinconfig=Dual -CAD.provider= -Dma.ADC1.0.Direction=DMA_PERIPH_TO_MEMORY -Dma.ADC1.0.EventEnable=DISABLE -Dma.ADC1.0.Instance=DMA1_Channel1 -Dma.ADC1.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD -Dma.ADC1.0.MemInc=DMA_MINC_ENABLE -Dma.ADC1.0.Mode=DMA_CIRCULAR -Dma.ADC1.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD -Dma.ADC1.0.PeriphInc=DMA_PINC_DISABLE -Dma.ADC1.0.Polarity=HAL_DMAMUX_REQ_GEN_RISING -Dma.ADC1.0.Priority=DMA_PRIORITY_LOW -Dma.ADC1.0.RequestNumber=1 -Dma.ADC1.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber -Dma.ADC1.0.SignalID=NONE -Dma.ADC1.0.SyncEnable=DISABLE -Dma.ADC1.0.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT -Dma.ADC1.0.SyncRequestNumber=1 -Dma.ADC1.0.SyncSignalID=NONE -Dma.Request0=ADC1 -Dma.RequestsNb=1 -FDCAN2.AutoRetransmission=ENABLE -FDCAN2.CalculateBaudRateNominal=1000000 -FDCAN2.CalculateTimeBitNominal=1000 -FDCAN2.CalculateTimeQuantumNominal=6.25 -FDCAN2.DataPrescaler=8 -FDCAN2.DataSyncJumpWidth=16 -FDCAN2.DataTimeSeg1=14 -FDCAN2.DataTimeSeg2=5 -FDCAN2.ExtFiltersNbr=2 -FDCAN2.FrameFormat=FDCAN_FRAME_CLASSIC -FDCAN2.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal,FrameFormat,NominalTimeSeg1,NominalTimeSeg2,NominalPrescaler,AutoRetransmission,StdFiltersNbr,TransmitPause,NominalSyncJumpWidth,DataTimeSeg1,DataTimeSeg2,DataPrescaler,DataSyncJumpWidth,ExtFiltersNbr,ProtocolException -FDCAN2.NominalPrescaler=1 -FDCAN2.NominalSyncJumpWidth=16 -FDCAN2.NominalTimeSeg1=119 -FDCAN2.NominalTimeSeg2=40 -FDCAN2.ProtocolException=ENABLE -FDCAN2.StdFiltersNbr=0 -FDCAN2.TransmitPause=DISABLE -File.Version=6 -GPIO.groupedBy=Group By Peripherals -I2C2.IPParameters=Timing -I2C2.Timing=0x30D29DE4 -KeepUserPlacement=false -LPUART1.BaudRate=115200 -LPUART1.IPParameters=BaudRate -Mcu.CPN=STM32G474RET6 -Mcu.Family=STM32G4 -Mcu.IP0=ADC1 -Mcu.IP1=DMA -Mcu.IP10=USART1 -Mcu.IP2=FDCAN2 -Mcu.IP3=I2C2 -Mcu.IP4=LPUART1 -Mcu.IP5=NVIC -Mcu.IP6=RCC -Mcu.IP7=SPI3 -Mcu.IP8=SYS -Mcu.IP9=TIM2 -Mcu.IPNb=11 -Mcu.Name=STM32G474R(B-C-E)Tx -Mcu.Package=LQFP64 -Mcu.Pin0=PF0-OSC_IN -Mcu.Pin1=PF1-OSC_OUT -Mcu.Pin10=PA7 -Mcu.Pin11=PC4 -Mcu.Pin12=PC5 -Mcu.Pin13=PB0 -Mcu.Pin14=PB1 -Mcu.Pin15=PB11 -Mcu.Pin16=PB12 -Mcu.Pin17=PB13 -Mcu.Pin18=PB14 -Mcu.Pin19=PB15 -Mcu.Pin2=PC1 -Mcu.Pin20=PA8 -Mcu.Pin21=PA11 -Mcu.Pin22=PA12 -Mcu.Pin23=PA13 -Mcu.Pin24=PA14 -Mcu.Pin25=PC10 -Mcu.Pin26=PC11 -Mcu.Pin27=PC12 -Mcu.Pin28=PB3 -Mcu.Pin29=PB4 -Mcu.Pin3=PC2 -Mcu.Pin30=PB5 -Mcu.Pin31=PB6 -Mcu.Pin32=PB7 -Mcu.Pin33=PB8-BOOT0 -Mcu.Pin34=PB9 -Mcu.Pin35=VP_SYS_VS_Systick -Mcu.Pin36=VP_SYS_VS_DBSignals -Mcu.Pin37=VP_TIM2_VS_ClockSourceINT -Mcu.Pin4=PC3 -Mcu.Pin5=PA0 -Mcu.Pin6=PA2 -Mcu.Pin7=PA3 -Mcu.Pin8=PA5 -Mcu.Pin9=PA6 -Mcu.PinsNb=38 -Mcu.ThirdPartyNb=0 -Mcu.UserConstants= -Mcu.UserName=STM32G474RETx -MxCube.Version=6.15.0 -MxDb.Version=DB.6.0.150 -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.FDCAN2_IT0_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true -NVIC.ForceEnableDMAVector=false -NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:false -NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 -NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false -NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -PA0.Signal=S_TIM2_CH1 -PA11.Locked=true -PA11.Mode=CTS_RTS -PA11.Signal=USART1_CTS -PA12.Locked=true -PA12.Mode=CTS_RTS -PA12.Signal=USART1_RTS -PA13.Locked=true -PA13.Mode=Trace_Asynchronous_SW -PA13.Signal=SYS_JTMS-SWDIO -PA14.Locked=true -PA14.Mode=Trace_Asynchronous_SW -PA14.Signal=SYS_JTCK-SWCLK -PA2.GPIOParameters=GPIO_Speed -PA2.GPIO_Speed=GPIO_SPEED_FREQ_HIGH -PA2.Locked=true -PA2.Mode=Asynchronous -PA2.Signal=LPUART1_TX -PA3.GPIOParameters=GPIO_Speed -PA3.GPIO_Speed=GPIO_SPEED_FREQ_HIGH -PA3.Locked=true -PA3.Mode=Asynchronous -PA3.Signal=LPUART1_RX -PA5.GPIOParameters=GPIO_Label -PA5.GPIO_Label=BLINKY -PA5.Locked=true -PA5.Signal=GPIO_Output -PA6.GPIOParameters=GPIO_Label -PA6.GPIO_Label=IMD_SENSE -PA6.Locked=true -PA6.Signal=ADC2_IN3 -PA7.GPIOParameters=GPIO_Label -PA7.GPIO_Label=AMS_SENSE -PA7.Locked=true -PA7.Signal=ADC2_IN4 -PA8.Mode=I2C -PA8.Signal=I2C2_SDA -PB0.GPIOParameters=GPIO_Label -PB0.GPIO_Label=BRAKE_F_SIGNAL -PB0.Locked=true -PB0.Mode=IN15-Single-Ended -PB0.Signal=ADC1_IN15 -PB1.GPIOParameters=GPIO_Label -PB1.GPIO_Label=BRAKE_R_SIGNAL -PB1.Locked=true -PB1.Mode=IN12-Single-Ended -PB1.Signal=ADC1_IN12 -PB11.GPIOParameters=GPIO_Label -PB11.GPIO_Label=LED_TEST -PB11.Locked=true -PB11.Signal=GPIO_Output -PB12.GPIOParameters=GPIO_Speed,GPIO_PuPd -PB12.GPIO_PuPd=GPIO_PULLUP -PB12.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PB12.Locked=true -PB12.Mode=FDCAN_Activate -PB12.Signal=FDCAN2_RX -PB13.GPIOParameters=GPIO_Speed -PB13.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PB13.Locked=true -PB13.Mode=FDCAN_Activate -PB13.Signal=FDCAN2_TX -PB14.GPIOParameters=GPIO_Label -PB14.GPIO_Label=AUX_SIGNAL -PB14.Locked=true -PB14.Mode=IN5-Single-Ended -PB14.Signal=ADC1_IN5 -PB15.GPIOParameters=GPIO_Label -PB15.GPIO_Label=STEERING_ANGLE -PB15.Locked=true -PB15.Signal=ADC2_IN15 -PB3.Locked=true -PB3.Mode=Trace_Asynchronous_SW -PB3.Signal=SYS_JTDO-SWO -PB4.GPIOParameters=GPIO_Label -PB4.GPIO_Label=BRAKE_LIGHT -PB4.Locked=true -PB4.Signal=GPIO_Output -PB5.GPIOParameters=GPIO_Label -PB5.GPIO_Label=TSSI_G_CONTROL -PB5.Locked=true -PB5.Signal=GPIO_Output -PB6.Locked=true -PB6.Mode=Asynchronous -PB6.Signal=USART1_TX -PB7.Locked=true -PB7.Signal=UART4_CTS -PB8-BOOT0.GPIOParameters=GPIO_Label -PB8-BOOT0.GPIO_Label=AUX_CONTROL -PB8-BOOT0.Locked=true -PB8-BOOT0.Signal=GPIO_Output -PB9.GPIOParameters=GPIO_Label -PB9.GPIO_Label=SOFTWARE_OK_CONTROL -PB9.Locked=true -PB9.Signal=GPIO_Output -PC1.GPIOParameters=GPIO_Label -PC1.GPIO_Label=BSPD_SIGNAL -PC1.Locked=true -PC1.Mode=IN7-Single-Ended -PC1.Signal=ADC1_IN7 -PC10.Mode=Full_Duplex_Master -PC10.Signal=SPI3_SCK -PC11.Mode=Full_Duplex_Master -PC11.Signal=SPI3_MISO -PC12.Mode=Full_Duplex_Master -PC12.Signal=SPI3_MOSI -PC2.GPIOParameters=GPIO_Label -PC2.GPIO_Label=APPS1_SIGNAL -PC2.Locked=true -PC2.Mode=IN8-Single-Ended -PC2.Signal=ADC1_IN8 -PC3.GPIOParameters=GPIO_Label -PC3.GPIO_Label=APPS2_SIGNAL -PC3.Locked=true -PC3.Mode=IN9-Single-Ended -PC3.Signal=ADC1_IN9 -PC4.Mode=I2C -PC4.Signal=I2C2_SCL -PC5.Mode=Asynchronous -PC5.Signal=USART1_RX -PF0-OSC_IN.Locked=true -PF0-OSC_IN.Mode=HSE-External-Oscillator -PF0-OSC_IN.Signal=RCC_OSC_IN -PF1-OSC_OUT.Locked=true -PF1-OSC_OUT.Mode=HSE-External-Oscillator -PF1-OSC_OUT.Signal=RCC_OSC_OUT -PinOutPanel.RotationAngle=180 -ProjectManager.AskForMigrate=true -ProjectManager.BackupPrevious=false -ProjectManager.CompilerLinker=GCC -ProjectManager.CompilerOptimize=6 -ProjectManager.ComputerToolchain=false -ProjectManager.CoupleFile=true -ProjectManager.CustomerFirmwarePackage= -ProjectManager.DefaultFWLocation=true -ProjectManager.DeletePrevious=true -ProjectManager.DeviceId=STM32G474RETx -ProjectManager.FirmwarePackage=STM32Cube FW_G4 V1.6.1 -ProjectManager.FreePins=true -ProjectManager.HalAssertFull=false -ProjectManager.HeapSize=0x200 -ProjectManager.KeepUserCode=true -ProjectManager.LastFirmware=true -ProjectManager.LibraryCopy=0 -ProjectManager.MainLocation=Core/Src -ProjectManager.NoMain=false -ProjectManager.PreviousToolchain= -ProjectManager.ProjectBuild=false -ProjectManager.ProjectFileName=G4PERTESTING.ioc -ProjectManager.ProjectName=G4PERTESTING -ProjectManager.ProjectStructure= -ProjectManager.RegisterCallBack= -ProjectManager.StackSize=0x400 -ProjectManager.TargetToolchain=CMake -ProjectManager.ToolChainLocation= -ProjectManager.UAScriptAfterPath= -ProjectManager.UAScriptBeforePath= -ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_DMA_Init-DMA-false-LL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_ADC1_Init-ADC1-false-LL-true,6-MX_LPUART1_UART_Init-LPUART1-false-LL-true,7-MX_I2C2_Init-I2C2-false-LL-true,8-MX_USART1_UART_Init-USART1-false-LL-true,9-MX_SPI3_Init-SPI3-false-LL-true,10-MX_TIM2_Init-TIM2-false-LL-true -RCC.ADC12Freq_Value=160000000 -RCC.ADC345Freq_Value=160000000 -RCC.AHBFreq_Value=160000000 -RCC.APB1Freq_Value=160000000 -RCC.APB1TimFreq_Value=160000000 -RCC.APB2Freq_Value=160000000 -RCC.APB2TimFreq_Value=160000000 -RCC.CRSFreq_Value=48000000 -RCC.CortexFreq_Value=160000000 -RCC.EXTERNAL_CLOCK_VALUE=12288000 -RCC.EnbaleCSS=true -RCC.FCLKCortexFreq_Value=160000000 -RCC.FDCANFreq_Value=160000000 -RCC.FamilyName=M -RCC.HCLKFreq_Value=160000000 -RCC.HRTIM1Freq_Value=160000000 -RCC.HSE_VALUE=16000000 -RCC.HSI48_VALUE=48000000 -RCC.HSI_VALUE=16000000 -RCC.I2C1Freq_Value=160000000 -RCC.I2C2Freq_Value=160000000 -RCC.I2C3Freq_Value=160000000 -RCC.I2C4Freq_Value=160000000 -RCC.I2SFreq_Value=160000000 -RCC.IPParameters=ADC12Freq_Value,ADC345Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,EnbaleCSS,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HRTIM1Freq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PLLSourceVirtual,PWRFreq_Value,QSPIFreq_Value,RNGFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value -RCC.LPTIM1Freq_Value=160000000 -RCC.LPUART1Freq_Value=160000000 -RCC.LSCOPinFreq_Value=32000 -RCC.LSE_VALUE=32768 -RCC.LSI_VALUE=32000 -RCC.MCO1PinFreq_Value=16000000 -RCC.PLLN=20 -RCC.PLLPoutputFreq_Value=160000000 -RCC.PLLQoutputFreq_Value=160000000 -RCC.PLLRCLKFreq_Value=160000000 -RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE -RCC.PWRFreq_Value=160000000 -RCC.QSPIFreq_Value=160000000 -RCC.RNGFreq_Value=160000000 -RCC.SAI1Freq_Value=160000000 -RCC.SYSCLKFreq_VALUE=160000000 -RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK -RCC.UART4Freq_Value=160000000 -RCC.UART5Freq_Value=160000000 -RCC.USART1Freq_Value=160000000 -RCC.USART2Freq_Value=160000000 -RCC.USART3Freq_Value=160000000 -RCC.USBFreq_Value=160000000 -RCC.VCOInputFreq_Value=16000000 -RCC.VCOOutputFreq_Value=320000000 -SH.S_TIM2_CH1.0=TIM2_CH1,Forced Output1 CH1 -SH.S_TIM2_CH1.ConfNb=1 -SPI3.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_32 -SPI3.CalculateBaudRate=5.0 MBits/s -SPI3.Direction=SPI_DIRECTION_2LINES -SPI3.IPParameters=VirtualType,Mode,Direction,BaudRatePrescaler,CalculateBaudRate -SPI3.Mode=SPI_MODE_MASTER -SPI3.VirtualType=VM_MASTER -TIM2.Channel-Forced\ Output1\ CH1=TIM_CHANNEL_1 -TIM2.IPParameters=Channel-Forced Output1 CH1 -USART1.IPParameters=VirtualMode-Asynchronous -USART1.VirtualMode-Asynchronous=VM_ASYNC -VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals -VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick -VP_TIM2_VS_ClockSourceINT.Mode=Internal -VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT -board=custom diff --git a/G474xE_CAN_TESTING/PROFILER_TEST/CMakeLists.txt b/G474xE_CAN_TESTING/PROFILER_TEST/CMakeLists.txt deleted file mode 100644 index e3c0515e4..000000000 --- a/G474xE_CAN_TESTING/PROFILER_TEST/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -# Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) - -# Define the build type -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug") -endif() - -# Enable compile command to ease indexing with e.g. clangd -set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) - -# Enable CMake support for ASM and C languages -enable_language( - C - ASM -) - -# Core project settings -project(${CMAKE_PROJECT_NAME}) - -# what, does in fact not get the filename of somthing but rather the name of the project from the path -get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) - -add_library(${PROJECT_NAME}_USER_CODE INTERFACE) - -target_sources( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Src/adc.c - ../Core/Src/crc.c - ../Core/Src/dma.c - ../Core/Src/gpio.c - ../Core/Src/i2c.c - main.c - ../Core/Src/spi.c - ../Core/Src/stm32g4xx_hal_msp.c - ../Core/Src/stm32g4xx_it.c - ../Core/Src/tim.c - ../Core/Src/usart.c -) - -target_link_libraries( - ${PROJECT_NAME}_USER_CODE - INTERFACE - PERIPHERAL_CAN_LIB - LOGOMATIC_OLD_LIB -) - -target_include_directories( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Inc - . -) diff --git a/G474xE_CAN_TESTING/PROFILER_TEST/can_cfg.h b/G474xE_CAN_TESTING/PROFILER_TEST/can_cfg.h deleted file mode 100644 index a9e30c564..000000000 --- a/G474xE_CAN_TESTING/PROFILER_TEST/can_cfg.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef CAN_CFG_H -#define CAN_CFG_H - -// #define USEDMA - -#define USECAN1 -#define TX_BUFFER_1_SIZE 10 - -// not using -// #define CAN1_RX_GPIO_PORT -// #define CAN1_RX_GPIO_PIN -// #define CAN1_TX_GPIO_PORT -// #define CAN1_TX_GPIO_PIN - -// #define CAN - -#define USECAN2 -#define TX_BUFFER_2_SIZE 10 - -#endif diff --git a/G474xE_CAN_TESTING/PROFILER_TEST/main.c b/G474xE_CAN_TESTING/PROFILER_TEST/main.c deleted file mode 100644 index c916470eb..000000000 --- a/G474xE_CAN_TESTING/PROFILER_TEST/main.c +++ /dev/null @@ -1,275 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "adc.h" -#include "can.h" // Assume this works -#include "can_tests.h" -#include "dma.h" -#include "fdcan.h" -#include "gpio.h" -#include "i2c.h" -#include "spi.h" -#include "tim.h" -#include "usart.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -#include "Logomatic.h" -// #include "profile.h" -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* 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 -----------------------------------------------*/ -void SystemClock_Config(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ -/* Enable ITM for SWO output */ -static void ITM_Enable(void) -{ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_0; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - DBGMCU->CR |= DBGMCU_CR_TRACE_IOEN; - - /* Enable TRC (Trace) */ - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; - - /* Configure TPI for SWO output (set prescaler for 2MHz SWO clock) */ - TPI->SPPR = 2U; /* 2 = Manchester/async UART mode */ - TPI->ACPR = 84U; /* Prescaler: (170 MHz / (84+1) / 2) ≈ 1MHz SWO */ - - ITM->TER |= (1UL << 0); - ITM->TCR |= (ITM_TCR_ITMENA_Msk | ITM_TCR_SWOENA_Msk); -} -// static int toggleze = 0; -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU - * Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the - * Systick. */ - HAL_Init(); - /* USER CODE BEGIN Init */ - ITM_Enable(); - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); - // MX_FDCAN2_Init(); - MX_ADC1_Init(); - MX_LPUART1_UART_Init(); - MX_I2C2_Init(); - MX_USART1_UART_Init(); - MX_SPI3_Init(); - MX_TIM2_Init(); - - /* USER CODE BEGIN 2 */ - - LOGOMATIC("Booted!\n"); - - // LOGOMATIC("running can_stress_test:\n"); - profiler_test(); - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) { - /* USER CODE END WHILE */ - LOGOMATIC("Main Loop\n"); - LL_mDelay(1000); - - // Receive on GPIOs - // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, toggleze ? GPIO_PIN_SET - // : GPIO_PIN_RESET); HAL_Delay(1000); msg.data[0] = toggleze ? - // 0x00 : 0x80; can_send(data_can, &msg); - - // RCC->CFGR |= RCC_CFGR_SW; - /* USER CODE BEGIN 3 */ - } -} - -/** - * @brief System Clock Configuration - * @retval None - */ - -// void SystemClock_Config(void) -// { -// LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); -// while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) { -// } -// LL_PWR_EnableRange1BoostMode(); -// LL_RCC_HSE_Enable(); - -// /* Wait till HSE is ready */ -// while (LL_RCC_HSE_IsReady() != 1) { -// } - -// LL_RCC_HSE_EnableCSS(); -// LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_1, 20, -// LL_RCC_PLLR_DIV_2); -// //LL_RCC_PLL_ConfigDomain_48M(LL_RCC_PLLSOURCE_HSE, ); -// LL_RCC_PLL_EnableDomain_SYS(); -// LL_RCC_PLL_Enable(); -// /* Wait till PLL is ready */ -// while (LL_RCC_PLL_IsReady() != 1) { -// } - -// LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); -// /* Wait till System clock is ready */ -// while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { -// } - -// /* Insure 1us transition state at intermediate medium speed clock*/ -// for (__IO uint32_t i = (170 >> 1); i != 0; i--) -// ; - -// /* Set AHB prescaler*/ -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); -// LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); -// LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); -// LL_SetSystemCoreClock(160000000); - -// /* Update the time base */ -// if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { -// Error_Handler(); -// } -// }*/ -void SystemClock_Config(void) -{ - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - // LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(170000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return - * state */ - __disable_irq(); - while (1) {} - /* USER CODE END Error_Handler_Debug */ -} -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line - number, ex: printf("Wrong parameters value: file %s on line %d\r\n", - file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ diff --git a/G474xE_CAN_TESTING/README.md b/G474xE_CAN_TESTING/README.md deleted file mode 100644 index 558f1c125..000000000 --- a/G474xE_CAN_TESTING/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# STM32G474 CAN -Nucleo-G474RE-C04 - -Plug in the board following ST-LINK pinout -Compile and flash G4CANTESTING.elf diff --git a/G4ADCTESTING/CMakeLists.txt b/G4ADCTESTING/CMakeLists.txt deleted file mode 100644 index 64f36cea2..000000000 --- a/G4ADCTESTING/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -# Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) - -# Define the build type -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug") -endif() - -# Enable compile command to ease indexing with e.g. clangd -set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) - -# Enable CMake support for ASM and C languages -enable_language( - C - ASM -) - -# Core project settings -project(${CMAKE_PROJECT_NAME}) - -# what, does in fact not get the filename of somthing but rather the name of the project from the path -get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) - -add_library(${PROJECT_NAME}_USER_CODE INTERFACE) -target_sources( - ${PROJECT_NAME}_USER_CODE - INTERFACE - Core/Src/adc.c - Core/Src/crc.c - Core/Src/dma.c - Core/Src/fdcan.c - Core/Src/gpio.c - Core/Src/i2c.c - Core/Src/main.c - Core/Src/spi.c - Core/Src/stm32g4xx_hal_msp.c - Core/Src/stm32g4xx_it.c - Core/Src/tim.c - Core/Src/usart.c -) - -target_link_libraries( - ${PROJECT_NAME}_USER_CODE - INTERFACE - GR_ADC - LOGOMATIC_OLD_LIB -) - -target_include_directories(${PROJECT_NAME}_USER_CODE INTERFACE Core/Inc) diff --git a/G4ADCTESTING/Core/Inc/adc.h b/G4ADCTESTING/Core/Inc/adc.h deleted file mode 100644 index 41154538b..000000000 --- a/G4ADCTESTING/Core/Inc/adc.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file adc.h - * @brief This file contains all the function prototypes for - * the adc.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __ADC_H__ -#define __ADC_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_ADC1_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __ADC_H__ */ diff --git a/G4ADCTESTING/Core/Inc/crc.h b/G4ADCTESTING/Core/Inc/crc.h deleted file mode 100644 index 133957e92..000000000 --- a/G4ADCTESTING/Core/Inc/crc.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file crc.h - * @brief This file contains all the function prototypes for - * the crc.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __CRC_H__ -#define __CRC_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern CRC_HandleTypeDef hcrc; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_CRC_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CRC_H__ */ diff --git a/G4ADCTESTING/Core/Inc/dma.h b/G4ADCTESTING/Core/Inc/dma.h deleted file mode 100644 index ae819cab4..000000000 --- a/G4ADCTESTING/Core/Inc/dma.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file dma.h - * @brief This file contains all the function prototypes for - * the dma.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __DMA_H__ -#define __DMA_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* DMA memory to memory transfer handles -------------------------------------*/ - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_DMA_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __DMA_H__ */ diff --git a/G4ADCTESTING/Core/Inc/fdcan.h b/G4ADCTESTING/Core/Inc/fdcan.h deleted file mode 100644 index 56c4a8adb..000000000 --- a/G4ADCTESTING/Core/Inc/fdcan.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file fdcan.h - * @brief This file contains all the function prototypes for - * the fdcan.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __FDCAN_H__ -#define __FDCAN_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern FDCAN_HandleTypeDef hfdcan2; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_FDCAN2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __FDCAN_H__ */ diff --git a/G4ADCTESTING/Core/Inc/gpio.h b/G4ADCTESTING/Core/Inc/gpio.h deleted file mode 100644 index 843d4e9e7..000000000 --- a/G4ADCTESTING/Core/Inc/gpio.h +++ /dev/null @@ -1,48 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file gpio.h - * @brief This file contains all the function prototypes for - * the gpio.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __GPIO_H__ -#define __GPIO_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_GPIO_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif -#endif /*__ GPIO_H__ */ diff --git a/G4ADCTESTING/Core/Inc/i2c.h b/G4ADCTESTING/Core/Inc/i2c.h deleted file mode 100644 index 0a0a50803..000000000 --- a/G4ADCTESTING/Core/Inc/i2c.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file i2c.h - * @brief This file contains all the function prototypes for - * the i2c.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __I2C_H__ -#define __I2C_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_I2C2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __I2C_H__ */ diff --git a/G4ADCTESTING/Core/Inc/main.h b/G4ADCTESTING/Core/Inc/main.h deleted file mode 100644 index 23d7ffce4..000000000 --- a/G4ADCTESTING/Core/Inc/main.h +++ /dev/null @@ -1,115 +0,0 @@ -/* 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) 2024 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 "stm32g4xx_hal.h" -#include "stm32g4xx_ll_adc.h" -#include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_dma.h" -#include "stm32g4xx_ll_exti.h" -#include "stm32g4xx_ll_gpio.h" -#include "stm32g4xx_ll_i2c.h" -#include "stm32g4xx_ll_lpuart.h" -#include "stm32g4xx_ll_pwr.h" -#include "stm32g4xx_ll_rcc.h" -#include "stm32g4xx_ll_spi.h" -#include "stm32g4xx_ll_system.h" -#include "stm32g4xx_ll_tim.h" -#include "stm32g4xx_ll_usart.h" -#include "stm32g4xx_ll_utils.h" - -/* 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 Error_Handler(void); - -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -/* Private defines -----------------------------------------------------------*/ -#define BSPD_SIGNAL_Pin LL_GPIO_PIN_1 -#define BSPD_SIGNAL_GPIO_Port GPIOC -#define APPS1_SIGNAL_Pin LL_GPIO_PIN_2 -#define APPS1_SIGNAL_GPIO_Port GPIOC -#define APPS2_SIGNAL_Pin LL_GPIO_PIN_3 -#define APPS2_SIGNAL_GPIO_Port GPIOC -#define BLINKY_Pin LL_GPIO_PIN_5 -#define BLINKY_GPIO_Port GPIOA -#define IMD_SENSE_Pin LL_GPIO_PIN_6 -#define IMD_SENSE_GPIO_Port GPIOA -#define AMS_SENSE_Pin LL_GPIO_PIN_7 -#define AMS_SENSE_GPIO_Port GPIOA -#define BRAKE_F_SIGNAL_Pin LL_GPIO_PIN_0 -#define BRAKE_F_SIGNAL_GPIO_Port GPIOB -#define BRAKE_R_SIGNAL_Pin LL_GPIO_PIN_1 -#define BRAKE_R_SIGNAL_GPIO_Port GPIOB -#define LED_TEST_Pin LL_GPIO_PIN_11 -#define LED_TEST_GPIO_Port GPIOB -#define AUX_SIGNAL_Pin LL_GPIO_PIN_14 -#define AUX_SIGNAL_GPIO_Port GPIOB -#define STEERING_ANGLE_Pin LL_GPIO_PIN_15 -#define STEERING_ANGLE_GPIO_Port GPIOB -#define BRAKE_LIGHT_Pin LL_GPIO_PIN_4 -#define BRAKE_LIGHT_GPIO_Port GPIOB -#define TSSI_G_CONTROL_Pin LL_GPIO_PIN_5 -#define TSSI_G_CONTROL_GPIO_Port GPIOB -#define AUX_CONTROL_Pin LL_GPIO_PIN_8 -#define AUX_CONTROL_GPIO_Port GPIOB -#define SOFTWARE_OK_CONTROL_Pin LL_GPIO_PIN_9 -#define SOFTWARE_OK_CONTROL_GPIO_Port GPIOB - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -#ifdef __cplusplus -} -#endif - -#endif /* __MAIN_H */ diff --git a/G4ADCTESTING/Core/Inc/spi.h b/G4ADCTESTING/Core/Inc/spi.h deleted file mode 100644 index 74bed003b..000000000 --- a/G4ADCTESTING/Core/Inc/spi.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file spi.h - * @brief This file contains all the function prototypes for - * the spi.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __SPI_H__ -#define __SPI_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_SPI3_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __SPI_H__ */ diff --git a/G4ADCTESTING/Core/Inc/stm32g4xx_hal_conf.h b/G4ADCTESTING/Core/Inc/stm32g4xx_hal_conf.h deleted file mode 100644 index 3e1fcb018..000000000 --- a/G4ADCTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ /dev/null @@ -1,390 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_conf.h - * @author MCD Application Team - * @brief HAL configuration file - ****************************************************************************** - * @attention - * - * Copyright (c) 2019 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 STM32G4xx_HAL_CONF_H -#define STM32G4xx_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_ADC_MODULE_ENABLED */ -/*#define HAL_COMP_MODULE_ENABLED */ -/*#define HAL_CORDIC_MODULE_ENABLED */ -#define HAL_CRC_MODULE_ENABLED -/*#define HAL_CRYP_MODULE_ENABLED */ -/*#define HAL_DAC_MODULE_ENABLED */ -#define HAL_FDCAN_MODULE_ENABLED -/*#define HAL_FMAC_MODULE_ENABLED */ -/*#define HAL_HRTIM_MODULE_ENABLED */ -/*#define HAL_IRDA_MODULE_ENABLED */ -/*#define HAL_IWDG_MODULE_ENABLED */ -/*#define HAL_I2C_MODULE_ENABLED */ -/*#define HAL_I2S_MODULE_ENABLED */ -/*#define HAL_LPTIM_MODULE_ENABLED */ -/*#define HAL_NAND_MODULE_ENABLED */ -/*#define HAL_NOR_MODULE_ENABLED */ -/*#define HAL_OPAMP_MODULE_ENABLED */ -/*#define HAL_PCD_MODULE_ENABLED */ -/*#define HAL_QSPI_MODULE_ENABLED */ -/*#define HAL_RNG_MODULE_ENABLED */ -/*#define HAL_RTC_MODULE_ENABLED */ -/*#define HAL_SAI_MODULE_ENABLED */ -/*#define HAL_SMARTCARD_MODULE_ENABLED */ -/*#define HAL_SMBUS_MODULE_ENABLED */ -/*#define HAL_SPI_MODULE_ENABLED */ -/*#define HAL_SRAM_MODULE_ENABLED */ -/*#define HAL_TIM_MODULE_ENABLED */ -/*#define HAL_UART_MODULE_ENABLED */ -/*#define HAL_USART_MODULE_ENABLED */ -/*#define HAL_WWDG_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 - -/* ########################## Register Callbacks selection - * ############################## */ -/** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U - -/* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(HSE_STARTUP_TIMEOUT) -#define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ - -/** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high - * precision clock to the USB peripheral by means of a special Clock Recovery - * System (CRS) circuitry. When the CRS is not used, the HSI48 RC oscillator - * runs on it default frequency which is subject to manufacturing process - * variations. - */ -#if !defined(HSI48_VALUE) -#define HSI48_VALUE \ - (48000000UL) /*!< Value of the Internal High Speed oscillator for USB \ - FS/RNG in Hz. The real value my vary depending on \ - manufacturing process variations.*/ -#endif /* HSI48_VALUE */ - -/** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined(LSI_VALUE) -/*!< Value of the Internal Low Speed oscillator in Hz -The real value may vary depending on the variations in voltage and -temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ -/** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system - * frequency - */ -#if !defined(LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ - -#if !defined(LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ - -/** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S - * and SAI clock source frequency, this source is inserted directly through - * I2S_CKIN pad. - */ -#if !defined(EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U - -/* ########################## Assert Selection ############################## */ -/** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -/* #define USE_FULL_ASSERT 1U */ - -/* ################## 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 "stm32g4xx_hal_rcc.h" -#endif /* HAL_RCC_MODULE_ENABLED */ - -#ifdef HAL_GPIO_MODULE_ENABLED -#include "stm32g4xx_hal_gpio.h" -#endif /* HAL_GPIO_MODULE_ENABLED */ - -#ifdef HAL_DMA_MODULE_ENABLED -#include "stm32g4xx_hal_dma.h" -#endif /* HAL_DMA_MODULE_ENABLED */ - -#ifdef HAL_CORTEX_MODULE_ENABLED -#include "stm32g4xx_hal_cortex.h" -#endif /* HAL_CORTEX_MODULE_ENABLED */ - -#ifdef HAL_ADC_MODULE_ENABLED -#include "stm32g4xx_hal_adc.h" -#endif /* HAL_ADC_MODULE_ENABLED */ - -#ifdef HAL_COMP_MODULE_ENABLED -#include "stm32g4xx_hal_comp.h" -#endif /* HAL_COMP_MODULE_ENABLED */ - -#ifdef HAL_CORDIC_MODULE_ENABLED -#include "stm32g4xx_hal_cordic.h" -#endif /* HAL_CORDIC_MODULE_ENABLED */ - -#ifdef HAL_CRC_MODULE_ENABLED -#include "stm32g4xx_hal_crc.h" -#endif /* HAL_CRC_MODULE_ENABLED */ - -#ifdef HAL_CRYP_MODULE_ENABLED -#include "stm32g4xx_hal_cryp.h" -#endif /* HAL_CRYP_MODULE_ENABLED */ - -#ifdef HAL_DAC_MODULE_ENABLED -#include "stm32g4xx_hal_dac.h" -#endif /* HAL_DAC_MODULE_ENABLED */ - -#ifdef HAL_EXTI_MODULE_ENABLED -#include "stm32g4xx_hal_exti.h" -#endif /* HAL_EXTI_MODULE_ENABLED */ - -#ifdef HAL_FDCAN_MODULE_ENABLED -#include "stm32g4xx_hal_fdcan.h" -#endif /* HAL_FDCAN_MODULE_ENABLED */ - -#ifdef HAL_FLASH_MODULE_ENABLED -#include "stm32g4xx_hal_flash.h" -#endif /* HAL_FLASH_MODULE_ENABLED */ - -#ifdef HAL_FMAC_MODULE_ENABLED -#include "stm32g4xx_hal_fmac.h" -#endif /* HAL_FMAC_MODULE_ENABLED */ - -#ifdef HAL_HRTIM_MODULE_ENABLED -#include "stm32g4xx_hal_hrtim.h" -#endif /* HAL_HRTIM_MODULE_ENABLED */ - -#ifdef HAL_IRDA_MODULE_ENABLED -#include "stm32g4xx_hal_irda.h" -#endif /* HAL_IRDA_MODULE_ENABLED */ - -#ifdef HAL_IWDG_MODULE_ENABLED -#include "stm32g4xx_hal_iwdg.h" -#endif /* HAL_IWDG_MODULE_ENABLED */ - -#ifdef HAL_I2C_MODULE_ENABLED -#include "stm32g4xx_hal_i2c.h" -#endif /* HAL_I2C_MODULE_ENABLED */ - -#ifdef HAL_I2S_MODULE_ENABLED -#include "stm32g4xx_hal_i2s.h" -#endif /* HAL_I2S_MODULE_ENABLED */ - -#ifdef HAL_LPTIM_MODULE_ENABLED -#include "stm32g4xx_hal_lptim.h" -#endif /* HAL_LPTIM_MODULE_ENABLED */ - -#ifdef HAL_NAND_MODULE_ENABLED -#include "stm32g4xx_hal_nand.h" -#endif /* HAL_NAND_MODULE_ENABLED */ - -#ifdef HAL_NOR_MODULE_ENABLED -#include "stm32g4xx_hal_nor.h" -#endif /* HAL_NOR_MODULE_ENABLED */ - -#ifdef HAL_OPAMP_MODULE_ENABLED -#include "stm32g4xx_hal_opamp.h" -#endif /* HAL_OPAMP_MODULE_ENABLED */ - -#ifdef HAL_PCD_MODULE_ENABLED -#include "stm32g4xx_hal_pcd.h" -#endif /* HAL_PCD_MODULE_ENABLED */ - -#ifdef HAL_PWR_MODULE_ENABLED -#include "stm32g4xx_hal_pwr.h" -#endif /* HAL_PWR_MODULE_ENABLED */ - -#ifdef HAL_QSPI_MODULE_ENABLED -#include "stm32g4xx_hal_qspi.h" -#endif /* HAL_QSPI_MODULE_ENABLED */ - -#ifdef HAL_RNG_MODULE_ENABLED -#include "stm32g4xx_hal_rng.h" -#endif /* HAL_RNG_MODULE_ENABLED */ - -#ifdef HAL_RTC_MODULE_ENABLED -#include "stm32g4xx_hal_rtc.h" -#endif /* HAL_RTC_MODULE_ENABLED */ - -#ifdef HAL_SAI_MODULE_ENABLED -#include "stm32g4xx_hal_sai.h" -#endif /* HAL_SAI_MODULE_ENABLED */ - -#ifdef HAL_SMARTCARD_MODULE_ENABLED -#include "stm32g4xx_hal_smartcard.h" -#endif /* HAL_SMARTCARD_MODULE_ENABLED */ - -#ifdef HAL_SMBUS_MODULE_ENABLED -#include "stm32g4xx_hal_smbus.h" -#endif /* HAL_SMBUS_MODULE_ENABLED */ - -#ifdef HAL_SPI_MODULE_ENABLED -#include "stm32g4xx_hal_spi.h" -#endif /* HAL_SPI_MODULE_ENABLED */ - -#ifdef HAL_SRAM_MODULE_ENABLED -#include "stm32g4xx_hal_sram.h" -#endif /* HAL_SRAM_MODULE_ENABLED */ - -#ifdef HAL_TIM_MODULE_ENABLED -#include "stm32g4xx_hal_tim.h" -#endif /* HAL_TIM_MODULE_ENABLED */ - -#ifdef HAL_UART_MODULE_ENABLED -#include "stm32g4xx_hal_uart.h" -#endif /* HAL_UART_MODULE_ENABLED */ - -#ifdef HAL_USART_MODULE_ENABLED -#include "stm32g4xx_hal_usart.h" -#endif /* HAL_USART_MODULE_ENABLED */ - -#ifdef HAL_WWDG_MODULE_ENABLED -#include "stm32g4xx_hal_wwdg.h" -#endif /* HAL_WWDG_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 /* STM32G4xx_HAL_CONF_H */ diff --git a/G4ADCTESTING/Core/Inc/stm32g4xx_it.h b/G4ADCTESTING/Core/Inc/stm32g4xx_it.h deleted file mode 100644 index b6c3b2f72..000000000 --- a/G4ADCTESTING/Core/Inc/stm32g4xx_it.h +++ /dev/null @@ -1,67 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_it.h - * @brief This file contains the headers of the interrupt handlers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __STM32G4xx_IT_H -#define __STM32G4xx_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); -void FDCAN2_IT0_IRQHandler(void); -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32G4xx_IT_H */ diff --git a/G4ADCTESTING/Core/Inc/tim.h b/G4ADCTESTING/Core/Inc/tim.h deleted file mode 100644 index c19e6cc71..000000000 --- a/G4ADCTESTING/Core/Inc/tim.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file tim.h - * @brief This file contains all the function prototypes for - * the tim.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __TIM_H__ -#define __TIM_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_TIM2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __TIM_H__ */ diff --git a/G4ADCTESTING/Core/Inc/usart.h b/G4ADCTESTING/Core/Inc/usart.h deleted file mode 100644 index daefd73e6..000000000 --- a/G4ADCTESTING/Core/Inc/usart.h +++ /dev/null @@ -1,50 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file usart.h - * @brief This file contains all the function prototypes for - * the usart.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __USART_H__ -#define __USART_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_LPUART1_UART_Init(void); -void MX_USART1_UART_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USART_H__ */ diff --git a/G4ADCTESTING/Core/Src/adc.c b/G4ADCTESTING/Core/Src/adc.c deleted file mode 100644 index f3dbff8ed..000000000 --- a/G4ADCTESTING/Core/Src/adc.c +++ /dev/null @@ -1,186 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file adc.c - * @brief This file provides code for the configuration - * of the ADC instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "adc.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* ADC1 init function */ -void MX_ADC1_Init(void) -{ - - /* USER CODE BEGIN ADC1_Init 0 */ - - /* USER CODE END ADC1_Init 0 */ - - LL_ADC_InitTypeDef ADC_InitStruct = {0}; - LL_ADC_REG_InitTypeDef ADC_REG_InitStruct = {0}; - LL_ADC_CommonInitTypeDef ADC_CommonInitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetADCClockSource(LL_RCC_ADC12_CLKSOURCE_SYSCLK); - - /* Peripheral clock enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_ADC12); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - /**ADC1 GPIO Configuration - PC1 ------> ADC1_IN7 - PC2 ------> ADC1_IN8 - PC3 ------> ADC1_IN9 - PB0 ------> ADC1_IN15 - PB1 ------> ADC1_IN12 - PB14 ------> ADC1_IN5 - */ - GPIO_InitStruct.Pin = BSPD_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BSPD_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = APPS1_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(APPS1_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = APPS2_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(APPS2_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = BRAKE_F_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_F_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = BRAKE_R_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_R_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = AUX_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AUX_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - /* ADC1 DMA Init */ - - /* ADC1 Init */ - LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_1, LL_DMAMUX_REQ_ADC1); - - LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_1, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); - - LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PRIORITY_LOW); - - LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_CIRCULAR); - - LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PERIPH_NOINCREMENT); - - LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT); - - LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_HALFWORD); - - LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_HALFWORD); - - /* USER CODE BEGIN ADC1_Init 1 */ - - /* USER CODE END ADC1_Init 1 */ - - /** Common config - */ - ADC_InitStruct.Resolution = LL_ADC_RESOLUTION_12B; - ADC_InitStruct.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT; - ADC_InitStruct.LowPowerMode = LL_ADC_LP_MODE_NONE; - LL_ADC_Init(ADC1, &ADC_InitStruct); - ADC_REG_InitStruct.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE; - ADC_REG_InitStruct.SequencerLength = LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS; - ADC_REG_InitStruct.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE; - ADC_REG_InitStruct.ContinuousMode = LL_ADC_REG_CONV_CONTINUOUS; - ADC_REG_InitStruct.DMATransfer = LL_ADC_REG_DMA_TRANSFER_UNLIMITED; - ADC_REG_InitStruct.Overrun = LL_ADC_REG_OVR_DATA_PRESERVED; - LL_ADC_REG_Init(ADC1, &ADC_REG_InitStruct); - LL_ADC_SetGainCompensation(ADC1, 0); - LL_ADC_SetOverSamplingScope(ADC1, LL_ADC_OVS_DISABLE); - ADC_CommonInitStruct.CommonClock = LL_ADC_CLOCK_ASYNC_DIV256; - ADC_CommonInitStruct.Multimode = LL_ADC_MULTI_INDEPENDENT; - LL_ADC_CommonInit(__LL_ADC_COMMON_INSTANCE(ADC1), &ADC_CommonInitStruct); - - /* Disable ADC deep power down (enabled by default after reset state) */ - LL_ADC_DisableDeepPowerDown(ADC1); - /* Enable ADC internal voltage regulator */ - LL_ADC_EnableInternalRegulator(ADC1); - /* Delay for ADC internal voltage regulator stabilization. */ - /* Compute number of CPU cycles to wait for, from delay in us. */ - /* Note: Variable divided by 2 to compensate partially */ - /* CPU processing cycles (depends on compilation optimization). */ - /* Note: If system core clock frequency is below 200kHz, wait time */ - /* is only a few CPU processing cycles. */ - uint32_t wait_loop_index; - wait_loop_index = ((LL_ADC_DELAY_INTERNAL_REGUL_STAB_US * (SystemCoreClock / (100000 * 2))) / 10); - while (wait_loop_index != 0) { - wait_loop_index--; - } - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_5); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_5, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_5, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_2, LL_ADC_CHANNEL_7); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_7, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_7, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_3, LL_ADC_CHANNEL_8); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_8, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_8, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_4, LL_ADC_CHANNEL_9); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_9, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_9, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_5, LL_ADC_CHANNEL_12); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_12, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_12, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_6, LL_ADC_CHANNEL_15); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_15, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_15, LL_ADC_SINGLE_ENDED); - /* USER CODE BEGIN ADC1_Init 2 */ - - /* USER CODE END ADC1_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4ADCTESTING/Core/Src/crc.c b/G4ADCTESTING/Core/Src/crc.c deleted file mode 100644 index 213510a5d..000000000 --- a/G4ADCTESTING/Core/Src/crc.c +++ /dev/null @@ -1,86 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file crc.c - * @brief This file provides code for the configuration - * of the CRC instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "crc.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -CRC_HandleTypeDef hcrc; - -/* CRC init function */ -void MX_CRC_Init(void) -{ - - /* USER CODE BEGIN CRC_Init 0 */ - - /* USER CODE END CRC_Init 0 */ - - /* USER CODE BEGIN CRC_Init 1 */ - - /* USER CODE END CRC_Init 1 */ - hcrc.Instance = CRC; - hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE; - hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE; - hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE; - hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE; - hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES; - if (HAL_CRC_Init(&hcrc) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN CRC_Init 2 */ - - /* USER CODE END CRC_Init 2 */ -} - -void HAL_CRC_MspInit(CRC_HandleTypeDef *crcHandle) -{ - - if (crcHandle->Instance == CRC) { - /* USER CODE BEGIN CRC_MspInit 0 */ - - /* USER CODE END CRC_MspInit 0 */ - /* CRC clock enable */ - __HAL_RCC_CRC_CLK_ENABLE(); - /* USER CODE BEGIN CRC_MspInit 1 */ - - /* USER CODE END CRC_MspInit 1 */ - } -} - -void HAL_CRC_MspDeInit(CRC_HandleTypeDef *crcHandle) -{ - - if (crcHandle->Instance == CRC) { - /* USER CODE BEGIN CRC_MspDeInit 0 */ - - /* USER CODE END CRC_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_CRC_CLK_DISABLE(); - /* USER CODE BEGIN CRC_MspDeInit 1 */ - - /* USER CODE END CRC_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4ADCTESTING/Core/Src/dma.c b/G4ADCTESTING/Core/Src/dma.c deleted file mode 100644 index 491e3889d..000000000 --- a/G4ADCTESTING/Core/Src/dma.c +++ /dev/null @@ -1,50 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file dma.c - * @brief This file provides code for the configuration - * of all the requested memory to memory DMA transfers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "dma.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure DMA */ -/*----------------------------------------------------------------------------*/ - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** - * Enable DMA controller clock - */ -void MX_DMA_Init(void) -{ - - /* Init with LL driver */ - /* DMA controller clock enable */ - LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMAMUX1); - LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1); -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ diff --git a/G4ADCTESTING/Core/Src/fdcan.c b/G4ADCTESTING/Core/Src/fdcan.c deleted file mode 100644 index f39dbfa2b..000000000 --- a/G4ADCTESTING/Core/Src/fdcan.c +++ /dev/null @@ -1,133 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file fdcan.c - * @brief This file provides code for the configuration - * of the FDCAN instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "fdcan.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -FDCAN_HandleTypeDef hfdcan2; - -/* FDCAN2 init function */ -void MX_FDCAN2_Init(void) -{ - - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_NORMAL; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ -} - -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) -{ - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - __HAL_RCC_FDCAN_CLK_ENABLE(); - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = 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_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } -} - -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) -{ - - if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_FDCAN_CLK_DISABLE(); - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4ADCTESTING/Core/Src/gpio.c b/G4ADCTESTING/Core/Src/gpio.c deleted file mode 100644 index d36e6eca6..000000000 --- a/G4ADCTESTING/Core/Src/gpio.c +++ /dev/null @@ -1,260 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file gpio.c - * @brief This file provides code for the configuration - * of all used GPIO pins. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "gpio.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure GPIO */ -/*----------------------------------------------------------------------------*/ -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is - enabled through - * the Code Generation settings) - PA6 ------> ADC2_IN3 - PA7 ------> ADC2_IN4 - PB15 ------> ADC2_IN15 - PB7 ------> UART4_CTS -*/ -void MX_GPIO_Init(void) -{ - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(BLINKY_GPIO_Port, BLINKY_Pin); - - /**/ - LL_GPIO_ResetOutputPin(LED_TEST_GPIO_Port, LED_TEST_Pin); - - /**/ - LL_GPIO_ResetOutputPin(BRAKE_LIGHT_GPIO_Port, BRAKE_LIGHT_Pin); - - /**/ - LL_GPIO_ResetOutputPin(TSSI_G_CONTROL_GPIO_Port, TSSI_G_CONTROL_Pin); - - /**/ - LL_GPIO_ResetOutputPin(AUX_CONTROL_GPIO_Port, AUX_CONTROL_Pin); - - /**/ - LL_GPIO_ResetOutputPin(SOFTWARE_OK_CONTROL_GPIO_Port, SOFTWARE_OK_CONTROL_Pin); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_13; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = BLINKY_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BLINKY_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = IMD_SENSE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(IMD_SENSE_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = AMS_SENSE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AMS_SENSE_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LED_TEST_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(LED_TEST_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = STEERING_ANGLE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(STEERING_ANGLE_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = BRAKE_LIGHT_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_LIGHT_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = TSSI_G_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(TSSI_G_CONTROL_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_14; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = AUX_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AUX_CONTROL_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = SOFTWARE_OK_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(SOFTWARE_OK_CONTROL_GPIO_Port, &GPIO_InitStruct); -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ diff --git a/G4ADCTESTING/Core/Src/i2c.c b/G4ADCTESTING/Core/Src/i2c.c deleted file mode 100644 index bfb4e0153..000000000 --- a/G4ADCTESTING/Core/Src/i2c.c +++ /dev/null @@ -1,92 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file i2c.c - * @brief This file provides code for the configuration - * of the I2C instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "i2c.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* I2C2 init function */ -void MX_I2C2_Init(void) -{ - - /* USER CODE BEGIN I2C2_Init 0 */ - - /* USER CODE END I2C2_Init 0 */ - - LL_I2C_InitTypeDef I2C_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetI2CClockSource(LL_RCC_I2C2_CLKSOURCE_PCLK1); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - /**I2C2 GPIO Configuration - PC4 ------> I2C2_SCL - PA8 ------> I2C2_SDA - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_4; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_4; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C2); - - /* USER CODE BEGIN I2C2_Init 1 */ - - /* USER CODE END I2C2_Init 1 */ - - /** I2C Initialization - */ - I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; - I2C_InitStruct.Timing = 0x30D29DE4; - I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE; - I2C_InitStruct.DigitalFilter = 0; - I2C_InitStruct.OwnAddress1 = 0; - I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK; - I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT; - LL_I2C_Init(I2C2, &I2C_InitStruct); - LL_I2C_EnableAutoEndMode(I2C2); - LL_I2C_SetOwnAddress2(I2C2, 0, LL_I2C_OWNADDRESS2_NOMASK); - LL_I2C_DisableOwnAddress2(I2C2); - LL_I2C_DisableGeneralCall(I2C2); - LL_I2C_EnableClockStretching(I2C2); - /* USER CODE BEGIN I2C2_Init 2 */ - - /* USER CODE END I2C2_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4ADCTESTING/Core/Src/main.c b/G4ADCTESTING/Core/Src/main.c deleted file mode 100644 index 5b3a492dc..000000000 --- a/G4ADCTESTING/Core/Src/main.c +++ /dev/null @@ -1,276 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "Logomatic.h" -#include "adc.h" -#include "dma.h" -#include "fdcan.h" -#include "gpio.h" -#include "gr_adc.h" -#include "i2c.h" -#include "malloc.h" -#include "spi.h" -#include "tim.h" -#include "usart.h" -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* 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 -----------------------------------------------*/ -void SystemClock_Config(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ -#define WINDOW_SIZE 10 // weighted average for now can extend to other window functions -#define NUM_SIGNALS 1 -volatile uint16_t buffers[NUM_SIGNALS] = {0}; // Contains new values -uint16_t outputs[NUM_SIGNALS] = {0}; // Updated averages -uint16_t *adcDataValues[NUM_SIGNALS] = {0}; -// Flag raised with DMA finishes transfer -volatile uint8_t DMA_Transfer_Complete = 0; - -/* Enable ITM for SWO output */ -static void ITM_Enable(void) -{ - /* Enable TRC (Trace) */ - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; - - /* Enable stimulus port 0 */ - ITM->TER |= (1UL << 0); - - /* Set trace control register */ - ITM->TCR |= ITM_TCR_ITMENA_Msk; -} - -/* USER CODE BEGIN 0 */ -void ADC_Configure(void) -{ - // Initialize which clock source to use - LL_RCC_SetADCClockSource(LL_RCC_ADC12_CLKSOURCE_SYSCLK); - /* Peripheral clock enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_ADC12); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - - ADC_Init_Values init_vals = {0}; - init_vals.ADC = ADC1; - init_vals.PS_Value = PS_8; - init_vals.Res = RESOLUTION_12; - init_vals.Num_Pin_Port_Objs = 1; - Pin_Ports p = {LL_GPIO_PIN_0, GPIOA}; - init_vals.Pins = &p; - init_vals.Num_Channels = 1; - Channel c = ADC_CHANNEL_1; - init_vals.Channels = &c; - SamplingTime s = SAMPLINGTIME_247CYCLES_5; - init_vals.SamplingTimes = &s; - ADC_Init(&init_vals); - - // Initialize DMA - DMA_Init_Values DMA_Init_Vals = {0}; - DMA_Init_Vals.DMA = DMA1; - DMA_Init_Vals.ADC = ADC1; - DMA_Init_Vals.Channel = DMA_CHANNEL_1; - DMA_Init_Vals.Src_Address = LL_ADC_DMA_GetRegAddr(ADC1, LL_ADC_DMA_REG_REGULAR_DATA); - DMA_Init_Vals.Dest_Address = &buffers; - DMA_Init_Vals.Data_Size = Word; - DMA_Init_Vals.Priority = LOW; - DMA_Init(&DMA_Init_Vals); - LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1); - - ADC_Enable_And_Calibrate(ADC1); -} -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU - * Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the - * Systick. */ - HAL_Init(); - - /* USER CODE BEGIN Init */ - ITM_Enable(); - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); - MX_FDCAN2_Init(); - MX_ADC1_Init(); - MX_LPUART1_UART_Init(); - MX_I2C2_Init(); - MX_USART1_UART_Init(); - MX_SPI3_Init(); - MX_TIM2_Init(); - /* USER CODE BEGIN 2 */ - ADC_Configure(); - /* USER CODE END 2 */ - adcDataValues[0] = malloc(sizeof(uint16_t) * WINDOW_SIZE); - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) { - /* USER CODE END WHILE */ - - // BLINKY - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET); - HAL_Delay(50); - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET); - HAL_Delay(50); - - /* USER CODE BEGIN 3 */ - LOGOMATIC("Buffer Value: %u\n", buffers[0]); - // ADC_UpdateAnalogValues(adcDataValues, buffers, NUM_SIGNALS, WINDOW_SIZE, outputs); - ADC_UpdateAnalogValues_EMA(buffers, NUM_SIGNALS, 0.3, outputs); - LOGOMATIC("Moving Average: %u\n", outputs[0]); - DMA_Transfer_Complete = 0; - // just test 1 pin for now - if (DMA_Transfer_Complete) {} - } - - free(adcDataValues[0]); -} - -void DMA1_Channel1_IRQHandler(void) -{ - if (LL_DMA_IsActiveFlag_TC1(DMA1)) { - LL_DMA_ClearFlag_TC1(DMA1); - DMA_Transfer_Complete = 1; // notify main loop - } -} - -/** - * @brief System Clock Configuration - * @retval None - */ -void SystemClock_Config(void) -{ - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(170000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return - * state */ - __disable_irq(); - while (1) {} - /* USER CODE END Error_Handler_Debug */ -} -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line - number, ex: printf("Wrong parameters value: file %s on line %d\r\n", - file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ diff --git a/G4ADCTESTING/Core/Src/spi.c b/G4ADCTESTING/Core/Src/spi.c deleted file mode 100644 index 66459f2ec..000000000 --- a/G4ADCTESTING/Core/Src/spi.c +++ /dev/null @@ -1,95 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file spi.c - * @brief This file provides code for the configuration - * of the SPI instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "spi.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* SPI3 init function */ -void MX_SPI3_Init(void) -{ - - /* USER CODE BEGIN SPI3_Init 0 */ - - /* USER CODE END SPI3_Init 0 */ - - LL_SPI_InitTypeDef SPI_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI3); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - /**SPI3 GPIO Configuration - PC10 ------> SPI3_SCK - PC11 ------> SPI3_MISO - PC12 ------> SPI3_MOSI - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_6; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_6; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_6; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN SPI3_Init 1 */ - - /* USER CODE END SPI3_Init 1 */ - SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; - SPI_InitStruct.Mode = LL_SPI_MODE_MASTER; - SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_4BIT; - SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; - SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE; - SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; - SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV32; - SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST; - SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; - SPI_InitStruct.CRCPoly = 7; - LL_SPI_Init(SPI3, &SPI_InitStruct); - LL_SPI_SetStandard(SPI3, LL_SPI_PROTOCOL_MOTOROLA); - LL_SPI_EnableNSSPulseMgt(SPI3); - /* USER CODE BEGIN SPI3_Init 2 */ - - /* USER CODE END SPI3_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4ADCTESTING/Core/Src/stm32g4xx_hal_msp.c b/G4ADCTESTING/Core/Src/stm32g4xx_hal_msp.c deleted file mode 100644 index 69189ef4e..000000000 --- a/G4ADCTESTING/Core/Src/stm32g4xx_hal_msp.c +++ /dev/null @@ -1,86 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_msp.c - * @brief This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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*/ - - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); - - /* USER CODE BEGIN MspInit 1 */ - - /* USER CODE END MspInit 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4ADCTESTING/Core/Src/stm32g4xx_it.c b/G4ADCTESTING/Core/Src/stm32g4xx_it.c deleted file mode 100644 index 2f0cf90a7..000000000 --- a/G4ADCTESTING/Core/Src/stm32g4xx_it.c +++ /dev/null @@ -1,212 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "stm32g4xx_it.h" - -#include "main.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 --------------------------------------------------------*/ -extern FDCAN_HandleTypeDef hfdcan2; -/* 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 Prefetch 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 */ -} - -/******************************************************************************/ -/* STM32G4xx 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_stm32g4xx.s). */ -/******************************************************************************/ - -/** - * @brief This function handles FDCAN2 interrupt 0. - */ -void FDCAN2_IT0_IRQHandler(void) -{ - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - - /* USER CODE END FDCAN2_IT0_IRQn 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4ADCTESTING/Core/Src/tim.c b/G4ADCTESTING/Core/Src/tim.c deleted file mode 100644 index 7f521c3bf..000000000 --- a/G4ADCTESTING/Core/Src/tim.c +++ /dev/null @@ -1,79 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file tim.c - * @brief This file provides code for the configuration - * of the TIM instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "tim.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* TIM2 init function */ -void MX_TIM2_Init(void) -{ - - /* USER CODE BEGIN TIM2_Init 0 */ - - /* USER CODE END TIM2_Init 0 */ - - LL_TIM_InitTypeDef TIM_InitStruct = {0}; - LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2); - - /* USER CODE BEGIN TIM2_Init 1 */ - - /* USER CODE END TIM2_Init 1 */ - TIM_InitStruct.Prescaler = 0; - TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; - TIM_InitStruct.Autoreload = 4294967295; - TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; - LL_TIM_Init(TIM2, &TIM_InitStruct); - LL_TIM_DisableARRPreload(TIM2); - LL_TIM_SetClockSource(TIM2, LL_TIM_CLOCKSOURCE_INTERNAL); - TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_FORCED_ACTIVE; - TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; - TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; - TIM_OC_InitStruct.CompareValue = 0; - TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; - LL_TIM_OC_Init(TIM2, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct); - LL_TIM_OC_DisableFast(TIM2, LL_TIM_CHANNEL_CH1); - LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_RESET); - LL_TIM_DisableMasterSlaveMode(TIM2); - /* USER CODE BEGIN TIM2_Init 2 */ - - /* USER CODE END TIM2_Init 2 */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - /**TIM2 GPIO Configuration - PA0 ------> TIM2_CH1 - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_1; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4ADCTESTING/Core/Src/usart.c b/G4ADCTESTING/Core/Src/usart.c deleted file mode 100644 index 56a3fa98f..000000000 --- a/G4ADCTESTING/Core/Src/usart.c +++ /dev/null @@ -1,184 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file usart.c - * @brief This file provides code for the configuration - * of the USART instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "usart.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* LPUART1 init function */ - -void MX_LPUART1_UART_Init(void) -{ - - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - LL_LPUART_InitTypeDef LPUART_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* Peripheral clock enable */ - LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_LPUART1); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_12; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_12; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - LPUART_InitStruct.PrescalerValue = LL_LPUART_PRESCALER_DIV1; - LPUART_InitStruct.BaudRate = 115200; - LPUART_InitStruct.DataWidth = LL_LPUART_DATAWIDTH_8B; - LPUART_InitStruct.StopBits = LL_LPUART_STOPBITS_1; - LPUART_InitStruct.Parity = LL_LPUART_PARITY_NONE; - LPUART_InitStruct.TransferDirection = LL_LPUART_DIRECTION_TX_RX; - LPUART_InitStruct.HardwareFlowControl = LL_LPUART_HWCONTROL_NONE; - LL_LPUART_Init(LPUART1, &LPUART_InitStruct); - LL_LPUART_SetTXFIFOThreshold(LPUART1, LL_LPUART_FIFOTHRESHOLD_1_8); - LL_LPUART_SetRXFIFOThreshold(LPUART1, LL_LPUART_FIFOTHRESHOLD_1_8); - LL_LPUART_DisableFIFO(LPUART1); - - /* USER CODE BEGIN WKUPType LPUART1 */ - - /* USER CODE END WKUPType LPUART1 */ - - LL_LPUART_Enable(LPUART1); - - /* Polling LPUART1 initialisation */ - while ((!(LL_LPUART_IsActiveFlag_TEACK(LPUART1))) || (!(LL_LPUART_IsActiveFlag_REACK(LPUART1)))) {} - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ -} -/* USART1 init function */ - -void MX_USART1_UART_Init(void) -{ - - /* USER CODE BEGIN USART1_Init 0 */ - - /* USER CODE END USART1_Init 0 */ - - LL_USART_InitTypeDef USART_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2); - - /* Peripheral clock enable */ - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - /**USART1 GPIO Configuration - PC5 ------> USART1_RX - PA11 ------> USART1_CTS - PA12 ------> USART1_RTS - PB6 ------> USART1_TX - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* USER CODE BEGIN USART1_Init 1 */ - - /* USER CODE END USART1_Init 1 */ - USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1; - USART_InitStruct.BaudRate = 115200; - USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; - USART_InitStruct.StopBits = LL_USART_STOPBITS_1; - USART_InitStruct.Parity = LL_USART_PARITY_NONE; - USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX; - USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_RTS_CTS; - USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16; - LL_USART_Init(USART1, &USART_InitStruct); - LL_USART_SetTXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8); - LL_USART_SetRXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8); - LL_USART_DisableFIFO(USART1); - LL_USART_ConfigAsyncMode(USART1); - - /* USER CODE BEGIN WKUPType USART1 */ - - /* USER CODE END WKUPType USART1 */ - - LL_USART_Enable(USART1); - - /* Polling USART1 initialisation */ - while ((!(LL_USART_IsActiveFlag_TEACK(USART1))) || (!(LL_USART_IsActiveFlag_REACK(USART1)))) {} - /* USER CODE BEGIN USART1_Init 2 */ - - /* USER CODE END USART1_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4ADCTESTING/G4PERTESTING.ioc b/G4ADCTESTING/G4PERTESTING.ioc deleted file mode 100644 index 8cf1860b1..000000000 --- a/G4ADCTESTING/G4PERTESTING.ioc +++ /dev/null @@ -1,382 +0,0 @@ -#MicroXplorer Configuration settings - do not modify -ADC1.Channel-2\#ChannelRegularConversion=ADC_CHANNEL_5 -ADC1.Channel-3\#ChannelRegularConversion=ADC_CHANNEL_7 -ADC1.Channel-4\#ChannelRegularConversion=ADC_CHANNEL_8 -ADC1.Channel-5\#ChannelRegularConversion=ADC_CHANNEL_9 -ADC1.Channel-6\#ChannelRegularConversion=ADC_CHANNEL_12 -ADC1.Channel-7\#ChannelRegularConversion=ADC_CHANNEL_15 -ADC1.ClockPrescaler=ADC_CLOCK_ASYNC_DIV256 -ADC1.CommonPathInternal=null|null|null|null -ADC1.ContinuousConvMode=ENABLE -ADC1.DMAContinuousRequests=ENABLE -ADC1.EOCSelection=ADC_EOC_SEQ_CONV -ADC1.ExternalTrigConv=ADC_SOFTWARE_START -ADC1.IPParameters=Rank-2\#ChannelRegularConversion,Channel-2\#ChannelRegularConversion,SamplingTime-2\#ChannelRegularConversion,OffsetNumber-2\#ChannelRegularConversion,NbrOfConversionFlag,master,Rank-3\#ChannelRegularConversion,Channel-3\#ChannelRegularConversion,SamplingTime-3\#ChannelRegularConversion,OffsetNumber-3\#ChannelRegularConversion,Rank-4\#ChannelRegularConversion,Channel-4\#ChannelRegularConversion,SamplingTime-4\#ChannelRegularConversion,OffsetNumber-4\#ChannelRegularConversion,Rank-5\#ChannelRegularConversion,Channel-5\#ChannelRegularConversion,SamplingTime-5\#ChannelRegularConversion,OffsetNumber-5\#ChannelRegularConversion,Rank-6\#ChannelRegularConversion,Channel-6\#ChannelRegularConversion,SamplingTime-6\#ChannelRegularConversion,OffsetNumber-6\#ChannelRegularConversion,Rank-7\#ChannelRegularConversion,Channel-7\#ChannelRegularConversion,SamplingTime-7\#ChannelRegularConversion,OffsetNumber-7\#ChannelRegularConversion,NbrOfConversion,ContinuousConvMode,DMAContinuousRequests,ClockPrescaler,EOCSelection,ExternalTrigConv,CommonPathInternal -ADC1.NbrOfConversion=6 -ADC1.NbrOfConversionFlag=1 -ADC1.OffsetNumber-2\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-3\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-4\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-5\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-6\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-7\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.Rank-2\#ChannelRegularConversion=1 -ADC1.Rank-3\#ChannelRegularConversion=2 -ADC1.Rank-4\#ChannelRegularConversion=3 -ADC1.Rank-5\#ChannelRegularConversion=4 -ADC1.Rank-6\#ChannelRegularConversion=5 -ADC1.Rank-7\#ChannelRegularConversion=6 -ADC1.SamplingTime-2\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-3\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-4\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-5\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-6\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-7\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.master=1 -CAD.formats=[] -CAD.pinconfig=Dual -CAD.provider= -Dma.ADC1.0.Direction=DMA_PERIPH_TO_MEMORY -Dma.ADC1.0.EventEnable=DISABLE -Dma.ADC1.0.Instance=DMA1_Channel1 -Dma.ADC1.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD -Dma.ADC1.0.MemInc=DMA_MINC_ENABLE -Dma.ADC1.0.Mode=DMA_CIRCULAR -Dma.ADC1.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD -Dma.ADC1.0.PeriphInc=DMA_PINC_DISABLE -Dma.ADC1.0.Polarity=HAL_DMAMUX_REQ_GEN_RISING -Dma.ADC1.0.Priority=DMA_PRIORITY_LOW -Dma.ADC1.0.RequestNumber=1 -Dma.ADC1.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber -Dma.ADC1.0.SignalID=NONE -Dma.ADC1.0.SyncEnable=DISABLE -Dma.ADC1.0.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT -Dma.ADC1.0.SyncRequestNumber=1 -Dma.ADC1.0.SyncSignalID=NONE -Dma.Request0=ADC1 -Dma.RequestsNb=1 -FDCAN2.AutoRetransmission=ENABLE -FDCAN2.CalculateBaudRateNominal=1000000 -FDCAN2.CalculateTimeBitNominal=1000 -FDCAN2.CalculateTimeQuantumNominal=6.25 -FDCAN2.DataPrescaler=8 -FDCAN2.DataSyncJumpWidth=16 -FDCAN2.DataTimeSeg1=14 -FDCAN2.DataTimeSeg2=5 -FDCAN2.ExtFiltersNbr=2 -FDCAN2.FrameFormat=FDCAN_FRAME_CLASSIC -FDCAN2.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal,FrameFormat,NominalTimeSeg1,NominalTimeSeg2,NominalPrescaler,AutoRetransmission,StdFiltersNbr,TransmitPause,NominalSyncJumpWidth,DataTimeSeg1,DataTimeSeg2,DataPrescaler,DataSyncJumpWidth,ExtFiltersNbr,ProtocolException -FDCAN2.NominalPrescaler=1 -FDCAN2.NominalSyncJumpWidth=16 -FDCAN2.NominalTimeSeg1=119 -FDCAN2.NominalTimeSeg2=40 -FDCAN2.ProtocolException=ENABLE -FDCAN2.StdFiltersNbr=0 -FDCAN2.TransmitPause=DISABLE -File.Version=6 -GPIO.groupedBy=Group By Peripherals -I2C2.IPParameters=Timing -I2C2.Timing=0x30D29DE4 -KeepUserPlacement=false -LPUART1.BaudRate=115200 -LPUART1.IPParameters=BaudRate -Mcu.CPN=STM32G474RET6 -Mcu.Family=STM32G4 -Mcu.IP0=ADC1 -Mcu.IP1=DMA -Mcu.IP10=USART1 -Mcu.IP2=FDCAN2 -Mcu.IP3=I2C2 -Mcu.IP4=LPUART1 -Mcu.IP5=NVIC -Mcu.IP6=RCC -Mcu.IP7=SPI3 -Mcu.IP8=SYS -Mcu.IP9=TIM2 -Mcu.IPNb=11 -Mcu.Name=STM32G474R(B-C-E)Tx -Mcu.Package=LQFP64 -Mcu.Pin0=PF0-OSC_IN -Mcu.Pin1=PF1-OSC_OUT -Mcu.Pin10=PA7 -Mcu.Pin11=PC4 -Mcu.Pin12=PC5 -Mcu.Pin13=PB0 -Mcu.Pin14=PB1 -Mcu.Pin15=PB11 -Mcu.Pin16=PB12 -Mcu.Pin17=PB13 -Mcu.Pin18=PB14 -Mcu.Pin19=PB15 -Mcu.Pin2=PC1 -Mcu.Pin20=PA8 -Mcu.Pin21=PA11 -Mcu.Pin22=PA12 -Mcu.Pin23=PA13 -Mcu.Pin24=PA14 -Mcu.Pin25=PC10 -Mcu.Pin26=PC11 -Mcu.Pin27=PC12 -Mcu.Pin28=PB3 -Mcu.Pin29=PB4 -Mcu.Pin3=PC2 -Mcu.Pin30=PB5 -Mcu.Pin31=PB6 -Mcu.Pin32=PB7 -Mcu.Pin33=PB8-BOOT0 -Mcu.Pin34=PB9 -Mcu.Pin35=VP_SYS_VS_Systick -Mcu.Pin36=VP_SYS_VS_DBSignals -Mcu.Pin37=VP_TIM2_VS_ClockSourceINT -Mcu.Pin4=PC3 -Mcu.Pin5=PA0 -Mcu.Pin6=PA2 -Mcu.Pin7=PA3 -Mcu.Pin8=PA5 -Mcu.Pin9=PA6 -Mcu.PinsNb=38 -Mcu.ThirdPartyNb=0 -Mcu.UserConstants= -Mcu.UserName=STM32G474RETx -MxCube.Version=6.15.0 -MxDb.Version=DB.6.0.150 -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.FDCAN2_IT0_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true -NVIC.ForceEnableDMAVector=false -NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:false -NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 -NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false -NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -PA0.Signal=S_TIM2_CH1 -PA11.Locked=true -PA11.Mode=CTS_RTS -PA11.Signal=USART1_CTS -PA12.Locked=true -PA12.Mode=CTS_RTS -PA12.Signal=USART1_RTS -PA13.Locked=true -PA13.Mode=Trace_Asynchronous_SW -PA13.Signal=SYS_JTMS-SWDIO -PA14.Locked=true -PA14.Mode=Trace_Asynchronous_SW -PA14.Signal=SYS_JTCK-SWCLK -PA2.GPIOParameters=GPIO_Speed -PA2.GPIO_Speed=GPIO_SPEED_FREQ_HIGH -PA2.Locked=true -PA2.Mode=Asynchronous -PA2.Signal=LPUART1_TX -PA3.GPIOParameters=GPIO_Speed -PA3.GPIO_Speed=GPIO_SPEED_FREQ_HIGH -PA3.Locked=true -PA3.Mode=Asynchronous -PA3.Signal=LPUART1_RX -PA5.GPIOParameters=GPIO_Label -PA5.GPIO_Label=BLINKY -PA5.Locked=true -PA5.Signal=GPIO_Output -PA6.GPIOParameters=GPIO_Label -PA6.GPIO_Label=IMD_SENSE -PA6.Locked=true -PA6.Signal=ADC2_IN3 -PA7.GPIOParameters=GPIO_Label -PA7.GPIO_Label=AMS_SENSE -PA7.Locked=true -PA7.Signal=ADC2_IN4 -PA8.Mode=I2C -PA8.Signal=I2C2_SDA -PB0.GPIOParameters=GPIO_Label -PB0.GPIO_Label=BRAKE_F_SIGNAL -PB0.Locked=true -PB0.Mode=IN15-Single-Ended -PB0.Signal=ADC1_IN15 -PB1.GPIOParameters=GPIO_Label -PB1.GPIO_Label=BRAKE_R_SIGNAL -PB1.Locked=true -PB1.Mode=IN12-Single-Ended -PB1.Signal=ADC1_IN12 -PB11.GPIOParameters=GPIO_Label -PB11.GPIO_Label=LED_TEST -PB11.Locked=true -PB11.Signal=GPIO_Output -PB12.GPIOParameters=GPIO_Speed,GPIO_PuPd -PB12.GPIO_PuPd=GPIO_PULLUP -PB12.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PB12.Locked=true -PB12.Mode=FDCAN_Activate -PB12.Signal=FDCAN2_RX -PB13.GPIOParameters=GPIO_Speed -PB13.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PB13.Locked=true -PB13.Mode=FDCAN_Activate -PB13.Signal=FDCAN2_TX -PB14.GPIOParameters=GPIO_Label -PB14.GPIO_Label=AUX_SIGNAL -PB14.Locked=true -PB14.Mode=IN5-Single-Ended -PB14.Signal=ADC1_IN5 -PB15.GPIOParameters=GPIO_Label -PB15.GPIO_Label=STEERING_ANGLE -PB15.Locked=true -PB15.Signal=ADC2_IN15 -PB3.Locked=true -PB3.Mode=Trace_Asynchronous_SW -PB3.Signal=SYS_JTDO-SWO -PB4.GPIOParameters=GPIO_Label -PB4.GPIO_Label=BRAKE_LIGHT -PB4.Locked=true -PB4.Signal=GPIO_Output -PB5.GPIOParameters=GPIO_Label -PB5.GPIO_Label=TSSI_G_CONTROL -PB5.Locked=true -PB5.Signal=GPIO_Output -PB6.Locked=true -PB6.Mode=Asynchronous -PB6.Signal=USART1_TX -PB7.Locked=true -PB7.Signal=UART4_CTS -PB8-BOOT0.GPIOParameters=GPIO_Label -PB8-BOOT0.GPIO_Label=AUX_CONTROL -PB8-BOOT0.Locked=true -PB8-BOOT0.Signal=GPIO_Output -PB9.GPIOParameters=GPIO_Label -PB9.GPIO_Label=SOFTWARE_OK_CONTROL -PB9.Locked=true -PB9.Signal=GPIO_Output -PC1.GPIOParameters=GPIO_Label -PC1.GPIO_Label=BSPD_SIGNAL -PC1.Locked=true -PC1.Mode=IN7-Single-Ended -PC1.Signal=ADC1_IN7 -PC10.Mode=Full_Duplex_Master -PC10.Signal=SPI3_SCK -PC11.Mode=Full_Duplex_Master -PC11.Signal=SPI3_MISO -PC12.Mode=Full_Duplex_Master -PC12.Signal=SPI3_MOSI -PC2.GPIOParameters=GPIO_Label -PC2.GPIO_Label=APPS1_SIGNAL -PC2.Locked=true -PC2.Mode=IN8-Single-Ended -PC2.Signal=ADC1_IN8 -PC3.GPIOParameters=GPIO_Label -PC3.GPIO_Label=APPS2_SIGNAL -PC3.Locked=true -PC3.Mode=IN9-Single-Ended -PC3.Signal=ADC1_IN9 -PC4.Mode=I2C -PC4.Signal=I2C2_SCL -PC5.Mode=Asynchronous -PC5.Signal=USART1_RX -PF0-OSC_IN.Locked=true -PF0-OSC_IN.Mode=HSE-External-Oscillator -PF0-OSC_IN.Signal=RCC_OSC_IN -PF1-OSC_OUT.Locked=true -PF1-OSC_OUT.Mode=HSE-External-Oscillator -PF1-OSC_OUT.Signal=RCC_OSC_OUT -PinOutPanel.RotationAngle=180 -ProjectManager.AskForMigrate=true -ProjectManager.BackupPrevious=false -ProjectManager.CompilerLinker=GCC -ProjectManager.CompilerOptimize=6 -ProjectManager.ComputerToolchain=false -ProjectManager.CoupleFile=true -ProjectManager.CustomerFirmwarePackage= -ProjectManager.DefaultFWLocation=true -ProjectManager.DeletePrevious=true -ProjectManager.DeviceId=STM32G474RETx -ProjectManager.FirmwarePackage=STM32Cube FW_G4 V1.6.1 -ProjectManager.FreePins=true -ProjectManager.HalAssertFull=false -ProjectManager.HeapSize=0x200 -ProjectManager.KeepUserCode=true -ProjectManager.LastFirmware=true -ProjectManager.LibraryCopy=0 -ProjectManager.MainLocation=Core/Src -ProjectManager.NoMain=false -ProjectManager.PreviousToolchain= -ProjectManager.ProjectBuild=false -ProjectManager.ProjectFileName=G4PERTESTING.ioc -ProjectManager.ProjectName=G4PERTESTING -ProjectManager.ProjectStructure= -ProjectManager.RegisterCallBack= -ProjectManager.StackSize=0x400 -ProjectManager.TargetToolchain=CMake -ProjectManager.ToolChainLocation= -ProjectManager.UAScriptAfterPath= -ProjectManager.UAScriptBeforePath= -ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_DMA_Init-DMA-false-LL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_ADC1_Init-ADC1-false-LL-true,6-MX_LPUART1_UART_Init-LPUART1-false-LL-true,7-MX_I2C2_Init-I2C2-false-LL-true,8-MX_USART1_UART_Init-USART1-false-LL-true,9-MX_SPI3_Init-SPI3-false-LL-true,10-MX_TIM2_Init-TIM2-false-LL-true -RCC.ADC12Freq_Value=160000000 -RCC.ADC345Freq_Value=160000000 -RCC.AHBFreq_Value=160000000 -RCC.APB1Freq_Value=160000000 -RCC.APB1TimFreq_Value=160000000 -RCC.APB2Freq_Value=160000000 -RCC.APB2TimFreq_Value=160000000 -RCC.CRSFreq_Value=48000000 -RCC.CortexFreq_Value=160000000 -RCC.EXTERNAL_CLOCK_VALUE=12288000 -RCC.EnbaleCSS=true -RCC.FCLKCortexFreq_Value=160000000 -RCC.FDCANFreq_Value=160000000 -RCC.FamilyName=M -RCC.HCLKFreq_Value=160000000 -RCC.HRTIM1Freq_Value=160000000 -RCC.HSE_VALUE=16000000 -RCC.HSI48_VALUE=48000000 -RCC.HSI_VALUE=16000000 -RCC.I2C1Freq_Value=160000000 -RCC.I2C2Freq_Value=160000000 -RCC.I2C3Freq_Value=160000000 -RCC.I2C4Freq_Value=160000000 -RCC.I2SFreq_Value=160000000 -RCC.IPParameters=ADC12Freq_Value,ADC345Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,EnbaleCSS,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HRTIM1Freq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PLLSourceVirtual,PWRFreq_Value,QSPIFreq_Value,RNGFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value -RCC.LPTIM1Freq_Value=160000000 -RCC.LPUART1Freq_Value=160000000 -RCC.LSCOPinFreq_Value=32000 -RCC.LSE_VALUE=32768 -RCC.LSI_VALUE=32000 -RCC.MCO1PinFreq_Value=16000000 -RCC.PLLN=20 -RCC.PLLPoutputFreq_Value=160000000 -RCC.PLLQoutputFreq_Value=160000000 -RCC.PLLRCLKFreq_Value=160000000 -RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE -RCC.PWRFreq_Value=160000000 -RCC.QSPIFreq_Value=160000000 -RCC.RNGFreq_Value=160000000 -RCC.SAI1Freq_Value=160000000 -RCC.SYSCLKFreq_VALUE=160000000 -RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK -RCC.UART4Freq_Value=160000000 -RCC.UART5Freq_Value=160000000 -RCC.USART1Freq_Value=160000000 -RCC.USART2Freq_Value=160000000 -RCC.USART3Freq_Value=160000000 -RCC.USBFreq_Value=160000000 -RCC.VCOInputFreq_Value=16000000 -RCC.VCOOutputFreq_Value=320000000 -SH.S_TIM2_CH1.0=TIM2_CH1,Forced Output1 CH1 -SH.S_TIM2_CH1.ConfNb=1 -SPI3.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_32 -SPI3.CalculateBaudRate=5.0 MBits/s -SPI3.Direction=SPI_DIRECTION_2LINES -SPI3.IPParameters=VirtualType,Mode,Direction,BaudRatePrescaler,CalculateBaudRate -SPI3.Mode=SPI_MODE_MASTER -SPI3.VirtualType=VM_MASTER -TIM2.Channel-Forced\ Output1\ CH1=TIM_CHANNEL_1 -TIM2.IPParameters=Channel-Forced Output1 CH1 -USART1.IPParameters=VirtualMode-Asynchronous -USART1.VirtualMode-Asynchronous=VM_ASYNC -VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals -VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick -VP_TIM2_VS_ClockSourceINT.Mode=Internal -VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT -board=custom diff --git a/G4ADCTESTING/README.md b/G4ADCTESTING/README.md deleted file mode 100644 index 79c0032d8..000000000 --- a/G4ADCTESTING/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# STM32G474 Blinky -Nucleo-G474RE-C04 - -Plug in the board following ST-LINK pinout -Compile and flash G4PERTESTING.elf diff --git a/G4FANCYCANTESTING/CAN_LOOPBACK_TEST/CMakeLists.txt b/G4FANCYCANTESTING/CAN_LOOPBACK_TEST/CMakeLists.txt deleted file mode 100644 index c7ecb6fa4..000000000 --- a/G4FANCYCANTESTING/CAN_LOOPBACK_TEST/CMakeLists.txt +++ /dev/null @@ -1,61 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -# Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) - -# Define the build type -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug") -endif() - -# Enable compile command to ease indexing with e.g. clangd -set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) - -# Enable CMake support for ASM and C languages -enable_language( - C - ASM -) - -# Core project settings -project(${CMAKE_PROJECT_NAME}) - -# what, does in fact not get the filename of somthing but rather the name of the project from the path -get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) - -add_library(${PROJECT_NAME}_USER_CODE INTERFACE) - -target_sources( - ${PROJECT_NAME}_USER_CODE - INTERFACE - ../Core/Src/adc.c - ../Core/Src/crc.c - ../Core/Src/dma.c - ../Core/Src/gpio.c - ../Core/Src/i2c.c - main.c - ../Core/Src/spi.c - ../Core/Src/stm32g4xx_hal_msp.c - ../Core/Src/stm32g4xx_it.c - ../Core/Src/tim.c - ../Core/Src/usart.c - ../Core/Src/FancyCAN_LoopbackTest.c -) - -set_target_properties( - ${NAME} - PROPERTIES - OUTPUT_NAME - "CAN_${NAME}" -) - -target_link_libraries( - ${PROJECT_NAME}_USER_CODE - INTERFACE - GRCAN_FANCYLAYER - LOGOMATIC_OLD_LIB -) - -target_include_directories(${PROJECT_NAME}_USER_CODE INTERFACE ../Core/Inc) diff --git a/G4FANCYCANTESTING/CAN_LOOPBACK_TEST/main.c b/G4FANCYCANTESTING/CAN_LOOPBACK_TEST/main.c deleted file mode 100644 index 739003d67..000000000 --- a/G4FANCYCANTESTING/CAN_LOOPBACK_TEST/main.c +++ /dev/null @@ -1,305 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "adc.h" -#include "can.h" // Assume this works -#include "can_tests.h" -#include "dma.h" -#include "gpio.h" -#include "i2c.h" -#include "spi.h" -#include "tim.h" -#include "usart.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -#include "FancyCAN_LoopbackTest.h" -#include "GRCAN_FancyLayer.h" -#include "Logomatic.h" -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* 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 -----------------------------------------------*/ -void SystemClock_Config(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ -/* Enable ITM for SWO output */ -static void ITM_Enable(void) -{ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_0; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - DBGMCU->CR |= DBGMCU_CR_TRACE_IOEN; - - /* Enable TRC (Trace) */ - CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; - - /* Configure TPI for SWO output (set prescaler for 2MHz SWO clock) */ - TPI->SPPR = 2U; /* 2 = Manchester/async UART mode */ - TPI->ACPR = 84U; /* Prescaler: (170 MHz / (84+1) / 2) ≈ 1MHz SWO */ - - ITM->TER |= (1UL << 0); - ITM->TCR |= (ITM_TCR_ITMENA_Msk | ITM_TCR_SWOENA_Msk); -} - -LogomaticConfig logomaticConfig = {.clock_source = LOGOMATIC_PCLK1, - .bus = LOGOMATIC_BUS, - .gpio_port = LOGOMATIC_GPIOA, - .gpio_pin_rx_tx_mask = LL_GPIO_PIN_2 | LL_GPIO_PIN_3, - .baud_rate = 115200, - .data_width = LOGOMATIC_DATAWIDTH_8B, - .stop_bits = LOGOMATIC_STOPBITS_1, - .parity = LOGOMATIC_PARITY_NONE, - .transfer_direction = LOGOMATIC_DIRECTION_TX, - .hardware_flow_control = LOGOMATIC_HWCONTROL_NONE, - .prescaler = LOGOMATIC_PRESCALER_DIV1, - .tx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8, - .rx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8}; - -// static int toggleze = 0; -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU - * Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the - * Systick. */ - HAL_Init(); - /* USER CODE BEGIN Init */ - ITM_Enable(); - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); - // MX_FDCAN2_Init(); //might make own init for hfdcan for use for multiple hfdcan busses - MX_ADC1_Init(); - MX_LPUART1_UART_Init(); - MX_I2C2_Init(); - MX_USART1_UART_Init(); - MX_SPI3_Init(); - MX_TIM2_Init(); - - /* USER CODE BEGIN 2 */ - - Setup_Logomatic(&logomaticConfig); - - LOGOMATIC("Booted!\n"); - - HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); - HAL_Delay(200); - - // LOGOMATIC("running can_basic_test:\n"); - // can_basic_test(); - - int result = FancyCAN_LoopbackTest(); - LOGOMATIC("\n"); - if (result) { - LOGOMATIC("CAN Loopback Test PASSED!\n"); - } else { - LOGOMATIC("CAN Loopback Test FAILED!\n"); - } - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) { - /* USER CODE END WHILE */ - // LOGOMATIC("Main Loop\n"); - LL_mDelay(1000); - HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); - - // Receive on GPIOs - // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, toggleze ? GPIO_PIN_SET - // : GPIO_PIN_RESET); HAL_Delay(1000); msg.data[0] = toggleze ? - // 0x00 : 0x80; can_send(data_can, &msg); - - // RCC->CFGR |= RCC_CFGR_SW; - /* USER CODE BEGIN 3 */ - } -} - -/** - * @brief System Clock Configuration - * @retval None - */ - -// void SystemClock_Config(void) -// { -// LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); -// while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) { -// } -// LL_PWR_EnableRange1BoostMode(); -// LL_RCC_HSE_Enable(); - -// /* Wait till HSE is ready */ -// while (LL_RCC_HSE_IsReady() != 1) { -// } - -// LL_RCC_HSE_EnableCSS(); -// LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_1, 20, -// LL_RCC_PLLR_DIV_2); -// //LL_RCC_PLL_ConfigDomain_48M(LL_RCC_PLLSOURCE_HSE, ); -// LL_RCC_PLL_EnableDomain_SYS(); -// LL_RCC_PLL_Enable(); -// /* Wait till PLL is ready */ -// while (LL_RCC_PLL_IsReady() != 1) { -// } - -// LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); -// /* Wait till System clock is ready */ -// while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { -// } - -// /* Insure 1us transition state at intermediate medium speed clock*/ -// for (__IO uint32_t i = (170 >> 1); i != 0; i--) -// ; - -// /* Set AHB prescaler*/ -// LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); -// LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); -// LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); -// LL_SetSystemCoreClock(160000000); - -// /* Update the time base */ -// if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { -// Error_Handler(); -// } -// }*/ -void SystemClock_Config(void) -{ - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - // LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(170000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return - * state */ - __disable_irq(); - while (1) {} - /* USER CODE END Error_Handler_Debug */ -} -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line - number, ex: printf("Wrong parameters value: file %s on line %d\r\n", - file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ diff --git a/G4FANCYCANTESTING/Core/Inc/FancyCAN_LoopbackTest.h b/G4FANCYCANTESTING/Core/Inc/FancyCAN_LoopbackTest.h deleted file mode 100644 index 9a2ba9a26..000000000 --- a/G4FANCYCANTESTING/Core/Inc/FancyCAN_LoopbackTest.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef FANCYCAN_LOOPBACKTEST_H -#define FANCYCAN_LOOPBACKTEST_H - -int FancyCAN_LoopbackTest(void); - -#endif // FANCYCAN_LOOPBACKTEST_H diff --git a/G4FANCYCANTESTING/Core/Inc/adc.h b/G4FANCYCANTESTING/Core/Inc/adc.h deleted file mode 100644 index 41154538b..000000000 --- a/G4FANCYCANTESTING/Core/Inc/adc.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file adc.h - * @brief This file contains all the function prototypes for - * the adc.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __ADC_H__ -#define __ADC_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_ADC1_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __ADC_H__ */ diff --git a/G4FANCYCANTESTING/Core/Inc/can_cfg.h b/G4FANCYCANTESTING/Core/Inc/can_cfg.h deleted file mode 100644 index 5e7e78550..000000000 --- a/G4FANCYCANTESTING/Core/Inc/can_cfg.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef CAN_CFG_H -#define CAN_CFG_H - -#define USECAN2 -#define TX_BUFFER_1_SIZE 10 - -#define TX_BUFFER_2_SIZE 10 - -#endif diff --git a/G4FANCYCANTESTING/Core/Inc/crc.h b/G4FANCYCANTESTING/Core/Inc/crc.h deleted file mode 100644 index 133957e92..000000000 --- a/G4FANCYCANTESTING/Core/Inc/crc.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file crc.h - * @brief This file contains all the function prototypes for - * the crc.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __CRC_H__ -#define __CRC_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern CRC_HandleTypeDef hcrc; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_CRC_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CRC_H__ */ diff --git a/G4FANCYCANTESTING/Core/Inc/dma.h b/G4FANCYCANTESTING/Core/Inc/dma.h deleted file mode 100644 index ae819cab4..000000000 --- a/G4FANCYCANTESTING/Core/Inc/dma.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file dma.h - * @brief This file contains all the function prototypes for - * the dma.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __DMA_H__ -#define __DMA_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* DMA memory to memory transfer handles -------------------------------------*/ - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_DMA_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __DMA_H__ */ diff --git a/G4FANCYCANTESTING/Core/Inc/gpio.h b/G4FANCYCANTESTING/Core/Inc/gpio.h deleted file mode 100644 index 843d4e9e7..000000000 --- a/G4FANCYCANTESTING/Core/Inc/gpio.h +++ /dev/null @@ -1,48 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file gpio.h - * @brief This file contains all the function prototypes for - * the gpio.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __GPIO_H__ -#define __GPIO_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_GPIO_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif -#endif /*__ GPIO_H__ */ diff --git a/G4FANCYCANTESTING/Core/Inc/i2c.h b/G4FANCYCANTESTING/Core/Inc/i2c.h deleted file mode 100644 index 0a0a50803..000000000 --- a/G4FANCYCANTESTING/Core/Inc/i2c.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file i2c.h - * @brief This file contains all the function prototypes for - * the i2c.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __I2C_H__ -#define __I2C_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_I2C2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __I2C_H__ */ diff --git a/G4FANCYCANTESTING/Core/Inc/main.h b/G4FANCYCANTESTING/Core/Inc/main.h deleted file mode 100644 index 23d7ffce4..000000000 --- a/G4FANCYCANTESTING/Core/Inc/main.h +++ /dev/null @@ -1,115 +0,0 @@ -/* 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) 2024 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 "stm32g4xx_hal.h" -#include "stm32g4xx_ll_adc.h" -#include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_dma.h" -#include "stm32g4xx_ll_exti.h" -#include "stm32g4xx_ll_gpio.h" -#include "stm32g4xx_ll_i2c.h" -#include "stm32g4xx_ll_lpuart.h" -#include "stm32g4xx_ll_pwr.h" -#include "stm32g4xx_ll_rcc.h" -#include "stm32g4xx_ll_spi.h" -#include "stm32g4xx_ll_system.h" -#include "stm32g4xx_ll_tim.h" -#include "stm32g4xx_ll_usart.h" -#include "stm32g4xx_ll_utils.h" - -/* 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 Error_Handler(void); - -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -/* Private defines -----------------------------------------------------------*/ -#define BSPD_SIGNAL_Pin LL_GPIO_PIN_1 -#define BSPD_SIGNAL_GPIO_Port GPIOC -#define APPS1_SIGNAL_Pin LL_GPIO_PIN_2 -#define APPS1_SIGNAL_GPIO_Port GPIOC -#define APPS2_SIGNAL_Pin LL_GPIO_PIN_3 -#define APPS2_SIGNAL_GPIO_Port GPIOC -#define BLINKY_Pin LL_GPIO_PIN_5 -#define BLINKY_GPIO_Port GPIOA -#define IMD_SENSE_Pin LL_GPIO_PIN_6 -#define IMD_SENSE_GPIO_Port GPIOA -#define AMS_SENSE_Pin LL_GPIO_PIN_7 -#define AMS_SENSE_GPIO_Port GPIOA -#define BRAKE_F_SIGNAL_Pin LL_GPIO_PIN_0 -#define BRAKE_F_SIGNAL_GPIO_Port GPIOB -#define BRAKE_R_SIGNAL_Pin LL_GPIO_PIN_1 -#define BRAKE_R_SIGNAL_GPIO_Port GPIOB -#define LED_TEST_Pin LL_GPIO_PIN_11 -#define LED_TEST_GPIO_Port GPIOB -#define AUX_SIGNAL_Pin LL_GPIO_PIN_14 -#define AUX_SIGNAL_GPIO_Port GPIOB -#define STEERING_ANGLE_Pin LL_GPIO_PIN_15 -#define STEERING_ANGLE_GPIO_Port GPIOB -#define BRAKE_LIGHT_Pin LL_GPIO_PIN_4 -#define BRAKE_LIGHT_GPIO_Port GPIOB -#define TSSI_G_CONTROL_Pin LL_GPIO_PIN_5 -#define TSSI_G_CONTROL_GPIO_Port GPIOB -#define AUX_CONTROL_Pin LL_GPIO_PIN_8 -#define AUX_CONTROL_GPIO_Port GPIOB -#define SOFTWARE_OK_CONTROL_Pin LL_GPIO_PIN_9 -#define SOFTWARE_OK_CONTROL_GPIO_Port GPIOB - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -#ifdef __cplusplus -} -#endif - -#endif /* __MAIN_H */ diff --git a/G4FANCYCANTESTING/Core/Inc/spi.h b/G4FANCYCANTESTING/Core/Inc/spi.h deleted file mode 100644 index 74bed003b..000000000 --- a/G4FANCYCANTESTING/Core/Inc/spi.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file spi.h - * @brief This file contains all the function prototypes for - * the spi.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __SPI_H__ -#define __SPI_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_SPI3_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __SPI_H__ */ diff --git a/G4FANCYCANTESTING/Core/Inc/stm32g4xx_hal_conf.h b/G4FANCYCANTESTING/Core/Inc/stm32g4xx_hal_conf.h deleted file mode 100644 index 3e1fcb018..000000000 --- a/G4FANCYCANTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ /dev/null @@ -1,390 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_conf.h - * @author MCD Application Team - * @brief HAL configuration file - ****************************************************************************** - * @attention - * - * Copyright (c) 2019 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 STM32G4xx_HAL_CONF_H -#define STM32G4xx_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_ADC_MODULE_ENABLED */ -/*#define HAL_COMP_MODULE_ENABLED */ -/*#define HAL_CORDIC_MODULE_ENABLED */ -#define HAL_CRC_MODULE_ENABLED -/*#define HAL_CRYP_MODULE_ENABLED */ -/*#define HAL_DAC_MODULE_ENABLED */ -#define HAL_FDCAN_MODULE_ENABLED -/*#define HAL_FMAC_MODULE_ENABLED */ -/*#define HAL_HRTIM_MODULE_ENABLED */ -/*#define HAL_IRDA_MODULE_ENABLED */ -/*#define HAL_IWDG_MODULE_ENABLED */ -/*#define HAL_I2C_MODULE_ENABLED */ -/*#define HAL_I2S_MODULE_ENABLED */ -/*#define HAL_LPTIM_MODULE_ENABLED */ -/*#define HAL_NAND_MODULE_ENABLED */ -/*#define HAL_NOR_MODULE_ENABLED */ -/*#define HAL_OPAMP_MODULE_ENABLED */ -/*#define HAL_PCD_MODULE_ENABLED */ -/*#define HAL_QSPI_MODULE_ENABLED */ -/*#define HAL_RNG_MODULE_ENABLED */ -/*#define HAL_RTC_MODULE_ENABLED */ -/*#define HAL_SAI_MODULE_ENABLED */ -/*#define HAL_SMARTCARD_MODULE_ENABLED */ -/*#define HAL_SMBUS_MODULE_ENABLED */ -/*#define HAL_SPI_MODULE_ENABLED */ -/*#define HAL_SRAM_MODULE_ENABLED */ -/*#define HAL_TIM_MODULE_ENABLED */ -/*#define HAL_UART_MODULE_ENABLED */ -/*#define HAL_USART_MODULE_ENABLED */ -/*#define HAL_WWDG_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 - -/* ########################## Register Callbacks selection - * ############################## */ -/** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U - -/* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(HSE_STARTUP_TIMEOUT) -#define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ - -/** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high - * precision clock to the USB peripheral by means of a special Clock Recovery - * System (CRS) circuitry. When the CRS is not used, the HSI48 RC oscillator - * runs on it default frequency which is subject to manufacturing process - * variations. - */ -#if !defined(HSI48_VALUE) -#define HSI48_VALUE \ - (48000000UL) /*!< Value of the Internal High Speed oscillator for USB \ - FS/RNG in Hz. The real value my vary depending on \ - manufacturing process variations.*/ -#endif /* HSI48_VALUE */ - -/** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined(LSI_VALUE) -/*!< Value of the Internal Low Speed oscillator in Hz -The real value may vary depending on the variations in voltage and -temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ -/** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system - * frequency - */ -#if !defined(LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ - -#if !defined(LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ - -/** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S - * and SAI clock source frequency, this source is inserted directly through - * I2S_CKIN pad. - */ -#if !defined(EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U - -/* ########################## Assert Selection ############################## */ -/** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -/* #define USE_FULL_ASSERT 1U */ - -/* ################## 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 "stm32g4xx_hal_rcc.h" -#endif /* HAL_RCC_MODULE_ENABLED */ - -#ifdef HAL_GPIO_MODULE_ENABLED -#include "stm32g4xx_hal_gpio.h" -#endif /* HAL_GPIO_MODULE_ENABLED */ - -#ifdef HAL_DMA_MODULE_ENABLED -#include "stm32g4xx_hal_dma.h" -#endif /* HAL_DMA_MODULE_ENABLED */ - -#ifdef HAL_CORTEX_MODULE_ENABLED -#include "stm32g4xx_hal_cortex.h" -#endif /* HAL_CORTEX_MODULE_ENABLED */ - -#ifdef HAL_ADC_MODULE_ENABLED -#include "stm32g4xx_hal_adc.h" -#endif /* HAL_ADC_MODULE_ENABLED */ - -#ifdef HAL_COMP_MODULE_ENABLED -#include "stm32g4xx_hal_comp.h" -#endif /* HAL_COMP_MODULE_ENABLED */ - -#ifdef HAL_CORDIC_MODULE_ENABLED -#include "stm32g4xx_hal_cordic.h" -#endif /* HAL_CORDIC_MODULE_ENABLED */ - -#ifdef HAL_CRC_MODULE_ENABLED -#include "stm32g4xx_hal_crc.h" -#endif /* HAL_CRC_MODULE_ENABLED */ - -#ifdef HAL_CRYP_MODULE_ENABLED -#include "stm32g4xx_hal_cryp.h" -#endif /* HAL_CRYP_MODULE_ENABLED */ - -#ifdef HAL_DAC_MODULE_ENABLED -#include "stm32g4xx_hal_dac.h" -#endif /* HAL_DAC_MODULE_ENABLED */ - -#ifdef HAL_EXTI_MODULE_ENABLED -#include "stm32g4xx_hal_exti.h" -#endif /* HAL_EXTI_MODULE_ENABLED */ - -#ifdef HAL_FDCAN_MODULE_ENABLED -#include "stm32g4xx_hal_fdcan.h" -#endif /* HAL_FDCAN_MODULE_ENABLED */ - -#ifdef HAL_FLASH_MODULE_ENABLED -#include "stm32g4xx_hal_flash.h" -#endif /* HAL_FLASH_MODULE_ENABLED */ - -#ifdef HAL_FMAC_MODULE_ENABLED -#include "stm32g4xx_hal_fmac.h" -#endif /* HAL_FMAC_MODULE_ENABLED */ - -#ifdef HAL_HRTIM_MODULE_ENABLED -#include "stm32g4xx_hal_hrtim.h" -#endif /* HAL_HRTIM_MODULE_ENABLED */ - -#ifdef HAL_IRDA_MODULE_ENABLED -#include "stm32g4xx_hal_irda.h" -#endif /* HAL_IRDA_MODULE_ENABLED */ - -#ifdef HAL_IWDG_MODULE_ENABLED -#include "stm32g4xx_hal_iwdg.h" -#endif /* HAL_IWDG_MODULE_ENABLED */ - -#ifdef HAL_I2C_MODULE_ENABLED -#include "stm32g4xx_hal_i2c.h" -#endif /* HAL_I2C_MODULE_ENABLED */ - -#ifdef HAL_I2S_MODULE_ENABLED -#include "stm32g4xx_hal_i2s.h" -#endif /* HAL_I2S_MODULE_ENABLED */ - -#ifdef HAL_LPTIM_MODULE_ENABLED -#include "stm32g4xx_hal_lptim.h" -#endif /* HAL_LPTIM_MODULE_ENABLED */ - -#ifdef HAL_NAND_MODULE_ENABLED -#include "stm32g4xx_hal_nand.h" -#endif /* HAL_NAND_MODULE_ENABLED */ - -#ifdef HAL_NOR_MODULE_ENABLED -#include "stm32g4xx_hal_nor.h" -#endif /* HAL_NOR_MODULE_ENABLED */ - -#ifdef HAL_OPAMP_MODULE_ENABLED -#include "stm32g4xx_hal_opamp.h" -#endif /* HAL_OPAMP_MODULE_ENABLED */ - -#ifdef HAL_PCD_MODULE_ENABLED -#include "stm32g4xx_hal_pcd.h" -#endif /* HAL_PCD_MODULE_ENABLED */ - -#ifdef HAL_PWR_MODULE_ENABLED -#include "stm32g4xx_hal_pwr.h" -#endif /* HAL_PWR_MODULE_ENABLED */ - -#ifdef HAL_QSPI_MODULE_ENABLED -#include "stm32g4xx_hal_qspi.h" -#endif /* HAL_QSPI_MODULE_ENABLED */ - -#ifdef HAL_RNG_MODULE_ENABLED -#include "stm32g4xx_hal_rng.h" -#endif /* HAL_RNG_MODULE_ENABLED */ - -#ifdef HAL_RTC_MODULE_ENABLED -#include "stm32g4xx_hal_rtc.h" -#endif /* HAL_RTC_MODULE_ENABLED */ - -#ifdef HAL_SAI_MODULE_ENABLED -#include "stm32g4xx_hal_sai.h" -#endif /* HAL_SAI_MODULE_ENABLED */ - -#ifdef HAL_SMARTCARD_MODULE_ENABLED -#include "stm32g4xx_hal_smartcard.h" -#endif /* HAL_SMARTCARD_MODULE_ENABLED */ - -#ifdef HAL_SMBUS_MODULE_ENABLED -#include "stm32g4xx_hal_smbus.h" -#endif /* HAL_SMBUS_MODULE_ENABLED */ - -#ifdef HAL_SPI_MODULE_ENABLED -#include "stm32g4xx_hal_spi.h" -#endif /* HAL_SPI_MODULE_ENABLED */ - -#ifdef HAL_SRAM_MODULE_ENABLED -#include "stm32g4xx_hal_sram.h" -#endif /* HAL_SRAM_MODULE_ENABLED */ - -#ifdef HAL_TIM_MODULE_ENABLED -#include "stm32g4xx_hal_tim.h" -#endif /* HAL_TIM_MODULE_ENABLED */ - -#ifdef HAL_UART_MODULE_ENABLED -#include "stm32g4xx_hal_uart.h" -#endif /* HAL_UART_MODULE_ENABLED */ - -#ifdef HAL_USART_MODULE_ENABLED -#include "stm32g4xx_hal_usart.h" -#endif /* HAL_USART_MODULE_ENABLED */ - -#ifdef HAL_WWDG_MODULE_ENABLED -#include "stm32g4xx_hal_wwdg.h" -#endif /* HAL_WWDG_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 /* STM32G4xx_HAL_CONF_H */ diff --git a/G4FANCYCANTESTING/Core/Inc/stm32g4xx_it.h b/G4FANCYCANTESTING/Core/Inc/stm32g4xx_it.h deleted file mode 100644 index b6c3b2f72..000000000 --- a/G4FANCYCANTESTING/Core/Inc/stm32g4xx_it.h +++ /dev/null @@ -1,67 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_it.h - * @brief This file contains the headers of the interrupt handlers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __STM32G4xx_IT_H -#define __STM32G4xx_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); -void FDCAN2_IT0_IRQHandler(void); -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32G4xx_IT_H */ diff --git a/G4FANCYCANTESTING/Core/Inc/tim.h b/G4FANCYCANTESTING/Core/Inc/tim.h deleted file mode 100644 index c19e6cc71..000000000 --- a/G4FANCYCANTESTING/Core/Inc/tim.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file tim.h - * @brief This file contains all the function prototypes for - * the tim.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __TIM_H__ -#define __TIM_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_TIM2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __TIM_H__ */ diff --git a/G4FANCYCANTESTING/Core/Inc/usart.h b/G4FANCYCANTESTING/Core/Inc/usart.h deleted file mode 100644 index daefd73e6..000000000 --- a/G4FANCYCANTESTING/Core/Inc/usart.h +++ /dev/null @@ -1,50 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file usart.h - * @brief This file contains all the function prototypes for - * the usart.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __USART_H__ -#define __USART_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_LPUART1_UART_Init(void); -void MX_USART1_UART_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USART_H__ */ diff --git a/G4FANCYCANTESTING/Core/Src/FancyCAN_LoopbackTest.c b/G4FANCYCANTESTING/Core/Src/FancyCAN_LoopbackTest.c deleted file mode 100644 index 07f9ca72a..000000000 --- a/G4FANCYCANTESTING/Core/Src/FancyCAN_LoopbackTest.c +++ /dev/null @@ -1,419 +0,0 @@ -#include -#include -#include - -#include "GRCAN_FancyLayer.h" -#include "Logomatic.h" -#include "stdlib.h" - -static volatile uint32_t rx_received = 0; -static volatile bool data_valid = false; -static uint8_t expected_data[TX_BUFFER_2_SIZE]; -static volatile uint32_t expected_size = 0; -static volatile uint32_t expected_id = 0; -static volatile bool id_valid = false; - -static void can_test_rx_callback(uint32_t id, void *data, uint32_t size) -{ - rx_received++; - if (size > sizeof(expected_data)) { - data_valid = false; - return; - } - data_valid = (size == expected_size) && (memcmp(data, expected_data, size) == 0); - id_valid = (id == expected_id); - - LOGOMATIC("\nCallback triggered: ID=%" PRIu32 ", Size=%lu, Data[0]=0x%x\n", id, (unsigned long)size, *(uint8_t *)data); -} - -// TODO - allow user to send data without needing to construct a header for the buffer -// TODO: G4 tests are dependent on the System clock configuration?? - -int GRCAN_Validate_InitBus(GRCAN_BUS_ID bus, GRCAN_OperatingMode mode, FDCAN_GlobalTypeDef *fdcan_instance) -{ - GRCAN_BusConfig bus_config; - GRCAN_SetDefaultBusConfig(&bus_config, bus); - bus_config.operating_mode = mode; // GRCAN_OPMODE_INTERNAL_LOOPBACK is only one tested so far - bus_config.fdcan_instance = fdcan_instance; - bus_config.rx_callback = can_test_rx_callback; // test loopback - - LOGOMATIC("Testing GRCAN_InitBus...\n"); - bool result = GRCAN_InitBus(&bus_config); - - if (result == true) { - LOGOMATIC("GRCAN_InitBus PASSED.\n"); - return 1; - } else { - LOGOMATIC("GRCAN_InitBus FAILED.\n"); - return 0; - } -} - -// GRCAN_ALL = 0xFF, -// GRCAN_ACU = 0x03, -// GRCAN_ECU = 0x02, -// GRCAN_CCU = 0x02, -// GRCAN_Charger = 0x00, -// GRCAN_Charging_SDC = 0x0C, -// GRCAN_DGPS = 0x30, -// GRCAN_Dash_Panel = 0x05, -// GRCAN_Debugger = 0x01, -// GRCAN_Fan_Ctrl_1 = 0x0D, -// GRCAN_Fan_Ctrl_2 = 0x0E, -// GRCAN_Fan_Ctrl_3 = 0x0F, -// GRCAN_GR_Inv = 0x08, -// GRCAN_TCM = 0x04, - -GRCAN_NODE_ID get_nodeID(GRCAN_BUS_ID bus) -{ - switch (bus) { - case GRCAN_BUS_PRIMARY: - return GRCAN_ACU; - case GRCAN_BUS_DATA: - return GRCAN_ECU; - case GRCAN_BUS_TESTING: - return GRCAN_Debugger; - case GRCAN_BUS_CHARGER: - return GRCAN_Charger; - default: - return GRCAN_ALL; // All causes error - } -} - -// typedef enum { -// GRCAN_DEBUG_2_0 = 0x000, -// GRCAN_DEBUG_FD = 0x001, -// GRCAN_PING = 0x002, -// GRCAN_ECU_STATUS_1 = 0x003, -// GRCAN_ECU_STATUS_2 = 0x004, -// GRCAN_ECU_STATUS_3 = 0x005, -// GRCAN_ECU_CONFIG = 0x006, -// GRCAN_ACU_STATUS_1 = 0x007, -// GRCAN_ACU_STATUS_2 = 0x008, -// GRCAN_ACU_STATUS_3 = 0x009, -// GRCAN_ACU_PRECHARGE = 0x00A, -// GRCAN_ACU_CONFIG_CHARGE_PARAMETERS = 0x00B, -// GRCAN_ACU_CONFIG_OPERATIONAL_PARAMETERS = 0x00C, -// GRCAN_ACU_CELL_DATA_1 = 0x00D, -// GRCAN_ACU_CELL_DATA_2 = 0x00E, -// GRCAN_ACU_CELL_DATA_3 = 0x00F, -// GRCAN_ACU_CELL_DATA_4 = 0x010, -// GRCAN_ACU_CELL_DATA_5 = 0x011, -// GRCAN_INV_STATUS_1 = 0x013, -// GRCAN_INV_STATUS_2 = 0x014, -// GRCAN_INV_STATUS_3 = 0x015, -// GRCAN_INV_CONFIG = 0x016, -// GRCAN_INV_CMD = 0x017, -// GRCAN_FAN_STATUS = 0x018, -// GRCAN_FAN_COMMAND = 0x019, -// GRCAN_DASH_STATUS = 0x01A, -// GRCAN_DASH_CONFIG = 0x01B, -// GRCAN_TCM_STATUS = 0x029, -// GRCAN_TCM_RESOURCE_UTILIZATION = 0x02A, -// GRCAN_DASH_WARNING_FLAGS = 0x02B, -// GRCAN_ECU_ANALOG_DATA = 0x02E, -// GRCAN_GPS_LAT = 0x031, -// GRCAN_GPS_LON = 0x032, -// GRCAN_GPS_ALT = 0x033, -// GRCAN_GPS_PX = 0x034, -// GRCAN_GPS_QY = 0x035, -// GRCAN_GPS_RZ = 0x036, -// GRCAN_UVW_DGPS = 0x030, -// GRCAN_ECU_PERFORMANCE = 0x123, -// } GRCAN_MSG_ID; - -GRCAN_MSG_ID get_messageID(GRCAN_BUS_ID bus) -{ - switch (bus) { - case GRCAN_BUS_PRIMARY: - return GRCAN_ACU_STATUS_1; - case GRCAN_BUS_DATA: - return GRCAN_ECU_STATUS_1; - case GRCAN_BUS_TESTING: - return GRCAN_DEBUG_2_0; - case GRCAN_BUS_CHARGER: - return GRCAN_ACU_CONFIG_CHG_PARAMS; - default: - return (GRCAN_MSG_ID)0xFF; // Invalid message ID - } -} - -int GRCAN_SendReceive(GRCAN_BUS_ID bus, GRCAN_NODE_ID nodeID, GRCAN_NODE_ID dest_nodeID, GRCAN_MSG_ID messageID, void *data, uint32_t size) -{ - if (data == NULL) { - data = "Hello"; - size = sizeof("Hello"); - } - - if (size > sizeof(expected_data)) { - LOGOMATIC("Data size exceeds expected_data buffer size. Test cannot proceed.\n"); - return 0; - } - - // typedef struct { - // GRCAN_NODE_ID srcID; - // GRCAN_NODE_ID destNode; - // GRCAN_MSG_ID messageID; - // } GRCAN_Fancy_ID; - - expected_size = size; - GRCAN_Fancy_ID GRCAN_Fancy_ID; - GRCAN_Fancy_ID.srcID = nodeID; - GRCAN_Fancy_ID.destNode = dest_nodeID; - GRCAN_Fancy_ID.messageID = messageID; - expected_id = GRCAN_Fancy_EncodeID(&GRCAN_Fancy_ID); - - rx_received = 0; - data_valid = false; - id_valid = false; - - GRCAN_SetLocalNodeID(nodeID); - - memcpy(expected_data, data, size); - bool send_result = GRCAN_Fancy_Send(bus, dest_nodeID, messageID, data, size); - - if (!send_result) { - LOGOMATIC("GRCAN_Fancy_Send failed to send message on bus %d\n", bus); - return 0; - } - - HAL_Delay(1); - - if (rx_received > 0 && data_valid && id_valid) { - LOGOMATIC("GRCAN_Fancy_Send PASSED. Callback verified and data is valid.\n"); - return 1; - } else { - LOGOMATIC("GRCAN_Fancy_Send FAILED. Callback not triggered or data is invalid.\n"); - return 0; - } -} - -int GRCAN_ErrorHandling() -{ - GRCAN_BusConfig invalid_config = {0}; - - LOGOMATIC("\nTesting GRCAN_InitBus with invalid config...\n"); - bool result = GRCAN_InitBus(&invalid_config); - if (result == false) { - LOGOMATIC("GRCAN_InitBus error handling PASSED.\n"); - return 1; - } else { - LOGOMATIC("GRCAN_InitBus error handling FAILED.\n"); - return 0; - } -} - -void get_test_payload(int idx, void **data, uint32_t *size) -{ - static uint8_t msg1[] = "Hello"; - static uint8_t msg2[] = "World"; - static uint8_t msg3[] = {12}; - static uint8_t msg4[] = {23}; - static uint8_t msg5[] = {0x00, 0x00, 0x00, 0x00}; - static uint8_t msg6[] = {0xFF, 0xFF, 0xFF, 0xFF}; - static uint8_t msg7[] = {0xAA, 0x55, 0xAA, 0x55}; - static uint8_t msg8[] = {0, 1, 2, 3, 4, 5, 6, 7}; - - switch (idx) { - case 0: - *data = msg1; - *size = sizeof(msg1); - break; - case 1: - *data = msg2; - *size = sizeof(msg2); - break; - case 2: - *data = msg3; - *size = sizeof(msg3); - break; - case 3: - *data = msg4; - *size = sizeof(msg4); - break; - case 4: - *data = msg5; - *size = sizeof(msg5); - break; - case 5: - *data = msg6; - *size = sizeof(msg6); - break; - case 6: - *data = msg7; - *size = sizeof(msg7); - break; - case 7: - *data = msg8; - *size = sizeof(msg8); - break; - default: - *data = NULL; - *size = 0; - break; - } -} - -int GRCAN_BurstSendTest(GRCAN_BUS_ID bus, GRCAN_NODE_ID nodeID, GRCAN_NODE_ID dest_nodeID, GRCAN_MSG_ID messageID, uint32_t count) -{ - uint8_t burst_msg[] = {0x10, 0x20, 0x30, 0x40}; - - LOGOMATIC("Starting burst send test on bus %d with %lu messages...\n", bus, (unsigned long)count); - - for (uint32_t i = 0; i < count; i++) { - if (!GRCAN_SendReceive(bus, nodeID, dest_nodeID, messageID, burst_msg, sizeof(burst_msg))) { - LOGOMATIC("Burst send test FAILED on iteration %lu.\n", (unsigned long)i); - return 0; - } - } - - LOGOMATIC("Burst send test PASSED on bus %d.\n", bus); - return 1; -} - -int GRCAN_InitDeactivateStressTest(GRCAN_BUS_ID bus, GRCAN_NODE_ID nodeID, GRCAN_NODE_ID dest_nodeID, GRCAN_MSG_ID messageID, FDCAN_GlobalTypeDef *fdcan_instance, uint32_t iterations) -{ - uint8_t stress_msg[] = "Stress"; - - LOGOMATIC("Starting init/deactivate stress test on bus %d for %lu iterations...\n", bus, (unsigned long)iterations); - - for (uint32_t i = 0; i < iterations; i++) { - if (!GRCAN_Validate_InitBus(bus, GRCAN_OPMODE_INTERNAL_LOOPBACK, fdcan_instance)) { - LOGOMATIC("Stress test FAILED during init on iteration %lu.\n", (unsigned long)i); - return 0; - } - - if (!GRCAN_SendReceive(bus, nodeID, dest_nodeID, messageID, stress_msg, sizeof(stress_msg))) { - LOGOMATIC("Stress test FAILED during send/receive on iteration %lu.\n", (unsigned long)i); - GRCAN_DeactivateBus(bus); - return 0; - } - - if (!GRCAN_DeactivateBus(bus)) { - LOGOMATIC("Stress test FAILED during deactivate on iteration %lu.\n", (unsigned long)i); - return 0; - } - } - - LOGOMATIC("Init/deactivate stress test PASSED on bus %d.\n", bus); - return 1; -} - -int FancyCAN_LoopbackTest(void) -{ - GRCAN_BUS_ID bus; - - for (bus = GRCAN_BUS_TESTING; bus <= GRCAN_BUS_CHARGER; bus++) { - LOGOMATIC("\n--- Testing bus %d ---\n", bus); - int res1 = GRCAN_Validate_InitBus(bus, GRCAN_OPMODE_INTERNAL_LOOPBACK, FDCAN2); - // GRCAN_OPMODE_EXTERNAL_LOOPBACK needs to be tested, can change FDCAN: make sure to #define USECANx - GRCAN_NODE_ID nodeID = get_nodeID(bus); - GRCAN_MSG_ID messageID = get_messageID(bus); - GRCAN_NODE_ID dest_nodeID = nodeID; // Loopback to self for internal - int res2 = 1; - for (int i = 0; i < 8; i++) { - void *data; - uint32_t size; - get_test_payload(i, &data, &size); - - LOGOMATIC("\nTesting GRCAN_SendReceive on bus %d...\n", bus); - res2 = GRCAN_SendReceive(bus, nodeID, dest_nodeID, messageID, data, size); // - if (res2 == 0) { - uint8_t data_value = *(uint8_t *)data; - switch (bus) { - case GRCAN_BUS_PRIMARY: - LOGOMATIC("Testing Bus:PRIMARY Loopback Test FAILED for message with first byte: %d.\n", data_value); - break; - case GRCAN_BUS_DATA: - LOGOMATIC("Testing Bus:DATA Loopback Test FAILED for message with first byte: %d.\n", data_value); - break; - case GRCAN_BUS_CHARGER: - LOGOMATIC("Testing Bus:CHARGER Loopback Test FAILED for message with first byte: %d.\n", data_value); - break; - case GRCAN_BUS_TESTING: - LOGOMATIC("Testing Bus:TESTING Loopback Test FAILED for message with first byte: %d.\n", data_value); - break; - default: - LOGOMATIC("Testing Bus:UNKNOWN Loopback Test FAILED for message with first byte: %d.\n", data_value); - break; - } - break; - } - } - - bool res4 = GRCAN_DeactivateBus(bus); - - if (!res1 || !res2) { - switch (bus) { - case GRCAN_BUS_PRIMARY: - LOGOMATIC("Testing Bus:PRIMARY Loopback Test FAILED during initialization or send/receive test.\n"); - break; - case GRCAN_BUS_DATA: - LOGOMATIC("Testing Bus:DATA Loopback Test FAILED during initialization or send/receive test.\n"); - break; - case GRCAN_BUS_TESTING: - LOGOMATIC("Testing Bus:TESTING Loopback Test FAILED during initialization or send/receive test.\n"); - break; - case GRCAN_BUS_CHARGER: - LOGOMATIC("Testing Bus:CHARGER Loopback Test FAILED during initialization or send/receive test.\n"); - break; - default: - LOGOMATIC("Testing Bus:UNKNOWN Loopback Test FAILED during initialization or send/receive test.\n"); - break; - } - } - if (!res4) { - switch (bus) { - case GRCAN_BUS_PRIMARY: - LOGOMATIC("Testing Bus:PRIMARY Loopback Test FAILED during bus deactivation.\n"); - break; - case GRCAN_BUS_DATA: - LOGOMATIC("Testing Bus:DATA Loopback Test FAILED during bus deactivation.\n"); - break; - case GRCAN_BUS_TESTING: - LOGOMATIC("Testing Bus:TESTING Loopback Test FAILED during bus deactivation.\n"); - break; - case GRCAN_BUS_CHARGER: - LOGOMATIC("Testing Bus:CHARGER Loopback Test FAILED during bus deactivation.\n"); - break; - default: - LOGOMATIC("Testing Bus:UNKNOWN Loopback Test FAILED during bus deactivation.\n"); - break; - } - } - } - - if (bus < 4) { - LOGOMATIC("\nLoopback Test FAILED. Not all buses were tested.\n"); - return 0; - } - - // The next tests takes a while, completely fine to remove - for (bus = GRCAN_BUS_TESTING; bus <= GRCAN_BUS_CHARGER; bus++) { - LOGOMATIC("\n--- Testing burst send on bus %d ---\n", bus); - GRCAN_Validate_InitBus(bus, GRCAN_OPMODE_INTERNAL_LOOPBACK, FDCAN2); - int burst_result = GRCAN_BurstSendTest(bus, get_nodeID(bus), get_nodeID(bus), get_messageID(bus), 100); - if (!burst_result) { - LOGOMATIC("\nLoopback Test FAILED during burst send test on bus %d.\n", bus); - return 0; - } - GRCAN_DeactivateBus(bus); - } - - for (bus = GRCAN_BUS_TESTING; bus <= GRCAN_BUS_CHARGER; bus++) { - LOGOMATIC("\n--- Testing init/deactivate stress test on bus %d ---\n", bus); - int stress_result = GRCAN_InitDeactivateStressTest(bus, get_nodeID(bus), get_nodeID(bus), get_messageID(bus), FDCAN2, 50); - if (!stress_result) { - LOGOMATIC("\nLoopback Test FAILED during init/deactivate stress test on bus %d.\n", bus); - return 0; - } - } - - int res3 = GRCAN_ErrorHandling(); - if (!res3) { - LOGOMATIC("\nLoopback Test FAILED during error handling test.\n"); - return 0; - } - - return 1; -} diff --git a/G4FANCYCANTESTING/Core/Src/adc.c b/G4FANCYCANTESTING/Core/Src/adc.c deleted file mode 100644 index f3dbff8ed..000000000 --- a/G4FANCYCANTESTING/Core/Src/adc.c +++ /dev/null @@ -1,186 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file adc.c - * @brief This file provides code for the configuration - * of the ADC instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "adc.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* ADC1 init function */ -void MX_ADC1_Init(void) -{ - - /* USER CODE BEGIN ADC1_Init 0 */ - - /* USER CODE END ADC1_Init 0 */ - - LL_ADC_InitTypeDef ADC_InitStruct = {0}; - LL_ADC_REG_InitTypeDef ADC_REG_InitStruct = {0}; - LL_ADC_CommonInitTypeDef ADC_CommonInitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetADCClockSource(LL_RCC_ADC12_CLKSOURCE_SYSCLK); - - /* Peripheral clock enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_ADC12); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - /**ADC1 GPIO Configuration - PC1 ------> ADC1_IN7 - PC2 ------> ADC1_IN8 - PC3 ------> ADC1_IN9 - PB0 ------> ADC1_IN15 - PB1 ------> ADC1_IN12 - PB14 ------> ADC1_IN5 - */ - GPIO_InitStruct.Pin = BSPD_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BSPD_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = APPS1_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(APPS1_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = APPS2_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(APPS2_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = BRAKE_F_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_F_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = BRAKE_R_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_R_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = AUX_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AUX_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - /* ADC1 DMA Init */ - - /* ADC1 Init */ - LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_1, LL_DMAMUX_REQ_ADC1); - - LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_1, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); - - LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PRIORITY_LOW); - - LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_CIRCULAR); - - LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PERIPH_NOINCREMENT); - - LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT); - - LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_HALFWORD); - - LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_HALFWORD); - - /* USER CODE BEGIN ADC1_Init 1 */ - - /* USER CODE END ADC1_Init 1 */ - - /** Common config - */ - ADC_InitStruct.Resolution = LL_ADC_RESOLUTION_12B; - ADC_InitStruct.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT; - ADC_InitStruct.LowPowerMode = LL_ADC_LP_MODE_NONE; - LL_ADC_Init(ADC1, &ADC_InitStruct); - ADC_REG_InitStruct.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE; - ADC_REG_InitStruct.SequencerLength = LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS; - ADC_REG_InitStruct.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE; - ADC_REG_InitStruct.ContinuousMode = LL_ADC_REG_CONV_CONTINUOUS; - ADC_REG_InitStruct.DMATransfer = LL_ADC_REG_DMA_TRANSFER_UNLIMITED; - ADC_REG_InitStruct.Overrun = LL_ADC_REG_OVR_DATA_PRESERVED; - LL_ADC_REG_Init(ADC1, &ADC_REG_InitStruct); - LL_ADC_SetGainCompensation(ADC1, 0); - LL_ADC_SetOverSamplingScope(ADC1, LL_ADC_OVS_DISABLE); - ADC_CommonInitStruct.CommonClock = LL_ADC_CLOCK_ASYNC_DIV256; - ADC_CommonInitStruct.Multimode = LL_ADC_MULTI_INDEPENDENT; - LL_ADC_CommonInit(__LL_ADC_COMMON_INSTANCE(ADC1), &ADC_CommonInitStruct); - - /* Disable ADC deep power down (enabled by default after reset state) */ - LL_ADC_DisableDeepPowerDown(ADC1); - /* Enable ADC internal voltage regulator */ - LL_ADC_EnableInternalRegulator(ADC1); - /* Delay for ADC internal voltage regulator stabilization. */ - /* Compute number of CPU cycles to wait for, from delay in us. */ - /* Note: Variable divided by 2 to compensate partially */ - /* CPU processing cycles (depends on compilation optimization). */ - /* Note: If system core clock frequency is below 200kHz, wait time */ - /* is only a few CPU processing cycles. */ - uint32_t wait_loop_index; - wait_loop_index = ((LL_ADC_DELAY_INTERNAL_REGUL_STAB_US * (SystemCoreClock / (100000 * 2))) / 10); - while (wait_loop_index != 0) { - wait_loop_index--; - } - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_5); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_5, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_5, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_2, LL_ADC_CHANNEL_7); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_7, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_7, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_3, LL_ADC_CHANNEL_8); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_8, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_8, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_4, LL_ADC_CHANNEL_9); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_9, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_9, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_5, LL_ADC_CHANNEL_12); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_12, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_12, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_6, LL_ADC_CHANNEL_15); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_15, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_15, LL_ADC_SINGLE_ENDED); - /* USER CODE BEGIN ADC1_Init 2 */ - - /* USER CODE END ADC1_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4FANCYCANTESTING/Core/Src/crc.c b/G4FANCYCANTESTING/Core/Src/crc.c deleted file mode 100644 index 213510a5d..000000000 --- a/G4FANCYCANTESTING/Core/Src/crc.c +++ /dev/null @@ -1,86 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file crc.c - * @brief This file provides code for the configuration - * of the CRC instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "crc.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -CRC_HandleTypeDef hcrc; - -/* CRC init function */ -void MX_CRC_Init(void) -{ - - /* USER CODE BEGIN CRC_Init 0 */ - - /* USER CODE END CRC_Init 0 */ - - /* USER CODE BEGIN CRC_Init 1 */ - - /* USER CODE END CRC_Init 1 */ - hcrc.Instance = CRC; - hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE; - hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE; - hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE; - hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE; - hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES; - if (HAL_CRC_Init(&hcrc) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN CRC_Init 2 */ - - /* USER CODE END CRC_Init 2 */ -} - -void HAL_CRC_MspInit(CRC_HandleTypeDef *crcHandle) -{ - - if (crcHandle->Instance == CRC) { - /* USER CODE BEGIN CRC_MspInit 0 */ - - /* USER CODE END CRC_MspInit 0 */ - /* CRC clock enable */ - __HAL_RCC_CRC_CLK_ENABLE(); - /* USER CODE BEGIN CRC_MspInit 1 */ - - /* USER CODE END CRC_MspInit 1 */ - } -} - -void HAL_CRC_MspDeInit(CRC_HandleTypeDef *crcHandle) -{ - - if (crcHandle->Instance == CRC) { - /* USER CODE BEGIN CRC_MspDeInit 0 */ - - /* USER CODE END CRC_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_CRC_CLK_DISABLE(); - /* USER CODE BEGIN CRC_MspDeInit 1 */ - - /* USER CODE END CRC_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4FANCYCANTESTING/Core/Src/dma.c b/G4FANCYCANTESTING/Core/Src/dma.c deleted file mode 100644 index 491e3889d..000000000 --- a/G4FANCYCANTESTING/Core/Src/dma.c +++ /dev/null @@ -1,50 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file dma.c - * @brief This file provides code for the configuration - * of all the requested memory to memory DMA transfers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "dma.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure DMA */ -/*----------------------------------------------------------------------------*/ - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** - * Enable DMA controller clock - */ -void MX_DMA_Init(void) -{ - - /* Init with LL driver */ - /* DMA controller clock enable */ - LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMAMUX1); - LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1); -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ diff --git a/G4FANCYCANTESTING/Core/Src/gpio.c b/G4FANCYCANTESTING/Core/Src/gpio.c deleted file mode 100644 index d36e6eca6..000000000 --- a/G4FANCYCANTESTING/Core/Src/gpio.c +++ /dev/null @@ -1,260 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file gpio.c - * @brief This file provides code for the configuration - * of all used GPIO pins. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "gpio.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure GPIO */ -/*----------------------------------------------------------------------------*/ -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is - enabled through - * the Code Generation settings) - PA6 ------> ADC2_IN3 - PA7 ------> ADC2_IN4 - PB15 ------> ADC2_IN15 - PB7 ------> UART4_CTS -*/ -void MX_GPIO_Init(void) -{ - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(BLINKY_GPIO_Port, BLINKY_Pin); - - /**/ - LL_GPIO_ResetOutputPin(LED_TEST_GPIO_Port, LED_TEST_Pin); - - /**/ - LL_GPIO_ResetOutputPin(BRAKE_LIGHT_GPIO_Port, BRAKE_LIGHT_Pin); - - /**/ - LL_GPIO_ResetOutputPin(TSSI_G_CONTROL_GPIO_Port, TSSI_G_CONTROL_Pin); - - /**/ - LL_GPIO_ResetOutputPin(AUX_CONTROL_GPIO_Port, AUX_CONTROL_Pin); - - /**/ - LL_GPIO_ResetOutputPin(SOFTWARE_OK_CONTROL_GPIO_Port, SOFTWARE_OK_CONTROL_Pin); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_13; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = BLINKY_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BLINKY_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = IMD_SENSE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(IMD_SENSE_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = AMS_SENSE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AMS_SENSE_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LED_TEST_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(LED_TEST_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = STEERING_ANGLE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(STEERING_ANGLE_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = BRAKE_LIGHT_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_LIGHT_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = TSSI_G_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(TSSI_G_CONTROL_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_14; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = AUX_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AUX_CONTROL_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = SOFTWARE_OK_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(SOFTWARE_OK_CONTROL_GPIO_Port, &GPIO_InitStruct); -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ diff --git a/G4FANCYCANTESTING/Core/Src/i2c.c b/G4FANCYCANTESTING/Core/Src/i2c.c deleted file mode 100644 index bfb4e0153..000000000 --- a/G4FANCYCANTESTING/Core/Src/i2c.c +++ /dev/null @@ -1,92 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file i2c.c - * @brief This file provides code for the configuration - * of the I2C instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "i2c.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* I2C2 init function */ -void MX_I2C2_Init(void) -{ - - /* USER CODE BEGIN I2C2_Init 0 */ - - /* USER CODE END I2C2_Init 0 */ - - LL_I2C_InitTypeDef I2C_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetI2CClockSource(LL_RCC_I2C2_CLKSOURCE_PCLK1); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - /**I2C2 GPIO Configuration - PC4 ------> I2C2_SCL - PA8 ------> I2C2_SDA - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_4; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_4; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C2); - - /* USER CODE BEGIN I2C2_Init 1 */ - - /* USER CODE END I2C2_Init 1 */ - - /** I2C Initialization - */ - I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; - I2C_InitStruct.Timing = 0x30D29DE4; - I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE; - I2C_InitStruct.DigitalFilter = 0; - I2C_InitStruct.OwnAddress1 = 0; - I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK; - I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT; - LL_I2C_Init(I2C2, &I2C_InitStruct); - LL_I2C_EnableAutoEndMode(I2C2); - LL_I2C_SetOwnAddress2(I2C2, 0, LL_I2C_OWNADDRESS2_NOMASK); - LL_I2C_DisableOwnAddress2(I2C2); - LL_I2C_DisableGeneralCall(I2C2); - LL_I2C_EnableClockStretching(I2C2); - /* USER CODE BEGIN I2C2_Init 2 */ - - /* USER CODE END I2C2_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4FANCYCANTESTING/Core/Src/spi.c b/G4FANCYCANTESTING/Core/Src/spi.c deleted file mode 100644 index 66459f2ec..000000000 --- a/G4FANCYCANTESTING/Core/Src/spi.c +++ /dev/null @@ -1,95 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file spi.c - * @brief This file provides code for the configuration - * of the SPI instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "spi.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* SPI3 init function */ -void MX_SPI3_Init(void) -{ - - /* USER CODE BEGIN SPI3_Init 0 */ - - /* USER CODE END SPI3_Init 0 */ - - LL_SPI_InitTypeDef SPI_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI3); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - /**SPI3 GPIO Configuration - PC10 ------> SPI3_SCK - PC11 ------> SPI3_MISO - PC12 ------> SPI3_MOSI - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_6; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_6; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_6; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN SPI3_Init 1 */ - - /* USER CODE END SPI3_Init 1 */ - SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; - SPI_InitStruct.Mode = LL_SPI_MODE_MASTER; - SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_4BIT; - SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; - SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE; - SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; - SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV32; - SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST; - SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; - SPI_InitStruct.CRCPoly = 7; - LL_SPI_Init(SPI3, &SPI_InitStruct); - LL_SPI_SetStandard(SPI3, LL_SPI_PROTOCOL_MOTOROLA); - LL_SPI_EnableNSSPulseMgt(SPI3); - /* USER CODE BEGIN SPI3_Init 2 */ - - /* USER CODE END SPI3_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4FANCYCANTESTING/Core/Src/stm32g4xx_hal_msp.c b/G4FANCYCANTESTING/Core/Src/stm32g4xx_hal_msp.c deleted file mode 100644 index 69189ef4e..000000000 --- a/G4FANCYCANTESTING/Core/Src/stm32g4xx_hal_msp.c +++ /dev/null @@ -1,86 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_msp.c - * @brief This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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*/ - - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); - - /* USER CODE BEGIN MspInit 1 */ - - /* USER CODE END MspInit 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4FANCYCANTESTING/Core/Src/stm32g4xx_it.c b/G4FANCYCANTESTING/Core/Src/stm32g4xx_it.c deleted file mode 100644 index dd322200e..000000000 --- a/G4FANCYCANTESTING/Core/Src/stm32g4xx_it.c +++ /dev/null @@ -1,194 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "stm32g4xx_it.h" - -#include "main.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 --------------------------------------------------------*/ -// extern FDCAN_HandleTypeDef hfdcan2; -/* 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 Prefetch 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 */ -} - -/******************************************************************************/ -/* STM32G4xx 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_stm32g4xx.s). */ -/******************************************************************************/ diff --git a/G4FANCYCANTESTING/Core/Src/tim.c b/G4FANCYCANTESTING/Core/Src/tim.c deleted file mode 100644 index 7f521c3bf..000000000 --- a/G4FANCYCANTESTING/Core/Src/tim.c +++ /dev/null @@ -1,79 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file tim.c - * @brief This file provides code for the configuration - * of the TIM instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "tim.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* TIM2 init function */ -void MX_TIM2_Init(void) -{ - - /* USER CODE BEGIN TIM2_Init 0 */ - - /* USER CODE END TIM2_Init 0 */ - - LL_TIM_InitTypeDef TIM_InitStruct = {0}; - LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2); - - /* USER CODE BEGIN TIM2_Init 1 */ - - /* USER CODE END TIM2_Init 1 */ - TIM_InitStruct.Prescaler = 0; - TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; - TIM_InitStruct.Autoreload = 4294967295; - TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; - LL_TIM_Init(TIM2, &TIM_InitStruct); - LL_TIM_DisableARRPreload(TIM2); - LL_TIM_SetClockSource(TIM2, LL_TIM_CLOCKSOURCE_INTERNAL); - TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_FORCED_ACTIVE; - TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; - TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; - TIM_OC_InitStruct.CompareValue = 0; - TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; - LL_TIM_OC_Init(TIM2, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct); - LL_TIM_OC_DisableFast(TIM2, LL_TIM_CHANNEL_CH1); - LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_RESET); - LL_TIM_DisableMasterSlaveMode(TIM2); - /* USER CODE BEGIN TIM2_Init 2 */ - - /* USER CODE END TIM2_Init 2 */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - /**TIM2 GPIO Configuration - PA0 ------> TIM2_CH1 - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_1; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4FANCYCANTESTING/Core/Src/usart.c b/G4FANCYCANTESTING/Core/Src/usart.c deleted file mode 100644 index 41561862c..000000000 --- a/G4FANCYCANTESTING/Core/Src/usart.c +++ /dev/null @@ -1,184 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file usart.c - * @brief This file provides code for the configuration - * of the USART instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "usart.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* LPUART1 init function */ - -void MX_LPUART1_UART_Init(void) -{ - - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - LL_LPUART_InitTypeDef LPUART_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_HSI); - - /* Peripheral clock enable */ - LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_LPUART1); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_12; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_12; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - LPUART_InitStruct.PrescalerValue = LL_LPUART_PRESCALER_DIV1; - LPUART_InitStruct.BaudRate = 115200; - LPUART_InitStruct.DataWidth = LL_LPUART_DATAWIDTH_8B; - LPUART_InitStruct.StopBits = LL_LPUART_STOPBITS_1; - LPUART_InitStruct.Parity = LL_LPUART_PARITY_NONE; - LPUART_InitStruct.TransferDirection = LL_LPUART_DIRECTION_TX_RX; - LPUART_InitStruct.HardwareFlowControl = LL_LPUART_HWCONTROL_NONE; - LL_LPUART_Init(LPUART1, &LPUART_InitStruct); - LL_LPUART_SetTXFIFOThreshold(LPUART1, LL_LPUART_FIFOTHRESHOLD_1_8); - LL_LPUART_SetRXFIFOThreshold(LPUART1, LL_LPUART_FIFOTHRESHOLD_1_8); - LL_LPUART_DisableFIFO(LPUART1); - - /* USER CODE BEGIN WKUPType LPUART1 */ - - /* USER CODE END WKUPType LPUART1 */ - - LL_LPUART_Enable(LPUART1); - - /* Polling LPUART1 initialisation */ - while ((!(LL_LPUART_IsActiveFlag_TEACK(LPUART1))) || (!(LL_LPUART_IsActiveFlag_REACK(LPUART1)))) {} - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ -} -/* USART1 init function */ - -void MX_USART1_UART_Init(void) -{ - - /* USER CODE BEGIN USART1_Init 0 */ - - /* USER CODE END USART1_Init 0 */ - - LL_USART_InitTypeDef USART_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2); - - /* Peripheral clock enable */ - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - /**USART1 GPIO Configuration - PC5 ------> USART1_RX - PA11 ------> USART1_CTS - PA12 ------> USART1_RTS - PB6 ------> USART1_TX - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* USER CODE BEGIN USART1_Init 1 */ - - /* USER CODE END USART1_Init 1 */ - USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1; - USART_InitStruct.BaudRate = 115200; - USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; - USART_InitStruct.StopBits = LL_USART_STOPBITS_1; - USART_InitStruct.Parity = LL_USART_PARITY_NONE; - USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX; - USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_RTS_CTS; - USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16; - LL_USART_Init(USART1, &USART_InitStruct); - LL_USART_SetTXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8); - LL_USART_SetRXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8); - LL_USART_DisableFIFO(USART1); - LL_USART_ConfigAsyncMode(USART1); - - /* USER CODE BEGIN WKUPType USART1 */ - - /* USER CODE END WKUPType USART1 */ - - LL_USART_Enable(USART1); - - /* Polling USART1 initialisation */ - while ((!(LL_USART_IsActiveFlag_TEACK(USART1))) || (!(LL_USART_IsActiveFlag_REACK(USART1)))) {} - /* USER CODE BEGIN USART1_Init 2 */ - - /* USER CODE END USART1_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4NEOTESTING/Core/Inc/stm32g4xx_hal_conf.h b/G4NEOTESTING/Core/Inc/stm32g4xx_hal_conf.h deleted file mode 100644 index 3e1fcb018..000000000 --- a/G4NEOTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ /dev/null @@ -1,390 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_conf.h - * @author MCD Application Team - * @brief HAL configuration file - ****************************************************************************** - * @attention - * - * Copyright (c) 2019 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 STM32G4xx_HAL_CONF_H -#define STM32G4xx_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_ADC_MODULE_ENABLED */ -/*#define HAL_COMP_MODULE_ENABLED */ -/*#define HAL_CORDIC_MODULE_ENABLED */ -#define HAL_CRC_MODULE_ENABLED -/*#define HAL_CRYP_MODULE_ENABLED */ -/*#define HAL_DAC_MODULE_ENABLED */ -#define HAL_FDCAN_MODULE_ENABLED -/*#define HAL_FMAC_MODULE_ENABLED */ -/*#define HAL_HRTIM_MODULE_ENABLED */ -/*#define HAL_IRDA_MODULE_ENABLED */ -/*#define HAL_IWDG_MODULE_ENABLED */ -/*#define HAL_I2C_MODULE_ENABLED */ -/*#define HAL_I2S_MODULE_ENABLED */ -/*#define HAL_LPTIM_MODULE_ENABLED */ -/*#define HAL_NAND_MODULE_ENABLED */ -/*#define HAL_NOR_MODULE_ENABLED */ -/*#define HAL_OPAMP_MODULE_ENABLED */ -/*#define HAL_PCD_MODULE_ENABLED */ -/*#define HAL_QSPI_MODULE_ENABLED */ -/*#define HAL_RNG_MODULE_ENABLED */ -/*#define HAL_RTC_MODULE_ENABLED */ -/*#define HAL_SAI_MODULE_ENABLED */ -/*#define HAL_SMARTCARD_MODULE_ENABLED */ -/*#define HAL_SMBUS_MODULE_ENABLED */ -/*#define HAL_SPI_MODULE_ENABLED */ -/*#define HAL_SRAM_MODULE_ENABLED */ -/*#define HAL_TIM_MODULE_ENABLED */ -/*#define HAL_UART_MODULE_ENABLED */ -/*#define HAL_USART_MODULE_ENABLED */ -/*#define HAL_WWDG_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 - -/* ########################## Register Callbacks selection - * ############################## */ -/** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U - -/* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(HSE_STARTUP_TIMEOUT) -#define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ - -/** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high - * precision clock to the USB peripheral by means of a special Clock Recovery - * System (CRS) circuitry. When the CRS is not used, the HSI48 RC oscillator - * runs on it default frequency which is subject to manufacturing process - * variations. - */ -#if !defined(HSI48_VALUE) -#define HSI48_VALUE \ - (48000000UL) /*!< Value of the Internal High Speed oscillator for USB \ - FS/RNG in Hz. The real value my vary depending on \ - manufacturing process variations.*/ -#endif /* HSI48_VALUE */ - -/** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined(LSI_VALUE) -/*!< Value of the Internal Low Speed oscillator in Hz -The real value may vary depending on the variations in voltage and -temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ -/** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system - * frequency - */ -#if !defined(LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ - -#if !defined(LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ - -/** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S - * and SAI clock source frequency, this source is inserted directly through - * I2S_CKIN pad. - */ -#if !defined(EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U - -/* ########################## Assert Selection ############################## */ -/** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -/* #define USE_FULL_ASSERT 1U */ - -/* ################## 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 "stm32g4xx_hal_rcc.h" -#endif /* HAL_RCC_MODULE_ENABLED */ - -#ifdef HAL_GPIO_MODULE_ENABLED -#include "stm32g4xx_hal_gpio.h" -#endif /* HAL_GPIO_MODULE_ENABLED */ - -#ifdef HAL_DMA_MODULE_ENABLED -#include "stm32g4xx_hal_dma.h" -#endif /* HAL_DMA_MODULE_ENABLED */ - -#ifdef HAL_CORTEX_MODULE_ENABLED -#include "stm32g4xx_hal_cortex.h" -#endif /* HAL_CORTEX_MODULE_ENABLED */ - -#ifdef HAL_ADC_MODULE_ENABLED -#include "stm32g4xx_hal_adc.h" -#endif /* HAL_ADC_MODULE_ENABLED */ - -#ifdef HAL_COMP_MODULE_ENABLED -#include "stm32g4xx_hal_comp.h" -#endif /* HAL_COMP_MODULE_ENABLED */ - -#ifdef HAL_CORDIC_MODULE_ENABLED -#include "stm32g4xx_hal_cordic.h" -#endif /* HAL_CORDIC_MODULE_ENABLED */ - -#ifdef HAL_CRC_MODULE_ENABLED -#include "stm32g4xx_hal_crc.h" -#endif /* HAL_CRC_MODULE_ENABLED */ - -#ifdef HAL_CRYP_MODULE_ENABLED -#include "stm32g4xx_hal_cryp.h" -#endif /* HAL_CRYP_MODULE_ENABLED */ - -#ifdef HAL_DAC_MODULE_ENABLED -#include "stm32g4xx_hal_dac.h" -#endif /* HAL_DAC_MODULE_ENABLED */ - -#ifdef HAL_EXTI_MODULE_ENABLED -#include "stm32g4xx_hal_exti.h" -#endif /* HAL_EXTI_MODULE_ENABLED */ - -#ifdef HAL_FDCAN_MODULE_ENABLED -#include "stm32g4xx_hal_fdcan.h" -#endif /* HAL_FDCAN_MODULE_ENABLED */ - -#ifdef HAL_FLASH_MODULE_ENABLED -#include "stm32g4xx_hal_flash.h" -#endif /* HAL_FLASH_MODULE_ENABLED */ - -#ifdef HAL_FMAC_MODULE_ENABLED -#include "stm32g4xx_hal_fmac.h" -#endif /* HAL_FMAC_MODULE_ENABLED */ - -#ifdef HAL_HRTIM_MODULE_ENABLED -#include "stm32g4xx_hal_hrtim.h" -#endif /* HAL_HRTIM_MODULE_ENABLED */ - -#ifdef HAL_IRDA_MODULE_ENABLED -#include "stm32g4xx_hal_irda.h" -#endif /* HAL_IRDA_MODULE_ENABLED */ - -#ifdef HAL_IWDG_MODULE_ENABLED -#include "stm32g4xx_hal_iwdg.h" -#endif /* HAL_IWDG_MODULE_ENABLED */ - -#ifdef HAL_I2C_MODULE_ENABLED -#include "stm32g4xx_hal_i2c.h" -#endif /* HAL_I2C_MODULE_ENABLED */ - -#ifdef HAL_I2S_MODULE_ENABLED -#include "stm32g4xx_hal_i2s.h" -#endif /* HAL_I2S_MODULE_ENABLED */ - -#ifdef HAL_LPTIM_MODULE_ENABLED -#include "stm32g4xx_hal_lptim.h" -#endif /* HAL_LPTIM_MODULE_ENABLED */ - -#ifdef HAL_NAND_MODULE_ENABLED -#include "stm32g4xx_hal_nand.h" -#endif /* HAL_NAND_MODULE_ENABLED */ - -#ifdef HAL_NOR_MODULE_ENABLED -#include "stm32g4xx_hal_nor.h" -#endif /* HAL_NOR_MODULE_ENABLED */ - -#ifdef HAL_OPAMP_MODULE_ENABLED -#include "stm32g4xx_hal_opamp.h" -#endif /* HAL_OPAMP_MODULE_ENABLED */ - -#ifdef HAL_PCD_MODULE_ENABLED -#include "stm32g4xx_hal_pcd.h" -#endif /* HAL_PCD_MODULE_ENABLED */ - -#ifdef HAL_PWR_MODULE_ENABLED -#include "stm32g4xx_hal_pwr.h" -#endif /* HAL_PWR_MODULE_ENABLED */ - -#ifdef HAL_QSPI_MODULE_ENABLED -#include "stm32g4xx_hal_qspi.h" -#endif /* HAL_QSPI_MODULE_ENABLED */ - -#ifdef HAL_RNG_MODULE_ENABLED -#include "stm32g4xx_hal_rng.h" -#endif /* HAL_RNG_MODULE_ENABLED */ - -#ifdef HAL_RTC_MODULE_ENABLED -#include "stm32g4xx_hal_rtc.h" -#endif /* HAL_RTC_MODULE_ENABLED */ - -#ifdef HAL_SAI_MODULE_ENABLED -#include "stm32g4xx_hal_sai.h" -#endif /* HAL_SAI_MODULE_ENABLED */ - -#ifdef HAL_SMARTCARD_MODULE_ENABLED -#include "stm32g4xx_hal_smartcard.h" -#endif /* HAL_SMARTCARD_MODULE_ENABLED */ - -#ifdef HAL_SMBUS_MODULE_ENABLED -#include "stm32g4xx_hal_smbus.h" -#endif /* HAL_SMBUS_MODULE_ENABLED */ - -#ifdef HAL_SPI_MODULE_ENABLED -#include "stm32g4xx_hal_spi.h" -#endif /* HAL_SPI_MODULE_ENABLED */ - -#ifdef HAL_SRAM_MODULE_ENABLED -#include "stm32g4xx_hal_sram.h" -#endif /* HAL_SRAM_MODULE_ENABLED */ - -#ifdef HAL_TIM_MODULE_ENABLED -#include "stm32g4xx_hal_tim.h" -#endif /* HAL_TIM_MODULE_ENABLED */ - -#ifdef HAL_UART_MODULE_ENABLED -#include "stm32g4xx_hal_uart.h" -#endif /* HAL_UART_MODULE_ENABLED */ - -#ifdef HAL_USART_MODULE_ENABLED -#include "stm32g4xx_hal_usart.h" -#endif /* HAL_USART_MODULE_ENABLED */ - -#ifdef HAL_WWDG_MODULE_ENABLED -#include "stm32g4xx_hal_wwdg.h" -#endif /* HAL_WWDG_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 /* STM32G4xx_HAL_CONF_H */ diff --git a/G4NEOTESTING/Core/Inc/stm32g4xx_it.h b/G4NEOTESTING/Core/Inc/stm32g4xx_it.h deleted file mode 100644 index b6c3b2f72..000000000 --- a/G4NEOTESTING/Core/Inc/stm32g4xx_it.h +++ /dev/null @@ -1,67 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_it.h - * @brief This file contains the headers of the interrupt handlers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __STM32G4xx_IT_H -#define __STM32G4xx_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); -void FDCAN2_IT0_IRQHandler(void); -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32G4xx_IT_H */ diff --git a/G4NEOTESTING/Core/Src/stm32g4xx_hal_msp.c b/G4NEOTESTING/Core/Src/stm32g4xx_hal_msp.c deleted file mode 100644 index 69189ef4e..000000000 --- a/G4NEOTESTING/Core/Src/stm32g4xx_hal_msp.c +++ /dev/null @@ -1,86 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_msp.c - * @brief This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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*/ - - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); - - /* USER CODE BEGIN MspInit 1 */ - - /* USER CODE END MspInit 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4PERTESTING/CMakeLists.txt b/G4PERTESTING/CMakeLists.txt deleted file mode 100644 index e9af49b58..000000000 --- a/G4PERTESTING/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -# Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) - -# Define the build type -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug") -endif() - -# Enable compile command to ease indexing with e.g. clangd -set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) - -# Enable CMake support for ASM and C languages -enable_language( - C - ASM -) - -# Core project settings -project(${CMAKE_PROJECT_NAME}) - -# what, does in fact not get the filename of somthing but rather the name of the project from the path -get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) - -add_library(${PROJECT_NAME}_USER_CODE INTERFACE) -target_sources( - ${PROJECT_NAME}_USER_CODE - INTERFACE - Core/Src/adc.c - Core/Src/crc.c - Core/Src/dma.c - Core/Src/fdcan.c - Core/Src/gpio.c - Core/Src/i2c.c - Core/Src/main.c - Core/Src/spi.c - Core/Src/stm32g4xx_hal_msp.c - Core/Src/stm32g4xx_it.c - Core/Src/tim.c - Core/Src/usart.c -) - -target_link_libraries(${PROJECT_NAME}_USER_CODE INTERFACE LOGOMATIC_OLD_LIB) - -target_include_directories(${PROJECT_NAME}_USER_CODE INTERFACE Core/Inc) diff --git a/G4PERTESTING/Core/Inc/adc.h b/G4PERTESTING/Core/Inc/adc.h deleted file mode 100644 index 41154538b..000000000 --- a/G4PERTESTING/Core/Inc/adc.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file adc.h - * @brief This file contains all the function prototypes for - * the adc.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __ADC_H__ -#define __ADC_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_ADC1_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __ADC_H__ */ diff --git a/G4PERTESTING/Core/Inc/crc.h b/G4PERTESTING/Core/Inc/crc.h deleted file mode 100644 index 133957e92..000000000 --- a/G4PERTESTING/Core/Inc/crc.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file crc.h - * @brief This file contains all the function prototypes for - * the crc.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __CRC_H__ -#define __CRC_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern CRC_HandleTypeDef hcrc; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_CRC_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CRC_H__ */ diff --git a/G4PERTESTING/Core/Inc/dma.h b/G4PERTESTING/Core/Inc/dma.h deleted file mode 100644 index ae819cab4..000000000 --- a/G4PERTESTING/Core/Inc/dma.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file dma.h - * @brief This file contains all the function prototypes for - * the dma.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __DMA_H__ -#define __DMA_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* DMA memory to memory transfer handles -------------------------------------*/ - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_DMA_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __DMA_H__ */ diff --git a/G4PERTESTING/Core/Inc/fdcan.h b/G4PERTESTING/Core/Inc/fdcan.h deleted file mode 100644 index 56c4a8adb..000000000 --- a/G4PERTESTING/Core/Inc/fdcan.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file fdcan.h - * @brief This file contains all the function prototypes for - * the fdcan.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __FDCAN_H__ -#define __FDCAN_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern FDCAN_HandleTypeDef hfdcan2; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_FDCAN2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __FDCAN_H__ */ diff --git a/G4PERTESTING/Core/Inc/gpio.h b/G4PERTESTING/Core/Inc/gpio.h deleted file mode 100644 index 843d4e9e7..000000000 --- a/G4PERTESTING/Core/Inc/gpio.h +++ /dev/null @@ -1,48 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file gpio.h - * @brief This file contains all the function prototypes for - * the gpio.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __GPIO_H__ -#define __GPIO_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_GPIO_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif -#endif /*__ GPIO_H__ */ diff --git a/G4PERTESTING/Core/Inc/i2c.h b/G4PERTESTING/Core/Inc/i2c.h deleted file mode 100644 index 0a0a50803..000000000 --- a/G4PERTESTING/Core/Inc/i2c.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file i2c.h - * @brief This file contains all the function prototypes for - * the i2c.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __I2C_H__ -#define __I2C_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_I2C2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __I2C_H__ */ diff --git a/G4PERTESTING/Core/Inc/main.h b/G4PERTESTING/Core/Inc/main.h deleted file mode 100644 index 23d7ffce4..000000000 --- a/G4PERTESTING/Core/Inc/main.h +++ /dev/null @@ -1,115 +0,0 @@ -/* 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) 2024 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 "stm32g4xx_hal.h" -#include "stm32g4xx_ll_adc.h" -#include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_dma.h" -#include "stm32g4xx_ll_exti.h" -#include "stm32g4xx_ll_gpio.h" -#include "stm32g4xx_ll_i2c.h" -#include "stm32g4xx_ll_lpuart.h" -#include "stm32g4xx_ll_pwr.h" -#include "stm32g4xx_ll_rcc.h" -#include "stm32g4xx_ll_spi.h" -#include "stm32g4xx_ll_system.h" -#include "stm32g4xx_ll_tim.h" -#include "stm32g4xx_ll_usart.h" -#include "stm32g4xx_ll_utils.h" - -/* 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 Error_Handler(void); - -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -/* Private defines -----------------------------------------------------------*/ -#define BSPD_SIGNAL_Pin LL_GPIO_PIN_1 -#define BSPD_SIGNAL_GPIO_Port GPIOC -#define APPS1_SIGNAL_Pin LL_GPIO_PIN_2 -#define APPS1_SIGNAL_GPIO_Port GPIOC -#define APPS2_SIGNAL_Pin LL_GPIO_PIN_3 -#define APPS2_SIGNAL_GPIO_Port GPIOC -#define BLINKY_Pin LL_GPIO_PIN_5 -#define BLINKY_GPIO_Port GPIOA -#define IMD_SENSE_Pin LL_GPIO_PIN_6 -#define IMD_SENSE_GPIO_Port GPIOA -#define AMS_SENSE_Pin LL_GPIO_PIN_7 -#define AMS_SENSE_GPIO_Port GPIOA -#define BRAKE_F_SIGNAL_Pin LL_GPIO_PIN_0 -#define BRAKE_F_SIGNAL_GPIO_Port GPIOB -#define BRAKE_R_SIGNAL_Pin LL_GPIO_PIN_1 -#define BRAKE_R_SIGNAL_GPIO_Port GPIOB -#define LED_TEST_Pin LL_GPIO_PIN_11 -#define LED_TEST_GPIO_Port GPIOB -#define AUX_SIGNAL_Pin LL_GPIO_PIN_14 -#define AUX_SIGNAL_GPIO_Port GPIOB -#define STEERING_ANGLE_Pin LL_GPIO_PIN_15 -#define STEERING_ANGLE_GPIO_Port GPIOB -#define BRAKE_LIGHT_Pin LL_GPIO_PIN_4 -#define BRAKE_LIGHT_GPIO_Port GPIOB -#define TSSI_G_CONTROL_Pin LL_GPIO_PIN_5 -#define TSSI_G_CONTROL_GPIO_Port GPIOB -#define AUX_CONTROL_Pin LL_GPIO_PIN_8 -#define AUX_CONTROL_GPIO_Port GPIOB -#define SOFTWARE_OK_CONTROL_Pin LL_GPIO_PIN_9 -#define SOFTWARE_OK_CONTROL_GPIO_Port GPIOB - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -#ifdef __cplusplus -} -#endif - -#endif /* __MAIN_H */ diff --git a/G4PERTESTING/Core/Inc/spi.h b/G4PERTESTING/Core/Inc/spi.h deleted file mode 100644 index 74bed003b..000000000 --- a/G4PERTESTING/Core/Inc/spi.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file spi.h - * @brief This file contains all the function prototypes for - * the spi.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __SPI_H__ -#define __SPI_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_SPI3_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __SPI_H__ */ diff --git a/G4PERTESTING/Core/Inc/stm32g4xx_hal_conf.h b/G4PERTESTING/Core/Inc/stm32g4xx_hal_conf.h deleted file mode 100644 index 3e1fcb018..000000000 --- a/G4PERTESTING/Core/Inc/stm32g4xx_hal_conf.h +++ /dev/null @@ -1,390 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_conf.h - * @author MCD Application Team - * @brief HAL configuration file - ****************************************************************************** - * @attention - * - * Copyright (c) 2019 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 STM32G4xx_HAL_CONF_H -#define STM32G4xx_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_ADC_MODULE_ENABLED */ -/*#define HAL_COMP_MODULE_ENABLED */ -/*#define HAL_CORDIC_MODULE_ENABLED */ -#define HAL_CRC_MODULE_ENABLED -/*#define HAL_CRYP_MODULE_ENABLED */ -/*#define HAL_DAC_MODULE_ENABLED */ -#define HAL_FDCAN_MODULE_ENABLED -/*#define HAL_FMAC_MODULE_ENABLED */ -/*#define HAL_HRTIM_MODULE_ENABLED */ -/*#define HAL_IRDA_MODULE_ENABLED */ -/*#define HAL_IWDG_MODULE_ENABLED */ -/*#define HAL_I2C_MODULE_ENABLED */ -/*#define HAL_I2S_MODULE_ENABLED */ -/*#define HAL_LPTIM_MODULE_ENABLED */ -/*#define HAL_NAND_MODULE_ENABLED */ -/*#define HAL_NOR_MODULE_ENABLED */ -/*#define HAL_OPAMP_MODULE_ENABLED */ -/*#define HAL_PCD_MODULE_ENABLED */ -/*#define HAL_QSPI_MODULE_ENABLED */ -/*#define HAL_RNG_MODULE_ENABLED */ -/*#define HAL_RTC_MODULE_ENABLED */ -/*#define HAL_SAI_MODULE_ENABLED */ -/*#define HAL_SMARTCARD_MODULE_ENABLED */ -/*#define HAL_SMBUS_MODULE_ENABLED */ -/*#define HAL_SPI_MODULE_ENABLED */ -/*#define HAL_SRAM_MODULE_ENABLED */ -/*#define HAL_TIM_MODULE_ENABLED */ -/*#define HAL_UART_MODULE_ENABLED */ -/*#define HAL_USART_MODULE_ENABLED */ -/*#define HAL_WWDG_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 - -/* ########################## Register Callbacks selection - * ############################## */ -/** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U - -/* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(HSE_STARTUP_TIMEOUT) -#define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ - -/** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high - * precision clock to the USB peripheral by means of a special Clock Recovery - * System (CRS) circuitry. When the CRS is not used, the HSI48 RC oscillator - * runs on it default frequency which is subject to manufacturing process - * variations. - */ -#if !defined(HSI48_VALUE) -#define HSI48_VALUE \ - (48000000UL) /*!< Value of the Internal High Speed oscillator for USB \ - FS/RNG in Hz. The real value my vary depending on \ - manufacturing process variations.*/ -#endif /* HSI48_VALUE */ - -/** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined(LSI_VALUE) -/*!< Value of the Internal Low Speed oscillator in Hz -The real value may vary depending on the variations in voltage and -temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ -/** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system - * frequency - */ -#if !defined(LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ - -#if !defined(LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ - -/** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S - * and SAI clock source frequency, this source is inserted directly through - * I2S_CKIN pad. - */ -#if !defined(EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U - -/* ########################## Assert Selection ############################## */ -/** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -/* #define USE_FULL_ASSERT 1U */ - -/* ################## 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 "stm32g4xx_hal_rcc.h" -#endif /* HAL_RCC_MODULE_ENABLED */ - -#ifdef HAL_GPIO_MODULE_ENABLED -#include "stm32g4xx_hal_gpio.h" -#endif /* HAL_GPIO_MODULE_ENABLED */ - -#ifdef HAL_DMA_MODULE_ENABLED -#include "stm32g4xx_hal_dma.h" -#endif /* HAL_DMA_MODULE_ENABLED */ - -#ifdef HAL_CORTEX_MODULE_ENABLED -#include "stm32g4xx_hal_cortex.h" -#endif /* HAL_CORTEX_MODULE_ENABLED */ - -#ifdef HAL_ADC_MODULE_ENABLED -#include "stm32g4xx_hal_adc.h" -#endif /* HAL_ADC_MODULE_ENABLED */ - -#ifdef HAL_COMP_MODULE_ENABLED -#include "stm32g4xx_hal_comp.h" -#endif /* HAL_COMP_MODULE_ENABLED */ - -#ifdef HAL_CORDIC_MODULE_ENABLED -#include "stm32g4xx_hal_cordic.h" -#endif /* HAL_CORDIC_MODULE_ENABLED */ - -#ifdef HAL_CRC_MODULE_ENABLED -#include "stm32g4xx_hal_crc.h" -#endif /* HAL_CRC_MODULE_ENABLED */ - -#ifdef HAL_CRYP_MODULE_ENABLED -#include "stm32g4xx_hal_cryp.h" -#endif /* HAL_CRYP_MODULE_ENABLED */ - -#ifdef HAL_DAC_MODULE_ENABLED -#include "stm32g4xx_hal_dac.h" -#endif /* HAL_DAC_MODULE_ENABLED */ - -#ifdef HAL_EXTI_MODULE_ENABLED -#include "stm32g4xx_hal_exti.h" -#endif /* HAL_EXTI_MODULE_ENABLED */ - -#ifdef HAL_FDCAN_MODULE_ENABLED -#include "stm32g4xx_hal_fdcan.h" -#endif /* HAL_FDCAN_MODULE_ENABLED */ - -#ifdef HAL_FLASH_MODULE_ENABLED -#include "stm32g4xx_hal_flash.h" -#endif /* HAL_FLASH_MODULE_ENABLED */ - -#ifdef HAL_FMAC_MODULE_ENABLED -#include "stm32g4xx_hal_fmac.h" -#endif /* HAL_FMAC_MODULE_ENABLED */ - -#ifdef HAL_HRTIM_MODULE_ENABLED -#include "stm32g4xx_hal_hrtim.h" -#endif /* HAL_HRTIM_MODULE_ENABLED */ - -#ifdef HAL_IRDA_MODULE_ENABLED -#include "stm32g4xx_hal_irda.h" -#endif /* HAL_IRDA_MODULE_ENABLED */ - -#ifdef HAL_IWDG_MODULE_ENABLED -#include "stm32g4xx_hal_iwdg.h" -#endif /* HAL_IWDG_MODULE_ENABLED */ - -#ifdef HAL_I2C_MODULE_ENABLED -#include "stm32g4xx_hal_i2c.h" -#endif /* HAL_I2C_MODULE_ENABLED */ - -#ifdef HAL_I2S_MODULE_ENABLED -#include "stm32g4xx_hal_i2s.h" -#endif /* HAL_I2S_MODULE_ENABLED */ - -#ifdef HAL_LPTIM_MODULE_ENABLED -#include "stm32g4xx_hal_lptim.h" -#endif /* HAL_LPTIM_MODULE_ENABLED */ - -#ifdef HAL_NAND_MODULE_ENABLED -#include "stm32g4xx_hal_nand.h" -#endif /* HAL_NAND_MODULE_ENABLED */ - -#ifdef HAL_NOR_MODULE_ENABLED -#include "stm32g4xx_hal_nor.h" -#endif /* HAL_NOR_MODULE_ENABLED */ - -#ifdef HAL_OPAMP_MODULE_ENABLED -#include "stm32g4xx_hal_opamp.h" -#endif /* HAL_OPAMP_MODULE_ENABLED */ - -#ifdef HAL_PCD_MODULE_ENABLED -#include "stm32g4xx_hal_pcd.h" -#endif /* HAL_PCD_MODULE_ENABLED */ - -#ifdef HAL_PWR_MODULE_ENABLED -#include "stm32g4xx_hal_pwr.h" -#endif /* HAL_PWR_MODULE_ENABLED */ - -#ifdef HAL_QSPI_MODULE_ENABLED -#include "stm32g4xx_hal_qspi.h" -#endif /* HAL_QSPI_MODULE_ENABLED */ - -#ifdef HAL_RNG_MODULE_ENABLED -#include "stm32g4xx_hal_rng.h" -#endif /* HAL_RNG_MODULE_ENABLED */ - -#ifdef HAL_RTC_MODULE_ENABLED -#include "stm32g4xx_hal_rtc.h" -#endif /* HAL_RTC_MODULE_ENABLED */ - -#ifdef HAL_SAI_MODULE_ENABLED -#include "stm32g4xx_hal_sai.h" -#endif /* HAL_SAI_MODULE_ENABLED */ - -#ifdef HAL_SMARTCARD_MODULE_ENABLED -#include "stm32g4xx_hal_smartcard.h" -#endif /* HAL_SMARTCARD_MODULE_ENABLED */ - -#ifdef HAL_SMBUS_MODULE_ENABLED -#include "stm32g4xx_hal_smbus.h" -#endif /* HAL_SMBUS_MODULE_ENABLED */ - -#ifdef HAL_SPI_MODULE_ENABLED -#include "stm32g4xx_hal_spi.h" -#endif /* HAL_SPI_MODULE_ENABLED */ - -#ifdef HAL_SRAM_MODULE_ENABLED -#include "stm32g4xx_hal_sram.h" -#endif /* HAL_SRAM_MODULE_ENABLED */ - -#ifdef HAL_TIM_MODULE_ENABLED -#include "stm32g4xx_hal_tim.h" -#endif /* HAL_TIM_MODULE_ENABLED */ - -#ifdef HAL_UART_MODULE_ENABLED -#include "stm32g4xx_hal_uart.h" -#endif /* HAL_UART_MODULE_ENABLED */ - -#ifdef HAL_USART_MODULE_ENABLED -#include "stm32g4xx_hal_usart.h" -#endif /* HAL_USART_MODULE_ENABLED */ - -#ifdef HAL_WWDG_MODULE_ENABLED -#include "stm32g4xx_hal_wwdg.h" -#endif /* HAL_WWDG_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 /* STM32G4xx_HAL_CONF_H */ diff --git a/G4PERTESTING/Core/Inc/stm32g4xx_it.h b/G4PERTESTING/Core/Inc/stm32g4xx_it.h deleted file mode 100644 index b6c3b2f72..000000000 --- a/G4PERTESTING/Core/Inc/stm32g4xx_it.h +++ /dev/null @@ -1,67 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_it.h - * @brief This file contains the headers of the interrupt handlers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __STM32G4xx_IT_H -#define __STM32G4xx_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); -void FDCAN2_IT0_IRQHandler(void); -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32G4xx_IT_H */ diff --git a/G4PERTESTING/Core/Inc/tim.h b/G4PERTESTING/Core/Inc/tim.h deleted file mode 100644 index c19e6cc71..000000000 --- a/G4PERTESTING/Core/Inc/tim.h +++ /dev/null @@ -1,49 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file tim.h - * @brief This file contains all the function prototypes for - * the tim.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __TIM_H__ -#define __TIM_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_TIM2_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __TIM_H__ */ diff --git a/G4PERTESTING/Core/Inc/usart.h b/G4PERTESTING/Core/Inc/usart.h deleted file mode 100644 index daefd73e6..000000000 --- a/G4PERTESTING/Core/Inc/usart.h +++ /dev/null @@ -1,50 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file usart.h - * @brief This file contains all the function prototypes for - * the usart.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 __USART_H__ -#define __USART_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_LPUART1_UART_Init(void); -void MX_USART1_UART_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USART_H__ */ diff --git a/G4PERTESTING/Core/Src/adc.c b/G4PERTESTING/Core/Src/adc.c deleted file mode 100644 index f3dbff8ed..000000000 --- a/G4PERTESTING/Core/Src/adc.c +++ /dev/null @@ -1,186 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file adc.c - * @brief This file provides code for the configuration - * of the ADC instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "adc.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* ADC1 init function */ -void MX_ADC1_Init(void) -{ - - /* USER CODE BEGIN ADC1_Init 0 */ - - /* USER CODE END ADC1_Init 0 */ - - LL_ADC_InitTypeDef ADC_InitStruct = {0}; - LL_ADC_REG_InitTypeDef ADC_REG_InitStruct = {0}; - LL_ADC_CommonInitTypeDef ADC_CommonInitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetADCClockSource(LL_RCC_ADC12_CLKSOURCE_SYSCLK); - - /* Peripheral clock enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_ADC12); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - /**ADC1 GPIO Configuration - PC1 ------> ADC1_IN7 - PC2 ------> ADC1_IN8 - PC3 ------> ADC1_IN9 - PB0 ------> ADC1_IN15 - PB1 ------> ADC1_IN12 - PB14 ------> ADC1_IN5 - */ - GPIO_InitStruct.Pin = BSPD_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BSPD_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = APPS1_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(APPS1_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = APPS2_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(APPS2_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = BRAKE_F_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_F_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = BRAKE_R_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_R_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = AUX_SIGNAL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AUX_SIGNAL_GPIO_Port, &GPIO_InitStruct); - - /* ADC1 DMA Init */ - - /* ADC1 Init */ - LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_1, LL_DMAMUX_REQ_ADC1); - - LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_1, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); - - LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PRIORITY_LOW); - - LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_CIRCULAR); - - LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PERIPH_NOINCREMENT); - - LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT); - - LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_HALFWORD); - - LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_HALFWORD); - - /* USER CODE BEGIN ADC1_Init 1 */ - - /* USER CODE END ADC1_Init 1 */ - - /** Common config - */ - ADC_InitStruct.Resolution = LL_ADC_RESOLUTION_12B; - ADC_InitStruct.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT; - ADC_InitStruct.LowPowerMode = LL_ADC_LP_MODE_NONE; - LL_ADC_Init(ADC1, &ADC_InitStruct); - ADC_REG_InitStruct.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE; - ADC_REG_InitStruct.SequencerLength = LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS; - ADC_REG_InitStruct.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE; - ADC_REG_InitStruct.ContinuousMode = LL_ADC_REG_CONV_CONTINUOUS; - ADC_REG_InitStruct.DMATransfer = LL_ADC_REG_DMA_TRANSFER_UNLIMITED; - ADC_REG_InitStruct.Overrun = LL_ADC_REG_OVR_DATA_PRESERVED; - LL_ADC_REG_Init(ADC1, &ADC_REG_InitStruct); - LL_ADC_SetGainCompensation(ADC1, 0); - LL_ADC_SetOverSamplingScope(ADC1, LL_ADC_OVS_DISABLE); - ADC_CommonInitStruct.CommonClock = LL_ADC_CLOCK_ASYNC_DIV256; - ADC_CommonInitStruct.Multimode = LL_ADC_MULTI_INDEPENDENT; - LL_ADC_CommonInit(__LL_ADC_COMMON_INSTANCE(ADC1), &ADC_CommonInitStruct); - - /* Disable ADC deep power down (enabled by default after reset state) */ - LL_ADC_DisableDeepPowerDown(ADC1); - /* Enable ADC internal voltage regulator */ - LL_ADC_EnableInternalRegulator(ADC1); - /* Delay for ADC internal voltage regulator stabilization. */ - /* Compute number of CPU cycles to wait for, from delay in us. */ - /* Note: Variable divided by 2 to compensate partially */ - /* CPU processing cycles (depends on compilation optimization). */ - /* Note: If system core clock frequency is below 200kHz, wait time */ - /* is only a few CPU processing cycles. */ - uint32_t wait_loop_index; - wait_loop_index = ((LL_ADC_DELAY_INTERNAL_REGUL_STAB_US * (SystemCoreClock / (100000 * 2))) / 10); - while (wait_loop_index != 0) { - wait_loop_index--; - } - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_5); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_5, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_5, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_2, LL_ADC_CHANNEL_7); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_7, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_7, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_3, LL_ADC_CHANNEL_8); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_8, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_8, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_4, LL_ADC_CHANNEL_9); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_9, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_9, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_5, LL_ADC_CHANNEL_12); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_12, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_12, LL_ADC_SINGLE_ENDED); - - /** Configure Regular Channel - */ - LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_6, LL_ADC_CHANNEL_15); - LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_15, LL_ADC_SAMPLINGTIME_92CYCLES_5); - LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_15, LL_ADC_SINGLE_ENDED); - /* USER CODE BEGIN ADC1_Init 2 */ - - /* USER CODE END ADC1_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4PERTESTING/Core/Src/crc.c b/G4PERTESTING/Core/Src/crc.c deleted file mode 100644 index 213510a5d..000000000 --- a/G4PERTESTING/Core/Src/crc.c +++ /dev/null @@ -1,86 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file crc.c - * @brief This file provides code for the configuration - * of the CRC instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "crc.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -CRC_HandleTypeDef hcrc; - -/* CRC init function */ -void MX_CRC_Init(void) -{ - - /* USER CODE BEGIN CRC_Init 0 */ - - /* USER CODE END CRC_Init 0 */ - - /* USER CODE BEGIN CRC_Init 1 */ - - /* USER CODE END CRC_Init 1 */ - hcrc.Instance = CRC; - hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE; - hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE; - hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE; - hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE; - hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES; - if (HAL_CRC_Init(&hcrc) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN CRC_Init 2 */ - - /* USER CODE END CRC_Init 2 */ -} - -void HAL_CRC_MspInit(CRC_HandleTypeDef *crcHandle) -{ - - if (crcHandle->Instance == CRC) { - /* USER CODE BEGIN CRC_MspInit 0 */ - - /* USER CODE END CRC_MspInit 0 */ - /* CRC clock enable */ - __HAL_RCC_CRC_CLK_ENABLE(); - /* USER CODE BEGIN CRC_MspInit 1 */ - - /* USER CODE END CRC_MspInit 1 */ - } -} - -void HAL_CRC_MspDeInit(CRC_HandleTypeDef *crcHandle) -{ - - if (crcHandle->Instance == CRC) { - /* USER CODE BEGIN CRC_MspDeInit 0 */ - - /* USER CODE END CRC_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_CRC_CLK_DISABLE(); - /* USER CODE BEGIN CRC_MspDeInit 1 */ - - /* USER CODE END CRC_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4PERTESTING/Core/Src/dma.c b/G4PERTESTING/Core/Src/dma.c deleted file mode 100644 index 491e3889d..000000000 --- a/G4PERTESTING/Core/Src/dma.c +++ /dev/null @@ -1,50 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file dma.c - * @brief This file provides code for the configuration - * of all the requested memory to memory DMA transfers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "dma.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure DMA */ -/*----------------------------------------------------------------------------*/ - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** - * Enable DMA controller clock - */ -void MX_DMA_Init(void) -{ - - /* Init with LL driver */ - /* DMA controller clock enable */ - LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMAMUX1); - LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1); -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ diff --git a/G4PERTESTING/Core/Src/fdcan.c b/G4PERTESTING/Core/Src/fdcan.c deleted file mode 100644 index f39dbfa2b..000000000 --- a/G4PERTESTING/Core/Src/fdcan.c +++ /dev/null @@ -1,133 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file fdcan.c - * @brief This file provides code for the configuration - * of the FDCAN instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "fdcan.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -FDCAN_HandleTypeDef hfdcan2; - -/* FDCAN2 init function */ -void MX_FDCAN2_Init(void) -{ - - /* USER CODE BEGIN FDCAN2_Init 0 */ - - /* USER CODE END FDCAN2_Init 0 */ - - /* USER CODE BEGIN FDCAN2_Init 1 */ - - /* USER CODE END FDCAN2_Init 1 */ - hfdcan2.Instance = FDCAN2; - hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1; - hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC; - hfdcan2.Init.Mode = FDCAN_MODE_NORMAL; - hfdcan2.Init.AutoRetransmission = ENABLE; - hfdcan2.Init.TransmitPause = DISABLE; - hfdcan2.Init.ProtocolException = ENABLE; - hfdcan2.Init.NominalPrescaler = 1; - hfdcan2.Init.NominalSyncJumpWidth = 16; - hfdcan2.Init.NominalTimeSeg1 = 119; - hfdcan2.Init.NominalTimeSeg2 = 40; - hfdcan2.Init.DataPrescaler = 8; - hfdcan2.Init.DataSyncJumpWidth = 16; - hfdcan2.Init.DataTimeSeg1 = 14; - hfdcan2.Init.DataTimeSeg2 = 5; - hfdcan2.Init.StdFiltersNbr = 0; - hfdcan2.Init.ExtFiltersNbr = 2; - hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; - if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN FDCAN2_Init 2 */ - - /* USER CODE END FDCAN2_Init 2 */ -} - -void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle) -{ - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspInit 0 */ - - /* USER CODE END FDCAN2_MspInit 0 */ - LL_RCC_SetFDCANClockSource(LL_RCC_FDCAN_CLKSOURCE_PCLK1); - - /* FDCAN2 clock enable */ - __HAL_RCC_FDCAN_CLK_ENABLE(); - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - GPIO_InitStruct.Pin = GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = 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_FDCAN2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* FDCAN2 interrupt Init */ - HAL_NVIC_SetPriority(FDCAN2_IT0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspInit 1 */ - - /* USER CODE END FDCAN2_MspInit 1 */ - } -} - -void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle) -{ - - if (fdcanHandle->Instance == FDCAN2) { - /* USER CODE BEGIN FDCAN2_MspDeInit 0 */ - - /* USER CODE END FDCAN2_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_FDCAN_CLK_DISABLE(); - - /**FDCAN2 GPIO Configuration - PB12 ------> FDCAN2_RX - PB13 ------> FDCAN2_TX - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12 | GPIO_PIN_13); - - /* FDCAN2 interrupt Deinit */ - HAL_NVIC_DisableIRQ(FDCAN2_IT0_IRQn); - /* USER CODE BEGIN FDCAN2_MspDeInit 1 */ - - /* USER CODE END FDCAN2_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4PERTESTING/Core/Src/gpio.c b/G4PERTESTING/Core/Src/gpio.c deleted file mode 100644 index d36e6eca6..000000000 --- a/G4PERTESTING/Core/Src/gpio.c +++ /dev/null @@ -1,260 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file gpio.c - * @brief This file provides code for the configuration - * of all used GPIO pins. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "gpio.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/*----------------------------------------------------------------------------*/ -/* Configure GPIO */ -/*----------------------------------------------------------------------------*/ -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is - enabled through - * the Code Generation settings) - PA6 ------> ADC2_IN3 - PA7 ------> ADC2_IN4 - PB15 ------> ADC2_IN15 - PB7 ------> UART4_CTS -*/ -void MX_GPIO_Init(void) -{ - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOF); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOG); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOD); - - /**/ - LL_GPIO_ResetOutputPin(BLINKY_GPIO_Port, BLINKY_Pin); - - /**/ - LL_GPIO_ResetOutputPin(LED_TEST_GPIO_Port, LED_TEST_Pin); - - /**/ - LL_GPIO_ResetOutputPin(BRAKE_LIGHT_GPIO_Port, BRAKE_LIGHT_Pin); - - /**/ - LL_GPIO_ResetOutputPin(TSSI_G_CONTROL_GPIO_Port, TSSI_G_CONTROL_Pin); - - /**/ - LL_GPIO_ResetOutputPin(AUX_CONTROL_GPIO_Port, AUX_CONTROL_Pin); - - /**/ - LL_GPIO_ResetOutputPin(SOFTWARE_OK_CONTROL_GPIO_Port, SOFTWARE_OK_CONTROL_Pin); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_13; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOG, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_1; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = BLINKY_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BLINKY_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = IMD_SENSE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(IMD_SENSE_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = AMS_SENSE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AMS_SENSE_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LED_TEST_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(LED_TEST_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = STEERING_ANGLE_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(STEERING_ANGLE_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_9; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_15; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = BRAKE_LIGHT_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(BRAKE_LIGHT_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = TSSI_G_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(TSSI_G_CONTROL_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_7; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_14; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = AUX_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(AUX_CONTROL_GPIO_Port, &GPIO_InitStruct); - - /**/ - GPIO_InitStruct.Pin = SOFTWARE_OK_CONTROL_Pin; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(SOFTWARE_OK_CONTROL_GPIO_Port, &GPIO_InitStruct); -} - -/* USER CODE BEGIN 2 */ - -/* USER CODE END 2 */ diff --git a/G4PERTESTING/Core/Src/i2c.c b/G4PERTESTING/Core/Src/i2c.c deleted file mode 100644 index bfb4e0153..000000000 --- a/G4PERTESTING/Core/Src/i2c.c +++ /dev/null @@ -1,92 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file i2c.c - * @brief This file provides code for the configuration - * of the I2C instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "i2c.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* I2C2 init function */ -void MX_I2C2_Init(void) -{ - - /* USER CODE BEGIN I2C2_Init 0 */ - - /* USER CODE END I2C2_Init 0 */ - - LL_I2C_InitTypeDef I2C_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetI2CClockSource(LL_RCC_I2C2_CLKSOURCE_PCLK1); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - /**I2C2 GPIO Configuration - PC4 ------> I2C2_SCL - PA8 ------> I2C2_SDA - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_4; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_4; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_8; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_4; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C2); - - /* USER CODE BEGIN I2C2_Init 1 */ - - /* USER CODE END I2C2_Init 1 */ - - /** I2C Initialization - */ - I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; - I2C_InitStruct.Timing = 0x30D29DE4; - I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE; - I2C_InitStruct.DigitalFilter = 0; - I2C_InitStruct.OwnAddress1 = 0; - I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK; - I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT; - LL_I2C_Init(I2C2, &I2C_InitStruct); - LL_I2C_EnableAutoEndMode(I2C2); - LL_I2C_SetOwnAddress2(I2C2, 0, LL_I2C_OWNADDRESS2_NOMASK); - LL_I2C_DisableOwnAddress2(I2C2); - LL_I2C_DisableGeneralCall(I2C2); - LL_I2C_EnableClockStretching(I2C2); - /* USER CODE BEGIN I2C2_Init 2 */ - - /* USER CODE END I2C2_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4PERTESTING/Core/Src/main.c b/G4PERTESTING/Core/Src/main.c deleted file mode 100644 index ba6196726..000000000 --- a/G4PERTESTING/Core/Src/main.c +++ /dev/null @@ -1,199 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "adc.h" -#include "dma.h" -#include "fdcan.h" -#include "gpio.h" -#include "i2c.h" -#include "spi.h" -#include "tim.h" -#include "usart.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* 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 -----------------------------------------------*/ -void SystemClock_Config(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - - /* USER CODE BEGIN 1 */ - - /* USER CODE END 1 */ - - /* MCU - * Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the - * Systick. */ - HAL_Init(); - - /* USER CODE BEGIN Init */ - - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_DMA_Init(); - MX_FDCAN2_Init(); - MX_ADC1_Init(); - MX_LPUART1_UART_Init(); - MX_I2C2_Init(); - MX_USART1_UART_Init(); - MX_SPI3_Init(); - MX_TIM2_Init(); - /* USER CODE BEGIN 2 */ - - /* USER CODE END 2 */ - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) { - /* USER CODE END WHILE */ - - // BLINKY - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET); - HAL_Delay(1000); - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET); - HAL_Delay(1000); - - /* USER CODE BEGIN 3 */ - } -} - -/** - * @brief System Clock Configuration - * @retval None - */ -void SystemClock_Config(void) -{ - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSE_Enable(); - /* Wait till HSE is ready */ - while (LL_RCC_HSE_IsReady() != 1) {} - - LL_RCC_HSE_EnableCSS(); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_1, 20, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(160000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - Error_Handler(); - } -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return - * state */ - __disable_irq(); - while (1) {} - /* USER CODE END Error_Handler_Debug */ -} -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line - number, ex: printf("Wrong parameters value: file %s on line %d\r\n", - file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ diff --git a/G4PERTESTING/Core/Src/spi.c b/G4PERTESTING/Core/Src/spi.c deleted file mode 100644 index 66459f2ec..000000000 --- a/G4PERTESTING/Core/Src/spi.c +++ /dev/null @@ -1,95 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file spi.c - * @brief This file provides code for the configuration - * of the SPI instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "spi.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* SPI3 init function */ -void MX_SPI3_Init(void) -{ - - /* USER CODE BEGIN SPI3_Init 0 */ - - /* USER CODE END SPI3_Init 0 */ - - LL_SPI_InitTypeDef SPI_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI3); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - /**SPI3 GPIO Configuration - PC10 ------> SPI3_SCK - PC11 ------> SPI3_MISO - PC12 ------> SPI3_MOSI - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_10; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_6; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_6; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_6; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN SPI3_Init 1 */ - - /* USER CODE END SPI3_Init 1 */ - SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; - SPI_InitStruct.Mode = LL_SPI_MODE_MASTER; - SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_4BIT; - SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; - SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE; - SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; - SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV32; - SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST; - SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; - SPI_InitStruct.CRCPoly = 7; - LL_SPI_Init(SPI3, &SPI_InitStruct); - LL_SPI_SetStandard(SPI3, LL_SPI_PROTOCOL_MOTOROLA); - LL_SPI_EnableNSSPulseMgt(SPI3); - /* USER CODE BEGIN SPI3_Init 2 */ - - /* USER CODE END SPI3_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4PERTESTING/Core/Src/stm32g4xx_hal_msp.c b/G4PERTESTING/Core/Src/stm32g4xx_hal_msp.c deleted file mode 100644 index 69189ef4e..000000000 --- a/G4PERTESTING/Core/Src/stm32g4xx_hal_msp.c +++ /dev/null @@ -1,86 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_msp.c - * @brief This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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*/ - - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); - - /* USER CODE BEGIN MspInit 1 */ - - /* USER CODE END MspInit 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4PERTESTING/Core/Src/stm32g4xx_it.c b/G4PERTESTING/Core/Src/stm32g4xx_it.c deleted file mode 100644 index 2f0cf90a7..000000000 --- a/G4PERTESTING/Core/Src/stm32g4xx_it.c +++ /dev/null @@ -1,212 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "stm32g4xx_it.h" - -#include "main.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 --------------------------------------------------------*/ -extern FDCAN_HandleTypeDef hfdcan2; -/* 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 Prefetch 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 */ -} - -/******************************************************************************/ -/* STM32G4xx 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_stm32g4xx.s). */ -/******************************************************************************/ - -/** - * @brief This function handles FDCAN2 interrupt 0. - */ -void FDCAN2_IT0_IRQHandler(void) -{ - /* USER CODE BEGIN FDCAN2_IT0_IRQn 0 */ - - /* USER CODE END FDCAN2_IT0_IRQn 0 */ - HAL_FDCAN_IRQHandler(&hfdcan2); - /* USER CODE BEGIN FDCAN2_IT0_IRQn 1 */ - - /* USER CODE END FDCAN2_IT0_IRQn 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4PERTESTING/Core/Src/tim.c b/G4PERTESTING/Core/Src/tim.c deleted file mode 100644 index 7f521c3bf..000000000 --- a/G4PERTESTING/Core/Src/tim.c +++ /dev/null @@ -1,79 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file tim.c - * @brief This file provides code for the configuration - * of the TIM instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "tim.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* TIM2 init function */ -void MX_TIM2_Init(void) -{ - - /* USER CODE BEGIN TIM2_Init 0 */ - - /* USER CODE END TIM2_Init 0 */ - - LL_TIM_InitTypeDef TIM_InitStruct = {0}; - LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2); - - /* USER CODE BEGIN TIM2_Init 1 */ - - /* USER CODE END TIM2_Init 1 */ - TIM_InitStruct.Prescaler = 0; - TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; - TIM_InitStruct.Autoreload = 4294967295; - TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; - LL_TIM_Init(TIM2, &TIM_InitStruct); - LL_TIM_DisableARRPreload(TIM2); - LL_TIM_SetClockSource(TIM2, LL_TIM_CLOCKSOURCE_INTERNAL); - TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_FORCED_ACTIVE; - TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; - TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; - TIM_OC_InitStruct.CompareValue = 0; - TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; - LL_TIM_OC_Init(TIM2, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct); - LL_TIM_OC_DisableFast(TIM2, LL_TIM_CHANNEL_CH1); - LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_RESET); - LL_TIM_DisableMasterSlaveMode(TIM2); - /* USER CODE BEGIN TIM2_Init 2 */ - - /* USER CODE END TIM2_Init 2 */ - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - /**TIM2 GPIO Configuration - PA0 ------> TIM2_CH1 - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_1; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4PERTESTING/Core/Src/usart.c b/G4PERTESTING/Core/Src/usart.c deleted file mode 100644 index 56a3fa98f..000000000 --- a/G4PERTESTING/Core/Src/usart.c +++ /dev/null @@ -1,184 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file usart.c - * @brief This file provides code for the configuration - * of the USART instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2025 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 "usart.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* LPUART1 init function */ - -void MX_LPUART1_UART_Init(void) -{ - - /* USER CODE BEGIN LPUART1_Init 0 */ - - /* USER CODE END LPUART1_Init 0 */ - - LL_LPUART_InitTypeDef LPUART_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1); - - /* Peripheral clock enable */ - LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_LPUART1); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - /**LPUART1 GPIO Configuration - PA2 ------> LPUART1_TX - PA3 ------> LPUART1_RX - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_2; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_12; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_12; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* USER CODE BEGIN LPUART1_Init 1 */ - - /* USER CODE END LPUART1_Init 1 */ - LPUART_InitStruct.PrescalerValue = LL_LPUART_PRESCALER_DIV1; - LPUART_InitStruct.BaudRate = 115200; - LPUART_InitStruct.DataWidth = LL_LPUART_DATAWIDTH_8B; - LPUART_InitStruct.StopBits = LL_LPUART_STOPBITS_1; - LPUART_InitStruct.Parity = LL_LPUART_PARITY_NONE; - LPUART_InitStruct.TransferDirection = LL_LPUART_DIRECTION_TX_RX; - LPUART_InitStruct.HardwareFlowControl = LL_LPUART_HWCONTROL_NONE; - LL_LPUART_Init(LPUART1, &LPUART_InitStruct); - LL_LPUART_SetTXFIFOThreshold(LPUART1, LL_LPUART_FIFOTHRESHOLD_1_8); - LL_LPUART_SetRXFIFOThreshold(LPUART1, LL_LPUART_FIFOTHRESHOLD_1_8); - LL_LPUART_DisableFIFO(LPUART1); - - /* USER CODE BEGIN WKUPType LPUART1 */ - - /* USER CODE END WKUPType LPUART1 */ - - LL_LPUART_Enable(LPUART1); - - /* Polling LPUART1 initialisation */ - while ((!(LL_LPUART_IsActiveFlag_TEACK(LPUART1))) || (!(LL_LPUART_IsActiveFlag_REACK(LPUART1)))) {} - /* USER CODE BEGIN LPUART1_Init 2 */ - - /* USER CODE END LPUART1_Init 2 */ -} -/* USART1 init function */ - -void MX_USART1_UART_Init(void) -{ - - /* USER CODE BEGIN USART1_Init 0 */ - - /* USER CODE END USART1_Init 0 */ - - LL_USART_InitTypeDef USART_InitStruct = {0}; - - LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; - - LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2); - - /* Peripheral clock enable */ - LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1); - - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); - LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); - /**USART1 GPIO Configuration - PC5 ------> USART1_RX - PA11 ------> USART1_CTS - PA12 ------> USART1_RTS - PB6 ------> USART1_TX - */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_12; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = LL_GPIO_PIN_6; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_7; - LL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* USER CODE BEGIN USART1_Init 1 */ - - /* USER CODE END USART1_Init 1 */ - USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1; - USART_InitStruct.BaudRate = 115200; - USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; - USART_InitStruct.StopBits = LL_USART_STOPBITS_1; - USART_InitStruct.Parity = LL_USART_PARITY_NONE; - USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX; - USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_RTS_CTS; - USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16; - LL_USART_Init(USART1, &USART_InitStruct); - LL_USART_SetTXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8); - LL_USART_SetRXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8); - LL_USART_DisableFIFO(USART1); - LL_USART_ConfigAsyncMode(USART1); - - /* USER CODE BEGIN WKUPType USART1 */ - - /* USER CODE END WKUPType USART1 */ - - LL_USART_Enable(USART1); - - /* Polling USART1 initialisation */ - while ((!(LL_USART_IsActiveFlag_TEACK(USART1))) || (!(LL_USART_IsActiveFlag_REACK(USART1)))) {} - /* USER CODE BEGIN USART1_Init 2 */ - - /* USER CODE END USART1_Init 2 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4PERTESTING/G4PERTESTING.ioc b/G4PERTESTING/G4PERTESTING.ioc deleted file mode 100644 index 8cf1860b1..000000000 --- a/G4PERTESTING/G4PERTESTING.ioc +++ /dev/null @@ -1,382 +0,0 @@ -#MicroXplorer Configuration settings - do not modify -ADC1.Channel-2\#ChannelRegularConversion=ADC_CHANNEL_5 -ADC1.Channel-3\#ChannelRegularConversion=ADC_CHANNEL_7 -ADC1.Channel-4\#ChannelRegularConversion=ADC_CHANNEL_8 -ADC1.Channel-5\#ChannelRegularConversion=ADC_CHANNEL_9 -ADC1.Channel-6\#ChannelRegularConversion=ADC_CHANNEL_12 -ADC1.Channel-7\#ChannelRegularConversion=ADC_CHANNEL_15 -ADC1.ClockPrescaler=ADC_CLOCK_ASYNC_DIV256 -ADC1.CommonPathInternal=null|null|null|null -ADC1.ContinuousConvMode=ENABLE -ADC1.DMAContinuousRequests=ENABLE -ADC1.EOCSelection=ADC_EOC_SEQ_CONV -ADC1.ExternalTrigConv=ADC_SOFTWARE_START -ADC1.IPParameters=Rank-2\#ChannelRegularConversion,Channel-2\#ChannelRegularConversion,SamplingTime-2\#ChannelRegularConversion,OffsetNumber-2\#ChannelRegularConversion,NbrOfConversionFlag,master,Rank-3\#ChannelRegularConversion,Channel-3\#ChannelRegularConversion,SamplingTime-3\#ChannelRegularConversion,OffsetNumber-3\#ChannelRegularConversion,Rank-4\#ChannelRegularConversion,Channel-4\#ChannelRegularConversion,SamplingTime-4\#ChannelRegularConversion,OffsetNumber-4\#ChannelRegularConversion,Rank-5\#ChannelRegularConversion,Channel-5\#ChannelRegularConversion,SamplingTime-5\#ChannelRegularConversion,OffsetNumber-5\#ChannelRegularConversion,Rank-6\#ChannelRegularConversion,Channel-6\#ChannelRegularConversion,SamplingTime-6\#ChannelRegularConversion,OffsetNumber-6\#ChannelRegularConversion,Rank-7\#ChannelRegularConversion,Channel-7\#ChannelRegularConversion,SamplingTime-7\#ChannelRegularConversion,OffsetNumber-7\#ChannelRegularConversion,NbrOfConversion,ContinuousConvMode,DMAContinuousRequests,ClockPrescaler,EOCSelection,ExternalTrigConv,CommonPathInternal -ADC1.NbrOfConversion=6 -ADC1.NbrOfConversionFlag=1 -ADC1.OffsetNumber-2\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-3\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-4\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-5\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-6\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.OffsetNumber-7\#ChannelRegularConversion=ADC_OFFSET_NONE -ADC1.Rank-2\#ChannelRegularConversion=1 -ADC1.Rank-3\#ChannelRegularConversion=2 -ADC1.Rank-4\#ChannelRegularConversion=3 -ADC1.Rank-5\#ChannelRegularConversion=4 -ADC1.Rank-6\#ChannelRegularConversion=5 -ADC1.Rank-7\#ChannelRegularConversion=6 -ADC1.SamplingTime-2\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-3\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-4\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-5\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-6\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.SamplingTime-7\#ChannelRegularConversion=ADC_SAMPLETIME_92CYCLES_5 -ADC1.master=1 -CAD.formats=[] -CAD.pinconfig=Dual -CAD.provider= -Dma.ADC1.0.Direction=DMA_PERIPH_TO_MEMORY -Dma.ADC1.0.EventEnable=DISABLE -Dma.ADC1.0.Instance=DMA1_Channel1 -Dma.ADC1.0.MemDataAlignment=DMA_MDATAALIGN_HALFWORD -Dma.ADC1.0.MemInc=DMA_MINC_ENABLE -Dma.ADC1.0.Mode=DMA_CIRCULAR -Dma.ADC1.0.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD -Dma.ADC1.0.PeriphInc=DMA_PINC_DISABLE -Dma.ADC1.0.Polarity=HAL_DMAMUX_REQ_GEN_RISING -Dma.ADC1.0.Priority=DMA_PRIORITY_LOW -Dma.ADC1.0.RequestNumber=1 -Dma.ADC1.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,SignalID,Polarity,RequestNumber,SyncSignalID,SyncPolarity,SyncEnable,EventEnable,SyncRequestNumber -Dma.ADC1.0.SignalID=NONE -Dma.ADC1.0.SyncEnable=DISABLE -Dma.ADC1.0.SyncPolarity=HAL_DMAMUX_SYNC_NO_EVENT -Dma.ADC1.0.SyncRequestNumber=1 -Dma.ADC1.0.SyncSignalID=NONE -Dma.Request0=ADC1 -Dma.RequestsNb=1 -FDCAN2.AutoRetransmission=ENABLE -FDCAN2.CalculateBaudRateNominal=1000000 -FDCAN2.CalculateTimeBitNominal=1000 -FDCAN2.CalculateTimeQuantumNominal=6.25 -FDCAN2.DataPrescaler=8 -FDCAN2.DataSyncJumpWidth=16 -FDCAN2.DataTimeSeg1=14 -FDCAN2.DataTimeSeg2=5 -FDCAN2.ExtFiltersNbr=2 -FDCAN2.FrameFormat=FDCAN_FRAME_CLASSIC -FDCAN2.IPParameters=CalculateTimeQuantumNominal,CalculateTimeBitNominal,CalculateBaudRateNominal,FrameFormat,NominalTimeSeg1,NominalTimeSeg2,NominalPrescaler,AutoRetransmission,StdFiltersNbr,TransmitPause,NominalSyncJumpWidth,DataTimeSeg1,DataTimeSeg2,DataPrescaler,DataSyncJumpWidth,ExtFiltersNbr,ProtocolException -FDCAN2.NominalPrescaler=1 -FDCAN2.NominalSyncJumpWidth=16 -FDCAN2.NominalTimeSeg1=119 -FDCAN2.NominalTimeSeg2=40 -FDCAN2.ProtocolException=ENABLE -FDCAN2.StdFiltersNbr=0 -FDCAN2.TransmitPause=DISABLE -File.Version=6 -GPIO.groupedBy=Group By Peripherals -I2C2.IPParameters=Timing -I2C2.Timing=0x30D29DE4 -KeepUserPlacement=false -LPUART1.BaudRate=115200 -LPUART1.IPParameters=BaudRate -Mcu.CPN=STM32G474RET6 -Mcu.Family=STM32G4 -Mcu.IP0=ADC1 -Mcu.IP1=DMA -Mcu.IP10=USART1 -Mcu.IP2=FDCAN2 -Mcu.IP3=I2C2 -Mcu.IP4=LPUART1 -Mcu.IP5=NVIC -Mcu.IP6=RCC -Mcu.IP7=SPI3 -Mcu.IP8=SYS -Mcu.IP9=TIM2 -Mcu.IPNb=11 -Mcu.Name=STM32G474R(B-C-E)Tx -Mcu.Package=LQFP64 -Mcu.Pin0=PF0-OSC_IN -Mcu.Pin1=PF1-OSC_OUT -Mcu.Pin10=PA7 -Mcu.Pin11=PC4 -Mcu.Pin12=PC5 -Mcu.Pin13=PB0 -Mcu.Pin14=PB1 -Mcu.Pin15=PB11 -Mcu.Pin16=PB12 -Mcu.Pin17=PB13 -Mcu.Pin18=PB14 -Mcu.Pin19=PB15 -Mcu.Pin2=PC1 -Mcu.Pin20=PA8 -Mcu.Pin21=PA11 -Mcu.Pin22=PA12 -Mcu.Pin23=PA13 -Mcu.Pin24=PA14 -Mcu.Pin25=PC10 -Mcu.Pin26=PC11 -Mcu.Pin27=PC12 -Mcu.Pin28=PB3 -Mcu.Pin29=PB4 -Mcu.Pin3=PC2 -Mcu.Pin30=PB5 -Mcu.Pin31=PB6 -Mcu.Pin32=PB7 -Mcu.Pin33=PB8-BOOT0 -Mcu.Pin34=PB9 -Mcu.Pin35=VP_SYS_VS_Systick -Mcu.Pin36=VP_SYS_VS_DBSignals -Mcu.Pin37=VP_TIM2_VS_ClockSourceINT -Mcu.Pin4=PC3 -Mcu.Pin5=PA0 -Mcu.Pin6=PA2 -Mcu.Pin7=PA3 -Mcu.Pin8=PA5 -Mcu.Pin9=PA6 -Mcu.PinsNb=38 -Mcu.ThirdPartyNb=0 -Mcu.UserConstants= -Mcu.UserName=STM32G474RETx -MxCube.Version=6.15.0 -MxDb.Version=DB.6.0.150 -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.FDCAN2_IT0_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true -NVIC.ForceEnableDMAVector=false -NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:false -NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 -NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false -NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -PA0.Signal=S_TIM2_CH1 -PA11.Locked=true -PA11.Mode=CTS_RTS -PA11.Signal=USART1_CTS -PA12.Locked=true -PA12.Mode=CTS_RTS -PA12.Signal=USART1_RTS -PA13.Locked=true -PA13.Mode=Trace_Asynchronous_SW -PA13.Signal=SYS_JTMS-SWDIO -PA14.Locked=true -PA14.Mode=Trace_Asynchronous_SW -PA14.Signal=SYS_JTCK-SWCLK -PA2.GPIOParameters=GPIO_Speed -PA2.GPIO_Speed=GPIO_SPEED_FREQ_HIGH -PA2.Locked=true -PA2.Mode=Asynchronous -PA2.Signal=LPUART1_TX -PA3.GPIOParameters=GPIO_Speed -PA3.GPIO_Speed=GPIO_SPEED_FREQ_HIGH -PA3.Locked=true -PA3.Mode=Asynchronous -PA3.Signal=LPUART1_RX -PA5.GPIOParameters=GPIO_Label -PA5.GPIO_Label=BLINKY -PA5.Locked=true -PA5.Signal=GPIO_Output -PA6.GPIOParameters=GPIO_Label -PA6.GPIO_Label=IMD_SENSE -PA6.Locked=true -PA6.Signal=ADC2_IN3 -PA7.GPIOParameters=GPIO_Label -PA7.GPIO_Label=AMS_SENSE -PA7.Locked=true -PA7.Signal=ADC2_IN4 -PA8.Mode=I2C -PA8.Signal=I2C2_SDA -PB0.GPIOParameters=GPIO_Label -PB0.GPIO_Label=BRAKE_F_SIGNAL -PB0.Locked=true -PB0.Mode=IN15-Single-Ended -PB0.Signal=ADC1_IN15 -PB1.GPIOParameters=GPIO_Label -PB1.GPIO_Label=BRAKE_R_SIGNAL -PB1.Locked=true -PB1.Mode=IN12-Single-Ended -PB1.Signal=ADC1_IN12 -PB11.GPIOParameters=GPIO_Label -PB11.GPIO_Label=LED_TEST -PB11.Locked=true -PB11.Signal=GPIO_Output -PB12.GPIOParameters=GPIO_Speed,GPIO_PuPd -PB12.GPIO_PuPd=GPIO_PULLUP -PB12.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PB12.Locked=true -PB12.Mode=FDCAN_Activate -PB12.Signal=FDCAN2_RX -PB13.GPIOParameters=GPIO_Speed -PB13.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PB13.Locked=true -PB13.Mode=FDCAN_Activate -PB13.Signal=FDCAN2_TX -PB14.GPIOParameters=GPIO_Label -PB14.GPIO_Label=AUX_SIGNAL -PB14.Locked=true -PB14.Mode=IN5-Single-Ended -PB14.Signal=ADC1_IN5 -PB15.GPIOParameters=GPIO_Label -PB15.GPIO_Label=STEERING_ANGLE -PB15.Locked=true -PB15.Signal=ADC2_IN15 -PB3.Locked=true -PB3.Mode=Trace_Asynchronous_SW -PB3.Signal=SYS_JTDO-SWO -PB4.GPIOParameters=GPIO_Label -PB4.GPIO_Label=BRAKE_LIGHT -PB4.Locked=true -PB4.Signal=GPIO_Output -PB5.GPIOParameters=GPIO_Label -PB5.GPIO_Label=TSSI_G_CONTROL -PB5.Locked=true -PB5.Signal=GPIO_Output -PB6.Locked=true -PB6.Mode=Asynchronous -PB6.Signal=USART1_TX -PB7.Locked=true -PB7.Signal=UART4_CTS -PB8-BOOT0.GPIOParameters=GPIO_Label -PB8-BOOT0.GPIO_Label=AUX_CONTROL -PB8-BOOT0.Locked=true -PB8-BOOT0.Signal=GPIO_Output -PB9.GPIOParameters=GPIO_Label -PB9.GPIO_Label=SOFTWARE_OK_CONTROL -PB9.Locked=true -PB9.Signal=GPIO_Output -PC1.GPIOParameters=GPIO_Label -PC1.GPIO_Label=BSPD_SIGNAL -PC1.Locked=true -PC1.Mode=IN7-Single-Ended -PC1.Signal=ADC1_IN7 -PC10.Mode=Full_Duplex_Master -PC10.Signal=SPI3_SCK -PC11.Mode=Full_Duplex_Master -PC11.Signal=SPI3_MISO -PC12.Mode=Full_Duplex_Master -PC12.Signal=SPI3_MOSI -PC2.GPIOParameters=GPIO_Label -PC2.GPIO_Label=APPS1_SIGNAL -PC2.Locked=true -PC2.Mode=IN8-Single-Ended -PC2.Signal=ADC1_IN8 -PC3.GPIOParameters=GPIO_Label -PC3.GPIO_Label=APPS2_SIGNAL -PC3.Locked=true -PC3.Mode=IN9-Single-Ended -PC3.Signal=ADC1_IN9 -PC4.Mode=I2C -PC4.Signal=I2C2_SCL -PC5.Mode=Asynchronous -PC5.Signal=USART1_RX -PF0-OSC_IN.Locked=true -PF0-OSC_IN.Mode=HSE-External-Oscillator -PF0-OSC_IN.Signal=RCC_OSC_IN -PF1-OSC_OUT.Locked=true -PF1-OSC_OUT.Mode=HSE-External-Oscillator -PF1-OSC_OUT.Signal=RCC_OSC_OUT -PinOutPanel.RotationAngle=180 -ProjectManager.AskForMigrate=true -ProjectManager.BackupPrevious=false -ProjectManager.CompilerLinker=GCC -ProjectManager.CompilerOptimize=6 -ProjectManager.ComputerToolchain=false -ProjectManager.CoupleFile=true -ProjectManager.CustomerFirmwarePackage= -ProjectManager.DefaultFWLocation=true -ProjectManager.DeletePrevious=true -ProjectManager.DeviceId=STM32G474RETx -ProjectManager.FirmwarePackage=STM32Cube FW_G4 V1.6.1 -ProjectManager.FreePins=true -ProjectManager.HalAssertFull=false -ProjectManager.HeapSize=0x200 -ProjectManager.KeepUserCode=true -ProjectManager.LastFirmware=true -ProjectManager.LibraryCopy=0 -ProjectManager.MainLocation=Core/Src -ProjectManager.NoMain=false -ProjectManager.PreviousToolchain= -ProjectManager.ProjectBuild=false -ProjectManager.ProjectFileName=G4PERTESTING.ioc -ProjectManager.ProjectName=G4PERTESTING -ProjectManager.ProjectStructure= -ProjectManager.RegisterCallBack= -ProjectManager.StackSize=0x400 -ProjectManager.TargetToolchain=CMake -ProjectManager.ToolChainLocation= -ProjectManager.UAScriptAfterPath= -ProjectManager.UAScriptBeforePath= -ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-LL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_DMA_Init-DMA-false-LL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_ADC1_Init-ADC1-false-LL-true,6-MX_LPUART1_UART_Init-LPUART1-false-LL-true,7-MX_I2C2_Init-I2C2-false-LL-true,8-MX_USART1_UART_Init-USART1-false-LL-true,9-MX_SPI3_Init-SPI3-false-LL-true,10-MX_TIM2_Init-TIM2-false-LL-true -RCC.ADC12Freq_Value=160000000 -RCC.ADC345Freq_Value=160000000 -RCC.AHBFreq_Value=160000000 -RCC.APB1Freq_Value=160000000 -RCC.APB1TimFreq_Value=160000000 -RCC.APB2Freq_Value=160000000 -RCC.APB2TimFreq_Value=160000000 -RCC.CRSFreq_Value=48000000 -RCC.CortexFreq_Value=160000000 -RCC.EXTERNAL_CLOCK_VALUE=12288000 -RCC.EnbaleCSS=true -RCC.FCLKCortexFreq_Value=160000000 -RCC.FDCANFreq_Value=160000000 -RCC.FamilyName=M -RCC.HCLKFreq_Value=160000000 -RCC.HRTIM1Freq_Value=160000000 -RCC.HSE_VALUE=16000000 -RCC.HSI48_VALUE=48000000 -RCC.HSI_VALUE=16000000 -RCC.I2C1Freq_Value=160000000 -RCC.I2C2Freq_Value=160000000 -RCC.I2C3Freq_Value=160000000 -RCC.I2C4Freq_Value=160000000 -RCC.I2SFreq_Value=160000000 -RCC.IPParameters=ADC12Freq_Value,ADC345Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,EnbaleCSS,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HRTIM1Freq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PLLSourceVirtual,PWRFreq_Value,QSPIFreq_Value,RNGFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value -RCC.LPTIM1Freq_Value=160000000 -RCC.LPUART1Freq_Value=160000000 -RCC.LSCOPinFreq_Value=32000 -RCC.LSE_VALUE=32768 -RCC.LSI_VALUE=32000 -RCC.MCO1PinFreq_Value=16000000 -RCC.PLLN=20 -RCC.PLLPoutputFreq_Value=160000000 -RCC.PLLQoutputFreq_Value=160000000 -RCC.PLLRCLKFreq_Value=160000000 -RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE -RCC.PWRFreq_Value=160000000 -RCC.QSPIFreq_Value=160000000 -RCC.RNGFreq_Value=160000000 -RCC.SAI1Freq_Value=160000000 -RCC.SYSCLKFreq_VALUE=160000000 -RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK -RCC.UART4Freq_Value=160000000 -RCC.UART5Freq_Value=160000000 -RCC.USART1Freq_Value=160000000 -RCC.USART2Freq_Value=160000000 -RCC.USART3Freq_Value=160000000 -RCC.USBFreq_Value=160000000 -RCC.VCOInputFreq_Value=16000000 -RCC.VCOOutputFreq_Value=320000000 -SH.S_TIM2_CH1.0=TIM2_CH1,Forced Output1 CH1 -SH.S_TIM2_CH1.ConfNb=1 -SPI3.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_32 -SPI3.CalculateBaudRate=5.0 MBits/s -SPI3.Direction=SPI_DIRECTION_2LINES -SPI3.IPParameters=VirtualType,Mode,Direction,BaudRatePrescaler,CalculateBaudRate -SPI3.Mode=SPI_MODE_MASTER -SPI3.VirtualType=VM_MASTER -TIM2.Channel-Forced\ Output1\ CH1=TIM_CHANNEL_1 -TIM2.IPParameters=Channel-Forced Output1 CH1 -USART1.IPParameters=VirtualMode-Asynchronous -USART1.VirtualMode-Asynchronous=VM_ASYNC -VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals -VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick -VP_TIM2_VS_ClockSourceINT.Mode=Internal -VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT -board=custom diff --git a/G4PERTESTING/README.md b/G4PERTESTING/README.md deleted file mode 100644 index 099ac620f..000000000 --- a/G4PERTESTING/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# STM32G474 ADC -Nucleo-G474RE-C04 - -Plug in the board following ST-LINK pinout -Compile and flash G4ADCTESTING.elf diff --git a/G4SPITESTING/CMakeLists.txt b/G4SPITESTING/CMakeLists.txt deleted file mode 100644 index 20c0a6194..000000000 --- a/G4SPITESTING/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -# Setup compiler settings -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) - -# Define the build type -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug") -endif() - -# Enable compile command to ease indexing with e.g. clangd -set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) - -# Enable CMake support for ASM and C languages -enable_language( - C - ASM -) - -# Core project settings -project(${CMAKE_PROJECT_NAME}) - -# what, does in fact not get the filename of somthing but rather the name of the project from the path -get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) - -add_library(${PROJECT_NAME}_USER_CODE INTERFACE) -target_sources( - ${PROJECT_NAME}_USER_CODE - INTERFACE - Core/Src/main.c - Core/Src/stm32g4xx_hal_msp.c - Core/Src/stm32g4xx_it.c -) - -target_link_libraries( - ${PROJECT_NAME}_USER_CODE - INTERFACE - SPI_Lib - LOGOMATIC_OLD_LIB -) - -target_include_directories(${PROJECT_NAME}_USER_CODE INTERFACE Core/Inc) diff --git a/G4SPITESTING/Core/Inc/main.h b/G4SPITESTING/Core/Inc/main.h deleted file mode 100644 index 9ff00d051..000000000 --- a/G4SPITESTING/Core/Inc/main.h +++ /dev/null @@ -1,116 +0,0 @@ -/* 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) 2024 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 "stm32g4xx_hal.h" -#include "stm32g4xx_ll_adc.h" -#include "stm32g4xx_ll_bus.h" -#include "stm32g4xx_ll_cortex.h" -#include "stm32g4xx_ll_crs.h" -#include "stm32g4xx_ll_dma.h" -#include "stm32g4xx_ll_exti.h" -#include "stm32g4xx_ll_gpio.h" -#include "stm32g4xx_ll_i2c.h" -#include "stm32g4xx_ll_lpuart.h" -#include "stm32g4xx_ll_pwr.h" -#include "stm32g4xx_ll_rcc.h" -#include "stm32g4xx_ll_spi.h" -#include "stm32g4xx_ll_system.h" -#include "stm32g4xx_ll_tim.h" -#include "stm32g4xx_ll_usart.h" -#include "stm32g4xx_ll_utils.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -#include -#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 BSPD_SIGNAL_Pin LL_GPIO_PIN_1 -#define BSPD_SIGNAL_GPIO_Port GPIOC -#define APPS1_SIGNAL_Pin LL_GPIO_PIN_2 -#define APPS1_SIGNAL_GPIO_Port GPIOC -#define APPS2_SIGNAL_Pin LL_GPIO_PIN_3 -#define APPS2_SIGNAL_GPIO_Port GPIOC -#define BLINKY_Pin LL_GPIO_PIN_5 -#define BLINKY_GPIO_Port GPIOA -#define IMD_SENSE_Pin LL_GPIO_PIN_6 -#define IMD_SENSE_GPIO_Port GPIOA -#define AMS_SENSE_Pin LL_GPIO_PIN_7 -#define AMS_SENSE_GPIO_Port GPIOA -#define BRAKE_F_SIGNAL_Pin LL_GPIO_PIN_0 -#define BRAKE_F_SIGNAL_GPIO_Port GPIOB -#define BRAKE_R_SIGNAL_Pin LL_GPIO_PIN_1 -#define BRAKE_R_SIGNAL_GPIO_Port GPIOB -#define LED_TEST_Pin LL_GPIO_PIN_11 -#define LED_TEST_GPIO_Port GPIOB -#define AUX_SIGNAL_Pin LL_GPIO_PIN_14 -#define AUX_SIGNAL_GPIO_Port GPIOB -#define STEERING_ANGLE_Pin LL_GPIO_PIN_15 -#define STEERING_ANGLE_GPIO_Port GPIOB -#define BRAKE_LIGHT_Pin LL_GPIO_PIN_4 -#define BRAKE_LIGHT_GPIO_Port GPIOB -#define TSSI_G_CONTROL_Pin LL_GPIO_PIN_5 -#define TSSI_G_CONTROL_GPIO_Port GPIOB -#define AUX_CONTROL_Pin LL_GPIO_PIN_8 -#define AUX_CONTROL_GPIO_Port GPIOB -#define SOFTWARE_OK_CONTROL_Pin LL_GPIO_PIN_9 -#define SOFTWARE_OK_CONTROL_GPIO_Port GPIOB - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -#ifdef __cplusplus -} -#endif - -#endif /* __MAIN_H */ diff --git a/G4SPITESTING/Core/Inc/stm32g4xx_hal_conf.h b/G4SPITESTING/Core/Inc/stm32g4xx_hal_conf.h deleted file mode 100644 index 3e1fcb018..000000000 --- a/G4SPITESTING/Core/Inc/stm32g4xx_hal_conf.h +++ /dev/null @@ -1,390 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_conf.h - * @author MCD Application Team - * @brief HAL configuration file - ****************************************************************************** - * @attention - * - * Copyright (c) 2019 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 STM32G4xx_HAL_CONF_H -#define STM32G4xx_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_ADC_MODULE_ENABLED */ -/*#define HAL_COMP_MODULE_ENABLED */ -/*#define HAL_CORDIC_MODULE_ENABLED */ -#define HAL_CRC_MODULE_ENABLED -/*#define HAL_CRYP_MODULE_ENABLED */ -/*#define HAL_DAC_MODULE_ENABLED */ -#define HAL_FDCAN_MODULE_ENABLED -/*#define HAL_FMAC_MODULE_ENABLED */ -/*#define HAL_HRTIM_MODULE_ENABLED */ -/*#define HAL_IRDA_MODULE_ENABLED */ -/*#define HAL_IWDG_MODULE_ENABLED */ -/*#define HAL_I2C_MODULE_ENABLED */ -/*#define HAL_I2S_MODULE_ENABLED */ -/*#define HAL_LPTIM_MODULE_ENABLED */ -/*#define HAL_NAND_MODULE_ENABLED */ -/*#define HAL_NOR_MODULE_ENABLED */ -/*#define HAL_OPAMP_MODULE_ENABLED */ -/*#define HAL_PCD_MODULE_ENABLED */ -/*#define HAL_QSPI_MODULE_ENABLED */ -/*#define HAL_RNG_MODULE_ENABLED */ -/*#define HAL_RTC_MODULE_ENABLED */ -/*#define HAL_SAI_MODULE_ENABLED */ -/*#define HAL_SMARTCARD_MODULE_ENABLED */ -/*#define HAL_SMBUS_MODULE_ENABLED */ -/*#define HAL_SPI_MODULE_ENABLED */ -/*#define HAL_SRAM_MODULE_ENABLED */ -/*#define HAL_TIM_MODULE_ENABLED */ -/*#define HAL_UART_MODULE_ENABLED */ -/*#define HAL_USART_MODULE_ENABLED */ -/*#define HAL_WWDG_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 - -/* ########################## Register Callbacks selection - * ############################## */ -/** - * @brief This is the list of modules where register callback can be used - */ -#define USE_HAL_ADC_REGISTER_CALLBACKS 0U -#define USE_HAL_COMP_REGISTER_CALLBACKS 0U -#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U -#define USE_HAL_DAC_REGISTER_CALLBACKS 0U -#define USE_HAL_EXTI_REGISTER_CALLBACKS 0U -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U -#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U -#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_I2C_REGISTER_CALLBACKS 0U -#define USE_HAL_I2S_REGISTER_CALLBACKS 0U -#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U -#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U -#define USE_HAL_NAND_REGISTER_CALLBACKS 0U -#define USE_HAL_NOR_REGISTER_CALLBACKS 0U -#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U -#define USE_HAL_PCD_REGISTER_CALLBACKS 0U -#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U -#define USE_HAL_RNG_REGISTER_CALLBACKS 0U -#define USE_HAL_RTC_REGISTER_CALLBACKS 0U -#define USE_HAL_SAI_REGISTER_CALLBACKS 0U -#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U -#define USE_HAL_SPI_REGISTER_CALLBACKS 0U -#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U -#define USE_HAL_TIM_REGISTER_CALLBACKS 0U -#define USE_HAL_UART_REGISTER_CALLBACKS 0U -#define USE_HAL_USART_REGISTER_CALLBACKS 0U -#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U - -/* ########################## Oscillator 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 (16000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ - -#if !defined(HSE_STARTUP_TIMEOUT) -#define HSE_STARTUP_TIMEOUT (100UL) /*!< 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 (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ - -/** - * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. - * This internal oscillator is mainly dedicated to provide a high - * precision clock to the USB peripheral by means of a special Clock Recovery - * System (CRS) circuitry. When the CRS is not used, the HSI48 RC oscillator - * runs on it default frequency which is subject to manufacturing process - * variations. - */ -#if !defined(HSI48_VALUE) -#define HSI48_VALUE \ - (48000000UL) /*!< Value of the Internal High Speed oscillator for USB \ - FS/RNG in Hz. The real value my vary depending on \ - manufacturing process variations.*/ -#endif /* HSI48_VALUE */ - -/** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined(LSI_VALUE) -/*!< Value of the Internal Low Speed oscillator in Hz -The real value may vary depending on the variations in voltage and -temperature.*/ -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ -/** - * @brief External Low Speed oscillator (LSE) value. - * This value is used by the UART, RTC HAL module to compute the system - * frequency - */ -#if !defined(LSE_VALUE) -#define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ -#endif /* LSE_VALUE */ - -#if !defined(LSE_STARTUP_TIMEOUT) -#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ -#endif /* LSE_STARTUP_TIMEOUT */ - -/** - * @brief External clock source for I2S and SAI peripherals - * This value is used by the I2S and SAI HAL modules to compute the I2S - * and SAI clock source frequency, this source is inserted directly through - * I2S_CKIN pad. - */ -#if !defined(EXTERNAL_CLOCK_VALUE) -#define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator 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 (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY (15UL) /*!< tick interrupt priority (lowest by default) */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 0U -#define INSTRUCTION_CACHE_ENABLE 1U -#define DATA_CACHE_ENABLE 1U - -/* ########################## Assert Selection ############################## */ -/** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -/* #define USE_FULL_ASSERT 1U */ - -/* ################## 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 "stm32g4xx_hal_rcc.h" -#endif /* HAL_RCC_MODULE_ENABLED */ - -#ifdef HAL_GPIO_MODULE_ENABLED -#include "stm32g4xx_hal_gpio.h" -#endif /* HAL_GPIO_MODULE_ENABLED */ - -#ifdef HAL_DMA_MODULE_ENABLED -#include "stm32g4xx_hal_dma.h" -#endif /* HAL_DMA_MODULE_ENABLED */ - -#ifdef HAL_CORTEX_MODULE_ENABLED -#include "stm32g4xx_hal_cortex.h" -#endif /* HAL_CORTEX_MODULE_ENABLED */ - -#ifdef HAL_ADC_MODULE_ENABLED -#include "stm32g4xx_hal_adc.h" -#endif /* HAL_ADC_MODULE_ENABLED */ - -#ifdef HAL_COMP_MODULE_ENABLED -#include "stm32g4xx_hal_comp.h" -#endif /* HAL_COMP_MODULE_ENABLED */ - -#ifdef HAL_CORDIC_MODULE_ENABLED -#include "stm32g4xx_hal_cordic.h" -#endif /* HAL_CORDIC_MODULE_ENABLED */ - -#ifdef HAL_CRC_MODULE_ENABLED -#include "stm32g4xx_hal_crc.h" -#endif /* HAL_CRC_MODULE_ENABLED */ - -#ifdef HAL_CRYP_MODULE_ENABLED -#include "stm32g4xx_hal_cryp.h" -#endif /* HAL_CRYP_MODULE_ENABLED */ - -#ifdef HAL_DAC_MODULE_ENABLED -#include "stm32g4xx_hal_dac.h" -#endif /* HAL_DAC_MODULE_ENABLED */ - -#ifdef HAL_EXTI_MODULE_ENABLED -#include "stm32g4xx_hal_exti.h" -#endif /* HAL_EXTI_MODULE_ENABLED */ - -#ifdef HAL_FDCAN_MODULE_ENABLED -#include "stm32g4xx_hal_fdcan.h" -#endif /* HAL_FDCAN_MODULE_ENABLED */ - -#ifdef HAL_FLASH_MODULE_ENABLED -#include "stm32g4xx_hal_flash.h" -#endif /* HAL_FLASH_MODULE_ENABLED */ - -#ifdef HAL_FMAC_MODULE_ENABLED -#include "stm32g4xx_hal_fmac.h" -#endif /* HAL_FMAC_MODULE_ENABLED */ - -#ifdef HAL_HRTIM_MODULE_ENABLED -#include "stm32g4xx_hal_hrtim.h" -#endif /* HAL_HRTIM_MODULE_ENABLED */ - -#ifdef HAL_IRDA_MODULE_ENABLED -#include "stm32g4xx_hal_irda.h" -#endif /* HAL_IRDA_MODULE_ENABLED */ - -#ifdef HAL_IWDG_MODULE_ENABLED -#include "stm32g4xx_hal_iwdg.h" -#endif /* HAL_IWDG_MODULE_ENABLED */ - -#ifdef HAL_I2C_MODULE_ENABLED -#include "stm32g4xx_hal_i2c.h" -#endif /* HAL_I2C_MODULE_ENABLED */ - -#ifdef HAL_I2S_MODULE_ENABLED -#include "stm32g4xx_hal_i2s.h" -#endif /* HAL_I2S_MODULE_ENABLED */ - -#ifdef HAL_LPTIM_MODULE_ENABLED -#include "stm32g4xx_hal_lptim.h" -#endif /* HAL_LPTIM_MODULE_ENABLED */ - -#ifdef HAL_NAND_MODULE_ENABLED -#include "stm32g4xx_hal_nand.h" -#endif /* HAL_NAND_MODULE_ENABLED */ - -#ifdef HAL_NOR_MODULE_ENABLED -#include "stm32g4xx_hal_nor.h" -#endif /* HAL_NOR_MODULE_ENABLED */ - -#ifdef HAL_OPAMP_MODULE_ENABLED -#include "stm32g4xx_hal_opamp.h" -#endif /* HAL_OPAMP_MODULE_ENABLED */ - -#ifdef HAL_PCD_MODULE_ENABLED -#include "stm32g4xx_hal_pcd.h" -#endif /* HAL_PCD_MODULE_ENABLED */ - -#ifdef HAL_PWR_MODULE_ENABLED -#include "stm32g4xx_hal_pwr.h" -#endif /* HAL_PWR_MODULE_ENABLED */ - -#ifdef HAL_QSPI_MODULE_ENABLED -#include "stm32g4xx_hal_qspi.h" -#endif /* HAL_QSPI_MODULE_ENABLED */ - -#ifdef HAL_RNG_MODULE_ENABLED -#include "stm32g4xx_hal_rng.h" -#endif /* HAL_RNG_MODULE_ENABLED */ - -#ifdef HAL_RTC_MODULE_ENABLED -#include "stm32g4xx_hal_rtc.h" -#endif /* HAL_RTC_MODULE_ENABLED */ - -#ifdef HAL_SAI_MODULE_ENABLED -#include "stm32g4xx_hal_sai.h" -#endif /* HAL_SAI_MODULE_ENABLED */ - -#ifdef HAL_SMARTCARD_MODULE_ENABLED -#include "stm32g4xx_hal_smartcard.h" -#endif /* HAL_SMARTCARD_MODULE_ENABLED */ - -#ifdef HAL_SMBUS_MODULE_ENABLED -#include "stm32g4xx_hal_smbus.h" -#endif /* HAL_SMBUS_MODULE_ENABLED */ - -#ifdef HAL_SPI_MODULE_ENABLED -#include "stm32g4xx_hal_spi.h" -#endif /* HAL_SPI_MODULE_ENABLED */ - -#ifdef HAL_SRAM_MODULE_ENABLED -#include "stm32g4xx_hal_sram.h" -#endif /* HAL_SRAM_MODULE_ENABLED */ - -#ifdef HAL_TIM_MODULE_ENABLED -#include "stm32g4xx_hal_tim.h" -#endif /* HAL_TIM_MODULE_ENABLED */ - -#ifdef HAL_UART_MODULE_ENABLED -#include "stm32g4xx_hal_uart.h" -#endif /* HAL_UART_MODULE_ENABLED */ - -#ifdef HAL_USART_MODULE_ENABLED -#include "stm32g4xx_hal_usart.h" -#endif /* HAL_USART_MODULE_ENABLED */ - -#ifdef HAL_WWDG_MODULE_ENABLED -#include "stm32g4xx_hal_wwdg.h" -#endif /* HAL_WWDG_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 /* STM32G4xx_HAL_CONF_H */ diff --git a/G4SPITESTING/Core/Inc/stm32g4xx_it.h b/G4SPITESTING/Core/Inc/stm32g4xx_it.h deleted file mode 100644 index b6c3b2f72..000000000 --- a/G4SPITESTING/Core/Inc/stm32g4xx_it.h +++ /dev/null @@ -1,67 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_it.h - * @brief This file contains the headers of the interrupt handlers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 __STM32G4xx_IT_H -#define __STM32G4xx_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); -void FDCAN2_IT0_IRQHandler(void); -/* USER CODE BEGIN EFP */ - -/* USER CODE END EFP */ - -#ifdef __cplusplus -} -#endif - -#endif /* __STM32G4xx_IT_H */ diff --git a/G4SPITESTING/Core/Src/main.c b/G4SPITESTING/Core/Src/main.c deleted file mode 100644 index 539e27d8f..000000000 --- a/G4SPITESTING/Core/Src/main.c +++ /dev/null @@ -1,298 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -#include - -#include "Logomatic.h" -#include "spi.h" -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* 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 */ -LogomaticConfig logomaticConfig = {.clock_source = LOGOMATIC_PCLK1, - .bus = LOGOMATIC_BUS, - .gpio_port = LOGOMATIC_GPIOA, - .gpio_pin_rx_tx_mask = LL_GPIO_PIN_2 | LL_GPIO_PIN_3, - .baud_rate = 115200, - .data_width = LOGOMATIC_DATAWIDTH_8B, - .stop_bits = LOGOMATIC_STOPBITS_1, - .parity = LOGOMATIC_PARITY_NONE, - .transfer_direction = LOGOMATIC_DIRECTION_TX, - .hardware_flow_control = LOGOMATIC_HWCONTROL_NONE, - .prescaler = LOGOMATIC_PRESCALER_DIV1, - .tx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8, - .rx_fifo_threshold = LOGOMATIC_FIFOTHRESHOLD_1_8}; -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -void SystemClock_Config(void); -/* USER CODE BEGIN PFP */ - -/* USER CODE END PFP */ - -/* Private user code ---------------------------------------------------------*/ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - - /* USER CODE BEGIN 1 */ - static GR_SPI_Handler handle_spi2, handle_spi3; - static LL_SPI_InitTypeDef config_spi2, config_spi3; - static GR_SPI_Pins pins_spi2, pins_spi3; - /*HAL_OSPI_HandleTypeDef hospi; - HAL_StatusTypeDef status;*/ - - /* USER CODE END 1 */ - - /* MCU - * Configuration--------------------------------------------------------*/ - - /* Reset of all peripherals, Initializes the Flash interface and the - * Systick. */ - HAL_Init(); - - /* USER CODE BEGIN Init */ - Setup_Logomatic(&logomaticConfig); - /* USER CODE END Init */ - - /* Configure the system clock */ - SystemClock_Config(); - - /* USER CODE BEGIN SysInit */ - LOGOMATIC("Booted!\n"); - /* USER CODE END SysInit */ - - /* Initialize all configured peripherals */ - /* USER CODE BEGIN 2 */ - LL_mDelay(1000); // Wait for peripherals to stabilize - LOGOMATIC("Booted!\n"); - - // ========== RECEIVER CONFIGURATION ========== - config_spi2.Mode = LL_SPI_MODE_SLAVE; - config_spi2.NSS = LL_SPI_NSS_HARD_INPUT; - config_spi2.TransferDirection = LL_SPI_FULL_DUPLEX; - config_spi2.DataWidth = LL_SPI_DATAWIDTH_8BIT; - config_spi2.ClockPolarity = LL_SPI_POLARITY_LOW; - config_spi2.ClockPhase = LL_SPI_PHASE_1EDGE; - config_spi2.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV32; - config_spi2.BitOrder = LL_SPI_LSB_FIRST; - config_spi2.CRCCalculation = LL_SPI_CRCCALCULATION_ENABLE; - config_spi2.CRCPoly = 0x1D; - - pins_spi2.SPIx = SPI2; - pins_spi2.COPI_port = GPIOB; - pins_spi2.CIPO_port = GPIOB; - pins_spi2.SCLK_port = GPIOB; - pins_spi2.NCS_port = GPIOB; - pins_spi2.COPI_pin = LL_GPIO_PIN_15; // COPI - pins_spi2.CIPO_pin = LL_GPIO_PIN_14; // CIPO - pins_spi2.SCLK_pin = LL_GPIO_PIN_13; // SCK - pins_spi2.NCS_pin = LL_GPIO_PIN_12; // NSS - pins_spi2.AFN = 5; - - GR_SPI_Initialize(&handle_spi2, &config_spi2, &pins_spi2); - - // ========== SENDER CONFIGURATION ========== - config_spi3.Mode = LL_SPI_MODE_MASTER; - config_spi3.NSS = LL_SPI_NSS_SOFT; - config_spi3.TransferDirection = LL_SPI_FULL_DUPLEX; - config_spi3.DataWidth = LL_SPI_DATAWIDTH_8BIT; - config_spi3.ClockPolarity = LL_SPI_POLARITY_LOW; - config_spi3.ClockPhase = LL_SPI_PHASE_1EDGE; - config_spi3.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV32; - config_spi3.BitOrder = LL_SPI_LSB_FIRST; - config_spi3.CRCCalculation = LL_SPI_CRCCALCULATION_ENABLE; - config_spi3.CRCPoly = 0x1D; - - // Configure GR_SPI_Pins struct - pins_spi3.SPIx = SPI3; - pins_spi3.COPI_port = GPIOC; - pins_spi3.CIPO_port = GPIOC; - pins_spi3.SCLK_port = GPIOC; - pins_spi3.NCS_port = GPIOA; - pins_spi3.COPI_pin = LL_GPIO_PIN_12; // COPI - pins_spi3.CIPO_pin = LL_GPIO_PIN_11; // CIPO - pins_spi3.SCLK_pin = LL_GPIO_PIN_10; // SCK - pins_spi3.NCS_pin = LL_GPIO_PIN_4; // NSS - pins_spi3.AFN = 6; - - GR_SPI_Initialize(&handle_spi3, &config_spi3, &pins_spi3); - - LOGOMATIC("Starting message transaction...\n"); - - GR_SPI_Message msg; - msg.data = (uint8_t *)malloc(32 * sizeof(uint8_t)); - msg.size = 32; // Must be <= 32 for this example code - - for (int i = 0; i < msg.size; i++) { - msg.data[i] = 'A' + i; - } - - GR_SPI_Send(&handle_spi3, &msg); - - LOGOMATIC("Sent message, now receiving...\n"); - - for (int i = 0; i < msg.size; i++) { - msg.data[i] = '#'; - } - - for (int i = 0; i < msg.size; i++) { - while (GR_SPI_IsRxEmpty(&handle_spi2)) - ; - uint8_t temp_byte; - GR_SPI_Message temp_msg = {0}; - temp_msg.data = &temp_byte; - temp_msg.size = 1; - GR_SPI_Receive(&handle_spi2, &temp_msg); - msg.data[i] = temp_byte; - } - - char str[33]; - memcpy(str, msg.data, msg.size * sizeof(uint8_t)); - str[msg.size] = '\0'; - - LOGOMATIC("Received: %s\n", str); - - free(msg.data); - GR_SPI_Close(&handle_spi2); - GR_SPI_Close(&handle_spi3); - - /* USER CODE END 2 */ - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) { - /* USER CODE END WHILE */ - - // BLINKY - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET); - HAL_Delay(1000); - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET); - HAL_Delay(1000); - LOGOMATIC("Blinking!\n"); - - /* USER CODE BEGIN 3 */ - } -} - -/* void test_spi_initialize(GR_SPI_Handler* handle, LL_SPI_InitTypeDef* config, -GR_SPI_Pins* pin_config){ if(GR_SPI_Initialize(&handle, &config, &pin_config) -} */ - -/** - * @brief System Clock Configuration - * @retval None - */ -void SystemClock_Config(void) -{ - LL_FLASH_SetLatency(LL_FLASH_LATENCY_4); - while (LL_FLASH_GetLatency() != LL_FLASH_LATENCY_4) {} - LL_PWR_EnableRange1BoostMode(); - LL_RCC_HSI_Enable(); - /* Wait till HSI is ready */ - while (LL_RCC_HSI_IsReady() != 1) {} - - LL_RCC_HSI_SetCalibTrimming(64); - LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_4, 85, LL_RCC_PLLR_DIV_2); - LL_RCC_PLL_EnableDomain_SYS(); - LL_RCC_PLL_Enable(); - /* Wait till PLL is ready */ - while (LL_RCC_PLL_IsReady() != 1) {} - - LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2); - /* Wait till System clock is ready */ - while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {} - - /* Insure 1us transition state at intermediate medium speed clock*/ - for (__IO uint32_t i = (170 >> 1); i != 0; i--) - ; - - /* Set AHB prescaler*/ - LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); - LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); - LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); - LL_SetSystemCoreClock(170000000); - - /* Update the time base */ - if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) { - // status = ERROR; - Error_Handler(); - } -} -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return - * state */ - __disable_irq(); - while (1) {} -} -#ifdef USE_FULL_ASSERT -/** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ -void assert_failed(uint8_t *file, uint32_t line) -{ - /* USER CODE BEGIN 6 */ - /* User can add his own implementation to report the file name and line - number, ex: printf("Wrong parameters value: file %s on line %d\r\n", - file, line) */ - /* USER CODE END 6 */ -} -#endif /* USE_FULL_ASSERT */ diff --git a/G4SPITESTING/Core/Src/stm32g4xx_hal_msp.c b/G4SPITESTING/Core/Src/stm32g4xx_hal_msp.c deleted file mode 100644 index 69189ef4e..000000000 --- a/G4SPITESTING/Core/Src/stm32g4xx_hal_msp.c +++ /dev/null @@ -1,86 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_hal_msp.c - * @brief This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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*/ - - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_PWREx_DisableUCPDDeadBattery(); - - /* USER CODE BEGIN MspInit 1 */ - - /* USER CODE END MspInit 1 */ -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4SPITESTING/Core/Src/stm32g4xx_it.c b/G4SPITESTING/Core/Src/stm32g4xx_it.c deleted file mode 100644 index 9549141b0..000000000 --- a/G4SPITESTING/Core/Src/stm32g4xx_it.c +++ /dev/null @@ -1,198 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file stm32g4xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 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 "stm32g4xx_it.h" - -#include "main.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 Prefetch 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 */ -} - -/******************************************************************************/ -/* STM32G4xx 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_stm32g4xx.s). */ -/******************************************************************************/ - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/G4SPITESTING/README.md b/G4SPITESTING/README.md deleted file mode 100644 index c35301534..000000000 --- a/G4SPITESTING/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# STM32G474 SPI -Nucleo-G474RE-C04 - -Compile and flash G4SPITESTING.elf - -## Testing - -Connect pins C11 and C12 together - -Run the program and watch the SWO console diff --git a/CUBEMXTESTING/Application/Inc/CANdler.h b/Testbench/CUBEMXTESTING/Application/Inc/CANdler.h similarity index 100% rename from CUBEMXTESTING/Application/Inc/CANdler.h rename to Testbench/CUBEMXTESTING/Application/Inc/CANdler.h diff --git a/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h b/Testbench/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h similarity index 100% rename from CUBEMXTESTING/Application/Inc/CubeCAN_Config.h rename to Testbench/CUBEMXTESTING/Application/Inc/CubeCAN_Config.h diff --git a/CUBEMXTESTING/Application/Inc/CubeVCP_Config.h b/Testbench/CUBEMXTESTING/Application/Inc/CubeVCP_Config.h similarity index 100% rename from CUBEMXTESTING/Application/Inc/CubeVCP_Config.h rename to Testbench/CUBEMXTESTING/Application/Inc/CubeVCP_Config.h diff --git a/CUBEMXTESTING/Application/Inc/Loop.h b/Testbench/CUBEMXTESTING/Application/Inc/Loop.h similarity index 100% rename from CUBEMXTESTING/Application/Inc/Loop.h rename to Testbench/CUBEMXTESTING/Application/Inc/Loop.h diff --git a/CUBEMXTESTING/Application/Src/CANdler.c b/Testbench/CUBEMXTESTING/Application/Src/CANdler.c similarity index 100% rename from CUBEMXTESTING/Application/Src/CANdler.c rename to Testbench/CUBEMXTESTING/Application/Src/CANdler.c diff --git a/CUBEMXTESTING/Application/Src/Loop.c b/Testbench/CUBEMXTESTING/Application/Src/Loop.c similarity index 100% rename from CUBEMXTESTING/Application/Src/Loop.c rename to Testbench/CUBEMXTESTING/Application/Src/Loop.c diff --git a/CUBEMXTESTING/CMakeLists.txt b/Testbench/CUBEMXTESTING/CMakeLists.txt similarity index 100% rename from CUBEMXTESTING/CMakeLists.txt rename to Testbench/CUBEMXTESTING/CMakeLists.txt diff --git a/CUBEMXTESTING/CUBEMXTESTING.ioc b/Testbench/CUBEMXTESTING/CUBEMXTESTING.ioc similarity index 100% rename from CUBEMXTESTING/CUBEMXTESTING.ioc rename to Testbench/CUBEMXTESTING/CUBEMXTESTING.ioc diff --git a/CUBEMXTESTING/Core/Inc/fdcan.h b/Testbench/CUBEMXTESTING/Core/Inc/fdcan.h similarity index 100% rename from CUBEMXTESTING/Core/Inc/fdcan.h rename to Testbench/CUBEMXTESTING/Core/Inc/fdcan.h diff --git a/CUBEMXTESTING/Core/Inc/gpio.h b/Testbench/CUBEMXTESTING/Core/Inc/gpio.h similarity index 100% rename from CUBEMXTESTING/Core/Inc/gpio.h rename to Testbench/CUBEMXTESTING/Core/Inc/gpio.h diff --git a/CUBEMXTESTING/Core/Inc/main.h b/Testbench/CUBEMXTESTING/Core/Inc/main.h similarity index 100% rename from CUBEMXTESTING/Core/Inc/main.h rename to Testbench/CUBEMXTESTING/Core/Inc/main.h diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h b/Testbench/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h similarity index 100% rename from CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h rename to Testbench/CUBEMXTESTING/Core/Inc/stm32g4xx_hal_conf.h diff --git a/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h b/Testbench/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h similarity index 100% rename from CUBEMXTESTING/Core/Inc/stm32g4xx_it.h rename to Testbench/CUBEMXTESTING/Core/Inc/stm32g4xx_it.h diff --git a/CUBEMXTESTING/Core/Inc/tim.h b/Testbench/CUBEMXTESTING/Core/Inc/tim.h similarity index 100% rename from CUBEMXTESTING/Core/Inc/tim.h rename to Testbench/CUBEMXTESTING/Core/Inc/tim.h diff --git a/CUBEMXTESTING/Core/Inc/usart.h b/Testbench/CUBEMXTESTING/Core/Inc/usart.h similarity index 100% rename from CUBEMXTESTING/Core/Inc/usart.h rename to Testbench/CUBEMXTESTING/Core/Inc/usart.h diff --git a/CUBEMXTESTING/Core/Src/fdcan.c b/Testbench/CUBEMXTESTING/Core/Src/fdcan.c similarity index 100% rename from CUBEMXTESTING/Core/Src/fdcan.c rename to Testbench/CUBEMXTESTING/Core/Src/fdcan.c diff --git a/CUBEMXTESTING/Core/Src/gpio.c b/Testbench/CUBEMXTESTING/Core/Src/gpio.c similarity index 100% rename from CUBEMXTESTING/Core/Src/gpio.c rename to Testbench/CUBEMXTESTING/Core/Src/gpio.c diff --git a/CUBEMXTESTING/Core/Src/main.c b/Testbench/CUBEMXTESTING/Core/Src/main.c similarity index 100% rename from CUBEMXTESTING/Core/Src/main.c rename to Testbench/CUBEMXTESTING/Core/Src/main.c diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c b/Testbench/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c similarity index 100% rename from CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c rename to Testbench/CUBEMXTESTING/Core/Src/stm32g4xx_hal_msp.c diff --git a/CUBEMXTESTING/Core/Src/stm32g4xx_it.c b/Testbench/CUBEMXTESTING/Core/Src/stm32g4xx_it.c similarity index 100% rename from CUBEMXTESTING/Core/Src/stm32g4xx_it.c rename to Testbench/CUBEMXTESTING/Core/Src/stm32g4xx_it.c diff --git a/CUBEMXTESTING/Core/Src/tim.c b/Testbench/CUBEMXTESTING/Core/Src/tim.c similarity index 100% rename from CUBEMXTESTING/Core/Src/tim.c rename to Testbench/CUBEMXTESTING/Core/Src/tim.c diff --git a/CUBEMXTESTING/Core/Src/usart.c b/Testbench/CUBEMXTESTING/Core/Src/usart.c similarity index 100% rename from CUBEMXTESTING/Core/Src/usart.c rename to Testbench/CUBEMXTESTING/Core/Src/usart.c diff --git a/CUBEMXTESTING/README_CAN_Timer_Configuration.md b/Testbench/CUBEMXTESTING/README_CAN_Timer_Configuration.md similarity index 100% rename from CUBEMXTESTING/README_CAN_Timer_Configuration.md rename to Testbench/CUBEMXTESTING/README_CAN_Timer_Configuration.md diff --git a/G4NEOTESTING/CMakeLists.txt b/Testbench/G4NEOTESTING/CMakeLists.txt similarity index 100% rename from G4NEOTESTING/CMakeLists.txt rename to Testbench/G4NEOTESTING/CMakeLists.txt diff --git a/G4NEOTESTING/Core/Inc/main.h b/Testbench/G4NEOTESTING/Core/Inc/main.h similarity index 100% rename from G4NEOTESTING/Core/Inc/main.h rename to Testbench/G4NEOTESTING/Core/Inc/main.h diff --git a/G431x8_CAN_TESTING/Core/Inc/stm32g4xx_hal_conf.h b/Testbench/G4NEOTESTING/Core/Inc/stm32g4xx_hal_conf.h similarity index 100% rename from G431x8_CAN_TESTING/Core/Inc/stm32g4xx_hal_conf.h rename to Testbench/G4NEOTESTING/Core/Inc/stm32g4xx_hal_conf.h diff --git a/G431x8_CAN_TESTING/Core/Inc/stm32g4xx_it.h b/Testbench/G4NEOTESTING/Core/Inc/stm32g4xx_it.h similarity index 100% rename from G431x8_CAN_TESTING/Core/Inc/stm32g4xx_it.h rename to Testbench/G4NEOTESTING/Core/Inc/stm32g4xx_it.h diff --git a/G4NEOTESTING/Core/Src/main.c b/Testbench/G4NEOTESTING/Core/Src/main.c similarity index 100% rename from G4NEOTESTING/Core/Src/main.c rename to Testbench/G4NEOTESTING/Core/Src/main.c diff --git a/G431x8_CAN_TESTING/Core/Src/stm32g4xx_hal_msp.c b/Testbench/G4NEOTESTING/Core/Src/stm32g4xx_hal_msp.c similarity index 100% rename from G431x8_CAN_TESTING/Core/Src/stm32g4xx_hal_msp.c rename to Testbench/G4NEOTESTING/Core/Src/stm32g4xx_hal_msp.c diff --git a/G4NEOTESTING/Core/Src/stm32g4xx_it.c b/Testbench/G4NEOTESTING/Core/Src/stm32g4xx_it.c similarity index 100% rename from G4NEOTESTING/Core/Src/stm32g4xx_it.c rename to Testbench/G4NEOTESTING/Core/Src/stm32g4xx_it.c diff --git a/G4NEOTESTING/README.md b/Testbench/G4NEOTESTING/README.md similarity index 100% rename from G4NEOTESTING/README.md rename to Testbench/G4NEOTESTING/README.md From bdea754e1db073ddac07f2411fb4475eea866d7b Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Mon, 17 Aug 2026 22:45:26 -0700 Subject: [PATCH 119/125] I forgot to change `.vscode` during #543 Signed-off-by: Daniel Hansen --- .vscode/launch.json | 341 -------------------------------------------- .vscode/tasks.json | 99 ------------- 2 files changed, 440 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index d7ec434ff..101ae7491 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -592,99 +592,6 @@ "showDevDebugOutput": "raw", "svdPath": "${workspaceFolder}/Lib/Vendor/CMSIS_5/SVD/STM32G474.svd" }, - { - "cwd": "${workspaceFolder}", - "executable": "${command:cmake.buildDirectory}/G4PERTESTING.elf", - "name": "G4PERTESTING", - "request": "launch", - "type": "cortex-debug", - "servertype": "openocd", - "configFiles": [ - "interface/stlink.cfg", - "target/stm32g4x.cfg" - ], - "searchDir": [], - "preLaunchTask": "CMake: configure and build G4PERTESTING", - "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Vendor/CMSIS_5/SVD/STM32G474.svd", - "swoConfig": { - "enabled": true, - "cpuFrequency": 170000000, - "swoFrequency": 2000000, - "source": "probe", - "decoders": [ - { - "type": "console", - "label": "ITM", - "showOnStartup": true, - "port": 0, - "encoding": "ascii" - } - ] - } - }, - { - "cwd": "${workspaceFolder}", - "executable": "${command:cmake.buildDirectory}/G4SPITESTING.elf", - "name": "G4SPITESTING", - "request": "launch", - "type": "cortex-debug", - "servertype": "openocd", - "configFiles": [ - "interface/stlink.cfg", - "target/stm32g4x.cfg" - ], - "searchDir": [], - "preLaunchTask": "CMake: configure and build G4SPITESTING", - "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Vendor/CMSIS_5/SVD/STM32G474.svd", - "swoConfig": { - "enabled": true, - "cpuFrequency": 170000000, - "swoFrequency": 2000000, - "source": "probe", - "decoders": [ - { - "type": "console", - "label": "ITM", - "showOnStartup": true, - "port": 0, - "encoding": "ascii" - } - ] - } - }, - { - "cwd": "${workspaceFolder}", - "executable": "${command:cmake.buildDirectory}/G4ADCTESTING.elf", - "name": "G4ADCTESTING", - "request": "launch", - "type": "cortex-debug", - "servertype": "openocd", - "configFiles": [ - "interface/stlink.cfg", - "target/stm32g4x.cfg" - ], - "searchDir": [], - "preLaunchTask": "CMake: configure and build G4ADCTESTING", - "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Vendor/CMSIS_5/SVD/STM32G474.svd", - "swoConfig": { - "enabled": true, - "cpuFrequency": 170000000, - "swoFrequency": 2000000, - "source": "probe", - "decoders": [ - { - "type": "console", - "label": "ITM", - "showOnStartup": true, - "port": 0, - "encoding": "ascii" - } - ] - } - }, { "cwd": "${workspaceFolder}", "executable": "${command:cmake.buildDirectory}/G4NEOTESTING.elf", @@ -715,254 +622,6 @@ } ] } - }, - { - "cwd": "${workspaceFolder}", - "executable": "${command:cmake.buildDirectory}/CAN_BASIC_TEST.elf", - "name": "CAN_BASIC_TEST", - "request": "launch", - "type": "cortex-debug", - "servertype": "openocd", - "configFiles": [ - "interface/stlink.cfg", - "target/stm32g4x.cfg" - ], - "searchDir": [], - "preLaunchTask": "CMake: configure and build CAN_BASIC_TEST", - "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Vendor/CMSIS_5/SVD/STM32G474.svd", - "swoConfig": { - "enabled": true, - "cpuFrequency": 170000000, - "swoFrequency": 2000000, - "source": "probe", - "decoders": [ - { - "type": "console", - "label": "ITM", - "showOnStartup": true, - "port": 0, - "encoding": "ascii" - } - ] - } - }, - { - "cwd": "${workspaceFolder}", - "executable": "${command:cmake.buildDirectory}/CAN_FILTER_TEST.elf", - "name": "CAN_FILTER_TEST", - "request": "launch", - "type": "cortex-debug", - "servertype": "openocd", - "configFiles": [ - "interface/stlink.cfg", - "target/stm32g4x.cfg" - ], - "searchDir": [], - "preLaunchTask": "CMake: configure and build CAN_FILTER_TEST", - "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Vendor/CMSIS_5/SVD/STM32G474.svd", - "swoConfig": { - "enabled": true, - "cpuFrequency": 170000000, - "swoFrequency": 2000000, - "source": "probe", - "decoders": [ - { - "type": "console", - "label": "ITM", - "showOnStartup": true, - "port": 0, - "encoding": "ascii" - } - ] - } - }, - { - "cwd": "${workspaceFolder}", - "executable": "${command:cmake.buildDirectory}/CAN_STRESS_TEST.elf", - "name": "CAN_STRESS_TEST", - "request": "launch", - "type": "cortex-debug", - "servertype": "openocd", - "configFiles": [ - "interface/stlink.cfg", - "target/stm32g4x.cfg" - ], - "searchDir": [], - "preLaunchTask": "CMake: configure and build CAN_STRESS_TEST", - "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Vendor/CMSIS_5/SVD/STM32G474.svd", - "swoConfig": { - "enabled": true, - "cpuFrequency": 170000000, - "swoFrequency": 2000000, - "source": "probe", - "decoders": [ - { - "type": "console", - "label": "ITM", - "showOnStartup": true, - "port": 0, - "encoding": "ascii" - } - ] - } - }, - { - "cwd": "${workspaceFolder}", - "executable": "${command:cmake.buildDirectory}/CAN_LOOPBACK_TEST.elf", - "name": "CAN_LOOPBACK_TEST", - "request": "launch", - "type": "cortex-debug", - "servertype": "openocd", - "configFiles": [ - "interface/stlink.cfg", - "target/stm32g4x.cfg" - ], - "searchDir": [], - "preLaunchTask": "CMake: configure and build CAN_LOOPBACK_TEST", - "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Vendor/CMSIS_5/SVD/STM32G474.svd", - "swoConfig": { - "enabled": true, - "cpuFrequency": 170000000, - "swoFrequency": 2000000, - "source": "probe", - "decoders": [ - { - "type": "console", - "label": "ITM", - "showOnStartup": true, - "port": 0, - "encoding": "ascii" - } - ] - } - }, - { - "cwd": "${workspaceFolder}", - "executable": "${command:cmake.buildDirectory}/CAN_LOST_RX_TEST.elf", - "name": "CAN_LOST_RX_TEST", - "request": "launch", - "type": "cortex-debug", - "servertype": "openocd", - "configFiles": [ - "interface/stlink.cfg", - "target/stm32g4x.cfg" - ], - "searchDir": [], - "preLaunchTask": "CMake: configure and build CAN_LOST_RX_TEST", - "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Vendor/CMSIS_5/SVD/STM32G474.svd", - "swoConfig": { - "enabled": true, - "cpuFrequency": 170000000, - "swoFrequency": 2000000, - "source": "probe", - "decoders": [ - { - "type": "console", - "label": "ITM", - "showOnStartup": true, - "port": 0, - "encoding": "ascii" - } - ] - } - }, - { - "cwd": "${workspaceFolder}", - "executable": "${command:cmake.buildDirectory}/CAN_RELEASE_TEST.elf", - "name": "CAN_RELEASE_TEST", - "request": "launch", - "type": "cortex-debug", - "servertype": "openocd", - "configFiles": [ - "interface/stlink.cfg", - "target/stm32g4x.cfg" - ], - "searchDir": [], - "preLaunchTask": "CMake: configure and build CAN_RELEASE_TEST", - "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Vendor/CMSIS_5/SVD/STM32G474.svd", - "swoConfig": { - "enabled": true, - "cpuFrequency": 170000000, - "swoFrequency": 2000000, - "source": "probe", - "decoders": [ - { - "type": "console", - "label": "ITM", - "showOnStartup": true, - "port": 0, - "encoding": "ascii" - } - ] - } - }, - { - "cwd": "${workspaceFolder}", - "executable": "${command:cmake.buildDirectory}/PROFILER_TEST.elf", - "name": "PROFILER_TEST", - "request": "launch", - "type": "cortex-debug", - "servertype": "openocd", - "configFiles": [ - "interface/stlink.cfg", - "target/stm32g4x.cfg" - ], - "searchDir": [], - "preLaunchTask": "CMake: configure and build PROFILER_TEST", - "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Vendor/CMSIS_5/SVD/STM32G474.svd", - "swoConfig": { - "enabled": true, - "cpuFrequency": 170000000, - "swoFrequency": 2000000, - "source": "probe", - "decoders": [ - { - "type": "console", - "label": "ITM", - "showOnStartup": true, - "port": 0, - "encoding": "ascii" - } - ] - } - }, - { - "cwd": "${workspaceFolder}", - "executable": "${command:cmake.buildDirectory}/G431x8_CAN_BASIC_TEST.elf", - "name": "G431x8_CAN_BASIC_TEST", - "request": "launch", - "type": "cortex-debug", - "servertype": "openocd", - "configFiles": [ - "interface/stlink.cfg", - "target/stm32g4x.cfg" - ], - "searchDir": [], - "preLaunchTask": "CMake: configure and build G431x8_CAN_BASIC_TEST", - "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Vendor/CMSIS_5/SVD/STM32G431.svd", - "swoConfig": { - "enabled": true, - "cpuFrequency": 170000000, - "swoFrequency": 2000000, - "source": "probe", - "decoders": [ - { - "type": "console", - "label": "ITM", - "showOnStartup": true, - "port": 0, - "encoding": "ascii" - } - ] - } } ] } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index dd3358969..d3cb13330 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -164,33 +164,6 @@ ], "command": "cmake --build --preset ${command:cmake.activeBuildPresetName} --target G4HELLO" }, - { - "label": "CMake: configure and build G4PERTESTING", - "type": "shell", - "dependsOrder": "sequence", - "dependsOn": [ - "CMake: configure" - ], - "command": "cmake --build --preset ${command:cmake.activeBuildPresetName} --target G4PERTESTING" - }, - { - "label": "CMake: configure and build G4ADCTESTING", - "type": "shell", - "dependsOrder": "sequence", - "dependsOn": [ - "CMake: configure" - ], - "command": "cmake --build --preset ${command:cmake.activeBuildPresetName} --target G4ADCTESTING" - }, - { - "label": "CMake: configure and build G4SPITESTING", - "type": "shell", - "dependsOrder": "sequence", - "dependsOn": [ - "CMake: configure" - ], - "command": "cmake --build --preset ${command:cmake.activeBuildPresetName} --target G4SPITESTING" - }, { "label": "CMake: configure and build G4NEOTESTING", "type": "shell", @@ -253,78 +226,6 @@ "CMake: configure" ], "command": "cmake --build --preset ${command:cmake.activeBuildPresetName} --target W3_G4SPI_Receive" - }, - { - "label": "CMake: configure and build CAN_BASIC_TEST", - "type": "shell", - "dependsOrder": "sequence", - "dependsOn": [ - "CMake: configure" - ], - "command": "cmake --build --preset ${command:cmake.activeBuildPresetName} --target CAN_BASIC_TEST" - }, - { - "label": "CMake: configure and build CAN_STRESS_TEST", - "type": "shell", - "dependsOrder": "sequence", - "dependsOn": [ - "CMake: configure" - ], - "command": "cmake --build --preset ${command:cmake.activeBuildPresetName} --target CAN_STRESS_TEST" - }, - { - "label": "CMake: configure and build CAN_FILTER_TEST", - "type": "shell", - "dependsOrder": "sequence", - "dependsOn": [ - "CMake: configure" - ], - "command": "cmake --build --preset ${command:cmake.activeBuildPresetName} --target CAN_FILTER_TEST" - }, - { - "label": "CMake: configure and build CAN_RELEASE_TEST", - "type": "shell", - "dependsOrder": "sequence", - "dependsOn": [ - "CMake: configure" - ], - "command": "cmake --build --preset ${command:cmake.activeBuildPresetName} --target CAN_RELEASE_TEST" - }, - { - "label": "CMake: configure and build CAN_LOST_RX_TEST", - "type": "shell", - "dependsOrder": "sequence", - "dependsOn": [ - "CMake: configure" - ], - "command": "cmake --build --preset ${command:cmake.activeBuildPresetName} --target CAN_LOST_RX_TEST" - }, - { - "label": "CMake: configure and build CAN_LOOPBACK_TEST", - "type": "shell", - "dependsOrder": "sequence", - "dependsOn": [ - "CMake: configure" - ], - "command": "cmake --build --preset ${command:cmake.activeBuildPresetName} --target CAN_LOOPBACK_TEST" - }, - { - "label": "CMake: configure and build PROFILER_TEST", - "type": "shell", - "dependsOrder": "sequence", - "dependsOn": [ - "CMake: configure" - ], - "command": "cmake --build --preset ${command:cmake.activeBuildPresetName} --target PROFILER_TEST" - }, - { - "label": "CMake: configure and build G431x8_CAN_BASIC_TEST", - "type": "shell", - "dependsOrder": "sequence", - "dependsOn": [ - "CMake: configure" - ], - "command": "cmake --build --preset ${command:cmake.activeBuildPresetName} --target G431x8_CAN_BASIC_TEST" } ] } From e2717187f5b35fc1adaec8b8cf9c59d2f0c48610 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Tue, 18 Aug 2026 00:56:52 -0700 Subject: [PATCH 120/125] Add deprecation notice for ADC Signed-off-by: Daniel Hansen --- Lib/FancyLayers-RENAME/ADC/adc.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Lib/FancyLayers-RENAME/ADC/adc.cmake b/Lib/FancyLayers-RENAME/ADC/adc.cmake index 941fca30d..ea5f29bf6 100644 --- a/Lib/FancyLayers-RENAME/ADC/adc.cmake +++ b/Lib/FancyLayers-RENAME/ADC/adc.cmake @@ -5,3 +5,10 @@ target_sources(GR_ADC INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Src/gr_adc.c) target_include_directories(GR_ADC INTERFACE ${CMAKE_CURRENT_LIST_DIR}/Inc) target_link_libraries(GR_ADC INTERFACE GLOBALSHARE_LIB) + +set_target_properties( + GR_ADC + PROPERTIES + DEPRECATION + "GR_ADC is deprecated and should be removed in favor of STM32CubeMX functionality." +) From a05c9f6fb240dbb033ee587555f257994b8f7367 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Tue, 18 Aug 2026 00:59:13 -0700 Subject: [PATCH 121/125] Add deprecation notice for SPI Signed-off-by: Daniel Hansen --- Lib/FancyLayers-RENAME/SPI/spi.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Lib/FancyLayers-RENAME/SPI/spi.cmake b/Lib/FancyLayers-RENAME/SPI/spi.cmake index d2f773772..856b2566f 100644 --- a/Lib/FancyLayers-RENAME/SPI/spi.cmake +++ b/Lib/FancyLayers-RENAME/SPI/spi.cmake @@ -9,3 +9,10 @@ target_link_libraries( MsgBuffer_Lib GLOBALSHARE_LIB ) + +set_target_properties( + SPI_Lib + PROPERTIES + DEPRECATION + "SPI_Lib is deprecated and should be removed in favor of STM32CubeMX functionality." +) From 363ac85404b1a874535af2061c1d6b01219b72d9 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Tue, 18 Aug 2026 00:59:20 -0700 Subject: [PATCH 122/125] Add deprecation notice for USART Signed-off-by: Daniel Hansen --- Lib/Peripherals/USART/common.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Lib/Peripherals/USART/common.cmake b/Lib/Peripherals/USART/common.cmake index 5c0d4577b..2f8aaac01 100644 --- a/Lib/Peripherals/USART/common.cmake +++ b/Lib/Peripherals/USART/common.cmake @@ -8,3 +8,10 @@ target_include_directories( INTERFACE ${CMAKE_CURRENT_LIST_DIR}/../.. ) + +set_target_properties( + PERIPHERAL_USART_LIB + PROPERTIES + DEPRECATION + "PERIPHERAL_USART_LIB is deprecated and should be removed in favor of STM32CubeMX functionality or VCP_LIB." +) From d39d795a6233e786aea326bdc2060f4f9f426e62 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Tue, 18 Aug 2026 01:01:37 -0700 Subject: [PATCH 123/125] Add deprecation notice for VCP Signed-off-by: Daniel Hansen --- Lib/Utils/VirtualComPort/vcp.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Lib/Utils/VirtualComPort/vcp.cmake b/Lib/Utils/VirtualComPort/vcp.cmake index fb200f096..9eda7ead3 100644 --- a/Lib/Utils/VirtualComPort/vcp.cmake +++ b/Lib/Utils/VirtualComPort/vcp.cmake @@ -18,3 +18,10 @@ target_link_libraries( GLOBALSHARE_LIB LOGOMATIC_OLD_LIB ) + +set_target_properties( + VCP_LIB + PROPERTIES + DEPRECATION + "VCP_LIB is deprecated and should be removed in favor of CUBE_VCP_LIB." +) From 9aa1921303262ac1fd8d4f8ae139e41c66ff63f0 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Tue, 18 Aug 2026 01:02:05 -0700 Subject: [PATCH 124/125] Format Signed-off-by: Daniel Hansen From 2458029bd02f7a86ff987346969d29708e10628a Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Tue, 18 Aug 2026 02:12:10 -0700 Subject: [PATCH 125/125] Remove old timer config instructions Signed-off-by: Daniel Hansen --- .../README_CAN_Timer_Configuration.md | 941 ------------------ 1 file changed, 941 deletions(-) delete mode 100644 Testbench/CUBEMXTESTING/README_CAN_Timer_Configuration.md diff --git a/Testbench/CUBEMXTESTING/README_CAN_Timer_Configuration.md b/Testbench/CUBEMXTESTING/README_CAN_Timer_Configuration.md deleted file mode 100644 index ee8330180..000000000 --- a/Testbench/CUBEMXTESTING/README_CAN_Timer_Configuration.md +++ /dev/null @@ -1,941 +0,0 @@ -# CAN Timer Configuration Guide - -This guide explains how to configure, modify, and extend the CubeMX-based CAN timer implementation. - -The current design uses STM32CubeMX for hardware configuration and a custom CAN runtime for software queue handling. - ---- - -# 1. Ownership Model - -## CubeMX controls - -CubeMX owns all hardware-level configuration: - -- enabled FDCAN peripherals -- enabled timer peripherals -- FDCAN GPIO pins -- FDCAN clock source -- FDCAN bit timing -- timer clock source -- timer prescaler -- initial timer period -- NVIC interrupt enable -- NVIC interrupt priority -- generated HAL handles -- generated interrupt handlers - -Examples: - -```c -FDCAN_HandleTypeDef hfdcan1; -FDCAN_HandleTypeDef hfdcan2; -TIM_HandleTypeDef htim5; -``` - -CubeMX also generates: - -```c -MX_FDCAN1_Init(); -MX_FDCAN2_Init(); -MX_TIM5_Init(); -``` - -Do not manually duplicate this hardware initialization inside the custom CAN library. - -## User-controlled runtime settings - -The user-controlled values are stored in the generated `can_cfg.h` file inside a preserved user-code section. - -Example: - -```c -/* USER CODE BEGIN CAN_USER_CONFIG */ - -#ifndef TX_BUFFER_1_SIZE -#define TX_BUFFER_1_SIZE 20U -#endif - -#ifndef TX_BUFFER_2_SIZE -#define TX_BUFFER_2_SIZE 20U -#endif - -#ifndef TX_BUFFER_3_SIZE -#define TX_BUFFER_3_SIZE 20U -#endif - -#ifndef CAN_TIMER_INDEX -#define CAN_TIMER_INDEX 5 -#endif - -#ifndef CAN_TIMER_TICK_US -#define CAN_TIMER_TICK_US 100U -#endif - -#ifndef CAN_DEQUEUE_PERIOD_US -#define CAN_DEQUEUE_PERIOD_US 500U -#endif - -/* USER CODE END CAN_USER_CONFIG */ -``` - -CubeMX preserves values inside this section when code is regenerated. - ---- - -# 2. Editable Values - -## `TX_BUFFER_1_SIZE` - -Controls the number of software-queued transmit messages for CAN1. - -```c -#define TX_BUFFER_1_SIZE 20U -``` - -Example: - -```c -#define TX_BUFFER_1_SIZE 50U -``` - -Use a larger value when CAN1 may temporarily produce messages faster than the hardware can transmit them. - -A larger queue consumes more RAM. - -## `TX_BUFFER_2_SIZE` - -Controls the software TX queue size for CAN2. - -```c -#define TX_BUFFER_2_SIZE 20U -``` - -## `TX_BUFFER_3_SIZE` - -Controls the software TX queue size for CAN3. - -```c -#define TX_BUFFER_3_SIZE 20U -``` - -This value is ignored when CAN3 is not enabled. - -Queue sizes must be greater than zero. - ---- - -## `CAN_TIMER_INDEX` - -Selects the CubeMX-generated timer used for CAN queue servicing. - -```c -#define CAN_TIMER_INDEX 5 -``` - -This maps to: - -```c -htim5 -``` - -Examples: - -```c -#define CAN_TIMER_INDEX 1 -``` - -selects: - -```c -htim1 -``` - -```c -#define CAN_TIMER_INDEX 2 -``` - -selects: - -```c -htim2 -``` - -```c -#define CAN_TIMER_INDEX 3 -``` - -selects: - -```c -htim3 -``` - -The selected timer must also be enabled in CubeMX. - -If the selected timer is not enabled, the generated configuration should produce a compile-time error. - ---- - -## `CAN_TIMER_TICK_US` - -Defines the duration of one timer counter tick in microseconds. - -```c -#define CAN_TIMER_TICK_US 100U -``` - -This value must match the timer prescaler configured in CubeMX. - -The equation is: - -```text -Timer counter frequency = -Timer input clock / (Prescaler + 1) -``` - -Then: - -```text -Timer tick duration = -1 / Timer counter frequency -``` - -For a 160 MHz timer clock and: - -```c -Prescaler = 15999 -``` - -the counter frequency is: - -```text -160,000,000 / 16,000 = 10,000 Hz -``` - -Therefore: - -```text -1 count = 100 us -``` - -The matching runtime value is: - -```c -#define CAN_TIMER_TICK_US 100U -``` - -### Example: 10 us timer tick - -To create a 10 us timer tick with a 160 MHz timer clock: - -```text -Prescaler = 1599 -``` - -because: - -```text -160,000,000 / 1600 = 100,000 Hz -``` - -Therefore: - -```text -1 count = 10 us -``` - -The matching configuration is: - -```c -#define CAN_TIMER_TICK_US 10U -``` - -Always change the prescaler through CubeMX. - -Do not manually edit the generated `tim.c` file. - ---- - -## `CAN_DEQUEUE_PERIOD_US` - -Controls how often the runtime attempts to dequeue and transmit a queued CAN message. - -```c -#define CAN_DEQUEUE_PERIOD_US 500U -``` - -For: - -```c -#define CAN_TIMER_TICK_US 100U -``` - -the timer uses: - -```text -500 us / 100 us = 5 counts -``` - -The auto-reload value becomes: - -```text -ARR = 5 - 1 = 4 -``` - -The generated macros calculate this automatically: - -```c -#define CAN_TIMER_PERIOD_COUNTS \ - (CAN_DEQUEUE_PERIOD_US / CAN_TIMER_TICK_US) - -#define CAN_TIMER_AUTORELOAD \ - (CAN_TIMER_PERIOD_COUNTS - 1U) -``` - -### Example periods - -With a 100 us timer tick: - -| Desired dequeue period | `CAN_DEQUEUE_PERIOD_US` | ARR | -|---:|---:|---:| -| 500 us | `500U` | 4 | -| 1 ms | `1000U` | 9 | -| 2 ms | `2000U` | 19 | -| 5 ms | `5000U` | 49 | -| 10 ms | `10000U` | 99 | -| 100 ms | `100000U` | 999 | - -The dequeue period must be evenly divisible by the timer tick. - -Valid: - -```c -#define CAN_TIMER_TICK_US 100U -#define CAN_DEQUEUE_PERIOD_US 500U -``` - -Invalid: - -```c -#define CAN_TIMER_TICK_US 100U -#define CAN_DEQUEUE_PERIOD_US 550U -``` - -The second example is invalid because 550 us cannot be represented exactly using 100 us timer counts. - ---- - -# 3. Changing the Active Timer - -To change from TIM5 to TIM2: - -## Step 1: Enable TIM2 in CubeMX - -In CubeMX: - -```text -Pinout & Configuration - Timers - TIM2 - Clock Source: Internal Clock -``` - -Configure the desired prescaler and period. - -Enable: - -```text -TIM2 global interrupt -``` - -## Step 2: Regenerate code - -CubeMX should generate: - -```c -TIM_HandleTypeDef htim2; -void MX_TIM2_Init(void); -``` - -and: - -```c -void TIM2_IRQHandler(void) -{ - HAL_TIM_IRQHandler(&htim2); -} -``` - -## Step 3: Change `can_cfg.h` - -```c -#define CAN_TIMER_INDEX 2 -``` - -## Step 4: Update the timer tick - -Set `CAN_TIMER_TICK_US` to match TIM2's prescaler. - -Example: - -```c -#define CAN_TIMER_TICK_US 100U -``` - -## Step 5: Initialize TIM2 in `main.c` - -CubeMX should generate: - -```c -MX_TIM2_Init(); -``` - -before: - -```c -CAN_Timer_Start(); -``` - ---- - -# 4. Using One Shared Timer - -The current implementation uses one selected timer for all enabled CAN buses. - -Example: - -```text -TIM5 - | - +--> CAN_Timer_Tick() - | - +--> service CAN1 queue - +--> service CAN2 queue -``` - -This is the recommended design in most cases. - -Advantages: - -- fewer hardware timers used -- simpler configuration -- simpler startup -- one callback -- easier CubeMX integration -- easier synchronization between CAN buses - -The callback is: - -```c -void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) -{ - if (htim == &CAN_TIMER_HANDLE) { - CAN_Timer_Tick(); - } -} -``` - ---- - -# 5. Servicing Multiple CAN Buses - -## Priority-based scheduling - -This approach always checks CAN1 first: - -```c -void CAN_Timer_Tick(void) -{ -#ifdef USECAN1 - if (CAN_ProcessOneTxMessage(&can1)) { - return; - } -#endif - -#ifdef USECAN2 - if (CAN_ProcessOneTxMessage(&can2)) { - return; - } -#endif - -#ifdef USECAN3 - (void)CAN_ProcessOneTxMessage(&can3); -#endif -} -``` - -Advantages: - -- simple -- supports bus priority - -Disadvantage: - -- lower-priority buses can be starved - -## Round-robin scheduling - -This approach alternates between buses: - -```c -void CAN_Timer_Tick(void) -{ - static uint8_t next_bus = 0U; - -#if defined(USECAN1) && defined(USECAN2) - - if (next_bus == 0U) { - (void)CAN_ProcessOneTxMessage(&can1); - next_bus = 1U; - } else { - (void)CAN_ProcessOneTxMessage(&can2); - next_bus = 0U; - } - -#elif defined(USECAN1) - - (void)CAN_ProcessOneTxMessage(&can1); - -#elif defined(USECAN2) - - (void)CAN_ProcessOneTxMessage(&can2); - -#endif -} -``` - -Advantages: - -- fairer between buses -- avoids CAN1 permanently dominating CAN2 - ---- - -# 6. Using Multiple Active Timers - -The current template selects one shared timer. - -It can be extended so each CAN peripheral uses a separate timer. - -Example: - -```text -TIM1 services CAN1 -TIM2 services CAN2 -TIM3 services CAN3 -``` - -Use separate configuration values: - -```c -#define CAN1_TIMER_INDEX 1 -#define CAN2_TIMER_INDEX 2 -#define CAN3_TIMER_INDEX 3 - -#define CAN1_TIMER_TICK_US 100U -#define CAN2_TIMER_TICK_US 100U -#define CAN3_TIMER_TICK_US 100U - -#define CAN1_DEQUEUE_PERIOD_US 500U -#define CAN2_DEQUEUE_PERIOD_US 1000U -#define CAN3_DEQUEUE_PERIOD_US 2000U -``` - -Create separate timer handles: - -```c -#define CAN1_TIMER_HANDLE \ - CAN_CFG_JOIN(htim, CAN1_TIMER_INDEX) - -#define CAN2_TIMER_HANDLE \ - CAN_CFG_JOIN(htim, CAN2_TIMER_INDEX) - -#define CAN3_TIMER_HANDLE \ - CAN_CFG_JOIN(htim, CAN3_TIMER_INDEX) -``` - -Create separate auto-reload values: - -```c -#define CAN1_TIMER_AUTORELOAD \ - ((CAN1_DEQUEUE_PERIOD_US / CAN1_TIMER_TICK_US) - 1U) - -#define CAN2_TIMER_AUTORELOAD \ - ((CAN2_DEQUEUE_PERIOD_US / CAN2_TIMER_TICK_US) - 1U) - -#define CAN3_TIMER_AUTORELOAD \ - ((CAN3_DEQUEUE_PERIOD_US / CAN3_TIMER_TICK_US) - 1U) -``` - -The callback would route each timer separately: - -```c -void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) -{ -#ifdef USECAN1 - if (htim == &CAN1_TIMER_HANDLE) { - CAN1_Timer_Tick(); - return; - } -#endif - -#ifdef USECAN2 - if (htim == &CAN2_TIMER_HANDLE) { - CAN2_Timer_Tick(); - return; - } -#endif - -#ifdef USECAN3 - if (htim == &CAN3_TIMER_HANDLE) { - CAN3_Timer_Tick(); - return; - } -#endif -} -``` - -Each timer must also be started separately: - -```c -if (CAN1_Timer_Start() != HAL_OK) { - Error_Handler(); -} - -if (CAN2_Timer_Start() != HAL_OK) { - Error_Handler(); -} - -if (CAN3_Timer_Start() != HAL_OK) { - Error_Handler(); -} -``` - -Use multiple timers only when the buses require: - -- independent transmission periods -- strict timing separation -- different interrupt priorities -- separate bandwidth policies - -For most applications, one shared timer with round-robin queue servicing is simpler and more efficient. - ---- - -# 7. Timer Startup Function - -The shared-timer implementation should use: - -```c -HAL_StatusTypeDef CAN_Timer_Start(void) -{ - TIM_HandleTypeDef *htim = &CAN_TIMER_HANDLE; - - __HAL_TIM_DISABLE(htim); - - __HAL_TIM_SET_AUTORELOAD( - htim, - CAN_TIMER_AUTORELOAD); - - __HAL_TIM_SET_COUNTER(htim, 0U); - - htim->Instance->EGR = TIM_EGR_UG; - - __HAL_TIM_CLEAR_FLAG( - htim, - TIM_FLAG_UPDATE); - - return HAL_TIM_Base_Start_IT(htim); -} -``` - -This function changes only the runtime period. - -It does not configure: - -- timer clocks -- timer prescaler -- NVIC -- timer instance -- timer IRQ handler - -CubeMX owns those settings. - ---- - -# 8. Required Startup Order - -The hardware initialization must happen before custom runtime initialization. - -Correct: - -```c -MX_GPIO_Init(); -MX_FDCAN1_Init(); -MX_FDCAN2_Init(); -MX_TIM5_Init(); - -GR_CAN_Init(); - -if (CAN_Timer_Start() != HAL_OK) { - Error_Handler(); -} -``` - -Incorrect: - -```c -CAN_Timer_Start(); -MX_TIM5_Init(); -``` - -The timer handle is not ready until `MX_TIM5_Init()` runs. - ---- - -# 9. Files That May Be Edited - -## Edit directly - -These files contain custom code: - -```text -can.c -can.h -gr_can_init.c -gr_can_init.h -can_cfg_h.ftl -README -CMakeLists.txt -``` - -## Edit only inside user-code sections - -```text -main.c -``` - -Examples: - -```c -/* USER CODE BEGIN Includes */ -/* USER CODE END Includes */ -``` - -```c -/* USER CODE BEGIN 2 */ -/* USER CODE END 2 */ -``` - -```c -/* USER CODE BEGIN 4 */ -/* USER CODE END 4 */ -``` - -## Do not manually edit - -These files are generated by CubeMX: - -```text -fdcan.c -fdcan.h -tim.c -tim.h -gpio.c -gpio.h -stm32g4xx_it.c -stm32g4xx_it.h -stm32g4xx_hal_conf.h -``` - -Modify their settings through CubeMX and regenerate. - ---- - -# 10. Regeneration Checklist - -After regenerating CubeMX code, verify: - -```text -main.c includes tim.h -main.c calls MX_TIM5_Init() -tim.c exists -tim.h exists -htim5 is declared -TIM5_IRQHandler exists -HAL_TIM_MODULE_ENABLED is defined -FDCAN1 and FDCAN2 still initialize -can_cfg.h contains USECAN1 and USECAN2 -Core/Src/tim.c is included in the build -``` - -Also verify that custom code remains inside user-code sections. - ---- - -# 11. Testing Changes - -## Test timer frequency - -Temporarily replace queue servicing with a counter: - -```c -volatile uint32_t can_timer_ticks = 0U; - -void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) -{ - if (htim == &CAN_TIMER_HANDLE) { - can_timer_ticks++; - } -} -``` - -With: - -```c -#define CAN_DEQUEUE_PERIOD_US 500U -``` - -the counter should increment approximately 2,000 times per second. - -For easier debugging: - -```c -#define CAN_DEQUEUE_PERIOD_US 100000U -``` - -This creates one callback every 100 ms. - -## Test CAN queue servicing - -1. Initialize FDCAN. -2. Initialize the custom CAN runtime. -3. Start the timer. -4. Add one frame to the software queue. -5. Confirm `CAN_Timer_Tick()` runs. -6. Confirm one frame is removed from the queue. -7. Confirm the HAL transmit function succeeds. -8. Confirm another CAN node receives the frame. - ---- - -# 12. Common Errors - -## Selected timer is not enabled - -Example: - -```text -CAN_TIMER_INDEX selects TIM2, but TIM2 is not enabled in CubeMX -``` - -Fix: - -- enable TIM2 in CubeMX, or -- select an enabled timer - -## `htim5` linker error - -Confirm: - -```text -Core/Src/tim.c -``` - -is included in the build. - -## No timer callback - -Confirm: - -- `MX_TIM5_Init()` is called -- `CAN_Timer_Start()` returns `HAL_OK` -- the timer interrupt is enabled -- `TIM5_IRQHandler()` exists -- `HAL_TIM_IRQHandler(&htim5)` is called -- global interrupts are enabled - -## Wrong timer rate - -Confirm: - -- timer input clock -- prescaler -- `CAN_TIMER_TICK_US` -- `CAN_DEQUEUE_PERIOD_US` - -All four values must agree. - -## Duplicate interrupt handler - -Do not define another: - -```c -TIM5_IRQHandler() -``` - -inside the CAN library. - -CubeMX owns the IRQ handler. - -## Messages remain queued - -Check: - -- FDCAN was started -- the hardware TX FIFO has room -- another node is present to acknowledge messages -- the transceiver is enabled -- bus bit timing matches -- queue dequeue code is being called - ---- - -# 13. Current Default Configuration - -Current timer: - -```text -TIM5 -``` - -Timer input clock: - -```text -160 MHz -``` - -Prescaler: - -```text -15999 -``` - -Timer tick: - -```text -100 us -``` - -CAN dequeue period: - -```text -500 us -``` - -Calculated auto-reload: - -```text -4 -``` - -Default queue sizes: - -```text -CAN1: 20 messages -CAN2: 20 messages -CAN3: 20 messages -``` - -The current implementation uses one shared timer for all enabled CAN buses.