From 7b0938748abc6c000de52b3b7d9303908840d392 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 30 Oct 2025 04:43:08 -0700 Subject: [PATCH 1/9] Remove empty peripheral files for STM32 platforms --- Lib/Platform/STM32G474xE/Peripheral/ADC/empty.txt | 0 Lib/Platform/STM32G474xE/Peripheral/CAN/empty.txt | 0 Lib/Platform/STM32G474xE/Peripheral/DAC/empty.txt | 0 Lib/Platform/STM32G474xE/Peripheral/GPIO/empty.txt | 0 Lib/Platform/STM32G474xE/Peripheral/I2C/empty.txt | 0 Lib/Platform/STM32G474xE/Peripheral/SPI/empty.txt | 0 Lib/Platform/STM32L476xG/Peripheral/ADC/empty.txt | 0 Lib/Platform/STM32L476xG/Peripheral/CAN/empty.txt | 0 Lib/Platform/STM32L476xG/Peripheral/DAC/empty.txt | 0 Lib/Platform/STM32L476xG/Peripheral/GPIO/empty.txt | 0 Lib/Platform/STM32L476xG/Peripheral/I2C/empty.txt | 0 Lib/Platform/STM32L476xG/Peripheral/SPI/empty.txt | 0 Lib/Platform/STM32U5A9xJ/Peripheral/ADC/empty.txt | 0 Lib/Platform/STM32U5A9xJ/Peripheral/CAN/empty.txt | 0 Lib/Platform/STM32U5A9xJ/Peripheral/DAC/empty.txt | 0 Lib/Platform/STM32U5A9xJ/Peripheral/GPIO/empty.txt | 0 Lib/Platform/STM32U5A9xJ/Peripheral/I2C/empty.txt | 0 Lib/Platform/STM32U5A9xJ/Peripheral/SPI/empty.txt | 0 18 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Lib/Platform/STM32G474xE/Peripheral/ADC/empty.txt delete mode 100644 Lib/Platform/STM32G474xE/Peripheral/CAN/empty.txt delete mode 100644 Lib/Platform/STM32G474xE/Peripheral/DAC/empty.txt delete mode 100644 Lib/Platform/STM32G474xE/Peripheral/GPIO/empty.txt delete mode 100644 Lib/Platform/STM32G474xE/Peripheral/I2C/empty.txt delete mode 100644 Lib/Platform/STM32G474xE/Peripheral/SPI/empty.txt delete mode 100644 Lib/Platform/STM32L476xG/Peripheral/ADC/empty.txt delete mode 100644 Lib/Platform/STM32L476xG/Peripheral/CAN/empty.txt delete mode 100644 Lib/Platform/STM32L476xG/Peripheral/DAC/empty.txt delete mode 100644 Lib/Platform/STM32L476xG/Peripheral/GPIO/empty.txt delete mode 100644 Lib/Platform/STM32L476xG/Peripheral/I2C/empty.txt delete mode 100644 Lib/Platform/STM32L476xG/Peripheral/SPI/empty.txt delete mode 100644 Lib/Platform/STM32U5A9xJ/Peripheral/ADC/empty.txt delete mode 100644 Lib/Platform/STM32U5A9xJ/Peripheral/CAN/empty.txt delete mode 100644 Lib/Platform/STM32U5A9xJ/Peripheral/DAC/empty.txt delete mode 100644 Lib/Platform/STM32U5A9xJ/Peripheral/GPIO/empty.txt delete mode 100644 Lib/Platform/STM32U5A9xJ/Peripheral/I2C/empty.txt delete mode 100644 Lib/Platform/STM32U5A9xJ/Peripheral/SPI/empty.txt diff --git a/Lib/Platform/STM32G474xE/Peripheral/ADC/empty.txt b/Lib/Platform/STM32G474xE/Peripheral/ADC/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32G474xE/Peripheral/CAN/empty.txt b/Lib/Platform/STM32G474xE/Peripheral/CAN/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32G474xE/Peripheral/DAC/empty.txt b/Lib/Platform/STM32G474xE/Peripheral/DAC/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32G474xE/Peripheral/GPIO/empty.txt b/Lib/Platform/STM32G474xE/Peripheral/GPIO/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32G474xE/Peripheral/I2C/empty.txt b/Lib/Platform/STM32G474xE/Peripheral/I2C/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32G474xE/Peripheral/SPI/empty.txt b/Lib/Platform/STM32G474xE/Peripheral/SPI/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32L476xG/Peripheral/ADC/empty.txt b/Lib/Platform/STM32L476xG/Peripheral/ADC/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32L476xG/Peripheral/CAN/empty.txt b/Lib/Platform/STM32L476xG/Peripheral/CAN/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32L476xG/Peripheral/DAC/empty.txt b/Lib/Platform/STM32L476xG/Peripheral/DAC/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32L476xG/Peripheral/GPIO/empty.txt b/Lib/Platform/STM32L476xG/Peripheral/GPIO/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32L476xG/Peripheral/I2C/empty.txt b/Lib/Platform/STM32L476xG/Peripheral/I2C/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32L476xG/Peripheral/SPI/empty.txt b/Lib/Platform/STM32L476xG/Peripheral/SPI/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32U5A9xJ/Peripheral/ADC/empty.txt b/Lib/Platform/STM32U5A9xJ/Peripheral/ADC/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32U5A9xJ/Peripheral/CAN/empty.txt b/Lib/Platform/STM32U5A9xJ/Peripheral/CAN/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32U5A9xJ/Peripheral/DAC/empty.txt b/Lib/Platform/STM32U5A9xJ/Peripheral/DAC/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32U5A9xJ/Peripheral/GPIO/empty.txt b/Lib/Platform/STM32U5A9xJ/Peripheral/GPIO/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32U5A9xJ/Peripheral/I2C/empty.txt b/Lib/Platform/STM32U5A9xJ/Peripheral/I2C/empty.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/Lib/Platform/STM32U5A9xJ/Peripheral/SPI/empty.txt b/Lib/Platform/STM32U5A9xJ/Peripheral/SPI/empty.txt deleted file mode 100644 index e69de29b..00000000 From 8e69b42a8e09265b0458304743300e07b883f943 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 30 Oct 2025 04:48:28 -0700 Subject: [PATCH 2/9] Add STM32G474 Hello World project - Created new project files for STM32G474 including main.c, interrupt handlers, and HAL MSP initialization. - Implemented system calls and memory management functions. - Configured system clock settings and GPIO initialization. - Added README.md for project setup instructions. - Updated CMakeLists.txt to include the new G4HELLO project. --- BLINKY/G4HELLO/CMakeLists.txt | 50 +++ BLINKY/G4HELLO/Core/Inc/main.h | 95 +++++ BLINKY/G4HELLO/Core/Inc/stm32g4xx_hal_conf.h | 380 +++++++++++++++++++ BLINKY/G4HELLO/Core/Inc/stm32g4xx_it.h | 67 ++++ BLINKY/G4HELLO/Core/Src/main.c | 297 +++++++++++++++ BLINKY/G4HELLO/Core/Src/stm32g4xx_hal_msp.c | 86 +++++ BLINKY/G4HELLO/Core/Src/stm32g4xx_it.c | 223 +++++++++++ BLINKY/G4HELLO/Core/Src/syscalls.c | 244 ++++++++++++ BLINKY/G4HELLO/Core/Src/sysmem.c | 87 +++++ BLINKY/G4HELLO/Core/Src/system_stm32g4xx.c | 285 ++++++++++++++ BLINKY/G4HELLO/README.md | 8 + CMakeLists.txt | 2 + 12 files changed, 1824 insertions(+) create mode 100644 BLINKY/G4HELLO/CMakeLists.txt create mode 100644 BLINKY/G4HELLO/Core/Inc/main.h create mode 100644 BLINKY/G4HELLO/Core/Inc/stm32g4xx_hal_conf.h create mode 100644 BLINKY/G4HELLO/Core/Inc/stm32g4xx_it.h create mode 100644 BLINKY/G4HELLO/Core/Src/main.c create mode 100644 BLINKY/G4HELLO/Core/Src/stm32g4xx_hal_msp.c create mode 100644 BLINKY/G4HELLO/Core/Src/stm32g4xx_it.c create mode 100644 BLINKY/G4HELLO/Core/Src/syscalls.c create mode 100644 BLINKY/G4HELLO/Core/Src/sysmem.c create mode 100644 BLINKY/G4HELLO/Core/Src/system_stm32g4xx.c create mode 100644 BLINKY/G4HELLO/README.md diff --git a/BLINKY/G4HELLO/CMakeLists.txt b/BLINKY/G4HELLO/CMakeLists.txt new file mode 100644 index 00000000..8febf9b6 --- /dev/null +++ b/BLINKY/G4HELLO/CMakeLists.txt @@ -0,0 +1,50 @@ +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() + +# what, does in fact not get the filename of somthing but rather the name of the project from the path +get_filename_component(GR_PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) + +# 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}) + +# Questionable... +# set(TARGET_FLAGS "-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard ") +# set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "-T${CHIP_PATH}/CompileDependencies/STM32G474RETx_FLASH.ld") + +add_library(${GR_PROJECT_NAME}_USER_CODE INTERFACE) +target_sources( + ${GR_PROJECT_NAME}_USER_CODE + INTERFACE + Core/Src/main.c + Core/Src/stm32g4xx_it.c + Core/Src/stm32g4xx_hal_msp.c + Core/Src/system_stm32g4xx.c + Core/Src/sysmem.c + Core/Src/syscalls.c +) + +target_link_libraries(${GR_PROJECT_NAME}_USER_CODE INTERFACE) + +target_include_directories( + ${GR_PROJECT_NAME}_USER_CODE + INTERFACE + Core/Inc +) diff --git a/BLINKY/G4HELLO/Core/Inc/main.h b/BLINKY/G4HELLO/Core/Inc/main.h new file mode 100644 index 00000000..ad269546 --- /dev/null +++ b/BLINKY/G4HELLO/Core/Inc/main.h @@ -0,0 +1,95 @@ +/* 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) 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 __MAIN_H +#define __MAIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32g4xx_hal.h" + +#include "stm32g4xx_ll_lpuart.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 RCC_OSC32_IN_Pin LL_GPIO_PIN_14 +#define RCC_OSC32_IN_GPIO_Port GPIOC +#define RCC_OSC32_OUT_Pin LL_GPIO_PIN_15 +#define RCC_OSC32_OUT_GPIO_Port GPIOC +#define RCC_OSC_IN_Pin LL_GPIO_PIN_0 +#define RCC_OSC_IN_GPIO_Port GPIOF +#define RCC_OSC_OUT_Pin LL_GPIO_PIN_1 +#define RCC_OSC_OUT_GPIO_Port GPIOF +#define T_SWDIO_Pin LL_GPIO_PIN_13 +#define T_SWDIO_GPIO_Port GPIOA +#define T_SWCLK_Pin LL_GPIO_PIN_14 +#define T_SWCLK_GPIO_Port GPIOA +#define T_SWO_Pin LL_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/BLINKY/G4HELLO/Core/Inc/stm32g4xx_hal_conf.h b/BLINKY/G4HELLO/Core/Inc/stm32g4xx_hal_conf.h new file mode 100644 index 00000000..25fc721f --- /dev/null +++ b/BLINKY/G4HELLO/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/BLINKY/G4HELLO/Core/Inc/stm32g4xx_it.h b/BLINKY/G4HELLO/Core/Inc/stm32g4xx_it.h new file mode 100644 index 00000000..b3b57684 --- /dev/null +++ b/BLINKY/G4HELLO/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) 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 __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/BLINKY/G4HELLO/Core/Src/main.c b/BLINKY/G4HELLO/Core/Src/main.c new file mode 100644 index 00000000..d8b8bb50 --- /dev/null +++ b/BLINKY/G4HELLO/Core/Src/main.c @@ -0,0 +1,297 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.c + * @brief : Main program body + ****************************************************************************** + * @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 "main.h" + +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ +#include "Logomatic.h" +#include +/* 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); +static void MX_GPIO_Init(void); +static void MX_LPUART1_UART_Init(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) +{ + /* 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 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_LPUART1_UART_Init(); + /* USER CODE BEGIN 2 */ + + /* USER CODE END 2 */ + + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ + while (1) { + /* USER CODE END WHILE */ + + /* USER CODE BEGIN 3 */ + LOGOMATIC("Hello, LOGOMATIC! Great to be here %f\n", 3.14159265); + LL_mDelay(750); + } + /* 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_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(); + } +} + +/** + * @brief LPUART1 Initialization Function + * @param None + * @retval None + */ +static 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 (ST-LINK VCP) + PA3 ------> LPUART1_RX (ST-LINK VCP) + */ + GPIO_InitStruct.Pin = LL_GPIO_PIN_2; + 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_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_LOW; + 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; + 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); + LL_LPUART_SetWakeUpMethod(LPUART1, LL_LPUART_WAKEUP_IDLELINE); + + /* 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 */ +} + +/** + * @brief GPIO Initialization Function + * @param None + * @retval None + */ +static void MX_GPIO_Init(void) +{ + /* USER CODE BEGIN MX_GPIO_Init_1 */ + + /* USER CODE END MX_GPIO_Init_1 */ + + /* 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_GPIOA); + LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB); + + /* USER CODE BEGIN MX_GPIO_Init_2 */ + + /* USER CODE END MX_GPIO_Init_2 */ +} + +/* 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/BLINKY/G4HELLO/Core/Src/stm32g4xx_hal_msp.c b/BLINKY/G4HELLO/Core/Src/stm32g4xx_hal_msp.c new file mode 100644 index 00000000..5fe13811 --- /dev/null +++ b/BLINKY/G4HELLO/Core/Src/stm32g4xx_hal_msp.c @@ -0,0 +1,86 @@ +/* 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) 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 "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/BLINKY/G4HELLO/Core/Src/stm32g4xx_it.c b/BLINKY/G4HELLO/Core/Src/stm32g4xx_it.c new file mode 100644 index 00000000..1434f4bb --- /dev/null +++ b/BLINKY/G4HELLO/Core/Src/stm32g4xx_it.c @@ -0,0 +1,223 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g4xx_it.c + * @brief Interrupt Service Routines. + ****************************************************************************** + * @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 "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 */ + if (LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_13) != RESET) + { + LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_13); + /* USER CODE BEGIN LL_EXTI_LINE_13 */ + + /* USER CODE END LL_EXTI_LINE_13 */ + } + /* 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/BLINKY/G4HELLO/Core/Src/syscalls.c b/BLINKY/G4HELLO/Core/Src/syscalls.c new file mode 100644 index 00000000..e10d76fa --- /dev/null +++ b/BLINKY/G4HELLO/Core/Src/syscalls.c @@ -0,0 +1,244 @@ +/** + ****************************************************************************** + * @file syscalls.c + * @author Auto-generated by STM32CubeMX + * @brief Minimal System calls file + * + * For more information about which c-functions + * need which of these lowlevel functions + * please consult the Newlib or Picolibc libc-manual + ****************************************************************************** + * @attention + * + * Copyright (c) 2020-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. + * + ****************************************************************************** + */ + +/* Includes */ +#include +#include +#include +#include +#include +#include +#include +#include + + +/* Variables */ +extern int __io_putchar(int ch) __attribute__((weak)); +extern int __io_getchar(void) __attribute__((weak)); + + +char *__env[1] = { 0 }; +char **environ = __env; + + +/* Functions */ +void initialise_monitor_handles() +{ +} + +int _getpid(void) +{ + return 1; +} + +int _kill(int pid, int sig) +{ + (void)pid; + (void)sig; + errno = EINVAL; + return -1; +} + +void _exit (int status) +{ + _kill(status, -1); + while (1) {} /* Make sure we hang here */ +} + +__attribute__((weak)) int _read(int file, char *ptr, int len) +{ + (void)file; + int DataIdx; + + for (DataIdx = 0; DataIdx < len; DataIdx++) + { + *ptr++ = __io_getchar(); + } + + return len; +} + +__attribute__((weak)) int _write(int file, char *ptr, int len) +{ + (void)file; + int DataIdx; + + for (DataIdx = 0; DataIdx < len; DataIdx++) + { + __io_putchar(*ptr++); + } + return len; +} + +int _close(int file) +{ + (void)file; + return -1; +} + + +int _fstat(int file, struct stat *st) +{ + (void)file; + st->st_mode = S_IFCHR; + return 0; +} + +int _isatty(int file) +{ + (void)file; + return 1; +} + +int _lseek(int file, int ptr, int dir) +{ + (void)file; + (void)ptr; + (void)dir; + return 0; +} + +int _open(char *path, int flags, ...) +{ + (void)path; + (void)flags; + /* Pretend like we always fail */ + return -1; +} + +int _wait(int *status) +{ + (void)status; + errno = ECHILD; + return -1; +} + +int _unlink(char *name) +{ + (void)name; + errno = ENOENT; + return -1; +} + +clock_t _times(struct tms *buf) +{ + (void)buf; + return -1; +} + +int _stat(const char *file, struct stat *st) +{ + (void)file; + st->st_mode = S_IFCHR; + return 0; +} + +int _link(char *old, char *new) +{ + (void)old; + (void)new; + errno = EMLINK; + return -1; +} + +int _fork(void) +{ + errno = EAGAIN; + return -1; +} + +int _execve(char *name, char **argv, char **env) +{ + (void)name; + (void)argv; + (void)env; + errno = ENOMEM; + return -1; +} + +// --- Picolibc Specific Section --- +#if defined(__PICOLIBC__) + +/** + * @brief Picolibc helper function to output a character to a FILE stream. + * This redirects the output to the low-level __io_putchar function. + * @param c Character to write. + * @param file FILE stream pointer (ignored). + * @retval int The character written. + */ +static int starm_putc(char c, FILE *file) +{ + (void) file; + __io_putchar(c); + return c; +} + +/** + * @brief Picolibc helper function to input a character from a FILE stream. + * This redirects the input from the low-level __io_getchar function. + * @param file FILE stream pointer (ignored). + * @retval int The character read, cast to an unsigned char then int. + */ +static int starm_getc(FILE *file) +{ + unsigned char c; + (void) file; + c = __io_getchar(); + return c; +} + +// Define and initialize the standard I/O streams for Picolibc. +// FDEV_SETUP_STREAM connects the starm_putc and starm_getc helper functions to a FILE structure. +// _FDEV_SETUP_RW indicates the stream is for reading and writing. +static FILE __stdio = FDEV_SETUP_STREAM(starm_putc, + starm_getc, + NULL, + _FDEV_SETUP_RW); + +// Assign the standard stream pointers (stdin, stdout, stderr) to the initialized stream. +// Picolibc uses these pointers for standard I/O operations (printf, scanf, etc.). +FILE *const stdin = &__stdio; +__strong_reference(stdin, stdout); +__strong_reference(stdin, stderr); + +// Create strong aliases mapping standard C library function names (without underscore) +// to the implemented system call stubs (with underscore). Picolibc uses these +// standard names internally, so this linking is required. +__strong_reference(_read, read); +__strong_reference(_write, write); +__strong_reference(_times, times); +__strong_reference(_execve, execve); +__strong_reference(_fork, fork); +__strong_reference(_link, link); +__strong_reference(_unlink, unlink); +__strong_reference(_stat, stat); +__strong_reference(_wait, wait); +__strong_reference(_open, open); +__strong_reference(_close, close); +__strong_reference(_lseek, lseek); +__strong_reference(_isatty, isatty); +__strong_reference(_fstat, fstat); +__strong_reference(_exit, exit); +__strong_reference(_kill, kill); +__strong_reference(_getpid, getpid); + +#endif //__PICOLIBC__ diff --git a/BLINKY/G4HELLO/Core/Src/sysmem.c b/BLINKY/G4HELLO/Core/Src/sysmem.c new file mode 100644 index 00000000..a875d42c --- /dev/null +++ b/BLINKY/G4HELLO/Core/Src/sysmem.c @@ -0,0 +1,87 @@ +/** + ****************************************************************************** + * @file sysmem.c + * @author Generated by STM32CubeMX + * @brief System Memory calls file + * + * For more information about which C functions + * need which of these lowlevel functions + * please consult the Newlib or Picolibc libc manual + ****************************************************************************** + * @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. + * + ****************************************************************************** + */ + +/* Includes */ +#include +#include +#include + +/** + * Pointer to the current high watermark of the heap usage + */ +static uint8_t *__sbrk_heap_end = NULL; + +/** + * @brief _sbrk() allocates memory to the newlib heap and is used by malloc + * and others from the C library + * + * @verbatim + * ############################################################################ + * # .data # .bss # newlib heap # MSP stack # + * # # # # Reserved by _Min_Stack_Size # + * ############################################################################ + * ^-- RAM start ^-- _end _estack, RAM end --^ + * @endverbatim + * + * This implementation starts allocating at the '_end' linker symbol + * The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack + * The implementation considers '_estack' linker symbol to be RAM end + * NOTE: If the MSP stack, at any point during execution, grows larger than the + * reserved size, please increase the '_Min_Stack_Size'. + * + * @param incr Memory size + * @return Pointer to allocated memory + */ +void *_sbrk(ptrdiff_t incr) +{ + extern uint8_t _end; /* Symbol defined in the linker script */ + extern uint8_t _estack; /* Symbol defined in the linker script */ + extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */ + const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size; + const uint8_t *max_heap = (uint8_t *)stack_limit; + uint8_t *prev_heap_end; + + /* Initialize heap end at first call */ + if (NULL == __sbrk_heap_end) + { + __sbrk_heap_end = &_end; + } + + /* Protect heap from growing into the reserved MSP stack */ + if (__sbrk_heap_end + incr > max_heap) + { + errno = ENOMEM; + return (void *)-1; + } + + prev_heap_end = __sbrk_heap_end; + __sbrk_heap_end += incr; + + return (void *)prev_heap_end; +} + +#if defined(__PICOLIBC__) + // Picolibc expects syscalls without the leading underscore. + // This creates a strong alias so that + // calls to `sbrk()` are resolved to our `_sbrk()` implementation. + __strong_reference(_sbrk, sbrk); +#endif diff --git a/BLINKY/G4HELLO/Core/Src/system_stm32g4xx.c b/BLINKY/G4HELLO/Core/Src/system_stm32g4xx.c new file mode 100644 index 00000000..922e57ab --- /dev/null +++ b/BLINKY/G4HELLO/Core/Src/system_stm32g4xx.c @@ -0,0 +1,285 @@ +/** + ****************************************************************************** + * @file system_stm32g4xx.c + * @author MCD Application Team + * @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File + * + * This file provides two functions and one global variable to be called from + * user application: + * - SystemInit(): This function is called at startup just after reset and + * before branch to main program. This call is made inside + * the "startup_stm32g4xx.s" file. + * + * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used + * by the user application to setup the SysTick + * timer or configure other parameters. + * + * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must + * be called whenever the core clock is changed + * during program execution. + * + * After each device reset the HSI (16 MHz) is used as system clock source. + * Then SystemInit() function is called, in "startup_stm32g4xx.s" file, to + * configure the system clock before to branch to main program. + * + * This file configures the system clock as follows: + *============================================================================= + *----------------------------------------------------------------------------- + * System Clock source | HSI + *----------------------------------------------------------------------------- + * SYSCLK(Hz) | 16000000 + *----------------------------------------------------------------------------- + * HCLK(Hz) | 16000000 + *----------------------------------------------------------------------------- + * AHB Prescaler | 1 + *----------------------------------------------------------------------------- + * APB1 Prescaler | 1 + *----------------------------------------------------------------------------- + * APB2 Prescaler | 1 + *----------------------------------------------------------------------------- + * PLL_M | 1 + *----------------------------------------------------------------------------- + * PLL_N | 16 + *----------------------------------------------------------------------------- + * PLL_P | 7 + *----------------------------------------------------------------------------- + * PLL_Q | 2 + *----------------------------------------------------------------------------- + * PLL_R | 2 + *----------------------------------------------------------------------------- + * Require 48MHz for RNG | Disabled + *----------------------------------------------------------------------------- + *============================================================================= + ****************************************************************************** + * @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. + * + ****************************************************************************** + */ + +/** @addtogroup CMSIS + * @{ + */ + +/** @addtogroup stm32g4xx_system + * @{ + */ + +/** @addtogroup STM32G4xx_System_Private_Includes + * @{ + */ + +#include "stm32g4xx.h" + +#if !defined (HSE_VALUE) + #define HSE_VALUE 24000000U /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSI_VALUE) + #define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ + +/** + * @} + */ + +/** @addtogroup STM32G4xx_System_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup STM32G4xx_System_Private_Defines + * @{ + */ + +/************************* Miscellaneous Configuration ************************/ +/* Note: Following vector table addresses must be defined in line with linker + configuration. */ +/*!< Uncomment the following line if you need to relocate the vector table + anywhere in Flash or Sram, else the vector table is kept at the automatic + remap of boot address selected */ +/* #define USER_VECT_TAB_ADDRESS */ + +#if defined(USER_VECT_TAB_ADDRESS) +/*!< Uncomment the following line if you need to relocate your vector Table + in Sram else user remap will be done in Flash. */ +/* #define VECT_TAB_SRAM */ +#if defined(VECT_TAB_SRAM) +#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field. + This value must be a multiple of 0x200. */ +#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. + This value must be a multiple of 0x200. */ +#else +#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field. + This value must be a multiple of 0x200. */ +#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. + This value must be a multiple of 0x200. */ +#endif /* VECT_TAB_SRAM */ +#endif /* USER_VECT_TAB_ADDRESS */ +/******************************************************************************/ +/** + * @} + */ + +/** @addtogroup STM32G4xx_System_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup STM32G4xx_System_Private_Variables + * @{ + */ + /* The SystemCoreClock variable is updated in three ways: + 1) by calling CMSIS function SystemCoreClockUpdate() + 2) by calling HAL API function HAL_RCC_GetHCLKFreq() + 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency + Note: If you use this function to configure the system clock; then there + is no need to call the 2 first functions listed above, since SystemCoreClock + variable is updated automatically. + */ + uint32_t SystemCoreClock = HSI_VALUE; + + const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U}; + const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U}; + +/** + * @} + */ + +/** @addtogroup STM32G4xx_System_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup STM32G4xx_System_Private_Functions + * @{ + */ + +/** + * @brief Setup the microcontroller system. + * @param None + * @retval None + */ + +void SystemInit(void) +{ + /* FPU settings ------------------------------------------------------------*/ + #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) + SCB->CPACR |= ((3UL << (10*2))|(3UL << (11*2))); /* set CP10 and CP11 Full Access */ + #endif + + /* Configure the Vector Table location add offset address ------------------*/ +#if defined(USER_VECT_TAB_ADDRESS) + SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ +#endif /* USER_VECT_TAB_ADDRESS */ +} + +/** + * @brief Update SystemCoreClock variable according to Clock Register Values. + * The SystemCoreClock variable contains the core clock (HCLK), it can + * be used by the user application to setup the SysTick timer or configure + * other parameters. + * + * @note Each time the core clock (HCLK) changes, this function must be called + * to update SystemCoreClock variable value. Otherwise, any configuration + * based on this variable will be incorrect. + * + * @note - The system frequency computed by this function is not the real + * frequency in the chip. It is calculated based on the predefined + * constant and the selected clock source: + * + * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**) + * + * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***) + * + * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***) + * or HSI_VALUE(*) multiplied/divided by the PLL factors. + * + * (**) HSI_VALUE is a constant defined in stm32g4xx_hal.h file (default value + * 16 MHz) but the real value may vary depending on the variations + * in voltage and temperature. + * + * (***) HSE_VALUE is a constant defined in stm32g4xx_hal.h file (default value + * 24 MHz), user has to ensure that HSE_VALUE is same as the real + * frequency of the crystal used. Otherwise, this function may + * have wrong result. + * + * - The result of this function could be not correct when using fractional + * value for HSE crystal. + * + * @param None + * @retval None + */ +void SystemCoreClockUpdate(void) +{ + uint32_t tmp, pllvco, pllr, pllsource, pllm; + + /* Get SYSCLK source -------------------------------------------------------*/ + switch (RCC->CFGR & RCC_CFGR_SWS) + { + case 0x04: /* HSI used as system clock source */ + SystemCoreClock = HSI_VALUE; + break; + + case 0x08: /* HSE used as system clock source */ + SystemCoreClock = HSE_VALUE; + break; + + case 0x0C: /* PLL used as system clock source */ + /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN + SYSCLK = PLL_VCO / PLLR + */ + pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC); + pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4) + 1U ; + if (pllsource == 0x02UL) /* HSI used as PLL clock source */ + { + pllvco = (HSI_VALUE / pllm); + } + else /* HSE used as PLL clock source */ + { + pllvco = (HSE_VALUE / pllm); + } + pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 8); + pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 25) + 1U) * 2U; + SystemCoreClock = pllvco/pllr; + break; + + default: + break; + } + /* Compute HCLK clock frequency --------------------------------------------*/ + /* Get HCLK prescaler */ + tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; + /* HCLK clock frequency */ + SystemCoreClock >>= tmp; +} + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + + diff --git a/BLINKY/G4HELLO/README.md b/BLINKY/G4HELLO/README.md new file mode 100644 index 00000000..b2bbf49d --- /dev/null +++ b/BLINKY/G4HELLO/README.md @@ -0,0 +1,8 @@ +# STM32G474 Hello World + +Nucleo-G474RE-C04 + +Plug in the board following ST-LINK pinout +Compile and flash G4HELLO.elf + +Look at the SWO port for debug text diff --git a/CMakeLists.txt b/CMakeLists.txt index fbb0eab4..79253ce8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,8 @@ message( ${CMAKE_BUILD_TYPE} ) +add_gr_project(STM32G474xE BLINKY G4HELLO) + add_gr_project(STM32G474xE BLINKY G4BLINKY) add_gr_project(STM32U5A9xJ BLINKY U5BLINKY) add_gr_project(STM32L476xG BLINKY L4BLINKY) From 23928b836eaf4026b041934e3757a7328d3c5533 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 30 Oct 2025 04:51:56 -0700 Subject: [PATCH 3/9] Add Logomatic logging functionality and test executables --- Lib/GlobalShare/Inc/Logomatic.h | 19 ++++++++++++++++ Lib/GlobalShare/Test/logomatic_float_print.c | 9 ++++++++ Lib/GlobalShare/Test/logomatic_simple_print.c | 7 ++++++ Lib/GlobalShare/common.cmake | 22 +++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 Lib/GlobalShare/Inc/Logomatic.h create mode 100644 Lib/GlobalShare/Test/logomatic_float_print.c create mode 100644 Lib/GlobalShare/Test/logomatic_simple_print.c diff --git a/Lib/GlobalShare/Inc/Logomatic.h b/Lib/GlobalShare/Inc/Logomatic.h new file mode 100644 index 00000000..25bd3f0e --- /dev/null +++ b/Lib/GlobalShare/Inc/Logomatic.h @@ -0,0 +1,19 @@ +#include + +#ifndef _LOGOMATIC_H_ + #define _LOGOMATIC_H_ + + #ifdef LOGOMATIC_ENABLED + #define LOGOMATIC(...) printf(__VA_ARGS__) + #else + #define LOGOMATIC(...) + #endif + + #if defined(LOGOMATIC_ENABLED) && defined(ITM) + __attribute__((weak)) int __io_putchar(int ch) + { + ITM_SendChar(ch); + return ch; + } + #endif +#endif diff --git a/Lib/GlobalShare/Test/logomatic_float_print.c b/Lib/GlobalShare/Test/logomatic_float_print.c new file mode 100644 index 00000000..acd6d793 --- /dev/null +++ b/Lib/GlobalShare/Test/logomatic_float_print.c @@ -0,0 +1,9 @@ +#include + +#include "Logomatic.h" + +int main(void) +{ + LOGOMATIC("I like %f\n", M_PI); + return 0; +} diff --git a/Lib/GlobalShare/Test/logomatic_simple_print.c b/Lib/GlobalShare/Test/logomatic_simple_print.c new file mode 100644 index 00000000..4dcfba60 --- /dev/null +++ b/Lib/GlobalShare/Test/logomatic_simple_print.c @@ -0,0 +1,7 @@ +#include "Logomatic.h" + +int main(void) +{ + LOGOMATIC("Hello, Logomatic!\n"); + return 0; +} diff --git a/Lib/GlobalShare/common.cmake b/Lib/GlobalShare/common.cmake index e7837e87..87153d0e 100644 --- a/Lib/GlobalShare/common.cmake +++ b/Lib/GlobalShare/common.cmake @@ -5,3 +5,25 @@ target_include_directories( INTERFACE $ ) + +if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + target_compile_definitions(GLOBALSHARE_LIB INTERFACE LOGOMATIC_ENABLED) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -u _printf_float") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -u _printf_float") +endif() + +if(CMAKE_BUILD_TYPE STREQUAL "Test") + target_compile_definitions(GLOBALSHARE_LIB INTERFACE LOGOMATIC_ENABLED) + + add_executable(logomatic_simple + ${CMAKE_CURRENT_LIST_DIR}/Test/logomatic_simple_print.c + ) + target_link_libraries(logomatic_simple PRIVATE GLOBALSHARE_LIB) + add_test(logomatic_simple_test logomatic_simple) + + add_executable(logomatic_float + ${CMAKE_CURRENT_LIST_DIR}/Test/logomatic_float_print.c + ) + target_link_libraries(logomatic_float PRIVATE GLOBALSHARE_LIB) + add_test(logomatic_float_test logomatic_float) +endif() From deb36112197c3e3c34a1c1234f85ece09d9dafc1 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 30 Oct 2025 04:52:03 -0700 Subject: [PATCH 4/9] Update launch configurations for STM32 projects and adjust SWO settings --- .vscode/launch.json | 108 +++++++++++++------------------------------- 1 file changed, 32 insertions(+), 76 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 45112ef9..31b8d98d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -34,8 +34,8 @@ }, { "cwd": "${workspaceFolder}", - "executable": "${command:cmake.buildDirectory}/W3_G4SPI_Receive.elf", - "name": "SPI Receive W3 WS", + "executable": "${command:cmake.buildDirectory}/G4HELLO.elf", + "name": "G4HELLO", "request": "launch", "type": "cortex-debug", "servertype": "openocd", @@ -49,8 +49,8 @@ "svdPath": "${workspaceFolder}/Lib/Platform/STM32G474xE/CompileDependencies/STM32G474.svd", "swoConfig": { "enabled": true, - "cpuFrequency": 160000000, - "swoFrequency": 115200, + "cpuFrequency": 170000000, + "swoFrequency": 2000000, "source": "probe", "decoders": [ { @@ -65,8 +65,8 @@ }, { "cwd": "${workspaceFolder}", - "executable": "${command:cmake.buildDirectory}/W3_G4SPI_Transmit.elf", - "name": "SPI Transmit W3 WS", + "executable": "${command:cmake.buildDirectory}/G4BLINKY.elf", + "name": "G4BLINKY", "request": "launch", "type": "cortex-debug", "servertype": "openocd", @@ -78,26 +78,11 @@ "preLaunchTask": "CMake: configure and build", "showDevDebugOutput": "raw", "svdPath": "${workspaceFolder}/Lib/Platform/STM32G474xE/CompileDependencies/STM32G474.svd", - "swoConfig": { - "enabled": true, - "cpuFrequency": 160000000, - "swoFrequency": 115200, - "source": "probe", - "decoders": [ - { - "type": "console", - "label": "ITM", - "showOnStartup": true, - "port": 0, - "encoding": "ascii" - } - ] - } }, { "cwd": "${workspaceFolder}", - "executable": "${command:cmake.buildDirectory}/G4BLINKY.elf", - "name": "G4BLINKY", + "executable": "${command:cmake.buildDirectory}/U5BLINKY.elf", + "name": "U5BLINKY", "request": "launch", "type": "cortex-debug", "servertype": "openocd", @@ -108,27 +93,28 @@ "searchDir": [], "preLaunchTask": "CMake: configure and build", "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Platform/STM32G474xE/CompileDependencies/STM32G474.svd", - "swoConfig": { - "enabled": true, - "cpuFrequency": 160000000, - "swoFrequency": 115200, - "source": "probe", - "decoders": [ - { - "type": "console", - "label": "ITM", - "showOnStartup": true, - "port": 0, - "encoding": "ascii" - } - ] - } + "svdPath": "${workspaceFolder}/Lib/Platform/STM32U5A9xJ/CompileDependencies/STM32U5A9.svd", }, { "cwd": "${workspaceFolder}", - "executable": "${command:cmake.buildDirectory}/U5BLINKY.elf", - "name": "U5BLINKY", + "executable": "${command:cmake.buildDirectory}/L4BLINKY.elf", + "name": "L4BLINKY", + "request": "launch", + "type": "cortex-debug", + "servertype": "openocd", + "configFiles": [ + "interface/stlink.cfg", + "target/stm32l4x.cfg" + ], + "searchDir": [], + "preLaunchTask": "CMake: configure and build", + "showDevDebugOutput": "raw", + "svdPath": "${workspaceFolder}/Lib/Platform/STM32L476xG/CompileDependencies/STM32L476.svd", + }, + { + "cwd": "${workspaceFolder}", + "executable": "${command:cmake.buildDirectory}/W3_G4SPI_Receive.elf", + "name": "SPI Receive W3 WS", "request": "launch", "type": "cortex-debug", "servertype": "openocd", @@ -139,53 +125,23 @@ "searchDir": [], "preLaunchTask": "CMake: configure and build", "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Platform/STM32U5A9xJ/CompileDependencies/STM32U5A9.svd", - "swoConfig": { - "enabled": true, - "cpuFrequency": 160000000, - "swoFrequency": 115200, - "source": "probe", - "decoders": [ - { - "type": "console", - "label": "ITM", - "showOnStartup": true, - "port": 0, - "encoding": "ascii" - } - ] - } + "svdPath": "${workspaceFolder}/Lib/Platform/STM32G474xE/CompileDependencies/STM32G474.svd", }, { "cwd": "${workspaceFolder}", - "executable": "${command:cmake.buildDirectory}/L4BLINKY.elf", - "name": "L4BLINKY", + "executable": "${command:cmake.buildDirectory}/W3_G4SPI_Transmit.elf", + "name": "SPI Transmit W3 WS", "request": "launch", "type": "cortex-debug", "servertype": "openocd", "configFiles": [ "interface/stlink.cfg", - "target/stm32l4x.cfg" + "target/stm32g4x.cfg" ], "searchDir": [], "preLaunchTask": "CMake: configure and build", "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Platform/STM32L476xG/CompileDependencies/STM32L476.svd", - "swoConfig": { - "enabled": true, - "cpuFrequency": 160000000, - "swoFrequency": 115200, - "source": "probe", - "decoders": [ - { - "type": "console", - "label": "ITM", - "showOnStartup": true, - "port": 0, - "encoding": "ascii" - } - ] - } + "svdPath": "${workspaceFolder}/Lib/Platform/STM32G474xE/CompileDependencies/STM32G474.svd", } ] } From 89a80f0af2367689a8cefecfe200449148ccd304 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 30 Oct 2025 04:52:07 -0700 Subject: [PATCH 5/9] Add Logomatic logging library for embedded systems --- Lib/GlobalShare/Logomatic.md | 134 +++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 Lib/GlobalShare/Logomatic.md diff --git a/Lib/GlobalShare/Logomatic.md b/Lib/GlobalShare/Logomatic.md new file mode 100644 index 00000000..536d1687 --- /dev/null +++ b/Lib/GlobalShare/Logomatic.md @@ -0,0 +1,134 @@ +# Logomatic + +A lightweight, header-only logging library for embedded systems that provides `printf`-style logging with automatic output routing based on the build target. + +## Overview + +Logomatic enables unified logging across Hardware-on-the-Loop (HOOTL) testing and embedded targets using a single API. The library automatically routes log output to the appropriate backend: + +- **HOOTL builds**: Standard output (stdout) for test integration +- **Embedded targets**: ITM (Instrumentation Trace Macrocell) for SWO (Serial Wire Output) debugging + +## Features + +- **Header-only**: Just `#include "Logomatic.h"` - no linking required +- **Printf-compatible API**: Drop-in replacement for `printf` with identical syntax +- **Automatic target detection**: Uses ITM when available, standard library otherwise +- **Compile-time configuration**: Zero overhead when disabled +- **CMSIS-compliant**: Uses standard ARM CMSIS ITM interface +- **Weak symbol implementation**: Can be overridden for custom backends + +## Usage + +### Basic Example + +```c +#include "Logomatic.h" + +void example_function(int count, float value) { + LOGOMATIC("Sensor reading: count=%d, value=%.2f\n", count, value); +} +``` + +The `LOGOMATIC()` macro expands to `printf()` when `LOGOMATIC_ENABLED` is defined, or to nothing when disabled - providing zero runtime overhead in release builds. + +## Build Targets + +### HOOTL Testing + +In HOOTL (simulation/test) builds, logs are written to standard output: + +```c +LOGOMATIC("Hello, World! I hope I %s!\n", "PASS"); +// Output: Hello, World! I hope I PASS! +``` + +This allows integration with test frameworks and CI/CD pipelines that capture stdout. + +### Embedded Hardware + +On ARM Cortex-M targets with ITM support, logs are transmitted via the ITM peripheral using the Serial Wire Output (SWO) protocol: + +```c +LOGOMATIC("ADC value: %d\n", adc_reading); +// Transmitted over SWO to debugger console +``` + +**Requirements:** + +- ITM must be initialized in firmware (enable TRCENA, ITM ports, etc.) +- SWO pin connected to debug probe +- Debug probe configured to capture SWO data (see Configuration below) + +**Automatic Detection:** + +The library checks for `ITM` definition at compile-time. If ITM is available (defined by CMSIS headers), the custom `__io_putchar` implementation routes output to SWO. Otherwise, standard library printf is used. + +## Configuration + +### Build Configuration + +Logomatic is automatically enabled in Debug and RelWithDebInfo builds via `GlobalShare/common.cmake`: + +```cmake +if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + target_compile_definitions(GLOBALSHARE_LIB INTERFACE LOGOMATIC_ENABLED) +endif() +``` + +### Firmware Initialization + +Initialize ITM in your firmware before using `LOGOMATIC()`: + +```c +void ITM_Enable(void) +{ + CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; + ITM->TER |= (1UL << 0); // Enable stimulus port 0 + ITM->TCR |= ITM_TCR_ITMENA_Msk; +} + +int main(void) +{ + ITM_Enable(); + LOGOMATIC("System initialized\n"); + // ... +} +``` + +### SWO Setup for STM32 + +Configure your debugger to capture SWO data on ITM Port 0: + +**VS Code cortex-debug with OpenOCD:** + +```json +{ + "swoConfig": { + "enabled": true, + "cpuFrequency": 170000000, // Match your system clock + "swoFrequency": 2000000, + "source": "probe", + "decoders": [ + { "port": 0, "type": "console", "label": "SWO:ITM" } + ] + } +} +``` + +## Implementation Details + +### Output Mechanism + +The library provides a weak `__io_putchar()` implementation that's called by the standard library's `printf()`. + +- **HOOTL builds**: `ITM` is not defined, so standard library `__io_putchar` is used and the output is sent to stdout +- **Embedded builds**: Custom weak implementation routes characters to ITM and the output is sent over SWO +- **Weak linkage**: Can be overridden in user code for custom output backends + +### Performance Characteristics + +- **Overhead**: Zero when disabled (macro compiles to nothing) +- **Timing impact**: ~1-5 µs per character at 2 MHz SWO frequency +- **Buffer behavior**: ITM hardware FIFO handles buffering transparently +- **Interrupt safety**: Uses CMSIS `ITM_SendChar()` which handles port readiness From a291b7d8f12b5cac9230be955c7bf526c7e3d880 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 30 Oct 2025 11:54:35 +0000 Subject: [PATCH 6/9] Automatic CMake Format: Standardized formatting automatically --- BLINKY/G4HELLO/CMakeLists.txt | 6 +----- Lib/GlobalShare/common.cmake | 34 ++++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/BLINKY/G4HELLO/CMakeLists.txt b/BLINKY/G4HELLO/CMakeLists.txt index 8febf9b6..5854c81f 100644 --- a/BLINKY/G4HELLO/CMakeLists.txt +++ b/BLINKY/G4HELLO/CMakeLists.txt @@ -43,8 +43,4 @@ target_sources( target_link_libraries(${GR_PROJECT_NAME}_USER_CODE INTERFACE) -target_include_directories( - ${GR_PROJECT_NAME}_USER_CODE - INTERFACE - Core/Inc -) +target_include_directories(${GR_PROJECT_NAME}_USER_CODE INTERFACE Core/Inc) diff --git a/Lib/GlobalShare/common.cmake b/Lib/GlobalShare/common.cmake index 87153d0e..307d01a6 100644 --- a/Lib/GlobalShare/common.cmake +++ b/Lib/GlobalShare/common.cmake @@ -6,24 +6,34 @@ target_include_directories( $ ) -if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") +if( + CMAKE_BUILD_TYPE + STREQUAL + "Debug" + OR + CMAKE_BUILD_TYPE + STREQUAL + "RelWithDebInfo" +) target_compile_definitions(GLOBALSHARE_LIB INTERFACE LOGOMATIC_ENABLED) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -u _printf_float") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -u _printf_float") endif() if(CMAKE_BUILD_TYPE STREQUAL "Test") - target_compile_definitions(GLOBALSHARE_LIB INTERFACE LOGOMATIC_ENABLED) + target_compile_definitions(GLOBALSHARE_LIB INTERFACE LOGOMATIC_ENABLED) - add_executable(logomatic_simple - ${CMAKE_CURRENT_LIST_DIR}/Test/logomatic_simple_print.c - ) - target_link_libraries(logomatic_simple PRIVATE GLOBALSHARE_LIB) - add_test(logomatic_simple_test logomatic_simple) + add_executable( + logomatic_simple + ${CMAKE_CURRENT_LIST_DIR}/Test/logomatic_simple_print.c + ) + target_link_libraries(logomatic_simple PRIVATE GLOBALSHARE_LIB) + add_test(logomatic_simple_test logomatic_simple) - add_executable(logomatic_float - ${CMAKE_CURRENT_LIST_DIR}/Test/logomatic_float_print.c - ) - target_link_libraries(logomatic_float PRIVATE GLOBALSHARE_LIB) - add_test(logomatic_float_test logomatic_float) + add_executable( + logomatic_float + ${CMAKE_CURRENT_LIST_DIR}/Test/logomatic_float_print.c + ) + target_link_libraries(logomatic_float PRIVATE GLOBALSHARE_LIB) + add_test(logomatic_float_test logomatic_float) endif() From 1b469d40138904c42faad7201f1b3bec66429745 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 30 Oct 2025 11:56:01 +0000 Subject: [PATCH 7/9] Automatic Clang-Format: Standardized formatting automatically --- BLINKY/G4HELLO/Core/Inc/main.h | 46 +- BLINKY/G4HELLO/Core/Inc/stm32g4xx_hal_conf.h | 266 ++++++----- BLINKY/G4HELLO/Core/Inc/stm32g4xx_it.h | 30 +- BLINKY/G4HELLO/Core/Src/main.c | 5 +- BLINKY/G4HELLO/Core/Src/stm32g4xx_hal_msp.c | 56 +-- BLINKY/G4HELLO/Core/Src/stm32g4xx_it.c | 200 ++++---- BLINKY/G4HELLO/Core/Src/syscalls.c | 170 ++++--- BLINKY/G4HELLO/Core/Src/sysmem.c | 50 +- BLINKY/G4HELLO/Core/Src/system_stm32g4xx.c | 448 +++++++++--------- Lib/GlobalShare/Inc/Logomatic.h | 26 +- Lib/GlobalShare/Test/logomatic_float_print.c | 4 +- Lib/GlobalShare/Test/logomatic_simple_print.c | 4 +- 12 files changed, 658 insertions(+), 647 deletions(-) diff --git a/BLINKY/G4HELLO/Core/Inc/main.h b/BLINKY/G4HELLO/Core/Inc/main.h index ad269546..708a733b 100644 --- a/BLINKY/G4HELLO/Core/Inc/main.h +++ b/BLINKY/G4HELLO/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) 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file : main.h + * @brief : Header for main.c file. + * This file contains the common defines of the application. + ****************************************************************************** + * @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 -------------------------------------*/ @@ -29,17 +29,17 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" -#include "stm32g4xx_ll_lpuart.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_lpuart.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/BLINKY/G4HELLO/Core/Inc/stm32g4xx_hal_conf.h b/BLINKY/G4HELLO/Core/Inc/stm32g4xx_hal_conf.h index 25fc721f..6d840da0 100644 --- a/BLINKY/G4HELLO/Core/Inc/stm32g4xx_hal_conf.h +++ b/BLINKY/G4HELLO/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 */ @@ -74,124 +74,137 @@ #define HAL_PWR_MODULE_ENABLED #define HAL_CORTEX_MODULE_ENABLED -/* ########################## Register Callbacks selection ############################## */ +/* ########################## 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 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 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 (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 */ +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 */ + * @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 (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 +#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 - */ + * @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 +214,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,16 +370,17 @@ 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 - */ -#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) + * @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 diff --git a/BLINKY/G4HELLO/Core/Inc/stm32g4xx_it.h b/BLINKY/G4HELLO/Core/Inc/stm32g4xx_it.h index b3b57684..5d9237b5 100644 --- a/BLINKY/G4HELLO/Core/Inc/stm32g4xx_it.h +++ b/BLINKY/G4HELLO/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) 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file stm32g4xx_it.h + * @brief This file contains the headers of the interrupt handlers. + ****************************************************************************** + * @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 -------------------------------------*/ diff --git a/BLINKY/G4HELLO/Core/Src/main.c b/BLINKY/G4HELLO/Core/Src/main.c index d8b8bb50..37a85420 100644 --- a/BLINKY/G4HELLO/Core/Src/main.c +++ b/BLINKY/G4HELLO/Core/Src/main.c @@ -90,7 +90,7 @@ int main(void) * Systick. */ HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ ITM_Enable(); /* USER CODE END Init */ @@ -114,7 +114,8 @@ int main(void) /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ - LOGOMATIC("Hello, LOGOMATIC! Great to be here %f\n", 3.14159265); + LOGOMATIC("Hello, LOGOMATIC! Great to be here %f\n", + 3.14159265); LL_mDelay(750); } /* USER CODE END 3 */ diff --git a/BLINKY/G4HELLO/Core/Src/stm32g4xx_hal_msp.c b/BLINKY/G4HELLO/Core/Src/stm32g4xx_hal_msp.c index 5fe13811..f266230d 100644 --- a/BLINKY/G4HELLO/Core/Src/stm32g4xx_hal_msp.c +++ b/BLINKY/G4HELLO/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) 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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file stm32g4xx_hal_msp.c + * @brief This file provides code for the MSP Initialization + * and de-Initialization codes. + ****************************************************************************** + * @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 ------------------------------------------------------------------*/ @@ -58,27 +58,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/BLINKY/G4HELLO/Core/Src/stm32g4xx_it.c b/BLINKY/G4HELLO/Core/Src/stm32g4xx_it.c index 1434f4bb..766e1c51 100644 --- a/BLINKY/G4HELLO/Core/Src/stm32g4xx_it.c +++ b/BLINKY/G4HELLO/Core/Src/stm32g4xx_it.c @@ -1,25 +1,25 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file stm32g4xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @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. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file stm32g4xx_it.c + * @brief Interrupt Service Routines. + ****************************************************************************** + * @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 "main.h" #include "stm32g4xx_it.h" +#include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -64,131 +64,126 @@ /* 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,23 +194,22 @@ void SysTick_Handler(void) /******************************************************************************/ /** - * @brief This function handles EXTI line[15:10] interrupts. - */ + * @brief This function handles EXTI line[15:10] interrupts. + */ void EXTI15_10_IRQHandler(void) { - /* USER CODE BEGIN EXTI15_10_IRQn 0 */ + /* USER CODE BEGIN EXTI15_10_IRQn 0 */ - /* USER CODE END EXTI15_10_IRQn 0 */ - if (LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_13) != RESET) - { - LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_13); - /* USER CODE BEGIN LL_EXTI_LINE_13 */ + /* USER CODE END EXTI15_10_IRQn 0 */ + if (LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_13) != RESET) { + LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_13); + /* USER CODE BEGIN LL_EXTI_LINE_13 */ - /* USER CODE END LL_EXTI_LINE_13 */ - } - /* USER CODE BEGIN EXTI15_10_IRQn 1 */ + /* USER CODE END LL_EXTI_LINE_13 */ + } + /* USER CODE BEGIN EXTI15_10_IRQn 1 */ - /* USER CODE END EXTI15_10_IRQn 1 */ + /* USER CODE END EXTI15_10_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/BLINKY/G4HELLO/Core/Src/syscalls.c b/BLINKY/G4HELLO/Core/Src/syscalls.c index e10d76fa..2cd27c7d 100644 --- a/BLINKY/G4HELLO/Core/Src/syscalls.c +++ b/BLINKY/G4HELLO/Core/Src/syscalls.c @@ -21,158 +21,148 @@ */ /* Includes */ -#include -#include #include -#include #include -#include +#include +#include +#include #include #include - +#include /* Variables */ extern int __io_putchar(int ch) __attribute__((weak)); extern int __io_getchar(void) __attribute__((weak)); - -char *__env[1] = { 0 }; +char *__env[1] = {0}; char **environ = __env; - /* Functions */ -void initialise_monitor_handles() -{ -} +void initialise_monitor_handles() {} -int _getpid(void) -{ - return 1; -} +int _getpid(void) { return 1; } int _kill(int pid, int sig) { - (void)pid; - (void)sig; - errno = EINVAL; - return -1; + (void)pid; + (void)sig; + errno = EINVAL; + return -1; } -void _exit (int status) +void _exit(int status) { - _kill(status, -1); - while (1) {} /* Make sure we hang here */ + _kill(status, -1); + while (1) { + } /* Make sure we hang here */ } __attribute__((weak)) int _read(int file, char *ptr, int len) { - (void)file; - int DataIdx; + (void)file; + int DataIdx; - for (DataIdx = 0; DataIdx < len; DataIdx++) - { - *ptr++ = __io_getchar(); - } + for (DataIdx = 0; DataIdx < len; DataIdx++) { + *ptr++ = __io_getchar(); + } - return len; + return len; } __attribute__((weak)) int _write(int file, char *ptr, int len) { - (void)file; - int DataIdx; + (void)file; + int DataIdx; - for (DataIdx = 0; DataIdx < len; DataIdx++) - { - __io_putchar(*ptr++); - } - return len; + for (DataIdx = 0; DataIdx < len; DataIdx++) { + __io_putchar(*ptr++); + } + return len; } int _close(int file) { - (void)file; - return -1; + (void)file; + return -1; } - int _fstat(int file, struct stat *st) { - (void)file; - st->st_mode = S_IFCHR; - return 0; + (void)file; + st->st_mode = S_IFCHR; + return 0; } int _isatty(int file) { - (void)file; - return 1; + (void)file; + return 1; } int _lseek(int file, int ptr, int dir) { - (void)file; - (void)ptr; - (void)dir; - return 0; + (void)file; + (void)ptr; + (void)dir; + return 0; } int _open(char *path, int flags, ...) { - (void)path; - (void)flags; - /* Pretend like we always fail */ - return -1; + (void)path; + (void)flags; + /* Pretend like we always fail */ + return -1; } int _wait(int *status) { - (void)status; - errno = ECHILD; - return -1; + (void)status; + errno = ECHILD; + return -1; } int _unlink(char *name) { - (void)name; - errno = ENOENT; - return -1; + (void)name; + errno = ENOENT; + return -1; } clock_t _times(struct tms *buf) { - (void)buf; - return -1; + (void)buf; + return -1; } int _stat(const char *file, struct stat *st) { - (void)file; - st->st_mode = S_IFCHR; - return 0; + (void)file; + st->st_mode = S_IFCHR; + return 0; } int _link(char *old, char *new) { - (void)old; - (void)new; - errno = EMLINK; - return -1; + (void)old; + (void)new; + errno = EMLINK; + return -1; } int _fork(void) { - errno = EAGAIN; - return -1; + errno = EAGAIN; + return -1; } int _execve(char *name, char **argv, char **env) { - (void)name; - (void)argv; - (void)env; - errno = ENOMEM; - return -1; + (void)name; + (void)argv; + (void)env; + errno = ENOMEM; + return -1; } // --- Picolibc Specific Section --- @@ -187,8 +177,8 @@ int _execve(char *name, char **argv, char **env) */ static int starm_putc(char c, FILE *file) { - (void) file; - __io_putchar(c); + (void)file; + __io_putchar(c); return c; } @@ -201,28 +191,28 @@ static int starm_putc(char c, FILE *file) static int starm_getc(FILE *file) { unsigned char c; - (void) file; - c = __io_getchar(); + (void)file; + c = __io_getchar(); return c; } // Define and initialize the standard I/O streams for Picolibc. -// FDEV_SETUP_STREAM connects the starm_putc and starm_getc helper functions to a FILE structure. -// _FDEV_SETUP_RW indicates the stream is for reading and writing. -static FILE __stdio = FDEV_SETUP_STREAM(starm_putc, - starm_getc, - NULL, - _FDEV_SETUP_RW); - -// Assign the standard stream pointers (stdin, stdout, stderr) to the initialized stream. -// Picolibc uses these pointers for standard I/O operations (printf, scanf, etc.). +// FDEV_SETUP_STREAM connects the starm_putc and starm_getc helper functions to +// a FILE structure. _FDEV_SETUP_RW indicates the stream is for reading and +// writing. +static FILE __stdio = + FDEV_SETUP_STREAM(starm_putc, starm_getc, NULL, _FDEV_SETUP_RW); + +// Assign the standard stream pointers (stdin, stdout, stderr) to the +// initialized stream. Picolibc uses these pointers for standard I/O operations +// (printf, scanf, etc.). FILE *const stdin = &__stdio; __strong_reference(stdin, stdout); __strong_reference(stdin, stderr); -// Create strong aliases mapping standard C library function names (without underscore) -// to the implemented system call stubs (with underscore). Picolibc uses these -// standard names internally, so this linking is required. +// Create strong aliases mapping standard C library function names (without +// underscore) to the implemented system call stubs (with underscore). Picolibc +// uses these standard names internally, so this linking is required. __strong_reference(_read, read); __strong_reference(_write, write); __strong_reference(_times, times); diff --git a/BLINKY/G4HELLO/Core/Src/sysmem.c b/BLINKY/G4HELLO/Core/Src/sysmem.c index a875d42c..f0a3aca7 100644 --- a/BLINKY/G4HELLO/Core/Src/sysmem.c +++ b/BLINKY/G4HELLO/Core/Src/sysmem.c @@ -22,8 +22,8 @@ /* Includes */ #include -#include #include +#include /** * Pointer to the current high watermark of the heap usage @@ -53,35 +53,35 @@ static uint8_t *__sbrk_heap_end = NULL; */ void *_sbrk(ptrdiff_t incr) { - extern uint8_t _end; /* Symbol defined in the linker script */ - extern uint8_t _estack; /* Symbol defined in the linker script */ - extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */ - const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size; - const uint8_t *max_heap = (uint8_t *)stack_limit; - uint8_t *prev_heap_end; + extern uint8_t _end; /* Symbol defined in the linker script */ + extern uint8_t _estack; /* Symbol defined in the linker script */ + extern uint32_t + _Min_Stack_Size; /* Symbol defined in the linker script */ + const uint32_t stack_limit = + (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size; + const uint8_t *max_heap = (uint8_t *)stack_limit; + uint8_t *prev_heap_end; - /* Initialize heap end at first call */ - if (NULL == __sbrk_heap_end) - { - __sbrk_heap_end = &_end; - } + /* Initialize heap end at first call */ + if (NULL == __sbrk_heap_end) { + __sbrk_heap_end = &_end; + } - /* Protect heap from growing into the reserved MSP stack */ - if (__sbrk_heap_end + incr > max_heap) - { - errno = ENOMEM; - return (void *)-1; - } + /* Protect heap from growing into the reserved MSP stack */ + if (__sbrk_heap_end + incr > max_heap) { + errno = ENOMEM; + return (void *)-1; + } - prev_heap_end = __sbrk_heap_end; - __sbrk_heap_end += incr; + prev_heap_end = __sbrk_heap_end; + __sbrk_heap_end += incr; - return (void *)prev_heap_end; + return (void *)prev_heap_end; } #if defined(__PICOLIBC__) - // Picolibc expects syscalls without the leading underscore. - // This creates a strong alias so that - // calls to `sbrk()` are resolved to our `_sbrk()` implementation. - __strong_reference(_sbrk, sbrk); +// Picolibc expects syscalls without the leading underscore. +// This creates a strong alias so that +// calls to `sbrk()` are resolved to our `_sbrk()` implementation. +__strong_reference(_sbrk, sbrk); #endif diff --git a/BLINKY/G4HELLO/Core/Src/system_stm32g4xx.c b/BLINKY/G4HELLO/Core/Src/system_stm32g4xx.c index 922e57ab..6254a05b 100644 --- a/BLINKY/G4HELLO/Core/Src/system_stm32g4xx.c +++ b/BLINKY/G4HELLO/Core/Src/system_stm32g4xx.c @@ -1,109 +1,109 @@ /** - ****************************************************************************** - * @file system_stm32g4xx.c - * @author MCD Application Team - * @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File - * - * This file provides two functions and one global variable to be called from - * user application: - * - SystemInit(): This function is called at startup just after reset and - * before branch to main program. This call is made inside - * the "startup_stm32g4xx.s" file. - * - * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used - * by the user application to setup the SysTick - * timer or configure other parameters. - * - * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must - * be called whenever the core clock is changed - * during program execution. - * - * After each device reset the HSI (16 MHz) is used as system clock source. - * Then SystemInit() function is called, in "startup_stm32g4xx.s" file, to - * configure the system clock before to branch to main program. - * - * This file configures the system clock as follows: - *============================================================================= - *----------------------------------------------------------------------------- - * System Clock source | HSI - *----------------------------------------------------------------------------- - * SYSCLK(Hz) | 16000000 - *----------------------------------------------------------------------------- - * HCLK(Hz) | 16000000 - *----------------------------------------------------------------------------- - * AHB Prescaler | 1 - *----------------------------------------------------------------------------- - * APB1 Prescaler | 1 - *----------------------------------------------------------------------------- - * APB2 Prescaler | 1 - *----------------------------------------------------------------------------- - * PLL_M | 1 - *----------------------------------------------------------------------------- - * PLL_N | 16 - *----------------------------------------------------------------------------- - * PLL_P | 7 - *----------------------------------------------------------------------------- - * PLL_Q | 2 - *----------------------------------------------------------------------------- - * PLL_R | 2 - *----------------------------------------------------------------------------- - * Require 48MHz for RNG | Disabled - *----------------------------------------------------------------------------- - *============================================================================= - ****************************************************************************** - * @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 system_stm32g4xx.c + * @author MCD Application Team + * @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File + * + * This file provides two functions and one global variable to be called from + * user application: + * - SystemInit(): This function is called at startup just after reset and + * before branch to main program. This call is made inside + * the "startup_stm32g4xx.s" file. + * + * - SystemCoreClock variable: Contains the core clock (HCLK), it can be + *used by the user application to setup the SysTick timer or configure other + *parameters. + * + * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must + * be called whenever the core clock is changed + * during program execution. + * + * After each device reset the HSI (16 MHz) is used as system clock source. + * Then SystemInit() function is called, in "startup_stm32g4xx.s" file, to + * configure the system clock before to branch to main program. + * + * This file configures the system clock as follows: + *============================================================================= + *----------------------------------------------------------------------------- + * System Clock source | HSI + *----------------------------------------------------------------------------- + * SYSCLK(Hz) | 16000000 + *----------------------------------------------------------------------------- + * HCLK(Hz) | 16000000 + *----------------------------------------------------------------------------- + * AHB Prescaler | 1 + *----------------------------------------------------------------------------- + * APB1 Prescaler | 1 + *----------------------------------------------------------------------------- + * APB2 Prescaler | 1 + *----------------------------------------------------------------------------- + * PLL_M | 1 + *----------------------------------------------------------------------------- + * PLL_N | 16 + *----------------------------------------------------------------------------- + * PLL_P | 7 + *----------------------------------------------------------------------------- + * PLL_Q | 2 + *----------------------------------------------------------------------------- + * PLL_R | 2 + *----------------------------------------------------------------------------- + * Require 48MHz for RNG | Disabled + *----------------------------------------------------------------------------- + *============================================================================= + ****************************************************************************** + * @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. + * + ****************************************************************************** + */ /** @addtogroup CMSIS - * @{ - */ + * @{ + */ /** @addtogroup stm32g4xx_system - * @{ - */ + * @{ + */ /** @addtogroup STM32G4xx_System_Private_Includes - * @{ - */ + * @{ + */ #include "stm32g4xx.h" -#if !defined (HSE_VALUE) - #define HSE_VALUE 24000000U /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ +#if !defined(HSE_VALUE) +#define HSE_VALUE 24000000U /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ -#if !defined (HSI_VALUE) - #define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ +#if !defined(HSI_VALUE) +#define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ /** - * @} - */ + * @} + */ /** @addtogroup STM32G4xx_System_Private_TypesDefinitions - * @{ - */ + * @{ + */ /** - * @} - */ + * @} + */ /** @addtogroup STM32G4xx_System_Private_Defines - * @{ - */ + * @{ + */ /************************* Miscellaneous Configuration ************************/ /* Note: Following vector table addresses must be defined in line with linker - configuration. */ + configuration. */ /*!< Uncomment the following line if you need to relocate the vector table anywhere in Flash or Sram, else the vector table is kept at the automatic remap of boot address selected */ @@ -114,172 +114,184 @@ in Sram else user remap will be done in Flash. */ /* #define VECT_TAB_SRAM */ #if defined(VECT_TAB_SRAM) -#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field. - This value must be a multiple of 0x200. */ -#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. - This value must be a multiple of 0x200. */ +#define VECT_TAB_BASE_ADDRESS \ + SRAM_BASE /*!< Vector Table base address field. \ + This value must be a multiple of 0x200. */ +#define VECT_TAB_OFFSET \ + 0x00000000U /*!< Vector Table base offset field. \ + This value must be a multiple of 0x200. */ #else -#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field. - This value must be a multiple of 0x200. */ -#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. - This value must be a multiple of 0x200. */ -#endif /* VECT_TAB_SRAM */ -#endif /* USER_VECT_TAB_ADDRESS */ +#define VECT_TAB_BASE_ADDRESS \ + FLASH_BASE /*!< Vector Table base address field. \ + This value must be a multiple of 0x200. */ +#define VECT_TAB_OFFSET \ + 0x00000000U /*!< Vector Table base offset field. \ + This value must be a multiple of 0x200. */ +#endif /* VECT_TAB_SRAM */ +#endif /* USER_VECT_TAB_ADDRESS */ /******************************************************************************/ /** - * @} - */ + * @} + */ /** @addtogroup STM32G4xx_System_Private_Macros - * @{ - */ + * @{ + */ /** - * @} - */ + * @} + */ /** @addtogroup STM32G4xx_System_Private_Variables - * @{ - */ - /* The SystemCoreClock variable is updated in three ways: - 1) by calling CMSIS function SystemCoreClockUpdate() - 2) by calling HAL API function HAL_RCC_GetHCLKFreq() - 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency - Note: If you use this function to configure the system clock; then there - is no need to call the 2 first functions listed above, since SystemCoreClock - variable is updated automatically. - */ - uint32_t SystemCoreClock = HSI_VALUE; - - const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U}; - const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U}; + * @{ + */ +/* The SystemCoreClock variable is updated in three ways: + 1) by calling CMSIS function SystemCoreClockUpdate() + 2) by calling HAL API function HAL_RCC_GetHCLKFreq() + 3) each time HAL_RCC_ClockConfig() is called to configure the system clock + frequency Note: If you use this function to configure the system clock; then + there is no need to call the 2 first functions listed above, since + SystemCoreClock variable is updated automatically. +*/ +uint32_t SystemCoreClock = HSI_VALUE; + +const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, + 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U}; +const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U}; /** - * @} - */ + * @} + */ /** @addtogroup STM32G4xx_System_Private_FunctionPrototypes - * @{ - */ + * @{ + */ /** - * @} - */ + * @} + */ /** @addtogroup STM32G4xx_System_Private_Functions - * @{ - */ + * @{ + */ /** - * @brief Setup the microcontroller system. - * @param None - * @retval None - */ + * @brief Setup the microcontroller system. + * @param None + * @retval None + */ void SystemInit(void) { - /* FPU settings ------------------------------------------------------------*/ - #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) - SCB->CPACR |= ((3UL << (10*2))|(3UL << (11*2))); /* set CP10 and CP11 Full Access */ - #endif - - /* Configure the Vector Table location add offset address ------------------*/ +/* FPU settings ------------------------------------------------------------*/ +#if (__FPU_PRESENT == 1) && (__FPU_USED == 1) + SCB->CPACR |= ((3UL << (10 * 2)) | + (3UL << (11 * 2))); /* set CP10 and CP11 Full Access */ +#endif + + /* Configure the Vector Table location add offset address + * ------------------*/ #if defined(USER_VECT_TAB_ADDRESS) - SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ -#endif /* USER_VECT_TAB_ADDRESS */ + SCB->VTOR = + VECT_TAB_BASE_ADDRESS | + VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ +#endif /* USER_VECT_TAB_ADDRESS */ } /** - * @brief Update SystemCoreClock variable according to Clock Register Values. - * The SystemCoreClock variable contains the core clock (HCLK), it can - * be used by the user application to setup the SysTick timer or configure - * other parameters. - * - * @note Each time the core clock (HCLK) changes, this function must be called - * to update SystemCoreClock variable value. Otherwise, any configuration - * based on this variable will be incorrect. - * - * @note - The system frequency computed by this function is not the real - * frequency in the chip. It is calculated based on the predefined - * constant and the selected clock source: - * - * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**) - * - * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***) - * - * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***) - * or HSI_VALUE(*) multiplied/divided by the PLL factors. - * - * (**) HSI_VALUE is a constant defined in stm32g4xx_hal.h file (default value - * 16 MHz) but the real value may vary depending on the variations - * in voltage and temperature. - * - * (***) HSE_VALUE is a constant defined in stm32g4xx_hal.h file (default value - * 24 MHz), user has to ensure that HSE_VALUE is same as the real - * frequency of the crystal used. Otherwise, this function may - * have wrong result. - * - * - The result of this function could be not correct when using fractional - * value for HSE crystal. - * - * @param None - * @retval None - */ + * @brief Update SystemCoreClock variable according to Clock Register Values. + * The SystemCoreClock variable contains the core clock (HCLK), it can + * be used by the user application to setup the SysTick timer or + * configure other parameters. + * + * @note Each time the core clock (HCLK) changes, this function must be called + * to update SystemCoreClock variable value. Otherwise, any + * configuration based on this variable will be incorrect. + * + * @note - The system frequency computed by this function is not the real + * frequency in the chip. It is calculated based on the predefined + * constant and the selected clock source: + * + * - If SYSCLK source is HSI, SystemCoreClock will contain the + * HSI_VALUE(**) + * + * - If SYSCLK source is HSE, SystemCoreClock will contain the + * HSE_VALUE(***) + * + * - If SYSCLK source is PLL, SystemCoreClock will contain the + * HSE_VALUE(***) or HSI_VALUE(*) multiplied/divided by the PLL factors. + * + * (**) HSI_VALUE is a constant defined in stm32g4xx_hal.h file (default + * value 16 MHz) but the real value may vary depending on the variations in + * voltage and temperature. + * + * (***) HSE_VALUE is a constant defined in stm32g4xx_hal.h file + * (default value 24 MHz), user has to ensure that HSE_VALUE is same as the real + * frequency of the crystal used. Otherwise, this function may + * have wrong result. + * + * - The result of this function could be not correct when using + * fractional value for HSE crystal. + * + * @param None + * @retval None + */ void SystemCoreClockUpdate(void) { - uint32_t tmp, pllvco, pllr, pllsource, pllm; - - /* Get SYSCLK source -------------------------------------------------------*/ - switch (RCC->CFGR & RCC_CFGR_SWS) - { - case 0x04: /* HSI used as system clock source */ - SystemCoreClock = HSI_VALUE; - break; - - case 0x08: /* HSE used as system clock source */ - SystemCoreClock = HSE_VALUE; - break; - - case 0x0C: /* PLL used as system clock source */ - /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN - SYSCLK = PLL_VCO / PLLR - */ - pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC); - pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4) + 1U ; - if (pllsource == 0x02UL) /* HSI used as PLL clock source */ - { - pllvco = (HSI_VALUE / pllm); - } - else /* HSE used as PLL clock source */ - { - pllvco = (HSE_VALUE / pllm); - } - pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 8); - pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 25) + 1U) * 2U; - SystemCoreClock = pllvco/pllr; - break; - - default: - break; - } - /* Compute HCLK clock frequency --------------------------------------------*/ - /* Get HCLK prescaler */ - tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; - /* HCLK clock frequency */ - SystemCoreClock >>= tmp; + uint32_t tmp, pllvco, pllr, pllsource, pllm; + + /* Get SYSCLK source + * -------------------------------------------------------*/ + switch (RCC->CFGR & RCC_CFGR_SWS) { + case 0x04: /* HSI used as system clock source */ + SystemCoreClock = HSI_VALUE; + break; + + case 0x08: /* HSE used as system clock source */ + SystemCoreClock = HSE_VALUE; + break; + + case 0x0C: /* PLL used as system clock source */ + /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN + SYSCLK = PLL_VCO / PLLR + */ + pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC); + pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4) + 1U; + if (pllsource == + 0x02UL) /* HSI used as PLL clock source */ + { + pllvco = (HSI_VALUE / pllm); + } else /* HSE used as PLL clock source */ + { + pllvco = (HSE_VALUE / pllm); + } + pllvco = + pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 8); + pllr = + (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 25) + 1U) * + 2U; + SystemCoreClock = pllvco / pllr; + break; + + default: + break; + } + /* Compute HCLK clock frequency + * --------------------------------------------*/ + /* Get HCLK prescaler */ + tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; + /* HCLK clock frequency */ + SystemCoreClock >>= tmp; } - /** - * @} - */ + * @} + */ /** - * @} - */ + * @} + */ /** - * @} - */ - - + * @} + */ diff --git a/Lib/GlobalShare/Inc/Logomatic.h b/Lib/GlobalShare/Inc/Logomatic.h index 25bd3f0e..8f1a8b9b 100644 --- a/Lib/GlobalShare/Inc/Logomatic.h +++ b/Lib/GlobalShare/Inc/Logomatic.h @@ -1,19 +1,19 @@ #include #ifndef _LOGOMATIC_H_ - #define _LOGOMATIC_H_ +#define _LOGOMATIC_H_ - #ifdef LOGOMATIC_ENABLED - #define LOGOMATIC(...) printf(__VA_ARGS__) - #else - #define LOGOMATIC(...) - #endif +#ifdef LOGOMATIC_ENABLED +#define LOGOMATIC(...) printf(__VA_ARGS__) +#else +#define LOGOMATIC(...) +#endif - #if defined(LOGOMATIC_ENABLED) && defined(ITM) - __attribute__((weak)) int __io_putchar(int ch) - { - ITM_SendChar(ch); - return ch; - } - #endif +#if defined(LOGOMATIC_ENABLED) && defined(ITM) +__attribute__((weak)) int __io_putchar(int ch) +{ + ITM_SendChar(ch); + return ch; +} +#endif #endif diff --git a/Lib/GlobalShare/Test/logomatic_float_print.c b/Lib/GlobalShare/Test/logomatic_float_print.c index acd6d793..b80e84e7 100644 --- a/Lib/GlobalShare/Test/logomatic_float_print.c +++ b/Lib/GlobalShare/Test/logomatic_float_print.c @@ -4,6 +4,6 @@ int main(void) { - LOGOMATIC("I like %f\n", M_PI); - return 0; + LOGOMATIC("I like %f\n", M_PI); + return 0; } diff --git a/Lib/GlobalShare/Test/logomatic_simple_print.c b/Lib/GlobalShare/Test/logomatic_simple_print.c index 4dcfba60..cf72683f 100644 --- a/Lib/GlobalShare/Test/logomatic_simple_print.c +++ b/Lib/GlobalShare/Test/logomatic_simple_print.c @@ -2,6 +2,6 @@ int main(void) { - LOGOMATIC("Hello, Logomatic!\n"); - return 0; + LOGOMATIC("Hello, Logomatic!\n"); + return 0; } From d9c53c4b824d6f2e73f01748b8175cb164000998 Mon Sep 17 00:00:00 2001 From: Daniel Hansen Date: Thu, 30 Oct 2025 04:56:17 -0700 Subject: [PATCH 8/9] Fix formatting of svdPath entries in launch.json --- .vscode/launch.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 31b8d98d..49424bc0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -77,7 +77,7 @@ "searchDir": [], "preLaunchTask": "CMake: configure and build", "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Platform/STM32G474xE/CompileDependencies/STM32G474.svd", + "svdPath": "${workspaceFolder}/Lib/Platform/STM32G474xE/CompileDependencies/STM32G474.svd" }, { "cwd": "${workspaceFolder}", @@ -93,7 +93,7 @@ "searchDir": [], "preLaunchTask": "CMake: configure and build", "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Platform/STM32U5A9xJ/CompileDependencies/STM32U5A9.svd", + "svdPath": "${workspaceFolder}/Lib/Platform/STM32U5A9xJ/CompileDependencies/STM32U5A9.svd" }, { "cwd": "${workspaceFolder}", @@ -109,7 +109,7 @@ "searchDir": [], "preLaunchTask": "CMake: configure and build", "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Platform/STM32L476xG/CompileDependencies/STM32L476.svd", + "svdPath": "${workspaceFolder}/Lib/Platform/STM32L476xG/CompileDependencies/STM32L476.svd" }, { "cwd": "${workspaceFolder}", @@ -125,7 +125,7 @@ "searchDir": [], "preLaunchTask": "CMake: configure and build", "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Platform/STM32G474xE/CompileDependencies/STM32G474.svd", + "svdPath": "${workspaceFolder}/Lib/Platform/STM32G474xE/CompileDependencies/STM32G474.svd" }, { "cwd": "${workspaceFolder}", @@ -141,7 +141,7 @@ "searchDir": [], "preLaunchTask": "CMake: configure and build", "showDevDebugOutput": "raw", - "svdPath": "${workspaceFolder}/Lib/Platform/STM32G474xE/CompileDependencies/STM32G474.svd", + "svdPath": "${workspaceFolder}/Lib/Platform/STM32G474xE/CompileDependencies/STM32G474.svd" } ] } From 833c29df2c06c6174b5d6d19276c3aa8cab5d2d5 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 30 Oct 2025 11:58:13 +0000 Subject: [PATCH 9/9] Automatic Clang-Format: Standardized formatting automatically --- BLINKY/G4HELLO/Core/Inc/stm32g4xx_hal_conf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BLINKY/G4HELLO/Core/Inc/stm32g4xx_hal_conf.h b/BLINKY/G4HELLO/Core/Inc/stm32g4xx_hal_conf.h index 6d840da0..03683b17 100644 --- a/BLINKY/G4HELLO/Core/Inc/stm32g4xx_hal_conf.h +++ b/BLINKY/G4HELLO/Core/Inc/stm32g4xx_hal_conf.h @@ -146,7 +146,7 @@ extern "C" { #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 \ + FS/RNG in Hz. The real value my vary depending on \ manufacturing process variations.*/ #endif /* HSI48_VALUE */