From e1071bff12bc1eb95f2a4a403fc743d635176f66 Mon Sep 17 00:00:00 2001 From: Ivan Lange Date: Tue, 24 Mar 2026 15:57:33 -0400 Subject: [PATCH 01/13] Setup motherboard project --- boards/motherboard/.gitignore | 15 + boards/motherboard/Inc/gpio.h | 49 +++ boards/motherboard/Inc/main.h | 71 ++++ boards/motherboard/Inc/stm32g0xx_hal_conf.h | 351 ++++++++++++++++++ boards/motherboard/Inc/stm32g0xx_it.h | 62 ++++ boards/motherboard/Inc/usb_drd_fs.h | 52 +++ boards/motherboard/STM32G0B1VETX_FLASH.ld | 188 ++++++++++ boards/motherboard/STM32G0B1VETX_RAM.ld | 188 ++++++++++ .../Startup/startup_stm32g0b1vetx.s | 296 +++++++++++++++ boards/motherboard/motherboard.ioc | 120 ++++++ boards/motherboard/platformio.ini | 23 ++ boards/motherboard/post_cubemx.sh | 11 + boards/motherboard/src/gpio.c | 60 +++ boards/motherboard/src/main.c | 182 +++++++++ boards/motherboard/src/stm32g0xx_hal_msp.c | 85 +++++ boards/motherboard/src/stm32g0xx_it.c | 145 ++++++++ boards/motherboard/src/syscalls.c | 176 +++++++++ boards/motherboard/src/sysmem.c | 79 ++++ boards/motherboard/src/system_stm32g0xx.c | 304 +++++++++++++++ boards/motherboard/src/usb_drd_fs.c | 121 ++++++ 20 files changed, 2578 insertions(+) create mode 100644 boards/motherboard/.gitignore create mode 100644 boards/motherboard/Inc/gpio.h create mode 100644 boards/motherboard/Inc/main.h create mode 100644 boards/motherboard/Inc/stm32g0xx_hal_conf.h create mode 100644 boards/motherboard/Inc/stm32g0xx_it.h create mode 100644 boards/motherboard/Inc/usb_drd_fs.h create mode 100644 boards/motherboard/STM32G0B1VETX_FLASH.ld create mode 100644 boards/motherboard/STM32G0B1VETX_RAM.ld create mode 100644 boards/motherboard/Startup/startup_stm32g0b1vetx.s create mode 100644 boards/motherboard/motherboard.ioc create mode 100644 boards/motherboard/platformio.ini create mode 100644 boards/motherboard/post_cubemx.sh create mode 100644 boards/motherboard/src/gpio.c create mode 100644 boards/motherboard/src/main.c create mode 100644 boards/motherboard/src/stm32g0xx_hal_msp.c create mode 100644 boards/motherboard/src/stm32g0xx_it.c create mode 100644 boards/motherboard/src/syscalls.c create mode 100644 boards/motherboard/src/sysmem.c create mode 100644 boards/motherboard/src/system_stm32g0xx.c create mode 100644 boards/motherboard/src/usb_drd_fs.c diff --git a/boards/motherboard/.gitignore b/boards/motherboard/.gitignore new file mode 100644 index 0000000..cb5a7d2 --- /dev/null +++ b/boards/motherboard/.gitignore @@ -0,0 +1,15 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch + +# PlatformIO doesn't have the U0 driver yet. Instead of tracking ~200k lines of code, +# each developer should `Generate Code` in CubeMX to get the drivers and middlewares +Drivers/ +Middlewares/ + +# STMCubeMX dotfiles +.project +.cproject +.mxproject diff --git a/boards/motherboard/Inc/gpio.h b/boards/motherboard/Inc/gpio.h new file mode 100644 index 0000000..1204b1d --- /dev/null +++ b/boards/motherboard/Inc/gpio.h @@ -0,0 +1,49 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file gpio.h + * @brief This file contains all the function prototypes for + * the gpio.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __GPIO_H__ +#define __GPIO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_GPIO_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif +#endif /*__ GPIO_H__ */ + diff --git a/boards/motherboard/Inc/main.h b/boards/motherboard/Inc/main.h new file mode 100644 index 0000000..351e668 --- /dev/null +++ b/boards/motherboard/Inc/main.h @@ -0,0 +1,71 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.h + * @brief : Header for main.c file. + * This file contains the common defines of the application. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __MAIN_H +#define __MAIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32g0xx_hal.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 DEBUG_Pin GPIO_PIN_7 +#define DEBUG_GPIO_Port GPIOE + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +#ifdef __cplusplus +} +#endif + +#endif /* __MAIN_H */ diff --git a/boards/motherboard/Inc/stm32g0xx_hal_conf.h b/boards/motherboard/Inc/stm32g0xx_hal_conf.h new file mode 100644 index 0000000..448c212 --- /dev/null +++ b/boards/motherboard/Inc/stm32g0xx_hal_conf.h @@ -0,0 +1,351 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g0xx_hal_conf.h + * @author MCD Application Team + * @brief HAL configuration file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2018 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 STM32G0xx_HAL_CONF_H +#define STM32G0xx_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_CEC_MODULE_ENABLED */ +/* #define HAL_COMP_MODULE_ENABLED */ +/* #define HAL_CRC_MODULE_ENABLED */ +/* #define HAL_CRYP_MODULE_ENABLED */ +/* #define HAL_DAC_MODULE_ENABLED */ +/* #define HAL_EXTI_MODULE_ENABLED */ +/* #define HAL_FDCAN_MODULE_ENABLED */ +/* #define HAL_HCD_MODULE_ENABLED */ +/* #define HAL_I2C_MODULE_ENABLED */ +/* #define HAL_I2S_MODULE_ENABLED */ +/* #define HAL_IWDG_MODULE_ENABLED */ +/* #define HAL_IRDA_MODULE_ENABLED */ +/* #define HAL_LPTIM_MODULE_ENABLED */ +#define HAL_PCD_MODULE_ENABLED +/* #define HAL_RNG_MODULE_ENABLED */ +/* #define HAL_RTC_MODULE_ENABLED */ +/* #define HAL_SMARTCARD_MODULE_ENABLED */ +/* #define HAL_SMBUS_MODULE_ENABLED */ +/* #define HAL_SPI_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_CEC_REGISTER_CALLBACKS 0u +#define USE_HAL_COMP_REGISTER_CALLBACKS 0u +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0u +#define USE_HAL_DAC_REGISTER_CALLBACKS 0u +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0u +#define USE_HAL_HCD_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_PCD_REGISTER_CALLBACKS 0u +#define USE_HAL_RNG_REGISTER_CALLBACKS 0u +#define USE_HAL_RTC_REGISTER_CALLBACKS 0u +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0u +#define USE_HAL_SPI_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 (8000000UL) /*!< 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 */ + +#if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx) +/** + * @brief Internal High Speed oscillator (HSI48) value for USB FS, SDMMC 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 48000000U /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/RNG in Hz. + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ +#endif + +/** + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz +The real value may vary depending on the variations +in voltage and temperature.*/ +/** + * @brief External Low Speed oscillator (LSE) value. + * 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 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 I2S1 peripheral + * This value is used by the RCC HAL module to compute the I2S1 clock source + * frequency. + */ +#if !defined (EXTERNAL_I2S1_CLOCK_VALUE) +#define EXTERNAL_I2S1_CLOCK_VALUE (48000UL) /*!< Value of the I2S1 External clock source in Hz*/ +#endif /* EXTERNAL_I2S1_CLOCK_VALUE */ + +#if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx) +/** + * @brief External clock source for I2S2 peripheral + * This value is used by the RCC HAL module to compute the I2S2 clock source + * frequency. + */ +#if !defined (EXTERNAL_I2S2_CLOCK_VALUE) + #define EXTERNAL_I2S2_CLOCK_VALUE 48000U /*!< Value of the I2S2 External clock source in Hz*/ +#endif /* EXTERNAL_I2S2_CLOCK_VALUE */ +#endif + +/* 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 3U /*!< tick interrupt priority */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 1U +#define INSTRUCTION_CACHE_ENABLE 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 + +/* ################## CRYP peripheral configuration ########################## */ + +#define USE_HAL_CRYP_SUSPEND_RESUME 1U + +/* ########################## Assert Selection ############################## */ +/** + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +/* #define USE_FULL_ASSERT 1U */ + +/* Includes ------------------------------------------------------------------*/ +/** + * @brief Include modules header file + */ + +#ifdef HAL_RCC_MODULE_ENABLED +#include "stm32g0xx_hal_rcc.h" +#endif /* HAL_RCC_MODULE_ENABLED */ + +#ifdef HAL_GPIO_MODULE_ENABLED +#include "stm32g0xx_hal_gpio.h" +#endif /* HAL_GPIO_MODULE_ENABLED */ + +#ifdef HAL_DMA_MODULE_ENABLED +#include "stm32g0xx_hal_dma.h" +#endif /* HAL_DMA_MODULE_ENABLED */ + +#ifdef HAL_CORTEX_MODULE_ENABLED +#include "stm32g0xx_hal_cortex.h" +#endif /* HAL_CORTEX_MODULE_ENABLED */ + +#ifdef HAL_ADC_MODULE_ENABLED +#include "stm32g0xx_hal_adc.h" +#include "stm32g0xx_hal_adc_ex.h" +#endif /* HAL_ADC_MODULE_ENABLED */ + +#ifdef HAL_CEC_MODULE_ENABLED +#include "stm32g0xx_hal_cec.h" +#endif /* HAL_CEC_MODULE_ENABLED */ + +#ifdef HAL_COMP_MODULE_ENABLED +#include "stm32g0xx_hal_comp.h" +#endif /* HAL_COMP_MODULE_ENABLED */ + +#ifdef HAL_CRC_MODULE_ENABLED +#include "stm32g0xx_hal_crc.h" +#endif /* HAL_CRC_MODULE_ENABLED */ + +#ifdef HAL_CRYP_MODULE_ENABLED +#include "stm32g0xx_hal_cryp.h" +#endif /* HAL_CRYP_MODULE_ENABLED */ + +#ifdef HAL_DAC_MODULE_ENABLED +#include "stm32g0xx_hal_dac.h" +#endif /* HAL_DAC_MODULE_ENABLED */ + +#ifdef HAL_EXTI_MODULE_ENABLED +#include "stm32g0xx_hal_exti.h" +#endif /* HAL_EXTI_MODULE_ENABLED */ + +#ifdef HAL_FLASH_MODULE_ENABLED +#include "stm32g0xx_hal_flash.h" +#endif /* HAL_FLASH_MODULE_ENABLED */ + +#ifdef HAL_FDCAN_MODULE_ENABLED +#include "stm32g0xx_hal_fdcan.h" +#endif /* HAL_FDCAN_MODULE_ENABLED */ + +#ifdef HAL_HCD_MODULE_ENABLED +#include "stm32g0xx_hal_hcd.h" +#endif /* HAL_HCD_MODULE_ENABLED */ + +#ifdef HAL_I2C_MODULE_ENABLED +#include "stm32g0xx_hal_i2c.h" +#endif /* HAL_I2C_MODULE_ENABLED */ + +#ifdef HAL_I2S_MODULE_ENABLED +#include "stm32g0xx_hal_i2s.h" +#endif /* HAL_I2S_MODULE_ENABLED */ + +#ifdef HAL_IRDA_MODULE_ENABLED +#include "stm32g0xx_hal_irda.h" +#endif /* HAL_IRDA_MODULE_ENABLED */ + +#ifdef HAL_IWDG_MODULE_ENABLED +#include "stm32g0xx_hal_iwdg.h" +#endif /* HAL_IWDG_MODULE_ENABLED */ + +#ifdef HAL_LPTIM_MODULE_ENABLED +#include "stm32g0xx_hal_lptim.h" +#endif /* HAL_LPTIM_MODULE_ENABLED */ + +#ifdef HAL_PCD_MODULE_ENABLED +#include "stm32g0xx_hal_pcd.h" +#endif /* HAL_PCD_MODULE_ENABLED */ + +#ifdef HAL_PWR_MODULE_ENABLED +#include "stm32g0xx_hal_pwr.h" +#endif /* HAL_PWR_MODULE_ENABLED */ + +#ifdef HAL_RNG_MODULE_ENABLED +#include "stm32g0xx_hal_rng.h" +#endif /* HAL_RNG_MODULE_ENABLED */ + +#ifdef HAL_RTC_MODULE_ENABLED +#include "stm32g0xx_hal_rtc.h" +#endif /* HAL_RTC_MODULE_ENABLED */ + +#ifdef HAL_SMARTCARD_MODULE_ENABLED +#include "stm32g0xx_hal_smartcard.h" +#endif /* HAL_SMARTCARD_MODULE_ENABLED */ + +#ifdef HAL_SMBUS_MODULE_ENABLED +#include "stm32g0xx_hal_smbus.h" +#endif /* HAL_SMBUS_MODULE_ENABLED */ + +#ifdef HAL_SPI_MODULE_ENABLED +#include "stm32g0xx_hal_spi.h" +#endif /* HAL_SPI_MODULE_ENABLED */ + +#ifdef HAL_TIM_MODULE_ENABLED +#include "stm32g0xx_hal_tim.h" +#endif /* HAL_TIM_MODULE_ENABLED */ + +#ifdef HAL_UART_MODULE_ENABLED +#include "stm32g0xx_hal_uart.h" +#endif /* HAL_UART_MODULE_ENABLED */ + +#ifdef HAL_USART_MODULE_ENABLED +#include "stm32g0xx_hal_usart.h" +#endif /* HAL_USART_MODULE_ENABLED */ + +#ifdef HAL_WWDG_MODULE_ENABLED +#include "stm32g0xx_hal_wwdg.h" +#endif /* HAL_WWDG_MODULE_ENABLED */ + +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT +/** + * @brief The assert_param macro is used for functions 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 /* STM32G0xx_HAL_CONF_H */ diff --git a/boards/motherboard/Inc/stm32g0xx_it.h b/boards/motherboard/Inc/stm32g0xx_it.h new file mode 100644 index 0000000..9fcd05f --- /dev/null +++ b/boards/motherboard/Inc/stm32g0xx_it.h @@ -0,0 +1,62 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g0xx_it.h + * @brief This file contains the headers of the interrupt handlers. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32G0xx_IT_H +#define __STM32G0xx_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 SVC_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); +/* USER CODE BEGIN EFP */ + +/* USER CODE END EFP */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32G0xx_IT_H */ diff --git a/boards/motherboard/Inc/usb_drd_fs.h b/boards/motherboard/Inc/usb_drd_fs.h new file mode 100644 index 0000000..140ccb6 --- /dev/null +++ b/boards/motherboard/Inc/usb_drd_fs.h @@ -0,0 +1,52 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file usb_drd_fs.h + * @brief This file contains all the function prototypes for + * the usb_drd_fs.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USB_DRD_FS_H__ +#define __USB_DRD_FS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern PCD_HandleTypeDef hpcd_USB_DRD_FS; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_USB_DRD_FS_PCD_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USB_DRD_FS_H__ */ + diff --git a/boards/motherboard/STM32G0B1VETX_FLASH.ld b/boards/motherboard/STM32G0B1VETX_FLASH.ld new file mode 100644 index 0000000..0491066 --- /dev/null +++ b/boards/motherboard/STM32G0B1VETX_FLASH.ld @@ -0,0 +1,188 @@ +/* +****************************************************************************** +** +** @file : LinkerScript.ld +** +** @author : Auto-generated by STM32CubeIDE +** +** @brief : Linker script for STM32G0B1VETx Device from STM32G0 series +** 512KBytes FLASH +** 144KBytes RAM +** +** Set heap size, stack size and stack location according +** to application requirements. +** +** Set memory bank area and size if external memory is used +** +** Target : STMicroelectronics STM32 +** +** Distribution: The file is distributed as is, without any warranty +** of any kind. +** +****************************************************************************** +** @attention +** +** Copyright (c) 2026 STMicroelectronics. +** All rights reserved. +** +** This software is licensed under terms that can be found in the LICENSE file +** in the root directory of this software component. +** If no LICENSE file comes with this software, it is provided AS-IS. +** +****************************************************************************** +*/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 144K + FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K +} + +/* Sections */ +SECTIONS +{ + + /* The startup code into "FLASH" Rom type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >FLASH + + /* The program code and other data into "FLASH" Rom type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >FLASH + + /* Constant data into "FLASH" Rom type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >FLASH + + .ARM.extab (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >FLASH + + .ARM (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >FLASH + + .preinit_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >FLASH + + .init_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >FLASH + + .fini_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >FLASH + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + *(.RamFunc) /* .RamFunc sections */ + *(.RamFunc*) /* .RamFunc* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM AT> FLASH + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/boards/motherboard/STM32G0B1VETX_RAM.ld b/boards/motherboard/STM32G0B1VETX_RAM.ld new file mode 100644 index 0000000..486580b --- /dev/null +++ b/boards/motherboard/STM32G0B1VETX_RAM.ld @@ -0,0 +1,188 @@ +/* +****************************************************************************** +** +** @file : LinkerScript.ld (debug in RAM dedicated) +** +** @author : Auto-generated by STM32CubeIDE +** +** @brief : Linker script for STM32G0B1VETx Device from STM32G0 series +** 512KBytes FLASH +** 144KBytes RAM +** +** Set heap size, stack size and stack location according +** to application requirements. +** +** Set memory bank area and size if external memory is used +** +** Target : STMicroelectronics STM32 +** +** Distribution: The file is distributed as is, without any warranty +** of any kind. +** +****************************************************************************** +** @attention +** +** Copyright (c) 2026 STMicroelectronics. +** All rights reserved. +** +** This software is licensed under terms that can be found in the LICENSE file +** in the root directory of this software component. +** If no LICENSE file comes with this software, it is provided AS-IS. +** +****************************************************************************** +*/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Highest address of the user mode stack */ +_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ + +_Min_Heap_Size = 0x200; /* required amount of heap */ +_Min_Stack_Size = 0x400; /* required amount of stack */ + +/* Memories definition */ +MEMORY +{ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 144K + FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K +} + +/* Sections */ +SECTIONS +{ + + /* The startup code into "RAM" Ram type memory */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } >RAM + + /* The program code and other data into "RAM" Ram type memory */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + *(.RamFunc) /* .RamFunc sections */ + *(.RamFunc*) /* .RamFunc* sections */ + + KEEP (*(.init)) + KEEP (*(.fini)) + + . = ALIGN(4); + _etext = .; /* define a global symbols at end of code */ + } >RAM + + /* Constant data into "RAM" Ram type memory */ + .rodata : + { + . = ALIGN(4); + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + . = ALIGN(4); + } >RAM + + .ARM.extab (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + *(.ARM.extab* .gnu.linkonce.armextab.*) + . = ALIGN(4); + } >RAM + + .ARM (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + . = ALIGN(4); + } >RAM + + .preinit_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + . = ALIGN(4); + } >RAM + + .init_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + . = ALIGN(4); + } >RAM + + .fini_array (READONLY) : /* The "READONLY" keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */ + { + . = ALIGN(4); + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + . = ALIGN(4); + } >RAM + + /* Used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* Initialized data sections into "RAM" Ram type memory */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end */ + + } >RAM + + /* Uninitialized data section into "RAM" Ram type memory */ + . = ALIGN(4); + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + _sbss = .; /* define a global symbol at bss start */ + __bss_start__ = _sbss; + *(.bss) + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end */ + __bss_end__ = _ebss; + } >RAM + + /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ + ._user_heap_stack : + { + . = ALIGN(8); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + . = . + _Min_Heap_Size; + . = . + _Min_Stack_Size; + . = ALIGN(8); + } >RAM + + /* Remove information from the compiler libraries */ + /DISCARD/ : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + } + + .ARM.attributes 0 : { *(.ARM.attributes) } +} diff --git a/boards/motherboard/Startup/startup_stm32g0b1vetx.s b/boards/motherboard/Startup/startup_stm32g0b1vetx.s new file mode 100644 index 0000000..88a1208 --- /dev/null +++ b/boards/motherboard/Startup/startup_stm32g0b1vetx.s @@ -0,0 +1,296 @@ +/** + ****************************************************************************** + * @file startup_stm32g0b1xx.s + * @author MCD Application Team + * @brief STM32G0b1xx devices vector table GCC toolchain. + * This module performs: + * - Set the initial SP + * - Set the initial PC == Reset_Handler, + * - Set the vector table entries with the exceptions ISR address + * - Branches to main in the C library (which eventually + * calls main()). + * After Reset the Cortex-M0+ processor is in Thread mode, + * priority is Privileged, and the Stack is set to Main. + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 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. + * + ****************************************************************************** + */ + +.syntax unified +.cpu cortex-m0plus +.fpu softvfp +.thumb + +.global g_pfnVectors +.global Default_Handler + +/* start address for the initialization values of the .data section. +defined in linker script */ +.word _sidata +/* start address for the .data section. defined in linker script */ +.word _sdata +/* end address for the .data section. defined in linker script */ +.word _edata +/* start address for the .bss section. defined in linker script */ +.word _sbss +/* end address for the .bss section. defined in linker script */ +.word _ebss + +/** + * @brief This is the code that gets called when the processor first + * starts execution following a reset event. Only the absolutely + * necessary set is performed, after which the application + * supplied main() routine is called. + * @param None + * @retval None +*/ + + .section .text.Reset_Handler + .weak Reset_Handler + .type Reset_Handler, %function +Reset_Handler: + ldr r0, =_estack + mov sp, r0 /* set stack pointer */ + +/* Call the clock system initialization function.*/ + bl SystemInit + +/* Copy the data segment initializers from flash to SRAM */ + ldr r0, =_sdata + ldr r1, =_edata + ldr r2, =_sidata + movs r3, #0 + b LoopCopyDataInit + +CopyDataInit: + ldr r4, [r2, r3] + str r4, [r0, r3] + adds r3, r3, #4 + +LoopCopyDataInit: + adds r4, r0, r3 + cmp r4, r1 + bcc CopyDataInit + +/* Zero fill the bss segment. */ + ldr r2, =_sbss + ldr r4, =_ebss + movs r3, #0 + b LoopFillZerobss + +FillZerobss: + str r3, [r2] + adds r2, r2, #4 + +LoopFillZerobss: + cmp r2, r4 + bcc FillZerobss + +/* Call static constructors */ + bl __libc_init_array +/* Call the application s entry point.*/ + bl main + +LoopForever: + b LoopForever + +.size Reset_Handler, .-Reset_Handler + +/** + * @brief This is the code that gets called when the processor receives an + * unexpected interrupt. This simply enters an infinite loop, preserving + * the system state for examination by a debugger. + * + * @param None + * @retval None +*/ + .section .text.Default_Handler,"ax",%progbits +Default_Handler: +Infinite_Loop: + b Infinite_Loop + .size Default_Handler, .-Default_Handler + +/****************************************************************************** +* +* The minimal vector table for a Cortex M0. Note that the proper constructs +* must be placed on this to ensure that it ends up at physical address +* 0x0000.0000. +* +******************************************************************************/ + .section .isr_vector,"a",%progbits + .type g_pfnVectors, %object + +g_pfnVectors: + .word _estack + .word Reset_Handler + .word NMI_Handler + .word HardFault_Handler + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + .word SVC_Handler + .word 0 + .word 0 + .word PendSV_Handler + .word SysTick_Handler + .word WWDG_IRQHandler /* Window WatchDog */ + .word PVD_VDDIO2_IRQHandler /* PVD through EXTI Line detect */ + .word RTC_TAMP_IRQHandler /* RTC through the EXTI line */ + .word FLASH_IRQHandler /* FLASH */ + .word RCC_CRS_IRQHandler /* RCC & CRS */ + .word EXTI0_1_IRQHandler /* EXTI Line 0 and 1 */ + .word EXTI2_3_IRQHandler /* EXTI Line 2 and 3 */ + .word EXTI4_15_IRQHandler /* EXTI Line 4 to 15 */ + .word USB_UCPD1_2_IRQHandler /* USB, UCPD1, UCPD2 */ + .word DMA1_Channel1_IRQHandler /* DMA1 Channel 1 */ + .word DMA1_Channel2_3_IRQHandler /* DMA1 Channel 2 and Channel 3 */ + .word DMA1_Ch4_7_DMA2_Ch1_5_DMAMUX1_OVR_IRQHandler /* DMA1 Ch4 to Ch7, DMA2 Ch1 to Ch5, DMAMUX1 overrun */ + .word ADC1_COMP_IRQHandler /* ADC1, COMP1 and COMP2 */ + .word TIM1_BRK_UP_TRG_COM_IRQHandler /* TIM1 Break, Update, Trigger and Commutation */ + .word TIM1_CC_IRQHandler /* TIM1 Capture Compare */ + .word TIM2_IRQHandler /* TIM2 */ + .word TIM3_TIM4_IRQHandler /* TIM3, TIM4 */ + .word TIM6_DAC_LPTIM1_IRQHandler /* TIM6, DAC and LPTIM1 */ + .word TIM7_LPTIM2_IRQHandler /* TIM7 and LPTIM2 */ + .word TIM14_IRQHandler /* TIM14 */ + .word TIM15_IRQHandler /* TIM15 */ + .word TIM16_FDCAN_IT0_IRQHandler /* TIM16 & FDCAN1_IT0 & FDCAN2_IT0 */ + .word TIM17_FDCAN_IT1_IRQHandler /* TIM17 & FDCAN1_IT1 & FDCAN2_IT1 */ + .word I2C1_IRQHandler /* I2C1 */ + .word I2C2_3_IRQHandler /* I2C2, I2C3 */ + .word SPI1_IRQHandler /* SPI1 */ + .word SPI2_3_IRQHandler /* SPI2, SPI3 */ + .word USART1_IRQHandler /* USART1 */ + .word USART2_LPUART2_IRQHandler /* USART2 & LPUART2 */ + .word USART3_4_5_6_LPUART1_IRQHandler /* USART3, USART4, USART5, USART6, LPUART1 */ + .word CEC_IRQHandler /* CEC */ + + .size g_pfnVectors, .-g_pfnVectors + +/******************************************************************************* +* +* Provide weak aliases for each Exception handler to the Default_Handler. +* As they are weak aliases, any function with the same name will override +* this definition. +* +*******************************************************************************/ + + .weak NMI_Handler + .thumb_set NMI_Handler,Default_Handler + + .weak HardFault_Handler + .thumb_set HardFault_Handler,Default_Handler + + .weak SVC_Handler + .thumb_set SVC_Handler,Default_Handler + + .weak PendSV_Handler + .thumb_set PendSV_Handler,Default_Handler + + .weak SysTick_Handler + .thumb_set SysTick_Handler,Default_Handler + + .weak WWDG_IRQHandler + .thumb_set WWDG_IRQHandler,Default_Handler + + .weak PVD_VDDIO2_IRQHandler + .thumb_set PVD_VDDIO2_IRQHandler,Default_Handler + + .weak RTC_TAMP_IRQHandler + .thumb_set RTC_TAMP_IRQHandler,Default_Handler + + .weak FLASH_IRQHandler + .thumb_set FLASH_IRQHandler,Default_Handler + + .weak RCC_CRS_IRQHandler + .thumb_set RCC_CRS_IRQHandler,Default_Handler + + .weak EXTI0_1_IRQHandler + .thumb_set EXTI0_1_IRQHandler,Default_Handler + + .weak EXTI2_3_IRQHandler + .thumb_set EXTI2_3_IRQHandler,Default_Handler + + .weak EXTI4_15_IRQHandler + .thumb_set EXTI4_15_IRQHandler,Default_Handler + + .weak USB_UCPD1_2_IRQHandler + .thumb_set USB_UCPD1_2_IRQHandler,Default_Handler + + .weak DMA1_Channel1_IRQHandler + .thumb_set DMA1_Channel1_IRQHandler,Default_Handler + + .weak DMA1_Channel2_3_IRQHandler + .thumb_set DMA1_Channel2_3_IRQHandler,Default_Handler + + .weak DMA1_Ch4_7_DMA2_Ch1_5_DMAMUX1_OVR_IRQHandler + .thumb_set DMA1_Ch4_7_DMA2_Ch1_5_DMAMUX1_OVR_IRQHandler,Default_Handler + + .weak ADC1_COMP_IRQHandler + .thumb_set ADC1_COMP_IRQHandler,Default_Handler + + .weak TIM1_BRK_UP_TRG_COM_IRQHandler + .thumb_set TIM1_BRK_UP_TRG_COM_IRQHandler,Default_Handler + + .weak TIM1_CC_IRQHandler + .thumb_set TIM1_CC_IRQHandler,Default_Handler + + .weak TIM2_IRQHandler + .thumb_set TIM2_IRQHandler,Default_Handler + + .weak TIM3_TIM4_IRQHandler + .thumb_set TIM3_TIM4_IRQHandler,Default_Handler + + .weak TIM6_DAC_LPTIM1_IRQHandler + .thumb_set TIM6_DAC_LPTIM1_IRQHandler,Default_Handler + + .weak TIM7_LPTIM2_IRQHandler + .thumb_set TIM7_LPTIM2_IRQHandler,Default_Handler + + .weak TIM14_IRQHandler + .thumb_set TIM14_IRQHandler,Default_Handler + + .weak TIM15_IRQHandler + .thumb_set TIM15_IRQHandler,Default_Handler + + .weak TIM16_FDCAN_IT0_IRQHandler + .thumb_set TIM16_FDCAN_IT0_IRQHandler,Default_Handler + + .weak TIM17_FDCAN_IT1_IRQHandler + .thumb_set TIM17_FDCAN_IT1_IRQHandler,Default_Handler + + .weak I2C1_IRQHandler + .thumb_set I2C1_IRQHandler,Default_Handler + + .weak I2C2_3_IRQHandler + .thumb_set I2C2_3_IRQHandler,Default_Handler + + .weak SPI1_IRQHandler + .thumb_set SPI1_IRQHandler,Default_Handler + + .weak SPI2_3_IRQHandler + .thumb_set SPI2_3_IRQHandler,Default_Handler + + .weak USART1_IRQHandler + .thumb_set USART1_IRQHandler,Default_Handler + + .weak USART2_LPUART2_IRQHandler + .thumb_set USART2_LPUART2_IRQHandler,Default_Handler + + .weak USART3_4_5_6_LPUART1_IRQHandler + .thumb_set USART3_4_5_6_LPUART1_IRQHandler,Default_Handler + + .weak CEC_IRQHandler + .thumb_set CEC_IRQHandler,Default_Handler diff --git a/boards/motherboard/motherboard.ioc b/boards/motherboard/motherboard.ioc new file mode 100644 index 0000000..14adc95 --- /dev/null +++ b/boards/motherboard/motherboard.ioc @@ -0,0 +1,120 @@ +#MicroXplorer Configuration settings - do not modify +CAD.formats= +CAD.pinconfig= +CAD.provider= +File.Version=6 +GPIO.groupedBy= +KeepUserPlacement=false +Mcu.CPN=STM32G0B1VET6 +Mcu.Family=STM32G0 +Mcu.IP0=NVIC +Mcu.IP1=RCC +Mcu.IP2=SYS +Mcu.IP3=USB_DRD_FS +Mcu.IPNb=4 +Mcu.Name=STM32G0B1V(B-C-E)Tx +Mcu.Package=LQFP100 +Mcu.Pin0=PE7 +Mcu.Pin1=PA11 [PA9] +Mcu.Pin2=PA12 [PA10] +Mcu.Pin3=VP_SYS_VS_Systick +Mcu.Pin4=VP_SYS_VS_DBSignals +Mcu.PinsNb=5 +Mcu.ThirdPartyNb=0 +Mcu.UserConstants= +Mcu.UserName=STM32G0B1VETx +MxCube.Version=6.17.0 +MxDb.Version=DB.6.0.170 +NVIC.ForceEnableDMAVector=true +NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false +NVIC.SVC_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true +NVIC.SysTick_IRQn=true\:3\:0\:false\:false\:true\:false\:true\:false +PA11\ [PA9].Mode=Device +PA11\ [PA9].Signal=USB_DM +PA12\ [PA10].Mode=Device +PA12\ [PA10].Signal=USB_DP +PE7.GPIOParameters=GPIO_Label +PE7.GPIO_Label=DEBUG +PE7.Locked=true +PE7.Signal=GPIO_Output +PinOutPanel.RotationAngle=0 +ProjectManager.AskForMigrate=true +ProjectManager.BackupPrevious=false +ProjectManager.CompilerLinker=GCC +ProjectManager.CompilerOptimize=6 +ProjectManager.ComputerToolchain=false +ProjectManager.CoupleFile=true +ProjectManager.CustomerFirmwarePackage= +ProjectManager.DefaultFWLocation=true +ProjectManager.DeletePrevious=true +ProjectManager.DeviceId=STM32G0B1VETx +ProjectManager.FirmwarePackage=STM32Cube FW_G0 V1.6.3 +ProjectManager.FreePins=false +ProjectManager.FreePinsContext= +ProjectManager.HalAssertFull=false +ProjectManager.HeapSize=0x200 +ProjectManager.KeepUserCode=true +ProjectManager.LastFirmware=true +ProjectManager.LibraryCopy=1 +ProjectManager.MainLocation=Src +ProjectManager.NoMain=false +ProjectManager.PreviousToolchain=STM32CubeIDE +ProjectManager.ProjectBuild=false +ProjectManager.ProjectFileName=motherboard.ioc +ProjectManager.ProjectName=motherboard +ProjectManager.ProjectStructure= +ProjectManager.RegisterCallBack= +ProjectManager.StackSize=0x400 +ProjectManager.TargetToolchain=STM32CubeIDE +ProjectManager.ToolChainLocation= +ProjectManager.UAScriptAfterPath= +ProjectManager.UAScriptBeforePath= +ProjectManager.UnderRoot=true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USB_DRD_FS_PCD_Init-USB_DRD_FS-false-HAL-true +RCC.AHBFreq_Value=16000000 +RCC.APBFreq_Value=16000000 +RCC.APBTimFreq_Value=16000000 +RCC.CECFreq_Value=32786.88524590164 +RCC.CortexFreq_Value=16000000 +RCC.EXTERNAL_CLOCK_VALUE=48000 +RCC.FCLKCortexFreq_Value=16000000 +RCC.FDCANFreq_Value=16000000 +RCC.FamilyName=M +RCC.HCLKFreq_Value=16000000 +RCC.HSE_VALUE=8000000 +RCC.HSI48_VALUE=48000000 +RCC.HSI_VALUE=16000000 +RCC.I2C1Freq_Value=16000000 +RCC.I2C2Freq_Value=16000000 +RCC.I2S1Freq_Value=16000000 +RCC.I2S2Freq_Value=16000000 +RCC.IPParameters=AHBFreq_Value,APBFreq_Value,APBTimFreq_Value,CECFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2S1Freq_Value,I2S2Freq_Value,LPTIM1Freq_Value,LPTIM2Freq_Value,LPUART1Freq_Value,LPUART2Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,MCO2PinFreq_Value,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PWRFreq_Value,SYSCLKFreq_VALUE,TIM15Freq_Value,TIM1Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value +RCC.LPTIM1Freq_Value=16000000 +RCC.LPTIM2Freq_Value=16000000 +RCC.LPUART1Freq_Value=16000000 +RCC.LPUART2Freq_Value=16000000 +RCC.LSCOPinFreq_Value=32000 +RCC.LSE_VALUE=32768 +RCC.LSI_VALUE=32000 +RCC.MCO1PinFreq_Value=16000000 +RCC.MCO2PinFreq_Value=16000000 +RCC.PLLPoutputFreq_Value=64000000 +RCC.PLLQoutputFreq_Value=64000000 +RCC.PLLRCLKFreq_Value=64000000 +RCC.PWRFreq_Value=16000000 +RCC.SYSCLKFreq_VALUE=16000000 +RCC.TIM15Freq_Value=16000000 +RCC.TIM1Freq_Value=16000000 +RCC.USART1Freq_Value=16000000 +RCC.USART2Freq_Value=16000000 +RCC.USART3Freq_Value=16000000 +RCC.USBFreq_Value=48000000 +RCC.VCOInputFreq_Value=16000000 +RCC.VCOOutputFreq_Value=128000000 +VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals +VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals +VP_SYS_VS_Systick.Mode=SysTick +VP_SYS_VS_Systick.Signal=SYS_VS_Systick +board=custom diff --git a/boards/motherboard/platformio.ini b/boards/motherboard/platformio.ini new file mode 100644 index 0000000..ca3159b --- /dev/null +++ b/boards/motherboard/platformio.ini @@ -0,0 +1,23 @@ +[platformio] +src_dir = . +include_dir = Inc + +[env:nucleo_g0b1re] +platform = ststm32 +board = nucleo_g0b1re + +board_build.mcu = stm32g0b1vet6 +board_build.f_cpu = 64000000L + +framework = stm32cube +build_src_filter = + + + + + + +build_flags = + -ICore/Inc + -Ilib + -DUSE_HAL_DRIVER + -DSTM32G0B1xx + -std=c++17 + -Wunused-function diff --git a/boards/motherboard/post_cubemx.sh b/boards/motherboard/post_cubemx.sh new file mode 100644 index 0000000..5ae627a --- /dev/null +++ b/boards/motherboard/post_cubemx.sh @@ -0,0 +1,11 @@ +echo "Removing unused CubeMX files" +rm -rfv Src/app_freertos.c +rm -rfv Inc/app_freertos.h + +IOC=$(find *.ioc) +echo "Sorting $IOC for better git diffs" +sort $IOC --version-sort --output=$IOC + +FILES_TO_FORMAT=$(find Inc Src -iname "*.h" -o -iname "*.c" -o -iname "*.cpp" -o -iname "*.hpp") +clang-format -i --verbose $FILES_TO_FORMAT +clang-format -i $FILES_TO_FORMAT # clang-format has some idempotency issues. run it twice diff --git a/boards/motherboard/src/gpio.c b/boards/motherboard/src/gpio.c new file mode 100644 index 0000000..148571f --- /dev/null +++ b/boards/motherboard/src/gpio.c @@ -0,0 +1,60 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file gpio.c + * @brief This file provides code for the configuration + * of all used GPIO pins. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "gpio.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/*----------------------------------------------------------------------------*/ +/* Configure GPIO */ +/*----------------------------------------------------------------------------*/ +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + +/** Configure pins +*/ +void MX_GPIO_Init(void) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOE_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(DEBUG_GPIO_Port, DEBUG_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pin : DEBUG_Pin */ + GPIO_InitStruct.Pin = DEBUG_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(DEBUG_GPIO_Port, &GPIO_InitStruct); + +} + +/* USER CODE BEGIN 2 */ + +/* USER CODE END 2 */ diff --git a/boards/motherboard/src/main.c b/boards/motherboard/src/main.c new file mode 100644 index 0000000..f45701f --- /dev/null +++ b/boards/motherboard/src/main.c @@ -0,0 +1,182 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : main.c + * @brief : Main program body + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "main.h" +#include "usb_drd_fs.h" +#include "gpio.h" + +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN PTD */ + +/* USER CODE END PTD */ + +/* Private define ------------------------------------------------------------*/ +/* USER CODE BEGIN PD */ + +/* USER CODE END PD */ + +/* Private macro -------------------------------------------------------------*/ +/* USER CODE BEGIN PM */ + +/* USER CODE END PM */ + +/* Private variables ---------------------------------------------------------*/ + +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +void SystemClock_Config(void); +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* Private user code ---------------------------------------------------------*/ +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/** + * @brief The application entry point. + * @retval int + */ +int main(void) +{ + + /* USER CODE BEGIN 1 */ + + /* USER CODE END 1 */ + + /* MCU Configuration--------------------------------------------------------*/ + + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); + + /* USER CODE BEGIN Init */ + + /* USER CODE END Init */ + + /* Configure the system clock */ + SystemClock_Config(); + + /* USER CODE BEGIN SysInit */ + + /* USER CODE END SysInit */ + + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_USB_DRD_FS_PCD_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 */ + HAL_GPIO_TogglePin(DEBUG_GPIO_Port, DEBUG_Pin); + HAL_Delay(500); + } + /* USER CODE END 3 */ +} + +/** + * @brief System Clock Configuration + * @retval None + */ +void SystemClock_Config(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + + /** Configure the main internal regulator output voltage + */ + HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); + + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI48; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; + RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; + RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) + { + Error_Handler(); + } + + /** Initializes the CPU, AHB and APB buses clocks + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK + |RCC_CLOCKTYPE_PCLK1; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) + { + Error_Handler(); + } +} + +/* USER CODE BEGIN 4 */ + +/* USER CODE END 4 */ + +/** + * @brief This function is executed in case of error occurrence. + * @retval None + */ +void Error_Handler(void) +{ + /* USER CODE BEGIN Error_Handler_Debug */ + /* User can add his own implementation to report the HAL error return state */ + __disable_irq(); + while (1) + { + } + /* USER CODE END Error_Handler_Debug */ +} +#ifdef USE_FULL_ASSERT +/** + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ +void assert_failed(uint8_t *file, uint32_t line) +{ + /* USER CODE BEGIN 6 */ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ + /* USER CODE END 6 */ +} +#endif /* USE_FULL_ASSERT */ diff --git a/boards/motherboard/src/stm32g0xx_hal_msp.c b/boards/motherboard/src/stm32g0xx_hal_msp.c new file mode 100644 index 0000000..da20304 --- /dev/null +++ b/boards/motherboard/src/stm32g0xx_hal_msp.c @@ -0,0 +1,85 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g0xx_hal_msp.c + * @brief This file provides code for the MSP Initialization + * and de-Initialization codes. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "main.h" +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN TD */ + +/* USER CODE END TD */ + +/* Private define ------------------------------------------------------------*/ +/* USER CODE BEGIN Define */ + +/* USER CODE END Define */ + +/* Private macro -------------------------------------------------------------*/ +/* USER CODE BEGIN Macro */ + +/* USER CODE END Macro */ + +/* Private variables ---------------------------------------------------------*/ +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* External functions --------------------------------------------------------*/ +/* USER CODE BEGIN ExternalFunctions */ + +/* USER CODE END ExternalFunctions */ + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ +/** + * Initializes the Global MSP. + */ +void HAL_MspInit(void) +{ + + /* USER CODE BEGIN MspInit 0 */ + + /* USER CODE END MspInit 0 */ + + __HAL_RCC_SYSCFG_CLK_ENABLE(); + __HAL_RCC_PWR_CLK_ENABLE(); + + /* System interrupt init*/ + + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD1_STROBE | SYSCFG_CFGR1_UCPD2_STROBE); + + /* USER CODE BEGIN MspInit 1 */ + + /* USER CODE END MspInit 1 */ +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/boards/motherboard/src/stm32g0xx_it.c b/boards/motherboard/src/stm32g0xx_it.c new file mode 100644 index 0000000..fa339fe --- /dev/null +++ b/boards/motherboard/src/stm32g0xx_it.c @@ -0,0 +1,145 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g0xx_it.c + * @brief Interrupt Service Routines. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" +#include "stm32g0xx_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-M0+ 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 System service call via SWI instruction. + */ +void SVC_Handler(void) +{ + /* USER CODE BEGIN SVC_IRQn 0 */ + + /* USER CODE END SVC_IRQn 0 */ + /* USER CODE BEGIN SVC_IRQn 1 */ + + /* USER CODE END SVC_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 */ +} + +/******************************************************************************/ +/* STM32G0xx 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_stm32g0xx.s). */ +/******************************************************************************/ + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/boards/motherboard/src/syscalls.c b/boards/motherboard/src/syscalls.c new file mode 100644 index 0000000..0197f26 --- /dev/null +++ b/boards/motherboard/src/syscalls.c @@ -0,0 +1,176 @@ +/** + ****************************************************************************** + * @file syscalls.c + * @author Auto-generated by STM32CubeIDE + * @brief STM32CubeIDE Minimal System calls file + * + * For more information about which c-functions + * need which of these lowlevel functions + * please consult the Newlib libc-manual + ****************************************************************************** + * @attention + * + * Copyright (c) 2020-2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* 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; +} + +int _times(struct tms *buf) +{ + (void)buf; + return -1; +} + +int _stat(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; +} diff --git a/boards/motherboard/src/sysmem.c b/boards/motherboard/src/sysmem.c new file mode 100644 index 0000000..23ea8e0 --- /dev/null +++ b/boards/motherboard/src/sysmem.c @@ -0,0 +1,79 @@ +/** + ****************************************************************************** + * @file sysmem.c + * @author Generated by STM32CubeIDE + * @brief STM32CubeIDE System Memory calls file + * + * For more information about which C functions + * need which of these lowlevel functions + * please consult the newlib libc manual + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ + +/* Includes */ +#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; +} diff --git a/boards/motherboard/src/system_stm32g0xx.c b/boards/motherboard/src/system_stm32g0xx.c new file mode 100644 index 0000000..92a7f28 --- /dev/null +++ b/boards/motherboard/src/system_stm32g0xx.c @@ -0,0 +1,304 @@ +/** + ****************************************************************************** + * @file system_stm32g0xx.c + * @author MCD Application Team + * @brief CMSIS Cortex-M0+ 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_stm32g0xx.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 (8 MHz then 16 MHz) is used as system clock source. + * Then SystemInit() function is called, in "startup_stm32g0xx.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 + *----------------------------------------------------------------------------- + * APB Prescaler | 1 + *----------------------------------------------------------------------------- + * HSI Division factor | 1 + *----------------------------------------------------------------------------- + * PLL_M | 1 + *----------------------------------------------------------------------------- + * PLL_N | 8 + *----------------------------------------------------------------------------- + * PLL_P | 7 + *----------------------------------------------------------------------------- + * PLL_Q | 2 + *----------------------------------------------------------------------------- + * PLL_R | 2 + *----------------------------------------------------------------------------- + * Require 48MHz for RNG | Disabled + *----------------------------------------------------------------------------- + *============================================================================= + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 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 stm32g0xx_system + * @{ + */ + +/** @addtogroup STM32G0xx_System_Private_Includes + * @{ + */ + +#include "stm32g0xx.h" + +#if !defined (HSE_VALUE) +#define HSE_VALUE (8000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSI_VALUE) + #define HSI_VALUE (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ + +#if !defined (LSI_VALUE) + #define LSI_VALUE (32000UL) /*!< Value of LSI in Hz*/ +#endif /* LSI_VALUE */ + +#if !defined (LSE_VALUE) + #define LSE_VALUE (32768UL) /*!< Value of LSE in Hz*/ +#endif /* LSE_VALUE */ + +/** + * @} + */ + +/** @addtogroup STM32G0xx_System_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @addtogroup STM32G0xx_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. */ +#else +#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field. + This value must be a multiple of 0x200. */ +#endif /* VECT_TAB_SRAM */ + +#if !defined(VECT_TAB_OFFSET) +#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table offset field. + This value must be a multiple of 0x200. */ +#endif /* VECT_TAB_OFFSET */ + +#endif /* USER_VECT_TAB_ADDRESS */ +/******************************************************************************/ +/** + * @} + */ + +/** @addtogroup STM32G0xx_System_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @addtogroup STM32G0xx_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 = 16000000UL; + + const uint32_t AHBPrescTable[16UL] = {0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL, 6UL, 7UL, 8UL, 9UL}; + const uint32_t APBPrescTable[8UL] = {0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL}; + +/** + * @} + */ + +/** @addtogroup STM32G0xx_System_Private_FunctionPrototypes + * @{ + */ + +/** + * @} + */ + +/** @addtogroup STM32G0xx_System_Private_Functions + * @{ + */ + +/** + * @brief Setup the microcontroller system. + * @param None + * @retval None + */ +void SystemInit(void) +{ + /* Configure the Vector Table location -------------------------------------*/ +#if defined(USER_VECT_TAB_ADDRESS) + SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation */ +#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(**) / HSI division factor + * + * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***) + * + * - If SYSCLK source is LSI, SystemCoreClock will contain the LSI_VALUE + * + * - If SYSCLK source is LSE, SystemCoreClock will contain the LSE_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 stm32g0xx_hal_conf.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 stm32g0xx_hal_conf.h file (default value + * 8 MHz), user has to ensure that HSE_VALUE is same as the real + * frequency of the crystal used. Otherwise, this function may + * have wrong result. + * + * - The result of this function could be not correct when using fractional + * value for HSE crystal. + * + * @param None + * @retval None + */ +void SystemCoreClockUpdate(void) +{ + uint32_t tmp; + uint32_t pllvco; + uint32_t pllr; + uint32_t pllsource; + uint32_t pllm; + uint32_t hsidiv; + + /* Get SYSCLK source -------------------------------------------------------*/ + switch (RCC->CFGR & RCC_CFGR_SWS) + { + case RCC_CFGR_SWS_0: /* HSE used as system clock */ + SystemCoreClock = HSE_VALUE; + break; + + case (RCC_CFGR_SWS_1 | RCC_CFGR_SWS_0): /* LSI used as system clock */ + SystemCoreClock = LSI_VALUE; + break; + + case RCC_CFGR_SWS_2: /* LSE used as system clock */ + SystemCoreClock = LSE_VALUE; + break; + + case RCC_CFGR_SWS_1: /* PLL used as system clock */ + /* 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) >> RCC_PLLCFGR_PLLM_Pos) + 1UL; + + if(pllsource == 0x03UL) /* HSE used as PLL clock source */ + { + pllvco = (HSE_VALUE / pllm); + } + else /* HSI used as PLL clock source */ + { + pllvco = (HSI_VALUE / pllm); + } + pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos); + pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> RCC_PLLCFGR_PLLR_Pos) + 1UL); + + SystemCoreClock = pllvco/pllr; + break; + + case 0x00000000U: /* HSI used as system clock */ + default: /* HSI used as system clock */ + hsidiv = (1UL << ((READ_BIT(RCC->CR, RCC_CR_HSIDIV))>> RCC_CR_HSIDIV_Pos)); + SystemCoreClock = (HSI_VALUE/hsidiv); + break; + } + /* Compute HCLK clock frequency --------------------------------------------*/ + /* Get HCLK prescaler */ + tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos)]; + /* HCLK clock frequency */ + SystemCoreClock >>= tmp; +} + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/boards/motherboard/src/usb_drd_fs.c b/boards/motherboard/src/usb_drd_fs.c new file mode 100644 index 0000000..6d12192 --- /dev/null +++ b/boards/motherboard/src/usb_drd_fs.c @@ -0,0 +1,121 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file usb_drd_fs.c + * @brief This file provides code for the configuration + * of the USB_DRD_FS instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "usb_drd_fs.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +PCD_HandleTypeDef hpcd_USB_DRD_FS; + +/* USB_DRD_FS init function */ + +void MX_USB_DRD_FS_PCD_Init(void) +{ + + /* USER CODE BEGIN USB_DRD_FS_Init 0 */ + + /* USER CODE END USB_DRD_FS_Init 0 */ + + /* USER CODE BEGIN USB_DRD_FS_Init 1 */ + + /* USER CODE END USB_DRD_FS_Init 1 */ + hpcd_USB_DRD_FS.Instance = USB_DRD_FS; + hpcd_USB_DRD_FS.Init.dev_endpoints = 8; + hpcd_USB_DRD_FS.Init.Host_channels = 8; + hpcd_USB_DRD_FS.Init.speed = PCD_SPEED_FULL; + hpcd_USB_DRD_FS.Init.phy_itface = PCD_PHY_EMBEDDED; + hpcd_USB_DRD_FS.Init.Sof_enable = DISABLE; + hpcd_USB_DRD_FS.Init.low_power_enable = DISABLE; + hpcd_USB_DRD_FS.Init.lpm_enable = DISABLE; + hpcd_USB_DRD_FS.Init.battery_charging_enable = DISABLE; + hpcd_USB_DRD_FS.Init.vbus_sensing_enable = DISABLE; + hpcd_USB_DRD_FS.Init.bulk_doublebuffer_enable = DISABLE; + hpcd_USB_DRD_FS.Init.iso_singlebuffer_enable = DISABLE; + if (HAL_PCD_Init(&hpcd_USB_DRD_FS) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN USB_DRD_FS_Init 2 */ + + /* USER CODE END USB_DRD_FS_Init 2 */ + +} + +void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) +{ + + RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; + if(pcdHandle->Instance==USB_DRD_FS) + { + /* USER CODE BEGIN USB_DRD_FS_MspInit 0 */ + + /* USER CODE END USB_DRD_FS_MspInit 0 */ + + /** Initializes the peripherals clocks + */ + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; + PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) + { + Error_Handler(); + } + + /* USB_DRD_FS clock enable */ + __HAL_RCC_USB_CLK_ENABLE(); + + /* Enable VDDUSB */ + if(__HAL_RCC_PWR_IS_CLK_DISABLED()) + { + __HAL_RCC_PWR_CLK_ENABLE(); + HAL_PWREx_EnableVddUSB(); + __HAL_RCC_PWR_CLK_DISABLE(); + } + else + { + HAL_PWREx_EnableVddUSB(); + } + /* USER CODE BEGIN USB_DRD_FS_MspInit 1 */ + + /* USER CODE END USB_DRD_FS_MspInit 1 */ + } +} + +void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) +{ + + if(pcdHandle->Instance==USB_DRD_FS) + { + /* USER CODE BEGIN USB_DRD_FS_MspDeInit 0 */ + + /* USER CODE END USB_DRD_FS_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USB_CLK_DISABLE(); + /* USER CODE BEGIN USB_DRD_FS_MspDeInit 1 */ + + /* USER CODE END USB_DRD_FS_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + From 7e23d47b60827a8038722089f4d7d4bfd7d40519 Mon Sep 17 00:00:00 2001 From: Ivan Lange Date: Thu, 26 Mar 2026 14:51:11 -0400 Subject: [PATCH 02/13] Add basic HSD debugging --- boards/motherboard/.gitignore | 2 ++ boards/motherboard/Inc/main.h | 12 +++++++++ boards/motherboard/motherboard.ioc | 42 +++++++++++++++++++++++++----- boards/motherboard/src/gpio.c | 19 +++++++++++--- boards/motherboard/src/main.c | 7 ++++- 5 files changed, 71 insertions(+), 11 deletions(-) diff --git a/boards/motherboard/.gitignore b/boards/motherboard/.gitignore index cb5a7d2..6378e5f 100644 --- a/boards/motherboard/.gitignore +++ b/boards/motherboard/.gitignore @@ -13,3 +13,5 @@ Middlewares/ .project .cproject .mxproject +.osx.project +.settings/ diff --git a/boards/motherboard/Inc/main.h b/boards/motherboard/Inc/main.h index 351e668..86d0dd0 100644 --- a/boards/motherboard/Inc/main.h +++ b/boards/motherboard/Inc/main.h @@ -57,8 +57,20 @@ void Error_Handler(void); /* USER CODE END EFP */ /* Private defines -----------------------------------------------------------*/ +#define P6V_SCATTER_PWR_EN_Pin GPIO_PIN_0 +#define P6V_SCATTER_PWR_EN_GPIO_Port GPIOF +#define P6V_SCATTER_HSD_DIAG_EN_Pin GPIO_PIN_1 +#define P6V_SCATTER_HSD_DIAG_EN_GPIO_Port GPIOF #define DEBUG_Pin GPIO_PIN_7 #define DEBUG_GPIO_Port GPIOE +#define VGA_PWR_EN_Pin GPIO_PIN_11 +#define VGA_PWR_EN_GPIO_Port GPIOF +#define VCO_PWR_EN_Pin GPIO_PIN_12 +#define VCO_PWR_EN_GPIO_Port GPIOF +#define GEN_EN_Pin GPIO_PIN_0 +#define GEN_EN_GPIO_Port GPIOE +#define LPA_PWR_EN_Pin GPIO_PIN_1 +#define LPA_PWR_EN_GPIO_Port GPIOE /* USER CODE BEGIN Private defines */ diff --git a/boards/motherboard/motherboard.ioc b/boards/motherboard/motherboard.ioc index 14adc95..923c86e 100644 --- a/boards/motherboard/motherboard.ioc +++ b/boards/motherboard/motherboard.ioc @@ -14,12 +14,18 @@ Mcu.IP3=USB_DRD_FS Mcu.IPNb=4 Mcu.Name=STM32G0B1V(B-C-E)Tx Mcu.Package=LQFP100 -Mcu.Pin0=PE7 -Mcu.Pin1=PA11 [PA9] -Mcu.Pin2=PA12 [PA10] -Mcu.Pin3=VP_SYS_VS_Systick -Mcu.Pin4=VP_SYS_VS_DBSignals -Mcu.PinsNb=5 +Mcu.Pin0=PF0-OSC_IN (PF0) +Mcu.Pin1=PF1-OSC_OUT (PF1) +Mcu.Pin10=VP_SYS_VS_DBSignals +Mcu.Pin2=PE7 +Mcu.Pin3=PA11 [PA9] +Mcu.Pin4=PA12 [PA10] +Mcu.Pin5=PF11 +Mcu.Pin6=PF12 +Mcu.Pin7=PE0 +Mcu.Pin8=PE1 +Mcu.Pin9=VP_SYS_VS_Systick +Mcu.PinsNb=11 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32G0B1VETx @@ -35,10 +41,34 @@ PA11\ [PA9].Mode=Device PA11\ [PA9].Signal=USB_DM PA12\ [PA10].Mode=Device PA12\ [PA10].Signal=USB_DP +PE0.GPIOParameters=GPIO_Label +PE0.GPIO_Label=GEN_EN +PE0.Locked=true +PE0.Signal=GPIO_Output +PE1.GPIOParameters=GPIO_Label +PE1.GPIO_Label=LPA_PWR_EN +PE1.Locked=true +PE1.Signal=GPIO_Output PE7.GPIOParameters=GPIO_Label PE7.GPIO_Label=DEBUG PE7.Locked=true PE7.Signal=GPIO_Output +PF0-OSC_IN\ (PF0).GPIOParameters=GPIO_Label +PF0-OSC_IN\ (PF0).GPIO_Label=P6V_SCATTER_PWR_EN +PF0-OSC_IN\ (PF0).Locked=true +PF0-OSC_IN\ (PF0).Signal=GPIO_Output +PF1-OSC_OUT\ (PF1).GPIOParameters=GPIO_Label +PF1-OSC_OUT\ (PF1).GPIO_Label=P6V_SCATTER_HSD_DIAG_EN +PF1-OSC_OUT\ (PF1).Locked=true +PF1-OSC_OUT\ (PF1).Signal=GPIO_Output +PF11.GPIOParameters=GPIO_Label +PF11.GPIO_Label=VGA_PWR_EN +PF11.Locked=true +PF11.Signal=GPIO_Output +PF12.GPIOParameters=GPIO_Label +PF12.GPIO_Label=VCO_PWR_EN +PF12.Locked=true +PF12.Signal=GPIO_Output PinOutPanel.RotationAngle=0 ProjectManager.AskForMigrate=true ProjectManager.BackupPrevious=false diff --git a/boards/motherboard/src/gpio.c b/boards/motherboard/src/gpio.c index 148571f..7e92ad3 100644 --- a/boards/motherboard/src/gpio.c +++ b/boards/motherboard/src/gpio.c @@ -40,18 +40,29 @@ void MX_GPIO_Init(void) GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOE_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(DEBUG_GPIO_Port, DEBUG_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOF, P6V_SCATTER_PWR_EN_Pin|P6V_SCATTER_HSD_DIAG_EN_Pin|VGA_PWR_EN_Pin|VCO_PWR_EN_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin : DEBUG_Pin */ - GPIO_InitStruct.Pin = DEBUG_Pin; + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOE, DEBUG_Pin|GEN_EN_Pin|LPA_PWR_EN_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pins : P6V_SCATTER_PWR_EN_Pin P6V_SCATTER_HSD_DIAG_EN_Pin VGA_PWR_EN_Pin VCO_PWR_EN_Pin */ + GPIO_InitStruct.Pin = P6V_SCATTER_PWR_EN_Pin|P6V_SCATTER_HSD_DIAG_EN_Pin|VGA_PWR_EN_Pin|VCO_PWR_EN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /*Configure GPIO pins : DEBUG_Pin GEN_EN_Pin LPA_PWR_EN_Pin */ + GPIO_InitStruct.Pin = DEBUG_Pin|GEN_EN_Pin|LPA_PWR_EN_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(DEBUG_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); } diff --git a/boards/motherboard/src/main.c b/boards/motherboard/src/main.c index f45701f..20e986f 100644 --- a/boards/motherboard/src/main.c +++ b/boards/motherboard/src/main.c @@ -89,7 +89,12 @@ int main(void) MX_GPIO_Init(); MX_USB_DRD_FS_PCD_Init(); /* USER CODE BEGIN 2 */ - + HAL_GPIO_WritePin(VCO_PWR_EN_GPIO_Port, VCO_PWR_EN_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(VGA_PWR_EN_GPIO_Port, VGA_PWR_EN_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(LPA_PWR_EN_GPIO_Port, LPA_PWR_EN_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GEN_EN_GPIO_Port, GEN_EN_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(P6V_SCATTER_PWR_EN_GPIO_Port, P6V_SCATTER_PWR_EN_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(P6V_SCATTER_HSD_DIAG_EN_GPIO_Port, P6V_SCATTER_HSD_DIAG_EN_Pin, GPIO_PIN_RESET); /* USER CODE END 2 */ /* Infinite loop */ From 16ae79dd29e0ec37b20a233d84043215c8ffa1a9 Mon Sep 17 00:00:00 2001 From: Ivan Lange Date: Mon, 30 Mar 2026 12:05:33 -0400 Subject: [PATCH 03/13] Setup freertos --- boards/motherboard/Inc/FreeRTOSConfig.h | 125 +++++ boards/motherboard/Inc/gpio.h | 33 +- boards/motherboard/Inc/main.h | 32 +- boards/motherboard/Inc/stm32g0xx_hal_conf.h | 271 +++++----- boards/motherboard/Inc/stm32g0xx_it.h | 34 +- boards/motherboard/Inc/tasks.hpp | 11 + boards/motherboard/Inc/usb_drd_fs.h | 33 +- boards/motherboard/motherboard.ioc | 54 +- boards/motherboard/platformio.ini | 9 +- boards/motherboard/post_cubemx.sh | 0 boards/motherboard/src/gpio.c | 87 ++-- boards/motherboard/src/main.c | 259 +++++----- boards/motherboard/src/stm32g0xx_hal_msp.c | 63 +-- .../src/stm32g0xx_hal_timebase_tim.c | 126 +++++ boards/motherboard/src/stm32g0xx_it.c | 134 ++--- boards/motherboard/src/syscalls.c | 186 +++---- boards/motherboard/src/sysmem.c | 44 +- boards/motherboard/src/system_stm32g0xx.c | 484 +++++++++--------- boards/motherboard/src/tasks.cpp | 53 ++ boards/motherboard/src/usb_drd_fs.c | 173 +++---- 20 files changed, 1266 insertions(+), 945 deletions(-) create mode 100644 boards/motherboard/Inc/FreeRTOSConfig.h create mode 100644 boards/motherboard/Inc/tasks.hpp mode change 100644 => 100755 boards/motherboard/post_cubemx.sh create mode 100644 boards/motherboard/src/stm32g0xx_hal_timebase_tim.c create mode 100644 boards/motherboard/src/tasks.cpp diff --git a/boards/motherboard/Inc/FreeRTOSConfig.h b/boards/motherboard/Inc/FreeRTOSConfig.h new file mode 100644 index 0000000..d9bfc99 --- /dev/null +++ b/boards/motherboard/Inc/FreeRTOSConfig.h @@ -0,0 +1,125 @@ +/* USER CODE BEGIN Header */ +/* + * FreeRTOS Kernel V10.3.1 + * Portion Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights + * Reserved. Portion Copyright (C) 2019 StMicroelectronics, Inc. All Rights + * Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ +/* USER CODE END Header */ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * These parameters and more are described within the 'configuration' section of + * the FreeRTOS API documentation available on the FreeRTOS.org web site. + * + * See http://www.freertos.org/a00110.html + *----------------------------------------------------------*/ + +/* USER CODE BEGIN Includes */ +/* Section where include file can be added */ +/* USER CODE END Includes */ + +/* Ensure definitions are only used by the compiler, and not by the assembler. + */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) +#include +extern uint32_t SystemCoreClock; +#endif +#define configENABLE_FPU 0 +#define configENABLE_MPU 0 + +#define configUSE_PREEMPTION 1 +#define configSUPPORT_STATIC_ALLOCATION 1 +#define configSUPPORT_DYNAMIC_ALLOCATION 0 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ (SystemCoreClock) +#define configTICK_RATE_HZ ((TickType_t)1000) +#define configMAX_PRIORITIES (7) +#define configMINIMAL_STACK_SIZE ((uint16_t)128) +#define configMAX_TASK_NAME_LEN (16) +#define configUSE_16_BIT_TICKS 0 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 +/* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */ +/* Defaults to size_t for backward compatibility, but can be changed + if lengths will always be less than the number of bytes in a size_t. */ +#define configMESSAGE_BUFFER_LENGTH_TYPE size_t +/* USER CODE END MESSAGE_BUFFER_LENGTH_TYPE */ + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES (2) + +/* The following flag must be enabled only when using newlib */ +#define configUSE_NEWLIB_REENTRANT 1 + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 + +/* Normal assert() semantics without relying on the provision of an assert.h +header file. */ +/* USER CODE BEGIN 1 */ +#define configASSERT(x) \ + if ((x) == 0) { \ + taskDISABLE_INTERRUPTS(); \ + for (;;); \ + } +/* USER CODE END 1 */ + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS +standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler + +/* IMPORTANT: This define is commented when used with STM32Cube firmware, when + the timebase source is SysTick, to prevent overwriting SysTick_Handler + defined within STM32Cube HAL */ + +#define xPortSysTickHandler SysTick_Handler + +/* USER CODE BEGIN Defines */ +/* Section where parameter definitions can be added (for instance, to override + * default ones in FreeRTOS.h) */ +/* USER CODE END Defines */ + +#endif /* FREERTOS_CONFIG_H */ diff --git a/boards/motherboard/Inc/gpio.h b/boards/motherboard/Inc/gpio.h index 1204b1d..907d2a4 100644 --- a/boards/motherboard/Inc/gpio.h +++ b/boards/motherboard/Inc/gpio.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file gpio.h - * @brief This file contains all the function prototypes for - * the gpio.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file gpio.h + * @brief This file contains all the function prototypes for + * the gpio.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __GPIO_H__ @@ -46,4 +46,3 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ - diff --git a/boards/motherboard/Inc/main.h b/boards/motherboard/Inc/main.h index 86d0dd0..c59c473 100644 --- a/boards/motherboard/Inc/main.h +++ b/boards/motherboard/Inc/main.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file : main.h - * @brief : Header for main.c file. - * This file contains the common defines of the application. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file : main.h + * @brief : Header for main.c file. + * This file contains the common defines of the application. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ diff --git a/boards/motherboard/Inc/stm32g0xx_hal_conf.h b/boards/motherboard/Inc/stm32g0xx_hal_conf.h index 448c212..bcb078a 100644 --- a/boards/motherboard/Inc/stm32g0xx_hal_conf.h +++ b/boards/motherboard/Inc/stm32g0xx_hal_conf.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file stm32g0xx_hal_conf.h - * @author MCD Application Team - * @brief HAL configuration file. - ****************************************************************************** - * @attention - * - * Copyright (c) 2018 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 stm32g0xx_hal_conf.h + * @author MCD Application Team + * @brief HAL configuration file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2018 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 -------------------------------------*/ @@ -31,8 +31,8 @@ extern "C" { /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED /* #define HAL_ADC_MODULE_ENABLED */ /* #define HAL_CEC_MODULE_ENABLED */ @@ -54,7 +54,7 @@ extern "C" { /* #define HAL_SMARTCARD_MODULE_ENABLED */ /* #define HAL_SMBUS_MODULE_ENABLED */ /* #define HAL_SPI_MODULE_ENABLED */ -/* #define HAL_TIM_MODULE_ENABLED */ +#define HAL_TIM_MODULE_ENABLED /* #define HAL_UART_MODULE_ENABLED */ /* #define HAL_USART_MODULE_ENABLED */ /* #define HAL_WWDG_MODULE_ENABLED */ @@ -66,106 +66,115 @@ extern "C" { #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_CEC_REGISTER_CALLBACKS 0u -#define USE_HAL_COMP_REGISTER_CALLBACKS 0u -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0u -#define USE_HAL_DAC_REGISTER_CALLBACKS 0u -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0u -#define USE_HAL_HCD_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_PCD_REGISTER_CALLBACKS 0u -#define USE_HAL_RNG_REGISTER_CALLBACKS 0u -#define USE_HAL_RTC_REGISTER_CALLBACKS 0u -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0u -#define USE_HAL_SPI_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_CEC_REGISTER_CALLBACKS 0u +#define USE_HAL_COMP_REGISTER_CALLBACKS 0u +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0u +#define USE_HAL_DAC_REGISTER_CALLBACKS 0u +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0u +#define USE_HAL_HCD_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_PCD_REGISTER_CALLBACKS 0u +#define USE_HAL_RNG_REGISTER_CALLBACKS 0u +#define USE_HAL_RTC_REGISTER_CALLBACKS 0u +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0u +#define USE_HAL_SPI_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 (8000000UL) /*!< 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 (8000000UL) /*!< 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 */ #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx) /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS, SDMMC 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 48000000U /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/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, SDMMC 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 \ + 48000000U /*!< Value of the Internal High Speed oscillator for USB \ + FS/SDMMC/RNG in Hz. The real value my vary depending on \ + manufacturing process variations.*/ +#endif /* HSI48_VALUE */ #endif /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz -The real value may vary depending on the variations + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined(LSI_VALUE) +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz \ +The real value may vary depending on the variations \ in voltage and temperature.*/ /** - * @brief External Low Speed oscillator (LSE) value. - * 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 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 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 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 I2S1 peripheral - * This value is used by the RCC HAL module to compute the I2S1 clock source - * frequency. - */ -#if !defined (EXTERNAL_I2S1_CLOCK_VALUE) -#define EXTERNAL_I2S1_CLOCK_VALUE (48000UL) /*!< Value of the I2S1 External clock source in Hz*/ -#endif /* EXTERNAL_I2S1_CLOCK_VALUE */ + * @brief External clock source for I2S1 peripheral + * This value is used by the RCC HAL module to compute the I2S1 clock + * source frequency. + */ +#if !defined(EXTERNAL_I2S1_CLOCK_VALUE) +#define EXTERNAL_I2S1_CLOCK_VALUE \ + (48000UL) /*!< Value of the I2S1 External clock source in Hz*/ +#endif /* EXTERNAL_I2S1_CLOCK_VALUE */ #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx) /** - * @brief External clock source for I2S2 peripheral - * This value is used by the RCC HAL module to compute the I2S2 clock source - * frequency. - */ -#if !defined (EXTERNAL_I2S2_CLOCK_VALUE) - #define EXTERNAL_I2S2_CLOCK_VALUE 48000U /*!< Value of the I2S2 External clock source in Hz*/ -#endif /* EXTERNAL_I2S2_CLOCK_VALUE */ + * @brief External clock source for I2S2 peripheral + * This value is used by the RCC HAL module to compute the I2S2 clock + * source frequency. + */ +#if !defined(EXTERNAL_I2S2_CLOCK_VALUE) +#define EXTERNAL_I2S2_CLOCK_VALUE \ + 48000U /*!< Value of the I2S2 External clock source in Hz*/ +#endif /* EXTERNAL_I2S2_CLOCK_VALUE */ #endif /* Tip: To avoid modifying this file each time you need to use different HSE, @@ -173,38 +182,39 @@ in voltage and temperature.*/ /* ########################### System Configuration ######################### */ /** - * @brief This is the HAL system configuration section - */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY 3U /*!< tick interrupt priority */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 1U -#define INSTRUCTION_CACHE_ENABLE 1U + * @brief This is the HAL system configuration section + */ +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY 3U /*!< tick interrupt priority */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 1U +#define INSTRUCTION_CACHE_ENABLE 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 -*/ + * Activated: CRC code is present inside driver + * Deactivated: CRC code cleaned from driver + */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U -/* ################## CRYP peripheral configuration ########################## */ +/* ################## CRYP peripheral configuration ########################## + */ -#define USE_HAL_CRYP_SUSPEND_RESUME 1U +#define USE_HAL_CRYP_SUSPEND_RESUME 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 */ /* Includes ------------------------------------------------------------------*/ /** - * @brief Include modules header file - */ + * @brief Include modules header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g0xx_hal_rcc.h" @@ -328,18 +338,19 @@ 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 functions 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 functions 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); +void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ diff --git a/boards/motherboard/Inc/stm32g0xx_it.h b/boards/motherboard/Inc/stm32g0xx_it.h index 9fcd05f..3833c29 100644 --- a/boards/motherboard/Inc/stm32g0xx_it.h +++ b/boards/motherboard/Inc/stm32g0xx_it.h @@ -1,20 +1,20 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file stm32g0xx_it.h - * @brief This file contains the headers of the interrupt handlers. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file stm32g0xx_it.h + * @brief This file contains the headers of the interrupt handlers. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ @@ -48,9 +48,7 @@ extern "C" { /* Exported functions prototypes ---------------------------------------------*/ void NMI_Handler(void); void HardFault_Handler(void); -void SVC_Handler(void); -void PendSV_Handler(void); -void SysTick_Handler(void); +void TIM1_BRK_UP_TRG_COM_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/boards/motherboard/Inc/tasks.hpp b/boards/motherboard/Inc/tasks.hpp new file mode 100644 index 0000000..079054e --- /dev/null +++ b/boards/motherboard/Inc/tasks.hpp @@ -0,0 +1,11 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +void MX_FREERTOS_Init(void); + +#ifdef __cplusplus +} +#endif diff --git a/boards/motherboard/Inc/usb_drd_fs.h b/boards/motherboard/Inc/usb_drd_fs.h index 140ccb6..935b255 100644 --- a/boards/motherboard/Inc/usb_drd_fs.h +++ b/boards/motherboard/Inc/usb_drd_fs.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file usb_drd_fs.h - * @brief This file contains all the function prototypes for - * the usb_drd_fs.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file usb_drd_fs.h + * @brief This file contains all the function prototypes for + * the usb_drd_fs.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USB_DRD_FS_H__ @@ -49,4 +49,3 @@ void MX_USB_DRD_FS_PCD_Init(void); #endif #endif /* __USB_DRD_FS_H__ */ - diff --git a/boards/motherboard/motherboard.ioc b/boards/motherboard/motherboard.ioc index 923c86e..31a9ece 100644 --- a/boards/motherboard/motherboard.ioc +++ b/boards/motherboard/motherboard.ioc @@ -1,22 +1,28 @@ -#MicroXplorer Configuration settings - do not modify CAD.formats= CAD.pinconfig= CAD.provider= +FREERTOS.Events01= +FREERTOS.FootprintOK=true +FREERTOS.INCLUDE_vTaskDelayUntil=1 +FREERTOS.IPParameters=Tasks01,INCLUDE_vTaskDelayUntil,MEMORY_ALLOCATION,FootprintOK,configUSE_NEWLIB_REENTRANT,Events01 +FREERTOS.MEMORY_ALLOCATION=1 +FREERTOS.Tasks01=defaultTask,0,128,StartDefaultTask,Default,NULL,Static,defaultTaskBuffer,defaultTaskControlBlock +FREERTOS.configUSE_NEWLIB_REENTRANT=1 File.Version=6 GPIO.groupedBy= KeepUserPlacement=false Mcu.CPN=STM32G0B1VET6 Mcu.Family=STM32G0 -Mcu.IP0=NVIC -Mcu.IP1=RCC -Mcu.IP2=SYS -Mcu.IP3=USB_DRD_FS -Mcu.IPNb=4 +Mcu.IP0=FREERTOS +Mcu.IP1=NVIC +Mcu.IP2=RCC +Mcu.IP3=SYS +Mcu.IP4=USB_DRD_FS +Mcu.IPNb=5 Mcu.Name=STM32G0B1V(B-C-E)Tx Mcu.Package=LQFP100 Mcu.Pin0=PF0-OSC_IN (PF0) Mcu.Pin1=PF1-OSC_OUT (PF1) -Mcu.Pin10=VP_SYS_VS_DBSignals Mcu.Pin2=PE7 Mcu.Pin3=PA11 [PA9] Mcu.Pin4=PA12 [PA10] @@ -24,19 +30,27 @@ Mcu.Pin5=PF11 Mcu.Pin6=PF12 Mcu.Pin7=PE0 Mcu.Pin8=PE1 -Mcu.Pin9=VP_SYS_VS_Systick -Mcu.PinsNb=11 +Mcu.Pin9=VP_FREERTOS_VS_CMSIS_V1 +Mcu.Pin10=VP_SYS_VS_tim1 +Mcu.Pin11=VP_SYS_VS_DBSignals +Mcu.PinsNb=12 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32G0B1VETx MxCube.Version=6.17.0 MxDb.Version=DB.6.0.170 NVIC.ForceEnableDMAVector=true -NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false -NVIC.SVC_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true -NVIC.SysTick_IRQn=true\:3\:0\:false\:false\:true\:false\:true\:false +NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false +NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false +NVIC.PendSV_IRQn=true\:3\:0\:false\:false\:false\:true\:false\:false\:false +NVIC.SVC_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false\:true +NVIC.SavedPendsvIrqHandlerGenerated=true +NVIC.SavedSvcallIrqHandlerGenerated=true +NVIC.SavedSystickIrqHandlerGenerated=true +NVIC.SysTick_IRQn=true\:3\:0\:false\:false\:false\:true\:false\:true\:false +NVIC.TIM1_BRK_UP_TRG_COM_IRQn=true\:3\:0\:false\:false\:true\:false\:false\:true\:true +NVIC.TimeBaseIP=TIM1 +NVIC.TimeBase=TIM1_BRK_UP_TRG_COM_IRQn PA11\ [PA9].Mode=Device PA11\ [PA9].Signal=USB_DM PA12\ [PA10].Mode=Device @@ -81,8 +95,8 @@ ProjectManager.DefaultFWLocation=true ProjectManager.DeletePrevious=true ProjectManager.DeviceId=STM32G0B1VETx ProjectManager.FirmwarePackage=STM32Cube FW_G0 V1.6.3 -ProjectManager.FreePins=false ProjectManager.FreePinsContext= +ProjectManager.FreePins=false ProjectManager.HalAssertFull=false ProjectManager.HeapSize=0x200 ProjectManager.KeepUserCode=true @@ -135,16 +149,20 @@ RCC.PLLQoutputFreq_Value=64000000 RCC.PLLRCLKFreq_Value=64000000 RCC.PWRFreq_Value=16000000 RCC.SYSCLKFreq_VALUE=16000000 -RCC.TIM15Freq_Value=16000000 RCC.TIM1Freq_Value=16000000 +RCC.TIM15Freq_Value=16000000 RCC.USART1Freq_Value=16000000 RCC.USART2Freq_Value=16000000 RCC.USART3Freq_Value=16000000 RCC.USBFreq_Value=48000000 RCC.VCOInputFreq_Value=16000000 RCC.VCOOutputFreq_Value=128000000 +VP_FREERTOS_VS_CMSIS_V1.Mode=CMSIS_V1 +VP_FREERTOS_VS_CMSIS_V1.Signal=FREERTOS_VS_CMSIS_V1 VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick +VP_SYS_VS_tim1.Mode=TIM1 +VP_SYS_VS_tim1.Signal=SYS_VS_tim1 board=custom +rtos.0.ip=FREERTOS +#MicroXplorer Configuration settings - do not modify diff --git a/boards/motherboard/platformio.ini b/boards/motherboard/platformio.ini index ca3159b..e309d7e 100644 --- a/boards/motherboard/platformio.ini +++ b/boards/motherboard/platformio.ini @@ -14,10 +14,17 @@ build_src_filter = + + + + # FreeRTOS + + + build_flags = - -ICore/Inc + -IInc -Ilib -DUSE_HAL_DRIVER -DSTM32G0B1xx -std=c++17 -Wunused-function + # FreeRTOS + -I Middlewares/Third_Party/FreeRTOS/Source/include + -I Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM0 + -I Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS diff --git a/boards/motherboard/post_cubemx.sh b/boards/motherboard/post_cubemx.sh old mode 100644 new mode 100755 diff --git a/boards/motherboard/src/gpio.c b/boards/motherboard/src/gpio.c index 7e92ad3..64ce0af 100644 --- a/boards/motherboard/src/gpio.c +++ b/boards/motherboard/src/gpio.c @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file gpio.c - * @brief This file provides code for the configuration - * of all used GPIO pins. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file gpio.c + * @brief This file provides code for the configuration + * of all used GPIO pins. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ @@ -33,37 +33,40 @@ /* USER CODE END 1 */ /** Configure pins -*/ -void MX_GPIO_Init(void) -{ + */ +void MX_GPIO_Init(void) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; - GPIO_InitTypeDef GPIO_InitStruct = {0}; + /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOF_CLK_ENABLE(); + __HAL_RCC_GPIOE_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOF_CLK_ENABLE(); - __HAL_RCC_GPIOE_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOF, + P6V_SCATTER_PWR_EN_Pin | P6V_SCATTER_HSD_DIAG_EN_Pin | + VGA_PWR_EN_Pin | VCO_PWR_EN_Pin, + GPIO_PIN_RESET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOF, P6V_SCATTER_PWR_EN_Pin|P6V_SCATTER_HSD_DIAG_EN_Pin|VGA_PWR_EN_Pin|VCO_PWR_EN_Pin, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOE, DEBUG_Pin | GEN_EN_Pin | LPA_PWR_EN_Pin, + GPIO_PIN_RESET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOE, DEBUG_Pin|GEN_EN_Pin|LPA_PWR_EN_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pins : P6V_SCATTER_PWR_EN_Pin P6V_SCATTER_HSD_DIAG_EN_Pin VGA_PWR_EN_Pin VCO_PWR_EN_Pin */ - GPIO_InitStruct.Pin = P6V_SCATTER_PWR_EN_Pin|P6V_SCATTER_HSD_DIAG_EN_Pin|VGA_PWR_EN_Pin|VCO_PWR_EN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /*Configure GPIO pins : DEBUG_Pin GEN_EN_Pin LPA_PWR_EN_Pin */ - GPIO_InitStruct.Pin = DEBUG_Pin|GEN_EN_Pin|LPA_PWR_EN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); + /*Configure GPIO pins : P6V_SCATTER_PWR_EN_Pin P6V_SCATTER_HSD_DIAG_EN_Pin + * VGA_PWR_EN_Pin VCO_PWR_EN_Pin */ + GPIO_InitStruct.Pin = P6V_SCATTER_PWR_EN_Pin | P6V_SCATTER_HSD_DIAG_EN_Pin | + VGA_PWR_EN_Pin | VCO_PWR_EN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); + /*Configure GPIO pins : DEBUG_Pin GEN_EN_Pin LPA_PWR_EN_Pin */ + GPIO_InitStruct.Pin = DEBUG_Pin | GEN_EN_Pin | LPA_PWR_EN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); } /* USER CODE BEGIN 2 */ diff --git a/boards/motherboard/src/main.c b/boards/motherboard/src/main.c index 20e986f..04883ed 100644 --- a/boards/motherboard/src/main.c +++ b/boards/motherboard/src/main.c @@ -1,29 +1,31 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file : main.c + * @brief : Main program body + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" -#include "usb_drd_fs.h" + +#include "cmsis_os.h" #include "gpio.h" +#include "usb_drd_fs.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ - +#include "tasks.hpp" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -49,6 +51,7 @@ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); +void MX_FREERTOS_Init(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ @@ -59,96 +62,101 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ + * @brief The application entry point. + * @retval int + */ +int main(void) { + /* USER CODE BEGIN 1 */ + + /* USER CODE END 1 */ - /* USER CODE BEGIN 1 */ + /* MCU + * Configuration--------------------------------------------------------*/ - /* USER CODE END 1 */ + /* Reset of all peripherals, Initializes the Flash interface and the + * Systick. */ + HAL_Init(); - /* MCU Configuration--------------------------------------------------------*/ + /* USER CODE BEGIN Init */ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* USER CODE END Init */ - /* USER CODE BEGIN Init */ + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE END Init */ + /* USER CODE BEGIN SysInit */ - /* Configure the system clock */ - SystemClock_Config(); + /* USER CODE END SysInit */ - /* USER CODE BEGIN SysInit */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_USB_DRD_FS_PCD_Init(); + /* USER CODE BEGIN 2 */ + // HAL_GPIO_WritePin(VCO_PWR_EN_GPIO_Port, VCO_PWR_EN_Pin, GPIO_PIN_RESET); + // HAL_GPIO_WritePin(VGA_PWR_EN_GPIO_Port, VGA_PWR_EN_Pin, GPIO_PIN_RESET); + // HAL_GPIO_WritePin(LPA_PWR_EN_GPIO_Port, LPA_PWR_EN_Pin, GPIO_PIN_RESET); + // HAL_GPIO_WritePin(GEN_EN_GPIO_Port, GEN_EN_Pin, GPIO_PIN_RESET); + // HAL_GPIO_WritePin(P6V_SCATTER_PWR_EN_GPIO_Port, P6V_SCATTER_PWR_EN_Pin, + // GPIO_PIN_SET); + // HAL_GPIO_WritePin(P6V_SCATTER_HSD_DIAG_EN_GPIO_Port, + // P6V_SCATTER_HSD_DIAG_EN_Pin, GPIO_PIN_RESET); + /* USER CODE END 2 */ - /* USER CODE END SysInit */ + /* Call init function for freertos objects (in cmsis_os2.c) */ + MX_FREERTOS_Init(); - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_USB_DRD_FS_PCD_Init(); - /* USER CODE BEGIN 2 */ - HAL_GPIO_WritePin(VCO_PWR_EN_GPIO_Port, VCO_PWR_EN_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(VGA_PWR_EN_GPIO_Port, VGA_PWR_EN_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(LPA_PWR_EN_GPIO_Port, LPA_PWR_EN_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(GEN_EN_GPIO_Port, GEN_EN_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(P6V_SCATTER_PWR_EN_GPIO_Port, P6V_SCATTER_PWR_EN_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(P6V_SCATTER_HSD_DIAG_EN_GPIO_Port, P6V_SCATTER_HSD_DIAG_EN_Pin, GPIO_PIN_RESET); - /* USER CODE END 2 */ + /* Start scheduler */ + osKernelStart(); - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) - { - /* USER CODE END WHILE */ + /* We should never get here as control is now taken by the scheduler */ - /* USER CODE BEGIN 3 */ - HAL_GPIO_TogglePin(DEBUG_GPIO_Port, DEBUG_Pin); - HAL_Delay(500); - } - /* USER CODE END 3 */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ + while (1) { + /* USER CODE END WHILE */ + + /* USER CODE BEGIN 3 */ + } + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ -void SystemClock_Config(void) -{ - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - - /** Configure the main internal regulator output voltage - */ - HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); - - /** Initializes the RCC Oscillators according to the specified parameters - * in the RCC_OscInitTypeDef structure. - */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI48; - RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; - RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; - RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) - { - Error_Handler(); - } - - /** Initializes the CPU, AHB and APB buses clocks - */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK - |RCC_CLOCKTYPE_PCLK1; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; - - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) - { - Error_Handler(); - } + * @brief System Clock Configuration + * @retval None + */ +void SystemClock_Config(void) { + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + + /** Configure the main internal regulator output voltage + */ + HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); + + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = + RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSI48; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; + RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; + RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { + Error_Handler(); + } + + /** Initializes the CPU, AHB and APB buses clocks + */ + RCC_ClkInitStruct.ClockType = + RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -156,32 +164,51 @@ void SystemClock_Config(void) /* 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 */ + * @brief Period elapsed callback in non blocking mode + * @note This function is called when TIM1 interrupt took place, inside + * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment + * a global variable "uwTick" used as application time base. + * @param htim : TIM handle + * @retval None + */ +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim) { + /* USER CODE BEGIN Callback 0 */ + + /* USER CODE END Callback 0 */ + if (htim->Instance == TIM1) { + HAL_IncTick(); + } + /* USER CODE BEGIN Callback 1 */ + + /* USER CODE END Callback 1 */ +} + +/** + * @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 */ + * @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/boards/motherboard/src/stm32g0xx_hal_msp.c b/boards/motherboard/src/stm32g0xx_hal_msp.c index da20304..8718647 100644 --- a/boards/motherboard/src/stm32g0xx_hal_msp.c +++ b/boards/motherboard/src/stm32g0xx_hal_msp.c @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file stm32g0xx_hal_msp.c - * @brief This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file stm32g0xx_hal_msp.c + * @brief This file provides code for the MSP Initialization + * and de-Initialization codes. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" @@ -57,27 +57,28 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ -void HAL_MspInit(void) -{ + * 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*/ + /* PendSV_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(PendSV_IRQn, 3, 0); - /* System interrupt init*/ + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD1_STROBE | + SYSCFG_CFGR1_UCPD2_STROBE); - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD1_STROBE | SYSCFG_CFGR1_UCPD2_STROBE); + /* 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/boards/motherboard/src/stm32g0xx_hal_timebase_tim.c b/boards/motherboard/src/stm32g0xx_hal_timebase_tim.c new file mode 100644 index 0000000..10b4a05 --- /dev/null +++ b/boards/motherboard/src/stm32g0xx_hal_timebase_tim.c @@ -0,0 +1,126 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file stm32g0xx_hal_timebase_tim.c + * @brief HAL time base based on the hardware TIM. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32g0xx_hal.h" +#include "stm32g0xx_hal_tim.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +TIM_HandleTypeDef htim1; +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief This function configures the TIM1 as a time base source. + * The time source is configured to have 1ms time base with a dedicated + * Tick interrupt priority. + * @note This function is called automatically at the beginning of program + * after reset by HAL_Init() or at any time when clock is configured, by + * HAL_RCC_ClockConfig(). + * @param TickPriority: Tick interrupt priority. + * @retval HAL status + */ +HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { + RCC_ClkInitTypeDef clkconfig; + uint32_t uwTimclock, uwAPB1Prescaler; + uint32_t uwPrescalerValue; + uint32_t pFLatency; + + HAL_StatusTypeDef status = HAL_OK; + + /* Enable TIM1 clock */ + __HAL_RCC_TIM1_CLK_ENABLE(); + + /* Get clock configuration */ + HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); + + /* Get APB1 prescaler */ + uwAPB1Prescaler = clkconfig.APB1CLKDivider; + /* Compute TIM1 clock */ + if (uwAPB1Prescaler == RCC_HCLK_DIV1) { + uwTimclock = HAL_RCC_GetPCLK1Freq(); + } else { + uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq(); + } + + /* Compute the prescaler value to have TIM1 counter clock equal to 1MHz */ + uwPrescalerValue = (uint32_t)((uwTimclock / 1000000U) - 1U); + + /* Initialize TIM1 */ + htim1.Instance = TIM1; + + /* Initialize TIMx peripheral as follow: + * Period = [(TIM1CLK/1000) - 1]. to have a (1/1000) s time base. + * Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. + * ClockDivision = 0 + * Counter direction = Up + */ + htim1.Init.Period = (1000000U / 1000U) - 1U; + htim1.Init.Prescaler = uwPrescalerValue; + htim1.Init.ClockDivision = 0; + htim1.Init.CounterMode = TIM_COUNTERMODE_UP; + htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + + status = HAL_TIM_Base_Init(&htim1); + if (status == HAL_OK) { + /* Start the TIM time Base generation in interrupt mode */ + status = HAL_TIM_Base_Start_IT(&htim1); + if (status == HAL_OK) { + /* Enable the TIM1 global Interrupt */ + HAL_NVIC_EnableIRQ(TIM1_BRK_UP_TRG_COM_IRQn); + /* Configure the SysTick IRQ priority */ + if (TickPriority < (1UL << __NVIC_PRIO_BITS)) { + /* Configure the TIM IRQ priority */ + HAL_NVIC_SetPriority(TIM1_BRK_UP_TRG_COM_IRQn, TickPriority, + 0U); + uwTickPrio = TickPriority; + } else { + status = HAL_ERROR; + } + } + } + + /* Return function status */ + return status; +} + +/** + * @brief Suspend Tick increment. + * @note Disable the tick increment by disabling TIM1 update interrupt. + * @param None + * @retval None + */ +void HAL_SuspendTick(void) { + /* Disable TIM1 update Interrupt */ + __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_UPDATE); +} + +/** + * @brief Resume Tick increment. + * @note Enable the tick increment by Enabling TIM1 update interrupt. + * @param None + * @retval None + */ +void HAL_ResumeTick(void) { + /* Enable TIM1 Update interrupt */ + __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE); +} diff --git a/boards/motherboard/src/stm32g0xx_it.c b/boards/motherboard/src/stm32g0xx_it.c index fa339fe..40dd304 100644 --- a/boards/motherboard/src/stm32g0xx_it.c +++ b/boards/motherboard/src/stm32g0xx_it.c @@ -1,25 +1,26 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file stm32g0xx_it.c - * @brief Interrupt Service Routines. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file stm32g0xx_it.c + * @brief Interrupt Service Routines. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "main.h" #include "stm32g0xx_it.h" + +#include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -55,82 +56,39 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ +extern TIM_HandleTypeDef htim1; /* USER CODE BEGIN EV */ /* USER CODE END EV */ /******************************************************************************/ -/* Cortex-M0+ Processor Interruption and Exception Handlers */ +/* Cortex-M0+ 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 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 System service call via SWI instruction. - */ -void SVC_Handler(void) -{ - /* USER CODE BEGIN SVC_IRQn 0 */ - - /* USER CODE END SVC_IRQn 0 */ - /* USER CODE BEGIN SVC_IRQn 1 */ - - /* USER CODE END SVC_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 */ + * @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 */ + } } /******************************************************************************/ @@ -140,6 +98,20 @@ void SysTick_Handler(void) /* please refer to the startup file (startup_stm32g0xx.s). */ /******************************************************************************/ +/** + * @brief This function handles TIM1 break, update, trigger and commutation + * interrupts. + */ +void TIM1_BRK_UP_TRG_COM_IRQHandler(void) { + /* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 0 */ + + /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 0 */ + HAL_TIM_IRQHandler(&htim1); + /* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 1 */ + + /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 1 */ +} + /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ diff --git a/boards/motherboard/src/syscalls.c b/boards/motherboard/src/syscalls.c index 0197f26..368653c 100644 --- a/boards/motherboard/src/syscalls.c +++ b/boards/motherboard/src/syscalls.c @@ -21,156 +21,132 @@ */ /* 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 **environ = __env; - +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; +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 */ +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; +__attribute__((weak)) int _read(int file, char* ptr, int len) { + (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; +__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; + for (DataIdx = 0; DataIdx < len; DataIdx++) { + __io_putchar(*ptr++); + } + return len; } -int _close(int file) -{ - (void)file; - return -1; +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 _fstat(int file, struct stat* st) { + (void)file; + st->st_mode = S_IFCHR; + return 0; } -int _isatty(int file) -{ - (void)file; - return 1; +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 _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 _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 _wait(int* status) { + (void)status; + errno = ECHILD; + return -1; } -int _unlink(char *name) -{ - (void)name; - errno = ENOENT; - return -1; +int _unlink(char* name) { + (void)name; + errno = ENOENT; + return -1; } -int _times(struct tms *buf) -{ - (void)buf; - return -1; +int _times(struct tms* buf) { + (void)buf; + return -1; } -int _stat(char *file, struct stat *st) -{ - (void)file; - st->st_mode = S_IFCHR; - return 0; +int _stat(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 _link(char* old, char* new) { + (void)old; + (void)new; + errno = EMLINK; + return -1; } -int _fork(void) -{ - errno = EAGAIN; - 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; +int _execve(char* name, char** argv, char** env) { + (void)name; + (void)argv; + (void)env; + errno = ENOMEM; + return -1; } diff --git a/boards/motherboard/src/sysmem.c b/boards/motherboard/src/sysmem.c index 23ea8e0..29a55f1 100644 --- a/boards/motherboard/src/sysmem.c +++ b/boards/motherboard/src/sysmem.c @@ -27,7 +27,7 @@ /** * Pointer to the current high watermark of the heap usage */ -static uint8_t *__sbrk_heap_end = NULL; +static uint8_t* __sbrk_heap_end = NULL; /** * @brief _sbrk() allocates memory to the newlib heap and is used by malloc @@ -50,30 +50,28 @@ static uint8_t *__sbrk_heap_end = NULL; * @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; +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; - } + /* 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; } diff --git a/boards/motherboard/src/system_stm32g0xx.c b/boards/motherboard/src/system_stm32g0xx.c index 92a7f28..e623759 100644 --- a/boards/motherboard/src/system_stm32g0xx.c +++ b/boards/motherboard/src/system_stm32g0xx.c @@ -1,112 +1,112 @@ /** - ****************************************************************************** - * @file system_stm32g0xx.c - * @author MCD Application Team - * @brief CMSIS Cortex-M0+ 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_stm32g0xx.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 (8 MHz then 16 MHz) is used as system clock source. - * Then SystemInit() function is called, in "startup_stm32g0xx.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 - *----------------------------------------------------------------------------- - * APB Prescaler | 1 - *----------------------------------------------------------------------------- - * HSI Division factor | 1 - *----------------------------------------------------------------------------- - * PLL_M | 1 - *----------------------------------------------------------------------------- - * PLL_N | 8 - *----------------------------------------------------------------------------- - * PLL_P | 7 - *----------------------------------------------------------------------------- - * PLL_Q | 2 - *----------------------------------------------------------------------------- - * PLL_R | 2 - *----------------------------------------------------------------------------- - * Require 48MHz for RNG | Disabled - *----------------------------------------------------------------------------- - *============================================================================= - ****************************************************************************** - * @attention - * - * Copyright (c) 2018-2021 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_stm32g0xx.c + * @author MCD Application Team + * @brief CMSIS Cortex-M0+ 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_stm32g0xx.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 (8 MHz then 16 MHz) is used as system clock + * source. Then SystemInit() function is called, in "startup_stm32g0xx.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 + *----------------------------------------------------------------------------- + * APB Prescaler | 1 + *----------------------------------------------------------------------------- + * HSI Division factor | 1 + *----------------------------------------------------------------------------- + * PLL_M | 1 + *----------------------------------------------------------------------------- + * PLL_N | 8 + *----------------------------------------------------------------------------- + * PLL_P | 7 + *----------------------------------------------------------------------------- + * PLL_Q | 2 + *----------------------------------------------------------------------------- + * PLL_R | 2 + *----------------------------------------------------------------------------- + * Require 48MHz for RNG | Disabled + *----------------------------------------------------------------------------- + *============================================================================= + ****************************************************************************** + * @attention + * + * Copyright (c) 2018-2021 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 stm32g0xx_system - * @{ - */ + * @{ + */ /** @addtogroup STM32G0xx_System_Private_Includes - * @{ - */ + * @{ + */ #include "stm32g0xx.h" -#if !defined (HSE_VALUE) -#define HSE_VALUE (8000000UL) /*!< Value of the External oscillator in Hz */ -#endif /* HSE_VALUE */ +#if !defined(HSE_VALUE) +#define HSE_VALUE (8000000UL) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ -#if !defined (HSI_VALUE) - #define HSI_VALUE (16000000UL) /*!< Value of the Internal oscillator in Hz*/ -#endif /* HSI_VALUE */ +#if !defined(HSI_VALUE) +#define HSI_VALUE (16000000UL) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ -#if !defined (LSI_VALUE) - #define LSI_VALUE (32000UL) /*!< Value of LSI in Hz*/ -#endif /* LSI_VALUE */ +#if !defined(LSI_VALUE) +#define LSI_VALUE (32000UL) /*!< Value of LSI in Hz*/ +#endif /* LSI_VALUE */ -#if !defined (LSE_VALUE) - #define LSE_VALUE (32768UL) /*!< Value of LSE in Hz*/ -#endif /* LSE_VALUE */ +#if !defined(LSE_VALUE) +#define LSE_VALUE (32768UL) /*!< Value of LSE in Hz*/ +#endif /* LSE_VALUE */ /** - * @} - */ + * @} + */ /** @addtogroup STM32G0xx_System_Private_TypesDefinitions - * @{ - */ + * @{ + */ /** - * @} - */ + * @} + */ /** @addtogroup STM32G0xx_System_Private_Defines - * @{ - */ + * @{ + */ /************************* Miscellaneous Configuration ************************/ /* Note: Following vector table addresses must be defined in line with linker @@ -121,184 +121,196 @@ 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_BASE_ADDRESS \ + SRAM_BASE /*!< Vector Table base address 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. */ -#endif /* VECT_TAB_SRAM */ +#define VECT_TAB_BASE_ADDRESS \ + FLASH_BASE /*!< Vector Table base address field. \ + This value must be a multiple of 0x200. */ +#endif /* VECT_TAB_SRAM */ #if !defined(VECT_TAB_OFFSET) -#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table offset field. - This value must be a multiple of 0x200. */ -#endif /* VECT_TAB_OFFSET */ +#define VECT_TAB_OFFSET \ + 0x00000000U /*!< Vector Table offset field. \ + This value must be a multiple of 0x200. */ +#endif /* VECT_TAB_OFFSET */ #endif /* USER_VECT_TAB_ADDRESS */ /******************************************************************************/ /** - * @} - */ + * @} + */ /** @addtogroup STM32G0xx_System_Private_Macros - * @{ - */ + * @{ + */ /** - * @} - */ + * @} + */ /** @addtogroup STM32G0xx_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 = 16000000UL; - - const uint32_t AHBPrescTable[16UL] = {0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL, 6UL, 7UL, 8UL, 9UL}; - const uint32_t APBPrescTable[8UL] = {0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL}; + * @{ + */ +/* 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 = 16000000UL; + +const uint32_t AHBPrescTable[16UL] = {0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, + 1UL, 2UL, 3UL, 4UL, 6UL, 7UL, 8UL, 9UL}; +const uint32_t APBPrescTable[8UL] = {0UL, 0UL, 0UL, 0UL, 1UL, 2UL, 3UL, 4UL}; /** - * @} - */ + * @} + */ /** @addtogroup STM32G0xx_System_Private_FunctionPrototypes - * @{ - */ + * @{ + */ /** - * @} - */ + * @} + */ /** @addtogroup STM32G0xx_System_Private_Functions - * @{ - */ + * @{ + */ /** - * @brief Setup the microcontroller system. - * @param None - * @retval None - */ -void SystemInit(void) -{ - /* Configure the Vector Table location -------------------------------------*/ + * @brief Setup the microcontroller system. + * @param None + * @retval None + */ +void SystemInit(void) { + /* Configure the Vector Table location + * -------------------------------------*/ #if defined(USER_VECT_TAB_ADDRESS) - SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation */ -#endif /* USER_VECT_TAB_ADDRESS */ + SCB->VTOR = + VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation */ +#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(**) / HSI division factor - * - * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***) - * - * - If SYSCLK source is LSI, SystemCoreClock will contain the LSI_VALUE - * - * - If SYSCLK source is LSE, SystemCoreClock will contain the LSE_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 stm32g0xx_hal_conf.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 stm32g0xx_hal_conf.h file (default value - * 8 MHz), user has to ensure that HSE_VALUE is same as the real - * frequency of the crystal used. Otherwise, this function may - * have wrong result. - * - * - The result of this function could be not correct when using fractional - * value for HSE crystal. - * - * @param None - * @retval None - */ -void SystemCoreClockUpdate(void) -{ - uint32_t tmp; - uint32_t pllvco; - uint32_t pllr; - uint32_t pllsource; - uint32_t pllm; - uint32_t hsidiv; - - /* Get SYSCLK source -------------------------------------------------------*/ - switch (RCC->CFGR & RCC_CFGR_SWS) - { - case RCC_CFGR_SWS_0: /* HSE used as system clock */ - SystemCoreClock = HSE_VALUE; - break; - - case (RCC_CFGR_SWS_1 | RCC_CFGR_SWS_0): /* LSI used as system clock */ - SystemCoreClock = LSI_VALUE; - break; - - case RCC_CFGR_SWS_2: /* LSE used as system clock */ - SystemCoreClock = LSE_VALUE; - break; - - case RCC_CFGR_SWS_1: /* PLL used as system clock */ - /* 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) >> RCC_PLLCFGR_PLLM_Pos) + 1UL; - - if(pllsource == 0x03UL) /* HSE used as PLL clock source */ - { - pllvco = (HSE_VALUE / pllm); - } - else /* HSI used as PLL clock source */ - { - pllvco = (HSI_VALUE / pllm); - } - pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> RCC_PLLCFGR_PLLN_Pos); - pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> RCC_PLLCFGR_PLLR_Pos) + 1UL); - - SystemCoreClock = pllvco/pllr; - break; - - case 0x00000000U: /* HSI used as system clock */ - default: /* HSI used as system clock */ - hsidiv = (1UL << ((READ_BIT(RCC->CR, RCC_CR_HSIDIV))>> RCC_CR_HSIDIV_Pos)); - SystemCoreClock = (HSI_VALUE/hsidiv); - break; - } - /* Compute HCLK clock frequency --------------------------------------------*/ - /* Get HCLK prescaler */ - tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos)]; - /* HCLK clock frequency */ - SystemCoreClock >>= tmp; + * @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(**) / HSI division factor + * + * - If SYSCLK source is HSE, SystemCoreClock will contain the + * HSE_VALUE(***) + * + * - If SYSCLK source is LSI, SystemCoreClock will contain the + * LSI_VALUE + * + * - If SYSCLK source is LSE, SystemCoreClock will contain the + * LSE_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 stm32g0xx_hal_conf.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 stm32g0xx_hal_conf.h file + * (default value 8 MHz), user has to ensure that HSE_VALUE is same as the real + * frequency of the crystal used. Otherwise, this function may + * have wrong result. + * + * - The result of this function could be not correct when using + * fractional value for HSE crystal. + * + * @param None + * @retval None + */ +void SystemCoreClockUpdate(void) { + uint32_t tmp; + uint32_t pllvco; + uint32_t pllr; + uint32_t pllsource; + uint32_t pllm; + uint32_t hsidiv; + + /* Get SYSCLK source + * -------------------------------------------------------*/ + switch (RCC->CFGR & RCC_CFGR_SWS) { + case RCC_CFGR_SWS_0: /* HSE used as system clock */ + SystemCoreClock = HSE_VALUE; + break; + + case (RCC_CFGR_SWS_1 | RCC_CFGR_SWS_0): /* LSI used as system clock */ + SystemCoreClock = LSI_VALUE; + break; + + case RCC_CFGR_SWS_2: /* LSE used as system clock */ + SystemCoreClock = LSE_VALUE; + break; + + case RCC_CFGR_SWS_1: /* PLL used as system clock */ + /* 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) >> RCC_PLLCFGR_PLLM_Pos) + + 1UL; + + if (pllsource == 0x03UL) /* HSE used as PLL clock source */ + { + pllvco = (HSE_VALUE / pllm); + } else /* HSI used as PLL clock source */ + { + pllvco = (HSI_VALUE / pllm); + } + pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> + RCC_PLLCFGR_PLLN_Pos); + pllr = + (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> RCC_PLLCFGR_PLLR_Pos) + + 1UL); + + SystemCoreClock = pllvco / pllr; + break; + + case 0x00000000U: /* HSI used as system clock */ + default: /* HSI used as system clock */ + hsidiv = (1UL << ((READ_BIT(RCC->CR, RCC_CR_HSIDIV)) >> + RCC_CR_HSIDIV_Pos)); + SystemCoreClock = (HSI_VALUE / hsidiv); + break; + } + /* Compute HCLK clock frequency + * --------------------------------------------*/ + /* Get HCLK prescaler */ + tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> RCC_CFGR_HPRE_Pos)]; + /* HCLK clock frequency */ + SystemCoreClock >>= tmp; } - /** - * @} - */ + * @} + */ /** - * @} - */ + * @} + */ /** - * @} - */ + * @} + */ diff --git a/boards/motherboard/src/tasks.cpp b/boards/motherboard/src/tasks.cpp new file mode 100644 index 0000000..3ad725a --- /dev/null +++ b/boards/motherboard/src/tasks.cpp @@ -0,0 +1,53 @@ +#include "tasks.hpp" + +#include "FreeRTOS.h" +#include "main.h" +#include "stm32g0xx_hal.h" +#include "task.h" + +enum { + PRIORITY_10HZ = 1, + PRIORITY_100HZ = 2, + PRIORITY_1000HZ = 3, +}; + +static const size_t STACK_SIZE_WORDS = 512; + +StaticTask_t t1000hz_ctrl; +StackType_t t1000hz_stack[STACK_SIZE_WORDS]; + +StaticTask_t t100hz_ctrl; +StackType_t t100hz_stack[STACK_SIZE_WORDS]; + +StaticTask_t t10hz_ctrl; +StackType_t t10hz_stack[STACK_SIZE_WORDS]; + +void task_10hz(void* argument) { + (void)argument; + TickType_t wake_time = xTaskGetTickCount(); + + while (true) { + HAL_GPIO_TogglePin(DEBUG_GPIO_Port, DEBUG_Pin); + vTaskDelayUntil(&wake_time, pdMS_TO_TICKS(100)); + } +}; + +void MX_FREERTOS_Init() { + xTaskCreateStatic(task_10hz, "10Hz", STACK_SIZE_WORDS, NULL, PRIORITY_10HZ, + t10hz_stack, &t10hz_ctrl); + + vTaskStartScheduler(); +} + +extern "C" { +void vApplicationGetIdleTaskMemory(StaticTask_t** ppxIdleTaskTCBBuffer, + StackType_t** ppxIdleTaskStackBuffer, + uint32_t* pulIdleTaskStackSize) { + static StaticTask_t xIdleTaskTCB; + static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE]; + + *ppxIdleTaskTCBBuffer = &xIdleTaskTCB; + *ppxIdleTaskStackBuffer = uxIdleTaskStack; + *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; +} +} \ No newline at end of file diff --git a/boards/motherboard/src/usb_drd_fs.c b/boards/motherboard/src/usb_drd_fs.c index 6d12192..a51e85d 100644 --- a/boards/motherboard/src/usb_drd_fs.c +++ b/boards/motherboard/src/usb_drd_fs.c @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file usb_drd_fs.c - * @brief This file provides code for the configuration - * of the USB_DRD_FS instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file usb_drd_fs.c + * @brief This file provides code for the configuration + * of the USB_DRD_FS instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "usb_drd_fs.h" @@ -28,94 +28,79 @@ PCD_HandleTypeDef hpcd_USB_DRD_FS; /* USB_DRD_FS init function */ -void MX_USB_DRD_FS_PCD_Init(void) -{ - - /* USER CODE BEGIN USB_DRD_FS_Init 0 */ - - /* USER CODE END USB_DRD_FS_Init 0 */ - - /* USER CODE BEGIN USB_DRD_FS_Init 1 */ - - /* USER CODE END USB_DRD_FS_Init 1 */ - hpcd_USB_DRD_FS.Instance = USB_DRD_FS; - hpcd_USB_DRD_FS.Init.dev_endpoints = 8; - hpcd_USB_DRD_FS.Init.Host_channels = 8; - hpcd_USB_DRD_FS.Init.speed = PCD_SPEED_FULL; - hpcd_USB_DRD_FS.Init.phy_itface = PCD_PHY_EMBEDDED; - hpcd_USB_DRD_FS.Init.Sof_enable = DISABLE; - hpcd_USB_DRD_FS.Init.low_power_enable = DISABLE; - hpcd_USB_DRD_FS.Init.lpm_enable = DISABLE; - hpcd_USB_DRD_FS.Init.battery_charging_enable = DISABLE; - hpcd_USB_DRD_FS.Init.vbus_sensing_enable = DISABLE; - hpcd_USB_DRD_FS.Init.bulk_doublebuffer_enable = DISABLE; - hpcd_USB_DRD_FS.Init.iso_singlebuffer_enable = DISABLE; - if (HAL_PCD_Init(&hpcd_USB_DRD_FS) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN USB_DRD_FS_Init 2 */ - - /* USER CODE END USB_DRD_FS_Init 2 */ - -} - -void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) -{ - - RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; - if(pcdHandle->Instance==USB_DRD_FS) - { - /* USER CODE BEGIN USB_DRD_FS_MspInit 0 */ - - /* USER CODE END USB_DRD_FS_MspInit 0 */ - - /** Initializes the peripherals clocks - */ - PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; - PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; - if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) - { - Error_Handler(); +void MX_USB_DRD_FS_PCD_Init(void) { + /* USER CODE BEGIN USB_DRD_FS_Init 0 */ + + /* USER CODE END USB_DRD_FS_Init 0 */ + + /* USER CODE BEGIN USB_DRD_FS_Init 1 */ + + /* USER CODE END USB_DRD_FS_Init 1 */ + hpcd_USB_DRD_FS.Instance = USB_DRD_FS; + hpcd_USB_DRD_FS.Init.dev_endpoints = 8; + hpcd_USB_DRD_FS.Init.Host_channels = 8; + hpcd_USB_DRD_FS.Init.speed = PCD_SPEED_FULL; + hpcd_USB_DRD_FS.Init.phy_itface = PCD_PHY_EMBEDDED; + hpcd_USB_DRD_FS.Init.Sof_enable = DISABLE; + hpcd_USB_DRD_FS.Init.low_power_enable = DISABLE; + hpcd_USB_DRD_FS.Init.lpm_enable = DISABLE; + hpcd_USB_DRD_FS.Init.battery_charging_enable = DISABLE; + hpcd_USB_DRD_FS.Init.vbus_sensing_enable = DISABLE; + hpcd_USB_DRD_FS.Init.bulk_doublebuffer_enable = DISABLE; + hpcd_USB_DRD_FS.Init.iso_singlebuffer_enable = DISABLE; + if (HAL_PCD_Init(&hpcd_USB_DRD_FS) != HAL_OK) { + Error_Handler(); } + /* USER CODE BEGIN USB_DRD_FS_Init 2 */ - /* USB_DRD_FS clock enable */ - __HAL_RCC_USB_CLK_ENABLE(); + /* USER CODE END USB_DRD_FS_Init 2 */ +} - /* Enable VDDUSB */ - if(__HAL_RCC_PWR_IS_CLK_DISABLED()) - { - __HAL_RCC_PWR_CLK_ENABLE(); - HAL_PWREx_EnableVddUSB(); - __HAL_RCC_PWR_CLK_DISABLE(); - } - else - { - HAL_PWREx_EnableVddUSB(); +void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) { + RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; + if (pcdHandle->Instance == USB_DRD_FS) { + /* USER CODE BEGIN USB_DRD_FS_MspInit 0 */ + + /* USER CODE END USB_DRD_FS_MspInit 0 */ + + /** Initializes the peripherals clocks + */ + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; + PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { + Error_Handler(); + } + + /* USB_DRD_FS clock enable */ + __HAL_RCC_USB_CLK_ENABLE(); + + /* Enable VDDUSB */ + if (__HAL_RCC_PWR_IS_CLK_DISABLED()) { + __HAL_RCC_PWR_CLK_ENABLE(); + HAL_PWREx_EnableVddUSB(); + __HAL_RCC_PWR_CLK_DISABLE(); + } else { + HAL_PWREx_EnableVddUSB(); + } + /* USER CODE BEGIN USB_DRD_FS_MspInit 1 */ + + /* USER CODE END USB_DRD_FS_MspInit 1 */ } - /* USER CODE BEGIN USB_DRD_FS_MspInit 1 */ - - /* USER CODE END USB_DRD_FS_MspInit 1 */ - } } -void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) -{ - - if(pcdHandle->Instance==USB_DRD_FS) - { - /* USER CODE BEGIN USB_DRD_FS_MspDeInit 0 */ +void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) { + if (pcdHandle->Instance == USB_DRD_FS) { + /* USER CODE BEGIN USB_DRD_FS_MspDeInit 0 */ - /* USER CODE END USB_DRD_FS_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_USB_CLK_DISABLE(); - /* USER CODE BEGIN USB_DRD_FS_MspDeInit 1 */ + /* USER CODE END USB_DRD_FS_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USB_CLK_DISABLE(); + /* USER CODE BEGIN USB_DRD_FS_MspDeInit 1 */ - /* USER CODE END USB_DRD_FS_MspDeInit 1 */ - } + /* USER CODE END USB_DRD_FS_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - From 5893a63fb21fbc05c2644f20d04f5dcf4d025f40 Mon Sep 17 00:00:00 2001 From: Ivan Lange Date: Tue, 31 Mar 2026 00:14:42 -0400 Subject: [PATCH 04/13] Update .ioc and add USB --- boards/motherboard/Inc/FreeRTOSConfig.h | 72 +- boards/motherboard/Inc/gpio.h | 1 + boards/motherboard/Inc/stm32g0xx_hal_conf.h | 235 +++--- boards/motherboard/Inc/usb_device.h | 103 +++ boards/motherboard/Inc/usb_drd_fs.h | 51 -- boards/motherboard/Inc/usbd_cdc_if.h | 132 +++ boards/motherboard/Inc/usbd_conf.h | 174 ++++ boards/motherboard/Inc/usbd_desc.h | 143 ++++ boards/motherboard/motherboard.ioc | 160 +++- boards/motherboard/src/app_freertos.c | 140 +++ boards/motherboard/src/gpio.c | 55 +- boards/motherboard/src/main.c | 208 ++--- boards/motherboard/src/stm32g0xx_hal_msp.c | 33 +- .../src/stm32g0xx_hal_timebase_tim.c | 181 ++-- boards/motherboard/src/stm32g0xx_it.c | 62 +- boards/motherboard/src/tasks.cpp | 3 + boards/motherboard/src/usb_device.c | 97 +++ boards/motherboard/src/usb_drd_fs.c | 106 --- boards/motherboard/src/usbd_cdc_if.c | 329 ++++++++ boards/motherboard/src/usbd_conf.c | 794 ++++++++++++++++++ boards/motherboard/src/usbd_desc.c | 396 +++++++++ 21 files changed, 2875 insertions(+), 600 deletions(-) create mode 100644 boards/motherboard/Inc/usb_device.h delete mode 100644 boards/motherboard/Inc/usb_drd_fs.h create mode 100644 boards/motherboard/Inc/usbd_cdc_if.h create mode 100644 boards/motherboard/Inc/usbd_conf.h create mode 100644 boards/motherboard/Inc/usbd_desc.h create mode 100644 boards/motherboard/src/app_freertos.c create mode 100644 boards/motherboard/src/usb_device.c delete mode 100644 boards/motherboard/src/usb_drd_fs.c create mode 100644 boards/motherboard/src/usbd_cdc_if.c create mode 100644 boards/motherboard/src/usbd_conf.c create mode 100644 boards/motherboard/src/usbd_desc.c diff --git a/boards/motherboard/Inc/FreeRTOSConfig.h b/boards/motherboard/Inc/FreeRTOSConfig.h index d9bfc99..6ef313d 100644 --- a/boards/motherboard/Inc/FreeRTOSConfig.h +++ b/boards/motherboard/Inc/FreeRTOSConfig.h @@ -39,8 +39,8 @@ * These definitions should be adjusted for your particular hardware and * application requirements. * - * These parameters and more are described within the 'configuration' section of - * the FreeRTOS API documentation available on the FreeRTOS.org web site. + * These parameters and more are described within the 'configuration' section of the + * FreeRTOS API documentation available on the FreeRTOS.org web site. * * See http://www.freertos.org/a00110.html *----------------------------------------------------------*/ @@ -49,29 +49,28 @@ /* Section where include file can be added */ /* USER CODE END Includes */ -/* Ensure definitions are only used by the compiler, and not by the assembler. - */ +/* Ensure definitions are only used by the compiler, and not by the assembler. */ #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) -#include -extern uint32_t SystemCoreClock; + #include + extern uint32_t SystemCoreClock; #endif -#define configENABLE_FPU 0 -#define configENABLE_MPU 0 +#define configENABLE_FPU 0 +#define configENABLE_MPU 0 -#define configUSE_PREEMPTION 1 -#define configSUPPORT_STATIC_ALLOCATION 1 -#define configSUPPORT_DYNAMIC_ALLOCATION 0 -#define configUSE_IDLE_HOOK 0 -#define configUSE_TICK_HOOK 0 -#define configCPU_CLOCK_HZ (SystemCoreClock) -#define configTICK_RATE_HZ ((TickType_t)1000) -#define configMAX_PRIORITIES (7) -#define configMINIMAL_STACK_SIZE ((uint16_t)128) -#define configMAX_TASK_NAME_LEN (16) -#define configUSE_16_BIT_TICKS 0 -#define configUSE_MUTEXES 1 -#define configQUEUE_REGISTRY_SIZE 8 -#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 +#define configUSE_PREEMPTION 1 +#define configSUPPORT_STATIC_ALLOCATION 1 +#define configSUPPORT_DYNAMIC_ALLOCATION 0 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( SystemCoreClock ) +#define configTICK_RATE_HZ ((TickType_t)1000) +#define configMAX_PRIORITIES ( 7 ) +#define configMINIMAL_STACK_SIZE ((uint16_t)128) +#define configMAX_TASK_NAME_LEN ( 16 ) +#define configUSE_16_BIT_TICKS 0 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 /* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */ /* Defaults to size_t for backward compatibility, but can be changed if lengths will always be less than the number of bytes in a size_t. */ @@ -79,22 +78,22 @@ extern uint32_t SystemCoreClock; /* USER CODE END MESSAGE_BUFFER_LENGTH_TYPE */ /* Co-routine definitions. */ -#define configUSE_CO_ROUTINES 0 -#define configMAX_CO_ROUTINE_PRIORITIES (2) +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) /* The following flag must be enabled only when using newlib */ -#define configUSE_NEWLIB_REENTRANT 1 +#define configUSE_NEWLIB_REENTRANT 1 /* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */ -#define INCLUDE_vTaskPrioritySet 1 -#define INCLUDE_uxTaskPriorityGet 1 -#define INCLUDE_vTaskDelete 1 -#define INCLUDE_vTaskCleanUpResources 0 -#define INCLUDE_vTaskSuspend 1 -#define INCLUDE_vTaskDelayUntil 1 -#define INCLUDE_vTaskDelay 1 -#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 /* Normal assert() semantics without relying on the provision of an assert.h header file. */ @@ -108,12 +107,11 @@ header file. */ /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS standard names. */ -#define vPortSVCHandler SVC_Handler +#define vPortSVCHandler SVC_Handler #define xPortPendSVHandler PendSV_Handler -/* IMPORTANT: This define is commented when used with STM32Cube firmware, when - the timebase source is SysTick, to prevent overwriting SysTick_Handler - defined within STM32Cube HAL */ +/* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick, + to prevent overwriting SysTick_Handler defined within STM32Cube HAL */ #define xPortSysTickHandler SysTick_Handler diff --git a/boards/motherboard/Inc/gpio.h b/boards/motherboard/Inc/gpio.h index 907d2a4..c91d06e 100644 --- a/boards/motherboard/Inc/gpio.h +++ b/boards/motherboard/Inc/gpio.h @@ -46,3 +46,4 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ + diff --git a/boards/motherboard/Inc/stm32g0xx_hal_conf.h b/boards/motherboard/Inc/stm32g0xx_hal_conf.h index bcb078a..cb0d292 100644 --- a/boards/motherboard/Inc/stm32g0xx_hal_conf.h +++ b/boards/motherboard/Inc/stm32g0xx_hal_conf.h @@ -31,8 +31,8 @@ extern "C" { /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED /* #define HAL_ADC_MODULE_ENABLED */ /* #define HAL_CEC_MODULE_ENABLED */ @@ -66,115 +66,106 @@ extern "C" { #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_CEC_REGISTER_CALLBACKS 0u -#define USE_HAL_COMP_REGISTER_CALLBACKS 0u -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0u -#define USE_HAL_DAC_REGISTER_CALLBACKS 0u -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0u -#define USE_HAL_HCD_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_PCD_REGISTER_CALLBACKS 0u -#define USE_HAL_RNG_REGISTER_CALLBACKS 0u -#define USE_HAL_RTC_REGISTER_CALLBACKS 0u -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0u -#define USE_HAL_SPI_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_CEC_REGISTER_CALLBACKS 0u +#define USE_HAL_COMP_REGISTER_CALLBACKS 0u +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0u +#define USE_HAL_DAC_REGISTER_CALLBACKS 0u +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0u +#define USE_HAL_HCD_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_PCD_REGISTER_CALLBACKS 0u +#define USE_HAL_RNG_REGISTER_CALLBACKS 0u +#define USE_HAL_RTC_REGISTER_CALLBACKS 0u +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0u +#define USE_HAL_SPI_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 (8000000UL) /*!< 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 (8000000UL) /*!< 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 */ #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx) /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS, SDMMC 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 \ - 48000000U /*!< Value of the Internal High Speed oscillator for USB \ - FS/SDMMC/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, SDMMC 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 48000000U /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/RNG in Hz. + The real value my vary depending on manufacturing process variations.*/ +#endif /* HSI48_VALUE */ #endif /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined(LSI_VALUE) -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz \ -The real value may vary depending on the variations \ + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz +The real value may vary depending on the variations in voltage and temperature.*/ /** - * @brief External Low Speed oscillator (LSE) value. - * 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 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 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 I2S1 peripheral - * This value is used by the RCC HAL module to compute the I2S1 clock - * source frequency. - */ -#if !defined(EXTERNAL_I2S1_CLOCK_VALUE) -#define EXTERNAL_I2S1_CLOCK_VALUE \ - (48000UL) /*!< Value of the I2S1 External clock source in Hz*/ -#endif /* EXTERNAL_I2S1_CLOCK_VALUE */ + * @brief External clock source for I2S1 peripheral + * This value is used by the RCC HAL module to compute the I2S1 clock source + * frequency. + */ +#if !defined (EXTERNAL_I2S1_CLOCK_VALUE) +#define EXTERNAL_I2S1_CLOCK_VALUE (48000UL) /*!< Value of the I2S1 External clock source in Hz*/ +#endif /* EXTERNAL_I2S1_CLOCK_VALUE */ #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx) /** - * @brief External clock source for I2S2 peripheral - * This value is used by the RCC HAL module to compute the I2S2 clock - * source frequency. - */ -#if !defined(EXTERNAL_I2S2_CLOCK_VALUE) -#define EXTERNAL_I2S2_CLOCK_VALUE \ - 48000U /*!< Value of the I2S2 External clock source in Hz*/ -#endif /* EXTERNAL_I2S2_CLOCK_VALUE */ + * @brief External clock source for I2S2 peripheral + * This value is used by the RCC HAL module to compute the I2S2 clock source + * frequency. + */ +#if !defined (EXTERNAL_I2S2_CLOCK_VALUE) + #define EXTERNAL_I2S2_CLOCK_VALUE 48000U /*!< Value of the I2S2 External clock source in Hz*/ +#endif /* EXTERNAL_I2S2_CLOCK_VALUE */ #endif /* Tip: To avoid modifying this file each time you need to use different HSE, @@ -182,39 +173,38 @@ in voltage and temperature.*/ /* ########################### System Configuration ######################### */ /** - * @brief This is the HAL system configuration section - */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY 3U /*!< tick interrupt priority */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 1U -#define INSTRUCTION_CACHE_ENABLE 1U + * @brief This is the HAL system configuration section + */ +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY 3U /*!< tick interrupt priority */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 1U +#define INSTRUCTION_CACHE_ENABLE 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 - */ +* Activated: CRC code is present inside driver +* Deactivated: CRC code cleaned from driver +*/ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U -/* ################## CRYP peripheral configuration ########################## - */ +/* ################## CRYP peripheral configuration ########################## */ -#define USE_HAL_CRYP_SUSPEND_RESUME 1U +#define USE_HAL_CRYP_SUSPEND_RESUME 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 */ /* Includes ------------------------------------------------------------------*/ /** - * @brief Include modules header file - */ + * @brief Include modules header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g0xx_hal_rcc.h" @@ -338,19 +328,18 @@ 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 functions 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 functions 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); +void assert_failed(uint8_t *file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ diff --git a/boards/motherboard/Inc/usb_device.h b/boards/motherboard/Inc/usb_device.h new file mode 100644 index 0000000..75e8e77 --- /dev/null +++ b/boards/motherboard/Inc/usb_device.h @@ -0,0 +1,103 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : usb_device.h + * @version : v3.0_Cube + * @brief : Header for usb_device.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USB_DEVICE__H__ +#define __USB_DEVICE__H__ + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "stm32g0xx.h" +#include "stm32g0xx_hal.h" +#include "usbd_def.h" + +/* USER CODE BEGIN INCLUDE */ + +/* USER CODE END INCLUDE */ + +/** @addtogroup USBD_OTG_DRIVER + * @{ + */ + +/** @defgroup USBD_DEVICE USBD_DEVICE + * @brief Device file for Usb otg low level driver. + * @{ + */ + +/** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables + * @brief Public variables. + * @{ + */ + +/* Private variables ---------------------------------------------------------*/ +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +/* Private function prototypes -----------------------------------------------*/ +/* USER CODE BEGIN PFP */ + +/* USER CODE END PFP */ + +/* + * -- Insert your variables declaration here -- + */ +/* USER CODE BEGIN VARIABLES */ + +/* USER CODE END VARIABLES */ +/** + * @} + */ + +/** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype + * @brief Declaration of public functions for Usb device. + * @{ + */ + +/** USB Device initialization function. */ +void MX_USB_Device_Init(void); + +/* + * -- Insert functions declaration here -- + */ +/* USER CODE BEGIN FD */ + +/* USER CODE END FD */ +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USB_DEVICE__H__ */ + diff --git a/boards/motherboard/Inc/usb_drd_fs.h b/boards/motherboard/Inc/usb_drd_fs.h deleted file mode 100644 index 935b255..0000000 --- a/boards/motherboard/Inc/usb_drd_fs.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file usb_drd_fs.h - * @brief This file contains all the function prototypes for - * the usb_drd_fs.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_DRD_FS_H__ -#define __USB_DRD_FS_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern PCD_HandleTypeDef hpcd_USB_DRD_FS; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_USB_DRD_FS_PCD_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USB_DRD_FS_H__ */ diff --git a/boards/motherboard/Inc/usbd_cdc_if.h b/boards/motherboard/Inc/usbd_cdc_if.h new file mode 100644 index 0000000..a39a635 --- /dev/null +++ b/boards/motherboard/Inc/usbd_cdc_if.h @@ -0,0 +1,132 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : usbd_cdc_if.h + * @version : v3.0_Cube + * @brief : Header for usbd_cdc_if.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ + +#ifndef __USBD_CDC_IF_H__ +#define __USBD_CDC_IF_H__ + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_cdc.h" + +/* USER CODE BEGIN INCLUDE */ + +/* USER CODE END INCLUDE */ + +/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY + * @brief For Usb device. + * @{ + */ + +/** @defgroup USBD_CDC_IF USBD_CDC_IF + * @brief Usb VCP device module + * @{ + */ + +/** @defgroup USBD_CDC_IF_Exported_Defines USBD_CDC_IF_Exported_Defines + * @brief Defines. + * @{ + */ +/* Define size for the receive and transmit buffer over CDC */ +#define APP_RX_DATA_SIZE 2048 +#define APP_TX_DATA_SIZE 2048 +/* USER CODE BEGIN EXPORTED_DEFINES */ + +/* USER CODE END EXPORTED_DEFINES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_Types USBD_CDC_IF_Exported_Types + * @brief Types. + * @{ + */ + +/* USER CODE BEGIN EXPORTED_TYPES */ + +/* USER CODE END EXPORTED_TYPES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_Macros USBD_CDC_IF_Exported_Macros + * @brief Aliases. + * @{ + */ + +/* USER CODE BEGIN EXPORTED_MACRO */ + +/* USER CODE END EXPORTED_MACRO */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables + * @brief Public variables. + * @{ + */ + +/** CDC Interface callback. */ +extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS; + +/* USER CODE BEGIN EXPORTED_VARIABLES */ + +/* USER CODE END EXPORTED_VARIABLES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype USBD_CDC_IF_Exported_FunctionsPrototype + * @brief Public functions declaration. + * @{ + */ + +uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len); + +/* USER CODE BEGIN EXPORTED_FUNCTIONS */ + +/* USER CODE END EXPORTED_FUNCTIONS */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_CDC_IF_H__ */ + diff --git a/boards/motherboard/Inc/usbd_conf.h b/boards/motherboard/Inc/usbd_conf.h new file mode 100644 index 0000000..6175d73 --- /dev/null +++ b/boards/motherboard/Inc/usbd_conf.h @@ -0,0 +1,174 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : usbd_conf.h + * @version : v3.0_Cube + * @brief : Header for usbd_conf.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_CONF__H__ +#define __USBD_CONF__H__ + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include +#include +#include +#include "stm32g0xx.h" +#include "stm32g0xx_hal.h" + +/* USER CODE BEGIN INCLUDE */ + +/* USER CODE END INCLUDE */ + +/** @addtogroup USBD_OTG_DRIVER + * @brief Driver for Usb device. + * @{ + */ + +/** @defgroup USBD_CONF USBD_CONF + * @brief Configuration file for Usb otg low level driver. + * @{ + */ + +/** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables + * @brief Public variables. + * @{ + */ + +/* Private variables ---------------------------------------------------------*/ +/* USER CODE BEGIN PV */ +/* USER CODE END PV */ +/** + * @} + */ + +/** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines + * @brief Defines for configuration of the Usb device. + * @{ + */ + +/*---------- -----------*/ +#define USBD_MAX_NUM_INTERFACES 1U +/*---------- -----------*/ +#define USBD_MAX_NUM_CONFIGURATION 1U +/*---------- -----------*/ +#define USBD_MAX_STR_DESC_SIZ 512U +/*---------- -----------*/ +#define USBD_DEBUG_LEVEL 0U +/*---------- -----------*/ +#define USBD_LPM_ENABLED 1U +/*---------- -----------*/ +#define USBD_SELF_POWERED 1U + +/****************************************/ +/* #define for FS and HS identification */ +#define DEVICE_FS 0 + +/** + * @} + */ + +/** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros + * @brief Aliases. + * @{ + */ + +/* Memory management macros make sure to use static memory allocation */ +/** Alias for memory allocation. */ +#define USBD_malloc (void *)USBD_static_malloc + +/** Alias for memory release. */ +#define USBD_free USBD_static_free + +/** Alias for memory set. */ +#define USBD_memset memset + +/** Alias for memory copy. */ +#define USBD_memcpy memcpy + +/** Alias for delay. */ +#define USBD_Delay HAL_Delay + +/* DEBUG macros */ + +#if (USBD_DEBUG_LEVEL > 0) +#define USBD_UsrLog(...) printf(__VA_ARGS__);\ + printf("\n"); +#else +#define USBD_UsrLog(...) +#endif + +#if (USBD_DEBUG_LEVEL > 1) + +#define USBD_ErrLog(...) printf("ERROR: ") ;\ + printf(__VA_ARGS__);\ + printf("\n"); +#else +#define USBD_ErrLog(...) +#endif + +#if (USBD_DEBUG_LEVEL > 2) +#define USBD_DbgLog(...) printf("DEBUG : ") ;\ + printf(__VA_ARGS__);\ + printf("\n"); +#else +#define USBD_DbgLog(...) +#endif + +/** + * @} + */ + +/** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types + * @brief Types. + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype + * @brief Declaration of public functions for Usb device. + * @{ + */ + +/* Exported functions -------------------------------------------------------*/ +void *USBD_static_malloc(uint32_t size); +void USBD_static_free(void *p); + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_CONF__H__ */ + diff --git a/boards/motherboard/Inc/usbd_desc.h b/boards/motherboard/Inc/usbd_desc.h new file mode 100644 index 0000000..9916164 --- /dev/null +++ b/boards/motherboard/Inc/usbd_desc.h @@ -0,0 +1,143 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : usbd_desc.c + * @version : v3.0_Cube + * @brief : Header for usbd_conf.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_DESC__C__ +#define __USBD_DESC__C__ + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_def.h" + +/* USER CODE BEGIN INCLUDE */ + +/* USER CODE END INCLUDE */ + +/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup USBD_DESC USBD_DESC + * @brief Usb device descriptors module. + * @{ + */ + +/** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants + * @brief Constants. + * @{ + */ +#define DEVICE_ID1 (UID_BASE) +#define DEVICE_ID2 (UID_BASE + 0x4) +#define DEVICE_ID3 (UID_BASE + 0x8) + +#define USB_SIZ_STRING_SERIAL 0x1A + +/* USER CODE BEGIN EXPORTED_CONSTANTS */ + +/* USER CODE END EXPORTED_CONSTANTS */ + +/** + * @} + */ + +/** @defgroup USBD_DESC_Exported_Defines USBD_DESC_Exported_Defines + * @brief Defines. + * @{ + */ + +/* USER CODE BEGIN EXPORTED_DEFINES */ + +/* USER CODE END EXPORTED_DEFINES */ + +/** + * @} + */ + +/** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions + * @brief Types. + * @{ + */ + +/* USER CODE BEGIN EXPORTED_TYPES */ + +/* USER CODE END EXPORTED_TYPES */ + +/** + * @} + */ + +/** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros + * @brief Aliases. + * @{ + */ + +/* USER CODE BEGIN EXPORTED_MACRO */ + +/* USER CODE END EXPORTED_MACRO */ + +/** + * @} + */ + +/** @defgroup USBD_DESC_Exported_Variables USBD_DESC_Exported_Variables + * @brief Public variables. + * @{ + */ + +extern USBD_DescriptorsTypeDef CDC_Desc; + +/* USER CODE BEGIN EXPORTED_VARIABLES */ + +/* USER CODE END EXPORTED_VARIABLES */ + +/** + * @} + */ + +/** @defgroup USBD_DESC_Exported_FunctionsPrototype USBD_DESC_Exported_FunctionsPrototype + * @brief Public functions declaration. + * @{ + */ + +/* USER CODE BEGIN EXPORTED_FUNCTIONS */ + +/* USER CODE END EXPORTED_FUNCTIONS */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_DESC__C__ */ + diff --git a/boards/motherboard/motherboard.ioc b/boards/motherboard/motherboard.ioc index 31a9ece..772034f 100644 --- a/boards/motherboard/motherboard.ioc +++ b/boards/motherboard/motherboard.ioc @@ -1,3 +1,4 @@ +#MicroXplorer Configuration settings - do not modify CAD.formats= CAD.pinconfig= CAD.provider= @@ -17,23 +18,46 @@ Mcu.IP0=FREERTOS Mcu.IP1=NVIC Mcu.IP2=RCC Mcu.IP3=SYS -Mcu.IP4=USB_DRD_FS -Mcu.IPNb=5 +Mcu.IP4=USB_DEVICE +Mcu.IP5=USB_DRD_FS +Mcu.IPNb=6 Mcu.Name=STM32G0B1V(B-C-E)Tx Mcu.Package=LQFP100 -Mcu.Pin0=PF0-OSC_IN (PF0) -Mcu.Pin1=PF1-OSC_OUT (PF1) -Mcu.Pin2=PE7 -Mcu.Pin3=PA11 [PA9] -Mcu.Pin4=PA12 [PA10] -Mcu.Pin5=PF11 -Mcu.Pin6=PF12 -Mcu.Pin7=PE0 -Mcu.Pin8=PE1 -Mcu.Pin9=VP_FREERTOS_VS_CMSIS_V1 -Mcu.Pin10=VP_SYS_VS_tim1 -Mcu.Pin11=VP_SYS_VS_DBSignals -Mcu.PinsNb=12 +Mcu.Pin0=PE4 +Mcu.Pin1=PE5 +Mcu.Pin10=PA11 [PA9] +Mcu.Pin11=PA12 [PA10] +Mcu.Pin12=PF8 +Mcu.Pin13=PD0 +Mcu.Pin14=PD1 +Mcu.Pin15=PD2 +Mcu.Pin16=PD3 +Mcu.Pin17=PD4 +Mcu.Pin18=PD5 +Mcu.Pin19=PD6 +Mcu.Pin2=PF0-OSC_IN (PF0) +Mcu.Pin20=PD7 +Mcu.Pin21=PF9 +Mcu.Pin22=PF10 +Mcu.Pin23=PF11 +Mcu.Pin24=PF12 +Mcu.Pin25=PF13 +Mcu.Pin26=PE0 +Mcu.Pin27=PE1 +Mcu.Pin28=PE2 +Mcu.Pin29=PE3 +Mcu.Pin3=PF1-OSC_OUT (PF1) +Mcu.Pin30=VP_FREERTOS_VS_CMSIS_V1 +Mcu.Pin31=VP_SYS_VS_tim1 +Mcu.Pin32=VP_SYS_VS_DBSignals +Mcu.Pin33=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS +Mcu.Pin4=PE7 +Mcu.Pin5=PE8 +Mcu.Pin6=PD12 +Mcu.Pin7=PD13 +Mcu.Pin8=PD14 +Mcu.Pin9=PD15 +Mcu.PinsNb=34 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32G0B1VETx @@ -49,12 +73,60 @@ NVIC.SavedSvcallIrqHandlerGenerated=true NVIC.SavedSystickIrqHandlerGenerated=true NVIC.SysTick_IRQn=true\:3\:0\:false\:false\:false\:true\:false\:true\:false NVIC.TIM1_BRK_UP_TRG_COM_IRQn=true\:3\:0\:false\:false\:true\:false\:false\:true\:true -NVIC.TimeBaseIP=TIM1 NVIC.TimeBase=TIM1_BRK_UP_TRG_COM_IRQn +NVIC.TimeBaseIP=TIM1 PA11\ [PA9].Mode=Device PA11\ [PA9].Signal=USB_DM PA12\ [PA10].Mode=Device PA12\ [PA10].Signal=USB_DP +PD0.GPIOParameters=GPIO_Label +PD0.GPIO_Label=P12V_HSD_DIAG_EN +PD0.Locked=true +PD0.Signal=GPIO_Output +PD1.GPIOParameters=GPIO_Label +PD1.GPIO_Label=MUX_ST +PD1.Locked=true +PD1.Signal=GPIO_Input +PD12.GPIOParameters=GPIO_Label +PD12.GPIO_Label=LPA_EN +PD12.Locked=true +PD12.Signal=GPIO_Output +PD13.GPIOParameters=GPIO_Label +PD13.GPIO_Label=VGA_ATTSEL0 +PD13.Locked=true +PD13.Signal=GPIO_Output +PD14.GPIOParameters=GPIO_Label +PD14.GPIO_Label=VGA_EN +PD14.Locked=true +PD14.Signal=GPIO_Output +PD15.GPIOParameters=GPIO_Label +PD15.GPIO_Label=VGA_ATTSEL1 +PD15.Locked=true +PD15.Signal=GPIO_Output +PD2.GPIOParameters=GPIO_Label +PD2.GPIO_Label=FAN1_PWR_EN +PD2.Locked=true +PD2.Signal=GPIO_Output +PD3.GPIOParameters=GPIO_Label +PD3.GPIO_Label=nFAULT_FAN1 +PD3.Locked=true +PD3.Signal=GPIO_Input +PD4.GPIOParameters=GPIO_Label +PD4.GPIO_Label=FAN2_PWR_EN +PD4.Locked=true +PD4.Signal=GPIO_Output +PD5.GPIOParameters=GPIO_Label +PD5.GPIO_Label=nFAULT_FAN2 +PD5.Locked=true +PD5.Signal=GPIO_Input +PD6.GPIOParameters=GPIO_Label +PD6.GPIO_Label=P6V_HDS_ONE_DIAG_EN +PD6.Locked=true +PD6.Signal=GPIO_Output +PD7.GPIOParameters=GPIO_Label +PD7.GPIO_Label=P6V_HSD_ONE_nFAULT +PD7.Locked=true +PD7.Signal=GPIO_Input PE0.GPIOParameters=GPIO_Label PE0.GPIO_Label=GEN_EN PE0.Locked=true @@ -63,10 +135,34 @@ PE1.GPIOParameters=GPIO_Label PE1.GPIO_Label=LPA_PWR_EN PE1.Locked=true PE1.Signal=GPIO_Output +PE2.GPIOParameters=GPIO_Label +PE2.GPIO_Label=VCO_CE +PE2.Locked=true +PE2.Signal=GPIO_Output +PE3.GPIOParameters=GPIO_Label +PE3.GPIO_Label=VCO_LE +PE3.Locked=true +PE3.Signal=GPIO_Output +PE4.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultOutputPP +PE4.GPIO_Label=VGA_CS_N +PE4.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD +PE4.GPIO_PuPd=GPIO_NOPULL +PE4.Locked=true +PE4.Signal=GPIO_Output +PE5.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultOutputPP +PE5.GPIO_Label=TEMP_CS_N +PE5.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD +PE5.GPIO_PuPd=GPIO_NOPULL +PE5.Locked=true +PE5.Signal=GPIO_Output PE7.GPIOParameters=GPIO_Label -PE7.GPIO_Label=DEBUG +PE7.GPIO_Label=DEBUG2 PE7.Locked=true PE7.Signal=GPIO_Output +PE8.GPIOParameters=GPIO_Label +PE8.GPIO_Label=DEBUG1 +PE8.Locked=true +PE8.Signal=GPIO_Output PF0-OSC_IN\ (PF0).GPIOParameters=GPIO_Label PF0-OSC_IN\ (PF0).GPIO_Label=P6V_SCATTER_PWR_EN PF0-OSC_IN\ (PF0).Locked=true @@ -75,6 +171,10 @@ PF1-OSC_OUT\ (PF1).GPIOParameters=GPIO_Label PF1-OSC_OUT\ (PF1).GPIO_Label=P6V_SCATTER_HSD_DIAG_EN PF1-OSC_OUT\ (PF1).Locked=true PF1-OSC_OUT\ (PF1).Signal=GPIO_Output +PF10.GPIOParameters=GPIO_Label +PF10.GPIO_Label=P6V_HSD_ONE_SEH +PF10.Locked=true +PF10.Signal=GPIO_Output PF11.GPIOParameters=GPIO_Label PF11.GPIO_Label=VGA_PWR_EN PF11.Locked=true @@ -83,6 +183,19 @@ PF12.GPIOParameters=GPIO_Label PF12.GPIO_Label=VCO_PWR_EN PF12.Locked=true PF12.Signal=GPIO_Output +PF13.GPIOParameters=PinState,GPIO_Label +PF13.GPIO_Label=P6V_HSD_TWO_DIAG_EN +PF13.Locked=true +PF13.PinState=GPIO_PIN_RESET +PF13.Signal=GPIO_Output +PF8.GPIOParameters=GPIO_Label +PF8.GPIO_Label=P6V_PG +PF8.Locked=true +PF8.Signal=GPIO_Input +PF9.GPIOParameters=GPIO_Label +PF9.GPIO_Label=P6V_HSD_ONE_SEL +PF9.Locked=true +PF9.Signal=GPIO_Output PinOutPanel.RotationAngle=0 ProjectManager.AskForMigrate=true ProjectManager.BackupPrevious=false @@ -95,8 +208,8 @@ ProjectManager.DefaultFWLocation=true ProjectManager.DeletePrevious=true ProjectManager.DeviceId=STM32G0B1VETx ProjectManager.FirmwarePackage=STM32Cube FW_G0 V1.6.3 -ProjectManager.FreePinsContext= ProjectManager.FreePins=false +ProjectManager.FreePinsContext= ProjectManager.HalAssertFull=false ProjectManager.HeapSize=0x200 ProjectManager.KeepUserCode=true @@ -116,7 +229,7 @@ ProjectManager.ToolChainLocation= ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=true -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USB_DRD_FS_PCD_Init-USB_DRD_FS-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USB_Device_Init-USB_DEVICE-false-HAL-false RCC.AHBFreq_Value=16000000 RCC.APBFreq_Value=16000000 RCC.APBTimFreq_Value=16000000 @@ -149,20 +262,25 @@ RCC.PLLQoutputFreq_Value=64000000 RCC.PLLRCLKFreq_Value=64000000 RCC.PWRFreq_Value=16000000 RCC.SYSCLKFreq_VALUE=16000000 -RCC.TIM1Freq_Value=16000000 RCC.TIM15Freq_Value=16000000 +RCC.TIM1Freq_Value=16000000 RCC.USART1Freq_Value=16000000 RCC.USART2Freq_Value=16000000 RCC.USART3Freq_Value=16000000 RCC.USBFreq_Value=48000000 RCC.VCOInputFreq_Value=16000000 RCC.VCOOutputFreq_Value=128000000 +USB_DEVICE.CLASS_NAME_FS=CDC +USB_DEVICE.IPParameters=VirtualMode,VirtualModeFS,CLASS_NAME_FS +USB_DEVICE.VirtualMode=Cdc +USB_DEVICE.VirtualModeFS=Cdc_FS VP_FREERTOS_VS_CMSIS_V1.Mode=CMSIS_V1 VP_FREERTOS_VS_CMSIS_V1.Signal=FREERTOS_VS_CMSIS_V1 VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals VP_SYS_VS_tim1.Mode=TIM1 VP_SYS_VS_tim1.Signal=SYS_VS_tim1 +VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Mode=CDC_FS +VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Signal=USB_DEVICE_VS_USB_DEVICE_CDC_FS board=custom rtos.0.ip=FREERTOS -#MicroXplorer Configuration settings - do not modify diff --git a/boards/motherboard/src/app_freertos.c b/boards/motherboard/src/app_freertos.c new file mode 100644 index 0000000..1abe2f0 --- /dev/null +++ b/boards/motherboard/src/app_freertos.c @@ -0,0 +1,140 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * File Name : app_freertos.c + * Description : Code for freertos applications + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "FreeRTOS.h" +#include "task.h" +#include "main.h" +#include "cmsis_os.h" + +/* Private includes ----------------------------------------------------------*/ +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* USER CODE BEGIN PTD */ + +/* USER CODE END PTD */ + +/* Private define ------------------------------------------------------------*/ +/* USER CODE BEGIN PD */ + +/* USER CODE END PD */ + +/* Private macro -------------------------------------------------------------*/ +/* USER CODE BEGIN PM */ + +/* USER CODE END PM */ + +/* Private variables ---------------------------------------------------------*/ +/* USER CODE BEGIN Variables */ + +/* USER CODE END Variables */ +osThreadId defaultTaskHandle; +uint32_t defaultTaskBuffer[ 128 ]; +osStaticThreadDef_t defaultTaskControlBlock; + +/* Private function prototypes -----------------------------------------------*/ +/* USER CODE BEGIN FunctionPrototypes */ + +/* USER CODE END FunctionPrototypes */ + +void StartDefaultTask(void const * argument); + +void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */ + +/* GetIdleTaskMemory prototype (linked to static allocation support) */ +void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ); + +/* USER CODE BEGIN GET_IDLE_TASK_MEMORY */ +static StaticTask_t xIdleTaskTCBBuffer; +static StackType_t xIdleStack[configMINIMAL_STACK_SIZE]; + +void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ) +{ + *ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer; + *ppxIdleTaskStackBuffer = &xIdleStack[0]; + *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; + /* place for user code */ +} +/* USER CODE END GET_IDLE_TASK_MEMORY */ + +/** + * @brief FreeRTOS initialization + * @param None + * @retval None + */ +void MX_FREERTOS_Init(void) { + /* USER CODE BEGIN Init */ + + /* USER CODE END Init */ + + /* USER CODE BEGIN RTOS_MUTEX */ + /* add mutexes, ... */ + /* USER CODE END RTOS_MUTEX */ + + /* USER CODE BEGIN RTOS_SEMAPHORES */ + /* add semaphores, ... */ + /* USER CODE END RTOS_SEMAPHORES */ + + /* USER CODE BEGIN RTOS_TIMERS */ + /* start timers, add new ones, ... */ + /* USER CODE END RTOS_TIMERS */ + + /* USER CODE BEGIN RTOS_QUEUES */ + /* add queues, ... */ + /* USER CODE END RTOS_QUEUES */ + + /* Create the thread(s) */ + /* definition and creation of defaultTask */ + osThreadStaticDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128, defaultTaskBuffer, &defaultTaskControlBlock); + defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL); + + /* USER CODE BEGIN RTOS_THREADS */ + /* add threads, ... */ + /* USER CODE END RTOS_THREADS */ + +} + +/* USER CODE BEGIN Header_StartDefaultTask */ +/** + * @brief Function implementing the defaultTask thread. + * @param argument: Not used + * @retval None + */ +/* USER CODE END Header_StartDefaultTask */ +void StartDefaultTask(void const * argument) +{ + /* init code for USB_Device */ + MX_USB_Device_Init(); + /* USER CODE BEGIN StartDefaultTask */ + /* Infinite loop */ + for(;;) + { + osDelay(1); + } + /* USER CODE END StartDefaultTask */ +} + +/* Private application code --------------------------------------------------*/ +/* USER CODE BEGIN Application */ + +/* USER CODE END Application */ + diff --git a/boards/motherboard/src/gpio.c b/boards/motherboard/src/gpio.c index 64ce0af..e611891 100644 --- a/boards/motherboard/src/gpio.c +++ b/boards/motherboard/src/gpio.c @@ -33,40 +33,37 @@ /* USER CODE END 1 */ /** Configure pins - */ -void MX_GPIO_Init(void) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; +*/ +void MX_GPIO_Init(void) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOF_CLK_ENABLE(); + __HAL_RCC_GPIOE_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOF_CLK_ENABLE(); - __HAL_RCC_GPIOE_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOF, P6V_SCATTER_PWR_EN_Pin|P6V_SCATTER_HSD_DIAG_EN_Pin|VGA_PWR_EN_Pin|VCO_PWR_EN_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOF, - P6V_SCATTER_PWR_EN_Pin | P6V_SCATTER_HSD_DIAG_EN_Pin | - VGA_PWR_EN_Pin | VCO_PWR_EN_Pin, - GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOE, DEBUG_Pin|GEN_EN_Pin|LPA_PWR_EN_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOE, DEBUG_Pin | GEN_EN_Pin | LPA_PWR_EN_Pin, - GPIO_PIN_RESET); + /*Configure GPIO pins : P6V_SCATTER_PWR_EN_Pin P6V_SCATTER_HSD_DIAG_EN_Pin VGA_PWR_EN_Pin VCO_PWR_EN_Pin */ + GPIO_InitStruct.Pin = P6V_SCATTER_PWR_EN_Pin|P6V_SCATTER_HSD_DIAG_EN_Pin|VGA_PWR_EN_Pin|VCO_PWR_EN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); - /*Configure GPIO pins : P6V_SCATTER_PWR_EN_Pin P6V_SCATTER_HSD_DIAG_EN_Pin - * VGA_PWR_EN_Pin VCO_PWR_EN_Pin */ - GPIO_InitStruct.Pin = P6V_SCATTER_PWR_EN_Pin | P6V_SCATTER_HSD_DIAG_EN_Pin | - VGA_PWR_EN_Pin | VCO_PWR_EN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); + /*Configure GPIO pins : DEBUG_Pin GEN_EN_Pin LPA_PWR_EN_Pin */ + GPIO_InitStruct.Pin = DEBUG_Pin|GEN_EN_Pin|LPA_PWR_EN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); - /*Configure GPIO pins : DEBUG_Pin GEN_EN_Pin LPA_PWR_EN_Pin */ - GPIO_InitStruct.Pin = DEBUG_Pin | GEN_EN_Pin | LPA_PWR_EN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); } /* USER CODE BEGIN 2 */ diff --git a/boards/motherboard/src/main.c b/boards/motherboard/src/main.c index 04883ed..c2504a6 100644 --- a/boards/motherboard/src/main.c +++ b/boards/motherboard/src/main.c @@ -18,10 +18,9 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" - #include "cmsis_os.h" +#include "usb_device.h" #include "gpio.h" -#include "usb_drd_fs.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -62,36 +61,35 @@ void MX_FREERTOS_Init(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ -int main(void) { - /* USER CODE BEGIN 1 */ + * @brief The application entry point. + * @retval int + */ +int main(void) +{ + + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU - * Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the - * Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_USB_DRD_FS_PCD_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + /* USER CODE BEGIN 2 */ // HAL_GPIO_WritePin(VCO_PWR_EN_GPIO_Port, VCO_PWR_EN_Pin, GPIO_PIN_RESET); // HAL_GPIO_WritePin(VGA_PWR_EN_GPIO_Port, VGA_PWR_EN_Pin, GPIO_PIN_RESET); // HAL_GPIO_WritePin(LPA_PWR_EN_GPIO_Port, LPA_PWR_EN_Pin, GPIO_PIN_RESET); @@ -100,63 +98,65 @@ int main(void) { // GPIO_PIN_SET); // HAL_GPIO_WritePin(P6V_SCATTER_HSD_DIAG_EN_GPIO_Port, // P6V_SCATTER_HSD_DIAG_EN_Pin, GPIO_PIN_RESET); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Call init function for freertos objects (in cmsis_os2.c) */ - MX_FREERTOS_Init(); + /* Call init function for freertos objects (in cmsis_os2.c) */ + MX_FREERTOS_Init(); - /* Start scheduler */ - osKernelStart(); + /* Start scheduler */ + osKernelStart(); - /* We should never get here as control is now taken by the scheduler */ + /* We should never get here as control is now taken by the scheduler */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ -void SystemClock_Config(void) { - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - - /** Configure the main internal regulator output voltage - */ - HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); - - /** Initializes the RCC Oscillators according to the specified parameters - * in the RCC_OscInitTypeDef structure. - */ - RCC_OscInitStruct.OscillatorType = - RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSI48; - RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; - RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; - RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { - Error_Handler(); - } - - /** Initializes the CPU, AHB and APB buses clocks - */ - RCC_ClkInitStruct.ClockType = - RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; - - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) { - Error_Handler(); - } + * @brief System Clock Configuration + * @retval None + */ +void SystemClock_Config(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + + /** Configure the main internal regulator output voltage + */ + HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); + + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI48; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; + RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; + RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) + { + Error_Handler(); + } + + /** Initializes the CPU, AHB and APB buses clocks + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK + |RCC_CLOCKTYPE_PCLK1; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) + { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -164,51 +164,55 @@ void SystemClock_Config(void) { /* USER CODE END 4 */ /** - * @brief Period elapsed callback in non blocking mode - * @note This function is called when TIM1 interrupt took place, inside - * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment - * a global variable "uwTick" used as application time base. - * @param htim : TIM handle - * @retval None - */ -void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim) { - /* USER CODE BEGIN Callback 0 */ - - /* USER CODE END Callback 0 */ - if (htim->Instance == TIM1) { - HAL_IncTick(); - } - /* USER CODE BEGIN Callback 1 */ - - /* USER CODE END Callback 1 */ + * @brief Period elapsed callback in non blocking mode + * @note This function is called when TIM1 interrupt took place, inside + * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment + * a global variable "uwTick" used as application time base. + * @param htim : TIM handle + * @retval None + */ +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) +{ + /* USER CODE BEGIN Callback 0 */ + + /* USER CODE END Callback 0 */ + if (htim->Instance == TIM1) + { + HAL_IncTick(); + } + /* USER CODE BEGIN Callback 1 */ + + /* USER CODE END Callback 1 */ } /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + * @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 */ + /* 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 */ + * @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 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/boards/motherboard/src/stm32g0xx_hal_msp.c b/boards/motherboard/src/stm32g0xx_hal_msp.c index 8718647..a720f89 100644 --- a/boards/motherboard/src/stm32g0xx_hal_msp.c +++ b/boards/motherboard/src/stm32g0xx_hal_msp.c @@ -57,28 +57,29 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ -void HAL_MspInit(void) { - /* USER CODE BEGIN MspInit 0 */ + * Initializes the Global MSP. + */ +void HAL_MspInit(void) +{ + + /* 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*/ - /* PendSV_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(PendSV_IRQn, 3, 0); + /* System interrupt init*/ + /* PendSV_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(PendSV_IRQn, 3, 0); - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD1_STROBE | - SYSCFG_CFGR1_UCPD2_STROBE); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD1_STROBE | SYSCFG_CFGR1_UCPD2_STROBE); - /* 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/boards/motherboard/src/stm32g0xx_hal_timebase_tim.c b/boards/motherboard/src/stm32g0xx_hal_timebase_tim.c index 10b4a05..603c8f5 100644 --- a/boards/motherboard/src/stm32g0xx_hal_timebase_tim.c +++ b/boards/motherboard/src/stm32g0xx_hal_timebase_tim.c @@ -25,102 +25,113 @@ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ -TIM_HandleTypeDef htim1; +TIM_HandleTypeDef htim1; /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /** - * @brief This function configures the TIM1 as a time base source. - * The time source is configured to have 1ms time base with a dedicated - * Tick interrupt priority. - * @note This function is called automatically at the beginning of program - * after reset by HAL_Init() or at any time when clock is configured, by - * HAL_RCC_ClockConfig(). - * @param TickPriority: Tick interrupt priority. - * @retval HAL status - */ -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - RCC_ClkInitTypeDef clkconfig; - uint32_t uwTimclock, uwAPB1Prescaler; - uint32_t uwPrescalerValue; - uint32_t pFLatency; - - HAL_StatusTypeDef status = HAL_OK; - - /* Enable TIM1 clock */ - __HAL_RCC_TIM1_CLK_ENABLE(); - - /* Get clock configuration */ - HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); - - /* Get APB1 prescaler */ - uwAPB1Prescaler = clkconfig.APB1CLKDivider; - /* Compute TIM1 clock */ - if (uwAPB1Prescaler == RCC_HCLK_DIV1) { - uwTimclock = HAL_RCC_GetPCLK1Freq(); - } else { - uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq(); - } + * @brief This function configures the TIM1 as a time base source. + * The time source is configured to have 1ms time base with a dedicated + * Tick interrupt priority. + * @note This function is called automatically at the beginning of program after + * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). + * @param TickPriority: Tick interrupt priority. + * @retval HAL status + */ +HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) +{ + RCC_ClkInitTypeDef clkconfig; + uint32_t uwTimclock, uwAPB1Prescaler; + uint32_t uwPrescalerValue; + uint32_t pFLatency; + + HAL_StatusTypeDef status = HAL_OK; + + /* Enable TIM1 clock */ + __HAL_RCC_TIM1_CLK_ENABLE(); + + /* Get clock configuration */ + HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); + + /* Get APB1 prescaler */ + uwAPB1Prescaler = clkconfig.APB1CLKDivider; + /* Compute TIM1 clock */ + if (uwAPB1Prescaler == RCC_HCLK_DIV1) + { + uwTimclock = HAL_RCC_GetPCLK1Freq(); + } + else + { + uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq(); + } + + /* Compute the prescaler value to have TIM1 counter clock equal to 1MHz */ + uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U); - /* Compute the prescaler value to have TIM1 counter clock equal to 1MHz */ - uwPrescalerValue = (uint32_t)((uwTimclock / 1000000U) - 1U); - - /* Initialize TIM1 */ - htim1.Instance = TIM1; - - /* Initialize TIMx peripheral as follow: - * Period = [(TIM1CLK/1000) - 1]. to have a (1/1000) s time base. - * Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. - * ClockDivision = 0 - * Counter direction = Up - */ - htim1.Init.Period = (1000000U / 1000U) - 1U; - htim1.Init.Prescaler = uwPrescalerValue; - htim1.Init.ClockDivision = 0; - htim1.Init.CounterMode = TIM_COUNTERMODE_UP; - htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - - status = HAL_TIM_Base_Init(&htim1); - if (status == HAL_OK) { - /* Start the TIM time Base generation in interrupt mode */ - status = HAL_TIM_Base_Start_IT(&htim1); - if (status == HAL_OK) { - /* Enable the TIM1 global Interrupt */ - HAL_NVIC_EnableIRQ(TIM1_BRK_UP_TRG_COM_IRQn); - /* Configure the SysTick IRQ priority */ - if (TickPriority < (1UL << __NVIC_PRIO_BITS)) { - /* Configure the TIM IRQ priority */ - HAL_NVIC_SetPriority(TIM1_BRK_UP_TRG_COM_IRQn, TickPriority, - 0U); - uwTickPrio = TickPriority; - } else { - status = HAL_ERROR; - } - } + /* Initialize TIM1 */ + htim1.Instance = TIM1; + + /* Initialize TIMx peripheral as follow: + * Period = [(TIM1CLK/1000) - 1]. to have a (1/1000) s time base. + * Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. + * ClockDivision = 0 + * Counter direction = Up + */ + htim1.Init.Period = (1000000U / 1000U) - 1U; + htim1.Init.Prescaler = uwPrescalerValue; + htim1.Init.ClockDivision = 0; + htim1.Init.CounterMode = TIM_COUNTERMODE_UP; + htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + + status = HAL_TIM_Base_Init(&htim1); + if (status == HAL_OK) + { + + /* Start the TIM time Base generation in interrupt mode */ + status = HAL_TIM_Base_Start_IT(&htim1); + if (status == HAL_OK) + { + /* Enable the TIM1 global Interrupt */ + HAL_NVIC_EnableIRQ(TIM1_BRK_UP_TRG_COM_IRQn); + /* Configure the SysTick IRQ priority */ + if (TickPriority < (1UL << __NVIC_PRIO_BITS)) + { + /* Configure the TIM IRQ priority */ + HAL_NVIC_SetPriority(TIM1_BRK_UP_TRG_COM_IRQn, TickPriority, 0U); + uwTickPrio = TickPriority; + } + else + { + status = HAL_ERROR; + } } + } - /* Return function status */ - return status; + /* Return function status */ + return status; } /** - * @brief Suspend Tick increment. - * @note Disable the tick increment by disabling TIM1 update interrupt. - * @param None - * @retval None - */ -void HAL_SuspendTick(void) { - /* Disable TIM1 update Interrupt */ - __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_UPDATE); + * @brief Suspend Tick increment. + * @note Disable the tick increment by disabling TIM1 update interrupt. + * @param None + * @retval None + */ +void HAL_SuspendTick(void) +{ + /* Disable TIM1 update Interrupt */ + __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_UPDATE); } /** - * @brief Resume Tick increment. - * @note Enable the tick increment by Enabling TIM1 update interrupt. - * @param None - * @retval None - */ -void HAL_ResumeTick(void) { - /* Enable TIM1 Update interrupt */ - __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE); + * @brief Resume Tick increment. + * @note Enable the tick increment by Enabling TIM1 update interrupt. + * @param None + * @retval None + */ +void HAL_ResumeTick(void) +{ + /* Enable TIM1 Update interrupt */ + __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE); } + diff --git a/boards/motherboard/src/stm32g0xx_it.c b/boards/motherboard/src/stm32g0xx_it.c index 40dd304..92d50bc 100644 --- a/boards/motherboard/src/stm32g0xx_it.c +++ b/boards/motherboard/src/stm32g0xx_it.c @@ -18,9 +18,8 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "stm32g0xx_it.h" - #include "main.h" +#include "stm32g0xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -63,32 +62,35 @@ extern TIM_HandleTypeDef htim1; /* USER CODE END EV */ /******************************************************************************/ -/* Cortex-M0+ Processor Interruption and Exception Handlers */ +/* Cortex-M0+ 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 */ + * @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 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 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 */ + } } /******************************************************************************/ @@ -99,17 +101,17 @@ void HardFault_Handler(void) { /******************************************************************************/ /** - * @brief This function handles TIM1 break, update, trigger and commutation - * interrupts. - */ -void TIM1_BRK_UP_TRG_COM_IRQHandler(void) { - /* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 0 */ + * @brief This function handles TIM1 break, update, trigger and commutation interrupts. + */ +void TIM1_BRK_UP_TRG_COM_IRQHandler(void) +{ + /* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 0 */ - /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 0 */ - HAL_TIM_IRQHandler(&htim1); - /* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 1 */ + /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 0 */ + HAL_TIM_IRQHandler(&htim1); + /* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 1 */ - /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 1 */ + /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/boards/motherboard/src/tasks.cpp b/boards/motherboard/src/tasks.cpp index 3ad725a..5298225 100644 --- a/boards/motherboard/src/tasks.cpp +++ b/boards/motherboard/src/tasks.cpp @@ -39,6 +39,9 @@ void MX_FREERTOS_Init() { vTaskStartScheduler(); } +/* static allocation is used for freeRTOS, so the application must +provide an implementation of vApplicationGetIdleTaskMemory() to provide +the memory that is used by the Idle task. */ extern "C" { void vApplicationGetIdleTaskMemory(StaticTask_t** ppxIdleTaskTCBBuffer, StackType_t** ppxIdleTaskStackBuffer, diff --git a/boards/motherboard/src/usb_device.c b/boards/motherboard/src/usb_device.c new file mode 100644 index 0000000..04c0f19 --- /dev/null +++ b/boards/motherboard/src/usb_device.c @@ -0,0 +1,97 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : usb_device.c + * @version : v3.0_Cube + * @brief : This file implements the USB Device + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ + +#include "usb_device.h" +#include "usbd_core.h" +#include "usbd_desc.h" +#include "usbd_cdc.h" +#include "usbd_cdc_if.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* USER CODE BEGIN PV */ +/* Private variables ---------------------------------------------------------*/ + +/* USER CODE END PV */ + +/* USER CODE BEGIN PFP */ +/* Private function prototypes -----------------------------------------------*/ + +/* USER CODE END PFP */ + +extern void Error_Handler(void); +/* USB Device Core handle declaration. */ +USBD_HandleTypeDef hUsbDeviceFS; +extern USBD_DescriptorsTypeDef CDC_Desc; + +/* + * -- Insert your variables declaration here -- + */ +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/* + * -- Insert your external function declaration here -- + */ +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + +/** + * Init USB device Library, add supported class and start the library + * @retval None + */ +void MX_USB_Device_Init(void) +{ + /* USER CODE BEGIN USB_Device_Init_PreTreatment */ + + /* USER CODE END USB_Device_Init_PreTreatment */ + + /* Init Device Library, add supported class and start the library. */ + if (USBD_Init(&hUsbDeviceFS, &CDC_Desc, DEVICE_FS) != USBD_OK) { + Error_Handler(); + } + if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) { + Error_Handler(); + } + if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) { + Error_Handler(); + } + if (USBD_Start(&hUsbDeviceFS) != USBD_OK) { + Error_Handler(); + } + /* USER CODE BEGIN USB_Device_Init_PostTreatment */ + + /* USER CODE END USB_Device_Init_PostTreatment */ +} + +/** + * @} + */ + +/** + * @} + */ + diff --git a/boards/motherboard/src/usb_drd_fs.c b/boards/motherboard/src/usb_drd_fs.c deleted file mode 100644 index a51e85d..0000000 --- a/boards/motherboard/src/usb_drd_fs.c +++ /dev/null @@ -1,106 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file usb_drd_fs.c - * @brief This file provides code for the configuration - * of the USB_DRD_FS instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Includes ------------------------------------------------------------------*/ -#include "usb_drd_fs.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -PCD_HandleTypeDef hpcd_USB_DRD_FS; - -/* USB_DRD_FS init function */ - -void MX_USB_DRD_FS_PCD_Init(void) { - /* USER CODE BEGIN USB_DRD_FS_Init 0 */ - - /* USER CODE END USB_DRD_FS_Init 0 */ - - /* USER CODE BEGIN USB_DRD_FS_Init 1 */ - - /* USER CODE END USB_DRD_FS_Init 1 */ - hpcd_USB_DRD_FS.Instance = USB_DRD_FS; - hpcd_USB_DRD_FS.Init.dev_endpoints = 8; - hpcd_USB_DRD_FS.Init.Host_channels = 8; - hpcd_USB_DRD_FS.Init.speed = PCD_SPEED_FULL; - hpcd_USB_DRD_FS.Init.phy_itface = PCD_PHY_EMBEDDED; - hpcd_USB_DRD_FS.Init.Sof_enable = DISABLE; - hpcd_USB_DRD_FS.Init.low_power_enable = DISABLE; - hpcd_USB_DRD_FS.Init.lpm_enable = DISABLE; - hpcd_USB_DRD_FS.Init.battery_charging_enable = DISABLE; - hpcd_USB_DRD_FS.Init.vbus_sensing_enable = DISABLE; - hpcd_USB_DRD_FS.Init.bulk_doublebuffer_enable = DISABLE; - hpcd_USB_DRD_FS.Init.iso_singlebuffer_enable = DISABLE; - if (HAL_PCD_Init(&hpcd_USB_DRD_FS) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN USB_DRD_FS_Init 2 */ - - /* USER CODE END USB_DRD_FS_Init 2 */ -} - -void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) { - RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; - if (pcdHandle->Instance == USB_DRD_FS) { - /* USER CODE BEGIN USB_DRD_FS_MspInit 0 */ - - /* USER CODE END USB_DRD_FS_MspInit 0 */ - - /** Initializes the peripherals clocks - */ - PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; - PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; - if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { - Error_Handler(); - } - - /* USB_DRD_FS clock enable */ - __HAL_RCC_USB_CLK_ENABLE(); - - /* Enable VDDUSB */ - if (__HAL_RCC_PWR_IS_CLK_DISABLED()) { - __HAL_RCC_PWR_CLK_ENABLE(); - HAL_PWREx_EnableVddUSB(); - __HAL_RCC_PWR_CLK_DISABLE(); - } else { - HAL_PWREx_EnableVddUSB(); - } - /* USER CODE BEGIN USB_DRD_FS_MspInit 1 */ - - /* USER CODE END USB_DRD_FS_MspInit 1 */ - } -} - -void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) { - if (pcdHandle->Instance == USB_DRD_FS) { - /* USER CODE BEGIN USB_DRD_FS_MspDeInit 0 */ - - /* USER CODE END USB_DRD_FS_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_USB_CLK_DISABLE(); - /* USER CODE BEGIN USB_DRD_FS_MspDeInit 1 */ - - /* USER CODE END USB_DRD_FS_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/boards/motherboard/src/usbd_cdc_if.c b/boards/motherboard/src/usbd_cdc_if.c new file mode 100644 index 0000000..fe0e8e1 --- /dev/null +++ b/boards/motherboard/src/usbd_cdc_if.c @@ -0,0 +1,329 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : usbd_cdc_if.c + * @version : v3.0_Cube + * @brief : Usb device for Virtual Com Port. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_cdc_if.h" + +/* USER CODE BEGIN INCLUDE */ + +/* USER CODE END INCLUDE */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ + +/* USER CODE BEGIN PV */ +/* Private variables ---------------------------------------------------------*/ + +/* USER CODE END PV */ + +/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY + * @brief Usb device library. + * @{ + */ + +/** @addtogroup USBD_CDC_IF + * @{ + */ + +/** @defgroup USBD_CDC_IF_Private_TypesDefinitions USBD_CDC_IF_Private_TypesDefinitions + * @brief Private types. + * @{ + */ + +/* USER CODE BEGIN PRIVATE_TYPES */ + +/* USER CODE END PRIVATE_TYPES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Private_Defines USBD_CDC_IF_Private_Defines + * @brief Private defines. + * @{ + */ + +/* USER CODE BEGIN PRIVATE_DEFINES */ +/* USER CODE END PRIVATE_DEFINES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Private_Macros USBD_CDC_IF_Private_Macros + * @brief Private macros. + * @{ + */ + +/* USER CODE BEGIN PRIVATE_MACRO */ + +/* USER CODE END PRIVATE_MACRO */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Private_Variables USBD_CDC_IF_Private_Variables + * @brief Private variables. + * @{ + */ +/* Create buffer for reception and transmission */ +/* It's up to user to redefine and/or remove those define */ +/** Received data over USB are stored in this buffer */ +uint8_t UserRxBufferFS[APP_RX_DATA_SIZE]; + +/** Data to send over USB CDC are stored in this buffer */ +uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; + +/* USER CODE BEGIN PRIVATE_VARIABLES */ + +/* USER CODE END PRIVATE_VARIABLES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables + * @brief Public variables. + * @{ + */ + +extern USBD_HandleTypeDef hUsbDeviceFS; + +/* USER CODE BEGIN EXPORTED_VARIABLES */ + +/* USER CODE END EXPORTED_VARIABLES */ + +/** + * @} + */ + +/** @defgroup USBD_CDC_IF_Private_FunctionPrototypes USBD_CDC_IF_Private_FunctionPrototypes + * @brief Private functions declaration. + * @{ + */ + +static int8_t CDC_Init_FS(void); +static int8_t CDC_DeInit_FS(void); +static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length); +static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len); +static int8_t CDC_TransmitCplt_FS(uint8_t *pbuf, uint32_t *Len, uint8_t epnum); + +/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ + +/* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */ + +/** + * @} + */ + +USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = +{ + CDC_Init_FS, + CDC_DeInit_FS, + CDC_Control_FS, + CDC_Receive_FS, + CDC_TransmitCplt_FS +}; + +/* Private functions ---------------------------------------------------------*/ +/** + * @brief Initializes the CDC media low layer over the FS USB IP + * @retval USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_Init_FS(void) +{ + /* USER CODE BEGIN 3 */ + /* Set Application Buffers */ + USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0); + USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS); + return (USBD_OK); + /* USER CODE END 3 */ +} + +/** + * @brief DeInitializes the CDC media low layer + * @retval USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_DeInit_FS(void) +{ + /* USER CODE BEGIN 4 */ + return (USBD_OK); + /* USER CODE END 4 */ +} + +/** + * @brief Manage the CDC class requests + * @param cmd: Command code + * @param pbuf: Buffer containing command data (request parameters) + * @param length: Number of data to be sent (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) +{ + /* USER CODE BEGIN 5 */ + switch(cmd) + { + case CDC_SEND_ENCAPSULATED_COMMAND: + + break; + + case CDC_GET_ENCAPSULATED_RESPONSE: + + break; + + case CDC_SET_COMM_FEATURE: + + break; + + case CDC_GET_COMM_FEATURE: + + break; + + case CDC_CLEAR_COMM_FEATURE: + + break; + + /*******************************************************************************/ + /* Line Coding Structure */ + /*-----------------------------------------------------------------------------*/ + /* Offset | Field | Size | Value | Description */ + /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/ + /* 4 | bCharFormat | 1 | Number | Stop bits */ + /* 0 - 1 Stop bit */ + /* 1 - 1.5 Stop bits */ + /* 2 - 2 Stop bits */ + /* 5 | bParityType | 1 | Number | Parity */ + /* 0 - None */ + /* 1 - Odd */ + /* 2 - Even */ + /* 3 - Mark */ + /* 4 - Space */ + /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ + /*******************************************************************************/ + case CDC_SET_LINE_CODING: + + break; + + case CDC_GET_LINE_CODING: + + break; + + case CDC_SET_CONTROL_LINE_STATE: + + break; + + case CDC_SEND_BREAK: + + break; + + default: + break; + } + + return (USBD_OK); + /* USER CODE END 5 */ +} + +/** + * @brief Data received over USB OUT endpoint are sent over CDC interface + * through this function. + * + * @note + * This function will issue a NAK packet on any OUT packet received on + * USB endpoint until exiting this function. If you exit this function + * before transfer is complete on CDC interface (ie. using DMA controller) + * it will result in receiving more data while previous ones are still + * not sent. + * + * @param Buf: Buffer of data to be received + * @param Len: Number of data received (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) +{ + /* USER CODE BEGIN 6 */ + USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); + USBD_CDC_ReceivePacket(&hUsbDeviceFS); + return (USBD_OK); + /* USER CODE END 6 */ +} + +/** + * @brief CDC_Transmit_FS + * Data to send over USB IN endpoint are sent over CDC interface + * through this function. + * @note + * + * + * @param Buf: Buffer of data to be sent + * @param Len: Number of data to be sent (in bytes) + * @retval USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY + */ +uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) +{ + uint8_t result = USBD_OK; + /* USER CODE BEGIN 7 */ + USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData; + if (hcdc->TxState != 0){ + return USBD_BUSY; + } + USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len); + result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); + /* USER CODE END 7 */ + return result; +} + +/** + * @brief CDC_TransmitCplt_FS + * Data transmitted callback + * + * @note + * This function is IN transfer complete callback used to inform user that + * the submitted Data is successfully sent over USB. + * + * @param Buf: Buffer of data to be received + * @param Len: Number of data received (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_TransmitCplt_FS(uint8_t *Buf, uint32_t *Len, uint8_t epnum) +{ + uint8_t result = USBD_OK; + /* USER CODE BEGIN 13 */ + UNUSED(Buf); + UNUSED(Len); + UNUSED(epnum); + /* USER CODE END 13 */ + return result; +} + +/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ + +/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ + +/** + * @} + */ + +/** + * @} + */ + diff --git a/boards/motherboard/src/usbd_conf.c b/boards/motherboard/src/usbd_conf.c new file mode 100644 index 0000000..c401db4 --- /dev/null +++ b/boards/motherboard/src/usbd_conf.c @@ -0,0 +1,794 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : usbd_conf.c + * @version : v3.0_Cube + * @brief : This file implements the board support package for the USB device library + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32g0xx.h" +#include "stm32g0xx_hal.h" +#include "usbd_def.h" +#include "usbd_core.h" + +#include "usbd_cdc.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ + +/* Private variables ---------------------------------------------------------*/ +/* USER CODE BEGIN PV */ + +/* USER CODE END PV */ + +PCD_HandleTypeDef hpcd_USB_DRD_FS; +void Error_Handler(void); + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/* Exported function prototypes ----------------------------------------------*/ + +/* USER CODE BEGIN PFP */ +/* Private function prototypes -----------------------------------------------*/ + +/* USER CODE END PFP */ + +/* Private functions ---------------------------------------------------------*/ +static USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status); +/* USER CODE BEGIN 1 */ +static void SystemClockConfig_Resume(void); + +/* USER CODE END 1 */ +extern void SystemClock_Config(void); + +/******************************************************************************* + LL Driver Callbacks (PCD -> USB Device Library) +*******************************************************************************/ +/* MSP Init */ + +void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) +{ + RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; + if(pcdHandle->Instance==USB_DRD_FS) + { + /* USER CODE BEGIN USB_DRD_FS_MspInit 0 */ + + /* USER CODE END USB_DRD_FS_MspInit 0 */ + + /** Initializes the peripherals clocks + */ + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; + PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) + { + Error_Handler(); + } + + /* Peripheral clock enable */ + __HAL_RCC_USB_CLK_ENABLE(); + + /* Enable VDDUSB */ + if(__HAL_RCC_PWR_IS_CLK_DISABLED()) + { + __HAL_RCC_PWR_CLK_ENABLE(); + HAL_PWREx_EnableVddUSB(); + __HAL_RCC_PWR_CLK_DISABLE(); + } + else + { + HAL_PWREx_EnableVddUSB(); + } + /* USER CODE BEGIN USB_DRD_FS_MspInit 1 */ + + /* USER CODE END USB_DRD_FS_MspInit 1 */ + } +} + +void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) +{ + if(pcdHandle->Instance==USB_DRD_FS) + { + /* USER CODE BEGIN USB_DRD_FS_MspDeInit 0 */ + + /* USER CODE END USB_DRD_FS_MspDeInit 0 */ + /* Disable Peripheral clock */ + __HAL_RCC_USB_CLK_DISABLE(); + /* USER CODE BEGIN USB_DRD_FS_MspDeInit 1 */ + + /* USER CODE END USB_DRD_FS_MspDeInit 1 */ + } +} + +/** + * @brief Setup stage callback + * @param hpcd: PCD handle + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) +#else +void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + /* USER CODE BEGIN HAL_PCD_SetupStageCallback_PreTreatment */ + + /* USER CODE END HAL_PCD_SetupStageCallback_PreTreatment */ + USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup); + /* USER CODE BEGIN HAL_PCD_SetupStageCallback_PostTreatment */ + + /* USER CODE END HAL_PCD_SetupStageCallback_PostTreatment */ +} + +/** + * @brief Data Out stage callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint number + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#else +void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + /* USER CODE BEGIN HAL_PCD_DataOutStageCallback_PreTreatment */ + + /* USER CODE END HAL_PCD_DataOutStageCallback_PreTreatment */ + USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); + /* USER CODE BEGIN HAL_PCD_DataOutStageCallback_PostTreatment */ + + /* USER CODE END HAL_PCD_DataOutStageCallback_PostTreatment */ +} + +/** + * @brief Data In stage callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint number + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#else +void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + /* USER CODE BEGIN HAL_PCD_DataInStageCallback_PreTreatment */ + + /* USER CODE END HAL_PCD_DataInStageCallback_PreTreatment */ + USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); + /* USER CODE BEGIN HAL_PCD_DataInStageCallback_PostTreatment */ + + /* USER CODE END HAL_PCD_DataInStageCallback_PostTreatment */ +} + +/** + * @brief SOF callback. + * @param hpcd: PCD handle + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_SOFCallback(PCD_HandleTypeDef *hpcd) +#else +void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + /* USER CODE BEGIN HAL_PCD_SOFCallback_PreTreatment */ + + /* USER CODE END HAL_PCD_SOFCallback_PreTreatment */ + USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); + /* USER CODE BEGIN HAL_PCD_SOFCallback_PostTreatment */ + + /* USER CODE END HAL_PCD_SOFCallback_PostTreatment */ +} + +/** + * @brief Reset callback. + * @param hpcd: PCD handle + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ResetCallback(PCD_HandleTypeDef *hpcd) +#else +void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + /* USER CODE BEGIN HAL_PCD_ResetCallback_PreTreatment */ + + /* USER CODE END HAL_PCD_ResetCallback_PreTreatment */ + USBD_SpeedTypeDef speed = USBD_SPEED_FULL; + if (hpcd->Init.speed != USBD_FS_SPEED) + { + Error_Handler(); + } + /* Set Speed. */ + USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed); + + /* Reset Device. */ + USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); + /* USER CODE BEGIN HAL_PCD_ResetCallback_PostTreatment */ + + /* USER CODE END HAL_PCD_ResetCallback_PostTreatment */ +} + +/** + * @brief Suspend callback. + * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) + * @param hpcd: PCD handle + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) +#else +void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + /* USER CODE BEGIN HAL_PCD_SuspendCallback_PreTreatment */ + + /* USER CODE END HAL_PCD_SuspendCallback_PreTreatment */ + /* __HAL_PCD_GATE_PHYCLOCK(hpcd);*/ + /* Inform USB library that core enters in suspend Mode. */ + USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); + /* Enter in STOP mode. */ + /* USER CODE BEGIN 2 */ + if (hpcd->Init.low_power_enable) + { + /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ + SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); + } + /* USER CODE END 2 */ + /* USER CODE BEGIN HAL_PCD_SuspendCallback_PostTreatment */ + + /* USER CODE END HAL_PCD_SuspendCallback_PostTreatment */ +} + +/** + * @brief Resume callback. + * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) + * @param hpcd: PCD handle + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) +#else +void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + /* USER CODE BEGIN HAL_PCD_ResumeCallback_PreTreatment */ + + /* USER CODE END HAL_PCD_ResumeCallback_PreTreatment */ + /* __HAL_PCD_UNGATE_PHYCLOCK(hpcd);*/ + + /* USER CODE BEGIN 3 */ + if (hpcd->Init.low_power_enable) + { + /* Reset SLEEPDEEP bit of Cortex System Control Register. */ + SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); + SystemClockConfig_Resume(); + } + /* USER CODE END 3 */ + + USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData); + /* USER CODE BEGIN HAL_PCD_ResumeCallback_PostTreatment */ + + /* USER CODE END HAL_PCD_ResumeCallback_PostTreatment */ +} + +/** + * @brief ISOOUTIncomplete callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint number + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#else +void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + /* USER CODE BEGIN HAL_PCD_ISOOUTIncompleteCallback_PreTreatment */ + + /* USER CODE END HAL_PCD_ISOOUTIncompleteCallback_PreTreatment */ + USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); + /* USER CODE BEGIN HAL_PCD_ISOOUTIncompleteCallback_PostTreatment */ + + /* USER CODE END HAL_PCD_ISOOUTIncompleteCallback_PostTreatment */ +} + +/** + * @brief ISOINIncomplete callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint number + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#else +void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + /* USER CODE BEGIN HAL_PCD_ISOINIncompleteCallback_PreTreatment */ + + /* USER CODE END HAL_PCD_ISOINIncompleteCallback_PreTreatment */ + USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); + /* USER CODE BEGIN HAL_PCD_ISOINIncompleteCallback_PostTreatment */ + + /* USER CODE END HAL_PCD_ISOINIncompleteCallback_PostTreatment */ +} + +/** + * @brief Connect callback. + * @param hpcd: PCD handle + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) +#else +void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + /* USER CODE BEGIN HAL_PCD_ConnectCallback_PreTreatment */ + + /* USER CODE END HAL_PCD_ConnectCallback_PreTreatment */ + USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData); + /* USER CODE BEGIN HAL_PCD_ConnectCallback_PostTreatment */ + + /* USER CODE END HAL_PCD_ConnectCallback_PostTreatment */ +} + +/** + * @brief Disconnect callback. + * @param hpcd: PCD handle + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) +#else +void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PreTreatment */ + + /* USER CODE END HAL_PCD_DisconnectCallback_PreTreatment */ + USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); + /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PostTreatment */ + + /* USER CODE END HAL_PCD_DisconnectCallback_PostTreatment */ +} + + /* USER CODE BEGIN LowLevelInterface */ + + /* USER CODE END LowLevelInterface */ + +/******************************************************************************* + LL Driver Interface (USB Device Library --> PCD) +*******************************************************************************/ + +/** + * @brief Initializes the low level portion of the device driver. + * @param pdev: Device handle + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) +{ + /* Init USB Ip. */ + hpcd_USB_DRD_FS.pData = pdev; + /* Link the driver to the stack. */ + pdev->pData = &hpcd_USB_DRD_FS; + + hpcd_USB_DRD_FS.Instance = USB_DRD_FS; + hpcd_USB_DRD_FS.Init.dev_endpoints = 8; + hpcd_USB_DRD_FS.Init.Host_channels = 8; + hpcd_USB_DRD_FS.Init.speed = PCD_SPEED_FULL; + hpcd_USB_DRD_FS.Init.phy_itface = PCD_PHY_EMBEDDED; + hpcd_USB_DRD_FS.Init.Sof_enable = DISABLE; + hpcd_USB_DRD_FS.Init.low_power_enable = DISABLE; + hpcd_USB_DRD_FS.Init.lpm_enable = DISABLE; + hpcd_USB_DRD_FS.Init.battery_charging_enable = DISABLE; + hpcd_USB_DRD_FS.Init.vbus_sensing_enable = DISABLE; + hpcd_USB_DRD_FS.Init.bulk_doublebuffer_enable = DISABLE; + hpcd_USB_DRD_FS.Init.iso_singlebuffer_enable = DISABLE; + if (HAL_PCD_Init(&hpcd_USB_DRD_FS) != HAL_OK) + { + Error_Handler( ); + } + +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) + /* Register USB PCD CallBacks */ + HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_SOF_CB_ID, PCD_SOFCallback); + HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback); + HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_RESET_CB_ID, PCD_ResetCallback); + HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_SUSPEND_CB_ID, PCD_SuspendCallback); + HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_RESUME_CB_ID, PCD_ResumeCallback); + HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_CONNECT_CB_ID, PCD_ConnectCallback); + HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback); + /* USER CODE BEGIN RegisterCallBackFirstPart */ + + /* USER CODE END RegisterCallBackFirstPart */ + HAL_PCD_RegisterLpmCallback(&hpcd_USB_DRD_FS, PCDEx_LPM_Callback); + HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_DRD_FS, PCD_DataOutStageCallback); + HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_DRD_FS, PCD_DataInStageCallback); + HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_DRD_FS, PCD_ISOOUTIncompleteCallback); + HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_DRD_FS, PCD_ISOINIncompleteCallback); + /* USER CODE BEGIN RegisterCallBackSecondPart */ + + /* USER CODE END RegisterCallBackSecondPart */ +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ + /* USER CODE BEGIN EndPoint_Configuration */ + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58); + /* USER CODE END EndPoint_Configuration */ + /* USER CODE BEGIN EndPoint_Configuration_CDC */ + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0xC0); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x01 , PCD_SNG_BUF, 0x110); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x82 , PCD_SNG_BUF, 0x100); + /* USER CODE END EndPoint_Configuration_CDC */ + + return USBD_OK; +} + +/** + * @brief De-Initializes the low level portion of the device driver. + * @param pdev: Device handle + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_DeInit(pdev->pData); + + usb_status = USBD_Get_USB_Status(hal_status); + + return usb_status; +} + +/** + * @brief Starts the low level portion of the device driver. + * @param pdev: Device handle + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_Start(pdev->pData); + + usb_status = USBD_Get_USB_Status(hal_status); + + return usb_status; +} + +/** + * @brief Stops the low level portion of the device driver. + * @param pdev: Device handle + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_Stop(pdev->pData); + + usb_status = USBD_Get_USB_Status(hal_status); + + return usb_status; +} + +/** + * @brief Opens an endpoint of the low level driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @param ep_type: Endpoint type + * @param ep_mps: Endpoint max packet size + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type); + + usb_status = USBD_Get_USB_Status(hal_status); + + return usb_status; +} + +/** + * @brief Closes an endpoint of the low level driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr); + + usb_status = USBD_Get_USB_Status(hal_status); + + return usb_status; +} + +/** + * @brief Flushes an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr); + + usb_status = USBD_Get_USB_Status(hal_status); + + return usb_status; +} + +/** + * @brief Sets a Stall condition on an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr); + + usb_status = USBD_Get_USB_Status(hal_status); + + return usb_status; +} + +/** + * @brief Clears a Stall condition on an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr); + + usb_status = USBD_Get_USB_Status(hal_status); + + return usb_status; +} + +/** + * @brief Returns Stall condition. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval Stall (1: Yes, 0: No) + */ +uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; + + if((ep_addr & 0x80) == 0x80) + { + return hpcd->IN_ep[ep_addr & 0x7F].is_stall; + } + else + { + return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; + } +} + +/** + * @brief Assigns a USB address to the device. + * @param pdev: Device handle + * @param dev_addr: Device address + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr); + + usb_status = USBD_Get_USB_Status(hal_status); + + return usb_status; +} + +/** + * @brief Transmits data over an endpoint. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @param pbuf: Pointer to data to be sent + * @param size: Data size + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size); + + usb_status = USBD_Get_USB_Status(hal_status); + + return usb_status; +} + +/** + * @brief Prepares an endpoint for reception. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @param pbuf: Pointer to data to be received + * @param size: Data size + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size); + + usb_status = USBD_Get_USB_Status(hal_status); + + return usb_status; +} + +/** + * @brief Returns the last transferred packet size. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval Received Data Size + */ +uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr); +} + +/** + * @brief Send LPM message to user layer + * @param hpcd: PCD handle + * @param msg: LPM message + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) +#else +void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + /* USER CODE BEGIN LPM_Callback */ + switch (msg) + { + case PCD_LPM_L0_ACTIVE: + if (hpcd->Init.low_power_enable) + { + SystemClockConfig_Resume(); + + /* Reset SLEEPDEEP bit of Cortex System Control Register. */ + SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); + } + /*__HAL_PCD_UNGATE_PHYCLOCK(hpcd);*/ + USBD_LL_Resume(hpcd->pData); + break; + + case PCD_LPM_L1_ACTIVE: + /*__HAL_PCD_GATE_PHYCLOCK(hpcd);*/ + USBD_LL_Suspend(hpcd->pData); + + /* Enter in STOP mode. */ + if (hpcd->Init.low_power_enable) + { + /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ + SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); + } + break; + } + /* USER CODE END LPM_Callback */ +} + +/** + * @brief Static single allocation. + * @param size: Size of allocated memory + * @retval None + */ +void *USBD_static_malloc(uint32_t size) +{ + static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */ + return mem; +} + +/** + * @brief Dummy memory free + * @param p: Pointer to allocated memory address + * @retval None + */ +void USBD_static_free(void *p) +{ + +} + +/** + * @brief Delays routine for the USB Device Library. + * @param Delay: Delay in ms + * @retval None + */ +void USBD_LL_Delay(uint32_t Delay) +{ + HAL_Delay(Delay); +} + +/* USER CODE BEGIN 5 */ +/** + * @brief Configures system clock after wake-up from USB resume callBack: + * enable HSI, PLL and select PLL as system clock source. + * @retval None + */ +static void SystemClockConfig_Resume(void) +{ + SystemClock_Config(); +} +/* USER CODE END 5 */ + +/** + * @brief Returns the USB status depending on the HAL status: + * @param hal_status: HAL status + * @retval USB status + */ +USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status) +{ + USBD_StatusTypeDef usb_status = USBD_OK; + + switch (hal_status) + { + case HAL_OK : + usb_status = USBD_OK; + break; + case HAL_ERROR : + usb_status = USBD_FAIL; + break; + case HAL_BUSY : + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT : + usb_status = USBD_FAIL; + break; + default : + usb_status = USBD_FAIL; + break; + } + return usb_status; +} diff --git a/boards/motherboard/src/usbd_desc.c b/boards/motherboard/src/usbd_desc.c new file mode 100644 index 0000000..627e34f --- /dev/null +++ b/boards/motherboard/src/usbd_desc.c @@ -0,0 +1,396 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : usbd_desc.c + * @version : v3.0_Cube + * @brief : This file implements the USB device descriptors. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_core.h" +#include "usbd_desc.h" +#include "usbd_conf.h" + +/* USER CODE BEGIN INCLUDE */ + +/* USER CODE END INCLUDE */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ + +/* USER CODE BEGIN PV */ +/* Private variables ---------------------------------------------------------*/ + +/* USER CODE END PV */ + +/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY + * @{ + */ + +/** @addtogroup USBD_DESC + * @{ + */ + +/** @defgroup USBD_DESC_Private_TypesDefinitions USBD_DESC_Private_TypesDefinitions + * @brief Private types. + * @{ + */ + +/* USER CODE BEGIN PRIVATE_TYPES */ + +/* USER CODE END PRIVATE_TYPES */ + +/** + * @} + */ + +/** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines + * @brief Private defines. + * @{ + */ + +#define USBD_VID 1155 +#define USBD_LANGID_STRING 1033 +#define USBD_MANUFACTURER_STRING "STMicroelectronics" +#define USBD_PID 22336 +#define USBD_PRODUCT_STRING "STM32 Virtual ComPort" +#define USBD_CONFIGURATION_STRING "CDC Config" +#define USBD_INTERFACE_STRING "CDC Interface" + +/* USER CODE BEGIN PRIVATE_DEFINES */ + +/* USER CODE END PRIVATE_DEFINES */ + +/** + * @} + */ + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros + * @brief Private macros. + * @{ + */ + +/* USER CODE BEGIN PRIVATE_MACRO */ + +/* USER CODE END PRIVATE_MACRO */ + +/** + * @} + */ + +/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes + * @brief Private functions declaration. + * @{ + */ + +static void Get_SerialNum(void); +static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len); + +/** + * @} + */ + +/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes + * @brief Private functions declaration. + * @{ + */ + +uint8_t * USBD_CDC_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +uint8_t * USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +uint8_t * USBD_CDC_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +uint8_t * USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +uint8_t * USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +uint8_t * USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); +uint8_t * USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); + +/** + * @} + */ + +/** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables + * @brief Private variables. + * @{ + */ + +USBD_DescriptorsTypeDef CDC_Desc = +{ + USBD_CDC_DeviceDescriptor, + USBD_CDC_LangIDStrDescriptor, + USBD_CDC_ManufacturerStrDescriptor, + USBD_CDC_ProductStrDescriptor, + USBD_CDC_SerialStrDescriptor, + USBD_CDC_ConfigStrDescriptor, + USBD_CDC_InterfaceStrDescriptor +}; + +#if defined ( __ICCARM__ ) /* IAR Compiler */ + #pragma data_alignment=4 +#endif /* defined ( __ICCARM__ ) */ +/** USB standard device descriptor. */ +__ALIGN_BEGIN uint8_t USBD_CDC_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = +{ + 0x12, /*bLength */ + USB_DESC_TYPE_DEVICE, /*bDescriptorType*/ + 0x00, /*bcdUSB */ + 0x02, + 0x02, /*bDeviceClass*/ + 0x02, /*bDeviceSubClass*/ + 0x00, /*bDeviceProtocol*/ + USB_MAX_EP0_SIZE, /*bMaxPacketSize*/ + LOBYTE(USBD_VID), /*idVendor*/ + HIBYTE(USBD_VID), /*idVendor*/ + LOBYTE(USBD_PID), /*idProduct*/ + HIBYTE(USBD_PID), /*idProduct*/ + 0x00, /*bcdDevice rel. 2.00*/ + 0x02, + USBD_IDX_MFC_STR, /*Index of manufacturer string*/ + USBD_IDX_PRODUCT_STR, /*Index of product string*/ + USBD_IDX_SERIAL_STR, /*Index of serial number string*/ + USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/ +}; + +/* USB_DeviceDescriptor */ + +/** + * @} + */ + +/** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables + * @brief Private variables. + * @{ + */ + +#if defined ( __ICCARM__ ) /* IAR Compiler */ + #pragma data_alignment=4 +#endif /* defined ( __ICCARM__ ) */ + +/** USB lang identifier descriptor. */ +__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = +{ + USB_LEN_LANGID_STR_DESC, + USB_DESC_TYPE_STRING, + LOBYTE(USBD_LANGID_STRING), + HIBYTE(USBD_LANGID_STRING) +}; + +#if defined ( __ICCARM__ ) /* IAR Compiler */ + #pragma data_alignment=4 +#endif /* defined ( __ICCARM__ ) */ +/* Internal string descriptor. */ +__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; + +#if defined ( __ICCARM__ ) /*!< IAR Compiler */ + #pragma data_alignment=4 +#endif +__ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = { + USB_SIZ_STRING_SERIAL, + USB_DESC_TYPE_STRING, +}; + +/** + * @} + */ + +/** @defgroup USBD_DESC_Private_Functions USBD_DESC_Private_Functions + * @brief Private functions. + * @{ + */ + +/** + * @brief Return the device descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t * USBD_CDC_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +{ + UNUSED(speed); + *length = sizeof(USBD_CDC_DeviceDesc); + return USBD_CDC_DeviceDesc; +} + +/** + * @brief Return the LangID string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t * USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +{ + UNUSED(speed); + *length = sizeof(USBD_LangIDDesc); + return USBD_LangIDDesc; +} + +/** + * @brief Return the product string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t * USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +{ + if(speed == 0) + { + USBD_GetString((uint8_t *)USBD_PRODUCT_STRING, USBD_StrDesc, length); + } + else + { + USBD_GetString((uint8_t *)USBD_PRODUCT_STRING, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +/** + * @brief Return the manufacturer string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t * USBD_CDC_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +{ + UNUSED(speed); + USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); + return USBD_StrDesc; +} + +/** + * @brief Return the serial number string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t * USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +{ + UNUSED(speed); + *length = USB_SIZ_STRING_SERIAL; + + /* Update the serial number string descriptor with the data from the unique + * ID */ + Get_SerialNum(); + + /* USER CODE BEGIN USBD_CDC_SerialStrDescriptor */ + + /* USER CODE END USBD_CDC_SerialStrDescriptor */ + + return (uint8_t *) USBD_StringSerial; +} + +/** + * @brief Return the configuration string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t * USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +{ + if(speed == USBD_SPEED_HIGH) + { + USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING, USBD_StrDesc, length); + } + else + { + USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +/** + * @brief Return the interface string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t * USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) +{ + if(speed == 0) + { + USBD_GetString((uint8_t *)USBD_INTERFACE_STRING, USBD_StrDesc, length); + } + else + { + USBD_GetString((uint8_t *)USBD_INTERFACE_STRING, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +/** + * @brief Create the serial number string descriptor + * @param None + * @retval None + */ +static void Get_SerialNum(void) +{ + uint32_t deviceserial0; + uint32_t deviceserial1; + uint32_t deviceserial2; + + deviceserial0 = *(uint32_t *) DEVICE_ID1; + deviceserial1 = *(uint32_t *) DEVICE_ID2; + deviceserial2 = *(uint32_t *) DEVICE_ID3; + + deviceserial0 += deviceserial2; + + if (deviceserial0 != 0) + { + IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8); + IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4); + } +} + +/** + * @brief Convert Hex 32Bits value into char + * @param value: value to convert + * @param pbuf: pointer to the buffer + * @param len: buffer length + * @retval None + */ +static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len) +{ + uint8_t idx = 0; + + for (idx = 0; idx < len; idx++) + { + if (((value >> 28)) < 0xA) + { + pbuf[2 * idx] = (value >> 28) + '0'; + } + else + { + pbuf[2 * idx] = (value >> 28) + 'A' - 10; + } + + value = value << 4; + + pbuf[2 * idx + 1] = 0; + } +} +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + From 7aaae20fb1807188091ef3a86ac506bcacbab98f Mon Sep 17 00:00:00 2001 From: Ivan Lange Date: Tue, 31 Mar 2026 00:57:34 -0400 Subject: [PATCH 05/13] Complete .ioc for motherboard --- boards/motherboard/Inc/adc.h | 52 ++++ boards/motherboard/Inc/dac.h | 52 ++++ boards/motherboard/Inc/main.h | 92 +++++- boards/motherboard/Inc/spi.h | 55 ++++ boards/motherboard/Inc/stm32g0xx_hal_conf.h | 8 +- boards/motherboard/Inc/usart.h | 52 ++++ boards/motherboard/motherboard.ioc | 323 +++++++++++++++++--- boards/motherboard/src/adc.c | 154 ++++++++++ boards/motherboard/src/dac.c | 120 ++++++++ boards/motherboard/src/gpio.c | 111 ++++++- boards/motherboard/src/main.c | 9 + boards/motherboard/src/spi.c | 199 ++++++++++++ boards/motherboard/src/usart.c | 141 +++++++++ 13 files changed, 1312 insertions(+), 56 deletions(-) create mode 100644 boards/motherboard/Inc/adc.h create mode 100644 boards/motherboard/Inc/dac.h create mode 100644 boards/motherboard/Inc/spi.h create mode 100644 boards/motherboard/Inc/usart.h create mode 100644 boards/motherboard/src/adc.c create mode 100644 boards/motherboard/src/dac.c create mode 100644 boards/motherboard/src/spi.c create mode 100644 boards/motherboard/src/usart.c diff --git a/boards/motherboard/Inc/adc.h b/boards/motherboard/Inc/adc.h new file mode 100644 index 0000000..b844764 --- /dev/null +++ b/boards/motherboard/Inc/adc.h @@ -0,0 +1,52 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file adc.h + * @brief This file contains all the function prototypes for + * the adc.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __ADC_H__ +#define __ADC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern ADC_HandleTypeDef hadc1; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_ADC1_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __ADC_H__ */ + diff --git a/boards/motherboard/Inc/dac.h b/boards/motherboard/Inc/dac.h new file mode 100644 index 0000000..04e00b7 --- /dev/null +++ b/boards/motherboard/Inc/dac.h @@ -0,0 +1,52 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file dac.h + * @brief This file contains all the function prototypes for + * the dac.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __DAC_H__ +#define __DAC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern DAC_HandleTypeDef hdac1; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_DAC1_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __DAC_H__ */ + diff --git a/boards/motherboard/Inc/main.h b/boards/motherboard/Inc/main.h index c59c473..ae3ad5a 100644 --- a/boards/motherboard/Inc/main.h +++ b/boards/motherboard/Inc/main.h @@ -57,20 +57,108 @@ void Error_Handler(void); /* USER CODE END EFP */ /* Private defines -----------------------------------------------------------*/ +#define VGA_CS_N_Pin GPIO_PIN_4 +#define VGA_CS_N_GPIO_Port GPIOE +#define TEMP_CS_N_Pin GPIO_PIN_5 +#define TEMP_CS_N_GPIO_Port GPIOE +#define TEMP_ALERT_N_Pin GPIO_PIN_13 +#define TEMP_ALERT_N_GPIO_Port GPIOC #define P6V_SCATTER_PWR_EN_Pin GPIO_PIN_0 #define P6V_SCATTER_PWR_EN_GPIO_Port GPIOF #define P6V_SCATTER_HSD_DIAG_EN_Pin GPIO_PIN_1 #define P6V_SCATTER_HSD_DIAG_EN_GPIO_Port GPIOF -#define DEBUG_Pin GPIO_PIN_7 -#define DEBUG_GPIO_Port GPIOE +#define LNA_EN_Pin GPIO_PIN_1 +#define LNA_EN_GPIO_Port GPIOC +#define LOGAMP_EN_Pin GPIO_PIN_2 +#define LOGAMP_EN_GPIO_Port GPIOC +#define LOG_VSENSE_Pin GPIO_PIN_0 +#define LOG_VSENSE_GPIO_Port GPIOA +#define P6V_SCATTER_CS_Pin GPIO_PIN_4 +#define P6V_SCATTER_CS_GPIO_Port GPIOA +#define DAC_ADJ_Pin GPIO_PIN_5 +#define DAC_ADJ_GPIO_Port GPIOA +#define LPA_PWR_DET_Pin GPIO_PIN_7 +#define LPA_PWR_DET_GPIO_Port GPIOA +#define COMM_TX_Pin GPIO_PIN_4 +#define COMM_TX_GPIO_Port GPIOC +#define COMM_RX_Pin GPIO_PIN_5 +#define COMM_RX_GPIO_Port GPIOC +#define PWR_DOWN_Pin GPIO_PIN_0 +#define PWR_DOWN_GPIO_Port GPIOB +#define P6V_CS_TWO_Pin GPIO_PIN_1 +#define P6V_CS_TWO_GPIO_Port GPIOB +#define P6V_CS_ONE_Pin GPIO_PIN_2 +#define P6V_CS_ONE_GPIO_Port GPIOB +#define DEBUG2_Pin GPIO_PIN_7 +#define DEBUG2_GPIO_Port GPIOE +#define DEBUG1_Pin GPIO_PIN_8 +#define DEBUG1_GPIO_Port GPIOE +#define P12V_CS_Pin GPIO_PIN_10 +#define P12V_CS_GPIO_Port GPIOB +#define FAN1_PWM_Pin GPIO_PIN_9 +#define FAN1_PWM_GPIO_Port GPIOA +#define WARN_LIGHT_Pin GPIO_PIN_6 +#define WARN_LIGHT_GPIO_Port GPIOC +#define FAN2_PWM_Pin GPIO_PIN_7 +#define FAN2_PWM_GPIO_Port GPIOC +#define LPA_EN_Pin GPIO_PIN_12 +#define LPA_EN_GPIO_Port GPIOD +#define VGA_ATTSEL0_Pin GPIO_PIN_13 +#define VGA_ATTSEL0_GPIO_Port GPIOD +#define VGA_EN_Pin GPIO_PIN_14 +#define VGA_EN_GPIO_Port GPIOD +#define VGA_ATTSEL1_Pin GPIO_PIN_15 +#define VGA_ATTSEL1_GPIO_Port GPIOD +#define P6V_PG_Pin GPIO_PIN_8 +#define P6V_PG_GPIO_Port GPIOF +#define USB_nFAULT_Pin GPIO_PIN_15 +#define USB_nFAULT_GPIO_Port GPIOA +#define P5V_VSENSE_Pin GPIO_PIN_8 +#define P5V_VSENSE_GPIO_Port GPIOC +#define P12V_VSENSE_Pin GPIO_PIN_9 +#define P12V_VSENSE_GPIO_Port GPIOC +#define P12V_HSD_DIAG_EN_Pin GPIO_PIN_0 +#define P12V_HSD_DIAG_EN_GPIO_Port GPIOD +#define MUX_ST_Pin GPIO_PIN_1 +#define MUX_ST_GPIO_Port GPIOD +#define FAN1_PWR_EN_Pin GPIO_PIN_2 +#define FAN1_PWR_EN_GPIO_Port GPIOD +#define nFAULT_FAN1_Pin GPIO_PIN_3 +#define nFAULT_FAN1_GPIO_Port GPIOD +#define FAN2_PWR_EN_Pin GPIO_PIN_4 +#define FAN2_PWR_EN_GPIO_Port GPIOD +#define nFAULT_FAN2_Pin GPIO_PIN_5 +#define nFAULT_FAN2_GPIO_Port GPIOD +#define P6V_HDS_ONE_DIAG_EN_Pin GPIO_PIN_6 +#define P6V_HDS_ONE_DIAG_EN_GPIO_Port GPIOD +#define P6V_HSD_ONE_nFAULT_Pin GPIO_PIN_7 +#define P6V_HSD_ONE_nFAULT_GPIO_Port GPIOD +#define P6V_HSD_ONE_SEL_Pin GPIO_PIN_9 +#define P6V_HSD_ONE_SEL_GPIO_Port GPIOF +#define P6V_HSD_ONE_SEH_Pin GPIO_PIN_10 +#define P6V_HSD_ONE_SEH_GPIO_Port GPIOF #define VGA_PWR_EN_Pin GPIO_PIN_11 #define VGA_PWR_EN_GPIO_Port GPIOF #define VCO_PWR_EN_Pin GPIO_PIN_12 #define VCO_PWR_EN_GPIO_Port GPIOF +#define P6V_HSD_TWO_DIAG_EN_Pin GPIO_PIN_13 +#define P6V_HSD_TWO_DIAG_EN_GPIO_Port GPIOF +#define P6V_HSD_TWO_nFAULT_Pin GPIO_PIN_3 +#define P6V_HSD_TWO_nFAULT_GPIO_Port GPIOB +#define P6V_HSD_TWO_SEL_Pin GPIO_PIN_4 +#define P6V_HSD_TWO_SEL_GPIO_Port GPIOB +#define P6V_HSD_TWO_SEH_Pin GPIO_PIN_5 +#define P6V_HSD_TWO_SEH_GPIO_Port GPIOB #define GEN_EN_Pin GPIO_PIN_0 #define GEN_EN_GPIO_Port GPIOE #define LPA_PWR_EN_Pin GPIO_PIN_1 #define LPA_PWR_EN_GPIO_Port GPIOE +#define VCO_CE_Pin GPIO_PIN_2 +#define VCO_CE_GPIO_Port GPIOE +#define VCO_LE_Pin GPIO_PIN_3 +#define VCO_LE_GPIO_Port GPIOE +#define VCO_MUXOUT_Pin GPIO_PIN_6 +#define VCO_MUXOUT_GPIO_Port GPIOB /* USER CODE BEGIN Private defines */ diff --git a/boards/motherboard/Inc/spi.h b/boards/motherboard/Inc/spi.h new file mode 100644 index 0000000..d674292 --- /dev/null +++ b/boards/motherboard/Inc/spi.h @@ -0,0 +1,55 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file spi.h + * @brief This file contains all the function prototypes for + * the spi.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __SPI_H__ +#define __SPI_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern SPI_HandleTypeDef hspi2; + +extern SPI_HandleTypeDef hspi3; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_SPI2_Init(void); +void MX_SPI3_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __SPI_H__ */ + diff --git a/boards/motherboard/Inc/stm32g0xx_hal_conf.h b/boards/motherboard/Inc/stm32g0xx_hal_conf.h index cb0d292..49b45a8 100644 --- a/boards/motherboard/Inc/stm32g0xx_hal_conf.h +++ b/boards/motherboard/Inc/stm32g0xx_hal_conf.h @@ -34,12 +34,12 @@ extern "C" { * @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_CEC_MODULE_ENABLED */ /* #define HAL_COMP_MODULE_ENABLED */ /* #define HAL_CRC_MODULE_ENABLED */ /* #define HAL_CRYP_MODULE_ENABLED */ -/* #define HAL_DAC_MODULE_ENABLED */ +#define HAL_DAC_MODULE_ENABLED /* #define HAL_EXTI_MODULE_ENABLED */ /* #define HAL_FDCAN_MODULE_ENABLED */ /* #define HAL_HCD_MODULE_ENABLED */ @@ -53,9 +53,9 @@ extern "C" { /* #define HAL_RTC_MODULE_ENABLED */ /* #define HAL_SMARTCARD_MODULE_ENABLED */ /* #define HAL_SMBUS_MODULE_ENABLED */ -/* #define HAL_SPI_MODULE_ENABLED */ +#define HAL_SPI_MODULE_ENABLED #define HAL_TIM_MODULE_ENABLED -/* #define HAL_UART_MODULE_ENABLED */ +#define HAL_UART_MODULE_ENABLED /* #define HAL_USART_MODULE_ENABLED */ /* #define HAL_WWDG_MODULE_ENABLED */ #define HAL_GPIO_MODULE_ENABLED diff --git a/boards/motherboard/Inc/usart.h b/boards/motherboard/Inc/usart.h new file mode 100644 index 0000000..a13cfca --- /dev/null +++ b/boards/motherboard/Inc/usart.h @@ -0,0 +1,52 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file usart.h + * @brief This file contains all the function prototypes for + * the usart.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USART_H__ +#define __USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern UART_HandleTypeDef huart1; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_USART1_UART_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USART_H__ */ + diff --git a/boards/motherboard/motherboard.ioc b/boards/motherboard/motherboard.ioc index 772034f..225210d 100644 --- a/boards/motherboard/motherboard.ioc +++ b/boards/motherboard/motherboard.ioc @@ -1,7 +1,16 @@ #MicroXplorer Configuration settings - do not modify +ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_0 +ADC1.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag,master,SelectedChannel +ADC1.NbrOfConversionFlag=1 +ADC1.Rank-0\#ChannelRegularConversion=1 +ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLINGTIME_COMMON_1 +ADC1.SelectedChannel=ADC_CHANNEL_0|ADC_CHANNEL_4|ADC_CHANNEL_7|ADC_CHANNEL_9|ADC_CHANNEL_10|ADC_CHANNEL_11 +ADC1.master=1 CAD.formats= CAD.pinconfig= CAD.provider= +DAC1.DAC_Channel-DAC_OUT2=DAC_CHANNEL_2 +DAC1.IPParameters=DAC_Channel-DAC_OUT2 FREERTOS.Events01= FREERTOS.FootprintOK=true FREERTOS.INCLUDE_vTaskDelayUntil=1 @@ -10,54 +19,123 @@ FREERTOS.MEMORY_ALLOCATION=1 FREERTOS.Tasks01=defaultTask,0,128,StartDefaultTask,Default,NULL,Static,defaultTaskBuffer,defaultTaskControlBlock FREERTOS.configUSE_NEWLIB_REENTRANT=1 File.Version=6 -GPIO.groupedBy= +GPIO.groupedBy=Group By Peripherals KeepUserPlacement=false Mcu.CPN=STM32G0B1VET6 Mcu.Family=STM32G0 -Mcu.IP0=FREERTOS -Mcu.IP1=NVIC -Mcu.IP2=RCC -Mcu.IP3=SYS -Mcu.IP4=USB_DEVICE -Mcu.IP5=USB_DRD_FS -Mcu.IPNb=6 +Mcu.IP0=ADC1 +Mcu.IP1=DAC1 +Mcu.IP10=USB_DRD_FS +Mcu.IP2=FREERTOS +Mcu.IP3=NVIC +Mcu.IP4=RCC +Mcu.IP5=SPI2 +Mcu.IP6=SPI3 +Mcu.IP7=SYS +Mcu.IP8=USART1 +Mcu.IP9=USB_DEVICE +Mcu.IPNb=11 Mcu.Name=STM32G0B1V(B-C-E)Tx Mcu.Package=LQFP100 -Mcu.Pin0=PE4 -Mcu.Pin1=PE5 -Mcu.Pin10=PA11 [PA9] -Mcu.Pin11=PA12 [PA10] -Mcu.Pin12=PF8 -Mcu.Pin13=PD0 -Mcu.Pin14=PD1 -Mcu.Pin15=PD2 -Mcu.Pin16=PD3 -Mcu.Pin17=PD4 -Mcu.Pin18=PD5 -Mcu.Pin19=PD6 -Mcu.Pin2=PF0-OSC_IN (PF0) -Mcu.Pin20=PD7 -Mcu.Pin21=PF9 -Mcu.Pin22=PF10 -Mcu.Pin23=PF11 -Mcu.Pin24=PF12 -Mcu.Pin25=PF13 -Mcu.Pin26=PE0 -Mcu.Pin27=PE1 -Mcu.Pin28=PE2 -Mcu.Pin29=PE3 -Mcu.Pin3=PF1-OSC_OUT (PF1) -Mcu.Pin30=VP_FREERTOS_VS_CMSIS_V1 -Mcu.Pin31=VP_SYS_VS_tim1 -Mcu.Pin32=VP_SYS_VS_DBSignals -Mcu.Pin33=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS -Mcu.Pin4=PE7 -Mcu.Pin5=PE8 -Mcu.Pin6=PD12 -Mcu.Pin7=PD13 -Mcu.Pin8=PD14 -Mcu.Pin9=PD15 -Mcu.PinsNb=34 +Mcu.Pin0=PB9 +Mcu.Pin1=PC10 +Mcu.Pin10=PF0-OSC_IN (PF0) +Mcu.Pin11=PF1-OSC_OUT (PF1) +Mcu.Pin12=PF2-NRST +Mcu.Pin13=PF3 +Mcu.Pin14=PF4 +Mcu.Pin15=PF5 +Mcu.Pin16=PC0 +Mcu.Pin17=PC1 +Mcu.Pin18=PC2 +Mcu.Pin19=PC3 +Mcu.Pin2=PC11 +Mcu.Pin20=PA0 +Mcu.Pin21=PA1 +Mcu.Pin22=PA2 +Mcu.Pin23=PA3 +Mcu.Pin24=PA4 +Mcu.Pin25=PA5 +Mcu.Pin26=PA6 +Mcu.Pin27=PA7 +Mcu.Pin28=PC4 +Mcu.Pin29=PC5 +Mcu.Pin3=PE4 +Mcu.Pin30=PB0 +Mcu.Pin31=PB1 +Mcu.Pin32=PB2 +Mcu.Pin33=PF6 +Mcu.Pin34=PF7 +Mcu.Pin35=PE7 +Mcu.Pin36=PE8 +Mcu.Pin37=PE9 +Mcu.Pin38=PE10 +Mcu.Pin39=PE11 +Mcu.Pin4=PE5 +Mcu.Pin40=PE12 +Mcu.Pin41=PE13 +Mcu.Pin42=PE14 +Mcu.Pin43=PE15 +Mcu.Pin44=PB10 +Mcu.Pin45=PB11 +Mcu.Pin46=PB12 +Mcu.Pin47=PB13 +Mcu.Pin48=PB14 +Mcu.Pin49=PB15 +Mcu.Pin5=PE6 +Mcu.Pin50=PA8 +Mcu.Pin51=PA9 +Mcu.Pin52=PC6 +Mcu.Pin53=PC7 +Mcu.Pin54=PD8 +Mcu.Pin55=PD9 +Mcu.Pin56=PD10 +Mcu.Pin57=PD11 +Mcu.Pin58=PD12 +Mcu.Pin59=PD13 +Mcu.Pin6=PC12 +Mcu.Pin60=PD14 +Mcu.Pin61=PD15 +Mcu.Pin62=PA10 +Mcu.Pin63=PA11 [PA9] +Mcu.Pin64=PA12 [PA10] +Mcu.Pin65=PF8 +Mcu.Pin66=PA13 +Mcu.Pin67=PA14-BOOT0 +Mcu.Pin68=PA15 +Mcu.Pin69=PC8 +Mcu.Pin7=PC13 +Mcu.Pin70=PC9 +Mcu.Pin71=PD0 +Mcu.Pin72=PD1 +Mcu.Pin73=PD2 +Mcu.Pin74=PD3 +Mcu.Pin75=PD4 +Mcu.Pin76=PD5 +Mcu.Pin77=PD6 +Mcu.Pin78=PD7 +Mcu.Pin79=PF9 +Mcu.Pin8=PC14-OSC32_IN (PC14) +Mcu.Pin80=PF10 +Mcu.Pin81=PF11 +Mcu.Pin82=PF12 +Mcu.Pin83=PF13 +Mcu.Pin84=PB3 +Mcu.Pin85=PB4 +Mcu.Pin86=PB5 +Mcu.Pin87=PE0 +Mcu.Pin88=PE1 +Mcu.Pin89=PE2 +Mcu.Pin9=PC15-OSC32_OUT (PC15) +Mcu.Pin90=PE3 +Mcu.Pin91=PB6 +Mcu.Pin92=PB7 +Mcu.Pin93=PB8 +Mcu.Pin94=VP_FREERTOS_VS_CMSIS_V1 +Mcu.Pin95=VP_SYS_VS_tim1 +Mcu.Pin96=VP_SYS_VS_DBSignals +Mcu.Pin97=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS +Mcu.PinsNb=98 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32G0B1VETx @@ -75,10 +153,133 @@ NVIC.SysTick_IRQn=true\:3\:0\:false\:false\:false\:true\:false\:true\:false NVIC.TIM1_BRK_UP_TRG_COM_IRQn=true\:3\:0\:false\:false\:true\:false\:false\:true\:true NVIC.TimeBase=TIM1_BRK_UP_TRG_COM_IRQn NVIC.TimeBaseIP=TIM1 +PA0.GPIOParameters=GPIO_Label +PA0.GPIO_Label=LOG_VSENSE +PA0.Locked=true +PA0.Mode=IN0 +PA0.Signal=ADC1_IN0 +PA1.Locked=true +PA10.Locked=true PA11\ [PA9].Mode=Device PA11\ [PA9].Signal=USB_DM PA12\ [PA10].Mode=Device PA12\ [PA10].Signal=USB_DP +PA13.Locked=true +PA14-BOOT0.Locked=true +PA15.GPIOParameters=GPIO_Label +PA15.GPIO_Label=USB_nFAULT +PA15.Locked=true +PA15.Signal=GPIO_Input +PA2.Locked=true +PA3.Locked=true +PA4.GPIOParameters=GPIO_Label +PA4.GPIO_Label=P6V_SCATTER_CS +PA4.Mode=IN4 +PA4.Signal=ADC1_IN4 +PA5.GPIOParameters=GPIO_Label +PA5.GPIO_Label=DAC_ADJ +PA5.Signal=COMP_DAC12_group +PA6.Locked=true +PA7.GPIOParameters=GPIO_Label +PA7.GPIO_Label=LPA_PWR_DET +PA7.Mode=IN7 +PA7.Signal=ADC1_IN7 +PA8.Locked=true +PA9.GPIOParameters=GPIO_Label +PA9.GPIO_Label=FAN1_PWM +PA9.Locked=true +PA9.Signal=GPIO_Analog +PB0.GPIOParameters=GPIO_Label +PB0.GPIO_Label=PWR_DOWN +PB0.Locked=true +PB0.Signal=GPXTI0 +PB1.GPIOParameters=GPIO_Label +PB1.GPIO_Label=P6V_CS_TWO +PB1.Mode=IN9 +PB1.Signal=ADC1_IN9 +PB10.GPIOParameters=GPIO_Label +PB10.GPIO_Label=P12V_CS +PB10.Locked=true +PB10.Mode=IN11 +PB10.Signal=ADC1_IN11 +PB11.Locked=true +PB12.Locked=true +PB13.Locked=true +PB14.Locked=true +PB15.Locked=true +PB2.GPIOParameters=GPIO_Label +PB2.GPIO_Label=P6V_CS_ONE +PB2.Mode=IN10 +PB2.Signal=ADC1_IN10 +PB3.GPIOParameters=GPIO_Label +PB3.GPIO_Label=P6V_HSD_TWO_nFAULT +PB3.Locked=true +PB3.Signal=GPIO_Input +PB4.GPIOParameters=GPIO_Label +PB4.GPIO_Label=P6V_HSD_TWO_SEL +PB4.Locked=true +PB4.Signal=GPIO_Output +PB5.GPIOParameters=GPIO_Label +PB5.GPIO_Label=P6V_HSD_TWO_SEH +PB5.Locked=true +PB5.Signal=GPIO_Output +PB6.GPIOParameters=GPIO_Label +PB6.GPIO_Label=VCO_MUXOUT +PB6.Locked=true +PB6.Signal=GPIO_Input +PB7.Locked=true +PB7.Mode=Simplex_Bidirectional_Master +PB7.Signal=SPI2_MOSI +PB8.Locked=true +PB8.Mode=Simplex_Bidirectional_Master +PB8.Signal=SPI2_SCK +PB9.Locked=true +PC0.Locked=true +PC1.GPIOParameters=GPIO_Label +PC1.GPIO_Label=LNA_EN +PC1.Locked=true +PC1.Signal=GPIO_Output +PC10.Mode=Full_Duplex_Master +PC10.Signal=SPI3_SCK +PC11.Mode=Full_Duplex_Master +PC11.Signal=SPI3_MISO +PC12.Mode=Full_Duplex_Master +PC12.Signal=SPI3_MOSI +PC13.GPIOParameters=GPIO_Label +PC13.GPIO_Label=TEMP_ALERT_N +PC13.Locked=true +PC13.Signal=GPIO_Input +PC14-OSC32_IN\ (PC14).Locked=true +PC15-OSC32_OUT\ (PC15).Locked=true +PC2.GPIOParameters=GPIO_Label +PC2.GPIO_Label=LOGAMP_EN +PC2.Locked=true +PC2.Signal=GPIO_Output +PC3.Locked=true +PC4.GPIOParameters=GPIO_Label +PC4.GPIO_Label=COMM_TX +PC4.Mode=Asynchronous +PC4.Signal=USART1_TX +PC5.GPIOParameters=GPIO_Label +PC5.GPIO_Label=COMM_RX +PC5.Mode=Asynchronous +PC5.Signal=USART1_RX +PC6.GPIOParameters=GPIO_Label +PC6.GPIO_Label=WARN_LIGHT +PC6.Locked=true +PC6.Signal=GPIO_Output +PC7.GPIOParameters=GPIO_Label +PC7.GPIO_Label=FAN2_PWM +PC7.Locked=true +PC7.Signal=GPIO_Analog +PC8.GPIOParameters=GPIO_Label +PC8.GPIO_Label=P5V_VSENSE +PC8.Locked=true +PC8.Signal=GPIO_Input +PC9.GPIOParameters=GPIO_Label +PC9.GPIO_Label=P12V_VSENSE +PC9.Locked=true +PC9.Signal=GPIO_Input PD0.GPIOParameters=GPIO_Label PD0.GPIO_Label=P12V_HSD_DIAG_EN PD0.Locked=true @@ -87,6 +288,8 @@ PD1.GPIOParameters=GPIO_Label PD1.GPIO_Label=MUX_ST PD1.Locked=true PD1.Signal=GPIO_Input +PD10.Locked=true +PD11.Locked=true PD12.GPIOParameters=GPIO_Label PD12.GPIO_Label=LPA_EN PD12.Locked=true @@ -127,6 +330,8 @@ PD7.GPIOParameters=GPIO_Label PD7.GPIO_Label=P6V_HSD_ONE_nFAULT PD7.Locked=true PD7.Signal=GPIO_Input +PD8.Locked=true +PD9.Locked=true PE0.GPIOParameters=GPIO_Label PE0.GPIO_Label=GEN_EN PE0.Locked=true @@ -135,6 +340,12 @@ PE1.GPIOParameters=GPIO_Label PE1.GPIO_Label=LPA_PWR_EN PE1.Locked=true PE1.Signal=GPIO_Output +PE10.Locked=true +PE11.Locked=true +PE12.Locked=true +PE13.Locked=true +PE14.Locked=true +PE15.Locked=true PE2.GPIOParameters=GPIO_Label PE2.GPIO_Label=VCO_CE PE2.Locked=true @@ -155,6 +366,7 @@ PE5.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD PE5.GPIO_PuPd=GPIO_NOPULL PE5.Locked=true PE5.Signal=GPIO_Output +PE6.Locked=true PE7.GPIOParameters=GPIO_Label PE7.GPIO_Label=DEBUG2 PE7.Locked=true @@ -163,6 +375,7 @@ PE8.GPIOParameters=GPIO_Label PE8.GPIO_Label=DEBUG1 PE8.Locked=true PE8.Signal=GPIO_Output +PE9.Locked=true PF0-OSC_IN\ (PF0).GPIOParameters=GPIO_Label PF0-OSC_IN\ (PF0).GPIO_Label=P6V_SCATTER_PWR_EN PF0-OSC_IN\ (PF0).Locked=true @@ -188,6 +401,12 @@ PF13.GPIO_Label=P6V_HSD_TWO_DIAG_EN PF13.Locked=true PF13.PinState=GPIO_PIN_RESET PF13.Signal=GPIO_Output +PF2-NRST.Locked=true +PF3.Locked=true +PF4.Locked=true +PF5.Locked=true +PF6.Locked=true +PF7.Locked=true PF8.GPIOParameters=GPIO_Label PF8.GPIO_Label=P6V_PG PF8.Locked=true @@ -270,6 +489,24 @@ RCC.USART3Freq_Value=16000000 RCC.USBFreq_Value=48000000 RCC.VCOInputFreq_Value=16000000 RCC.VCOOutputFreq_Value=128000000 +SH.COMP_DAC12_group.0=DAC1_OUT2,DAC_OUT2 +SH.COMP_DAC12_group.ConfNb=1 +SH.GPXTI0.0=GPIO_EXTI0 +SH.GPXTI0.ConfNb=1 +SPI2.CalculateBaudRate=8.0 MBits/s +SPI2.DataSize=SPI_DATASIZE_8BIT +SPI2.Direction=SPI_DIRECTION_1LINE +SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize +SPI2.Mode=SPI_MODE_MASTER +SPI2.VirtualType=VM_MASTER +SPI3.CalculateBaudRate=8.0 MBits/s +SPI3.DataSize=SPI_DATASIZE_8BIT +SPI3.Direction=SPI_DIRECTION_2LINES +SPI3.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize +SPI3.Mode=SPI_MODE_MASTER +SPI3.VirtualType=VM_MASTER +USART1.IPParameters=VirtualMode-Asynchronous +USART1.VirtualMode-Asynchronous=VM_ASYNC USB_DEVICE.CLASS_NAME_FS=CDC USB_DEVICE.IPParameters=VirtualMode,VirtualModeFS,CLASS_NAME_FS USB_DEVICE.VirtualMode=Cdc diff --git a/boards/motherboard/src/adc.c b/boards/motherboard/src/adc.c new file mode 100644 index 0000000..938ccb7 --- /dev/null +++ b/boards/motherboard/src/adc.c @@ -0,0 +1,154 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file adc.c + * @brief This file provides code for the configuration + * of the ADC instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "adc.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +ADC_HandleTypeDef hadc1; + +/* ADC1 init function */ +void MX_ADC1_Init(void) +{ + + /* USER CODE BEGIN ADC1_Init 0 */ + + /* USER CODE END ADC1_Init 0 */ + + ADC_ChannelConfTypeDef sConfig = {0}; + + /* USER CODE BEGIN ADC1_Init 1 */ + + /* USER CODE END ADC1_Init 1 */ + + /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) + */ + hadc1.Instance = ADC1; + hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2; + hadc1.Init.Resolution = ADC_RESOLUTION_12B; + hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; + hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; + hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; + hadc1.Init.LowPowerAutoWait = DISABLE; + hadc1.Init.LowPowerAutoPowerOff = DISABLE; + hadc1.Init.ContinuousConvMode = DISABLE; + hadc1.Init.NbrOfConversion = 1; + hadc1.Init.DiscontinuousConvMode = DISABLE; + hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; + hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; + hadc1.Init.DMAContinuousRequests = DISABLE; + hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; + hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5; + hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_1CYCLE_5; + hadc1.Init.OversamplingMode = DISABLE; + hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH; + if (HAL_ADC_Init(&hadc1) != HAL_OK) + { + Error_Handler(); + } + + /** Configure Regular Channel + */ + sConfig.Channel = ADC_CHANNEL_0; + sConfig.Rank = ADC_REGULAR_RANK_1; + sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1; + if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN ADC1_Init 2 */ + + /* USER CODE END ADC1_Init 2 */ + +} + +void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(adcHandle->Instance==ADC1) + { + /* USER CODE BEGIN ADC1_MspInit 0 */ + + /* USER CODE END ADC1_MspInit 0 */ + /* ADC1 clock enable */ + __HAL_RCC_ADC_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**ADC1 GPIO Configuration + PA0 ------> ADC1_IN0 + PA4 ------> ADC1_IN4 + PA7 ------> ADC1_IN7 + PB1 ------> ADC1_IN9 + PB2 ------> ADC1_IN10 + PB10 ------> ADC1_IN11 + */ + GPIO_InitStruct.Pin = LOG_VSENSE_Pin|P6V_SCATTER_CS_Pin|LPA_PWR_DET_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = P6V_CS_TWO_Pin|P6V_CS_ONE_Pin|P12V_CS_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* USER CODE BEGIN ADC1_MspInit 1 */ + + /* USER CODE END ADC1_MspInit 1 */ + } +} + +void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle) +{ + + if(adcHandle->Instance==ADC1) + { + /* USER CODE BEGIN ADC1_MspDeInit 0 */ + + /* USER CODE END ADC1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_ADC_CLK_DISABLE(); + + /**ADC1 GPIO Configuration + PA0 ------> ADC1_IN0 + PA4 ------> ADC1_IN4 + PA7 ------> ADC1_IN7 + PB1 ------> ADC1_IN9 + PB2 ------> ADC1_IN10 + PB10 ------> ADC1_IN11 + */ + HAL_GPIO_DeInit(GPIOA, LOG_VSENSE_Pin|P6V_SCATTER_CS_Pin|LPA_PWR_DET_Pin); + + HAL_GPIO_DeInit(GPIOB, P6V_CS_TWO_Pin|P6V_CS_ONE_Pin|P12V_CS_Pin); + + /* USER CODE BEGIN ADC1_MspDeInit 1 */ + + /* USER CODE END ADC1_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + diff --git a/boards/motherboard/src/dac.c b/boards/motherboard/src/dac.c new file mode 100644 index 0000000..a16a6e9 --- /dev/null +++ b/boards/motherboard/src/dac.c @@ -0,0 +1,120 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file dac.c + * @brief This file provides code for the configuration + * of the DAC instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "dac.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +DAC_HandleTypeDef hdac1; + +/* DAC1 init function */ +void MX_DAC1_Init(void) +{ + + /* USER CODE BEGIN DAC1_Init 0 */ + + /* USER CODE END DAC1_Init 0 */ + + DAC_ChannelConfTypeDef sConfig = {0}; + + /* USER CODE BEGIN DAC1_Init 1 */ + + /* USER CODE END DAC1_Init 1 */ + + /** DAC Initialization + */ + hdac1.Instance = DAC1; + if (HAL_DAC_Init(&hdac1) != HAL_OK) + { + Error_Handler(); + } + + /** DAC channel OUT2 config + */ + sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE; + sConfig.DAC_Trigger = DAC_TRIGGER_NONE; + sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; + sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE; + sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY; + if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_2) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN DAC1_Init 2 */ + + /* USER CODE END DAC1_Init 2 */ + +} + +void HAL_DAC_MspInit(DAC_HandleTypeDef* dacHandle) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(dacHandle->Instance==DAC1) + { + /* USER CODE BEGIN DAC1_MspInit 0 */ + + /* USER CODE END DAC1_MspInit 0 */ + /* DAC1 clock enable */ + __HAL_RCC_DAC1_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**DAC1 GPIO Configuration + PA5 ------> DAC1_OUT2 + */ + GPIO_InitStruct.Pin = DAC_ADJ_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(DAC_ADJ_GPIO_Port, &GPIO_InitStruct); + + /* USER CODE BEGIN DAC1_MspInit 1 */ + + /* USER CODE END DAC1_MspInit 1 */ + } +} + +void HAL_DAC_MspDeInit(DAC_HandleTypeDef* dacHandle) +{ + + if(dacHandle->Instance==DAC1) + { + /* USER CODE BEGIN DAC1_MspDeInit 0 */ + + /* USER CODE END DAC1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_DAC1_CLK_DISABLE(); + + /**DAC1 GPIO Configuration + PA5 ------> DAC1_OUT2 + */ + HAL_GPIO_DeInit(DAC_ADJ_GPIO_Port, DAC_ADJ_Pin); + + /* USER CODE BEGIN DAC1_MspDeInit 1 */ + + /* USER CODE END DAC1_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + diff --git a/boards/motherboard/src/gpio.c b/boards/motherboard/src/gpio.c index e611891..a864f9f 100644 --- a/boards/motherboard/src/gpio.c +++ b/boards/motherboard/src/gpio.c @@ -40,30 +40,127 @@ void MX_GPIO_Init(void) GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOF_CLK_ENABLE(); + __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOE_CLK_ENABLE(); + __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOD_CLK_ENABLE(); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOE, VGA_CS_N_Pin|TEMP_CS_N_Pin|DEBUG2_Pin|DEBUG1_Pin + |GEN_EN_Pin|LPA_PWR_EN_Pin|VCO_CE_Pin|VCO_LE_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOF, P6V_SCATTER_PWR_EN_Pin|P6V_SCATTER_HSD_DIAG_EN_Pin|P6V_HSD_ONE_SEL_Pin|P6V_HSD_ONE_SEH_Pin + |VGA_PWR_EN_Pin|VCO_PWR_EN_Pin|P6V_HSD_TWO_DIAG_EN_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOC, LNA_EN_Pin|LOGAMP_EN_Pin|WARN_LIGHT_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOF, P6V_SCATTER_PWR_EN_Pin|P6V_SCATTER_HSD_DIAG_EN_Pin|VGA_PWR_EN_Pin|VCO_PWR_EN_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOD, LPA_EN_Pin|VGA_ATTSEL0_Pin|VGA_EN_Pin|VGA_ATTSEL1_Pin + |P12V_HSD_DIAG_EN_Pin|FAN1_PWR_EN_Pin|FAN2_PWR_EN_Pin|P6V_HDS_ONE_DIAG_EN_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOE, DEBUG_Pin|GEN_EN_Pin|LPA_PWR_EN_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOB, P6V_HSD_TWO_SEL_Pin|P6V_HSD_TWO_SEH_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pins : VGA_CS_N_Pin TEMP_CS_N_Pin */ + GPIO_InitStruct.Pin = VGA_CS_N_Pin|TEMP_CS_N_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); - /*Configure GPIO pins : P6V_SCATTER_PWR_EN_Pin P6V_SCATTER_HSD_DIAG_EN_Pin VGA_PWR_EN_Pin VCO_PWR_EN_Pin */ - GPIO_InitStruct.Pin = P6V_SCATTER_PWR_EN_Pin|P6V_SCATTER_HSD_DIAG_EN_Pin|VGA_PWR_EN_Pin|VCO_PWR_EN_Pin; + /*Configure GPIO pins : TEMP_ALERT_N_Pin P5V_VSENSE_Pin P12V_VSENSE_Pin */ + GPIO_InitStruct.Pin = TEMP_ALERT_N_Pin|P5V_VSENSE_Pin|P12V_VSENSE_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /*Configure GPIO pins : P6V_SCATTER_PWR_EN_Pin P6V_SCATTER_HSD_DIAG_EN_Pin P6V_HSD_ONE_SEL_Pin P6V_HSD_ONE_SEH_Pin + VGA_PWR_EN_Pin VCO_PWR_EN_Pin P6V_HSD_TWO_DIAG_EN_Pin */ + GPIO_InitStruct.Pin = P6V_SCATTER_PWR_EN_Pin|P6V_SCATTER_HSD_DIAG_EN_Pin|P6V_HSD_ONE_SEL_Pin|P6V_HSD_ONE_SEH_Pin + |VGA_PWR_EN_Pin|VCO_PWR_EN_Pin|P6V_HSD_TWO_DIAG_EN_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); - /*Configure GPIO pins : DEBUG_Pin GEN_EN_Pin LPA_PWR_EN_Pin */ - GPIO_InitStruct.Pin = DEBUG_Pin|GEN_EN_Pin|LPA_PWR_EN_Pin; + /*Configure GPIO pins : LNA_EN_Pin LOGAMP_EN_Pin WARN_LIGHT_Pin */ + GPIO_InitStruct.Pin = LNA_EN_Pin|LOGAMP_EN_Pin|WARN_LIGHT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /*Configure GPIO pin : PWR_DOWN_Pin */ + GPIO_InitStruct.Pin = PWR_DOWN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(PWR_DOWN_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pins : DEBUG2_Pin DEBUG1_Pin GEN_EN_Pin LPA_PWR_EN_Pin + VCO_CE_Pin VCO_LE_Pin */ + GPIO_InitStruct.Pin = DEBUG2_Pin|DEBUG1_Pin|GEN_EN_Pin|LPA_PWR_EN_Pin + |VCO_CE_Pin|VCO_LE_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); + /*Configure GPIO pin : FAN1_PWM_Pin */ + GPIO_InitStruct.Pin = FAN1_PWM_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(FAN1_PWM_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pin : FAN2_PWM_Pin */ + GPIO_InitStruct.Pin = FAN2_PWM_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(FAN2_PWM_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pins : LPA_EN_Pin VGA_ATTSEL0_Pin VGA_EN_Pin VGA_ATTSEL1_Pin + P12V_HSD_DIAG_EN_Pin FAN1_PWR_EN_Pin FAN2_PWR_EN_Pin P6V_HDS_ONE_DIAG_EN_Pin */ + GPIO_InitStruct.Pin = LPA_EN_Pin|VGA_ATTSEL0_Pin|VGA_EN_Pin|VGA_ATTSEL1_Pin + |P12V_HSD_DIAG_EN_Pin|FAN1_PWR_EN_Pin|FAN2_PWR_EN_Pin|P6V_HDS_ONE_DIAG_EN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /*Configure GPIO pin : P6V_PG_Pin */ + GPIO_InitStruct.Pin = P6V_PG_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(P6V_PG_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pin : USB_nFAULT_Pin */ + GPIO_InitStruct.Pin = USB_nFAULT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(USB_nFAULT_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pins : MUX_ST_Pin nFAULT_FAN1_Pin nFAULT_FAN2_Pin P6V_HSD_ONE_nFAULT_Pin */ + GPIO_InitStruct.Pin = MUX_ST_Pin|nFAULT_FAN1_Pin|nFAULT_FAN2_Pin|P6V_HSD_ONE_nFAULT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /*Configure GPIO pins : P6V_HSD_TWO_nFAULT_Pin VCO_MUXOUT_Pin */ + GPIO_InitStruct.Pin = P6V_HSD_TWO_nFAULT_Pin|VCO_MUXOUT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /*Configure GPIO pins : P6V_HSD_TWO_SEL_Pin P6V_HSD_TWO_SEH_Pin */ + GPIO_InitStruct.Pin = P6V_HSD_TWO_SEL_Pin|P6V_HSD_TWO_SEH_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + } /* USER CODE BEGIN 2 */ diff --git a/boards/motherboard/src/main.c b/boards/motherboard/src/main.c index c2504a6..9935d84 100644 --- a/boards/motherboard/src/main.c +++ b/boards/motherboard/src/main.c @@ -19,6 +19,10 @@ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "cmsis_os.h" +#include "adc.h" +#include "dac.h" +#include "spi.h" +#include "usart.h" #include "usb_device.h" #include "gpio.h" @@ -89,6 +93,11 @@ int main(void) /* Initialize all configured peripherals */ MX_GPIO_Init(); + MX_ADC1_Init(); + MX_DAC1_Init(); + MX_SPI2_Init(); + MX_SPI3_Init(); + MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ // HAL_GPIO_WritePin(VCO_PWR_EN_GPIO_Port, VCO_PWR_EN_Pin, GPIO_PIN_RESET); // HAL_GPIO_WritePin(VGA_PWR_EN_GPIO_Port, VGA_PWR_EN_Pin, GPIO_PIN_RESET); diff --git a/boards/motherboard/src/spi.c b/boards/motherboard/src/spi.c new file mode 100644 index 0000000..b0e9798 --- /dev/null +++ b/boards/motherboard/src/spi.c @@ -0,0 +1,199 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file spi.c + * @brief This file provides code for the configuration + * of the SPI instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "spi.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +SPI_HandleTypeDef hspi2; +SPI_HandleTypeDef hspi3; + +/* SPI2 init function */ +void MX_SPI2_Init(void) +{ + + /* USER CODE BEGIN SPI2_Init 0 */ + + /* USER CODE END SPI2_Init 0 */ + + /* USER CODE BEGIN SPI2_Init 1 */ + + /* USER CODE END SPI2_Init 1 */ + hspi2.Instance = SPI2; + hspi2.Init.Mode = SPI_MODE_MASTER; + hspi2.Init.Direction = SPI_DIRECTION_1LINE; + hspi2.Init.DataSize = SPI_DATASIZE_8BIT; + hspi2.Init.CLKPolarity = SPI_POLARITY_LOW; + hspi2.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi2.Init.NSS = SPI_NSS_SOFT; + hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; + hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB; + hspi2.Init.TIMode = SPI_TIMODE_DISABLE; + hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + hspi2.Init.CRCPolynomial = 7; + hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; + hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE; + if (HAL_SPI_Init(&hspi2) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN SPI2_Init 2 */ + + /* USER CODE END SPI2_Init 2 */ + +} +/* SPI3 init function */ +void MX_SPI3_Init(void) +{ + + /* USER CODE BEGIN SPI3_Init 0 */ + + /* USER CODE END SPI3_Init 0 */ + + /* USER CODE BEGIN SPI3_Init 1 */ + + /* USER CODE END SPI3_Init 1 */ + hspi3.Instance = SPI3; + hspi3.Init.Mode = SPI_MODE_MASTER; + hspi3.Init.Direction = SPI_DIRECTION_2LINES; + hspi3.Init.DataSize = SPI_DATASIZE_8BIT; + hspi3.Init.CLKPolarity = SPI_POLARITY_LOW; + hspi3.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi3.Init.NSS = SPI_NSS_SOFT; + hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; + hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB; + hspi3.Init.TIMode = SPI_TIMODE_DISABLE; + hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + hspi3.Init.CRCPolynomial = 7; + hspi3.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; + hspi3.Init.NSSPMode = SPI_NSS_PULSE_ENABLE; + if (HAL_SPI_Init(&hspi3) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN SPI3_Init 2 */ + + /* USER CODE END SPI3_Init 2 */ + +} + +void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(spiHandle->Instance==SPI2) + { + /* USER CODE BEGIN SPI2_MspInit 0 */ + + /* USER CODE END SPI2_MspInit 0 */ + /* SPI2 clock enable */ + __HAL_RCC_SPI2_CLK_ENABLE(); + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**SPI2 GPIO Configuration + PB7 ------> SPI2_MOSI + PB8 ------> SPI2_SCK + */ + GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF1_SPI2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* USER CODE BEGIN SPI2_MspInit 1 */ + + /* USER CODE END SPI2_MspInit 1 */ + } + else if(spiHandle->Instance==SPI3) + { + /* USER CODE BEGIN SPI3_MspInit 0 */ + + /* USER CODE END SPI3_MspInit 0 */ + /* SPI3 clock enable */ + __HAL_RCC_SPI3_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**SPI3 GPIO Configuration + PC10 ------> SPI3_SCK + PC11 ------> SPI3_MISO + PC12 ------> SPI3_MOSI + */ + GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF4_SPI3; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /* USER CODE BEGIN SPI3_MspInit 1 */ + + /* USER CODE END SPI3_MspInit 1 */ + } +} + +void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) +{ + + if(spiHandle->Instance==SPI2) + { + /* USER CODE BEGIN SPI2_MspDeInit 0 */ + + /* USER CODE END SPI2_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_SPI2_CLK_DISABLE(); + + /**SPI2 GPIO Configuration + PB7 ------> SPI2_MOSI + PB8 ------> SPI2_SCK + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7|GPIO_PIN_8); + + /* USER CODE BEGIN SPI2_MspDeInit 1 */ + + /* USER CODE END SPI2_MspDeInit 1 */ + } + else if(spiHandle->Instance==SPI3) + { + /* USER CODE BEGIN SPI3_MspDeInit 0 */ + + /* USER CODE END SPI3_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_SPI3_CLK_DISABLE(); + + /**SPI3 GPIO Configuration + PC10 ------> SPI3_SCK + PC11 ------> SPI3_MISO + PC12 ------> SPI3_MOSI + */ + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12); + + /* USER CODE BEGIN SPI3_MspDeInit 1 */ + + /* USER CODE END SPI3_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + diff --git a/boards/motherboard/src/usart.c b/boards/motherboard/src/usart.c new file mode 100644 index 0000000..a2edf89 --- /dev/null +++ b/boards/motherboard/src/usart.c @@ -0,0 +1,141 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file usart.c + * @brief This file provides code for the configuration + * of the USART instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "usart.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +UART_HandleTypeDef huart1; + +/* USART1 init function */ + +void MX_USART1_UART_Init(void) +{ + + /* USER CODE BEGIN USART1_Init 0 */ + + /* USER CODE END USART1_Init 0 */ + + /* USER CODE BEGIN USART1_Init 1 */ + + /* USER CODE END USART1_Init 1 */ + huart1.Instance = USART1; + huart1.Init.BaudRate = 115200; + huart1.Init.WordLength = UART_WORDLENGTH_8B; + huart1.Init.StopBits = UART_STOPBITS_1; + huart1.Init.Parity = UART_PARITY_NONE; + huart1.Init.Mode = UART_MODE_TX_RX; + huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart1.Init.OverSampling = UART_OVERSAMPLING_16; + huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&huart1) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) + { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN USART1_Init 2 */ + + /* USER CODE END USART1_Init 2 */ + +} + +void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; + if(uartHandle->Instance==USART1) + { + /* USER CODE BEGIN USART1_MspInit 0 */ + + /* USER CODE END USART1_MspInit 0 */ + + /** Initializes the peripherals clocks + */ + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1; + PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) + { + Error_Handler(); + } + + /* USART1 clock enable */ + __HAL_RCC_USART1_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**USART1 GPIO Configuration + PC4 ------> USART1_TX + PC5 ------> USART1_RX + */ + GPIO_InitStruct.Pin = COMM_TX_Pin|COMM_RX_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF1_USART1; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /* USER CODE BEGIN USART1_MspInit 1 */ + + /* USER CODE END USART1_MspInit 1 */ + } +} + +void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) +{ + + if(uartHandle->Instance==USART1) + { + /* USER CODE BEGIN USART1_MspDeInit 0 */ + + /* USER CODE END USART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USART1_CLK_DISABLE(); + + /**USART1 GPIO Configuration + PC4 ------> USART1_TX + PC5 ------> USART1_RX + */ + HAL_GPIO_DeInit(GPIOC, COMM_TX_Pin|COMM_RX_Pin); + + /* USER CODE BEGIN USART1_MspDeInit 1 */ + + /* USER CODE END USART1_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ + From ff04bde87729795faf2452e2c9904608ce1fcf79 Mon Sep 17 00:00:00 2001 From: Ivan Lange Date: Thu, 2 Apr 2026 12:32:44 -0400 Subject: [PATCH 06/13] Prepare rough project for in-lab debugging - refactor soon --- boards/motherboard/Inc/FreeRTOSConfig.h | 72 +- boards/motherboard/Inc/adc.h | 33 +- boards/motherboard/Inc/dac.h | 33 +- boards/motherboard/Inc/gpio.h | 1 - boards/motherboard/Inc/main.h | 7 +- boards/motherboard/Inc/spi.h | 33 +- boards/motherboard/Inc/stm32g0xx_hal_conf.h | 235 ++-- boards/motherboard/Inc/stm32g0xx_it.h | 1 + boards/motherboard/Inc/tim.h | 53 + boards/motherboard/Inc/usart.h | 33 +- boards/motherboard/Inc/usb_device.h | 76 +- boards/motherboard/Inc/usbd_cdc_if.h | 112 +- boards/motherboard/Inc/usbd_conf.h | 156 +-- boards/motherboard/Inc/usbd_desc.h | 129 +- boards/motherboard/lib/adf5355 | 1 + boards/motherboard/lib/periph | 1 + boards/motherboard/lib/util | 1 + boards/motherboard/motherboard.ioc | 211 ++-- boards/motherboard/src/adc.c | 245 ++-- boards/motherboard/src/app_freertos.c | 140 --- boards/motherboard/src/dac.c | 154 ++- boards/motherboard/src/gpio.c | 275 +++-- boards/motherboard/src/main.c | 240 ++-- boards/motherboard/src/spi.c | 313 +++-- boards/motherboard/src/stm32g0xx_hal_msp.c | 33 +- .../src/stm32g0xx_hal_timebase_tim.c | 181 ++- boards/motherboard/src/stm32g0xx_it.c | 75 +- boards/motherboard/src/tasks.cpp | 118 +- boards/motherboard/src/tim.c | 129 ++ boards/motherboard/src/usart.c | 211 ++-- boards/motherboard/src/usb_device.c | 96 +- boards/motherboard/src/usbd_cdc_if.c | 399 +++---- boards/motherboard/src/usbd_conf.c | 1057 ++++++++--------- boards/motherboard/src/usbd_desc.c | 532 ++++----- lib/adf5355/adf5355.hpp | 10 +- lib/periph/analog_input.hpp | 2 +- lib/periph/analog_output.hpp | 2 +- lib/periph/digital.hpp | 2 +- lib/periph/pwm.hpp | 86 ++ 39 files changed, 2833 insertions(+), 2655 deletions(-) create mode 100644 boards/motherboard/Inc/tim.h create mode 120000 boards/motherboard/lib/adf5355 create mode 120000 boards/motherboard/lib/periph create mode 120000 boards/motherboard/lib/util delete mode 100644 boards/motherboard/src/app_freertos.c create mode 100644 boards/motherboard/src/tim.c create mode 100644 lib/periph/pwm.hpp diff --git a/boards/motherboard/Inc/FreeRTOSConfig.h b/boards/motherboard/Inc/FreeRTOSConfig.h index 6ef313d..d9bfc99 100644 --- a/boards/motherboard/Inc/FreeRTOSConfig.h +++ b/boards/motherboard/Inc/FreeRTOSConfig.h @@ -39,8 +39,8 @@ * These definitions should be adjusted for your particular hardware and * application requirements. * - * These parameters and more are described within the 'configuration' section of the - * FreeRTOS API documentation available on the FreeRTOS.org web site. + * These parameters and more are described within the 'configuration' section of + * the FreeRTOS API documentation available on the FreeRTOS.org web site. * * See http://www.freertos.org/a00110.html *----------------------------------------------------------*/ @@ -49,28 +49,29 @@ /* Section where include file can be added */ /* USER CODE END Includes */ -/* Ensure definitions are only used by the compiler, and not by the assembler. */ +/* Ensure definitions are only used by the compiler, and not by the assembler. + */ #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) - #include - extern uint32_t SystemCoreClock; +#include +extern uint32_t SystemCoreClock; #endif -#define configENABLE_FPU 0 -#define configENABLE_MPU 0 +#define configENABLE_FPU 0 +#define configENABLE_MPU 0 -#define configUSE_PREEMPTION 1 -#define configSUPPORT_STATIC_ALLOCATION 1 -#define configSUPPORT_DYNAMIC_ALLOCATION 0 -#define configUSE_IDLE_HOOK 0 -#define configUSE_TICK_HOOK 0 -#define configCPU_CLOCK_HZ ( SystemCoreClock ) -#define configTICK_RATE_HZ ((TickType_t)1000) -#define configMAX_PRIORITIES ( 7 ) -#define configMINIMAL_STACK_SIZE ((uint16_t)128) -#define configMAX_TASK_NAME_LEN ( 16 ) -#define configUSE_16_BIT_TICKS 0 -#define configUSE_MUTEXES 1 -#define configQUEUE_REGISTRY_SIZE 8 -#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 +#define configUSE_PREEMPTION 1 +#define configSUPPORT_STATIC_ALLOCATION 1 +#define configSUPPORT_DYNAMIC_ALLOCATION 0 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ (SystemCoreClock) +#define configTICK_RATE_HZ ((TickType_t)1000) +#define configMAX_PRIORITIES (7) +#define configMINIMAL_STACK_SIZE ((uint16_t)128) +#define configMAX_TASK_NAME_LEN (16) +#define configUSE_16_BIT_TICKS 0 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 /* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */ /* Defaults to size_t for backward compatibility, but can be changed if lengths will always be less than the number of bytes in a size_t. */ @@ -78,22 +79,22 @@ /* USER CODE END MESSAGE_BUFFER_LENGTH_TYPE */ /* Co-routine definitions. */ -#define configUSE_CO_ROUTINES 0 -#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES (2) /* The following flag must be enabled only when using newlib */ -#define configUSE_NEWLIB_REENTRANT 1 +#define configUSE_NEWLIB_REENTRANT 1 /* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */ -#define INCLUDE_vTaskPrioritySet 1 -#define INCLUDE_uxTaskPriorityGet 1 -#define INCLUDE_vTaskDelete 1 -#define INCLUDE_vTaskCleanUpResources 0 -#define INCLUDE_vTaskSuspend 1 -#define INCLUDE_vTaskDelayUntil 1 -#define INCLUDE_vTaskDelay 1 -#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 /* Normal assert() semantics without relying on the provision of an assert.h header file. */ @@ -107,11 +108,12 @@ header file. */ /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS standard names. */ -#define vPortSVCHandler SVC_Handler +#define vPortSVCHandler SVC_Handler #define xPortPendSVHandler PendSV_Handler -/* IMPORTANT: This define is commented when used with STM32Cube firmware, when the timebase source is SysTick, - to prevent overwriting SysTick_Handler defined within STM32Cube HAL */ +/* IMPORTANT: This define is commented when used with STM32Cube firmware, when + the timebase source is SysTick, to prevent overwriting SysTick_Handler + defined within STM32Cube HAL */ #define xPortSysTickHandler SysTick_Handler diff --git a/boards/motherboard/Inc/adc.h b/boards/motherboard/Inc/adc.h index b844764..652cc78 100644 --- a/boards/motherboard/Inc/adc.h +++ b/boards/motherboard/Inc/adc.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file adc.h - * @brief This file contains all the function prototypes for - * the adc.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file adc.h + * @brief This file contains all the function prototypes for + * the adc.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __ADC_H__ @@ -49,4 +49,3 @@ void MX_ADC1_Init(void); #endif #endif /* __ADC_H__ */ - diff --git a/boards/motherboard/Inc/dac.h b/boards/motherboard/Inc/dac.h index 04e00b7..f2e6b4f 100644 --- a/boards/motherboard/Inc/dac.h +++ b/boards/motherboard/Inc/dac.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file dac.h - * @brief This file contains all the function prototypes for - * the dac.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file dac.h + * @brief This file contains all the function prototypes for + * the dac.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __DAC_H__ @@ -49,4 +49,3 @@ void MX_DAC1_Init(void); #endif #endif /* __DAC_H__ */ - diff --git a/boards/motherboard/Inc/gpio.h b/boards/motherboard/Inc/gpio.h index c91d06e..907d2a4 100644 --- a/boards/motherboard/Inc/gpio.h +++ b/boards/motherboard/Inc/gpio.h @@ -46,4 +46,3 @@ void MX_GPIO_Init(void); } #endif #endif /*__ GPIO_H__ */ - diff --git a/boards/motherboard/Inc/main.h b/boards/motherboard/Inc/main.h index ae3ad5a..3f7f1d3 100644 --- a/boards/motherboard/Inc/main.h +++ b/boards/motherboard/Inc/main.h @@ -85,6 +85,7 @@ void Error_Handler(void); #define COMM_RX_GPIO_Port GPIOC #define PWR_DOWN_Pin GPIO_PIN_0 #define PWR_DOWN_GPIO_Port GPIOB +#define PWR_DOWN_EXTI_IRQn EXTI0_1_IRQn #define P6V_CS_TWO_Pin GPIO_PIN_1 #define P6V_CS_TWO_GPIO_Port GPIOB #define P6V_CS_ONE_Pin GPIO_PIN_2 @@ -95,8 +96,8 @@ void Error_Handler(void); #define DEBUG1_GPIO_Port GPIOE #define P12V_CS_Pin GPIO_PIN_10 #define P12V_CS_GPIO_Port GPIOB -#define FAN1_PWM_Pin GPIO_PIN_9 -#define FAN1_PWM_GPIO_Port GPIOA +#define FAN1_PWN_Pin GPIO_PIN_9 +#define FAN1_PWN_GPIO_Port GPIOA #define WARN_LIGHT_Pin GPIO_PIN_6 #define WARN_LIGHT_GPIO_Port GPIOC #define FAN2_PWM_Pin GPIO_PIN_7 @@ -161,7 +162,7 @@ void Error_Handler(void); #define VCO_MUXOUT_GPIO_Port GPIOB /* USER CODE BEGIN Private defines */ - +extern int pwr_down_flag; /* USER CODE END Private defines */ #ifdef __cplusplus diff --git a/boards/motherboard/Inc/spi.h b/boards/motherboard/Inc/spi.h index d674292..734914c 100644 --- a/boards/motherboard/Inc/spi.h +++ b/boards/motherboard/Inc/spi.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file spi.h - * @brief This file contains all the function prototypes for - * the spi.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file spi.h + * @brief This file contains all the function prototypes for + * the spi.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __SPI_H__ @@ -52,4 +52,3 @@ void MX_SPI3_Init(void); #endif #endif /* __SPI_H__ */ - diff --git a/boards/motherboard/Inc/stm32g0xx_hal_conf.h b/boards/motherboard/Inc/stm32g0xx_hal_conf.h index 49b45a8..e81375d 100644 --- a/boards/motherboard/Inc/stm32g0xx_hal_conf.h +++ b/boards/motherboard/Inc/stm32g0xx_hal_conf.h @@ -31,8 +31,8 @@ extern "C" { /* ########################## Module Selection ############################## */ /** - * @brief This is the list of modules to be used in the HAL driver - */ + * @brief This is the list of modules to be used in the HAL driver + */ #define HAL_MODULE_ENABLED #define HAL_ADC_MODULE_ENABLED /* #define HAL_CEC_MODULE_ENABLED */ @@ -66,106 +66,115 @@ extern "C" { #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_CEC_REGISTER_CALLBACKS 0u -#define USE_HAL_COMP_REGISTER_CALLBACKS 0u -#define USE_HAL_CRYP_REGISTER_CALLBACKS 0u -#define USE_HAL_DAC_REGISTER_CALLBACKS 0u -#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0u -#define USE_HAL_HCD_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_PCD_REGISTER_CALLBACKS 0u -#define USE_HAL_RNG_REGISTER_CALLBACKS 0u -#define USE_HAL_RTC_REGISTER_CALLBACKS 0u -#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0u -#define USE_HAL_SPI_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_CEC_REGISTER_CALLBACKS 0u +#define USE_HAL_COMP_REGISTER_CALLBACKS 0u +#define USE_HAL_CRYP_REGISTER_CALLBACKS 0u +#define USE_HAL_DAC_REGISTER_CALLBACKS 0u +#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0u +#define USE_HAL_HCD_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_PCD_REGISTER_CALLBACKS 0u +#define USE_HAL_RNG_REGISTER_CALLBACKS 0u +#define USE_HAL_RTC_REGISTER_CALLBACKS 0u +#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0u +#define USE_HAL_SPI_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 (8000000UL) /*!< 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 (8000000UL) /*!< 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 */ #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx) /** - * @brief Internal High Speed oscillator (HSI48) value for USB FS, SDMMC 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 48000000U /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/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, SDMMC 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 \ + 48000000U /*!< Value of the Internal High Speed oscillator for USB \ + FS/SDMMC/RNG in Hz. The real value my vary depending on \ + manufacturing process variations.*/ +#endif /* HSI48_VALUE */ #endif /** - * @brief Internal Low Speed oscillator (LSI) value. - */ -#if !defined (LSI_VALUE) -#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ -#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz -The real value may vary depending on the variations + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined(LSI_VALUE) +#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz \ +The real value may vary depending on the variations \ in voltage and temperature.*/ /** - * @brief External Low Speed oscillator (LSE) value. - * 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 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 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 I2S1 peripheral - * This value is used by the RCC HAL module to compute the I2S1 clock source - * frequency. - */ -#if !defined (EXTERNAL_I2S1_CLOCK_VALUE) -#define EXTERNAL_I2S1_CLOCK_VALUE (48000UL) /*!< Value of the I2S1 External clock source in Hz*/ -#endif /* EXTERNAL_I2S1_CLOCK_VALUE */ + * @brief External clock source for I2S1 peripheral + * This value is used by the RCC HAL module to compute the I2S1 clock + * source frequency. + */ +#if !defined(EXTERNAL_I2S1_CLOCK_VALUE) +#define EXTERNAL_I2S1_CLOCK_VALUE \ + (48000UL) /*!< Value of the I2S1 External clock source in Hz*/ +#endif /* EXTERNAL_I2S1_CLOCK_VALUE */ #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx) /** - * @brief External clock source for I2S2 peripheral - * This value is used by the RCC HAL module to compute the I2S2 clock source - * frequency. - */ -#if !defined (EXTERNAL_I2S2_CLOCK_VALUE) - #define EXTERNAL_I2S2_CLOCK_VALUE 48000U /*!< Value of the I2S2 External clock source in Hz*/ -#endif /* EXTERNAL_I2S2_CLOCK_VALUE */ + * @brief External clock source for I2S2 peripheral + * This value is used by the RCC HAL module to compute the I2S2 clock + * source frequency. + */ +#if !defined(EXTERNAL_I2S2_CLOCK_VALUE) +#define EXTERNAL_I2S2_CLOCK_VALUE \ + 48000U /*!< Value of the I2S2 External clock source in Hz*/ +#endif /* EXTERNAL_I2S2_CLOCK_VALUE */ #endif /* Tip: To avoid modifying this file each time you need to use different HSE, @@ -173,38 +182,39 @@ in voltage and temperature.*/ /* ########################### System Configuration ######################### */ /** - * @brief This is the HAL system configuration section - */ -#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ -#define TICK_INT_PRIORITY 3U /*!< tick interrupt priority */ -#define USE_RTOS 0U -#define PREFETCH_ENABLE 1U -#define INSTRUCTION_CACHE_ENABLE 1U + * @brief This is the HAL system configuration section + */ +#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY 3U /*!< tick interrupt priority */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 1U +#define INSTRUCTION_CACHE_ENABLE 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 -*/ + * Activated: CRC code is present inside driver + * Deactivated: CRC code cleaned from driver + */ -#define USE_SPI_CRC 0U +#define USE_SPI_CRC 0U -/* ################## CRYP peripheral configuration ########################## */ +/* ################## CRYP peripheral configuration ########################## + */ -#define USE_HAL_CRYP_SUSPEND_RESUME 1U +#define USE_HAL_CRYP_SUSPEND_RESUME 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 */ /* Includes ------------------------------------------------------------------*/ /** - * @brief Include modules header file - */ + * @brief Include modules header file + */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g0xx_hal_rcc.h" @@ -328,18 +338,19 @@ 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 functions 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 functions 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); +void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ diff --git a/boards/motherboard/Inc/stm32g0xx_it.h b/boards/motherboard/Inc/stm32g0xx_it.h index 3833c29..4cc4459 100644 --- a/boards/motherboard/Inc/stm32g0xx_it.h +++ b/boards/motherboard/Inc/stm32g0xx_it.h @@ -48,6 +48,7 @@ extern "C" { /* Exported functions prototypes ---------------------------------------------*/ void NMI_Handler(void); void HardFault_Handler(void); +void EXTI0_1_IRQHandler(void); void TIM1_BRK_UP_TRG_COM_IRQHandler(void); /* USER CODE BEGIN EFP */ diff --git a/boards/motherboard/Inc/tim.h b/boards/motherboard/Inc/tim.h new file mode 100644 index 0000000..b65b0db --- /dev/null +++ b/boards/motherboard/Inc/tim.h @@ -0,0 +1,53 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file tim.h + * @brief This file contains all the function prototypes for + * the tim.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __TIM_H__ +#define __TIM_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern TIM_HandleTypeDef htim2; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_TIM2_Init(void); + +void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIM_H__ */ diff --git a/boards/motherboard/Inc/usart.h b/boards/motherboard/Inc/usart.h index a13cfca..714fb76 100644 --- a/boards/motherboard/Inc/usart.h +++ b/boards/motherboard/Inc/usart.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file usart.h - * @brief This file contains all the function prototypes for - * the usart.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file usart.h + * @brief This file contains all the function prototypes for + * the usart.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USART_H__ @@ -49,4 +49,3 @@ void MX_USART1_UART_Init(void); #endif #endif /* __USART_H__ */ - diff --git a/boards/motherboard/Inc/usb_device.h b/boards/motherboard/Inc/usb_device.h index 75e8e77..8e7d566 100644 --- a/boards/motherboard/Inc/usb_device.h +++ b/boards/motherboard/Inc/usb_device.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file : usb_device.h - * @version : v3.0_Cube - * @brief : Header for usb_device.c file. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file : usb_device.h + * @version : v3.0_Cube + * @brief : Header for usb_device.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ @@ -23,7 +23,7 @@ #define __USB_DEVICE__H__ #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -36,18 +36,18 @@ /* USER CODE END INCLUDE */ /** @addtogroup USBD_OTG_DRIVER - * @{ - */ + * @{ + */ /** @defgroup USBD_DEVICE USBD_DEVICE - * @brief Device file for Usb otg low level driver. - * @{ - */ + * @brief Device file for Usb otg low level driver. + * @{ + */ /** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables - * @brief Public variables. - * @{ - */ + * @brief Public variables. + * @{ + */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ @@ -66,13 +66,14 @@ /* USER CODE END VARIABLES */ /** - * @} - */ + * @} + */ -/** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype - * @brief Declaration of public functions for Usb device. - * @{ - */ +/** @defgroup USBD_DEVICE_Exported_FunctionsPrototype + * USBD_DEVICE_Exported_FunctionsPrototype + * @brief Declaration of public functions for Usb device. + * @{ + */ /** USB Device initialization function. */ void MX_USB_Device_Init(void); @@ -84,20 +85,19 @@ void MX_USB_Device_Init(void); /* USER CODE END FD */ /** - * @} - */ + * @} + */ /** - * @} - */ + * @} + */ /** - * @} - */ + * @} + */ #ifdef __cplusplus } #endif #endif /* __USB_DEVICE__H__ */ - diff --git a/boards/motherboard/Inc/usbd_cdc_if.h b/boards/motherboard/Inc/usbd_cdc_if.h index a39a635..141a052 100644 --- a/boards/motherboard/Inc/usbd_cdc_if.h +++ b/boards/motherboard/Inc/usbd_cdc_if.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file : usbd_cdc_if.h - * @version : v3.0_Cube - * @brief : Header for usbd_cdc_if.c file. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file : usbd_cdc_if.h + * @version : v3.0_Cube + * @brief : Header for usbd_cdc_if.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ @@ -24,7 +24,7 @@ #define __USBD_CDC_IF_H__ #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -35,60 +35,60 @@ /* USER CODE END INCLUDE */ /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @brief For Usb device. - * @{ - */ + * @brief For Usb device. + * @{ + */ /** @defgroup USBD_CDC_IF USBD_CDC_IF - * @brief Usb VCP device module - * @{ - */ + * @brief Usb VCP device module + * @{ + */ /** @defgroup USBD_CDC_IF_Exported_Defines USBD_CDC_IF_Exported_Defines - * @brief Defines. - * @{ - */ + * @brief Defines. + * @{ + */ /* Define size for the receive and transmit buffer over CDC */ -#define APP_RX_DATA_SIZE 2048 -#define APP_TX_DATA_SIZE 2048 +#define APP_RX_DATA_SIZE 2048 +#define APP_TX_DATA_SIZE 2048 /* USER CODE BEGIN EXPORTED_DEFINES */ /* USER CODE END EXPORTED_DEFINES */ /** - * @} - */ + * @} + */ /** @defgroup USBD_CDC_IF_Exported_Types USBD_CDC_IF_Exported_Types - * @brief Types. - * @{ - */ + * @brief Types. + * @{ + */ /* USER CODE BEGIN EXPORTED_TYPES */ /* USER CODE END EXPORTED_TYPES */ /** - * @} - */ + * @} + */ /** @defgroup USBD_CDC_IF_Exported_Macros USBD_CDC_IF_Exported_Macros - * @brief Aliases. - * @{ - */ + * @brief Aliases. + * @{ + */ /* USER CODE BEGIN EXPORTED_MACRO */ /* USER CODE END EXPORTED_MACRO */ /** - * @} - */ + * @} + */ /** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables - * @brief Public variables. - * @{ - */ + * @brief Public variables. + * @{ + */ /** CDC Interface callback. */ extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS; @@ -98,13 +98,14 @@ extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS; /* USER CODE END EXPORTED_VARIABLES */ /** - * @} - */ + * @} + */ -/** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype USBD_CDC_IF_Exported_FunctionsPrototype - * @brief Public functions declaration. - * @{ - */ +/** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype + * USBD_CDC_IF_Exported_FunctionsPrototype + * @brief Public functions declaration. + * @{ + */ uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len); @@ -113,20 +114,19 @@ uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len); /* USER CODE END EXPORTED_FUNCTIONS */ /** - * @} - */ + * @} + */ /** - * @} - */ + * @} + */ /** - * @} - */ + * @} + */ #ifdef __cplusplus } #endif #endif /* __USBD_CDC_IF_H__ */ - diff --git a/boards/motherboard/Inc/usbd_conf.h b/boards/motherboard/Inc/usbd_conf.h index 6175d73..e7833f5 100644 --- a/boards/motherboard/Inc/usbd_conf.h +++ b/boards/motherboard/Inc/usbd_conf.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file : usbd_conf.h - * @version : v3.0_Cube - * @brief : Header for usbd_conf.c file. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file : usbd_conf.h + * @version : v3.0_Cube + * @brief : Header for usbd_conf.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ @@ -23,13 +23,14 @@ #define __USBD_CONF__H__ #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include #include #include + #include "stm32g0xx.h" #include "stm32g0xx_hal.h" @@ -38,137 +39,140 @@ /* USER CODE END INCLUDE */ /** @addtogroup USBD_OTG_DRIVER - * @brief Driver for Usb device. - * @{ - */ + * @brief Driver for Usb device. + * @{ + */ /** @defgroup USBD_CONF USBD_CONF - * @brief Configuration file for Usb otg low level driver. - * @{ - */ + * @brief Configuration file for Usb otg low level driver. + * @{ + */ /** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables - * @brief Public variables. - * @{ - */ + * @brief Public variables. + * @{ + */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /** - * @} - */ + * @} + */ /** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines - * @brief Defines for configuration of the Usb device. - * @{ - */ + * @brief Defines for configuration of the Usb device. + * @{ + */ /*---------- -----------*/ -#define USBD_MAX_NUM_INTERFACES 1U +#define USBD_MAX_NUM_INTERFACES 1U /*---------- -----------*/ -#define USBD_MAX_NUM_CONFIGURATION 1U +#define USBD_MAX_NUM_CONFIGURATION 1U /*---------- -----------*/ -#define USBD_MAX_STR_DESC_SIZ 512U +#define USBD_MAX_STR_DESC_SIZ 512U /*---------- -----------*/ -#define USBD_DEBUG_LEVEL 0U +#define USBD_DEBUG_LEVEL 0U /*---------- -----------*/ -#define USBD_LPM_ENABLED 1U +#define USBD_LPM_ENABLED 1U /*---------- -----------*/ -#define USBD_SELF_POWERED 1U +#define USBD_SELF_POWERED 1U /****************************************/ /* #define for FS and HS identification */ -#define DEVICE_FS 0 +#define DEVICE_FS 0 /** - * @} - */ + * @} + */ /** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros - * @brief Aliases. - * @{ - */ + * @brief Aliases. + * @{ + */ /* Memory management macros make sure to use static memory allocation */ /** Alias for memory allocation. */ -#define USBD_malloc (void *)USBD_static_malloc +#define USBD_malloc (void*)USBD_static_malloc /** Alias for memory release. */ -#define USBD_free USBD_static_free +#define USBD_free USBD_static_free /** Alias for memory set. */ -#define USBD_memset memset +#define USBD_memset memset /** Alias for memory copy. */ -#define USBD_memcpy memcpy +#define USBD_memcpy memcpy /** Alias for delay. */ -#define USBD_Delay HAL_Delay +#define USBD_Delay HAL_Delay /* DEBUG macros */ #if (USBD_DEBUG_LEVEL > 0) -#define USBD_UsrLog(...) printf(__VA_ARGS__);\ - printf("\n"); +#define USBD_UsrLog(...) \ + printf(__VA_ARGS__); \ + printf("\n"); #else #define USBD_UsrLog(...) #endif #if (USBD_DEBUG_LEVEL > 1) -#define USBD_ErrLog(...) printf("ERROR: ") ;\ - printf(__VA_ARGS__);\ - printf("\n"); +#define USBD_ErrLog(...) \ + printf("ERROR: "); \ + printf(__VA_ARGS__); \ + printf("\n"); #else #define USBD_ErrLog(...) #endif #if (USBD_DEBUG_LEVEL > 2) -#define USBD_DbgLog(...) printf("DEBUG : ") ;\ - printf(__VA_ARGS__);\ - printf("\n"); +#define USBD_DbgLog(...) \ + printf("DEBUG : "); \ + printf(__VA_ARGS__); \ + printf("\n"); #else #define USBD_DbgLog(...) #endif /** - * @} - */ + * @} + */ /** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types - * @brief Types. - * @{ - */ + * @brief Types. + * @{ + */ /** - * @} - */ + * @} + */ -/** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype - * @brief Declaration of public functions for Usb device. - * @{ - */ +/** @defgroup USBD_CONF_Exported_FunctionsPrototype + * USBD_CONF_Exported_FunctionsPrototype + * @brief Declaration of public functions for Usb device. + * @{ + */ /* Exported functions -------------------------------------------------------*/ -void *USBD_static_malloc(uint32_t size); -void USBD_static_free(void *p); +void* USBD_static_malloc(uint32_t size); +void USBD_static_free(void* p); /** - * @} - */ + * @} + */ /** - * @} - */ + * @} + */ /** - * @} - */ + * @} + */ #ifdef __cplusplus } #endif #endif /* __USBD_CONF__H__ */ - diff --git a/boards/motherboard/Inc/usbd_desc.h b/boards/motherboard/Inc/usbd_desc.h index 9916164..a9c6f90 100644 --- a/boards/motherboard/Inc/usbd_desc.h +++ b/boards/motherboard/Inc/usbd_desc.h @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file : usbd_desc.c - * @version : v3.0_Cube - * @brief : Header for usbd_conf.c file. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file : usbd_desc.c + * @version : v3.0_Cube + * @brief : Header for usbd_conf.c file. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ @@ -23,7 +23,7 @@ #define __USBD_DESC__C__ #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* Includes ------------------------------------------------------------------*/ @@ -34,110 +34,111 @@ /* USER CODE END INCLUDE */ /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @{ - */ + * @{ + */ /** @defgroup USBD_DESC USBD_DESC - * @brief Usb device descriptors module. - * @{ - */ + * @brief Usb device descriptors module. + * @{ + */ /** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants - * @brief Constants. - * @{ - */ -#define DEVICE_ID1 (UID_BASE) -#define DEVICE_ID2 (UID_BASE + 0x4) -#define DEVICE_ID3 (UID_BASE + 0x8) + * @brief Constants. + * @{ + */ +#define DEVICE_ID1 (UID_BASE) +#define DEVICE_ID2 (UID_BASE + 0x4) +#define DEVICE_ID3 (UID_BASE + 0x8) -#define USB_SIZ_STRING_SERIAL 0x1A +#define USB_SIZ_STRING_SERIAL 0x1A /* USER CODE BEGIN EXPORTED_CONSTANTS */ /* USER CODE END EXPORTED_CONSTANTS */ /** - * @} - */ + * @} + */ /** @defgroup USBD_DESC_Exported_Defines USBD_DESC_Exported_Defines - * @brief Defines. - * @{ - */ + * @brief Defines. + * @{ + */ /* USER CODE BEGIN EXPORTED_DEFINES */ /* USER CODE END EXPORTED_DEFINES */ /** - * @} - */ + * @} + */ -/** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions - * @brief Types. - * @{ - */ +/** @defgroup USBD_DESC_Exported_TypesDefinitions + * USBD_DESC_Exported_TypesDefinitions + * @brief Types. + * @{ + */ /* USER CODE BEGIN EXPORTED_TYPES */ /* USER CODE END EXPORTED_TYPES */ /** - * @} - */ + * @} + */ /** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros - * @brief Aliases. - * @{ - */ + * @brief Aliases. + * @{ + */ /* USER CODE BEGIN EXPORTED_MACRO */ /* USER CODE END EXPORTED_MACRO */ /** - * @} - */ + * @} + */ /** @defgroup USBD_DESC_Exported_Variables USBD_DESC_Exported_Variables - * @brief Public variables. - * @{ - */ + * @brief Public variables. + * @{ + */ -extern USBD_DescriptorsTypeDef CDC_Desc; +extern USBD_DescriptorsTypeDef CDC_Desc; /* USER CODE BEGIN EXPORTED_VARIABLES */ /* USER CODE END EXPORTED_VARIABLES */ /** - * @} - */ + * @} + */ -/** @defgroup USBD_DESC_Exported_FunctionsPrototype USBD_DESC_Exported_FunctionsPrototype - * @brief Public functions declaration. - * @{ - */ +/** @defgroup USBD_DESC_Exported_FunctionsPrototype + * USBD_DESC_Exported_FunctionsPrototype + * @brief Public functions declaration. + * @{ + */ /* USER CODE BEGIN EXPORTED_FUNCTIONS */ /* USER CODE END EXPORTED_FUNCTIONS */ /** - * @} - */ + * @} + */ /** - * @} - */ + * @} + */ /** - * @} - */ + * @} + */ #ifdef __cplusplus } #endif #endif /* __USBD_DESC__C__ */ - diff --git a/boards/motherboard/lib/adf5355 b/boards/motherboard/lib/adf5355 new file mode 120000 index 0000000..ae8f57a --- /dev/null +++ b/boards/motherboard/lib/adf5355 @@ -0,0 +1 @@ +../../../lib/adf5355 \ No newline at end of file diff --git a/boards/motherboard/lib/periph b/boards/motherboard/lib/periph new file mode 120000 index 0000000..124d03d --- /dev/null +++ b/boards/motherboard/lib/periph @@ -0,0 +1 @@ +../../../lib/periph \ No newline at end of file diff --git a/boards/motherboard/lib/util b/boards/motherboard/lib/util new file mode 120000 index 0000000..5219c6c --- /dev/null +++ b/boards/motherboard/lib/util @@ -0,0 +1 @@ +../../../lib/util \ No newline at end of file diff --git a/boards/motherboard/motherboard.ioc b/boards/motherboard/motherboard.ioc index 225210d..f872665 100644 --- a/boards/motherboard/motherboard.ioc +++ b/boards/motherboard/motherboard.ioc @@ -1,4 +1,3 @@ -#MicroXplorer Configuration settings - do not modify ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_0 ADC1.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag,master,SelectedChannel ADC1.NbrOfConversionFlag=1 @@ -10,11 +9,11 @@ CAD.formats= CAD.pinconfig= CAD.provider= DAC1.DAC_Channel-DAC_OUT2=DAC_CHANNEL_2 -DAC1.IPParameters=DAC_Channel-DAC_OUT2 -FREERTOS.Events01= +DAC1.DAC_UserTrimming-DAC_OUT2=DAC_TRIMMING_FACTORY +DAC1.IPParameters=DAC_Channel-DAC_OUT2,DAC_UserTrimming-DAC_OUT2 FREERTOS.FootprintOK=true FREERTOS.INCLUDE_vTaskDelayUntil=1 -FREERTOS.IPParameters=Tasks01,INCLUDE_vTaskDelayUntil,MEMORY_ALLOCATION,FootprintOK,configUSE_NEWLIB_REENTRANT,Events01 +FREERTOS.IPParameters=Tasks01,INCLUDE_vTaskDelayUntil,MEMORY_ALLOCATION,FootprintOK,configUSE_NEWLIB_REENTRANT FREERTOS.MEMORY_ALLOCATION=1 FREERTOS.Tasks01=defaultTask,0,128,StartDefaultTask,Default,NULL,Static,defaultTaskBuffer,defaultTaskControlBlock FREERTOS.configUSE_NEWLIB_REENTRANT=1 @@ -25,20 +24,29 @@ Mcu.CPN=STM32G0B1VET6 Mcu.Family=STM32G0 Mcu.IP0=ADC1 Mcu.IP1=DAC1 -Mcu.IP10=USB_DRD_FS Mcu.IP2=FREERTOS Mcu.IP3=NVIC Mcu.IP4=RCC Mcu.IP5=SPI2 Mcu.IP6=SPI3 Mcu.IP7=SYS -Mcu.IP8=USART1 -Mcu.IP9=USB_DEVICE -Mcu.IPNb=11 +Mcu.IP8=TIM2 +Mcu.IP9=USART1 +Mcu.IP10=USB_DEVICE +Mcu.IP11=USB_DRD_FS +Mcu.IPNb=12 Mcu.Name=STM32G0B1V(B-C-E)Tx Mcu.Package=LQFP100 Mcu.Pin0=PB9 Mcu.Pin1=PC10 +Mcu.Pin2=PC11 +Mcu.Pin3=PE4 +Mcu.Pin4=PE5 +Mcu.Pin5=PE6 +Mcu.Pin6=PC12 +Mcu.Pin7=PC13 +Mcu.Pin8=PC14-OSC32_IN (PC14) +Mcu.Pin9=PC15-OSC32_OUT (PC15) Mcu.Pin10=PF0-OSC_IN (PF0) Mcu.Pin11=PF1-OSC_OUT (PF1) Mcu.Pin12=PF2-NRST @@ -49,7 +57,6 @@ Mcu.Pin16=PC0 Mcu.Pin17=PC1 Mcu.Pin18=PC2 Mcu.Pin19=PC3 -Mcu.Pin2=PC11 Mcu.Pin20=PA0 Mcu.Pin21=PA1 Mcu.Pin22=PA2 @@ -60,7 +67,6 @@ Mcu.Pin26=PA6 Mcu.Pin27=PA7 Mcu.Pin28=PC4 Mcu.Pin29=PC5 -Mcu.Pin3=PE4 Mcu.Pin30=PB0 Mcu.Pin31=PB1 Mcu.Pin32=PB2 @@ -71,7 +77,6 @@ Mcu.Pin36=PE8 Mcu.Pin37=PE9 Mcu.Pin38=PE10 Mcu.Pin39=PE11 -Mcu.Pin4=PE5 Mcu.Pin40=PE12 Mcu.Pin41=PE13 Mcu.Pin42=PE14 @@ -82,7 +87,6 @@ Mcu.Pin46=PB12 Mcu.Pin47=PB13 Mcu.Pin48=PB14 Mcu.Pin49=PB15 -Mcu.Pin5=PE6 Mcu.Pin50=PA8 Mcu.Pin51=PA9 Mcu.Pin52=PC6 @@ -93,7 +97,6 @@ Mcu.Pin56=PD10 Mcu.Pin57=PD11 Mcu.Pin58=PD12 Mcu.Pin59=PD13 -Mcu.Pin6=PC12 Mcu.Pin60=PD14 Mcu.Pin61=PD15 Mcu.Pin62=PA10 @@ -104,7 +107,6 @@ Mcu.Pin66=PA13 Mcu.Pin67=PA14-BOOT0 Mcu.Pin68=PA15 Mcu.Pin69=PC8 -Mcu.Pin7=PC13 Mcu.Pin70=PC9 Mcu.Pin71=PD0 Mcu.Pin72=PD1 @@ -115,7 +117,6 @@ Mcu.Pin76=PD5 Mcu.Pin77=PD6 Mcu.Pin78=PD7 Mcu.Pin79=PF9 -Mcu.Pin8=PC14-OSC32_IN (PC14) Mcu.Pin80=PF10 Mcu.Pin81=PF11 Mcu.Pin82=PF12 @@ -126,7 +127,6 @@ Mcu.Pin86=PB5 Mcu.Pin87=PE0 Mcu.Pin88=PE1 Mcu.Pin89=PE2 -Mcu.Pin9=PC15-OSC32_OUT (PC15) Mcu.Pin90=PE3 Mcu.Pin91=PB6 Mcu.Pin92=PB7 @@ -134,13 +134,15 @@ Mcu.Pin93=PB8 Mcu.Pin94=VP_FREERTOS_VS_CMSIS_V1 Mcu.Pin95=VP_SYS_VS_tim1 Mcu.Pin96=VP_SYS_VS_DBSignals -Mcu.Pin97=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS -Mcu.PinsNb=98 +Mcu.Pin97=VP_TIM2_VS_ClockSourceINT +Mcu.Pin98=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS +Mcu.PinsNb=99 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32G0B1VETx MxCube.Version=6.17.0 MxDb.Version=DB.6.0.170 +NVIC.EXTI0_1_IRQn=true\:3\:0\:false\:false\:true\:true\:true\:true\:true NVIC.ForceEnableDMAVector=true NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false @@ -151,25 +153,14 @@ NVIC.SavedSvcallIrqHandlerGenerated=true NVIC.SavedSystickIrqHandlerGenerated=true NVIC.SysTick_IRQn=true\:3\:0\:false\:false\:false\:true\:false\:true\:false NVIC.TIM1_BRK_UP_TRG_COM_IRQn=true\:3\:0\:false\:false\:true\:false\:false\:true\:true -NVIC.TimeBase=TIM1_BRK_UP_TRG_COM_IRQn NVIC.TimeBaseIP=TIM1 +NVIC.TimeBase=TIM1_BRK_UP_TRG_COM_IRQn PA0.GPIOParameters=GPIO_Label PA0.GPIO_Label=LOG_VSENSE PA0.Locked=true PA0.Mode=IN0 PA0.Signal=ADC1_IN0 PA1.Locked=true -PA10.Locked=true -PA11\ [PA9].Mode=Device -PA11\ [PA9].Signal=USB_DM -PA12\ [PA10].Mode=Device -PA12\ [PA10].Signal=USB_DP -PA13.Locked=true -PA14-BOOT0.Locked=true -PA15.GPIOParameters=GPIO_Label -PA15.GPIO_Label=USB_nFAULT -PA15.Locked=true -PA15.Signal=GPIO_Input PA2.Locked=true PA3.Locked=true PA4.GPIOParameters=GPIO_Label @@ -186,27 +177,29 @@ PA7.Mode=IN7 PA7.Signal=ADC1_IN7 PA8.Locked=true PA9.GPIOParameters=GPIO_Label -PA9.GPIO_Label=FAN1_PWM +PA9.GPIO_Label=FAN1_PWN PA9.Locked=true -PA9.Signal=GPIO_Analog -PB0.GPIOParameters=GPIO_Label +PA9.Signal=GPIO_Output +PA10.Locked=true +PA11\ [PA9].Mode=Device +PA11\ [PA9].Signal=USB_DM +PA12\ [PA10].Mode=Device +PA12\ [PA10].Signal=USB_DP +PA13.Locked=true +PA14-BOOT0.Locked=true +PA15.GPIOParameters=GPIO_Label +PA15.GPIO_Label=USB_nFAULT +PA15.Locked=true +PA15.Signal=GPIO_Input +PB0.GPIOParameters=GPIO_Label,GPIO_ModeDefaultEXTI PB0.GPIO_Label=PWR_DOWN +PB0.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING PB0.Locked=true PB0.Signal=GPXTI0 PB1.GPIOParameters=GPIO_Label PB1.GPIO_Label=P6V_CS_TWO PB1.Mode=IN9 PB1.Signal=ADC1_IN9 -PB10.GPIOParameters=GPIO_Label -PB10.GPIO_Label=P12V_CS -PB10.Locked=true -PB10.Mode=IN11 -PB10.Signal=ADC1_IN11 -PB11.Locked=true -PB12.Locked=true -PB13.Locked=true -PB14.Locked=true -PB15.Locked=true PB2.GPIOParameters=GPIO_Label PB2.GPIO_Label=P6V_CS_ONE PB2.Mode=IN10 @@ -234,23 +227,21 @@ PB8.Locked=true PB8.Mode=Simplex_Bidirectional_Master PB8.Signal=SPI2_SCK PB9.Locked=true +PB10.GPIOParameters=GPIO_Label +PB10.GPIO_Label=P12V_CS +PB10.Locked=true +PB10.Mode=IN11 +PB10.Signal=ADC1_IN11 +PB11.Locked=true +PB12.Locked=true +PB13.Locked=true +PB14.Locked=true +PB15.Locked=true PC0.Locked=true PC1.GPIOParameters=GPIO_Label PC1.GPIO_Label=LNA_EN PC1.Locked=true PC1.Signal=GPIO_Output -PC10.Mode=Full_Duplex_Master -PC10.Signal=SPI3_SCK -PC11.Mode=Full_Duplex_Master -PC11.Signal=SPI3_MISO -PC12.Mode=Full_Duplex_Master -PC12.Signal=SPI3_MOSI -PC13.GPIOParameters=GPIO_Label -PC13.GPIO_Label=TEMP_ALERT_N -PC13.Locked=true -PC13.Signal=GPIO_Input -PC14-OSC32_IN\ (PC14).Locked=true -PC15-OSC32_OUT\ (PC15).Locked=true PC2.GPIOParameters=GPIO_Label PC2.GPIO_Label=LOGAMP_EN PC2.Locked=true @@ -270,8 +261,7 @@ PC6.Locked=true PC6.Signal=GPIO_Output PC7.GPIOParameters=GPIO_Label PC7.GPIO_Label=FAN2_PWM -PC7.Locked=true -PC7.Signal=GPIO_Analog +PC7.Signal=S_TIM2_CH4 PC8.GPIOParameters=GPIO_Label PC8.GPIO_Label=P5V_VSENSE PC8.Locked=true @@ -280,6 +270,18 @@ PC9.GPIOParameters=GPIO_Label PC9.GPIO_Label=P12V_VSENSE PC9.Locked=true PC9.Signal=GPIO_Input +PC10.Mode=Full_Duplex_Master +PC10.Signal=SPI3_SCK +PC11.Mode=Full_Duplex_Master +PC11.Signal=SPI3_MISO +PC12.Mode=Full_Duplex_Master +PC12.Signal=SPI3_MOSI +PC13.GPIOParameters=GPIO_Label +PC13.GPIO_Label=TEMP_ALERT_N +PC13.Locked=true +PC13.Signal=GPIO_Input +PC14-OSC32_IN\ (PC14).Locked=true +PC15-OSC32_OUT\ (PC15).Locked=true PD0.GPIOParameters=GPIO_Label PD0.GPIO_Label=P12V_HSD_DIAG_EN PD0.Locked=true @@ -288,24 +290,6 @@ PD1.GPIOParameters=GPIO_Label PD1.GPIO_Label=MUX_ST PD1.Locked=true PD1.Signal=GPIO_Input -PD10.Locked=true -PD11.Locked=true -PD12.GPIOParameters=GPIO_Label -PD12.GPIO_Label=LPA_EN -PD12.Locked=true -PD12.Signal=GPIO_Output -PD13.GPIOParameters=GPIO_Label -PD13.GPIO_Label=VGA_ATTSEL0 -PD13.Locked=true -PD13.Signal=GPIO_Output -PD14.GPIOParameters=GPIO_Label -PD14.GPIO_Label=VGA_EN -PD14.Locked=true -PD14.Signal=GPIO_Output -PD15.GPIOParameters=GPIO_Label -PD15.GPIO_Label=VGA_ATTSEL1 -PD15.Locked=true -PD15.Signal=GPIO_Output PD2.GPIOParameters=GPIO_Label PD2.GPIO_Label=FAN1_PWR_EN PD2.Locked=true @@ -332,6 +316,24 @@ PD7.Locked=true PD7.Signal=GPIO_Input PD8.Locked=true PD9.Locked=true +PD10.Locked=true +PD11.Locked=true +PD12.GPIOParameters=GPIO_Label +PD12.GPIO_Label=LPA_EN +PD12.Locked=true +PD12.Signal=GPIO_Output +PD13.GPIOParameters=GPIO_Label +PD13.GPIO_Label=VGA_ATTSEL0 +PD13.Locked=true +PD13.Signal=GPIO_Output +PD14.GPIOParameters=GPIO_Label +PD14.GPIO_Label=VGA_EN +PD14.Locked=true +PD14.Signal=GPIO_Output +PD15.GPIOParameters=GPIO_Label +PD15.GPIO_Label=VGA_ATTSEL1 +PD15.Locked=true +PD15.Signal=GPIO_Output PE0.GPIOParameters=GPIO_Label PE0.GPIO_Label=GEN_EN PE0.Locked=true @@ -340,12 +342,6 @@ PE1.GPIOParameters=GPIO_Label PE1.GPIO_Label=LPA_PWR_EN PE1.Locked=true PE1.Signal=GPIO_Output -PE10.Locked=true -PE11.Locked=true -PE12.Locked=true -PE13.Locked=true -PE14.Locked=true -PE15.Locked=true PE2.GPIOParameters=GPIO_Label PE2.GPIO_Label=VCO_CE PE2.Locked=true @@ -376,6 +372,12 @@ PE8.GPIO_Label=DEBUG1 PE8.Locked=true PE8.Signal=GPIO_Output PE9.Locked=true +PE10.Locked=true +PE11.Locked=true +PE12.Locked=true +PE13.Locked=true +PE14.Locked=true +PE15.Locked=true PF0-OSC_IN\ (PF0).GPIOParameters=GPIO_Label PF0-OSC_IN\ (PF0).GPIO_Label=P6V_SCATTER_PWR_EN PF0-OSC_IN\ (PF0).Locked=true @@ -384,6 +386,20 @@ PF1-OSC_OUT\ (PF1).GPIOParameters=GPIO_Label PF1-OSC_OUT\ (PF1).GPIO_Label=P6V_SCATTER_HSD_DIAG_EN PF1-OSC_OUT\ (PF1).Locked=true PF1-OSC_OUT\ (PF1).Signal=GPIO_Output +PF2-NRST.Locked=true +PF3.Locked=true +PF4.Locked=true +PF5.Locked=true +PF6.Locked=true +PF7.Locked=true +PF8.GPIOParameters=GPIO_Label +PF8.GPIO_Label=P6V_PG +PF8.Locked=true +PF8.Signal=GPIO_Input +PF9.GPIOParameters=GPIO_Label +PF9.GPIO_Label=P6V_HSD_ONE_SEL +PF9.Locked=true +PF9.Signal=GPIO_Output PF10.GPIOParameters=GPIO_Label PF10.GPIO_Label=P6V_HSD_ONE_SEH PF10.Locked=true @@ -401,20 +417,6 @@ PF13.GPIO_Label=P6V_HSD_TWO_DIAG_EN PF13.Locked=true PF13.PinState=GPIO_PIN_RESET PF13.Signal=GPIO_Output -PF2-NRST.Locked=true -PF3.Locked=true -PF4.Locked=true -PF5.Locked=true -PF6.Locked=true -PF7.Locked=true -PF8.GPIOParameters=GPIO_Label -PF8.GPIO_Label=P6V_PG -PF8.Locked=true -PF8.Signal=GPIO_Input -PF9.GPIOParameters=GPIO_Label -PF9.GPIO_Label=P6V_HSD_ONE_SEL -PF9.Locked=true -PF9.Signal=GPIO_Output PinOutPanel.RotationAngle=0 ProjectManager.AskForMigrate=true ProjectManager.BackupPrevious=false @@ -427,8 +429,8 @@ ProjectManager.DefaultFWLocation=true ProjectManager.DeletePrevious=true ProjectManager.DeviceId=STM32G0B1VETx ProjectManager.FirmwarePackage=STM32Cube FW_G0 V1.6.3 -ProjectManager.FreePins=false ProjectManager.FreePinsContext= +ProjectManager.FreePins=false ProjectManager.HalAssertFull=false ProjectManager.HeapSize=0x200 ProjectManager.KeepUserCode=true @@ -448,7 +450,7 @@ ProjectManager.ToolChainLocation= ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=true -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USB_Device_Init-USB_DEVICE-false-HAL-false +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USB_Device_Init-USB_DEVICE-false-HAL-false,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_DAC1_Init-DAC1-false-HAL-true,6-MX_SPI2_Init-SPI2-false-HAL-true,7-MX_SPI3_Init-SPI3-false-HAL-true,8-MX_USART1_UART_Init-USART1-false-HAL-true,9-MX_TIM2_Init-TIM2-false-HAL-true RCC.AHBFreq_Value=16000000 RCC.APBFreq_Value=16000000 RCC.APBTimFreq_Value=16000000 @@ -481,8 +483,8 @@ RCC.PLLQoutputFreq_Value=64000000 RCC.PLLRCLKFreq_Value=64000000 RCC.PWRFreq_Value=16000000 RCC.SYSCLKFreq_VALUE=16000000 -RCC.TIM15Freq_Value=16000000 RCC.TIM1Freq_Value=16000000 +RCC.TIM15Freq_Value=16000000 RCC.USART1Freq_Value=16000000 RCC.USART2Freq_Value=16000000 RCC.USART3Freq_Value=16000000 @@ -493,6 +495,8 @@ SH.COMP_DAC12_group.0=DAC1_OUT2,DAC_OUT2 SH.COMP_DAC12_group.ConfNb=1 SH.GPXTI0.0=GPIO_EXTI0 SH.GPXTI0.ConfNb=1 +SH.S_TIM2_CH4.0=TIM2_CH4,PWM Generation4 CH4 +SH.S_TIM2_CH4.ConfNb=1 SPI2.CalculateBaudRate=8.0 MBits/s SPI2.DataSize=SPI_DATASIZE_8BIT SPI2.Direction=SPI_DIRECTION_1LINE @@ -505,19 +509,28 @@ SPI3.Direction=SPI_DIRECTION_2LINES SPI3.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize SPI3.Mode=SPI_MODE_MASTER SPI3.VirtualType=VM_MASTER +TIM2.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE +TIM2.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4 +TIM2.IPParameters=Prescaler,Period,AutoReloadPreload,Channel-PWM Generation4 CH4,OCPolarity_4 +TIM2.OCPolarity_4=TIM_OCPOLARITY_LOW +TIM2.Period=999 +TIM2.Prescaler=16 USART1.IPParameters=VirtualMode-Asynchronous USART1.VirtualMode-Asynchronous=VM_ASYNC USB_DEVICE.CLASS_NAME_FS=CDC USB_DEVICE.IPParameters=VirtualMode,VirtualModeFS,CLASS_NAME_FS -USB_DEVICE.VirtualMode=Cdc USB_DEVICE.VirtualModeFS=Cdc_FS +USB_DEVICE.VirtualMode=Cdc VP_FREERTOS_VS_CMSIS_V1.Mode=CMSIS_V1 VP_FREERTOS_VS_CMSIS_V1.Signal=FREERTOS_VS_CMSIS_V1 VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals VP_SYS_VS_DBSignals.Signal=SYS_VS_DBSignals VP_SYS_VS_tim1.Mode=TIM1 VP_SYS_VS_tim1.Signal=SYS_VS_tim1 +VP_TIM2_VS_ClockSourceINT.Mode=Internal +VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Mode=CDC_FS VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Signal=USB_DEVICE_VS_USB_DEVICE_CDC_FS board=custom rtos.0.ip=FREERTOS +#MicroXplorer Configuration settings - do not modify diff --git a/boards/motherboard/src/adc.c b/boards/motherboard/src/adc.c index 938ccb7..66b6bdd 100644 --- a/boards/motherboard/src/adc.c +++ b/boards/motherboard/src/adc.c @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file adc.c - * @brief This file provides code for the configuration - * of the ADC instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file adc.c + * @brief This file provides code for the configuration + * of the ADC instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "adc.h" @@ -27,128 +27,119 @@ ADC_HandleTypeDef hadc1; /* ADC1 init function */ -void MX_ADC1_Init(void) -{ - - /* USER CODE BEGIN ADC1_Init 0 */ - - /* USER CODE END ADC1_Init 0 */ - - ADC_ChannelConfTypeDef sConfig = {0}; - - /* USER CODE BEGIN ADC1_Init 1 */ - - /* USER CODE END ADC1_Init 1 */ - - /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) - */ - hadc1.Instance = ADC1; - hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2; - hadc1.Init.Resolution = ADC_RESOLUTION_12B; - hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; - hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; - hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; - hadc1.Init.LowPowerAutoWait = DISABLE; - hadc1.Init.LowPowerAutoPowerOff = DISABLE; - hadc1.Init.ContinuousConvMode = DISABLE; - hadc1.Init.NbrOfConversion = 1; - hadc1.Init.DiscontinuousConvMode = DISABLE; - hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; - hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; - hadc1.Init.DMAContinuousRequests = DISABLE; - hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; - hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5; - hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_1CYCLE_5; - hadc1.Init.OversamplingMode = DISABLE; - hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH; - if (HAL_ADC_Init(&hadc1) != HAL_OK) - { - Error_Handler(); - } - - /** Configure Regular Channel - */ - sConfig.Channel = ADC_CHANNEL_0; - sConfig.Rank = ADC_REGULAR_RANK_1; - sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1; - if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN ADC1_Init 2 */ - - /* USER CODE END ADC1_Init 2 */ - +void MX_ADC1_Init(void) { + /* USER CODE BEGIN ADC1_Init 0 */ + + /* USER CODE END ADC1_Init 0 */ + + ADC_ChannelConfTypeDef sConfig = {0}; + + /* USER CODE BEGIN ADC1_Init 1 */ + + /* USER CODE END ADC1_Init 1 */ + + /** Configure the global features of the ADC (Clock, Resolution, Data + * Alignment and number of conversion) + */ + hadc1.Instance = ADC1; + hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2; + hadc1.Init.Resolution = ADC_RESOLUTION_12B; + hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; + hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; + hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; + hadc1.Init.LowPowerAutoWait = DISABLE; + hadc1.Init.LowPowerAutoPowerOff = DISABLE; + hadc1.Init.ContinuousConvMode = DISABLE; + hadc1.Init.NbrOfConversion = 1; + hadc1.Init.DiscontinuousConvMode = DISABLE; + hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; + hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; + hadc1.Init.DMAContinuousRequests = DISABLE; + hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; + hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5; + hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_1CYCLE_5; + hadc1.Init.OversamplingMode = DISABLE; + hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH; + if (HAL_ADC_Init(&hadc1) != HAL_OK) { + Error_Handler(); + } + + /** Configure Regular Channel + */ + sConfig.Channel = ADC_CHANNEL_0; + sConfig.Rank = ADC_REGULAR_RANK_1; + sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1; + if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN ADC1_Init 2 */ + + /* USER CODE END ADC1_Init 2 */ } -void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle) -{ - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(adcHandle->Instance==ADC1) - { - /* USER CODE BEGIN ADC1_MspInit 0 */ - - /* USER CODE END ADC1_MspInit 0 */ - /* ADC1 clock enable */ - __HAL_RCC_ADC_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**ADC1 GPIO Configuration - PA0 ------> ADC1_IN0 - PA4 ------> ADC1_IN4 - PA7 ------> ADC1_IN7 - PB1 ------> ADC1_IN9 - PB2 ------> ADC1_IN10 - PB10 ------> ADC1_IN11 - */ - GPIO_InitStruct.Pin = LOG_VSENSE_Pin|P6V_SCATTER_CS_Pin|LPA_PWR_DET_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = P6V_CS_TWO_Pin|P6V_CS_ONE_Pin|P12V_CS_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* USER CODE BEGIN ADC1_MspInit 1 */ - - /* USER CODE END ADC1_MspInit 1 */ - } +void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (adcHandle->Instance == ADC1) { + /* USER CODE BEGIN ADC1_MspInit 0 */ + + /* USER CODE END ADC1_MspInit 0 */ + /* ADC1 clock enable */ + __HAL_RCC_ADC_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**ADC1 GPIO Configuration + PA0 ------> ADC1_IN0 + PA4 ------> ADC1_IN4 + PA7 ------> ADC1_IN7 + PB1 ------> ADC1_IN9 + PB2 ------> ADC1_IN10 + PB10 ------> ADC1_IN11 + */ + GPIO_InitStruct.Pin = + LOG_VSENSE_Pin | P6V_SCATTER_CS_Pin | LPA_PWR_DET_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = P6V_CS_TWO_Pin | P6V_CS_ONE_Pin | P12V_CS_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* USER CODE BEGIN ADC1_MspInit 1 */ + + /* USER CODE END ADC1_MspInit 1 */ + } } -void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle) -{ - - if(adcHandle->Instance==ADC1) - { - /* USER CODE BEGIN ADC1_MspDeInit 0 */ +void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle) { + if (adcHandle->Instance == ADC1) { + /* USER CODE BEGIN ADC1_MspDeInit 0 */ - /* USER CODE END ADC1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_ADC_CLK_DISABLE(); + /* USER CODE END ADC1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_ADC_CLK_DISABLE(); - /**ADC1 GPIO Configuration - PA0 ------> ADC1_IN0 - PA4 ------> ADC1_IN4 - PA7 ------> ADC1_IN7 - PB1 ------> ADC1_IN9 - PB2 ------> ADC1_IN10 - PB10 ------> ADC1_IN11 - */ - HAL_GPIO_DeInit(GPIOA, LOG_VSENSE_Pin|P6V_SCATTER_CS_Pin|LPA_PWR_DET_Pin); + /**ADC1 GPIO Configuration + PA0 ------> ADC1_IN0 + PA4 ------> ADC1_IN4 + PA7 ------> ADC1_IN7 + PB1 ------> ADC1_IN9 + PB2 ------> ADC1_IN10 + PB10 ------> ADC1_IN11 + */ + HAL_GPIO_DeInit(GPIOA, + LOG_VSENSE_Pin | P6V_SCATTER_CS_Pin | LPA_PWR_DET_Pin); - HAL_GPIO_DeInit(GPIOB, P6V_CS_TWO_Pin|P6V_CS_ONE_Pin|P12V_CS_Pin); + HAL_GPIO_DeInit(GPIOB, P6V_CS_TWO_Pin | P6V_CS_ONE_Pin | P12V_CS_Pin); - /* USER CODE BEGIN ADC1_MspDeInit 1 */ + /* USER CODE BEGIN ADC1_MspDeInit 1 */ - /* USER CODE END ADC1_MspDeInit 1 */ - } + /* USER CODE END ADC1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/boards/motherboard/src/app_freertos.c b/boards/motherboard/src/app_freertos.c deleted file mode 100644 index 1abe2f0..0000000 --- a/boards/motherboard/src/app_freertos.c +++ /dev/null @@ -1,140 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * File Name : app_freertos.c - * Description : Code for freertos applications - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "FreeRTOS.h" -#include "task.h" -#include "main.h" -#include "cmsis_os.h" - -/* Private includes ----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* USER CODE BEGIN PTD */ - -/* USER CODE END PTD */ - -/* Private define ------------------------------------------------------------*/ -/* USER CODE BEGIN PD */ - -/* USER CODE END PD */ - -/* Private macro -------------------------------------------------------------*/ -/* USER CODE BEGIN PM */ - -/* USER CODE END PM */ - -/* Private variables ---------------------------------------------------------*/ -/* USER CODE BEGIN Variables */ - -/* USER CODE END Variables */ -osThreadId defaultTaskHandle; -uint32_t defaultTaskBuffer[ 128 ]; -osStaticThreadDef_t defaultTaskControlBlock; - -/* Private function prototypes -----------------------------------------------*/ -/* USER CODE BEGIN FunctionPrototypes */ - -/* USER CODE END FunctionPrototypes */ - -void StartDefaultTask(void const * argument); - -void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */ - -/* GetIdleTaskMemory prototype (linked to static allocation support) */ -void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ); - -/* USER CODE BEGIN GET_IDLE_TASK_MEMORY */ -static StaticTask_t xIdleTaskTCBBuffer; -static StackType_t xIdleStack[configMINIMAL_STACK_SIZE]; - -void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ) -{ - *ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer; - *ppxIdleTaskStackBuffer = &xIdleStack[0]; - *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; - /* place for user code */ -} -/* USER CODE END GET_IDLE_TASK_MEMORY */ - -/** - * @brief FreeRTOS initialization - * @param None - * @retval None - */ -void MX_FREERTOS_Init(void) { - /* USER CODE BEGIN Init */ - - /* USER CODE END Init */ - - /* USER CODE BEGIN RTOS_MUTEX */ - /* add mutexes, ... */ - /* USER CODE END RTOS_MUTEX */ - - /* USER CODE BEGIN RTOS_SEMAPHORES */ - /* add semaphores, ... */ - /* USER CODE END RTOS_SEMAPHORES */ - - /* USER CODE BEGIN RTOS_TIMERS */ - /* start timers, add new ones, ... */ - /* USER CODE END RTOS_TIMERS */ - - /* USER CODE BEGIN RTOS_QUEUES */ - /* add queues, ... */ - /* USER CODE END RTOS_QUEUES */ - - /* Create the thread(s) */ - /* definition and creation of defaultTask */ - osThreadStaticDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128, defaultTaskBuffer, &defaultTaskControlBlock); - defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL); - - /* USER CODE BEGIN RTOS_THREADS */ - /* add threads, ... */ - /* USER CODE END RTOS_THREADS */ - -} - -/* USER CODE BEGIN Header_StartDefaultTask */ -/** - * @brief Function implementing the defaultTask thread. - * @param argument: Not used - * @retval None - */ -/* USER CODE END Header_StartDefaultTask */ -void StartDefaultTask(void const * argument) -{ - /* init code for USB_Device */ - MX_USB_Device_Init(); - /* USER CODE BEGIN StartDefaultTask */ - /* Infinite loop */ - for(;;) - { - osDelay(1); - } - /* USER CODE END StartDefaultTask */ -} - -/* Private application code --------------------------------------------------*/ -/* USER CODE BEGIN Application */ - -/* USER CODE END Application */ - diff --git a/boards/motherboard/src/dac.c b/boards/motherboard/src/dac.c index a16a6e9..92c7b07 100644 --- a/boards/motherboard/src/dac.c +++ b/boards/motherboard/src/dac.c @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file dac.c - * @brief This file provides code for the configuration - * of the DAC instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file dac.c + * @brief This file provides code for the configuration + * of the DAC instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "dac.h" @@ -27,94 +27,82 @@ DAC_HandleTypeDef hdac1; /* DAC1 init function */ -void MX_DAC1_Init(void) -{ +void MX_DAC1_Init(void) { + /* USER CODE BEGIN DAC1_Init 0 */ - /* USER CODE BEGIN DAC1_Init 0 */ + /* USER CODE END DAC1_Init 0 */ - /* USER CODE END DAC1_Init 0 */ + DAC_ChannelConfTypeDef sConfig = {0}; - DAC_ChannelConfTypeDef sConfig = {0}; + /* USER CODE BEGIN DAC1_Init 1 */ - /* USER CODE BEGIN DAC1_Init 1 */ + /* USER CODE END DAC1_Init 1 */ - /* USER CODE END DAC1_Init 1 */ + /** DAC Initialization + */ + hdac1.Instance = DAC1; + if (HAL_DAC_Init(&hdac1) != HAL_OK) { + Error_Handler(); + } - /** DAC Initialization - */ - hdac1.Instance = DAC1; - if (HAL_DAC_Init(&hdac1) != HAL_OK) - { - Error_Handler(); - } - - /** DAC channel OUT2 config - */ - sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE; - sConfig.DAC_Trigger = DAC_TRIGGER_NONE; - sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; - sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE; - sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY; - if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_2) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN DAC1_Init 2 */ - - /* USER CODE END DAC1_Init 2 */ + /** DAC channel OUT2 config + */ + sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE; + sConfig.DAC_Trigger = DAC_TRIGGER_NONE; + sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; + sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE; + sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY; + if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_2) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN DAC1_Init 2 */ + /* USER CODE END DAC1_Init 2 */ } -void HAL_DAC_MspInit(DAC_HandleTypeDef* dacHandle) -{ - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(dacHandle->Instance==DAC1) - { - /* USER CODE BEGIN DAC1_MspInit 0 */ +void HAL_DAC_MspInit(DAC_HandleTypeDef* dacHandle) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (dacHandle->Instance == DAC1) { + /* USER CODE BEGIN DAC1_MspInit 0 */ - /* USER CODE END DAC1_MspInit 0 */ - /* DAC1 clock enable */ - __HAL_RCC_DAC1_CLK_ENABLE(); + /* USER CODE END DAC1_MspInit 0 */ + /* DAC1 clock enable */ + __HAL_RCC_DAC1_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**DAC1 GPIO Configuration - PA5 ------> DAC1_OUT2 - */ - GPIO_InitStruct.Pin = DAC_ADJ_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(DAC_ADJ_GPIO_Port, &GPIO_InitStruct); + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**DAC1 GPIO Configuration + PA5 ------> DAC1_OUT2 + */ + GPIO_InitStruct.Pin = DAC_ADJ_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(DAC_ADJ_GPIO_Port, &GPIO_InitStruct); - /* USER CODE BEGIN DAC1_MspInit 1 */ + /* USER CODE BEGIN DAC1_MspInit 1 */ - /* USER CODE END DAC1_MspInit 1 */ - } + /* USER CODE END DAC1_MspInit 1 */ + } } -void HAL_DAC_MspDeInit(DAC_HandleTypeDef* dacHandle) -{ +void HAL_DAC_MspDeInit(DAC_HandleTypeDef* dacHandle) { + if (dacHandle->Instance == DAC1) { + /* USER CODE BEGIN DAC1_MspDeInit 0 */ - if(dacHandle->Instance==DAC1) - { - /* USER CODE BEGIN DAC1_MspDeInit 0 */ + /* USER CODE END DAC1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_DAC1_CLK_DISABLE(); - /* USER CODE END DAC1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_DAC1_CLK_DISABLE(); + /**DAC1 GPIO Configuration + PA5 ------> DAC1_OUT2 + */ + HAL_GPIO_DeInit(DAC_ADJ_GPIO_Port, DAC_ADJ_Pin); - /**DAC1 GPIO Configuration - PA5 ------> DAC1_OUT2 - */ - HAL_GPIO_DeInit(DAC_ADJ_GPIO_Port, DAC_ADJ_Pin); + /* USER CODE BEGIN DAC1_MspDeInit 1 */ - /* USER CODE BEGIN DAC1_MspDeInit 1 */ - - /* USER CODE END DAC1_MspDeInit 1 */ - } + /* USER CODE END DAC1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/boards/motherboard/src/gpio.c b/boards/motherboard/src/gpio.c index a864f9f..8ce1610 100644 --- a/boards/motherboard/src/gpio.c +++ b/boards/motherboard/src/gpio.c @@ -33,134 +33,153 @@ /* USER CODE END 1 */ /** Configure pins -*/ -void MX_GPIO_Init(void) -{ - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOE_CLK_ENABLE(); - __HAL_RCC_GPIOF_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - __HAL_RCC_GPIOD_CLK_ENABLE(); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOE, VGA_CS_N_Pin|TEMP_CS_N_Pin|DEBUG2_Pin|DEBUG1_Pin - |GEN_EN_Pin|LPA_PWR_EN_Pin|VCO_CE_Pin|VCO_LE_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOF, P6V_SCATTER_PWR_EN_Pin|P6V_SCATTER_HSD_DIAG_EN_Pin|P6V_HSD_ONE_SEL_Pin|P6V_HSD_ONE_SEH_Pin - |VGA_PWR_EN_Pin|VCO_PWR_EN_Pin|P6V_HSD_TWO_DIAG_EN_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOC, LNA_EN_Pin|LOGAMP_EN_Pin|WARN_LIGHT_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOD, LPA_EN_Pin|VGA_ATTSEL0_Pin|VGA_EN_Pin|VGA_ATTSEL1_Pin - |P12V_HSD_DIAG_EN_Pin|FAN1_PWR_EN_Pin|FAN2_PWR_EN_Pin|P6V_HDS_ONE_DIAG_EN_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOB, P6V_HSD_TWO_SEL_Pin|P6V_HSD_TWO_SEH_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pins : VGA_CS_N_Pin TEMP_CS_N_Pin */ - GPIO_InitStruct.Pin = VGA_CS_N_Pin|TEMP_CS_N_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); - - /*Configure GPIO pins : TEMP_ALERT_N_Pin P5V_VSENSE_Pin P12V_VSENSE_Pin */ - GPIO_InitStruct.Pin = TEMP_ALERT_N_Pin|P5V_VSENSE_Pin|P12V_VSENSE_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /*Configure GPIO pins : P6V_SCATTER_PWR_EN_Pin P6V_SCATTER_HSD_DIAG_EN_Pin P6V_HSD_ONE_SEL_Pin P6V_HSD_ONE_SEH_Pin - VGA_PWR_EN_Pin VCO_PWR_EN_Pin P6V_HSD_TWO_DIAG_EN_Pin */ - GPIO_InitStruct.Pin = P6V_SCATTER_PWR_EN_Pin|P6V_SCATTER_HSD_DIAG_EN_Pin|P6V_HSD_ONE_SEL_Pin|P6V_HSD_ONE_SEH_Pin - |VGA_PWR_EN_Pin|VCO_PWR_EN_Pin|P6V_HSD_TWO_DIAG_EN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); - - /*Configure GPIO pins : LNA_EN_Pin LOGAMP_EN_Pin WARN_LIGHT_Pin */ - GPIO_InitStruct.Pin = LNA_EN_Pin|LOGAMP_EN_Pin|WARN_LIGHT_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /*Configure GPIO pin : PWR_DOWN_Pin */ - GPIO_InitStruct.Pin = PWR_DOWN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(PWR_DOWN_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : DEBUG2_Pin DEBUG1_Pin GEN_EN_Pin LPA_PWR_EN_Pin - VCO_CE_Pin VCO_LE_Pin */ - GPIO_InitStruct.Pin = DEBUG2_Pin|DEBUG1_Pin|GEN_EN_Pin|LPA_PWR_EN_Pin - |VCO_CE_Pin|VCO_LE_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); - - /*Configure GPIO pin : FAN1_PWM_Pin */ - GPIO_InitStruct.Pin = FAN1_PWM_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(FAN1_PWM_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pin : FAN2_PWM_Pin */ - GPIO_InitStruct.Pin = FAN2_PWM_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(FAN2_PWM_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : LPA_EN_Pin VGA_ATTSEL0_Pin VGA_EN_Pin VGA_ATTSEL1_Pin - P12V_HSD_DIAG_EN_Pin FAN1_PWR_EN_Pin FAN2_PWR_EN_Pin P6V_HDS_ONE_DIAG_EN_Pin */ - GPIO_InitStruct.Pin = LPA_EN_Pin|VGA_ATTSEL0_Pin|VGA_EN_Pin|VGA_ATTSEL1_Pin - |P12V_HSD_DIAG_EN_Pin|FAN1_PWR_EN_Pin|FAN2_PWR_EN_Pin|P6V_HDS_ONE_DIAG_EN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /*Configure GPIO pin : P6V_PG_Pin */ - GPIO_InitStruct.Pin = P6V_PG_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(P6V_PG_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pin : USB_nFAULT_Pin */ - GPIO_InitStruct.Pin = USB_nFAULT_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(USB_nFAULT_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : MUX_ST_Pin nFAULT_FAN1_Pin nFAULT_FAN2_Pin P6V_HSD_ONE_nFAULT_Pin */ - GPIO_InitStruct.Pin = MUX_ST_Pin|nFAULT_FAN1_Pin|nFAULT_FAN2_Pin|P6V_HSD_ONE_nFAULT_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /*Configure GPIO pins : P6V_HSD_TWO_nFAULT_Pin VCO_MUXOUT_Pin */ - GPIO_InitStruct.Pin = P6V_HSD_TWO_nFAULT_Pin|VCO_MUXOUT_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /*Configure GPIO pins : P6V_HSD_TWO_SEL_Pin P6V_HSD_TWO_SEH_Pin */ - GPIO_InitStruct.Pin = P6V_HSD_TWO_SEL_Pin|P6V_HSD_TWO_SEH_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - + */ +void MX_GPIO_Init(void) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOE_CLK_ENABLE(); + __HAL_RCC_GPIOF_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOD_CLK_ENABLE(); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOE, + VGA_CS_N_Pin | TEMP_CS_N_Pin | DEBUG2_Pin | DEBUG1_Pin | + GEN_EN_Pin | LPA_PWR_EN_Pin | VCO_CE_Pin | VCO_LE_Pin, + GPIO_PIN_RESET); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOF, + P6V_SCATTER_PWR_EN_Pin | P6V_SCATTER_HSD_DIAG_EN_Pin | + P6V_HSD_ONE_SEL_Pin | P6V_HSD_ONE_SEH_Pin | + VGA_PWR_EN_Pin | VCO_PWR_EN_Pin | + P6V_HSD_TWO_DIAG_EN_Pin, + GPIO_PIN_RESET); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOC, LNA_EN_Pin | LOGAMP_EN_Pin | WARN_LIGHT_Pin, + GPIO_PIN_RESET); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(FAN1_PWN_GPIO_Port, FAN1_PWN_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOD, + LPA_EN_Pin | VGA_ATTSEL0_Pin | VGA_EN_Pin | + VGA_ATTSEL1_Pin | P12V_HSD_DIAG_EN_Pin | + FAN1_PWR_EN_Pin | FAN2_PWR_EN_Pin | + P6V_HDS_ONE_DIAG_EN_Pin, + GPIO_PIN_RESET); + + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOB, P6V_HSD_TWO_SEL_Pin | P6V_HSD_TWO_SEH_Pin, + GPIO_PIN_RESET); + + /*Configure GPIO pins : VGA_CS_N_Pin TEMP_CS_N_Pin */ + GPIO_InitStruct.Pin = VGA_CS_N_Pin | TEMP_CS_N_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); + + /*Configure GPIO pins : TEMP_ALERT_N_Pin P5V_VSENSE_Pin P12V_VSENSE_Pin */ + GPIO_InitStruct.Pin = TEMP_ALERT_N_Pin | P5V_VSENSE_Pin | P12V_VSENSE_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /*Configure GPIO pins : P6V_SCATTER_PWR_EN_Pin P6V_SCATTER_HSD_DIAG_EN_Pin + P6V_HSD_ONE_SEL_Pin P6V_HSD_ONE_SEH_Pin VGA_PWR_EN_Pin VCO_PWR_EN_Pin + P6V_HSD_TWO_DIAG_EN_Pin */ + GPIO_InitStruct.Pin = P6V_SCATTER_PWR_EN_Pin | P6V_SCATTER_HSD_DIAG_EN_Pin | + P6V_HSD_ONE_SEL_Pin | P6V_HSD_ONE_SEH_Pin | + VGA_PWR_EN_Pin | VCO_PWR_EN_Pin | + P6V_HSD_TWO_DIAG_EN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); + + /*Configure GPIO pins : LNA_EN_Pin LOGAMP_EN_Pin WARN_LIGHT_Pin */ + GPIO_InitStruct.Pin = LNA_EN_Pin | LOGAMP_EN_Pin | WARN_LIGHT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /*Configure GPIO pin : PWR_DOWN_Pin */ + GPIO_InitStruct.Pin = PWR_DOWN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(PWR_DOWN_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pins : DEBUG2_Pin DEBUG1_Pin GEN_EN_Pin LPA_PWR_EN_Pin + VCO_CE_Pin VCO_LE_Pin */ + GPIO_InitStruct.Pin = DEBUG2_Pin | DEBUG1_Pin | GEN_EN_Pin | + LPA_PWR_EN_Pin | VCO_CE_Pin | VCO_LE_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); + + /*Configure GPIO pin : FAN1_PWN_Pin */ + GPIO_InitStruct.Pin = FAN1_PWN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(FAN1_PWN_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pins : LPA_EN_Pin VGA_ATTSEL0_Pin VGA_EN_Pin + VGA_ATTSEL1_Pin P12V_HSD_DIAG_EN_Pin FAN1_PWR_EN_Pin FAN2_PWR_EN_Pin + P6V_HDS_ONE_DIAG_EN_Pin */ + GPIO_InitStruct.Pin = LPA_EN_Pin | VGA_ATTSEL0_Pin | VGA_EN_Pin | + VGA_ATTSEL1_Pin | P12V_HSD_DIAG_EN_Pin | + FAN1_PWR_EN_Pin | FAN2_PWR_EN_Pin | + P6V_HDS_ONE_DIAG_EN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /*Configure GPIO pin : P6V_PG_Pin */ + GPIO_InitStruct.Pin = P6V_PG_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(P6V_PG_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pin : USB_nFAULT_Pin */ + GPIO_InitStruct.Pin = USB_nFAULT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(USB_nFAULT_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pins : MUX_ST_Pin nFAULT_FAN1_Pin nFAULT_FAN2_Pin + * P6V_HSD_ONE_nFAULT_Pin */ + GPIO_InitStruct.Pin = + MUX_ST_Pin | nFAULT_FAN1_Pin | nFAULT_FAN2_Pin | P6V_HSD_ONE_nFAULT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /*Configure GPIO pins : P6V_HSD_TWO_nFAULT_Pin VCO_MUXOUT_Pin */ + GPIO_InitStruct.Pin = P6V_HSD_TWO_nFAULT_Pin | VCO_MUXOUT_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /*Configure GPIO pins : P6V_HSD_TWO_SEL_Pin P6V_HSD_TWO_SEH_Pin */ + GPIO_InitStruct.Pin = P6V_HSD_TWO_SEL_Pin | P6V_HSD_TWO_SEH_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* EXTI interrupt init*/ + HAL_NVIC_SetPriority(EXTI0_1_IRQn, 3, 0); + HAL_NVIC_EnableIRQ(EXTI0_1_IRQn); } /* USER CODE BEGIN 2 */ diff --git a/boards/motherboard/src/main.c b/boards/motherboard/src/main.c index 9935d84..9924a8c 100644 --- a/boards/motherboard/src/main.c +++ b/boards/motherboard/src/main.c @@ -18,13 +18,15 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" -#include "cmsis_os.h" + #include "adc.h" +#include "cmsis_os.h" #include "dac.h" +#include "gpio.h" #include "spi.h" +#include "tim.h" #include "usart.h" #include "usb_device.h" -#include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ @@ -49,7 +51,7 @@ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ - +int pwr_down_flag = 0; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -61,167 +63,159 @@ void MX_FREERTOS_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ - /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ -int main(void) -{ - - /* USER CODE BEGIN 1 */ + * @brief The application entry point. + * @retval int + */ +int main(void) { + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU + * Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the + * Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_ADC1_Init(); - MX_DAC1_Init(); - MX_SPI2_Init(); - MX_SPI3_Init(); - MX_USART1_UART_Init(); - /* USER CODE BEGIN 2 */ - // HAL_GPIO_WritePin(VCO_PWR_EN_GPIO_Port, VCO_PWR_EN_Pin, GPIO_PIN_RESET); - // HAL_GPIO_WritePin(VGA_PWR_EN_GPIO_Port, VGA_PWR_EN_Pin, GPIO_PIN_RESET); - // HAL_GPIO_WritePin(LPA_PWR_EN_GPIO_Port, LPA_PWR_EN_Pin, GPIO_PIN_RESET); - // HAL_GPIO_WritePin(GEN_EN_GPIO_Port, GEN_EN_Pin, GPIO_PIN_RESET); - // HAL_GPIO_WritePin(P6V_SCATTER_PWR_EN_GPIO_Port, P6V_SCATTER_PWR_EN_Pin, - // GPIO_PIN_SET); - // HAL_GPIO_WritePin(P6V_SCATTER_HSD_DIAG_EN_GPIO_Port, - // P6V_SCATTER_HSD_DIAG_EN_Pin, GPIO_PIN_RESET); - /* USER CODE END 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_ADC1_Init(); + MX_DAC1_Init(); + MX_SPI2_Init(); + MX_SPI3_Init(); + MX_USART1_UART_Init(); + MX_TIM2_Init(); + /* USER CODE BEGIN 2 */ + /* USER CODE END 2 */ - /* Call init function for freertos objects (in cmsis_os2.c) */ - MX_FREERTOS_Init(); + /* Call init function for freertos objects (in cmsis_os2.c) */ + MX_FREERTOS_Init(); - /* Start scheduler */ - osKernelStart(); + /* Start scheduler */ + osKernelStart(); - /* We should never get here as control is now taken by the scheduler */ + /* We should never get here as control is now taken by the scheduler */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ while (1) { - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ -void SystemClock_Config(void) -{ - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - - /** Configure the main internal regulator output voltage - */ - HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); - - /** Initializes the RCC Oscillators according to the specified parameters - * in the RCC_OscInitTypeDef structure. - */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI48; - RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; - RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; - RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) - { - Error_Handler(); - } - - /** Initializes the CPU, AHB and APB buses clocks - */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK - |RCC_CLOCKTYPE_PCLK1; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; - - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) - { - Error_Handler(); - } + * @brief System Clock Configuration + * @retval None + */ +void SystemClock_Config(void) { + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + + /** Configure the main internal regulator output voltage + */ + HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); + + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = + RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSI48; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; + RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; + RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { + Error_Handler(); + } + + /** Initializes the CPU, AHB and APB buses clocks + */ + RCC_ClkInitStruct.ClockType = + RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ - +void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin) { + if (GPIO_Pin == PWR_DOWN_Pin) { + pwr_down_flag = 1; + // your power down handling code here + // e.g. shut off fans, save state, set a flag etc. + } +} /* USER CODE END 4 */ /** - * @brief Period elapsed callback in non blocking mode - * @note This function is called when TIM1 interrupt took place, inside - * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment - * a global variable "uwTick" used as application time base. - * @param htim : TIM handle - * @retval None - */ -void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) -{ - /* USER CODE BEGIN Callback 0 */ - - /* USER CODE END Callback 0 */ - if (htim->Instance == TIM1) - { - HAL_IncTick(); - } - /* USER CODE BEGIN Callback 1 */ - - /* USER CODE END Callback 1 */ + * @brief Period elapsed callback in non blocking mode + * @note This function is called when TIM1 interrupt took place, inside + * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment + * a global variable "uwTick" used as application time base. + * @param htim : TIM handle + * @retval None + */ +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim) { + /* USER CODE BEGIN Callback 0 */ + + /* USER CODE END Callback 0 */ + if (htim->Instance == TIM1) { + HAL_IncTick(); + } + /* USER CODE BEGIN Callback 1 */ + + /* USER CODE END Callback 1 */ } /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ -void Error_Handler(void) -{ - /* USER CODE BEGIN Error_Handler_Debug */ + * @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 */ + /* 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 */ + * @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 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/boards/motherboard/src/spi.c b/boards/motherboard/src/spi.c index b0e9798..8e25fe5 100644 --- a/boards/motherboard/src/spi.c +++ b/boards/motherboard/src/spi.c @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file spi.c - * @brief This file provides code for the configuration - * of the SPI instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file spi.c + * @brief This file provides code for the configuration + * of the SPI instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "spi.h" @@ -28,172 +28,153 @@ SPI_HandleTypeDef hspi2; SPI_HandleTypeDef hspi3; /* SPI2 init function */ -void MX_SPI2_Init(void) -{ - - /* USER CODE BEGIN SPI2_Init 0 */ - - /* USER CODE END SPI2_Init 0 */ - - /* USER CODE BEGIN SPI2_Init 1 */ - - /* USER CODE END SPI2_Init 1 */ - hspi2.Instance = SPI2; - hspi2.Init.Mode = SPI_MODE_MASTER; - hspi2.Init.Direction = SPI_DIRECTION_1LINE; - hspi2.Init.DataSize = SPI_DATASIZE_8BIT; - hspi2.Init.CLKPolarity = SPI_POLARITY_LOW; - hspi2.Init.CLKPhase = SPI_PHASE_1EDGE; - hspi2.Init.NSS = SPI_NSS_SOFT; - hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; - hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB; - hspi2.Init.TIMode = SPI_TIMODE_DISABLE; - hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; - hspi2.Init.CRCPolynomial = 7; - hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; - hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE; - if (HAL_SPI_Init(&hspi2) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN SPI2_Init 2 */ - - /* USER CODE END SPI2_Init 2 */ - +void MX_SPI2_Init(void) { + /* USER CODE BEGIN SPI2_Init 0 */ + + /* USER CODE END SPI2_Init 0 */ + + /* USER CODE BEGIN SPI2_Init 1 */ + + /* USER CODE END SPI2_Init 1 */ + hspi2.Instance = SPI2; + hspi2.Init.Mode = SPI_MODE_MASTER; + hspi2.Init.Direction = SPI_DIRECTION_1LINE; + hspi2.Init.DataSize = SPI_DATASIZE_8BIT; + hspi2.Init.CLKPolarity = SPI_POLARITY_LOW; + hspi2.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi2.Init.NSS = SPI_NSS_SOFT; + hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; + hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB; + hspi2.Init.TIMode = SPI_TIMODE_DISABLE; + hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + hspi2.Init.CRCPolynomial = 7; + hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; + hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE; + if (HAL_SPI_Init(&hspi2) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN SPI2_Init 2 */ + + /* USER CODE END SPI2_Init 2 */ } /* SPI3 init function */ -void MX_SPI3_Init(void) -{ - - /* USER CODE BEGIN SPI3_Init 0 */ - - /* USER CODE END SPI3_Init 0 */ - - /* USER CODE BEGIN SPI3_Init 1 */ - - /* USER CODE END SPI3_Init 1 */ - hspi3.Instance = SPI3; - hspi3.Init.Mode = SPI_MODE_MASTER; - hspi3.Init.Direction = SPI_DIRECTION_2LINES; - hspi3.Init.DataSize = SPI_DATASIZE_8BIT; - hspi3.Init.CLKPolarity = SPI_POLARITY_LOW; - hspi3.Init.CLKPhase = SPI_PHASE_1EDGE; - hspi3.Init.NSS = SPI_NSS_SOFT; - hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; - hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB; - hspi3.Init.TIMode = SPI_TIMODE_DISABLE; - hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; - hspi3.Init.CRCPolynomial = 7; - hspi3.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; - hspi3.Init.NSSPMode = SPI_NSS_PULSE_ENABLE; - if (HAL_SPI_Init(&hspi3) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN SPI3_Init 2 */ - - /* USER CODE END SPI3_Init 2 */ - +void MX_SPI3_Init(void) { + /* USER CODE BEGIN SPI3_Init 0 */ + + /* USER CODE END SPI3_Init 0 */ + + /* USER CODE BEGIN SPI3_Init 1 */ + + /* USER CODE END SPI3_Init 1 */ + hspi3.Instance = SPI3; + hspi3.Init.Mode = SPI_MODE_MASTER; + hspi3.Init.Direction = SPI_DIRECTION_2LINES; + hspi3.Init.DataSize = SPI_DATASIZE_8BIT; + hspi3.Init.CLKPolarity = SPI_POLARITY_LOW; + hspi3.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi3.Init.NSS = SPI_NSS_SOFT; + hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; + hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB; + hspi3.Init.TIMode = SPI_TIMODE_DISABLE; + hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + hspi3.Init.CRCPolynomial = 7; + hspi3.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; + hspi3.Init.NSSPMode = SPI_NSS_PULSE_ENABLE; + if (HAL_SPI_Init(&hspi3) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN SPI3_Init 2 */ + + /* USER CODE END SPI3_Init 2 */ } -void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) -{ - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if(spiHandle->Instance==SPI2) - { - /* USER CODE BEGIN SPI2_MspInit 0 */ - - /* USER CODE END SPI2_MspInit 0 */ - /* SPI2 clock enable */ - __HAL_RCC_SPI2_CLK_ENABLE(); - - __HAL_RCC_GPIOB_CLK_ENABLE(); - /**SPI2 GPIO Configuration - PB7 ------> SPI2_MOSI - PB8 ------> SPI2_SCK - */ - GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF1_SPI2; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /* USER CODE BEGIN SPI2_MspInit 1 */ - - /* USER CODE END SPI2_MspInit 1 */ - } - else if(spiHandle->Instance==SPI3) - { - /* USER CODE BEGIN SPI3_MspInit 0 */ - - /* USER CODE END SPI3_MspInit 0 */ - /* SPI3 clock enable */ - __HAL_RCC_SPI3_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**SPI3 GPIO Configuration - PC10 ------> SPI3_SCK - PC11 ------> SPI3_MISO - PC12 ------> SPI3_MOSI - */ - GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF4_SPI3; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN SPI3_MspInit 1 */ - - /* USER CODE END SPI3_MspInit 1 */ - } +void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (spiHandle->Instance == SPI2) { + /* USER CODE BEGIN SPI2_MspInit 0 */ + + /* USER CODE END SPI2_MspInit 0 */ + /* SPI2 clock enable */ + __HAL_RCC_SPI2_CLK_ENABLE(); + + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**SPI2 GPIO Configuration + PB7 ------> SPI2_MOSI + PB8 ------> SPI2_SCK + */ + GPIO_InitStruct.Pin = GPIO_PIN_7 | GPIO_PIN_8; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF1_SPI2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* USER CODE BEGIN SPI2_MspInit 1 */ + + /* USER CODE END SPI2_MspInit 1 */ + } else if (spiHandle->Instance == SPI3) { + /* USER CODE BEGIN SPI3_MspInit 0 */ + + /* USER CODE END SPI3_MspInit 0 */ + /* SPI3 clock enable */ + __HAL_RCC_SPI3_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**SPI3 GPIO Configuration + PC10 ------> SPI3_SCK + PC11 ------> SPI3_MISO + PC12 ------> SPI3_MOSI + */ + GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF4_SPI3; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /* USER CODE BEGIN SPI3_MspInit 1 */ + + /* USER CODE END SPI3_MspInit 1 */ + } } -void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) -{ +void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) { + if (spiHandle->Instance == SPI2) { + /* USER CODE BEGIN SPI2_MspDeInit 0 */ - if(spiHandle->Instance==SPI2) - { - /* USER CODE BEGIN SPI2_MspDeInit 0 */ + /* USER CODE END SPI2_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_SPI2_CLK_DISABLE(); - /* USER CODE END SPI2_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_SPI2_CLK_DISABLE(); + /**SPI2 GPIO Configuration + PB7 ------> SPI2_MOSI + PB8 ------> SPI2_SCK + */ + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7 | GPIO_PIN_8); - /**SPI2 GPIO Configuration - PB7 ------> SPI2_MOSI - PB8 ------> SPI2_SCK - */ - HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7|GPIO_PIN_8); + /* USER CODE BEGIN SPI2_MspDeInit 1 */ - /* USER CODE BEGIN SPI2_MspDeInit 1 */ + /* USER CODE END SPI2_MspDeInit 1 */ + } else if (spiHandle->Instance == SPI3) { + /* USER CODE BEGIN SPI3_MspDeInit 0 */ - /* USER CODE END SPI2_MspDeInit 1 */ - } - else if(spiHandle->Instance==SPI3) - { - /* USER CODE BEGIN SPI3_MspDeInit 0 */ + /* USER CODE END SPI3_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_SPI3_CLK_DISABLE(); - /* USER CODE END SPI3_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_SPI3_CLK_DISABLE(); + /**SPI3 GPIO Configuration + PC10 ------> SPI3_SCK + PC11 ------> SPI3_MISO + PC12 ------> SPI3_MOSI + */ + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12); - /**SPI3 GPIO Configuration - PC10 ------> SPI3_SCK - PC11 ------> SPI3_MISO - PC12 ------> SPI3_MOSI - */ - HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12); + /* USER CODE BEGIN SPI3_MspDeInit 1 */ - /* USER CODE BEGIN SPI3_MspDeInit 1 */ - - /* USER CODE END SPI3_MspDeInit 1 */ - } + /* USER CODE END SPI3_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/boards/motherboard/src/stm32g0xx_hal_msp.c b/boards/motherboard/src/stm32g0xx_hal_msp.c index a720f89..8718647 100644 --- a/boards/motherboard/src/stm32g0xx_hal_msp.c +++ b/boards/motherboard/src/stm32g0xx_hal_msp.c @@ -57,29 +57,28 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ -void HAL_MspInit(void) -{ - - /* USER CODE BEGIN MspInit 0 */ + * Initializes the Global MSP. + */ +void HAL_MspInit(void) { + /* 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*/ - /* PendSV_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(PendSV_IRQn, 3, 0); + /* System interrupt init*/ + /* PendSV_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(PendSV_IRQn, 3, 0); - /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral - */ - HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD1_STROBE | SYSCFG_CFGR1_UCPD2_STROBE); + /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral + */ + HAL_SYSCFG_StrobeDBattpinsConfig(SYSCFG_CFGR1_UCPD1_STROBE | + SYSCFG_CFGR1_UCPD2_STROBE); - /* 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/boards/motherboard/src/stm32g0xx_hal_timebase_tim.c b/boards/motherboard/src/stm32g0xx_hal_timebase_tim.c index 603c8f5..10b4a05 100644 --- a/boards/motherboard/src/stm32g0xx_hal_timebase_tim.c +++ b/boards/motherboard/src/stm32g0xx_hal_timebase_tim.c @@ -25,113 +25,102 @@ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ -TIM_HandleTypeDef htim1; +TIM_HandleTypeDef htim1; /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /** - * @brief This function configures the TIM1 as a time base source. - * The time source is configured to have 1ms time base with a dedicated - * Tick interrupt priority. - * @note This function is called automatically at the beginning of program after - * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). - * @param TickPriority: Tick interrupt priority. - * @retval HAL status - */ -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) -{ - RCC_ClkInitTypeDef clkconfig; - uint32_t uwTimclock, uwAPB1Prescaler; - uint32_t uwPrescalerValue; - uint32_t pFLatency; - - HAL_StatusTypeDef status = HAL_OK; - - /* Enable TIM1 clock */ - __HAL_RCC_TIM1_CLK_ENABLE(); - - /* Get clock configuration */ - HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); - - /* Get APB1 prescaler */ - uwAPB1Prescaler = clkconfig.APB1CLKDivider; - /* Compute TIM1 clock */ - if (uwAPB1Prescaler == RCC_HCLK_DIV1) - { - uwTimclock = HAL_RCC_GetPCLK1Freq(); - } - else - { - uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq(); - } - - /* Compute the prescaler value to have TIM1 counter clock equal to 1MHz */ - uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U); - - /* Initialize TIM1 */ - htim1.Instance = TIM1; - - /* Initialize TIMx peripheral as follow: - * Period = [(TIM1CLK/1000) - 1]. to have a (1/1000) s time base. - * Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. - * ClockDivision = 0 - * Counter direction = Up - */ - htim1.Init.Period = (1000000U / 1000U) - 1U; - htim1.Init.Prescaler = uwPrescalerValue; - htim1.Init.ClockDivision = 0; - htim1.Init.CounterMode = TIM_COUNTERMODE_UP; - htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - - status = HAL_TIM_Base_Init(&htim1); - if (status == HAL_OK) - { + * @brief This function configures the TIM1 as a time base source. + * The time source is configured to have 1ms time base with a dedicated + * Tick interrupt priority. + * @note This function is called automatically at the beginning of program + * after reset by HAL_Init() or at any time when clock is configured, by + * HAL_RCC_ClockConfig(). + * @param TickPriority: Tick interrupt priority. + * @retval HAL status + */ +HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { + RCC_ClkInitTypeDef clkconfig; + uint32_t uwTimclock, uwAPB1Prescaler; + uint32_t uwPrescalerValue; + uint32_t pFLatency; + + HAL_StatusTypeDef status = HAL_OK; + + /* Enable TIM1 clock */ + __HAL_RCC_TIM1_CLK_ENABLE(); + + /* Get clock configuration */ + HAL_RCC_GetClockConfig(&clkconfig, &pFLatency); + + /* Get APB1 prescaler */ + uwAPB1Prescaler = clkconfig.APB1CLKDivider; + /* Compute TIM1 clock */ + if (uwAPB1Prescaler == RCC_HCLK_DIV1) { + uwTimclock = HAL_RCC_GetPCLK1Freq(); + } else { + uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq(); + } - /* Start the TIM time Base generation in interrupt mode */ - status = HAL_TIM_Base_Start_IT(&htim1); - if (status == HAL_OK) - { - /* Enable the TIM1 global Interrupt */ - HAL_NVIC_EnableIRQ(TIM1_BRK_UP_TRG_COM_IRQn); - /* Configure the SysTick IRQ priority */ - if (TickPriority < (1UL << __NVIC_PRIO_BITS)) - { - /* Configure the TIM IRQ priority */ - HAL_NVIC_SetPriority(TIM1_BRK_UP_TRG_COM_IRQn, TickPriority, 0U); - uwTickPrio = TickPriority; - } - else - { - status = HAL_ERROR; - } + /* Compute the prescaler value to have TIM1 counter clock equal to 1MHz */ + uwPrescalerValue = (uint32_t)((uwTimclock / 1000000U) - 1U); + + /* Initialize TIM1 */ + htim1.Instance = TIM1; + + /* Initialize TIMx peripheral as follow: + * Period = [(TIM1CLK/1000) - 1]. to have a (1/1000) s time base. + * Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock. + * ClockDivision = 0 + * Counter direction = Up + */ + htim1.Init.Period = (1000000U / 1000U) - 1U; + htim1.Init.Prescaler = uwPrescalerValue; + htim1.Init.ClockDivision = 0; + htim1.Init.CounterMode = TIM_COUNTERMODE_UP; + htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + + status = HAL_TIM_Base_Init(&htim1); + if (status == HAL_OK) { + /* Start the TIM time Base generation in interrupt mode */ + status = HAL_TIM_Base_Start_IT(&htim1); + if (status == HAL_OK) { + /* Enable the TIM1 global Interrupt */ + HAL_NVIC_EnableIRQ(TIM1_BRK_UP_TRG_COM_IRQn); + /* Configure the SysTick IRQ priority */ + if (TickPriority < (1UL << __NVIC_PRIO_BITS)) { + /* Configure the TIM IRQ priority */ + HAL_NVIC_SetPriority(TIM1_BRK_UP_TRG_COM_IRQn, TickPriority, + 0U); + uwTickPrio = TickPriority; + } else { + status = HAL_ERROR; + } + } } - } - /* Return function status */ - return status; + /* Return function status */ + return status; } /** - * @brief Suspend Tick increment. - * @note Disable the tick increment by disabling TIM1 update interrupt. - * @param None - * @retval None - */ -void HAL_SuspendTick(void) -{ - /* Disable TIM1 update Interrupt */ - __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_UPDATE); + * @brief Suspend Tick increment. + * @note Disable the tick increment by disabling TIM1 update interrupt. + * @param None + * @retval None + */ +void HAL_SuspendTick(void) { + /* Disable TIM1 update Interrupt */ + __HAL_TIM_DISABLE_IT(&htim1, TIM_IT_UPDATE); } /** - * @brief Resume Tick increment. - * @note Enable the tick increment by Enabling TIM1 update interrupt. - * @param None - * @retval None - */ -void HAL_ResumeTick(void) -{ - /* Enable TIM1 Update interrupt */ - __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE); + * @brief Resume Tick increment. + * @note Enable the tick increment by Enabling TIM1 update interrupt. + * @param None + * @retval None + */ +void HAL_ResumeTick(void) { + /* Enable TIM1 Update interrupt */ + __HAL_TIM_ENABLE_IT(&htim1, TIM_IT_UPDATE); } - diff --git a/boards/motherboard/src/stm32g0xx_it.c b/boards/motherboard/src/stm32g0xx_it.c index 92d50bc..3b4def9 100644 --- a/boards/motherboard/src/stm32g0xx_it.c +++ b/boards/motherboard/src/stm32g0xx_it.c @@ -18,8 +18,9 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "main.h" #include "stm32g0xx_it.h" + +#include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ @@ -62,35 +63,32 @@ extern TIM_HandleTypeDef htim1; /* USER CODE END EV */ /******************************************************************************/ -/* Cortex-M0+ Processor Interruption and Exception Handlers */ +/* Cortex-M0+ 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 */ + * @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 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 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 */ + } } /******************************************************************************/ @@ -101,17 +99,30 @@ void HardFault_Handler(void) /******************************************************************************/ /** - * @brief This function handles TIM1 break, update, trigger and commutation interrupts. - */ -void TIM1_BRK_UP_TRG_COM_IRQHandler(void) -{ - /* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 0 */ + * @brief This function handles EXTI line 0 and line 1 interrupts. + */ +void EXTI0_1_IRQHandler(void) { + /* USER CODE BEGIN EXTI0_1_IRQn 0 */ + + /* USER CODE END EXTI0_1_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(PWR_DOWN_Pin); + /* USER CODE BEGIN EXTI0_1_IRQn 1 */ + + /* USER CODE END EXTI0_1_IRQn 1 */ +} + +/** + * @brief This function handles TIM1 break, update, trigger and commutation + * interrupts. + */ +void TIM1_BRK_UP_TRG_COM_IRQHandler(void) { + /* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 0 */ - /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 0 */ - HAL_TIM_IRQHandler(&htim1); - /* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 1 */ + /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 0 */ + HAL_TIM_IRQHandler(&htim1); + /* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 1 */ - /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 1 */ + /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 1 */ } /* USER CODE BEGIN 1 */ diff --git a/boards/motherboard/src/tasks.cpp b/boards/motherboard/src/tasks.cpp index 5298225..5a2928f 100644 --- a/boards/motherboard/src/tasks.cpp +++ b/boards/motherboard/src/tasks.cpp @@ -1,40 +1,128 @@ #include "tasks.hpp" #include "FreeRTOS.h" +#include "lib/adf5355/adf5355.hpp" +#include "lib/periph/digital.hpp" +#include "lib/periph/pwm.hpp" +#include "lib/periph/spi.hpp" #include "main.h" -#include "stm32g0xx_hal.h" +#include "spi.h" #include "task.h" +#include "tim.h" + +// the current state of this file is for lab +// testing - it will be severly refactored soon enum { - PRIORITY_10HZ = 1, - PRIORITY_100HZ = 2, - PRIORITY_1000HZ = 3, + PRIORITY_1HZ = 1, + PRIORITY_10HZ = 2, + PRIORITY_100HZ = 3, + PRIORITY_1000HZ = 4, }; static const size_t STACK_SIZE_WORDS = 512; -StaticTask_t t1000hz_ctrl; -StackType_t t1000hz_stack[STACK_SIZE_WORDS]; - StaticTask_t t100hz_ctrl; StackType_t t100hz_stack[STACK_SIZE_WORDS]; -StaticTask_t t10hz_ctrl; -StackType_t t10hz_stack[STACK_SIZE_WORDS]; +StaticTask_t t1hz_ctrl; +StackType_t t1hz_stack[STACK_SIZE_WORDS]; -void task_10hz(void* argument) { +auto task_100hz(void* argument) -> void { (void)argument; TickType_t wake_time = xTaskGetTickCount(); + // GPIOs + amber::periph::DigitalOutput vco_pwr_en(*VCO_PWR_EN_GPIO_Port, + VCO_PWR_EN_Pin); + amber::periph::DigitalOutput gen_en(*GEN_EN_GPIO_Port, GEN_EN_Pin); + amber::periph::DigitalOutput vga_pwr_en(*VGA_PWR_EN_GPIO_Port, + VGA_PWR_EN_Pin); + amber::periph::DigitalOutput lpa_pwr_en(*LPA_PWR_EN_GPIO_Port, + LPA_PWR_EN_Pin); + amber::periph::DigitalOutput p6v_scatter_pwr_en( + *P6V_SCATTER_PWR_EN_GPIO_Port, P6V_SCATTER_PWR_EN_Pin); + amber::periph::DigitalOutput lpa_en(*LPA_EN_GPIO_Port, LPA_EN_Pin); + amber::periph::DigitalOutput lna_en(*LNA_EN_GPIO_Port, LNA_EN_Pin); + amber::periph::DigitalOutput p6v_scatter_hsd_diag_en( + *P6V_SCATTER_HSD_DIAG_EN_GPIO_Port, P6V_SCATTER_HSD_DIAG_EN_Pin); + amber::periph::DigitalOutput logamp_en(*LOGAMP_EN_GPIO_Port, LOGAMP_EN_Pin); + amber::periph::DigitalOutput fan2_pwr_en(*FAN2_PWR_EN_GPIO_Port, + FAN2_PWR_EN_Pin); + amber::periph::DigitalOutput fan1_pwr_en(*FAN1_PWR_EN_GPIO_Port, + FAN1_PWR_EN_Pin); + amber::periph::DigitalOutput fan1_pwm(*FAN1_PWN_GPIO_Port, FAN1_PWN_Pin); + amber::periph::DigitalOutput warn_light(*WARN_LIGHT_GPIO_Port, + WARN_LIGHT_Pin); + amber::periph::DigitalOutput vco_le(*VCO_LE_GPIO_Port, VCO_LE_Pin); + + amber::periph::Spi spi2(hspi2, vco_le); + amber::periph::Pwm fan2_pwm(htim2, TIM_CHANNEL_4); + + // initialize the ADF5355 + amber::adf5355::Driver::InitParam param{}; + param.freq_req = 5725000000ULL; + param.clkin_freq = 100000000UL; + amber::adf5355::Driver adf(spi2, param); + adf.setup(); + + fan2_pwm.Start(); + fan2_pwm.SetDutyCycle(100.0f); + + vco_pwr_en.SetHigh(); + gen_en.SetHigh(); + vga_pwr_en.SetHigh(); + lpa_pwr_en.SetHigh(); + p6v_scatter_pwr_en.SetHigh(); + lpa_en.SetHigh(); + lna_en.SetHigh(); + p6v_scatter_hsd_diag_en.SetHigh(); + logamp_en.SetHigh(); + fan2_pwr_en.SetHigh(); + fan1_pwr_en.SetHigh(); + fan1_pwm.SetHigh(); + warn_light.SetHigh(); + + while (true) { + if (pwr_down_flag) { + vco_pwr_en.SetLow(); + gen_en.SetLow(); + vga_pwr_en.SetLow(); + lpa_pwr_en.SetLow(); + p6v_scatter_pwr_en.SetLow(); + lpa_en.SetLow(); + lna_en.SetLow(); + p6v_scatter_hsd_diag_en.SetLow(); + logamp_en.SetLow(); + fan2_pwr_en.SetLow(); + fan1_pwr_en.SetLow(); + fan1_pwm.SetLow(); + warn_light.SetLow(); + + warn_light.SetLow(); + break; + } + + vTaskDelayUntil(&wake_time, pdMS_TO_TICKS(10)); + } +}; + +auto task_1hz(void* argument) -> void { + amber::periph::DigitalOutput debug1(*DEBUG1_GPIO_Port, DEBUG1_Pin); + while (true) { - HAL_GPIO_TogglePin(DEBUG_GPIO_Port, DEBUG_Pin); - vTaskDelayUntil(&wake_time, pdMS_TO_TICKS(100)); + debug1.Toggle(); + + vTaskDelay(pdMS_TO_TICKS(1000)); } }; -void MX_FREERTOS_Init() { - xTaskCreateStatic(task_10hz, "10Hz", STACK_SIZE_WORDS, NULL, PRIORITY_10HZ, - t10hz_stack, &t10hz_ctrl); +auto MX_FREERTOS_Init() -> void { + xTaskCreateStatic(task_1hz, "1Hz", STACK_SIZE_WORDS, NULL, PRIORITY_1HZ, + t1hz_stack, &t1hz_ctrl); + + xTaskCreateStatic(task_100hz, "100Hz", STACK_SIZE_WORDS, NULL, + PRIORITY_100HZ, t100hz_stack, &t100hz_ctrl); vTaskStartScheduler(); } diff --git a/boards/motherboard/src/tim.c b/boards/motherboard/src/tim.c new file mode 100644 index 0000000..12e0a48 --- /dev/null +++ b/boards/motherboard/src/tim.c @@ -0,0 +1,129 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file tim.c + * @brief This file provides code for the configuration + * of the TIM instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "tim.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +TIM_HandleTypeDef htim2; + +/* TIM2 init function */ +void MX_TIM2_Init(void) { + /* USER CODE BEGIN TIM2_Init 0 */ + + /* USER CODE END TIM2_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + TIM_OC_InitTypeDef sConfigOC = {0}; + + /* USER CODE BEGIN TIM2_Init 1 */ + + /* USER CODE END TIM2_Init 1 */ + htim2.Instance = TIM2; + htim2.Init.Prescaler = 16; + htim2.Init.CounterMode = TIM_COUNTERMODE_UP; + htim2.Init.Period = 999; + htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; + if (HAL_TIM_Base_Init(&htim2) != HAL_OK) { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) { + Error_Handler(); + } + if (HAL_TIM_PWM_Init(&htim2) != HAL_OK) { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != + HAL_OK) { + Error_Handler(); + } + sConfigOC.OCMode = TIM_OCMODE_PWM1; + sConfigOC.Pulse = 0; + sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW; + sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; + if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4) != + HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN TIM2_Init 2 */ + + /* USER CODE END TIM2_Init 2 */ + HAL_TIM_MspPostInit(&htim2); +} + +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) { + if (tim_baseHandle->Instance == TIM2) { + /* USER CODE BEGIN TIM2_MspInit 0 */ + + /* USER CODE END TIM2_MspInit 0 */ + /* TIM2 clock enable */ + __HAL_RCC_TIM2_CLK_ENABLE(); + /* USER CODE BEGIN TIM2_MspInit 1 */ + + /* USER CODE END TIM2_MspInit 1 */ + } +} +void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (timHandle->Instance == TIM2) { + /* USER CODE BEGIN TIM2_MspPostInit 0 */ + + /* USER CODE END TIM2_MspPostInit 0 */ + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**TIM2 GPIO Configuration + PC7 ------> TIM2_CH4 + */ + GPIO_InitStruct.Pin = FAN2_PWM_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF2_TIM2; + HAL_GPIO_Init(FAN2_PWM_GPIO_Port, &GPIO_InitStruct); + + /* USER CODE BEGIN TIM2_MspPostInit 1 */ + + /* USER CODE END TIM2_MspPostInit 1 */ + } +} + +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) { + if (tim_baseHandle->Instance == TIM2) { + /* USER CODE BEGIN TIM2_MspDeInit 0 */ + + /* USER CODE END TIM2_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM2_CLK_DISABLE(); + /* USER CODE BEGIN TIM2_MspDeInit 1 */ + + /* USER CODE END TIM2_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/boards/motherboard/src/usart.c b/boards/motherboard/src/usart.c index a2edf89..97b9640 100644 --- a/boards/motherboard/src/usart.c +++ b/boards/motherboard/src/usart.c @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file usart.c - * @brief This file provides code for the configuration - * of the USART instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file usart.c + * @brief This file provides code for the configuration + * of the USART instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "usart.h" @@ -28,114 +28,101 @@ UART_HandleTypeDef huart1; /* USART1 init function */ -void MX_USART1_UART_Init(void) -{ - - /* USER CODE BEGIN USART1_Init 0 */ - - /* USER CODE END USART1_Init 0 */ - - /* USER CODE BEGIN USART1_Init 1 */ - - /* USER CODE END USART1_Init 1 */ - huart1.Instance = USART1; - huart1.Init.BaudRate = 115200; - huart1.Init.WordLength = UART_WORDLENGTH_8B; - huart1.Init.StopBits = UART_STOPBITS_1; - huart1.Init.Parity = UART_PARITY_NONE; - huart1.Init.Mode = UART_MODE_TX_RX; - huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - huart1.Init.OverSampling = UART_OVERSAMPLING_16; - huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&huart1) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) - { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK) - { - Error_Handler(); - } - /* USER CODE BEGIN USART1_Init 2 */ - - /* USER CODE END USART1_Init 2 */ +void MX_USART1_UART_Init(void) { + /* USER CODE BEGIN USART1_Init 0 */ + + /* USER CODE END USART1_Init 0 */ + + /* USER CODE BEGIN USART1_Init 1 */ + + /* USER CODE END USART1_Init 1 */ + huart1.Instance = USART1; + huart1.Init.BaudRate = 115200; + huart1.Init.WordLength = UART_WORDLENGTH_8B; + huart1.Init.StopBits = UART_STOPBITS_1; + huart1.Init.Parity = UART_PARITY_NONE; + huart1.Init.Mode = UART_MODE_TX_RX; + huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart1.Init.OverSampling = UART_OVERSAMPLING_16; + huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; + huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; + if (HAL_UART_Init(&huart1) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != + HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != + HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN USART1_Init 2 */ + /* USER CODE END USART1_Init 2 */ } -void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) -{ - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; - if(uartHandle->Instance==USART1) - { - /* USER CODE BEGIN USART1_MspInit 0 */ - - /* USER CODE END USART1_MspInit 0 */ - - /** Initializes the peripherals clocks - */ - PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1; - PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; - if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) - { - Error_Handler(); +void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; + if (uartHandle->Instance == USART1) { + /* USER CODE BEGIN USART1_MspInit 0 */ + + /* USER CODE END USART1_MspInit 0 */ + + /** Initializes the peripherals clocks + */ + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1; + PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { + Error_Handler(); + } + + /* USART1 clock enable */ + __HAL_RCC_USART1_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**USART1 GPIO Configuration + PC4 ------> USART1_TX + PC5 ------> USART1_RX + */ + GPIO_InitStruct.Pin = COMM_TX_Pin | COMM_RX_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF1_USART1; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /* USER CODE BEGIN USART1_MspInit 1 */ + + /* USER CODE END USART1_MspInit 1 */ } - - /* USART1 clock enable */ - __HAL_RCC_USART1_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**USART1 GPIO Configuration - PC4 ------> USART1_TX - PC5 ------> USART1_RX - */ - GPIO_InitStruct.Pin = COMM_TX_Pin|COMM_RX_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF1_USART1; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN USART1_MspInit 1 */ - - /* USER CODE END USART1_MspInit 1 */ - } } -void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) -{ - - if(uartHandle->Instance==USART1) - { - /* USER CODE BEGIN USART1_MspDeInit 0 */ +void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { + if (uartHandle->Instance == USART1) { + /* USER CODE BEGIN USART1_MspDeInit 0 */ - /* USER CODE END USART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_USART1_CLK_DISABLE(); + /* USER CODE END USART1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USART1_CLK_DISABLE(); - /**USART1 GPIO Configuration - PC4 ------> USART1_TX - PC5 ------> USART1_RX - */ - HAL_GPIO_DeInit(GPIOC, COMM_TX_Pin|COMM_RX_Pin); + /**USART1 GPIO Configuration + PC4 ------> USART1_TX + PC5 ------> USART1_RX + */ + HAL_GPIO_DeInit(GPIOC, COMM_TX_Pin | COMM_RX_Pin); - /* USER CODE BEGIN USART1_MspDeInit 1 */ + /* USER CODE BEGIN USART1_MspDeInit 1 */ - /* USER CODE END USART1_MspDeInit 1 */ - } + /* USER CODE END USART1_MspDeInit 1 */ + } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ - diff --git a/boards/motherboard/src/usb_device.c b/boards/motherboard/src/usb_device.c index 04c0f19..1016ae2 100644 --- a/boards/motherboard/src/usb_device.c +++ b/boards/motherboard/src/usb_device.c @@ -1,30 +1,31 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file : usb_device.c - * @version : v3.0_Cube - * @brief : This file implements the USB Device - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file : usb_device.c + * @version : v3.0_Cube + * @brief : This file implements the USB Device + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "usb_device.h" -#include "usbd_core.h" -#include "usbd_desc.h" + #include "usbd_cdc.h" #include "usbd_cdc_if.h" +#include "usbd_core.h" +#include "usbd_desc.h" /* USER CODE BEGIN Includes */ @@ -60,38 +61,37 @@ extern USBD_DescriptorsTypeDef CDC_Desc; /* USER CODE END 1 */ /** - * Init USB device Library, add supported class and start the library - * @retval None - */ -void MX_USB_Device_Init(void) -{ - /* USER CODE BEGIN USB_Device_Init_PreTreatment */ - - /* USER CODE END USB_Device_Init_PreTreatment */ - - /* Init Device Library, add supported class and start the library. */ - if (USBD_Init(&hUsbDeviceFS, &CDC_Desc, DEVICE_FS) != USBD_OK) { - Error_Handler(); - } - if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) { - Error_Handler(); - } - if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) { - Error_Handler(); - } - if (USBD_Start(&hUsbDeviceFS) != USBD_OK) { - Error_Handler(); - } - /* USER CODE BEGIN USB_Device_Init_PostTreatment */ - - /* USER CODE END USB_Device_Init_PostTreatment */ + * Init USB device Library, add supported class and start the library + * @retval None + */ +void MX_USB_Device_Init(void) { + /* USER CODE BEGIN USB_Device_Init_PreTreatment */ + + /* USER CODE END USB_Device_Init_PreTreatment */ + + /* Init Device Library, add supported class and start the library. */ + if (USBD_Init(&hUsbDeviceFS, &CDC_Desc, DEVICE_FS) != USBD_OK) { + Error_Handler(); + } + if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) { + Error_Handler(); + } + if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != + USBD_OK) { + Error_Handler(); + } + if (USBD_Start(&hUsbDeviceFS) != USBD_OK) { + Error_Handler(); + } + /* USER CODE BEGIN USB_Device_Init_PostTreatment */ + + /* USER CODE END USB_Device_Init_PostTreatment */ } /** - * @} - */ + * @} + */ /** - * @} - */ - + * @} + */ diff --git a/boards/motherboard/src/usbd_cdc_if.c b/boards/motherboard/src/usbd_cdc_if.c index fe0e8e1..2d1a851 100644 --- a/boards/motherboard/src/usbd_cdc_if.c +++ b/boards/motherboard/src/usbd_cdc_if.c @@ -1,21 +1,21 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file : usbd_cdc_if.c - * @version : v3.0_Cube - * @brief : Usb device for Virtual Com Port. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file : usbd_cdc_if.c + * @version : v3.0_Cube + * @brief : Usb device for Virtual Com Port. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ @@ -35,56 +35,57 @@ /* USER CODE END PV */ /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @brief Usb device library. - * @{ - */ + * @brief Usb device library. + * @{ + */ /** @addtogroup USBD_CDC_IF - * @{ - */ + * @{ + */ -/** @defgroup USBD_CDC_IF_Private_TypesDefinitions USBD_CDC_IF_Private_TypesDefinitions - * @brief Private types. - * @{ - */ +/** @defgroup USBD_CDC_IF_Private_TypesDefinitions + * USBD_CDC_IF_Private_TypesDefinitions + * @brief Private types. + * @{ + */ /* USER CODE BEGIN PRIVATE_TYPES */ /* USER CODE END PRIVATE_TYPES */ /** - * @} - */ + * @} + */ /** @defgroup USBD_CDC_IF_Private_Defines USBD_CDC_IF_Private_Defines - * @brief Private defines. - * @{ - */ + * @brief Private defines. + * @{ + */ /* USER CODE BEGIN PRIVATE_DEFINES */ /* USER CODE END PRIVATE_DEFINES */ /** - * @} - */ + * @} + */ /** @defgroup USBD_CDC_IF_Private_Macros USBD_CDC_IF_Private_Macros - * @brief Private macros. - * @{ - */ + * @brief Private macros. + * @{ + */ /* USER CODE BEGIN PRIVATE_MACRO */ /* USER CODE END PRIVATE_MACRO */ /** - * @} - */ + * @} + */ /** @defgroup USBD_CDC_IF_Private_Variables USBD_CDC_IF_Private_Variables - * @brief Private variables. - * @{ - */ + * @brief Private variables. + * @{ + */ /* Create buffer for reception and transmission */ /* It's up to user to redefine and/or remove those define */ /** Received data over USB are stored in this buffer */ @@ -98,13 +99,13 @@ uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; /* USER CODE END PRIVATE_VARIABLES */ /** - * @} - */ + * @} + */ /** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables - * @brief Public variables. - * @{ - */ + * @brief Public variables. + * @{ + */ extern USBD_HandleTypeDef hUsbDeviceFS; @@ -113,206 +114,201 @@ extern USBD_HandleTypeDef hUsbDeviceFS; /* USER CODE END EXPORTED_VARIABLES */ /** - * @} - */ + * @} + */ -/** @defgroup USBD_CDC_IF_Private_FunctionPrototypes USBD_CDC_IF_Private_FunctionPrototypes - * @brief Private functions declaration. - * @{ - */ +/** @defgroup USBD_CDC_IF_Private_FunctionPrototypes + * USBD_CDC_IF_Private_FunctionPrototypes + * @brief Private functions declaration. + * @{ + */ static int8_t CDC_Init_FS(void); static int8_t CDC_DeInit_FS(void); static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length); -static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len); -static int8_t CDC_TransmitCplt_FS(uint8_t *pbuf, uint32_t *Len, uint8_t epnum); +static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t* Len); +static int8_t CDC_TransmitCplt_FS(uint8_t* pbuf, uint32_t* Len, uint8_t epnum); /* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ /* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */ /** - * @} - */ - -USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = -{ - CDC_Init_FS, - CDC_DeInit_FS, - CDC_Control_FS, - CDC_Receive_FS, - CDC_TransmitCplt_FS -}; + * @} + */ + +USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = {CDC_Init_FS, CDC_DeInit_FS, + CDC_Control_FS, CDC_Receive_FS, + CDC_TransmitCplt_FS}; /* Private functions ---------------------------------------------------------*/ /** - * @brief Initializes the CDC media low layer over the FS USB IP - * @retval USBD_OK if all operations are OK else USBD_FAIL - */ -static int8_t CDC_Init_FS(void) -{ - /* USER CODE BEGIN 3 */ - /* Set Application Buffers */ - USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0); - USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS); - return (USBD_OK); - /* USER CODE END 3 */ + * @brief Initializes the CDC media low layer over the FS USB IP + * @retval USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_Init_FS(void) { + /* USER CODE BEGIN 3 */ + /* Set Application Buffers */ + USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0); + USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS); + return (USBD_OK); + /* USER CODE END 3 */ } /** - * @brief DeInitializes the CDC media low layer - * @retval USBD_OK if all operations are OK else USBD_FAIL - */ -static int8_t CDC_DeInit_FS(void) -{ - /* USER CODE BEGIN 4 */ - return (USBD_OK); - /* USER CODE END 4 */ + * @brief DeInitializes the CDC media low layer + * @retval USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_DeInit_FS(void) { + /* USER CODE BEGIN 4 */ + return (USBD_OK); + /* USER CODE END 4 */ } /** - * @brief Manage the CDC class requests - * @param cmd: Command code - * @param pbuf: Buffer containing command data (request parameters) - * @param length: Number of data to be sent (in bytes) - * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL - */ -static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) -{ - /* USER CODE BEGIN 5 */ - switch(cmd) - { - case CDC_SEND_ENCAPSULATED_COMMAND: + * @brief Manage the CDC class requests + * @param cmd: Command code + * @param pbuf: Buffer containing command data (request parameters) + * @param length: Number of data to be sent (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else + * USBD_FAIL + */ +static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) { + /* USER CODE BEGIN 5 */ + switch (cmd) { + case CDC_SEND_ENCAPSULATED_COMMAND: - break; + break; - case CDC_GET_ENCAPSULATED_RESPONSE: + case CDC_GET_ENCAPSULATED_RESPONSE: - break; + break; - case CDC_SET_COMM_FEATURE: + case CDC_SET_COMM_FEATURE: - break; + break; - case CDC_GET_COMM_FEATURE: + case CDC_GET_COMM_FEATURE: - break; + break; - case CDC_CLEAR_COMM_FEATURE: + case CDC_CLEAR_COMM_FEATURE: - break; + break; - /*******************************************************************************/ - /* Line Coding Structure */ - /*-----------------------------------------------------------------------------*/ - /* Offset | Field | Size | Value | Description */ - /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/ - /* 4 | bCharFormat | 1 | Number | Stop bits */ - /* 0 - 1 Stop bit */ - /* 1 - 1.5 Stop bits */ - /* 2 - 2 Stop bits */ - /* 5 | bParityType | 1 | Number | Parity */ - /* 0 - None */ - /* 1 - Odd */ - /* 2 - Even */ - /* 3 - Mark */ - /* 4 - Space */ - /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ - /*******************************************************************************/ - case CDC_SET_LINE_CODING: + /*******************************************************************************/ + /* Line Coding Structure */ + /*-----------------------------------------------------------------------------*/ + /* Offset | Field | Size | Value | Description */ + /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits + * per second*/ + /* 4 | bCharFormat | 1 | Number | Stop bits */ + /* 0 - 1 Stop bit */ + /* 1 - 1.5 Stop bits */ + /* 2 - 2 Stop bits */ + /* 5 | bParityType | 1 | Number | Parity */ + /* 0 - None */ + /* 1 - Odd */ + /* 2 - Even */ + /* 3 - Mark */ + /* 4 - Space */ + /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or + * 16). */ + /*******************************************************************************/ + case CDC_SET_LINE_CODING: - break; + break; - case CDC_GET_LINE_CODING: + case CDC_GET_LINE_CODING: - break; + break; - case CDC_SET_CONTROL_LINE_STATE: + case CDC_SET_CONTROL_LINE_STATE: - break; + break; - case CDC_SEND_BREAK: + case CDC_SEND_BREAK: - break; + break; - default: - break; - } + default: + break; + } - return (USBD_OK); - /* USER CODE END 5 */ + return (USBD_OK); + /* USER CODE END 5 */ } /** - * @brief Data received over USB OUT endpoint are sent over CDC interface - * through this function. - * - * @note - * This function will issue a NAK packet on any OUT packet received on - * USB endpoint until exiting this function. If you exit this function - * before transfer is complete on CDC interface (ie. using DMA controller) - * it will result in receiving more data while previous ones are still - * not sent. - * - * @param Buf: Buffer of data to be received - * @param Len: Number of data received (in bytes) - * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL - */ -static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) -{ - /* USER CODE BEGIN 6 */ - USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); - USBD_CDC_ReceivePacket(&hUsbDeviceFS); - return (USBD_OK); - /* USER CODE END 6 */ + * @brief Data received over USB OUT endpoint are sent over CDC interface + * through this function. + * + * @note + * This function will issue a NAK packet on any OUT packet received on + * USB endpoint until exiting this function. If you exit this function + * before transfer is complete on CDC interface (ie. using DMA + * controller) it will result in receiving more data while previous ones are + * still not sent. + * + * @param Buf: Buffer of data to be received + * @param Len: Number of data received (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else + * USBD_FAIL + */ +static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t* Len) { + /* USER CODE BEGIN 6 */ + USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); + USBD_CDC_ReceivePacket(&hUsbDeviceFS); + return (USBD_OK); + /* USER CODE END 6 */ } /** - * @brief CDC_Transmit_FS - * Data to send over USB IN endpoint are sent over CDC interface - * through this function. - * @note - * - * - * @param Buf: Buffer of data to be sent - * @param Len: Number of data to be sent (in bytes) - * @retval USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY - */ -uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) -{ - uint8_t result = USBD_OK; - /* USER CODE BEGIN 7 */ - USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData; - if (hcdc->TxState != 0){ - return USBD_BUSY; - } - USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len); - result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); - /* USER CODE END 7 */ - return result; + * @brief CDC_Transmit_FS + * Data to send over USB IN endpoint are sent over CDC interface + * through this function. + * @note + * + * + * @param Buf: Buffer of data to be sent + * @param Len: Number of data to be sent (in bytes) + * @retval USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY + */ +uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) { + uint8_t result = USBD_OK; + /* USER CODE BEGIN 7 */ + USBD_CDC_HandleTypeDef* hcdc = + (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData; + if (hcdc->TxState != 0) { + return USBD_BUSY; + } + USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len); + result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); + /* USER CODE END 7 */ + return result; } /** - * @brief CDC_TransmitCplt_FS - * Data transmitted callback - * - * @note - * This function is IN transfer complete callback used to inform user that - * the submitted Data is successfully sent over USB. - * - * @param Buf: Buffer of data to be received - * @param Len: Number of data received (in bytes) - * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL - */ -static int8_t CDC_TransmitCplt_FS(uint8_t *Buf, uint32_t *Len, uint8_t epnum) -{ - uint8_t result = USBD_OK; - /* USER CODE BEGIN 13 */ - UNUSED(Buf); - UNUSED(Len); - UNUSED(epnum); - /* USER CODE END 13 */ - return result; + * @brief CDC_TransmitCplt_FS + * Data transmitted callback + * + * @note + * This function is IN transfer complete callback used to inform user + * that the submitted Data is successfully sent over USB. + * + * @param Buf: Buffer of data to be received + * @param Len: Number of data received (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else + * USBD_FAIL + */ +static int8_t CDC_TransmitCplt_FS(uint8_t* Buf, uint32_t* Len, uint8_t epnum) { + uint8_t result = USBD_OK; + /* USER CODE BEGIN 13 */ + UNUSED(Buf); + UNUSED(Len); + UNUSED(epnum); + /* USER CODE END 13 */ + return result; } /* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ @@ -320,10 +316,9 @@ static int8_t CDC_TransmitCplt_FS(uint8_t *Buf, uint32_t *Len, uint8_t epnum) /* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ /** - * @} - */ + * @} + */ /** - * @} - */ - + * @} + */ diff --git a/boards/motherboard/src/usbd_conf.c b/boards/motherboard/src/usbd_conf.c index c401db4..31dc564 100644 --- a/boards/motherboard/src/usbd_conf.c +++ b/boards/motherboard/src/usbd_conf.c @@ -1,30 +1,30 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file : usbd_conf.c - * @version : v3.0_Cube - * @brief : This file implements the board support package for the USB device library - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file : usbd_conf.c + * @version : v3.0_Cube + * @brief : This file implements the board support package for the USB + * device library + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "stm32g0xx.h" #include "stm32g0xx_hal.h" -#include "usbd_def.h" -#include "usbd_core.h" - #include "usbd_cdc.h" +#include "usbd_core.h" +#include "usbd_def.h" /* USER CODE BEGIN Includes */ @@ -66,729 +66,722 @@ extern void SystemClock_Config(void); *******************************************************************************/ /* MSP Init */ -void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) -{ - RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; - if(pcdHandle->Instance==USB_DRD_FS) - { - /* USER CODE BEGIN USB_DRD_FS_MspInit 0 */ - - /* USER CODE END USB_DRD_FS_MspInit 0 */ - - /** Initializes the peripherals clocks - */ - PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; - PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; - if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) - { - Error_Handler(); +void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) { + RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; + if (pcdHandle->Instance == USB_DRD_FS) { + /* USER CODE BEGIN USB_DRD_FS_MspInit 0 */ + + /* USER CODE END USB_DRD_FS_MspInit 0 */ + + /** Initializes the peripherals clocks + */ + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; + PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { + Error_Handler(); + } + + /* Peripheral clock enable */ + __HAL_RCC_USB_CLK_ENABLE(); + + /* Enable VDDUSB */ + if (__HAL_RCC_PWR_IS_CLK_DISABLED()) { + __HAL_RCC_PWR_CLK_ENABLE(); + HAL_PWREx_EnableVddUSB(); + __HAL_RCC_PWR_CLK_DISABLE(); + } else { + HAL_PWREx_EnableVddUSB(); + } + /* USER CODE BEGIN USB_DRD_FS_MspInit 1 */ + + /* USER CODE END USB_DRD_FS_MspInit 1 */ } - - /* Peripheral clock enable */ - __HAL_RCC_USB_CLK_ENABLE(); - - /* Enable VDDUSB */ - if(__HAL_RCC_PWR_IS_CLK_DISABLED()) - { - __HAL_RCC_PWR_CLK_ENABLE(); - HAL_PWREx_EnableVddUSB(); - __HAL_RCC_PWR_CLK_DISABLE(); - } - else - { - HAL_PWREx_EnableVddUSB(); - } - /* USER CODE BEGIN USB_DRD_FS_MspInit 1 */ - - /* USER CODE END USB_DRD_FS_MspInit 1 */ - } } -void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) -{ - if(pcdHandle->Instance==USB_DRD_FS) - { - /* USER CODE BEGIN USB_DRD_FS_MspDeInit 0 */ +void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) { + if (pcdHandle->Instance == USB_DRD_FS) { + /* USER CODE BEGIN USB_DRD_FS_MspDeInit 0 */ - /* USER CODE END USB_DRD_FS_MspDeInit 0 */ - /* Disable Peripheral clock */ - __HAL_RCC_USB_CLK_DISABLE(); - /* USER CODE BEGIN USB_DRD_FS_MspDeInit 1 */ + /* USER CODE END USB_DRD_FS_MspDeInit 0 */ + /* Disable Peripheral clock */ + __HAL_RCC_USB_CLK_DISABLE(); + /* USER CODE BEGIN USB_DRD_FS_MspDeInit 1 */ - /* USER CODE END USB_DRD_FS_MspDeInit 1 */ - } + /* USER CODE END USB_DRD_FS_MspDeInit 1 */ + } } /** - * @brief Setup stage callback - * @param hpcd: PCD handle - * @retval None - */ + * @brief Setup stage callback + * @param hpcd: PCD handle + * @retval None + */ #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) +static void PCD_SetupStageCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - /* USER CODE BEGIN HAL_PCD_SetupStageCallback_PreTreatment */ + /* USER CODE BEGIN HAL_PCD_SetupStageCallback_PreTreatment */ - /* USER CODE END HAL_PCD_SetupStageCallback_PreTreatment */ - USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup); - /* USER CODE BEGIN HAL_PCD_SetupStageCallback_PostTreatment */ + /* USER CODE END HAL_PCD_SetupStageCallback_PreTreatment */ + USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t*)hpcd->Setup); + /* USER CODE BEGIN HAL_PCD_SetupStageCallback_PostTreatment */ - /* USER CODE END HAL_PCD_SetupStageCallback_PostTreatment */ + /* USER CODE END HAL_PCD_SetupStageCallback_PostTreatment */ } /** - * @brief Data Out stage callback. - * @param hpcd: PCD handle - * @param epnum: Endpoint number - * @retval None - */ + * @brief Data Out stage callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint number + * @retval None + */ #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +static void PCD_DataOutStageCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #else -void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - /* USER CODE BEGIN HAL_PCD_DataOutStageCallback_PreTreatment */ + /* USER CODE BEGIN HAL_PCD_DataOutStageCallback_PreTreatment */ - /* USER CODE END HAL_PCD_DataOutStageCallback_PreTreatment */ - USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); - /* USER CODE BEGIN HAL_PCD_DataOutStageCallback_PostTreatment */ + /* USER CODE END HAL_PCD_DataOutStageCallback_PreTreatment */ + USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, + hpcd->OUT_ep[epnum].xfer_buff); + /* USER CODE BEGIN HAL_PCD_DataOutStageCallback_PostTreatment */ - /* USER CODE END HAL_PCD_DataOutStageCallback_PostTreatment */ + /* USER CODE END HAL_PCD_DataOutStageCallback_PostTreatment */ } /** - * @brief Data In stage callback. - * @param hpcd: PCD handle - * @param epnum: Endpoint number - * @retval None - */ + * @brief Data In stage callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint number + * @retval None + */ #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +static void PCD_DataInStageCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #else -void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - /* USER CODE BEGIN HAL_PCD_DataInStageCallback_PreTreatment */ + /* USER CODE BEGIN HAL_PCD_DataInStageCallback_PreTreatment */ - /* USER CODE END HAL_PCD_DataInStageCallback_PreTreatment */ - USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); - /* USER CODE BEGIN HAL_PCD_DataInStageCallback_PostTreatment */ + /* USER CODE END HAL_PCD_DataInStageCallback_PreTreatment */ + USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, + hpcd->IN_ep[epnum].xfer_buff); + /* USER CODE BEGIN HAL_PCD_DataInStageCallback_PostTreatment */ - /* USER CODE END HAL_PCD_DataInStageCallback_PostTreatment */ + /* USER CODE END HAL_PCD_DataInStageCallback_PostTreatment */ } /** - * @brief SOF callback. - * @param hpcd: PCD handle - * @retval None - */ + * @brief SOF callback. + * @param hpcd: PCD handle + * @retval None + */ #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_SOFCallback(PCD_HandleTypeDef *hpcd) +static void PCD_SOFCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_SOFCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - /* USER CODE BEGIN HAL_PCD_SOFCallback_PreTreatment */ + /* USER CODE BEGIN HAL_PCD_SOFCallback_PreTreatment */ - /* USER CODE END HAL_PCD_SOFCallback_PreTreatment */ - USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); - /* USER CODE BEGIN HAL_PCD_SOFCallback_PostTreatment */ + /* USER CODE END HAL_PCD_SOFCallback_PreTreatment */ + USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); + /* USER CODE BEGIN HAL_PCD_SOFCallback_PostTreatment */ - /* USER CODE END HAL_PCD_SOFCallback_PostTreatment */ + /* USER CODE END HAL_PCD_SOFCallback_PostTreatment */ } /** - * @brief Reset callback. - * @param hpcd: PCD handle - * @retval None - */ + * @brief Reset callback. + * @param hpcd: PCD handle + * @retval None + */ #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ResetCallback(PCD_HandleTypeDef *hpcd) +static void PCD_ResetCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_ResetCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - /* USER CODE BEGIN HAL_PCD_ResetCallback_PreTreatment */ - - /* USER CODE END HAL_PCD_ResetCallback_PreTreatment */ - USBD_SpeedTypeDef speed = USBD_SPEED_FULL; - if (hpcd->Init.speed != USBD_FS_SPEED) - { - Error_Handler(); - } + /* USER CODE BEGIN HAL_PCD_ResetCallback_PreTreatment */ + + /* USER CODE END HAL_PCD_ResetCallback_PreTreatment */ + USBD_SpeedTypeDef speed = USBD_SPEED_FULL; + if (hpcd->Init.speed != USBD_FS_SPEED) { + Error_Handler(); + } /* Set Speed. */ - USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed); + USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed); - /* Reset Device. */ - USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); - /* USER CODE BEGIN HAL_PCD_ResetCallback_PostTreatment */ + /* Reset Device. */ + USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); + /* USER CODE BEGIN HAL_PCD_ResetCallback_PostTreatment */ - /* USER CODE END HAL_PCD_ResetCallback_PostTreatment */ + /* USER CODE END HAL_PCD_ResetCallback_PostTreatment */ } /** - * @brief Suspend callback. - * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) - * @param hpcd: PCD handle - * @retval None - */ + * @brief Suspend callback. + * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't + * support it) + * @param hpcd: PCD handle + * @retval None + */ #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) +static void PCD_SuspendCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_SuspendCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - /* USER CODE BEGIN HAL_PCD_SuspendCallback_PreTreatment */ - - /* USER CODE END HAL_PCD_SuspendCallback_PreTreatment */ - /* __HAL_PCD_GATE_PHYCLOCK(hpcd);*/ - /* Inform USB library that core enters in suspend Mode. */ - USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); - /* Enter in STOP mode. */ - /* USER CODE BEGIN 2 */ - if (hpcd->Init.low_power_enable) - { - /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ - SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); - } - /* USER CODE END 2 */ - /* USER CODE BEGIN HAL_PCD_SuspendCallback_PostTreatment */ - - /* USER CODE END HAL_PCD_SuspendCallback_PostTreatment */ -} - -/** - * @brief Resume callback. - * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) - * @param hpcd: PCD handle - * @retval None - */ + /* USER CODE BEGIN HAL_PCD_SuspendCallback_PreTreatment */ + + /* USER CODE END HAL_PCD_SuspendCallback_PreTreatment */ + /* __HAL_PCD_GATE_PHYCLOCK(hpcd);*/ + /* Inform USB library that core enters in suspend Mode. */ + USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); + /* Enter in STOP mode. */ + /* USER CODE BEGIN 2 */ + if (hpcd->Init.low_power_enable) { + /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. + */ + SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | + SCB_SCR_SLEEPONEXIT_Msk)); + } + /* USER CODE END 2 */ + /* USER CODE BEGIN HAL_PCD_SuspendCallback_PostTreatment */ + + /* USER CODE END HAL_PCD_SuspendCallback_PostTreatment */ +} + +/** + * @brief Resume callback. + * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't + * support it) + * @param hpcd: PCD handle + * @retval None + */ #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) +static void PCD_ResumeCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_ResumeCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - /* USER CODE BEGIN HAL_PCD_ResumeCallback_PreTreatment */ + /* USER CODE BEGIN HAL_PCD_ResumeCallback_PreTreatment */ - /* USER CODE END HAL_PCD_ResumeCallback_PreTreatment */ - /* __HAL_PCD_UNGATE_PHYCLOCK(hpcd);*/ + /* USER CODE END HAL_PCD_ResumeCallback_PreTreatment */ + /* __HAL_PCD_UNGATE_PHYCLOCK(hpcd);*/ - /* USER CODE BEGIN 3 */ - if (hpcd->Init.low_power_enable) - { - /* Reset SLEEPDEEP bit of Cortex System Control Register. */ - SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); - SystemClockConfig_Resume(); - } - /* USER CODE END 3 */ + /* USER CODE BEGIN 3 */ + if (hpcd->Init.low_power_enable) { + /* Reset SLEEPDEEP bit of Cortex System Control Register. */ + SCB->SCR &= (uint32_t)~( + (uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); + SystemClockConfig_Resume(); + } + /* USER CODE END 3 */ - USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData); - /* USER CODE BEGIN HAL_PCD_ResumeCallback_PostTreatment */ + USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData); + /* USER CODE BEGIN HAL_PCD_ResumeCallback_PostTreatment */ - /* USER CODE END HAL_PCD_ResumeCallback_PostTreatment */ + /* USER CODE END HAL_PCD_ResumeCallback_PostTreatment */ } /** - * @brief ISOOUTIncomplete callback. - * @param hpcd: PCD handle - * @param epnum: Endpoint number - * @retval None - */ + * @brief ISOOUTIncomplete callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint number + * @retval None + */ #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #else -void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - /* USER CODE BEGIN HAL_PCD_ISOOUTIncompleteCallback_PreTreatment */ + /* USER CODE BEGIN HAL_PCD_ISOOUTIncompleteCallback_PreTreatment */ - /* USER CODE END HAL_PCD_ISOOUTIncompleteCallback_PreTreatment */ - USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); - /* USER CODE BEGIN HAL_PCD_ISOOUTIncompleteCallback_PostTreatment */ + /* USER CODE END HAL_PCD_ISOOUTIncompleteCallback_PreTreatment */ + USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); + /* USER CODE BEGIN HAL_PCD_ISOOUTIncompleteCallback_PostTreatment */ - /* USER CODE END HAL_PCD_ISOOUTIncompleteCallback_PostTreatment */ + /* USER CODE END HAL_PCD_ISOOUTIncompleteCallback_PostTreatment */ } /** - * @brief ISOINIncomplete callback. - * @param hpcd: PCD handle - * @param epnum: Endpoint number - * @retval None - */ + * @brief ISOINIncomplete callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint number + * @retval None + */ #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #else -void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef* hpcd, uint8_t epnum) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - /* USER CODE BEGIN HAL_PCD_ISOINIncompleteCallback_PreTreatment */ + /* USER CODE BEGIN HAL_PCD_ISOINIncompleteCallback_PreTreatment */ - /* USER CODE END HAL_PCD_ISOINIncompleteCallback_PreTreatment */ - USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); - /* USER CODE BEGIN HAL_PCD_ISOINIncompleteCallback_PostTreatment */ + /* USER CODE END HAL_PCD_ISOINIncompleteCallback_PreTreatment */ + USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); + /* USER CODE BEGIN HAL_PCD_ISOINIncompleteCallback_PostTreatment */ - /* USER CODE END HAL_PCD_ISOINIncompleteCallback_PostTreatment */ + /* USER CODE END HAL_PCD_ISOINIncompleteCallback_PostTreatment */ } /** - * @brief Connect callback. - * @param hpcd: PCD handle - * @retval None - */ + * @brief Connect callback. + * @param hpcd: PCD handle + * @retval None + */ #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) +static void PCD_ConnectCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_ConnectCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - /* USER CODE BEGIN HAL_PCD_ConnectCallback_PreTreatment */ + /* USER CODE BEGIN HAL_PCD_ConnectCallback_PreTreatment */ - /* USER CODE END HAL_PCD_ConnectCallback_PreTreatment */ - USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData); - /* USER CODE BEGIN HAL_PCD_ConnectCallback_PostTreatment */ + /* USER CODE END HAL_PCD_ConnectCallback_PreTreatment */ + USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData); + /* USER CODE BEGIN HAL_PCD_ConnectCallback_PostTreatment */ - /* USER CODE END HAL_PCD_ConnectCallback_PostTreatment */ + /* USER CODE END HAL_PCD_ConnectCallback_PostTreatment */ } /** - * @brief Disconnect callback. - * @param hpcd: PCD handle - * @retval None - */ + * @brief Disconnect callback. + * @param hpcd: PCD handle + * @retval None + */ #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) +static void PCD_DisconnectCallback(PCD_HandleTypeDef* hpcd) #else -void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) +void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef* hpcd) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PreTreatment */ + /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PreTreatment */ - /* USER CODE END HAL_PCD_DisconnectCallback_PreTreatment */ - USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); - /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PostTreatment */ + /* USER CODE END HAL_PCD_DisconnectCallback_PreTreatment */ + USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); + /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PostTreatment */ - /* USER CODE END HAL_PCD_DisconnectCallback_PostTreatment */ + /* USER CODE END HAL_PCD_DisconnectCallback_PostTreatment */ } - /* USER CODE BEGIN LowLevelInterface */ +/* USER CODE BEGIN LowLevelInterface */ - /* USER CODE END LowLevelInterface */ +/* USER CODE END LowLevelInterface */ /******************************************************************************* LL Driver Interface (USB Device Library --> PCD) *******************************************************************************/ /** - * @brief Initializes the low level portion of the device driver. - * @param pdev: Device handle - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) -{ - /* Init USB Ip. */ - hpcd_USB_DRD_FS.pData = pdev; - /* Link the driver to the stack. */ - pdev->pData = &hpcd_USB_DRD_FS; - - hpcd_USB_DRD_FS.Instance = USB_DRD_FS; - hpcd_USB_DRD_FS.Init.dev_endpoints = 8; - hpcd_USB_DRD_FS.Init.Host_channels = 8; - hpcd_USB_DRD_FS.Init.speed = PCD_SPEED_FULL; - hpcd_USB_DRD_FS.Init.phy_itface = PCD_PHY_EMBEDDED; - hpcd_USB_DRD_FS.Init.Sof_enable = DISABLE; - hpcd_USB_DRD_FS.Init.low_power_enable = DISABLE; - hpcd_USB_DRD_FS.Init.lpm_enable = DISABLE; - hpcd_USB_DRD_FS.Init.battery_charging_enable = DISABLE; - hpcd_USB_DRD_FS.Init.vbus_sensing_enable = DISABLE; - hpcd_USB_DRD_FS.Init.bulk_doublebuffer_enable = DISABLE; - hpcd_USB_DRD_FS.Init.iso_singlebuffer_enable = DISABLE; - if (HAL_PCD_Init(&hpcd_USB_DRD_FS) != HAL_OK) - { - Error_Handler( ); - } + * @brief Initializes the low level portion of the device driver. + * @param pdev: Device handle + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef* pdev) { + /* Init USB Ip. */ + hpcd_USB_DRD_FS.pData = pdev; + /* Link the driver to the stack. */ + pdev->pData = &hpcd_USB_DRD_FS; + + hpcd_USB_DRD_FS.Instance = USB_DRD_FS; + hpcd_USB_DRD_FS.Init.dev_endpoints = 8; + hpcd_USB_DRD_FS.Init.Host_channels = 8; + hpcd_USB_DRD_FS.Init.speed = PCD_SPEED_FULL; + hpcd_USB_DRD_FS.Init.phy_itface = PCD_PHY_EMBEDDED; + hpcd_USB_DRD_FS.Init.Sof_enable = DISABLE; + hpcd_USB_DRD_FS.Init.low_power_enable = DISABLE; + hpcd_USB_DRD_FS.Init.lpm_enable = DISABLE; + hpcd_USB_DRD_FS.Init.battery_charging_enable = DISABLE; + hpcd_USB_DRD_FS.Init.vbus_sensing_enable = DISABLE; + hpcd_USB_DRD_FS.Init.bulk_doublebuffer_enable = DISABLE; + hpcd_USB_DRD_FS.Init.iso_singlebuffer_enable = DISABLE; + if (HAL_PCD_Init(&hpcd_USB_DRD_FS) != HAL_OK) { + Error_Handler(); + } #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) - /* Register USB PCD CallBacks */ - HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_SOF_CB_ID, PCD_SOFCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_RESET_CB_ID, PCD_ResetCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_SUSPEND_CB_ID, PCD_SuspendCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_RESUME_CB_ID, PCD_ResumeCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_CONNECT_CB_ID, PCD_ConnectCallback); - HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback); - /* USER CODE BEGIN RegisterCallBackFirstPart */ - - /* USER CODE END RegisterCallBackFirstPart */ - HAL_PCD_RegisterLpmCallback(&hpcd_USB_DRD_FS, PCDEx_LPM_Callback); - HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_DRD_FS, PCD_DataOutStageCallback); - HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_DRD_FS, PCD_DataInStageCallback); - HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_DRD_FS, PCD_ISOOUTIncompleteCallback); - HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_DRD_FS, PCD_ISOINIncompleteCallback); - /* USER CODE BEGIN RegisterCallBackSecondPart */ - - /* USER CODE END RegisterCallBackSecondPart */ + /* Register USB PCD CallBacks */ + HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_SOF_CB_ID, + PCD_SOFCallback); + HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_SETUPSTAGE_CB_ID, + PCD_SetupStageCallback); + HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_RESET_CB_ID, + PCD_ResetCallback); + HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_SUSPEND_CB_ID, + PCD_SuspendCallback); + HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_RESUME_CB_ID, + PCD_ResumeCallback); + HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_CONNECT_CB_ID, + PCD_ConnectCallback); + HAL_PCD_RegisterCallback(&hpcd_USB_DRD_FS, HAL_PCD_DISCONNECT_CB_ID, + PCD_DisconnectCallback); + /* USER CODE BEGIN RegisterCallBackFirstPart */ + + /* USER CODE END RegisterCallBackFirstPart */ + HAL_PCD_RegisterLpmCallback(&hpcd_USB_DRD_FS, PCDEx_LPM_Callback); + HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_DRD_FS, + PCD_DataOutStageCallback); + HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_DRD_FS, + PCD_DataInStageCallback); + HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_DRD_FS, + PCD_ISOOUTIncompleteCallback); + HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_DRD_FS, + PCD_ISOINIncompleteCallback); + /* USER CODE BEGIN RegisterCallBackSecondPart */ + + /* USER CODE END RegisterCallBackSecondPart */ #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ - /* USER CODE BEGIN EndPoint_Configuration */ - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18); - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58); - /* USER CODE END EndPoint_Configuration */ - /* USER CODE BEGIN EndPoint_Configuration_CDC */ - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x81 , PCD_SNG_BUF, 0xC0); - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x01 , PCD_SNG_BUF, 0x110); - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x82 , PCD_SNG_BUF, 0x100); - /* USER CODE END EndPoint_Configuration_CDC */ + /* USER CODE BEGIN EndPoint_Configuration */ + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x00, PCD_SNG_BUF, + 0x18); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x80, PCD_SNG_BUF, + 0x58); + /* USER CODE END EndPoint_Configuration */ + /* USER CODE BEGIN EndPoint_Configuration_CDC */ + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x81, PCD_SNG_BUF, + 0xC0); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x01, PCD_SNG_BUF, + 0x110); + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData, 0x82, PCD_SNG_BUF, + 0x100); + /* USER CODE END EndPoint_Configuration_CDC */ - return USBD_OK; + return USBD_OK; } /** - * @brief De-Initializes the low level portion of the device driver. - * @param pdev: Device handle - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; + * @brief De-Initializes the low level portion of the device driver. + * @param pdev: Device handle + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef* pdev) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; - hal_status = HAL_PCD_DeInit(pdev->pData); + hal_status = HAL_PCD_DeInit(pdev->pData); - usb_status = USBD_Get_USB_Status(hal_status); + usb_status = USBD_Get_USB_Status(hal_status); - return usb_status; + return usb_status; } /** - * @brief Starts the low level portion of the device driver. - * @param pdev: Device handle - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; + * @brief Starts the low level portion of the device driver. + * @param pdev: Device handle + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef* pdev) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; - hal_status = HAL_PCD_Start(pdev->pData); + hal_status = HAL_PCD_Start(pdev->pData); - usb_status = USBD_Get_USB_Status(hal_status); + usb_status = USBD_Get_USB_Status(hal_status); - return usb_status; + return usb_status; } /** - * @brief Stops the low level portion of the device driver. - * @param pdev: Device handle - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; + * @brief Stops the low level portion of the device driver. + * @param pdev: Device handle + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef* pdev) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; - hal_status = HAL_PCD_Stop(pdev->pData); + hal_status = HAL_PCD_Stop(pdev->pData); - usb_status = USBD_Get_USB_Status(hal_status); + usb_status = USBD_Get_USB_Status(hal_status); - return usb_status; + return usb_status; } /** - * @brief Opens an endpoint of the low level driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @param ep_type: Endpoint type - * @param ep_mps: Endpoint max packet size - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; + * @brief Opens an endpoint of the low level driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @param ep_type: Endpoint type + * @param ep_mps: Endpoint max packet size + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr, + uint8_t ep_type, uint16_t ep_mps) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; - hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type); + hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type); - usb_status = USBD_Get_USB_Status(hal_status); + usb_status = USBD_Get_USB_Status(hal_status); - return usb_status; + return usb_status; } /** - * @brief Closes an endpoint of the low level driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; + * @brief Closes an endpoint of the low level driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; - hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr); + hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr); - usb_status = USBD_Get_USB_Status(hal_status); + usb_status = USBD_Get_USB_Status(hal_status); - return usb_status; + return usb_status; } /** - * @brief Flushes an endpoint of the Low Level Driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; + * @brief Flushes an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; - hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr); + hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr); - usb_status = USBD_Get_USB_Status(hal_status); + usb_status = USBD_Get_USB_Status(hal_status); - return usb_status; + return usb_status; } /** - * @brief Sets a Stall condition on an endpoint of the Low Level Driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; + * @brief Sets a Stall condition on an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; - hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr); + hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr); - usb_status = USBD_Get_USB_Status(hal_status); + usb_status = USBD_Get_USB_Status(hal_status); - return usb_status; + return usb_status; } /** - * @brief Clears a Stall condition on an endpoint of the Low Level Driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; + * @brief Clears a Stall condition on an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef* pdev, + uint8_t ep_addr) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; - hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr); + hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr); - usb_status = USBD_Get_USB_Status(hal_status); + usb_status = USBD_Get_USB_Status(hal_status); - return usb_status; + return usb_status; } /** - * @brief Returns Stall condition. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval Stall (1: Yes, 0: No) - */ -uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; + * @brief Returns Stall condition. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval Stall (1: Yes, 0: No) + */ +uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { + PCD_HandleTypeDef* hpcd = (PCD_HandleTypeDef*)pdev->pData; - if((ep_addr & 0x80) == 0x80) - { - return hpcd->IN_ep[ep_addr & 0x7F].is_stall; - } - else - { - return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; - } + if ((ep_addr & 0x80) == 0x80) { + return hpcd->IN_ep[ep_addr & 0x7F].is_stall; + } else { + return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; + } } /** - * @brief Assigns a USB address to the device. - * @param pdev: Device handle - * @param dev_addr: Device address - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; + * @brief Assigns a USB address to the device. + * @param pdev: Device handle + * @param dev_addr: Device address + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef* pdev, + uint8_t dev_addr) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; - hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr); + hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr); - usb_status = USBD_Get_USB_Status(hal_status); + usb_status = USBD_Get_USB_Status(hal_status); - return usb_status; + return usb_status; } /** - * @brief Transmits data over an endpoint. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @param pbuf: Pointer to data to be sent - * @param size: Data size - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; + * @brief Transmits data over an endpoint. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @param pbuf: Pointer to data to be sent + * @param size: Data size + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef* pdev, uint8_t ep_addr, + uint8_t* pbuf, uint32_t size) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; - hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size); + hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size); - usb_status = USBD_Get_USB_Status(hal_status); + usb_status = USBD_Get_USB_Status(hal_status); - return usb_status; + return usb_status; } /** - * @brief Prepares an endpoint for reception. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @param pbuf: Pointer to data to be received - * @param size: Data size - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; + * @brief Prepares an endpoint for reception. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @param pbuf: Pointer to data to be received + * @param size: Data size + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef* pdev, + uint8_t ep_addr, uint8_t* pbuf, + uint32_t size) { + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; - hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size); + hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size); - usb_status = USBD_Get_USB_Status(hal_status); + usb_status = USBD_Get_USB_Status(hal_status); - return usb_status; + return usb_status; } /** - * @brief Returns the last transferred packet size. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval Received Data Size - */ -uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr); + * @brief Returns the last transferred packet size. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval Received Data Size + */ +uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef* pdev, uint8_t ep_addr) { + return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*)pdev->pData, ep_addr); } /** - * @brief Send LPM message to user layer - * @param hpcd: PCD handle - * @param msg: LPM message - * @retval None - */ + * @brief Send LPM message to user layer + * @param hpcd: PCD handle + * @param msg: LPM message + * @retval None + */ #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) +static void PCDEx_LPM_Callback(PCD_HandleTypeDef* hpcd, PCD_LPM_MsgTypeDef msg) #else -void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) +void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef* hpcd, PCD_LPM_MsgTypeDef msg) #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ { - /* USER CODE BEGIN LPM_Callback */ - switch (msg) - { - case PCD_LPM_L0_ACTIVE: - if (hpcd->Init.low_power_enable) - { - SystemClockConfig_Resume(); - - /* Reset SLEEPDEEP bit of Cortex System Control Register. */ - SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); + /* USER CODE BEGIN LPM_Callback */ + switch (msg) { + case PCD_LPM_L0_ACTIVE: + if (hpcd->Init.low_power_enable) { + SystemClockConfig_Resume(); + + /* Reset SLEEPDEEP bit of Cortex System Control Register. */ + SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | + SCB_SCR_SLEEPONEXIT_Msk)); + } + /*__HAL_PCD_UNGATE_PHYCLOCK(hpcd);*/ + USBD_LL_Resume(hpcd->pData); + break; + + case PCD_LPM_L1_ACTIVE: + /*__HAL_PCD_GATE_PHYCLOCK(hpcd);*/ + USBD_LL_Suspend(hpcd->pData); + + /* Enter in STOP mode. */ + if (hpcd->Init.low_power_enable) { + /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control + * Register. */ + SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | + SCB_SCR_SLEEPONEXIT_Msk)); + } + break; } - /*__HAL_PCD_UNGATE_PHYCLOCK(hpcd);*/ - USBD_LL_Resume(hpcd->pData); - break; - - case PCD_LPM_L1_ACTIVE: - /*__HAL_PCD_GATE_PHYCLOCK(hpcd);*/ - USBD_LL_Suspend(hpcd->pData); - - /* Enter in STOP mode. */ - if (hpcd->Init.low_power_enable) - { - /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ - SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); - } - break; - } - /* USER CODE END LPM_Callback */ + /* USER CODE END LPM_Callback */ } /** - * @brief Static single allocation. - * @param size: Size of allocated memory - * @retval None - */ -void *USBD_static_malloc(uint32_t size) -{ - static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */ - return mem; + * @brief Static single allocation. + * @param size: Size of allocated memory + * @retval None + */ +void* USBD_static_malloc(uint32_t size) { + static uint32_t + mem[(sizeof(USBD_CDC_HandleTypeDef) / 4) + 1]; /* On 32-bit boundary */ + return mem; } /** - * @brief Dummy memory free - * @param p: Pointer to allocated memory address - * @retval None - */ -void USBD_static_free(void *p) -{ - -} + * @brief Dummy memory free + * @param p: Pointer to allocated memory address + * @retval None + */ +void USBD_static_free(void* p) {} /** - * @brief Delays routine for the USB Device Library. - * @param Delay: Delay in ms - * @retval None - */ -void USBD_LL_Delay(uint32_t Delay) -{ - HAL_Delay(Delay); + * @brief Delays routine for the USB Device Library. + * @param Delay: Delay in ms + * @retval None + */ +void USBD_LL_Delay(uint32_t Delay) { + HAL_Delay(Delay); } /* USER CODE BEGIN 5 */ /** - * @brief Configures system clock after wake-up from USB resume callBack: - * enable HSI, PLL and select PLL as system clock source. - * @retval None - */ -static void SystemClockConfig_Resume(void) -{ - SystemClock_Config(); + * @brief Configures system clock after wake-up from USB resume callBack: + * enable HSI, PLL and select PLL as system clock source. + * @retval None + */ +static void SystemClockConfig_Resume(void) { + SystemClock_Config(); } /* USER CODE END 5 */ /** - * @brief Returns the USB status depending on the HAL status: - * @param hal_status: HAL status - * @retval USB status - */ -USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status) -{ - USBD_StatusTypeDef usb_status = USBD_OK; - - switch (hal_status) - { - case HAL_OK : - usb_status = USBD_OK; - break; - case HAL_ERROR : - usb_status = USBD_FAIL; - break; - case HAL_BUSY : - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT : - usb_status = USBD_FAIL; - break; - default : - usb_status = USBD_FAIL; - break; - } - return usb_status; + * @brief Returns the USB status depending on the HAL status: + * @param hal_status: HAL status + * @retval USB status + */ +USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status) { + USBD_StatusTypeDef usb_status = USBD_OK; + + switch (hal_status) { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; } diff --git a/boards/motherboard/src/usbd_desc.c b/boards/motherboard/src/usbd_desc.c index 627e34f..bc7a859 100644 --- a/boards/motherboard/src/usbd_desc.c +++ b/boards/motherboard/src/usbd_desc.c @@ -1,27 +1,28 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * @file : usbd_desc.c - * @version : v3.0_Cube - * @brief : This file implements the USB device descriptors. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file : usbd_desc.c + * @version : v3.0_Cube + * @brief : This file implements the USB device descriptors. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ -#include "usbd_core.h" #include "usbd_desc.h" + #include "usbd_conf.h" +#include "usbd_core.h" /* USER CODE BEGIN INCLUDE */ @@ -37,360 +38,343 @@ /* USER CODE END PV */ /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @{ - */ + * @{ + */ /** @addtogroup USBD_DESC - * @{ - */ + * @{ + */ -/** @defgroup USBD_DESC_Private_TypesDefinitions USBD_DESC_Private_TypesDefinitions - * @brief Private types. - * @{ - */ +/** @defgroup USBD_DESC_Private_TypesDefinitions + * USBD_DESC_Private_TypesDefinitions + * @brief Private types. + * @{ + */ /* USER CODE BEGIN PRIVATE_TYPES */ /* USER CODE END PRIVATE_TYPES */ /** - * @} - */ + * @} + */ /** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines - * @brief Private defines. - * @{ - */ - -#define USBD_VID 1155 -#define USBD_LANGID_STRING 1033 -#define USBD_MANUFACTURER_STRING "STMicroelectronics" -#define USBD_PID 22336 -#define USBD_PRODUCT_STRING "STM32 Virtual ComPort" -#define USBD_CONFIGURATION_STRING "CDC Config" -#define USBD_INTERFACE_STRING "CDC Interface" + * @brief Private defines. + * @{ + */ + +#define USBD_VID 1155 +#define USBD_LANGID_STRING 1033 +#define USBD_MANUFACTURER_STRING "STMicroelectronics" +#define USBD_PID 22336 +#define USBD_PRODUCT_STRING "STM32 Virtual ComPort" +#define USBD_CONFIGURATION_STRING "CDC Config" +#define USBD_INTERFACE_STRING "CDC Interface" /* USER CODE BEGIN PRIVATE_DEFINES */ /* USER CODE END PRIVATE_DEFINES */ /** - * @} - */ + * @} + */ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros - * @brief Private macros. - * @{ - */ + * @brief Private macros. + * @{ + */ /* USER CODE BEGIN PRIVATE_MACRO */ /* USER CODE END PRIVATE_MACRO */ /** - * @} - */ + * @} + */ -/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes - * @brief Private functions declaration. - * @{ - */ +/** @defgroup USBD_DESC_Private_FunctionPrototypes + * USBD_DESC_Private_FunctionPrototypes + * @brief Private functions declaration. + * @{ + */ static void Get_SerialNum(void); -static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len); +static void IntToUnicode(uint32_t value, uint8_t* pbuf, uint8_t len); /** - * @} - */ - -/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes - * @brief Private functions declaration. - * @{ - */ - -uint8_t * USBD_CDC_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_CDC_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t * USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); + * @} + */ + +/** @defgroup USBD_DESC_Private_FunctionPrototypes + * USBD_DESC_Private_FunctionPrototypes + * @brief Private functions declaration. + * @{ + */ + +uint8_t* USBD_CDC_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t* length); +uint8_t* USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, + uint16_t* length); +uint8_t* USBD_CDC_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, + uint16_t* length); +uint8_t* USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, + uint16_t* length); +uint8_t* USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, + uint16_t* length); +uint8_t* USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, + uint16_t* length); +uint8_t* USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, + uint16_t* length); /** - * @} - */ + * @} + */ /** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables - * @brief Private variables. - * @{ - */ - -USBD_DescriptorsTypeDef CDC_Desc = -{ - USBD_CDC_DeviceDescriptor, - USBD_CDC_LangIDStrDescriptor, - USBD_CDC_ManufacturerStrDescriptor, - USBD_CDC_ProductStrDescriptor, - USBD_CDC_SerialStrDescriptor, - USBD_CDC_ConfigStrDescriptor, - USBD_CDC_InterfaceStrDescriptor -}; - -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 + * @brief Private variables. + * @{ + */ + +USBD_DescriptorsTypeDef CDC_Desc = { + USBD_CDC_DeviceDescriptor, USBD_CDC_LangIDStrDescriptor, + USBD_CDC_ManufacturerStrDescriptor, USBD_CDC_ProductStrDescriptor, + USBD_CDC_SerialStrDescriptor, USBD_CDC_ConfigStrDescriptor, + USBD_CDC_InterfaceStrDescriptor}; + +#if defined(__ICCARM__) /* IAR Compiler */ +#pragma data_alignment = 4 #endif /* defined ( __ICCARM__ ) */ /** USB standard device descriptor. */ -__ALIGN_BEGIN uint8_t USBD_CDC_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = -{ - 0x12, /*bLength */ - USB_DESC_TYPE_DEVICE, /*bDescriptorType*/ - 0x00, /*bcdUSB */ - 0x02, - 0x02, /*bDeviceClass*/ - 0x02, /*bDeviceSubClass*/ - 0x00, /*bDeviceProtocol*/ - USB_MAX_EP0_SIZE, /*bMaxPacketSize*/ - LOBYTE(USBD_VID), /*idVendor*/ - HIBYTE(USBD_VID), /*idVendor*/ - LOBYTE(USBD_PID), /*idProduct*/ - HIBYTE(USBD_PID), /*idProduct*/ - 0x00, /*bcdDevice rel. 2.00*/ - 0x02, - USBD_IDX_MFC_STR, /*Index of manufacturer string*/ - USBD_IDX_PRODUCT_STR, /*Index of product string*/ - USBD_IDX_SERIAL_STR, /*Index of serial number string*/ - USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/ +__ALIGN_BEGIN uint8_t USBD_CDC_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = { + 0x12, /*bLength */ + USB_DESC_TYPE_DEVICE, /*bDescriptorType*/ + 0x00, /*bcdUSB */ + 0x02, + 0x02, /*bDeviceClass*/ + 0x02, /*bDeviceSubClass*/ + 0x00, /*bDeviceProtocol*/ + USB_MAX_EP0_SIZE, /*bMaxPacketSize*/ + LOBYTE(USBD_VID), /*idVendor*/ + HIBYTE(USBD_VID), /*idVendor*/ + LOBYTE(USBD_PID), /*idProduct*/ + HIBYTE(USBD_PID), /*idProduct*/ + 0x00, /*bcdDevice rel. 2.00*/ + 0x02, + USBD_IDX_MFC_STR, /*Index of manufacturer string*/ + USBD_IDX_PRODUCT_STR, /*Index of product string*/ + USBD_IDX_SERIAL_STR, /*Index of serial number string*/ + USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/ }; /* USB_DeviceDescriptor */ /** - * @} - */ + * @} + */ /** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables - * @brief Private variables. - * @{ - */ + * @brief Private variables. + * @{ + */ -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 +#if defined(__ICCARM__) /* IAR Compiler */ +#pragma data_alignment = 4 #endif /* defined ( __ICCARM__ ) */ /** USB lang identifier descriptor. */ -__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = -{ - USB_LEN_LANGID_STR_DESC, - USB_DESC_TYPE_STRING, - LOBYTE(USBD_LANGID_STRING), - HIBYTE(USBD_LANGID_STRING) -}; +__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = { + USB_LEN_LANGID_STR_DESC, USB_DESC_TYPE_STRING, LOBYTE(USBD_LANGID_STRING), + HIBYTE(USBD_LANGID_STRING)}; -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 +#if defined(__ICCARM__) /* IAR Compiler */ +#pragma data_alignment = 4 #endif /* defined ( __ICCARM__ ) */ /* Internal string descriptor. */ __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; -#if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 +#if defined(__ICCARM__) /*!< IAR Compiler */ +#pragma data_alignment = 4 #endif __ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = { - USB_SIZ_STRING_SERIAL, - USB_DESC_TYPE_STRING, + USB_SIZ_STRING_SERIAL, + USB_DESC_TYPE_STRING, }; /** - * @} - */ + * @} + */ /** @defgroup USBD_DESC_Private_Functions USBD_DESC_Private_Functions - * @brief Private functions. - * @{ - */ + * @brief Private functions. + * @{ + */ /** - * @brief Return the device descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_CDC_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - UNUSED(speed); - *length = sizeof(USBD_CDC_DeviceDesc); - return USBD_CDC_DeviceDesc; + * @brief Return the device descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t* USBD_CDC_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t* length) { + UNUSED(speed); + *length = sizeof(USBD_CDC_DeviceDesc); + return USBD_CDC_DeviceDesc; } /** - * @brief Return the LangID string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - UNUSED(speed); - *length = sizeof(USBD_LangIDDesc); - return USBD_LangIDDesc; + * @brief Return the LangID string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t* USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, + uint16_t* length) { + UNUSED(speed); + *length = sizeof(USBD_LangIDDesc); + return USBD_LangIDDesc; } /** - * @brief Return the product string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - if(speed == 0) - { - USBD_GetString((uint8_t *)USBD_PRODUCT_STRING, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_PRODUCT_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; + * @brief Return the product string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t* USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, + uint16_t* length) { + if (speed == 0) { + USBD_GetString((uint8_t*)USBD_PRODUCT_STRING, USBD_StrDesc, length); + } else { + USBD_GetString((uint8_t*)USBD_PRODUCT_STRING, USBD_StrDesc, length); + } + return USBD_StrDesc; } /** - * @brief Return the manufacturer string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_CDC_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - UNUSED(speed); - USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); - return USBD_StrDesc; + * @brief Return the manufacturer string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t* USBD_CDC_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, + uint16_t* length) { + UNUSED(speed); + USBD_GetString((uint8_t*)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); + return USBD_StrDesc; } /** - * @brief Return the serial number string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - UNUSED(speed); - *length = USB_SIZ_STRING_SERIAL; + * @brief Return the serial number string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t* USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, + uint16_t* length) { + UNUSED(speed); + *length = USB_SIZ_STRING_SERIAL; - /* Update the serial number string descriptor with the data from the unique - * ID */ - Get_SerialNum(); + /* Update the serial number string descriptor with the data from the unique + * ID */ + Get_SerialNum(); - /* USER CODE BEGIN USBD_CDC_SerialStrDescriptor */ + /* USER CODE BEGIN USBD_CDC_SerialStrDescriptor */ - /* USER CODE END USBD_CDC_SerialStrDescriptor */ + /* USER CODE END USBD_CDC_SerialStrDescriptor */ - return (uint8_t *) USBD_StringSerial; + return (uint8_t*)USBD_StringSerial; } /** - * @brief Return the configuration string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - if(speed == USBD_SPEED_HIGH) - { - USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; + * @brief Return the configuration string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t* USBD_CDC_ConfigStrDescriptor(USBD_SpeedTypeDef speed, + uint16_t* length) { + if (speed == USBD_SPEED_HIGH) { + USBD_GetString((uint8_t*)USBD_CONFIGURATION_STRING, USBD_StrDesc, + length); + } else { + USBD_GetString((uint8_t*)USBD_CONFIGURATION_STRING, USBD_StrDesc, + length); + } + return USBD_StrDesc; } /** - * @brief Return the interface string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - if(speed == 0) - { - USBD_GetString((uint8_t *)USBD_INTERFACE_STRING, USBD_StrDesc, length); - } - else - { - USBD_GetString((uint8_t *)USBD_INTERFACE_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; + * @brief Return the interface string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t* USBD_CDC_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, + uint16_t* length) { + if (speed == 0) { + USBD_GetString((uint8_t*)USBD_INTERFACE_STRING, USBD_StrDesc, length); + } else { + USBD_GetString((uint8_t*)USBD_INTERFACE_STRING, USBD_StrDesc, length); + } + return USBD_StrDesc; } /** - * @brief Create the serial number string descriptor - * @param None - * @retval None - */ -static void Get_SerialNum(void) -{ - uint32_t deviceserial0; - uint32_t deviceserial1; - uint32_t deviceserial2; - - deviceserial0 = *(uint32_t *) DEVICE_ID1; - deviceserial1 = *(uint32_t *) DEVICE_ID2; - deviceserial2 = *(uint32_t *) DEVICE_ID3; - - deviceserial0 += deviceserial2; - - if (deviceserial0 != 0) - { - IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8); - IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4); - } + * @brief Create the serial number string descriptor + * @param None + * @retval None + */ +static void Get_SerialNum(void) { + uint32_t deviceserial0; + uint32_t deviceserial1; + uint32_t deviceserial2; + + deviceserial0 = *(uint32_t*)DEVICE_ID1; + deviceserial1 = *(uint32_t*)DEVICE_ID2; + deviceserial2 = *(uint32_t*)DEVICE_ID3; + + deviceserial0 += deviceserial2; + + if (deviceserial0 != 0) { + IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8); + IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4); + } } /** - * @brief Convert Hex 32Bits value into char - * @param value: value to convert - * @param pbuf: pointer to the buffer - * @param len: buffer length - * @retval None - */ -static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len) -{ - uint8_t idx = 0; - - for (idx = 0; idx < len; idx++) - { - if (((value >> 28)) < 0xA) - { - pbuf[2 * idx] = (value >> 28) + '0'; - } - else - { - pbuf[2 * idx] = (value >> 28) + 'A' - 10; + * @brief Convert Hex 32Bits value into char + * @param value: value to convert + * @param pbuf: pointer to the buffer + * @param len: buffer length + * @retval None + */ +static void IntToUnicode(uint32_t value, uint8_t* pbuf, uint8_t len) { + uint8_t idx = 0; + + for (idx = 0; idx < len; idx++) { + if (((value >> 28)) < 0xA) { + pbuf[2 * idx] = (value >> 28) + '0'; + } else { + pbuf[2 * idx] = (value >> 28) + 'A' - 10; + } + + value = value << 4; + + pbuf[2 * idx + 1] = 0; } - - value = value << 4; - - pbuf[2 * idx + 1] = 0; - } } /** - * @} - */ + * @} + */ /** - * @} - */ + * @} + */ /** - * @} - */ - + * @} + */ diff --git a/lib/adf5355/adf5355.hpp b/lib/adf5355/adf5355.hpp index 11372ad..9b286d5 100644 --- a/lib/adf5355/adf5355.hpp +++ b/lib/adf5355/adf5355.hpp @@ -37,11 +37,11 @@ struct Driver { }; struct InitParam { - DeviceId dev_id; - uint64_t freq_req {0}; + DeviceId dev_id{DeviceId::ADF5355}; + uint64_t freq_req {5725000000ULL}; uint8_t freq_req_chan {0}; - uint32_t clkin_freq {0}; - uint32_t cp_ua {0}; + uint32_t clkin_freq {100000000UL}; + uint32_t cp_ua {900}; bool cp_neg_bleed_en {false}; bool cp_gated_bleed_en {false}; bool cp_bleed_current_polarity_en {false}; @@ -52,7 +52,7 @@ struct Driver { uint8_t outb_power {0}; bool phase_detector_polarity_neg {false}; bool ref_diff_en {false}; - bool mux_out_3v3_en {false}; + bool mux_out_3v3_en {true}; uint8_t ref_doubler_en {0}; uint8_t ref_div2_en {0}; MuxOutSel mux_out_sel {MuxOutSel::DIGITAL_LOCK_DETECT}; diff --git a/lib/periph/analog_input.hpp b/lib/periph/analog_input.hpp index cf812d9..80c7a7c 100644 --- a/lib/periph/analog_input.hpp +++ b/lib/periph/analog_input.hpp @@ -1,6 +1,6 @@ /** * @file analog_input.hpp - * @author Ivan Lange + * @author Blake Freer and Ivan Lange * @brief Analog input driver wrapper * * @date 2026-03-22 diff --git a/lib/periph/analog_output.hpp b/lib/periph/analog_output.hpp index 9f4dac5..4fc151a 100644 --- a/lib/periph/analog_output.hpp +++ b/lib/periph/analog_output.hpp @@ -1,6 +1,6 @@ /** * @file analog_output.hpp - * @author Ivan Lange + * @author Blake Freer and Ivan Lange * @brief Analog output driver wrapper * * @date 2026-03-22 diff --git a/lib/periph/digital.hpp b/lib/periph/digital.hpp index 5953a14..dcff7f2 100644 --- a/lib/periph/digital.hpp +++ b/lib/periph/digital.hpp @@ -1,6 +1,6 @@ /** * @file digital.hpp - * @author Ivan Lange + * @author Blake Freer and Ivan Lange * @brief Digital input/output driver wrapper * * @date 2026-03-22 diff --git a/lib/periph/pwm.hpp b/lib/periph/pwm.hpp new file mode 100644 index 0000000..fd58f41 --- /dev/null +++ b/lib/periph/pwm.hpp @@ -0,0 +1,86 @@ +/** + * @file pwm.hpp + * @author Blake Freer and Ivan Lange + * @brief PWM driver wrapper + * + * @date 2026-03-21 + */ + +#pragma once + +#include +#include + +#ifdef STM32F7 +#include "stm32f7xx_hal.h" +#elif STM32G0 +#include "stm32g0xx_hal.h" + +#endif + +#ifdef HAL_TIM_MODULE_ENABLED + +namespace amber::periph { + +struct Pwm { + Pwm(TIM_HandleTypeDef& htim, uint32_t channel) + : _htim(htim), _channel(channel) {} + + ~Pwm() = default; + + auto Start() noexcept -> void { + HAL_TIM_PWM_Start(&_htim, _channel); + } + + auto Stop() noexcept -> void { + HAL_TIM_PWM_Stop(&_htim, _channel); + } + + auto SetDutyCycle(const float dutyCycle) noexcept -> void { + _dutyCycle = std::clamp(dutyCycle, 0, 100); + + uint32_t pulse = static_cast((_dutyCycle / 100.0f) * + (_htim.Init.Period + 1)); + __HAL_TIM_SET_COMPARE(&_htim, _channel, pulse); + } + + auto GetDutyCycle() const noexcept -> float { + uint32_t pulse = __HAL_TIM_GET_COMPARE(&_htim, _channel); + uint32_t period = __HAL_TIM_GET_AUTORELOAD(&_htim); + + return (static_cast(pulse) / static_cast(period)) * + 100.0f; + } + + auto SetFrequency(const float frequency) noexcept -> void { + float freq = std::max(kMinFrequency, frequency); + uint32_t autoReload = static_cast( + static_cast(GetTimerFrequency()) / freq); + + __HAL_TIM_SET_AUTORELOAD(&_htim, autoReload); + } + + auto GetFrequency() const noexcept -> float { + float freq = static_cast(GetTimerFrequency()) / + (static_cast(__HAL_TIM_GET_AUTORELOAD(&_htim))); + + return freq; + } + +private: + static constexpr float kMinFrequency = 0.000015259022f; + + TIM_HandleTypeDef& _htim; + uint32_t _channel; + + float _dutyCycle = 0.0; + + auto GetTimerFrequency() const noexcept -> float { + auto tickFreq = HAL_GetTickFreq(); + return tickFreq; + } +}; + +} // namespace amber::periph + +#endif // HAL_TIM_MODULE_ENABLED From f58cb6d8bc6f73781526c2e94a9b97866651fa36 Mon Sep 17 00:00:00 2001 From: Ivan Lange Date: Sat, 4 Apr 2026 20:51:52 -0400 Subject: [PATCH 07/13] Add modules for control --- boards/motherboard/Inc/main.h | 6 +- boards/motherboard/Inc/stm32g0xx_hal_conf.h | 2 +- boards/motherboard/Inc/usart.h | 51 --- boards/motherboard/lib/cobs | 1 + boards/motherboard/lib/tps1h100 | 1 + boards/motherboard/lib/tps274160b | 1 + boards/motherboard/motherboard.ioc | 334 ++++++++++---------- boards/motherboard/platformio.ini | 6 +- boards/motherboard/src/carrier/carrier.cpp | 76 +++++ boards/motherboard/src/carrier/carrier.hpp | 10 + boards/motherboard/src/gpio.c | 6 +- boards/motherboard/src/main.c | 3 +- boards/motherboard/src/power/power.cpp | 184 +++++++++++ boards/motherboard/src/power/power.hpp | 25 ++ boards/motherboard/src/serial/serial.cpp | 30 ++ boards/motherboard/src/serial/serial.hpp | 17 + boards/motherboard/src/tasks.cpp | 131 ++++---- boards/motherboard/src/thermal/thermal.cpp | 7 + boards/motherboard/src/thermal/thermal.hpp | 8 + boards/motherboard/src/usart.c | 128 -------- lib/adf5355/adf5355.hpp | 2 +- lib/adl6331/adl6331.cpp | 2 +- lib/adl6331/adl6331.hpp | 5 +- lib/cc1101/cc1101.cpp | 4 +- lib/cc1101/cc1101.hpp | 4 +- lib/periph/analog_input.hpp | 3 +- lib/periph/analog_output.hpp | 51 +-- lib/periph/digital.hpp | 3 + lib/tps1h100/tps1h100.cpp | 31 ++ lib/tps1h100/tps1h100.hpp | 43 +++ lib/tps274160b/tps274160b.cpp | 54 ++++ lib/tps274160b/tps274160b.hpp | 53 ++++ 32 files changed, 816 insertions(+), 466 deletions(-) delete mode 100644 boards/motherboard/Inc/usart.h create mode 120000 boards/motherboard/lib/cobs create mode 120000 boards/motherboard/lib/tps1h100 create mode 120000 boards/motherboard/lib/tps274160b create mode 100644 boards/motherboard/src/carrier/carrier.cpp create mode 100644 boards/motherboard/src/carrier/carrier.hpp create mode 100644 boards/motherboard/src/power/power.cpp create mode 100644 boards/motherboard/src/power/power.hpp create mode 100644 boards/motherboard/src/serial/serial.cpp create mode 100644 boards/motherboard/src/serial/serial.hpp create mode 100644 boards/motherboard/src/thermal/thermal.cpp create mode 100644 boards/motherboard/src/thermal/thermal.hpp delete mode 100644 boards/motherboard/src/usart.c create mode 100644 lib/tps1h100/tps1h100.cpp create mode 100644 lib/tps1h100/tps1h100.hpp create mode 100644 lib/tps274160b/tps274160b.cpp create mode 100644 lib/tps274160b/tps274160b.hpp diff --git a/boards/motherboard/Inc/main.h b/boards/motherboard/Inc/main.h index 3f7f1d3..f96db35 100644 --- a/boards/motherboard/Inc/main.h +++ b/boards/motherboard/Inc/main.h @@ -79,10 +79,8 @@ void Error_Handler(void); #define DAC_ADJ_GPIO_Port GPIOA #define LPA_PWR_DET_Pin GPIO_PIN_7 #define LPA_PWR_DET_GPIO_Port GPIOA -#define COMM_TX_Pin GPIO_PIN_4 -#define COMM_TX_GPIO_Port GPIOC -#define COMM_RX_Pin GPIO_PIN_5 -#define COMM_RX_GPIO_Port GPIOC +#define COMPARATOR_Pin GPIO_PIN_5 +#define COMPARATOR_GPIO_Port GPIOC #define PWR_DOWN_Pin GPIO_PIN_0 #define PWR_DOWN_GPIO_Port GPIOB #define PWR_DOWN_EXTI_IRQn EXTI0_1_IRQn diff --git a/boards/motherboard/Inc/stm32g0xx_hal_conf.h b/boards/motherboard/Inc/stm32g0xx_hal_conf.h index e81375d..75c244d 100644 --- a/boards/motherboard/Inc/stm32g0xx_hal_conf.h +++ b/boards/motherboard/Inc/stm32g0xx_hal_conf.h @@ -55,7 +55,7 @@ extern "C" { /* #define HAL_SMBUS_MODULE_ENABLED */ #define HAL_SPI_MODULE_ENABLED #define HAL_TIM_MODULE_ENABLED -#define HAL_UART_MODULE_ENABLED +/* #define HAL_UART_MODULE_ENABLED */ /* #define HAL_USART_MODULE_ENABLED */ /* #define HAL_WWDG_MODULE_ENABLED */ #define HAL_GPIO_MODULE_ENABLED diff --git a/boards/motherboard/Inc/usart.h b/boards/motherboard/Inc/usart.h deleted file mode 100644 index 714fb76..0000000 --- a/boards/motherboard/Inc/usart.h +++ /dev/null @@ -1,51 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file usart.h - * @brief This file contains all the function prototypes for - * the usart.c file - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USART_H__ -#define __USART_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "main.h" - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -extern UART_HandleTypeDef huart1; - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -void MX_USART1_UART_Init(void); - -/* USER CODE BEGIN Prototypes */ - -/* USER CODE END Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USART_H__ */ diff --git a/boards/motherboard/lib/cobs b/boards/motherboard/lib/cobs new file mode 120000 index 0000000..3ffa777 --- /dev/null +++ b/boards/motherboard/lib/cobs @@ -0,0 +1 @@ +../../../lib/cobs \ No newline at end of file diff --git a/boards/motherboard/lib/tps1h100 b/boards/motherboard/lib/tps1h100 new file mode 120000 index 0000000..520724d --- /dev/null +++ b/boards/motherboard/lib/tps1h100 @@ -0,0 +1 @@ +../../../lib/tps1h100 \ No newline at end of file diff --git a/boards/motherboard/lib/tps274160b b/boards/motherboard/lib/tps274160b new file mode 120000 index 0000000..1bf8602 --- /dev/null +++ b/boards/motherboard/lib/tps274160b @@ -0,0 +1 @@ +../../../lib/tps274160b \ No newline at end of file diff --git a/boards/motherboard/motherboard.ioc b/boards/motherboard/motherboard.ioc index f872665..cb37567 100644 --- a/boards/motherboard/motherboard.ioc +++ b/boards/motherboard/motherboard.ioc @@ -1,3 +1,4 @@ +#MicroXplorer Configuration settings - do not modify ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_0 ADC1.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag,master,SelectedChannel ADC1.NbrOfConversionFlag=1 @@ -24,6 +25,7 @@ Mcu.CPN=STM32G0B1VET6 Mcu.Family=STM32G0 Mcu.IP0=ADC1 Mcu.IP1=DAC1 +Mcu.IP10=USB_DRD_FS Mcu.IP2=FREERTOS Mcu.IP3=NVIC Mcu.IP4=RCC @@ -31,22 +33,12 @@ Mcu.IP5=SPI2 Mcu.IP6=SPI3 Mcu.IP7=SYS Mcu.IP8=TIM2 -Mcu.IP9=USART1 -Mcu.IP10=USB_DEVICE -Mcu.IP11=USB_DRD_FS -Mcu.IPNb=12 +Mcu.IP9=USB_DEVICE +Mcu.IPNb=11 Mcu.Name=STM32G0B1V(B-C-E)Tx Mcu.Package=LQFP100 Mcu.Pin0=PB9 Mcu.Pin1=PC10 -Mcu.Pin2=PC11 -Mcu.Pin3=PE4 -Mcu.Pin4=PE5 -Mcu.Pin5=PE6 -Mcu.Pin6=PC12 -Mcu.Pin7=PC13 -Mcu.Pin8=PC14-OSC32_IN (PC14) -Mcu.Pin9=PC15-OSC32_OUT (PC15) Mcu.Pin10=PF0-OSC_IN (PF0) Mcu.Pin11=PF1-OSC_OUT (PF1) Mcu.Pin12=PF2-NRST @@ -57,6 +49,7 @@ Mcu.Pin16=PC0 Mcu.Pin17=PC1 Mcu.Pin18=PC2 Mcu.Pin19=PC3 +Mcu.Pin2=PC11 Mcu.Pin20=PA0 Mcu.Pin21=PA1 Mcu.Pin22=PA2 @@ -65,78 +58,84 @@ Mcu.Pin24=PA4 Mcu.Pin25=PA5 Mcu.Pin26=PA6 Mcu.Pin27=PA7 -Mcu.Pin28=PC4 -Mcu.Pin29=PC5 -Mcu.Pin30=PB0 -Mcu.Pin31=PB1 -Mcu.Pin32=PB2 -Mcu.Pin33=PF6 -Mcu.Pin34=PF7 -Mcu.Pin35=PE7 -Mcu.Pin36=PE8 -Mcu.Pin37=PE9 -Mcu.Pin38=PE10 -Mcu.Pin39=PE11 -Mcu.Pin40=PE12 -Mcu.Pin41=PE13 -Mcu.Pin42=PE14 -Mcu.Pin43=PE15 -Mcu.Pin44=PB10 -Mcu.Pin45=PB11 -Mcu.Pin46=PB12 -Mcu.Pin47=PB13 -Mcu.Pin48=PB14 -Mcu.Pin49=PB15 -Mcu.Pin50=PA8 -Mcu.Pin51=PA9 -Mcu.Pin52=PC6 -Mcu.Pin53=PC7 -Mcu.Pin54=PD8 -Mcu.Pin55=PD9 -Mcu.Pin56=PD10 -Mcu.Pin57=PD11 -Mcu.Pin58=PD12 -Mcu.Pin59=PD13 -Mcu.Pin60=PD14 -Mcu.Pin61=PD15 -Mcu.Pin62=PA10 -Mcu.Pin63=PA11 [PA9] -Mcu.Pin64=PA12 [PA10] -Mcu.Pin65=PF8 -Mcu.Pin66=PA13 -Mcu.Pin67=PA14-BOOT0 -Mcu.Pin68=PA15 -Mcu.Pin69=PC8 -Mcu.Pin70=PC9 -Mcu.Pin71=PD0 -Mcu.Pin72=PD1 -Mcu.Pin73=PD2 -Mcu.Pin74=PD3 -Mcu.Pin75=PD4 -Mcu.Pin76=PD5 -Mcu.Pin77=PD6 -Mcu.Pin78=PD7 -Mcu.Pin79=PF9 -Mcu.Pin80=PF10 -Mcu.Pin81=PF11 -Mcu.Pin82=PF12 -Mcu.Pin83=PF13 -Mcu.Pin84=PB3 -Mcu.Pin85=PB4 -Mcu.Pin86=PB5 -Mcu.Pin87=PE0 -Mcu.Pin88=PE1 -Mcu.Pin89=PE2 -Mcu.Pin90=PE3 -Mcu.Pin91=PB6 -Mcu.Pin92=PB7 -Mcu.Pin93=PB8 -Mcu.Pin94=VP_FREERTOS_VS_CMSIS_V1 -Mcu.Pin95=VP_SYS_VS_tim1 -Mcu.Pin96=VP_SYS_VS_DBSignals -Mcu.Pin97=VP_TIM2_VS_ClockSourceINT -Mcu.Pin98=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS -Mcu.PinsNb=99 +Mcu.Pin28=PC5 +Mcu.Pin29=PB0 +Mcu.Pin3=PE4 +Mcu.Pin30=PB1 +Mcu.Pin31=PB2 +Mcu.Pin32=PF6 +Mcu.Pin33=PF7 +Mcu.Pin34=PE7 +Mcu.Pin35=PE8 +Mcu.Pin36=PE9 +Mcu.Pin37=PE10 +Mcu.Pin38=PE11 +Mcu.Pin39=PE12 +Mcu.Pin4=PE5 +Mcu.Pin40=PE13 +Mcu.Pin41=PE14 +Mcu.Pin42=PE15 +Mcu.Pin43=PB10 +Mcu.Pin44=PB11 +Mcu.Pin45=PB12 +Mcu.Pin46=PB13 +Mcu.Pin47=PB14 +Mcu.Pin48=PB15 +Mcu.Pin49=PA8 +Mcu.Pin5=PE6 +Mcu.Pin50=PA9 +Mcu.Pin51=PC6 +Mcu.Pin52=PC7 +Mcu.Pin53=PD8 +Mcu.Pin54=PD9 +Mcu.Pin55=PD10 +Mcu.Pin56=PD11 +Mcu.Pin57=PD12 +Mcu.Pin58=PD13 +Mcu.Pin59=PD14 +Mcu.Pin6=PC12 +Mcu.Pin60=PD15 +Mcu.Pin61=PA10 +Mcu.Pin62=PA11 [PA9] +Mcu.Pin63=PA12 [PA10] +Mcu.Pin64=PF8 +Mcu.Pin65=PA13 +Mcu.Pin66=PA14-BOOT0 +Mcu.Pin67=PA15 +Mcu.Pin68=PC8 +Mcu.Pin69=PC9 +Mcu.Pin7=PC13 +Mcu.Pin70=PD0 +Mcu.Pin71=PD1 +Mcu.Pin72=PD2 +Mcu.Pin73=PD3 +Mcu.Pin74=PD4 +Mcu.Pin75=PD5 +Mcu.Pin76=PD6 +Mcu.Pin77=PD7 +Mcu.Pin78=PF9 +Mcu.Pin79=PF10 +Mcu.Pin8=PC14-OSC32_IN (PC14) +Mcu.Pin80=PF11 +Mcu.Pin81=PF12 +Mcu.Pin82=PF13 +Mcu.Pin83=PB3 +Mcu.Pin84=PB4 +Mcu.Pin85=PB5 +Mcu.Pin86=PE0 +Mcu.Pin87=PE1 +Mcu.Pin88=PE2 +Mcu.Pin89=PE3 +Mcu.Pin9=PC15-OSC32_OUT (PC15) +Mcu.Pin90=PB6 +Mcu.Pin91=PB7 +Mcu.Pin92=PB8 +Mcu.Pin93=VP_FREERTOS_VS_CMSIS_V1 +Mcu.Pin94=VP_SYS_VS_tim1 +Mcu.Pin95=VP_SYS_VS_DBSignals +Mcu.Pin96=VP_TIM2_VS_ClockSourceINT +Mcu.Pin97=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS +Mcu.PinsNb=98 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32G0B1VETx @@ -153,14 +152,25 @@ NVIC.SavedSvcallIrqHandlerGenerated=true NVIC.SavedSystickIrqHandlerGenerated=true NVIC.SysTick_IRQn=true\:3\:0\:false\:false\:false\:true\:false\:true\:false NVIC.TIM1_BRK_UP_TRG_COM_IRQn=true\:3\:0\:false\:false\:true\:false\:false\:true\:true -NVIC.TimeBaseIP=TIM1 NVIC.TimeBase=TIM1_BRK_UP_TRG_COM_IRQn +NVIC.TimeBaseIP=TIM1 PA0.GPIOParameters=GPIO_Label PA0.GPIO_Label=LOG_VSENSE PA0.Locked=true PA0.Mode=IN0 PA0.Signal=ADC1_IN0 PA1.Locked=true +PA10.Locked=true +PA11\ [PA9].Mode=Device +PA11\ [PA9].Signal=USB_DM +PA12\ [PA10].Mode=Device +PA12\ [PA10].Signal=USB_DP +PA13.Locked=true +PA14-BOOT0.Locked=true +PA15.GPIOParameters=GPIO_Label +PA15.GPIO_Label=USB_nFAULT +PA15.Locked=true +PA15.Signal=GPIO_Input PA2.Locked=true PA3.Locked=true PA4.GPIOParameters=GPIO_Label @@ -180,17 +190,6 @@ PA9.GPIOParameters=GPIO_Label PA9.GPIO_Label=FAN1_PWN PA9.Locked=true PA9.Signal=GPIO_Output -PA10.Locked=true -PA11\ [PA9].Mode=Device -PA11\ [PA9].Signal=USB_DM -PA12\ [PA10].Mode=Device -PA12\ [PA10].Signal=USB_DP -PA13.Locked=true -PA14-BOOT0.Locked=true -PA15.GPIOParameters=GPIO_Label -PA15.GPIO_Label=USB_nFAULT -PA15.Locked=true -PA15.Signal=GPIO_Input PB0.GPIOParameters=GPIO_Label,GPIO_ModeDefaultEXTI PB0.GPIO_Label=PWR_DOWN PB0.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING @@ -200,6 +199,16 @@ PB1.GPIOParameters=GPIO_Label PB1.GPIO_Label=P6V_CS_TWO PB1.Mode=IN9 PB1.Signal=ADC1_IN9 +PB10.GPIOParameters=GPIO_Label +PB10.GPIO_Label=P12V_CS +PB10.Locked=true +PB10.Mode=IN11 +PB10.Signal=ADC1_IN11 +PB11.Locked=true +PB12.Locked=true +PB13.Locked=true +PB14.Locked=true +PB15.Locked=true PB2.GPIOParameters=GPIO_Label PB2.GPIO_Label=P6V_CS_ONE PB2.Mode=IN10 @@ -227,34 +236,32 @@ PB8.Locked=true PB8.Mode=Simplex_Bidirectional_Master PB8.Signal=SPI2_SCK PB9.Locked=true -PB10.GPIOParameters=GPIO_Label -PB10.GPIO_Label=P12V_CS -PB10.Locked=true -PB10.Mode=IN11 -PB10.Signal=ADC1_IN11 -PB11.Locked=true -PB12.Locked=true -PB13.Locked=true -PB14.Locked=true -PB15.Locked=true PC0.Locked=true PC1.GPIOParameters=GPIO_Label PC1.GPIO_Label=LNA_EN PC1.Locked=true PC1.Signal=GPIO_Output +PC10.Mode=Full_Duplex_Master +PC10.Signal=SPI3_SCK +PC11.Mode=Full_Duplex_Master +PC11.Signal=SPI3_MISO +PC12.Mode=Full_Duplex_Master +PC12.Signal=SPI3_MOSI +PC13.GPIOParameters=GPIO_Label +PC13.GPIO_Label=TEMP_ALERT_N +PC13.Locked=true +PC13.Signal=GPIO_Input +PC14-OSC32_IN\ (PC14).Locked=true +PC15-OSC32_OUT\ (PC15).Locked=true PC2.GPIOParameters=GPIO_Label PC2.GPIO_Label=LOGAMP_EN PC2.Locked=true PC2.Signal=GPIO_Output PC3.Locked=true -PC4.GPIOParameters=GPIO_Label -PC4.GPIO_Label=COMM_TX -PC4.Mode=Asynchronous -PC4.Signal=USART1_TX PC5.GPIOParameters=GPIO_Label -PC5.GPIO_Label=COMM_RX -PC5.Mode=Asynchronous -PC5.Signal=USART1_RX +PC5.GPIO_Label=COMPARATOR +PC5.Locked=true +PC5.Signal=GPIO_Input PC6.GPIOParameters=GPIO_Label PC6.GPIO_Label=WARN_LIGHT PC6.Locked=true @@ -270,18 +277,6 @@ PC9.GPIOParameters=GPIO_Label PC9.GPIO_Label=P12V_VSENSE PC9.Locked=true PC9.Signal=GPIO_Input -PC10.Mode=Full_Duplex_Master -PC10.Signal=SPI3_SCK -PC11.Mode=Full_Duplex_Master -PC11.Signal=SPI3_MISO -PC12.Mode=Full_Duplex_Master -PC12.Signal=SPI3_MOSI -PC13.GPIOParameters=GPIO_Label -PC13.GPIO_Label=TEMP_ALERT_N -PC13.Locked=true -PC13.Signal=GPIO_Input -PC14-OSC32_IN\ (PC14).Locked=true -PC15-OSC32_OUT\ (PC15).Locked=true PD0.GPIOParameters=GPIO_Label PD0.GPIO_Label=P12V_HSD_DIAG_EN PD0.Locked=true @@ -290,6 +285,24 @@ PD1.GPIOParameters=GPIO_Label PD1.GPIO_Label=MUX_ST PD1.Locked=true PD1.Signal=GPIO_Input +PD10.Locked=true +PD11.Locked=true +PD12.GPIOParameters=GPIO_Label +PD12.GPIO_Label=LPA_EN +PD12.Locked=true +PD12.Signal=GPIO_Output +PD13.GPIOParameters=GPIO_Label +PD13.GPIO_Label=VGA_ATTSEL0 +PD13.Locked=true +PD13.Signal=GPIO_Output +PD14.GPIOParameters=GPIO_Label +PD14.GPIO_Label=VGA_EN +PD14.Locked=true +PD14.Signal=GPIO_Output +PD15.GPIOParameters=GPIO_Label +PD15.GPIO_Label=VGA_ATTSEL1 +PD15.Locked=true +PD15.Signal=GPIO_Output PD2.GPIOParameters=GPIO_Label PD2.GPIO_Label=FAN1_PWR_EN PD2.Locked=true @@ -307,7 +320,7 @@ PD5.GPIO_Label=nFAULT_FAN2 PD5.Locked=true PD5.Signal=GPIO_Input PD6.GPIOParameters=GPIO_Label -PD6.GPIO_Label=P6V_HDS_ONE_DIAG_EN +PD6.GPIO_Label=P6V_HSD_ONE_DIAG_EN PD6.Locked=true PD6.Signal=GPIO_Output PD7.GPIOParameters=GPIO_Label @@ -316,24 +329,6 @@ PD7.Locked=true PD7.Signal=GPIO_Input PD8.Locked=true PD9.Locked=true -PD10.Locked=true -PD11.Locked=true -PD12.GPIOParameters=GPIO_Label -PD12.GPIO_Label=LPA_EN -PD12.Locked=true -PD12.Signal=GPIO_Output -PD13.GPIOParameters=GPIO_Label -PD13.GPIO_Label=VGA_ATTSEL0 -PD13.Locked=true -PD13.Signal=GPIO_Output -PD14.GPIOParameters=GPIO_Label -PD14.GPIO_Label=VGA_EN -PD14.Locked=true -PD14.Signal=GPIO_Output -PD15.GPIOParameters=GPIO_Label -PD15.GPIO_Label=VGA_ATTSEL1 -PD15.Locked=true -PD15.Signal=GPIO_Output PE0.GPIOParameters=GPIO_Label PE0.GPIO_Label=GEN_EN PE0.Locked=true @@ -342,6 +337,12 @@ PE1.GPIOParameters=GPIO_Label PE1.GPIO_Label=LPA_PWR_EN PE1.Locked=true PE1.Signal=GPIO_Output +PE10.Locked=true +PE11.Locked=true +PE12.Locked=true +PE13.Locked=true +PE14.Locked=true +PE15.Locked=true PE2.GPIOParameters=GPIO_Label PE2.GPIO_Label=VCO_CE PE2.Locked=true @@ -372,12 +373,6 @@ PE8.GPIO_Label=DEBUG1 PE8.Locked=true PE8.Signal=GPIO_Output PE9.Locked=true -PE10.Locked=true -PE11.Locked=true -PE12.Locked=true -PE13.Locked=true -PE14.Locked=true -PE15.Locked=true PF0-OSC_IN\ (PF0).GPIOParameters=GPIO_Label PF0-OSC_IN\ (PF0).GPIO_Label=P6V_SCATTER_PWR_EN PF0-OSC_IN\ (PF0).Locked=true @@ -386,20 +381,6 @@ PF1-OSC_OUT\ (PF1).GPIOParameters=GPIO_Label PF1-OSC_OUT\ (PF1).GPIO_Label=P6V_SCATTER_HSD_DIAG_EN PF1-OSC_OUT\ (PF1).Locked=true PF1-OSC_OUT\ (PF1).Signal=GPIO_Output -PF2-NRST.Locked=true -PF3.Locked=true -PF4.Locked=true -PF5.Locked=true -PF6.Locked=true -PF7.Locked=true -PF8.GPIOParameters=GPIO_Label -PF8.GPIO_Label=P6V_PG -PF8.Locked=true -PF8.Signal=GPIO_Input -PF9.GPIOParameters=GPIO_Label -PF9.GPIO_Label=P6V_HSD_ONE_SEL -PF9.Locked=true -PF9.Signal=GPIO_Output PF10.GPIOParameters=GPIO_Label PF10.GPIO_Label=P6V_HSD_ONE_SEH PF10.Locked=true @@ -417,6 +398,20 @@ PF13.GPIO_Label=P6V_HSD_TWO_DIAG_EN PF13.Locked=true PF13.PinState=GPIO_PIN_RESET PF13.Signal=GPIO_Output +PF2-NRST.Locked=true +PF3.Locked=true +PF4.Locked=true +PF5.Locked=true +PF6.Locked=true +PF7.Locked=true +PF8.GPIOParameters=GPIO_Label +PF8.GPIO_Label=P6V_PG +PF8.Locked=true +PF8.Signal=GPIO_Input +PF9.GPIOParameters=GPIO_Label +PF9.GPIO_Label=P6V_HSD_ONE_SEL +PF9.Locked=true +PF9.Signal=GPIO_Output PinOutPanel.RotationAngle=0 ProjectManager.AskForMigrate=true ProjectManager.BackupPrevious=false @@ -429,8 +424,8 @@ ProjectManager.DefaultFWLocation=true ProjectManager.DeletePrevious=true ProjectManager.DeviceId=STM32G0B1VETx ProjectManager.FirmwarePackage=STM32Cube FW_G0 V1.6.3 -ProjectManager.FreePinsContext= ProjectManager.FreePins=false +ProjectManager.FreePinsContext= ProjectManager.HalAssertFull=false ProjectManager.HeapSize=0x200 ProjectManager.KeepUserCode=true @@ -450,7 +445,7 @@ ProjectManager.ToolChainLocation= ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=true -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USB_Device_Init-USB_DEVICE-false-HAL-false,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_DAC1_Init-DAC1-false-HAL-true,6-MX_SPI2_Init-SPI2-false-HAL-true,7-MX_SPI3_Init-SPI3-false-HAL-true,8-MX_USART1_UART_Init-USART1-false-HAL-true,9-MX_TIM2_Init-TIM2-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USB_Device_Init-USB_DEVICE-false-HAL-false,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_DAC1_Init-DAC1-false-HAL-true,6-MX_SPI2_Init-SPI2-false-HAL-true,7-MX_SPI3_Init-SPI3-false-HAL-true,8-MX_TIM2_Init-TIM2-false-HAL-true RCC.AHBFreq_Value=16000000 RCC.APBFreq_Value=16000000 RCC.APBTimFreq_Value=16000000 @@ -483,8 +478,8 @@ RCC.PLLQoutputFreq_Value=64000000 RCC.PLLRCLKFreq_Value=64000000 RCC.PWRFreq_Value=16000000 RCC.SYSCLKFreq_VALUE=16000000 -RCC.TIM1Freq_Value=16000000 RCC.TIM15Freq_Value=16000000 +RCC.TIM1Freq_Value=16000000 RCC.USART1Freq_Value=16000000 RCC.USART2Freq_Value=16000000 RCC.USART3Freq_Value=16000000 @@ -515,12 +510,10 @@ TIM2.IPParameters=Prescaler,Period,AutoReloadPreload,Channel-PWM Generation4 CH4 TIM2.OCPolarity_4=TIM_OCPOLARITY_LOW TIM2.Period=999 TIM2.Prescaler=16 -USART1.IPParameters=VirtualMode-Asynchronous -USART1.VirtualMode-Asynchronous=VM_ASYNC USB_DEVICE.CLASS_NAME_FS=CDC USB_DEVICE.IPParameters=VirtualMode,VirtualModeFS,CLASS_NAME_FS -USB_DEVICE.VirtualModeFS=Cdc_FS USB_DEVICE.VirtualMode=Cdc +USB_DEVICE.VirtualModeFS=Cdc_FS VP_FREERTOS_VS_CMSIS_V1.Mode=CMSIS_V1 VP_FREERTOS_VS_CMSIS_V1.Signal=FREERTOS_VS_CMSIS_V1 VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals @@ -533,4 +526,3 @@ VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Mode=CDC_FS VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Signal=USB_DEVICE_VS_USB_DEVICE_CDC_FS board=custom rtos.0.ip=FREERTOS -#MicroXplorer Configuration settings - do not modify diff --git a/boards/motherboard/platformio.ini b/boards/motherboard/platformio.ini index e309d7e..4c773a2 100644 --- a/boards/motherboard/platformio.ini +++ b/boards/motherboard/platformio.ini @@ -14,6 +14,7 @@ build_src_filter = + + + + - # FreeRTOS + @@ -21,10 +22,13 @@ build_flags = -IInc -Ilib -DUSE_HAL_DRIVER - -DSTM32G0B1xx + -DSTM32G0B1xxl -std=c++17 -Wunused-function # FreeRTOS -I Middlewares/Third_Party/FreeRTOS/Source/include -I Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM0 -I Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS + +upload_protocol = dfu +upload_command = dfu-util -a 0 --dfuse-address 0x08000000:leave -D $SOURCE diff --git a/boards/motherboard/src/carrier/carrier.cpp b/boards/motherboard/src/carrier/carrier.cpp new file mode 100644 index 0000000..3edd73e --- /dev/null +++ b/boards/motherboard/src/carrier/carrier.cpp @@ -0,0 +1,76 @@ +#include "carrier.hpp" + +#include "lib/adf5355/adf5355.hpp" +#include "lib/periph/spi.hpp" + +#include "Src/power/power.hpp" + +// CubeMX +#include "adc.h" +#include "spi.h" + +namespace { + +static amber::periph::DigitalOutput lpaEn(*LPA_EN_GPIO_Port, LPA_EN_Pin); +static amber::periph::DigitalOutput vcoCe(*VCO_CE_GPIO_Port, VCO_CE_Pin); +static amber::periph::DigitalInput vcoMuxOut(*VCO_MUXOUT_GPIO_Port, VCO_MUXOUT_Pin); +static amber::periph::AnalogInput lpaPowerDetect(hadc1, ADC_CHANNEL_7); + +static bool vcoLocked = false; +static bool powerOffRequested = false; + +auto ADF5355Config() -> amber::adf5355::Driver::InitParam& { + static amber::adf5355::Driver::InitParam cfg{}; + return cfg; +} + +auto ADF5355() -> amber::adf5355::Driver& { + static amber::periph::DigitalOutput vcoLe(*VCO_LE_GPIO_Port, VCO_LE_Pin); + static amber::periph::Spi spi2(hspi2, vcoLe); + static amber::adf5355::Driver drv(spi2, ADF5355Config()); + return drv; +} + +} // namespace + +namespace carrier { + +auto Init() noexcept -> void { + if (power::GetPowerMuxState() == power::PowerMuxState::USB_POWER) { + lpaEn.SetLow(); + vcoCe.SetLow(); + } + + lpaEn.SetHigh(); + vcoCe.SetHigh(); + + HAL_Delay(10); + + ADF5355().setup(); +}; + +auto Update_100hz() noexcept -> void { + vcoLocked = vcoMuxOut.Read(); + + if (power::GetPowerMuxState() == power::PowerMuxState::USB_POWER) { + lpaEn.SetLow(); + vcoCe.SetLow(); + return; + } + + if (pwr_down_flag) { + vcoCe.SetLow(); + powerOffRequested = true; + return; + } +}; + +auto GetVcoLocked() noexcept -> bool { + return vcoLocked; +}; + +auto GetPowerDown() noexcept -> bool { + return powerOffRequested; +}; + +} // namespace carrier diff --git a/boards/motherboard/src/carrier/carrier.hpp b/boards/motherboard/src/carrier/carrier.hpp new file mode 100644 index 0000000..faf2f73 --- /dev/null +++ b/boards/motherboard/src/carrier/carrier.hpp @@ -0,0 +1,10 @@ +#pragma once + +namespace carrier { + +auto Init() noexcept -> void; +auto Update_100hz() noexcept -> void; +auto GetVcoLocked() noexcept -> bool; +auto GetPowerDown() noexcept -> bool; + +} // namespace carrier diff --git a/boards/motherboard/src/gpio.c b/boards/motherboard/src/gpio.c index 8ce1610..5a1f99c 100644 --- a/boards/motherboard/src/gpio.c +++ b/boards/motherboard/src/gpio.c @@ -85,8 +85,10 @@ void MX_GPIO_Init(void) { GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); - /*Configure GPIO pins : TEMP_ALERT_N_Pin P5V_VSENSE_Pin P12V_VSENSE_Pin */ - GPIO_InitStruct.Pin = TEMP_ALERT_N_Pin | P5V_VSENSE_Pin | P12V_VSENSE_Pin; + /*Configure GPIO pins : TEMP_ALERT_N_Pin COMPARATOR_Pin P5V_VSENSE_Pin + * P12V_VSENSE_Pin */ + GPIO_InitStruct.Pin = + TEMP_ALERT_N_Pin | COMPARATOR_Pin | P5V_VSENSE_Pin | P12V_VSENSE_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); diff --git a/boards/motherboard/src/main.c b/boards/motherboard/src/main.c index 9924a8c..4bf23fd 100644 --- a/boards/motherboard/src/main.c +++ b/boards/motherboard/src/main.c @@ -25,7 +25,6 @@ #include "gpio.h" #include "spi.h" #include "tim.h" -#include "usart.h" #include "usb_device.h" /* Private includes ----------------------------------------------------------*/ @@ -98,9 +97,9 @@ int main(void) { MX_DAC1_Init(); MX_SPI2_Init(); MX_SPI3_Init(); - MX_USART1_UART_Init(); MX_TIM2_Init(); /* USER CODE BEGIN 2 */ + /* USER CODE END 2 */ /* Call init function for freertos objects (in cmsis_os2.c) */ diff --git a/boards/motherboard/src/power/power.cpp b/boards/motherboard/src/power/power.cpp new file mode 100644 index 0000000..9e84534 --- /dev/null +++ b/boards/motherboard/src/power/power.cpp @@ -0,0 +1,184 @@ +#include "power.hpp" + +#include "Src/carrier/carrier.hpp" + +// CubeMX +#include "adc.h" +#include "gpio.h" + +namespace { + +static amber::periph::DigitalInput powerMux(*MUX_ST_GPIO_Port, MUX_ST_Pin); + +static uint8_t hsd1CsIdx = 0; +static uint8_t hsd2CsIdx = 0; + +static std::array hsd1Currents{}; +static std::array hsd2Currents{}; +static float scatterCurrent = 0.0f; +static float p12vCurrent = 0.0f; + +static power::PowerMuxState powerMuxState = power::PowerMuxState::USB_POWER; + +auto P6VHsd1Config() -> amber::tps274160b::Config& { + static amber::periph::DigitalOutput en0(*VCO_PWR_EN_GPIO_Port, VCO_PWR_EN_Pin); + static amber::periph::DigitalOutput en3(*VGA_PWR_EN_GPIO_Port, VGA_PWR_EN_Pin); + + static amber::periph::DigitalOutput diagSel0(*P6V_HSD_ONE_SEL_GPIO_Port, P6V_HSD_ONE_SEL_Pin); + static amber::periph::DigitalOutput diagSel1(*P6V_HSD_ONE_SEH_GPIO_Port, P6V_HSD_ONE_SEH_Pin); + + static amber::periph::DigitalInput fault(*P6V_HSD_ONE_nFAULT_GPIO_Port, P6V_HSD_ONE_nFAULT_Pin); + static amber::periph::DigitalOutput diagEn(*P6V_HDS_ONE_DIAG_EN_GPIO_Port, P6V_HDS_ONE_DIAG_EN_Pin); + static amber::periph::AnalogInput currentSense(hadc1, ADC_CHANNEL_10); + + static amber::tps274160b::Config cfg{ + .currentSenseResistor = 1800, + .enablePins = {en0, en0, en3, en3}, + .diagSelect = {diagSel0, diagSel1}, + .fault = fault, + .diagEn = diagEn, + .currentSense = currentSense, + }; + + return cfg; +} + +auto P6VHsd2Config() -> amber::tps274160b::Config& { + static amber::periph::DigitalOutput en0(*GEN_EN_GPIO_Port, GEN_EN_Pin); + static amber::periph::DigitalOutput en1(*VGA_PWR_EN_GPIO_Port, VGA_PWR_EN_Pin); + static amber::periph::DigitalOutput en2(*LPA_PWR_EN_GPIO_Port, LPA_PWR_EN_Pin); + static amber::periph::DigitalOutput en3(*VCO_PWR_EN_GPIO_Port, VCO_PWR_EN_Pin); + + static amber::periph::DigitalOutput diagSel0(*P6V_HSD_TWO_SEL_GPIO_Port, P6V_HSD_TWO_SEL_Pin); + static amber::periph::DigitalOutput diagSel1(*P6V_HSD_TWO_SEH_GPIO_Port, P6V_HSD_TWO_SEH_Pin); + + static amber::periph::DigitalInput fault(*P6V_HSD_TWO_nFAULT_GPIO_Port, P6V_HSD_TWO_nFAULT_Pin); + static amber::periph::DigitalOutput diagEn(*P6V_HSD_TWO_DIAG_EN_GPIO_Port, P6V_HSD_TWO_DIAG_EN_Pin); + static amber::periph::AnalogInput currentSense(hadc1, ADC_CHANNEL_9); + + static amber::tps274160b::Config cfg{ + .currentSenseResistor = 597, + .enablePins = {en0, en1, en2, en3}, + .diagSelect = {diagSel0, diagSel1}, + .fault = fault, + .diagEn = diagEn, + .currentSense = currentSense, + }; + + return cfg; +} + +auto P6VScatterConfig() -> amber::tps1h100::Config& { + static amber::periph::DigitalOutput en(*P6V_SCATTER_PWR_EN_GPIO_Port, P6V_SCATTER_PWR_EN_Pin); + static amber::periph::DigitalOutput diagEn(*P6V_SCATTER_HSD_DIAG_EN_GPIO_Port, P6V_SCATTER_HSD_DIAG_EN_Pin); + static amber::periph::AnalogInput currentSense(hadc1, ADC_CHANNEL_4); + + static amber::tps1h100::Config cfg{ + .currentSenseResistor = 750, + .enablePin = &en, + .diagEn = diagEn, + .currentSense = currentSense, + }; + + return cfg; +} + +auto P12VHsdConfig() -> amber::tps1h100::Config& { + static amber::periph::DigitalOutput diagEn(*P12V_HSD_DIAG_EN_GPIO_Port, P12V_HSD_DIAG_EN_Pin); + static amber::periph::AnalogInput currentSense(hadc1, ADC_CHANNEL_11); + + static amber::tps1h100::Config cfg{750, nullptr, diagEn, currentSense}; + + return cfg; +} + +auto P6VHsd1() -> amber::tps274160b::Driver& { + static amber::tps274160b::Driver drv(P6VHsd1Config()); + return drv; +} + +auto P6VHsd2() -> amber::tps274160b::Driver& { + static amber::tps274160b::Driver drv(P6VHsd2Config()); + return drv; +} + +auto P6VScatter() -> amber::tps1h100::Driver& { + static amber::tps1h100::Driver drv(P6VScatterConfig()); + return drv; +} + +// P12V is a current-sense only HSD, not software controllable +auto P12VHsd() -> amber::tps1h100::Driver& { + static amber::tps1h100::Driver drv(P12VHsdConfig()); + return drv; +} + +} // namespace + +namespace power { + +auto Init() noexcept -> void { + if (GetPowerMuxState() == PowerMuxState::USB_POWER) { + P6VHsd1().disableAll(); + P6VHsd2().disableAll(); + P6VScatter().disable(); + return; + } + + P6VHsd1().enableAll(); + P6VHsd2().enableAll(); + P6VScatter().enable(); + + P6VHsd1().diagEnable(true); + P6VHsd2().diagEnable(true); + P6VScatter().diagEnable(true); + P12VHsd().diagEnable(true); +} + +auto Update_100hz() noexcept -> void { + powerMuxState = powerMux.Read() ? PowerMuxState::BARREL_JACK : PowerMuxState::USB_POWER; + + if (GetPowerMuxState() == PowerMuxState::USB_POWER || carrier::GetPowerDown()) { + P6VHsd1().disableAll(); + P6VHsd2().disableAll(); + P6VScatter().disable(); + return; + } + + P6VHsd1().enableAll(); + P6VHsd2().enableAll(); + P6VScatter().enable(); + + P6VHsd1().selectDiagPin(hsd1CsIdx); + P6VHsd2().selectDiagPin(hsd2CsIdx); + + hsd1Currents[hsd1CsIdx] = P6VHsd1().getCurrent(); + hsd2Currents[hsd2CsIdx] = P6VHsd2().getCurrent(); + scatterCurrent = P6VScatter().getCurrent(); + p12vCurrent = P12VHsd().getCurrent(); + + hsd1CsIdx = (hsd1CsIdx + 1) % amber::tps274160b::kNumChannels; + hsd2CsIdx = (hsd2CsIdx + 1) % amber::tps274160b::kNumChannels; +} + +auto GetPowerMuxState() noexcept -> PowerMuxState { + return powerMuxState; +} + +auto GetP6VHsd1Currents() noexcept -> const std::array& { + return hsd1Currents; +} + +auto GetP6VHsd2Currents() noexcept -> const std::array& { + return hsd2Currents; +} + +auto GetP6VScatterCurrent() noexcept -> float { + return scatterCurrent; +} + +auto GetP12VCurrent() noexcept -> float { + return p12vCurrent; +} + +} // namespace power diff --git a/boards/motherboard/src/power/power.hpp b/boards/motherboard/src/power/power.hpp new file mode 100644 index 0000000..7d03646 --- /dev/null +++ b/boards/motherboard/src/power/power.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include +#include + +#include "lib/tps274160b/tps274160b.hpp" +#include "lib/tps1h100/tps1h100.hpp" + +namespace power { + +enum class PowerMuxState : uint8_t { + USB_POWER = 0, + BARREL_JACK = 1, +}; + +auto Init() noexcept -> void; +auto Update_100hz() noexcept -> void; + +auto GetPowerMuxState() noexcept -> PowerMuxState; +auto GetP6VHsd1Currents() noexcept -> const std::array&; +auto GetP6VHsd2Currents() noexcept -> const std::array&; +auto GetP6VScatterCurrent() noexcept -> float; +auto GetP12VCurrent() noexcept -> float; + +} // namespace power diff --git a/boards/motherboard/src/serial/serial.cpp b/boards/motherboard/src/serial/serial.cpp new file mode 100644 index 0000000..f9391f6 --- /dev/null +++ b/boards/motherboard/src/serial/serial.cpp @@ -0,0 +1,30 @@ +// #include "serial.hpp" + +// #include "cobs.hpp" + +// #include "usbd_cdc_if.h" +// #include "usbd_core.h" + +// #include "main.h" + + +// namespace serial { + +// extern "C" { +// extern USBD_HandleTypeDef hUsbDeviceFS; +// } + +// // RX State +// static uint32_t rx_counter = 0; +// constexpr uint32_t RX_BUF_SIZE = 1024; +// static uint8_t rx_buffer[RX_BUF_SIZE]; +// static uint16_t rx_buf_start = 0; +// static volatile uint16_t rx_buf_end = 0; + +// static amber::cobs::Decoder<1024> rx_decoder; + +// static uint8_t tx_counter = 0; +// static uint8_t pb_buffer[SENSOR_STATUS_SIZE]; +// static uint8_t cobs_buffer[amber::cobs::MaxEncodedLength(SENSOR_STATUS_SIZE)]; + +// } // namespace serial \ No newline at end of file diff --git a/boards/motherboard/src/serial/serial.hpp b/boards/motherboard/src/serial/serial.hpp new file mode 100644 index 0000000..8afc3c0 --- /dev/null +++ b/boards/motherboard/src/serial/serial.hpp @@ -0,0 +1,17 @@ +// #pragma once + +// // #include "motherboard.pb.h" + +// namespace serial { + +// void Init(void); +// void Receive(void); + +// void Update_10hz(void); +// void Update_100hz(void); + +// extern "C" { +// void SerialReceiveBytes(uint8_t* bytes, uint32_t len); +// } + +// } // namespace serial diff --git a/boards/motherboard/src/tasks.cpp b/boards/motherboard/src/tasks.cpp index 5a2928f..3266d7f 100644 --- a/boards/motherboard/src/tasks.cpp +++ b/boards/motherboard/src/tasks.cpp @@ -1,7 +1,13 @@ #include "tasks.hpp" #include "FreeRTOS.h" +#include "dac.h" + +#include "power/power.hpp" +#include "carrier/carrier.hpp" #include "lib/adf5355/adf5355.hpp" +#include "lib/periph/analog_output.hpp" +#include "lib/periph/analog_input.hpp" #include "lib/periph/digital.hpp" #include "lib/periph/pwm.hpp" #include "lib/periph/spi.hpp" @@ -9,9 +15,8 @@ #include "spi.h" #include "task.h" #include "tim.h" - -// the current state of this file is for lab -// testing - it will be severly refactored soon +#include "dac.h" +#include "adc.h" enum { PRIORITY_1HZ = 1, @@ -22,108 +27,88 @@ enum { static const size_t STACK_SIZE_WORDS = 512; +StaticTask_t t1000hz_ctrl; +StackType_t t1000hz_stack[STACK_SIZE_WORDS]; + StaticTask_t t100hz_ctrl; StackType_t t100hz_stack[STACK_SIZE_WORDS]; StaticTask_t t1hz_ctrl; StackType_t t1hz_stack[STACK_SIZE_WORDS]; -auto task_100hz(void* argument) -> void { +auto task_1000hz(void* argument) -> void { (void)argument; TickType_t wake_time = xTaskGetTickCount(); - // GPIOs - amber::periph::DigitalOutput vco_pwr_en(*VCO_PWR_EN_GPIO_Port, - VCO_PWR_EN_Pin); - amber::periph::DigitalOutput gen_en(*GEN_EN_GPIO_Port, GEN_EN_Pin); - amber::periph::DigitalOutput vga_pwr_en(*VGA_PWR_EN_GPIO_Port, - VGA_PWR_EN_Pin); - amber::periph::DigitalOutput lpa_pwr_en(*LPA_PWR_EN_GPIO_Port, - LPA_PWR_EN_Pin); - amber::periph::DigitalOutput p6v_scatter_pwr_en( - *P6V_SCATTER_PWR_EN_GPIO_Port, P6V_SCATTER_PWR_EN_Pin); - amber::periph::DigitalOutput lpa_en(*LPA_EN_GPIO_Port, LPA_EN_Pin); - amber::periph::DigitalOutput lna_en(*LNA_EN_GPIO_Port, LNA_EN_Pin); - amber::periph::DigitalOutput p6v_scatter_hsd_diag_en( - *P6V_SCATTER_HSD_DIAG_EN_GPIO_Port, P6V_SCATTER_HSD_DIAG_EN_Pin); - amber::periph::DigitalOutput logamp_en(*LOGAMP_EN_GPIO_Port, LOGAMP_EN_Pin); - amber::periph::DigitalOutput fan2_pwr_en(*FAN2_PWR_EN_GPIO_Port, - FAN2_PWR_EN_Pin); - amber::periph::DigitalOutput fan1_pwr_en(*FAN1_PWR_EN_GPIO_Port, - FAN1_PWR_EN_Pin); - amber::periph::DigitalOutput fan1_pwm(*FAN1_PWN_GPIO_Port, FAN1_PWN_Pin); - amber::periph::DigitalOutput warn_light(*WARN_LIGHT_GPIO_Port, - WARN_LIGHT_Pin); - amber::periph::DigitalOutput vco_le(*VCO_LE_GPIO_Port, VCO_LE_Pin); - - amber::periph::Spi spi2(hspi2, vco_le); - amber::periph::Pwm fan2_pwm(htim2, TIM_CHANNEL_4); - - // initialize the ADF5355 - amber::adf5355::Driver::InitParam param{}; - param.freq_req = 5725000000ULL; - param.clkin_freq = 100000000UL; - amber::adf5355::Driver adf(spi2, param); - adf.setup(); - - fan2_pwm.Start(); - fan2_pwm.SetDutyCycle(100.0f); - - vco_pwr_en.SetHigh(); - gen_en.SetHigh(); - vga_pwr_en.SetHigh(); - lpa_pwr_en.SetHigh(); - p6v_scatter_pwr_en.SetHigh(); - lpa_en.SetHigh(); - lna_en.SetHigh(); - p6v_scatter_hsd_diag_en.SetHigh(); - logamp_en.SetHigh(); - fan2_pwr_en.SetHigh(); - fan1_pwr_en.SetHigh(); - fan1_pwm.SetHigh(); - warn_light.SetHigh(); + // amber::periph::DigitalInput comparator(*COMPARATOR_GPIO_Port, COMPARATOR_Pin); + // amber::periph::AnalogOutput logv(hdac1, DAC1_CHANNEL_2); + // amber::periph::AnalogInput read(hadc1, ADC_CHANNEL_0); + // amber::periph::DigitalOutput debug2(*DEBUG2_GPIO_Port, DEBUG2_Pin); + + // // --- Configuration --- + // constexpr uint32_t TASK_HZ = 1000; + // constexpr float DECAY_RATE = 0.001f; // volts lost per tick — tune this + // constexpr float PEAK_FLOOR = 0.0f; // minimum peak hold value + + // float peak_hold = 0.0f; + + // logv.SetVoltage(0.95f); while (true) { - if (pwr_down_flag) { - vco_pwr_en.SetLow(); - gen_en.SetLow(); - vga_pwr_en.SetLow(); - lpa_pwr_en.SetLow(); - p6v_scatter_pwr_en.SetLow(); - lpa_en.SetLow(); - lna_en.SetLow(); - p6v_scatter_hsd_diag_en.SetLow(); - logamp_en.SetLow(); - fan2_pwr_en.SetLow(); - fan1_pwr_en.SetLow(); - fan1_pwm.SetLow(); - warn_light.SetLow(); - - warn_light.SetLow(); - break; - } + vTaskDelayUntil(&wake_time, pdMS_TO_TICKS(1)); + + // float new_sample = read.ReadVoltage(); + + // // Latch any new peak immediately + // if (new_sample > peak_hold) { + // peak_hold = new_sample; + // } else { + // // Slowly decay when no new peak + // peak_hold = std::max(peak_hold - DECAY_RATE, PEAK_FLOOR); + // } + + // debug2.Set(comparator.Read()); + } +} + +auto task_100hz(void* argument) -> void { + (void)argument; + TickType_t wake_time = xTaskGetTickCount(); + + while (true) { + power::Update_100hz(); + carrier::Update_100hz(); vTaskDelayUntil(&wake_time, pdMS_TO_TICKS(10)); } }; auto task_1hz(void* argument) -> void { + (void)argument; + TickType_t wake_time = xTaskGetTickCount(); + amber::periph::DigitalOutput debug1(*DEBUG1_GPIO_Port, DEBUG1_Pin); while (true) { debug1.Toggle(); - vTaskDelay(pdMS_TO_TICKS(1000)); + vTaskDelayUntil(&wake_time, pdMS_TO_TICKS(1000)); } }; auto MX_FREERTOS_Init() -> void { + power::Init(); + carrier::Init(); + xTaskCreateStatic(task_1hz, "1Hz", STACK_SIZE_WORDS, NULL, PRIORITY_1HZ, t1hz_stack, &t1hz_ctrl); xTaskCreateStatic(task_100hz, "100Hz", STACK_SIZE_WORDS, NULL, PRIORITY_100HZ, t100hz_stack, &t100hz_ctrl); + xTaskCreateStatic(task_1000hz, "1000Hz", STACK_SIZE_WORDS, NULL, + PRIORITY_1000HZ, t1000hz_stack, &t1000hz_ctrl); + vTaskStartScheduler(); } diff --git a/boards/motherboard/src/thermal/thermal.cpp b/boards/motherboard/src/thermal/thermal.cpp new file mode 100644 index 0000000..0e93874 --- /dev/null +++ b/boards/motherboard/src/thermal/thermal.cpp @@ -0,0 +1,7 @@ +#include "thermal.hpp" + +namespace thermal { + + + +} // namespace thermal \ No newline at end of file diff --git a/boards/motherboard/src/thermal/thermal.hpp b/boards/motherboard/src/thermal/thermal.hpp new file mode 100644 index 0000000..e2fa362 --- /dev/null +++ b/boards/motherboard/src/thermal/thermal.hpp @@ -0,0 +1,8 @@ +#pragma once + +namespace thermal { + +auto Init() noexcept -> void; +auto Update10Hz() noexcept -> void; + +} // namespace thermal \ No newline at end of file diff --git a/boards/motherboard/src/usart.c b/boards/motherboard/src/usart.c deleted file mode 100644 index 97b9640..0000000 --- a/boards/motherboard/src/usart.c +++ /dev/null @@ -1,128 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file usart.c - * @brief This file provides code for the configuration - * of the USART instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2026 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Includes ------------------------------------------------------------------*/ -#include "usart.h" - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -UART_HandleTypeDef huart1; - -/* USART1 init function */ - -void MX_USART1_UART_Init(void) { - /* USER CODE BEGIN USART1_Init 0 */ - - /* USER CODE END USART1_Init 0 */ - - /* USER CODE BEGIN USART1_Init 1 */ - - /* USER CODE END USART1_Init 1 */ - huart1.Instance = USART1; - huart1.Init.BaudRate = 115200; - huart1.Init.WordLength = UART_WORDLENGTH_8B; - huart1.Init.StopBits = UART_STOPBITS_1; - huart1.Init.Parity = UART_PARITY_NONE; - huart1.Init.Mode = UART_MODE_TX_RX; - huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - huart1.Init.OverSampling = UART_OVERSAMPLING_16; - huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; - huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&huart1) != HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != - HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != - HAL_OK) { - Error_Handler(); - } - if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK) { - Error_Handler(); - } - /* USER CODE BEGIN USART1_Init 2 */ - - /* USER CODE END USART1_Init 2 */ -} - -void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; - if (uartHandle->Instance == USART1) { - /* USER CODE BEGIN USART1_MspInit 0 */ - - /* USER CODE END USART1_MspInit 0 */ - - /** Initializes the peripherals clocks - */ - PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1; - PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; - if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { - Error_Handler(); - } - - /* USART1 clock enable */ - __HAL_RCC_USART1_CLK_ENABLE(); - - __HAL_RCC_GPIOC_CLK_ENABLE(); - /**USART1 GPIO Configuration - PC4 ------> USART1_TX - PC5 ------> USART1_RX - */ - GPIO_InitStruct.Pin = COMM_TX_Pin | COMM_RX_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStruct.Alternate = GPIO_AF1_USART1; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /* USER CODE BEGIN USART1_MspInit 1 */ - - /* USER CODE END USART1_MspInit 1 */ - } -} - -void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { - if (uartHandle->Instance == USART1) { - /* USER CODE BEGIN USART1_MspDeInit 0 */ - - /* USER CODE END USART1_MspDeInit 0 */ - /* Peripheral clock disable */ - __HAL_RCC_USART1_CLK_DISABLE(); - - /**USART1 GPIO Configuration - PC4 ------> USART1_TX - PC5 ------> USART1_RX - */ - HAL_GPIO_DeInit(GPIOC, COMM_TX_Pin | COMM_RX_Pin); - - /* USER CODE BEGIN USART1_MspDeInit 1 */ - - /* USER CODE END USART1_MspDeInit 1 */ - } -} - -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ diff --git a/lib/adf5355/adf5355.hpp b/lib/adf5355/adf5355.hpp index 9b286d5..43f797d 100644 --- a/lib/adf5355/adf5355.hpp +++ b/lib/adf5355/adf5355.hpp @@ -225,4 +225,4 @@ struct Driver { auto set_freq(uint64_t freq, uint8_t chan) noexcept -> int32_t; }; -} // namespace amber::devices +} // namespace amber::adf5355 diff --git a/lib/adl6331/adl6331.cpp b/lib/adl6331/adl6331.cpp index 03c1c5e..af6697e 100644 --- a/lib/adl6331/adl6331.cpp +++ b/lib/adl6331/adl6331.cpp @@ -1,6 +1,6 @@ #include "adl6331.hpp" -namespace amber::adl6331 { +namespace amber::driver::adl6331 { Driver::Driver(periph::Spi& spi, const Config& config) : _spi(spi), _config(config) {} diff --git a/lib/adl6331/adl6331.hpp b/lib/adl6331/adl6331.hpp index 524e6c0..57c66f4 100644 --- a/lib/adl6331/adl6331.hpp +++ b/lib/adl6331/adl6331.hpp @@ -77,11 +77,12 @@ typedef struct { bool amp2_en {true}; bool dsa_en {true}; - std::array states = { + std::array states = {{ {AmpMode::BYPASS, AmpMode::BYPASS, 24}, {AmpMode::FIXED_GAIN, AmpMode::FIXED_GAIN, 16}, {AmpMode::FIXED_GAIN, AmpMode::FIXED_GAIN, 8}, - {AmpMode::FIXED_GAIN, AmpMode::FIXED_GAIN, 0}}; + {AmpMode::FIXED_GAIN, AmpMode::FIXED_GAIN, 0} + }}; } Config; struct Driver { diff --git a/lib/cc1101/cc1101.cpp b/lib/cc1101/cc1101.cpp index 2185078..27d0f50 100644 --- a/lib/cc1101/cc1101.cpp +++ b/lib/cc1101/cc1101.cpp @@ -1,6 +1,6 @@ #include "cc1101.hpp" -namespace cc1101 { +namespace amber::cc1101 { Driver::Driver( const SPIClass& spi, @@ -102,4 +102,4 @@ auto Driver::begin(const Direction dir) noexcept -> void { delay(10); }; -} // namespace cc1101 +} // namespace amber::cc1101 diff --git a/lib/cc1101/cc1101.hpp b/lib/cc1101/cc1101.hpp index a62d8ec..7db1918 100644 --- a/lib/cc1101/cc1101.hpp +++ b/lib/cc1101/cc1101.hpp @@ -3,7 +3,7 @@ #include #include "digital.hpp" -namespace cc1101 { +namespace amber::cc1101 { namespace { @@ -61,4 +61,4 @@ struct Driver { pin::DigitalOutput& _cs; }; -} // namespace cc1101 +} // namespace amber::cc1101 diff --git a/lib/periph/analog_input.hpp b/lib/periph/analog_input.hpp index 80c7a7c..711b679 100644 --- a/lib/periph/analog_input.hpp +++ b/lib/periph/analog_input.hpp @@ -47,8 +47,7 @@ struct AnalogInput { ADC_ChannelConfTypeDef adcConfig = { .Channel = _adcChannel, .Rank = ADC_REGULAR_RANK_1, - .SamplingTime = ADC_SAMPLETIME_28CYCLES - .Offset = 0 + .SamplingTime = ADC_SAMPLETIME_19CYCLES_5, }; HAL_ADC_ConfigChannel(&_hadc, &adcConfig); diff --git a/lib/periph/analog_output.hpp b/lib/periph/analog_output.hpp index 4fc151a..2428f2f 100644 --- a/lib/periph/analog_output.hpp +++ b/lib/periph/analog_output.hpp @@ -1,59 +1,64 @@ -/** +/** * @file analog_output.hpp * @author Blake Freer and Ivan Lange * @brief Analog output driver wrapper - * + * * @date 2026-03-22 */ - #pragma once - #include #include #ifdef STM32F7 #include "stm32f7xx_hal.h" -#elif STM32G0 +#elif defined(STM32G0) #include "stm32g0xx_hal.h" - #endif #ifdef HAL_DAC_MODULE_ENABLED namespace amber::periph { +enum class DacResolution : uint8_t { + Bits8 = 8, + Bits12 = 12, +}; + struct AnalogOutput { - AnalogOutput(DAC_HandleTypeDef& hdac, uint32_t channel, float systemVoltage = 3.3f) + AnalogOutput(DAC_HandleTypeDef& hdac, + uint32_t channel, + DacResolution resolution = DacResolution::Bits12, + float systemVoltage = 3.3f) : _hdac(hdac), _channel(channel), - _systemVoltage(systemVoltage) {}; + _resolution(resolution), + _systemVoltage(systemVoltage) {} ~AnalogOutput() = default; auto SetVoltage(float voltage) noexcept -> void { HAL_DAC_Start(&_hdac, _channel); - uint32_t dacValue = std::clamp( - (voltage / _systemVoltage) * GetResolution(), 0, GetResolution() + const uint32_t maxCount = GetMaxCount(); + const uint32_t dacValue = static_cast( + std::clamp(voltage / _systemVoltage, 0.0f, 1.0f) * maxCount ); - HAL_DAC_SetValue(&_hdac, _channel, DAC_ALIGN_12B_R, dacValue); + const uint32_t align = (_resolution == DacResolution::Bits8) + ? DAC_ALIGN_8B_R + : DAC_ALIGN_12B_R; + + HAL_DAC_SetValue(&_hdac, _channel, align, dacValue); } private: DAC_HandleTypeDef& _hdac; - uint32_t _channel; - const float _systemVoltage; - - auto GetResolution() const noexcept -> uint32_t { - switch (DAC_GET_RESOLUTION(&_hdac)) { - case DAC_RESOLUTION_12B: - return 0xFFF; - case DAC_RESOLUTION_8B: - return 0xFF; - default: - return 0xFFF; // Default to 12-bit resolution - } + uint32_t _channel; + DacResolution _resolution; + const float _systemVoltage; + + auto GetMaxCount() const noexcept -> uint32_t { + return (_resolution == DacResolution::Bits8) ? 0xFFu : 0xFFFu; } }; diff --git a/lib/periph/digital.hpp b/lib/periph/digital.hpp index dcff7f2..8b4a3ce 100644 --- a/lib/periph/digital.hpp +++ b/lib/periph/digital.hpp @@ -48,6 +48,9 @@ struct DigitalOutput { auto SetLow() noexcept -> void { HAL_GPIO_WritePin(&_port, _pin, GPIO_PIN_RESET); } + auto Set(bool value) noexcept -> void { + HAL_GPIO_WritePin(&_port, _pin, value ? GPIO_PIN_SET : GPIO_PIN_RESET); + } auto Toggle() noexcept -> void { HAL_GPIO_TogglePin(&_port, _pin); } diff --git a/lib/tps1h100/tps1h100.cpp b/lib/tps1h100/tps1h100.cpp new file mode 100644 index 0000000..854acf6 --- /dev/null +++ b/lib/tps1h100/tps1h100.cpp @@ -0,0 +1,31 @@ +#include "tps1h100.hpp" + +namespace amber::tps1h100 { + +Driver::Driver(const Config& cfg) : _cfg(cfg) {} + +auto Driver::enable() noexcept -> void { + if (_cfg.enablePin == nullptr) { return; } + _cfg.enablePin->SetHigh(); +}; + +auto Driver::disable() noexcept -> void { + if (_cfg.enablePin == nullptr) { return; } + _cfg.enablePin->SetLow(); +}; + +auto Driver::set(bool enable) noexcept -> void { + if (_cfg.enablePin == nullptr) { return; } + _cfg.enablePin->Set(enable); +}; + +auto Driver::diagEnable(bool en) noexcept -> void { + _cfg.diagEn.Set(en); +}; + +auto Driver::getCurrent() const noexcept -> float { + const float voltage = _cfg.currentSense.ReadVoltage(); + return (voltage * kCurrentSenseRatio) / _cfg.currentSenseResistor; +}; + +} // namespace amber::tps1h100 diff --git a/lib/tps1h100/tps1h100.hpp b/lib/tps1h100/tps1h100.hpp new file mode 100644 index 0000000..3ab38db --- /dev/null +++ b/lib/tps1h100/tps1h100.hpp @@ -0,0 +1,43 @@ +/** + * @file tps1h100.hpp + * @author Ivan Lange + * @brief Driver for TPS1H100 4-Channel HSD + * + * @date 2026-04-04 + */ + +#pragma once + +#include "periph/analog_input.hpp" +#include "periph/digital.hpp" + +namespace amber::tps1h100 { + +static constexpr uint16_t kCurrentSenseRatio = 500; + +struct Config { + uint16_t currentSenseResistor; + + amber::periph::DigitalOutput* enablePin; + amber::periph::DigitalOutput& diagEn; + amber::periph::AnalogInput& currentSense; +}; + +struct Driver { + Driver(const Config& cfg); + ~Driver() = default; + + // channel control + auto enable() noexcept -> void; + auto disable() noexcept -> void; + auto set(bool enable) noexcept -> void; + + // diagnostics + auto diagEnable(bool en) noexcept -> void; + auto getCurrent() const noexcept -> float; + +private: + const Config& _cfg; +}; + +} // namespace amber::tps1h100 diff --git a/lib/tps274160b/tps274160b.cpp b/lib/tps274160b/tps274160b.cpp new file mode 100644 index 0000000..486c745 --- /dev/null +++ b/lib/tps274160b/tps274160b.cpp @@ -0,0 +1,54 @@ +#include "tps274160b.hpp" + +namespace amber::tps274160b { + +Driver::Driver(Config& cfg) : _cfg(cfg) {} + +auto Driver::enable(const uint8_t channel) noexcept -> void { + if (channel >= kNumChannels) { return; } + _cfg.enablePins[channel].SetHigh(); +}; + +auto Driver::disable(const uint8_t channel) noexcept -> void { + if (channel >= kNumChannels) { return; } + _cfg.enablePins[channel].SetLow(); +}; + +auto Driver::set(const uint8_t channel, bool enable) noexcept -> void { + if (channel >= kNumChannels) { return; } + _cfg.enablePins[channel].Set(enable); +}; + +auto Driver::enableAll() noexcept -> void { + for (auto& pin : _cfg.enablePins) { + pin.SetHigh(); + } +}; + +auto Driver::disableAll() noexcept -> void { + for (auto& pin : _cfg.enablePins) { + pin.SetLow(); + } +}; + +auto Driver::getFault() const noexcept -> bool { + return _cfg.fault.Read(); +}; + +auto Driver::diagEnable(bool en) noexcept -> void { + _cfg.diagEn.Set(en); +}; + +auto Driver::selectDiagPin(uint8_t pin) noexcept -> void { + if (pin >= kNumDiagPins) { return; } + + _cfg.diagSelect[0U].Set(pin & 0x1); + _cfg.diagSelect[1U].Set((pin >> 1) & 0x1); +} + +auto Driver::getCurrent() const noexcept -> float { + const float voltage = _cfg.currentSense.ReadVoltage(); + return (voltage * kCurrentSenseRatio) / _cfg.currentSenseResistor; +}; + +} // namespace amber::tps274160b diff --git a/lib/tps274160b/tps274160b.hpp b/lib/tps274160b/tps274160b.hpp new file mode 100644 index 0000000..6711b02 --- /dev/null +++ b/lib/tps274160b/tps274160b.hpp @@ -0,0 +1,53 @@ +/** + * @file tps274160.hpp + * @author Ivan Lange + * @brief Driver for TPS274160B 4-Channel HSD + * + * @date 2026-04-04 + */ + +#pragma once + +#include + +#include "periph/analog_input.hpp" +#include "periph/digital.hpp" + +namespace amber::tps274160b { + +static constexpr uint8_t kNumChannels = 4; +static constexpr uint8_t kNumDiagPins = 2; +static constexpr uint16_t kCurrentSenseRatio = 300; + +struct Config { + uint16_t currentSenseResistor; + + std::array enablePins; + std::array diagSelect; + amber::periph::DigitalInput& fault; + amber::periph::DigitalOutput& diagEn; + amber::periph::AnalogInput& currentSense; +}; + +struct Driver { + Driver(Config& cfg); + ~Driver() = default; + + // channel control + auto enable(const uint8_t channel) noexcept -> void; + auto disable(const uint8_t channel) noexcept -> void; + auto set(uint8_t channel, bool enable) noexcept -> void; + auto enableAll() noexcept -> void; + auto disableAll() noexcept -> void; + + // diagnostics + auto getFault() const noexcept -> bool; + auto diagEnable(bool en) noexcept -> void; + auto selectDiagPin(uint8_t pin) noexcept -> void; + auto getCurrent() const noexcept -> float; + +private: + Config& _cfg; +}; + +} // namespace amber::tps274160b From 68bd41002aee9c13fb227c08a06ee3950bdf0f72 Mon Sep 17 00:00:00 2001 From: Ivan Lange Date: Sun, 5 Apr 2026 00:20:40 -0400 Subject: [PATCH 08/13] Basic usb comms working --- boards/motherboard/Inc/main.h | 4 +- boards/motherboard/Inc/stm32g0xx_it.h | 1 + boards/motherboard/lib/macros | 1 + boards/motherboard/lib/tmp126 | 1 + boards/motherboard/motherboard.ioc | 178 +++++++++++---------- boards/motherboard/platformio.ini | 17 ++ boards/motherboard/proto | 1 + boards/motherboard/src/carrier/carrier.cpp | 6 +- boards/motherboard/src/carrier/carrier.hpp | 2 +- boards/motherboard/src/gpio.c | 6 +- boards/motherboard/src/main.c | 2 +- boards/motherboard/src/power/power.cpp | 68 +++++--- boards/motherboard/src/power/power.hpp | 8 +- boards/motherboard/src/serial/serial.cpp | 110 ++++++++++--- boards/motherboard/src/serial/serial.hpp | 21 ++- boards/motherboard/src/spi.c | 2 +- boards/motherboard/src/stm32g0xx_it.c | 14 ++ boards/motherboard/src/tasks.cpp | 61 +++---- boards/motherboard/src/thermal/thermal.cpp | 94 ++++++++++- boards/motherboard/src/thermal/thermal.hpp | 1 + boards/motherboard/src/usbd_cdc_if.c | 43 ++++- boards/motherboard/src/usbd_conf.c | 8 + boards/motherboard/src/usbd_desc.c | 4 +- lib/periph/spi.hpp | 11 ++ lib/tmp126/tmp126.cpp | 111 +++++++++++++ lib/tmp126/tmp126.hpp | 93 +++++++++++ proto/base_station.proto | 14 ++ 27 files changed, 683 insertions(+), 199 deletions(-) create mode 120000 boards/motherboard/lib/macros create mode 120000 boards/motherboard/lib/tmp126 create mode 120000 boards/motherboard/proto create mode 100644 lib/tmp126/tmp126.cpp create mode 100644 lib/tmp126/tmp126.hpp create mode 100644 proto/base_station.proto diff --git a/boards/motherboard/Inc/main.h b/boards/motherboard/Inc/main.h index f96db35..33a7c13 100644 --- a/boards/motherboard/Inc/main.h +++ b/boards/motherboard/Inc/main.h @@ -128,8 +128,8 @@ void Error_Handler(void); #define FAN2_PWR_EN_GPIO_Port GPIOD #define nFAULT_FAN2_Pin GPIO_PIN_5 #define nFAULT_FAN2_GPIO_Port GPIOD -#define P6V_HDS_ONE_DIAG_EN_Pin GPIO_PIN_6 -#define P6V_HDS_ONE_DIAG_EN_GPIO_Port GPIOD +#define P6V_HSD_ONE_DIAG_EN_Pin GPIO_PIN_6 +#define P6V_HSD_ONE_DIAG_EN_GPIO_Port GPIOD #define P6V_HSD_ONE_nFAULT_Pin GPIO_PIN_7 #define P6V_HSD_ONE_nFAULT_GPIO_Port GPIOD #define P6V_HSD_ONE_SEL_Pin GPIO_PIN_9 diff --git a/boards/motherboard/Inc/stm32g0xx_it.h b/boards/motherboard/Inc/stm32g0xx_it.h index 4cc4459..9216c45 100644 --- a/boards/motherboard/Inc/stm32g0xx_it.h +++ b/boards/motherboard/Inc/stm32g0xx_it.h @@ -49,6 +49,7 @@ extern "C" { void NMI_Handler(void); void HardFault_Handler(void); void EXTI0_1_IRQHandler(void); +void USB_UCPD1_2_IRQHandler(void); void TIM1_BRK_UP_TRG_COM_IRQHandler(void); /* USER CODE BEGIN EFP */ diff --git a/boards/motherboard/lib/macros b/boards/motherboard/lib/macros new file mode 120000 index 0000000..72fb3cf --- /dev/null +++ b/boards/motherboard/lib/macros @@ -0,0 +1 @@ +../../../lib/macros \ No newline at end of file diff --git a/boards/motherboard/lib/tmp126 b/boards/motherboard/lib/tmp126 new file mode 120000 index 0000000..08df619 --- /dev/null +++ b/boards/motherboard/lib/tmp126 @@ -0,0 +1 @@ +../../../lib/tmp126 \ No newline at end of file diff --git a/boards/motherboard/motherboard.ioc b/boards/motherboard/motherboard.ioc index cb37567..218b074 100644 --- a/boards/motherboard/motherboard.ioc +++ b/boards/motherboard/motherboard.ioc @@ -1,4 +1,3 @@ -#MicroXplorer Configuration settings - do not modify ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_0 ADC1.IPParameters=Rank-0\#ChannelRegularConversion,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag,master,SelectedChannel ADC1.NbrOfConversionFlag=1 @@ -25,7 +24,6 @@ Mcu.CPN=STM32G0B1VET6 Mcu.Family=STM32G0 Mcu.IP0=ADC1 Mcu.IP1=DAC1 -Mcu.IP10=USB_DRD_FS Mcu.IP2=FREERTOS Mcu.IP3=NVIC Mcu.IP4=RCC @@ -34,11 +32,20 @@ Mcu.IP6=SPI3 Mcu.IP7=SYS Mcu.IP8=TIM2 Mcu.IP9=USB_DEVICE +Mcu.IP10=USB_DRD_FS Mcu.IPNb=11 Mcu.Name=STM32G0B1V(B-C-E)Tx Mcu.Package=LQFP100 Mcu.Pin0=PB9 Mcu.Pin1=PC10 +Mcu.Pin2=PC11 +Mcu.Pin3=PE4 +Mcu.Pin4=PE5 +Mcu.Pin5=PE6 +Mcu.Pin6=PC12 +Mcu.Pin7=PC13 +Mcu.Pin8=PC14-OSC32_IN (PC14) +Mcu.Pin9=PC15-OSC32_OUT (PC15) Mcu.Pin10=PF0-OSC_IN (PF0) Mcu.Pin11=PF1-OSC_OUT (PF1) Mcu.Pin12=PF2-NRST @@ -49,7 +56,6 @@ Mcu.Pin16=PC0 Mcu.Pin17=PC1 Mcu.Pin18=PC2 Mcu.Pin19=PC3 -Mcu.Pin2=PC11 Mcu.Pin20=PA0 Mcu.Pin21=PA1 Mcu.Pin22=PA2 @@ -60,7 +66,6 @@ Mcu.Pin26=PA6 Mcu.Pin27=PA7 Mcu.Pin28=PC5 Mcu.Pin29=PB0 -Mcu.Pin3=PE4 Mcu.Pin30=PB1 Mcu.Pin31=PB2 Mcu.Pin32=PF6 @@ -71,7 +76,6 @@ Mcu.Pin36=PE9 Mcu.Pin37=PE10 Mcu.Pin38=PE11 Mcu.Pin39=PE12 -Mcu.Pin4=PE5 Mcu.Pin40=PE13 Mcu.Pin41=PE14 Mcu.Pin42=PE15 @@ -82,7 +86,6 @@ Mcu.Pin46=PB13 Mcu.Pin47=PB14 Mcu.Pin48=PB15 Mcu.Pin49=PA8 -Mcu.Pin5=PE6 Mcu.Pin50=PA9 Mcu.Pin51=PC6 Mcu.Pin52=PC7 @@ -93,7 +96,6 @@ Mcu.Pin56=PD11 Mcu.Pin57=PD12 Mcu.Pin58=PD13 Mcu.Pin59=PD14 -Mcu.Pin6=PC12 Mcu.Pin60=PD15 Mcu.Pin61=PA10 Mcu.Pin62=PA11 [PA9] @@ -104,7 +106,6 @@ Mcu.Pin66=PA14-BOOT0 Mcu.Pin67=PA15 Mcu.Pin68=PC8 Mcu.Pin69=PC9 -Mcu.Pin7=PC13 Mcu.Pin70=PD0 Mcu.Pin71=PD1 Mcu.Pin72=PD2 @@ -115,7 +116,6 @@ Mcu.Pin76=PD6 Mcu.Pin77=PD7 Mcu.Pin78=PF9 Mcu.Pin79=PF10 -Mcu.Pin8=PC14-OSC32_IN (PC14) Mcu.Pin80=PF11 Mcu.Pin81=PF12 Mcu.Pin82=PF13 @@ -126,7 +126,6 @@ Mcu.Pin86=PE0 Mcu.Pin87=PE1 Mcu.Pin88=PE2 Mcu.Pin89=PE3 -Mcu.Pin9=PC15-OSC32_OUT (PC15) Mcu.Pin90=PB6 Mcu.Pin91=PB7 Mcu.Pin92=PB8 @@ -152,25 +151,15 @@ NVIC.SavedSvcallIrqHandlerGenerated=true NVIC.SavedSystickIrqHandlerGenerated=true NVIC.SysTick_IRQn=true\:3\:0\:false\:false\:false\:true\:false\:true\:false NVIC.TIM1_BRK_UP_TRG_COM_IRQn=true\:3\:0\:false\:false\:true\:false\:false\:true\:true -NVIC.TimeBase=TIM1_BRK_UP_TRG_COM_IRQn NVIC.TimeBaseIP=TIM1 +NVIC.TimeBase=TIM1_BRK_UP_TRG_COM_IRQn +NVIC.USB_UCPD1_2_IRQn=true\:3\:0\:false\:false\:true\:true\:true\:true\:true PA0.GPIOParameters=GPIO_Label PA0.GPIO_Label=LOG_VSENSE PA0.Locked=true PA0.Mode=IN0 PA0.Signal=ADC1_IN0 PA1.Locked=true -PA10.Locked=true -PA11\ [PA9].Mode=Device -PA11\ [PA9].Signal=USB_DM -PA12\ [PA10].Mode=Device -PA12\ [PA10].Signal=USB_DP -PA13.Locked=true -PA14-BOOT0.Locked=true -PA15.GPIOParameters=GPIO_Label -PA15.GPIO_Label=USB_nFAULT -PA15.Locked=true -PA15.Signal=GPIO_Input PA2.Locked=true PA3.Locked=true PA4.GPIOParameters=GPIO_Label @@ -190,6 +179,17 @@ PA9.GPIOParameters=GPIO_Label PA9.GPIO_Label=FAN1_PWN PA9.Locked=true PA9.Signal=GPIO_Output +PA10.Locked=true +PA11\ [PA9].Mode=Device +PA11\ [PA9].Signal=USB_DM +PA12\ [PA10].Mode=Device +PA12\ [PA10].Signal=USB_DP +PA13.Locked=true +PA14-BOOT0.Locked=true +PA15.GPIOParameters=GPIO_Label +PA15.GPIO_Label=USB_nFAULT +PA15.Locked=true +PA15.Signal=GPIO_Input PB0.GPIOParameters=GPIO_Label,GPIO_ModeDefaultEXTI PB0.GPIO_Label=PWR_DOWN PB0.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING @@ -199,16 +199,6 @@ PB1.GPIOParameters=GPIO_Label PB1.GPIO_Label=P6V_CS_TWO PB1.Mode=IN9 PB1.Signal=ADC1_IN9 -PB10.GPIOParameters=GPIO_Label -PB10.GPIO_Label=P12V_CS -PB10.Locked=true -PB10.Mode=IN11 -PB10.Signal=ADC1_IN11 -PB11.Locked=true -PB12.Locked=true -PB13.Locked=true -PB14.Locked=true -PB15.Locked=true PB2.GPIOParameters=GPIO_Label PB2.GPIO_Label=P6V_CS_ONE PB2.Mode=IN10 @@ -236,23 +226,21 @@ PB8.Locked=true PB8.Mode=Simplex_Bidirectional_Master PB8.Signal=SPI2_SCK PB9.Locked=true +PB10.GPIOParameters=GPIO_Label +PB10.GPIO_Label=P12V_CS +PB10.Locked=true +PB10.Mode=IN11 +PB10.Signal=ADC1_IN11 +PB11.Locked=true +PB12.Locked=true +PB13.Locked=true +PB14.Locked=true +PB15.Locked=true PC0.Locked=true PC1.GPIOParameters=GPIO_Label PC1.GPIO_Label=LNA_EN PC1.Locked=true PC1.Signal=GPIO_Output -PC10.Mode=Full_Duplex_Master -PC10.Signal=SPI3_SCK -PC11.Mode=Full_Duplex_Master -PC11.Signal=SPI3_MISO -PC12.Mode=Full_Duplex_Master -PC12.Signal=SPI3_MOSI -PC13.GPIOParameters=GPIO_Label -PC13.GPIO_Label=TEMP_ALERT_N -PC13.Locked=true -PC13.Signal=GPIO_Input -PC14-OSC32_IN\ (PC14).Locked=true -PC15-OSC32_OUT\ (PC15).Locked=true PC2.GPIOParameters=GPIO_Label PC2.GPIO_Label=LOGAMP_EN PC2.Locked=true @@ -277,6 +265,18 @@ PC9.GPIOParameters=GPIO_Label PC9.GPIO_Label=P12V_VSENSE PC9.Locked=true PC9.Signal=GPIO_Input +PC10.Mode=Full_Duplex_Master +PC10.Signal=SPI3_SCK +PC11.Mode=Full_Duplex_Master +PC11.Signal=SPI3_MISO +PC12.Mode=Full_Duplex_Master +PC12.Signal=SPI3_MOSI +PC13.GPIOParameters=GPIO_Label +PC13.GPIO_Label=TEMP_ALERT_N +PC13.Locked=true +PC13.Signal=GPIO_Input +PC14-OSC32_IN\ (PC14).Locked=true +PC15-OSC32_OUT\ (PC15).Locked=true PD0.GPIOParameters=GPIO_Label PD0.GPIO_Label=P12V_HSD_DIAG_EN PD0.Locked=true @@ -285,24 +285,6 @@ PD1.GPIOParameters=GPIO_Label PD1.GPIO_Label=MUX_ST PD1.Locked=true PD1.Signal=GPIO_Input -PD10.Locked=true -PD11.Locked=true -PD12.GPIOParameters=GPIO_Label -PD12.GPIO_Label=LPA_EN -PD12.Locked=true -PD12.Signal=GPIO_Output -PD13.GPIOParameters=GPIO_Label -PD13.GPIO_Label=VGA_ATTSEL0 -PD13.Locked=true -PD13.Signal=GPIO_Output -PD14.GPIOParameters=GPIO_Label -PD14.GPIO_Label=VGA_EN -PD14.Locked=true -PD14.Signal=GPIO_Output -PD15.GPIOParameters=GPIO_Label -PD15.GPIO_Label=VGA_ATTSEL1 -PD15.Locked=true -PD15.Signal=GPIO_Output PD2.GPIOParameters=GPIO_Label PD2.GPIO_Label=FAN1_PWR_EN PD2.Locked=true @@ -329,6 +311,24 @@ PD7.Locked=true PD7.Signal=GPIO_Input PD8.Locked=true PD9.Locked=true +PD10.Locked=true +PD11.Locked=true +PD12.GPIOParameters=GPIO_Label +PD12.GPIO_Label=LPA_EN +PD12.Locked=true +PD12.Signal=GPIO_Output +PD13.GPIOParameters=GPIO_Label +PD13.GPIO_Label=VGA_ATTSEL0 +PD13.Locked=true +PD13.Signal=GPIO_Output +PD14.GPIOParameters=GPIO_Label +PD14.GPIO_Label=VGA_EN +PD14.Locked=true +PD14.Signal=GPIO_Output +PD15.GPIOParameters=GPIO_Label +PD15.GPIO_Label=VGA_ATTSEL1 +PD15.Locked=true +PD15.Signal=GPIO_Output PE0.GPIOParameters=GPIO_Label PE0.GPIO_Label=GEN_EN PE0.Locked=true @@ -337,12 +337,6 @@ PE1.GPIOParameters=GPIO_Label PE1.GPIO_Label=LPA_PWR_EN PE1.Locked=true PE1.Signal=GPIO_Output -PE10.Locked=true -PE11.Locked=true -PE12.Locked=true -PE13.Locked=true -PE14.Locked=true -PE15.Locked=true PE2.GPIOParameters=GPIO_Label PE2.GPIO_Label=VCO_CE PE2.Locked=true @@ -373,6 +367,12 @@ PE8.GPIO_Label=DEBUG1 PE8.Locked=true PE8.Signal=GPIO_Output PE9.Locked=true +PE10.Locked=true +PE11.Locked=true +PE12.Locked=true +PE13.Locked=true +PE14.Locked=true +PE15.Locked=true PF0-OSC_IN\ (PF0).GPIOParameters=GPIO_Label PF0-OSC_IN\ (PF0).GPIO_Label=P6V_SCATTER_PWR_EN PF0-OSC_IN\ (PF0).Locked=true @@ -381,6 +381,20 @@ PF1-OSC_OUT\ (PF1).GPIOParameters=GPIO_Label PF1-OSC_OUT\ (PF1).GPIO_Label=P6V_SCATTER_HSD_DIAG_EN PF1-OSC_OUT\ (PF1).Locked=true PF1-OSC_OUT\ (PF1).Signal=GPIO_Output +PF2-NRST.Locked=true +PF3.Locked=true +PF4.Locked=true +PF5.Locked=true +PF6.Locked=true +PF7.Locked=true +PF8.GPIOParameters=GPIO_Label +PF8.GPIO_Label=P6V_PG +PF8.Locked=true +PF8.Signal=GPIO_Input +PF9.GPIOParameters=GPIO_Label +PF9.GPIO_Label=P6V_HSD_ONE_SEL +PF9.Locked=true +PF9.Signal=GPIO_Output PF10.GPIOParameters=GPIO_Label PF10.GPIO_Label=P6V_HSD_ONE_SEH PF10.Locked=true @@ -398,20 +412,6 @@ PF13.GPIO_Label=P6V_HSD_TWO_DIAG_EN PF13.Locked=true PF13.PinState=GPIO_PIN_RESET PF13.Signal=GPIO_Output -PF2-NRST.Locked=true -PF3.Locked=true -PF4.Locked=true -PF5.Locked=true -PF6.Locked=true -PF7.Locked=true -PF8.GPIOParameters=GPIO_Label -PF8.GPIO_Label=P6V_PG -PF8.Locked=true -PF8.Signal=GPIO_Input -PF9.GPIOParameters=GPIO_Label -PF9.GPIO_Label=P6V_HSD_ONE_SEL -PF9.Locked=true -PF9.Signal=GPIO_Output PinOutPanel.RotationAngle=0 ProjectManager.AskForMigrate=true ProjectManager.BackupPrevious=false @@ -424,8 +424,8 @@ ProjectManager.DefaultFWLocation=true ProjectManager.DeletePrevious=true ProjectManager.DeviceId=STM32G0B1VETx ProjectManager.FirmwarePackage=STM32Cube FW_G0 V1.6.3 -ProjectManager.FreePins=false ProjectManager.FreePinsContext= +ProjectManager.FreePins=false ProjectManager.HalAssertFull=false ProjectManager.HeapSize=0x200 ProjectManager.KeepUserCode=true @@ -478,8 +478,8 @@ RCC.PLLQoutputFreq_Value=64000000 RCC.PLLRCLKFreq_Value=64000000 RCC.PWRFreq_Value=16000000 RCC.SYSCLKFreq_VALUE=16000000 -RCC.TIM15Freq_Value=16000000 RCC.TIM1Freq_Value=16000000 +RCC.TIM15Freq_Value=16000000 RCC.USART1Freq_Value=16000000 RCC.USART2Freq_Value=16000000 RCC.USART3Freq_Value=16000000 @@ -495,8 +495,9 @@ SH.S_TIM2_CH4.ConfNb=1 SPI2.CalculateBaudRate=8.0 MBits/s SPI2.DataSize=SPI_DATASIZE_8BIT SPI2.Direction=SPI_DIRECTION_1LINE -SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize +SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,NSSPMode SPI2.Mode=SPI_MODE_MASTER +SPI2.NSSPMode=SPI_NSS_PULSE_DISABLE SPI2.VirtualType=VM_MASTER SPI3.CalculateBaudRate=8.0 MBits/s SPI3.DataSize=SPI_DATASIZE_8BIT @@ -511,9 +512,11 @@ TIM2.OCPolarity_4=TIM_OCPOLARITY_LOW TIM2.Period=999 TIM2.Prescaler=16 USB_DEVICE.CLASS_NAME_FS=CDC -USB_DEVICE.IPParameters=VirtualMode,VirtualModeFS,CLASS_NAME_FS -USB_DEVICE.VirtualMode=Cdc +USB_DEVICE.IPParameters=VirtualMode,VirtualModeFS,CLASS_NAME_FS,MANUFACTURER_STRING,PRODUCT_STRING_CDC_FS +USB_DEVICE.MANUFACTURER_STRING=Amber +USB_DEVICE.PRODUCT_STRING_CDC_FS=Base Station USB_DEVICE.VirtualModeFS=Cdc_FS +USB_DEVICE.VirtualMode=Cdc VP_FREERTOS_VS_CMSIS_V1.Mode=CMSIS_V1 VP_FREERTOS_VS_CMSIS_V1.Signal=FREERTOS_VS_CMSIS_V1 VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals @@ -526,3 +529,4 @@ VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Mode=CDC_FS VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS.Signal=USB_DEVICE_VS_USB_DEVICE_CDC_FS board=custom rtos.0.ip=FREERTOS +#MicroXplorer Configuration settings - do not modify diff --git a/boards/motherboard/platformio.ini b/boards/motherboard/platformio.ini index 4c773a2..f1cc918 100644 --- a/boards/motherboard/platformio.ini +++ b/boards/motherboard/platformio.ini @@ -30,5 +30,22 @@ build_flags = -I Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM0 -I Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS +lib_deps = + nanopb/Nanopb + +custom_nanopb_protos = + + + +custom_nanopb_options = + --error-on-unmatched + --c-style + upload_protocol = dfu upload_command = dfu-util -a 0 --dfuse-address 0x08000000:leave -D $SOURCE + +platform_packages = + tool-openocd + +; upload_protocol = stlink +debug_tool = stlink +debug_build_flags = -g diff --git a/boards/motherboard/proto b/boards/motherboard/proto new file mode 120000 index 0000000..b943f93 --- /dev/null +++ b/boards/motherboard/proto @@ -0,0 +1 @@ +../../proto \ No newline at end of file diff --git a/boards/motherboard/src/carrier/carrier.cpp b/boards/motherboard/src/carrier/carrier.cpp index 3edd73e..2947475 100644 --- a/boards/motherboard/src/carrier/carrier.cpp +++ b/boards/motherboard/src/carrier/carrier.cpp @@ -1,10 +1,9 @@ #include "carrier.hpp" +#include "Src/power/power.hpp" #include "lib/adf5355/adf5355.hpp" #include "lib/periph/spi.hpp" -#include "Src/power/power.hpp" - // CubeMX #include "adc.h" #include "spi.h" @@ -13,7 +12,8 @@ namespace { static amber::periph::DigitalOutput lpaEn(*LPA_EN_GPIO_Port, LPA_EN_Pin); static amber::periph::DigitalOutput vcoCe(*VCO_CE_GPIO_Port, VCO_CE_Pin); -static amber::periph::DigitalInput vcoMuxOut(*VCO_MUXOUT_GPIO_Port, VCO_MUXOUT_Pin); +static amber::periph::DigitalInput vcoMuxOut(*VCO_MUXOUT_GPIO_Port, + VCO_MUXOUT_Pin); static amber::periph::AnalogInput lpaPowerDetect(hadc1, ADC_CHANNEL_7); static bool vcoLocked = false; diff --git a/boards/motherboard/src/carrier/carrier.hpp b/boards/motherboard/src/carrier/carrier.hpp index faf2f73..78dc26a 100644 --- a/boards/motherboard/src/carrier/carrier.hpp +++ b/boards/motherboard/src/carrier/carrier.hpp @@ -7,4 +7,4 @@ auto Update_100hz() noexcept -> void; auto GetVcoLocked() noexcept -> bool; auto GetPowerDown() noexcept -> bool; -} // namespace carrier +} // namespace carrier \ No newline at end of file diff --git a/boards/motherboard/src/gpio.c b/boards/motherboard/src/gpio.c index 5a1f99c..b3a7116 100644 --- a/boards/motherboard/src/gpio.c +++ b/boards/motherboard/src/gpio.c @@ -71,7 +71,7 @@ void MX_GPIO_Init(void) { LPA_EN_Pin | VGA_ATTSEL0_Pin | VGA_EN_Pin | VGA_ATTSEL1_Pin | P12V_HSD_DIAG_EN_Pin | FAN1_PWR_EN_Pin | FAN2_PWR_EN_Pin | - P6V_HDS_ONE_DIAG_EN_Pin, + P6V_HSD_ONE_DIAG_EN_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ @@ -136,11 +136,11 @@ void MX_GPIO_Init(void) { /*Configure GPIO pins : LPA_EN_Pin VGA_ATTSEL0_Pin VGA_EN_Pin VGA_ATTSEL1_Pin P12V_HSD_DIAG_EN_Pin FAN1_PWR_EN_Pin FAN2_PWR_EN_Pin - P6V_HDS_ONE_DIAG_EN_Pin */ + P6V_HSD_ONE_DIAG_EN_Pin */ GPIO_InitStruct.Pin = LPA_EN_Pin | VGA_ATTSEL0_Pin | VGA_EN_Pin | VGA_ATTSEL1_Pin | P12V_HSD_DIAG_EN_Pin | FAN1_PWR_EN_Pin | FAN2_PWR_EN_Pin | - P6V_HDS_ONE_DIAG_EN_Pin; + P6V_HSD_ONE_DIAG_EN_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; diff --git a/boards/motherboard/src/main.c b/boards/motherboard/src/main.c index 4bf23fd..fdaa92a 100644 --- a/boards/motherboard/src/main.c +++ b/boards/motherboard/src/main.c @@ -99,7 +99,7 @@ int main(void) { MX_SPI3_Init(); MX_TIM2_Init(); /* USER CODE BEGIN 2 */ - + MX_USB_Device_Init(); /* USER CODE END 2 */ /* Call init function for freertos objects (in cmsis_os2.c) */ diff --git a/boards/motherboard/src/power/power.cpp b/boards/motherboard/src/power/power.cpp index 9e84534..71f409f 100644 --- a/boards/motherboard/src/power/power.cpp +++ b/boards/motherboard/src/power/power.cpp @@ -21,14 +21,20 @@ static float p12vCurrent = 0.0f; static power::PowerMuxState powerMuxState = power::PowerMuxState::USB_POWER; auto P6VHsd1Config() -> amber::tps274160b::Config& { - static amber::periph::DigitalOutput en0(*VCO_PWR_EN_GPIO_Port, VCO_PWR_EN_Pin); - static amber::periph::DigitalOutput en3(*VGA_PWR_EN_GPIO_Port, VGA_PWR_EN_Pin); - - static amber::periph::DigitalOutput diagSel0(*P6V_HSD_ONE_SEL_GPIO_Port, P6V_HSD_ONE_SEL_Pin); - static amber::periph::DigitalOutput diagSel1(*P6V_HSD_ONE_SEH_GPIO_Port, P6V_HSD_ONE_SEH_Pin); - - static amber::periph::DigitalInput fault(*P6V_HSD_ONE_nFAULT_GPIO_Port, P6V_HSD_ONE_nFAULT_Pin); - static amber::periph::DigitalOutput diagEn(*P6V_HDS_ONE_DIAG_EN_GPIO_Port, P6V_HDS_ONE_DIAG_EN_Pin); + static amber::periph::DigitalOutput en0(*VCO_PWR_EN_GPIO_Port, + VCO_PWR_EN_Pin); + static amber::periph::DigitalOutput en3(*VGA_PWR_EN_GPIO_Port, + VGA_PWR_EN_Pin); + + static amber::periph::DigitalOutput diagSel0(*P6V_HSD_ONE_SEL_GPIO_Port, + P6V_HSD_ONE_SEL_Pin); + static amber::periph::DigitalOutput diagSel1(*P6V_HSD_ONE_SEH_GPIO_Port, + P6V_HSD_ONE_SEH_Pin); + + static amber::periph::DigitalInput fault(*P6V_HSD_ONE_nFAULT_GPIO_Port, + P6V_HSD_ONE_nFAULT_Pin); + static amber::periph::DigitalOutput diagEn(*P6V_HSD_ONE_DIAG_EN_GPIO_Port, + P6V_HSD_ONE_DIAG_EN_Pin); static amber::periph::AnalogInput currentSense(hadc1, ADC_CHANNEL_10); static amber::tps274160b::Config cfg{ @@ -45,15 +51,22 @@ auto P6VHsd1Config() -> amber::tps274160b::Config& { auto P6VHsd2Config() -> amber::tps274160b::Config& { static amber::periph::DigitalOutput en0(*GEN_EN_GPIO_Port, GEN_EN_Pin); - static amber::periph::DigitalOutput en1(*VGA_PWR_EN_GPIO_Port, VGA_PWR_EN_Pin); - static amber::periph::DigitalOutput en2(*LPA_PWR_EN_GPIO_Port, LPA_PWR_EN_Pin); - static amber::periph::DigitalOutput en3(*VCO_PWR_EN_GPIO_Port, VCO_PWR_EN_Pin); - - static amber::periph::DigitalOutput diagSel0(*P6V_HSD_TWO_SEL_GPIO_Port, P6V_HSD_TWO_SEL_Pin); - static amber::periph::DigitalOutput diagSel1(*P6V_HSD_TWO_SEH_GPIO_Port, P6V_HSD_TWO_SEH_Pin); - - static amber::periph::DigitalInput fault(*P6V_HSD_TWO_nFAULT_GPIO_Port, P6V_HSD_TWO_nFAULT_Pin); - static amber::periph::DigitalOutput diagEn(*P6V_HSD_TWO_DIAG_EN_GPIO_Port, P6V_HSD_TWO_DIAG_EN_Pin); + static amber::periph::DigitalOutput en1(*VGA_PWR_EN_GPIO_Port, + VGA_PWR_EN_Pin); + static amber::periph::DigitalOutput en2(*LPA_PWR_EN_GPIO_Port, + LPA_PWR_EN_Pin); + static amber::periph::DigitalOutput en3(*VCO_PWR_EN_GPIO_Port, + VCO_PWR_EN_Pin); + + static amber::periph::DigitalOutput diagSel0(*P6V_HSD_TWO_SEL_GPIO_Port, + P6V_HSD_TWO_SEL_Pin); + static amber::periph::DigitalOutput diagSel1(*P6V_HSD_TWO_SEH_GPIO_Port, + P6V_HSD_TWO_SEH_Pin); + + static amber::periph::DigitalInput fault(*P6V_HSD_TWO_nFAULT_GPIO_Port, + P6V_HSD_TWO_nFAULT_Pin); + static amber::periph::DigitalOutput diagEn(*P6V_HSD_TWO_DIAG_EN_GPIO_Port, + P6V_HSD_TWO_DIAG_EN_Pin); static amber::periph::AnalogInput currentSense(hadc1, ADC_CHANNEL_9); static amber::tps274160b::Config cfg{ @@ -69,8 +82,10 @@ auto P6VHsd2Config() -> amber::tps274160b::Config& { } auto P6VScatterConfig() -> amber::tps1h100::Config& { - static amber::periph::DigitalOutput en(*P6V_SCATTER_PWR_EN_GPIO_Port, P6V_SCATTER_PWR_EN_Pin); - static amber::periph::DigitalOutput diagEn(*P6V_SCATTER_HSD_DIAG_EN_GPIO_Port, P6V_SCATTER_HSD_DIAG_EN_Pin); + static amber::periph::DigitalOutput en(*P6V_SCATTER_PWR_EN_GPIO_Port, + P6V_SCATTER_PWR_EN_Pin); + static amber::periph::DigitalOutput diagEn( + *P6V_SCATTER_HSD_DIAG_EN_GPIO_Port, P6V_SCATTER_HSD_DIAG_EN_Pin); static amber::periph::AnalogInput currentSense(hadc1, ADC_CHANNEL_4); static amber::tps1h100::Config cfg{ @@ -84,7 +99,8 @@ auto P6VScatterConfig() -> amber::tps1h100::Config& { } auto P12VHsdConfig() -> amber::tps1h100::Config& { - static amber::periph::DigitalOutput diagEn(*P12V_HSD_DIAG_EN_GPIO_Port, P12V_HSD_DIAG_EN_Pin); + static amber::periph::DigitalOutput diagEn(*P12V_HSD_DIAG_EN_GPIO_Port, + P12V_HSD_DIAG_EN_Pin); static amber::periph::AnalogInput currentSense(hadc1, ADC_CHANNEL_11); static amber::tps1h100::Config cfg{750, nullptr, diagEn, currentSense}; @@ -136,9 +152,11 @@ auto Init() noexcept -> void { } auto Update_100hz() noexcept -> void { - powerMuxState = powerMux.Read() ? PowerMuxState::BARREL_JACK : PowerMuxState::USB_POWER; + powerMuxState = + powerMux.Read() ? PowerMuxState::BARREL_JACK : PowerMuxState::USB_POWER; - if (GetPowerMuxState() == PowerMuxState::USB_POWER || carrier::GetPowerDown()) { + if (GetPowerMuxState() == PowerMuxState::USB_POWER || + carrier::GetPowerDown()) { P6VHsd1().disableAll(); P6VHsd2().disableAll(); P6VScatter().disable(); @@ -165,11 +183,13 @@ auto GetPowerMuxState() noexcept -> PowerMuxState { return powerMuxState; } -auto GetP6VHsd1Currents() noexcept -> const std::array& { +auto GetP6VHsd1Currents() noexcept + -> const std::array& { return hsd1Currents; } -auto GetP6VHsd2Currents() noexcept -> const std::array& { +auto GetP6VHsd2Currents() noexcept + -> const std::array& { return hsd2Currents; } diff --git a/boards/motherboard/src/power/power.hpp b/boards/motherboard/src/power/power.hpp index 7d03646..d99289e 100644 --- a/boards/motherboard/src/power/power.hpp +++ b/boards/motherboard/src/power/power.hpp @@ -3,8 +3,8 @@ #include #include -#include "lib/tps274160b/tps274160b.hpp" #include "lib/tps1h100/tps1h100.hpp" +#include "lib/tps274160b/tps274160b.hpp" namespace power { @@ -17,8 +17,10 @@ auto Init() noexcept -> void; auto Update_100hz() noexcept -> void; auto GetPowerMuxState() noexcept -> PowerMuxState; -auto GetP6VHsd1Currents() noexcept -> const std::array&; -auto GetP6VHsd2Currents() noexcept -> const std::array&; +auto GetP6VHsd1Currents() noexcept + -> const std::array&; +auto GetP6VHsd2Currents() noexcept + -> const std::array&; auto GetP6VScatterCurrent() noexcept -> float; auto GetP12VCurrent() noexcept -> float; diff --git a/boards/motherboard/src/serial/serial.cpp b/boards/motherboard/src/serial/serial.cpp index f9391f6..fac1b7f 100644 --- a/boards/motherboard/src/serial/serial.cpp +++ b/boards/motherboard/src/serial/serial.cpp @@ -1,30 +1,100 @@ -// #include "serial.hpp" +#include "serial.hpp" -// #include "cobs.hpp" +#include "cobs.hpp" +#include "common_macros.hpp" -// #include "usbd_cdc_if.h" -// #include "usbd_core.h" +// Proto +#include "base_station.pb.h" +#include "pb_decode.h" +#include "pb_encode.h" -// #include "main.h" +// USB +#include "usbd_cdc_if.h" +#include "usbd_core.h" +// CubeMX +#include "main.h" -// namespace serial { +namespace serial { -// extern "C" { -// extern USBD_HandleTypeDef hUsbDeviceFS; -// } +extern "C" { +extern USBD_HandleTypeDef hUsbDeviceFS; +} -// // RX State -// static uint32_t rx_counter = 0; -// constexpr uint32_t RX_BUF_SIZE = 1024; -// static uint8_t rx_buffer[RX_BUF_SIZE]; -// static uint16_t rx_buf_start = 0; -// static volatile uint16_t rx_buf_end = 0; +// RX State +static uint32_t rx_counter = 0; -// static amber::cobs::Decoder<1024> rx_decoder; +constexpr uint32_t RX_BUF_SIZE = 1024; +static uint8_t rx_buffer[RX_BUF_SIZE]; +static uint16_t rx_buf_start = 0; +static volatile uint16_t rx_buf_end = 0; -// static uint8_t tx_counter = 0; -// static uint8_t pb_buffer[SENSOR_STATUS_SIZE]; -// static uint8_t cobs_buffer[amber::cobs::MaxEncodedLength(SENSOR_STATUS_SIZE)]; +static amber::cobs::Decoder<1024> rx_decoder; -// } // namespace serial \ No newline at end of file +// TX State +static uint8_t tx_counter = 0; +static uint8_t pb_buffer[BASE_STATION_STATUS_SIZE]; +static uint8_t cobs_buffer[amber::cobs::MaxEncodedLength(BASE_STATION_STATUS_SIZE)]; + +static base_station_command_t last_command; + +static void HandleCommand(base_station_command_t* cmd); +static void SendStatus(void); + +void Init(void) { +} + +void Update_100hz(void) { + SendStatus(); +} + +void Receive(void) { + bool has_data = false; + + while (rx_buf_start != rx_buf_end && !has_data) { + has_data = rx_decoder.Decode(&rx_buffer[rx_buf_start], 1); + rx_buf_start = (rx_buf_start + 1) % RX_BUF_SIZE; + } + + if (has_data) { + pb_istream_s istream = + pb_istream_from_buffer(rx_decoder.buffer, rx_decoder.length); + base_station_command_t cmd; + if (pb_decode(&istream, &base_station_command_t_msg, &cmd)) { + HandleCommand(&cmd); + } + rx_decoder.Reset(); + } +} + +void SendStatus(void) { + base_station_status_t status = BASE_STATION_STATUS_INIT_ZERO; + status.has_tx_counter = true; + status.tx_counter = tx_counter; + status.has_rx_counter = true; + status.rx_counter = rx_counter; + + pb_ostream_s ostream = + pb_ostream_from_buffer(pb_buffer, COUNTOF(pb_buffer)); + + if (pb_encode(&ostream, &base_station_status_t_msg, &status)) { + int len = + amber::cobs::Encode(pb_buffer, ostream.bytes_written, cobs_buffer); + CDC_Transmit_FS(cobs_buffer, len); + } +} + +void HandleCommand(base_station_command_t* cmd) { + rx_counter++; + last_command = *cmd; +} + +// Modifiers +void SerialReceiveBytes(uint8_t* bytes, uint32_t len) { + for (uint32_t i = 0; i < len; i++) { + rx_buffer[rx_buf_end] = bytes[i]; + rx_buf_end = (rx_buf_end + 1) % RX_BUF_SIZE; + } +} + +} // namespace serial diff --git a/boards/motherboard/src/serial/serial.hpp b/boards/motherboard/src/serial/serial.hpp index 8afc3c0..5ecd020 100644 --- a/boards/motherboard/src/serial/serial.hpp +++ b/boards/motherboard/src/serial/serial.hpp @@ -1,17 +1,16 @@ -// #pragma once +#pragma once -// // #include "motherboard.pb.h" +#include -// namespace serial { +namespace serial { -// void Init(void); -// void Receive(void); +void Init(void); +void Receive(void); -// void Update_10hz(void); -// void Update_100hz(void); +void Update_100hz(void); -// extern "C" { -// void SerialReceiveBytes(uint8_t* bytes, uint32_t len); -// } +extern "C" { +void SerialReceiveBytes(uint8_t* bytes, uint32_t len); +} -// } // namespace serial +} // namespace serial diff --git a/boards/motherboard/src/spi.c b/boards/motherboard/src/spi.c index 8e25fe5..2b75832 100644 --- a/boards/motherboard/src/spi.c +++ b/boards/motherboard/src/spi.c @@ -49,7 +49,7 @@ void MX_SPI2_Init(void) { hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; hspi2.Init.CRCPolynomial = 7; hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; - hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE; + hspi2.Init.NSSPMode = SPI_NSS_PULSE_DISABLE; if (HAL_SPI_Init(&hspi2) != HAL_OK) { Error_Handler(); } diff --git a/boards/motherboard/src/stm32g0xx_it.c b/boards/motherboard/src/stm32g0xx_it.c index 3b4def9..e1e444b 100644 --- a/boards/motherboard/src/stm32g0xx_it.c +++ b/boards/motherboard/src/stm32g0xx_it.c @@ -56,6 +56,7 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ +extern PCD_HandleTypeDef hpcd_USB_DRD_FS; extern TIM_HandleTypeDef htim1; /* USER CODE BEGIN EV */ @@ -111,6 +112,19 @@ void EXTI0_1_IRQHandler(void) { /* USER CODE END EXTI0_1_IRQn 1 */ } +/** + * @brief This function handles USB, UCPD1 and UCPD2 global interrupts. + */ +void USB_UCPD1_2_IRQHandler(void) { + /* USER CODE BEGIN USB_UCPD1_2_IRQn 0 */ + + /* USER CODE END USB_UCPD1_2_IRQn 0 */ + HAL_PCD_IRQHandler(&hpcd_USB_DRD_FS); + /* USER CODE BEGIN USB_UCPD1_2_IRQn 1 */ + + /* USER CODE END USB_UCPD1_2_IRQn 1 */ +} + /** * @brief This function handles TIM1 break, update, trigger and commutation * interrupts. diff --git a/boards/motherboard/src/tasks.cpp b/boards/motherboard/src/tasks.cpp index 3266d7f..eb89840 100644 --- a/boards/motherboard/src/tasks.cpp +++ b/boards/motherboard/src/tasks.cpp @@ -1,22 +1,14 @@ #include "tasks.hpp" #include "FreeRTOS.h" -#include "dac.h" - -#include "power/power.hpp" #include "carrier/carrier.hpp" -#include "lib/adf5355/adf5355.hpp" -#include "lib/periph/analog_output.hpp" -#include "lib/periph/analog_input.hpp" #include "lib/periph/digital.hpp" -#include "lib/periph/pwm.hpp" -#include "lib/periph/spi.hpp" #include "main.h" -#include "spi.h" +#include "power/power.hpp" #include "task.h" +#include "thermal/thermal.hpp" +#include "serial/serial.hpp" #include "tim.h" -#include "dac.h" -#include "adc.h" enum { PRIORITY_1HZ = 1, @@ -33,6 +25,9 @@ StackType_t t1000hz_stack[STACK_SIZE_WORDS]; StaticTask_t t100hz_ctrl; StackType_t t100hz_stack[STACK_SIZE_WORDS]; +StaticTask_t t10hz_ctrl; +StackType_t t10hz_stack[STACK_SIZE_WORDS]; + StaticTask_t t1hz_ctrl; StackType_t t1hz_stack[STACK_SIZE_WORDS]; @@ -40,34 +35,9 @@ auto task_1000hz(void* argument) -> void { (void)argument; TickType_t wake_time = xTaskGetTickCount(); - // amber::periph::DigitalInput comparator(*COMPARATOR_GPIO_Port, COMPARATOR_Pin); - // amber::periph::AnalogOutput logv(hdac1, DAC1_CHANNEL_2); - // amber::periph::AnalogInput read(hadc1, ADC_CHANNEL_0); - // amber::periph::DigitalOutput debug2(*DEBUG2_GPIO_Port, DEBUG2_Pin); - - // // --- Configuration --- - // constexpr uint32_t TASK_HZ = 1000; - // constexpr float DECAY_RATE = 0.001f; // volts lost per tick — tune this - // constexpr float PEAK_FLOOR = 0.0f; // minimum peak hold value - - // float peak_hold = 0.0f; - - // logv.SetVoltage(0.95f); - while (true) { + serial::Receive(); vTaskDelayUntil(&wake_time, pdMS_TO_TICKS(1)); - - // float new_sample = read.ReadVoltage(); - - // // Latch any new peak immediately - // if (new_sample > peak_hold) { - // peak_hold = new_sample; - // } else { - // // Slowly decay when no new peak - // peak_hold = std::max(peak_hold - DECAY_RATE, PEAK_FLOOR); - // } - - // debug2.Set(comparator.Read()); } } @@ -78,11 +48,23 @@ auto task_100hz(void* argument) -> void { while (true) { power::Update_100hz(); carrier::Update_100hz(); + serial::Update_100hz(); vTaskDelayUntil(&wake_time, pdMS_TO_TICKS(10)); } }; +auto task_10hz(void* argument) -> void { + (void)argument; + TickType_t wake_time = xTaskGetTickCount(); + + while (true) { + thermal::Update10Hz(); + + vTaskDelayUntil(&wake_time, pdMS_TO_TICKS(100)); + } +}; + auto task_1hz(void* argument) -> void { (void)argument; TickType_t wake_time = xTaskGetTickCount(); @@ -97,12 +79,17 @@ auto task_1hz(void* argument) -> void { }; auto MX_FREERTOS_Init() -> void { + serial::Init(); power::Init(); carrier::Init(); + thermal::Init(); xTaskCreateStatic(task_1hz, "1Hz", STACK_SIZE_WORDS, NULL, PRIORITY_1HZ, t1hz_stack, &t1hz_ctrl); + xTaskCreateStatic(task_10hz, "10Hz", STACK_SIZE_WORDS, NULL, PRIORITY_10HZ, + t10hz_stack, &t10hz_ctrl); + xTaskCreateStatic(task_100hz, "100Hz", STACK_SIZE_WORDS, NULL, PRIORITY_100HZ, t100hz_stack, &t100hz_ctrl); diff --git a/boards/motherboard/src/thermal/thermal.cpp b/boards/motherboard/src/thermal/thermal.cpp index 0e93874..fa986c8 100644 --- a/boards/motherboard/src/thermal/thermal.cpp +++ b/boards/motherboard/src/thermal/thermal.cpp @@ -1,7 +1,99 @@ #include "thermal.hpp" +#include + +#include "lib/tmp126/tmp126.hpp" +#include "periph/pwm.hpp" +#include "spi.h" +#include "tim.h" + namespace thermal { +namespace { + +static amber::periph::DigitalOutput tempCs(*TEMP_CS_N_GPIO_Port, TEMP_CS_N_Pin); +static amber::periph::DigitalOutput fan2En(*FAN2_PWR_EN_GPIO_Port, + FAN2_PWR_EN_Pin); + +static amber::periph::Pwm fan2Pwm(htim2, TIM_CHANNEL_4); +static amber::periph::Spi tempSpi(hspi2, tempCs); + +static amber::tmp126::Driver tempSensor(tempSpi, amber::tmp126::Config{}); +static bool tempSensorReady = false; + +constexpr float kAlpha = 0.1f; // EMA smoothing factor +constexpr uint8_t kTempRegions = 5; + +float filteredTemp = 0.0f; + +struct Point { + float temperature; + uint8_t duty; +}; + +constexpr std::array kThermalCurve{{ + {40.0f, 0}, + {55.0f, 25}, + {70.0f, 55}, + {85.0f, 85}, + {95.0f, 100}, +}}; + +auto LookupDuty(float temp) -> uint8_t { + if (temp <= kThermalCurve[0].temperature) { + return kThermalCurve[0].duty; + } + + if (temp >= kThermalCurve[kTempRegions - 1].temperature) { + return kThermalCurve[kTempRegions - 1].duty; + } + + for (size_t i = 0; i < kTempRegions - 1; ++i) { + const auto& p1 = kThermalCurve[i]; + const auto& p2 = kThermalCurve[i + 1]; + + if (temp >= p1.temperature && temp <= p2.temperature) { + float ratio = + (temp - p1.temperature) / (p2.temperature - p1.temperature); + return static_cast(p1.duty + ratio * (p2.duty - p1.duty)); + } + } + + return 100; // should never reach here +}; + +} // namespace + +auto Init() noexcept -> void { + filteredTemp = 25.0f; + fan2En.SetHigh(); + fan2Pwm.Start(); + fan2Pwm.SetDutyCycle(0.0f); + + tempSensorReady = (tempSensor.init() == amber::tmp126::Status::OK); + if (!tempSensorReady) { + fan2Pwm.SetDutyCycle(100.0f); + } +}; + +auto Update10Hz() noexcept -> void { + if (!tempSensorReady) { + return; + } + + const auto [status, temperature] = tempSensor.readTemperature(); + if (status != amber::tmp126::Status::OK) { + tempSensorReady = false; + fan2Pwm.SetDutyCycle(100.0f); + return; + } + + filteredTemp += kAlpha * (temperature - filteredTemp); + fan2Pwm.SetDutyCycle(LookupDuty(filteredTemp)); +}; +auto GetCarrierTemp() noexcept -> float { + return filteredTemp; +} -} // namespace thermal \ No newline at end of file +} // namespace thermal diff --git a/boards/motherboard/src/thermal/thermal.hpp b/boards/motherboard/src/thermal/thermal.hpp index e2fa362..5a02653 100644 --- a/boards/motherboard/src/thermal/thermal.hpp +++ b/boards/motherboard/src/thermal/thermal.hpp @@ -4,5 +4,6 @@ namespace thermal { auto Init() noexcept -> void; auto Update10Hz() noexcept -> void; +auto GetCarrierTemp() noexcept -> float; } // namespace thermal \ No newline at end of file diff --git a/boards/motherboard/src/usbd_cdc_if.c b/boards/motherboard/src/usbd_cdc_if.c index 2d1a851..e17508b 100644 --- a/boards/motherboard/src/usbd_cdc_if.c +++ b/boards/motherboard/src/usbd_cdc_if.c @@ -22,6 +22,10 @@ #include "usbd_cdc_if.h" /* USER CODE BEGIN INCLUDE */ +#include +#include +#include +#include /* USER CODE END INCLUDE */ @@ -50,7 +54,6 @@ */ /* USER CODE BEGIN PRIVATE_TYPES */ - /* USER CODE END PRIVATE_TYPES */ /** @@ -95,6 +98,8 @@ uint8_t UserRxBufferFS[APP_RX_DATA_SIZE]; uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; /* USER CODE BEGIN PRIVATE_VARIABLES */ +static char cdcCommandBuffer[32]; +static uint8_t cdcCommandLength = 0; /* USER CODE END PRIVATE_VARIABLES */ @@ -110,7 +115,7 @@ uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; extern USBD_HandleTypeDef hUsbDeviceFS; /* USER CODE BEGIN EXPORTED_VARIABLES */ - +extern void SerialReceiveBytes(uint8_t* bytes, uint32_t len); /* USER CODE END EXPORTED_VARIABLES */ /** @@ -130,6 +135,8 @@ static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t* Len); static int8_t CDC_TransmitCplt_FS(uint8_t* pbuf, uint32_t* Len, uint8_t epnum); /* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ +static void CDC_ProcessCommand(const char* command); +static void CDC_SendTemperature(void); /* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */ @@ -257,8 +264,10 @@ static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) { */ static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t* Len) { /* USER CODE BEGIN 6 */ - USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); + SerialReceiveBytes(Buf, *Len); + USBD_CDC_ReceivePacket(&hUsbDeviceFS); + return (USBD_OK); /* USER CODE END 6 */ } @@ -313,6 +322,34 @@ static int8_t CDC_TransmitCplt_FS(uint8_t* Buf, uint32_t* Len, uint8_t epnum) { /* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ +static void CDC_ProcessCommand(const char* command) { + if (strcmp(command, "temp") == 0 || strcmp(command, "temp?") == 0) { + CDC_SendTemperature(); + return; + } + + static uint8_t unknownResponse[] = "ERR unknown command\r\n"; + (void)CDC_Transmit_FS(unknownResponse, sizeof(unknownResponse) - 1U); +} + +static void CDC_SendTemperature(void) { + const float temperature = Thermal_GetCarrierTempC(); + const int32_t centiC = (int32_t)(temperature * 100.0f + + ((temperature >= 0.0f) ? 0.5f : -0.5f)); + const int32_t whole = centiC / 100; + const int32_t fractional = (centiC < 0 ? -centiC : centiC) % 100; + + static uint8_t response[32]; + const int length = + snprintf((char*)response, sizeof(response), "TEMP %ld.%02ld C\r\n", + (long)whole, (long)fractional); + if (length <= 0) { + return; + } + + (void)CDC_Transmit_FS(response, (uint16_t)length); +} + /* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ /** diff --git a/boards/motherboard/src/usbd_conf.c b/boards/motherboard/src/usbd_conf.c index 31dc564..d7507b1 100644 --- a/boards/motherboard/src/usbd_conf.c +++ b/boards/motherboard/src/usbd_conf.c @@ -92,6 +92,10 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) { } else { HAL_PWREx_EnableVddUSB(); } + + /* Peripheral interrupt init */ + HAL_NVIC_SetPriority(USB_UCPD1_2_IRQn, 3, 0); + HAL_NVIC_EnableIRQ(USB_UCPD1_2_IRQn); /* USER CODE BEGIN USB_DRD_FS_MspInit 1 */ /* USER CODE END USB_DRD_FS_MspInit 1 */ @@ -105,6 +109,10 @@ void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) { /* USER CODE END USB_DRD_FS_MspDeInit 0 */ /* Disable Peripheral clock */ __HAL_RCC_USB_CLK_DISABLE(); + + /* Peripheral interrupt Deinit*/ + HAL_NVIC_DisableIRQ(USB_UCPD1_2_IRQn); + /* USER CODE BEGIN USB_DRD_FS_MspDeInit 1 */ /* USER CODE END USB_DRD_FS_MspDeInit 1 */ diff --git a/boards/motherboard/src/usbd_desc.c b/boards/motherboard/src/usbd_desc.c index bc7a859..fbd5c9c 100644 --- a/boards/motherboard/src/usbd_desc.c +++ b/boards/motherboard/src/usbd_desc.c @@ -66,9 +66,9 @@ #define USBD_VID 1155 #define USBD_LANGID_STRING 1033 -#define USBD_MANUFACTURER_STRING "STMicroelectronics" +#define USBD_MANUFACTURER_STRING "Amber" #define USBD_PID 22336 -#define USBD_PRODUCT_STRING "STM32 Virtual ComPort" +#define USBD_PRODUCT_STRING "Base Station" #define USBD_CONFIGURATION_STRING "CDC Config" #define USBD_INTERFACE_STRING "CDC Interface" diff --git a/lib/periph/spi.hpp b/lib/periph/spi.hpp index 2b59e4d..9ca0667 100644 --- a/lib/periph/spi.hpp +++ b/lib/periph/spi.hpp @@ -51,6 +51,17 @@ struct Spi { return status; } + auto transmitThenReceive(const uint8_t* tx, uint16_t txLen, + uint8_t* rx, uint16_t rxLen) noexcept -> HAL_StatusTypeDef { + csAssert(); + auto status = HAL_SPI_Transmit(&_hspi, const_cast(tx), txLen, HAL_MAX_DELAY); + if (status == HAL_OK) { + status = HAL_SPI_Receive(&_hspi, rx, rxLen, HAL_MAX_DELAY); + } + csRelease(); + return status; + } + private: void csAssert() { _csPin.SetLow(); diff --git a/lib/tmp126/tmp126.cpp b/lib/tmp126/tmp126.cpp new file mode 100644 index 0000000..71576ac --- /dev/null +++ b/lib/tmp126/tmp126.cpp @@ -0,0 +1,111 @@ +#include "tmp126.hpp" + +namespace amber::tmp126 { + +Driver::Driver(periph::Spi& spi, const Config& config) + : _spi(spi), _config(config) {} + +auto Driver::init() noexcept -> Status { + auto status = softReset(); + if (status != Status::OK) { + return status; + } + + uint16_t cfg = 0x0000U; + + if (_config.averaging) { + cfg |= CFG_AVG_BIT; + } + + cfg &= ~CFG_MODE_BIT; + + cfg |= (static_cast(_config.conv_period) & CFG_PERIOD_MASK); + + status = writeReg(reg::CONFIGURATION, cfg); + if (status != Status::OK) { + return status; + } + + return Status::OK; +} + +auto Driver::softReset() noexcept -> Status { + return writeReg(reg::CONFIGURATION, CFG_RESET_BIT); +} + +auto Driver::setConvPeriod(const ConvPeriod period) noexcept -> Status { + auto [status, current] = readReg(reg::CONFIGURATION); + if (status != Status::OK) { + return status; + } + + uint16_t updated = (current & ~CFG_PERIOD_MASK) + | (static_cast(period) & CFG_PERIOD_MASK); + + return writeReg(reg::CONFIGURATION, updated); +} + +auto Driver::readTemperature() noexcept -> std::pair { + auto [status, raw] = readReg(reg::TEMP_RESULT); + if (status != Status::OK) { + return {status, 0.0f}; + } + return {Status::OK, rawToDegreesC(raw)}; +} + +auto Driver::isDataReady() noexcept -> bool { + auto [status, val] = readReg(reg::ALERT_STATUS); + if (status != Status::OK) { + return false; + } + return (val & ALERT_DATA_READY) != 0U; +} + +auto Driver::readReg(const reg r) noexcept -> std::pair { + auto txFrame = buildFrame(false, r, 0x0000U); + std::array rxFrame {}; + + auto status = _spi.transmitThenReceive(txFrame.data(), 2U, rxFrame.data(), 2U); + if (status != HAL_OK) { + return {Status::SPI_FAILURE, 0U}; + } + + uint16_t data = (static_cast(rxFrame[0]) << 8) + | static_cast(rxFrame[1]); + + return {Status::OK, data}; +} + +auto Driver::writeReg(const reg r, const uint16_t data) noexcept -> Status { + auto frame = buildFrame(true, r, data); + + auto halStatus = _spi.transmit(frame.data(), SPI_NUM_BYTES); + if (halStatus != HAL_OK) { + return Status::SPI_FAILURE; + } + + return Status::OK; +} + +auto Driver::buildFrame(const bool write, const reg r, const uint16_t data) + noexcept -> std::array +{ + std::array frame {0}; + + uint16_t cmd = write ? CMD_WRITE : CMD_READ; + cmd |= static_cast(r); + + frame[0] = static_cast(cmd >> 8); + frame[1] = static_cast(cmd & 0xFFU); + frame[2] = static_cast(data >> 8); + frame[3] = static_cast(data & 0xFFU); + + return frame; +} + +auto Driver::rawToDegreesC(const uint16_t raw) noexcept -> float { + auto signed14 = static_cast(raw) >> 2; + return static_cast(signed14) * LSB_DEG_C; +} + +} // namespace amber::tmp126 diff --git a/lib/tmp126/tmp126.hpp b/lib/tmp126/tmp126.hpp new file mode 100644 index 0000000..439a26d --- /dev/null +++ b/lib/tmp126/tmp126.hpp @@ -0,0 +1,93 @@ +/** + * @file tmp126.hpp + * @author Ivan Lange + * @brief Driver for TMP126 SPI temperature sensor + * + * @date 2026-04-04 + */ + +#pragma once + +#include +#include +#include // for std::pair + +#include "periph/spi.hpp" + +namespace amber::tmp126 { + +static constexpr float LSB_DEG_C = 0.03125f; +static constexpr uint8_t SPI_NUM_BYTES = 4U; +static constexpr uint16_t CMD_READ = (1U << 8); +static constexpr uint16_t CMD_WRITE = 0U; + +enum class reg : uint8_t { + TEMP_RESULT = 0x00, + SLEW_RESULT = 0x01, + ALERT_STATUS = 0x02, + CONFIGURATION = 0x03, + ALERT_ENABLE = 0x04, + TLOW_LIMIT = 0x05, + THIGH_LIMIT = 0x06, + HYSTERESIS = 0x07, + SLEW_LIMIT = 0x08, + UNIQUE_ID1 = 0x09, + UNIQUE_ID2 = 0x0A, + UNIQUE_ID3 = 0x0B, + DEVICE_ID = 0x0C, +}; + +enum class ConvPeriod : uint8_t { + MS_6 = 0b000, + MS_31_25 = 0b001, + MS_62_5 = 0b010, + MS_125 = 0b011, + MS_250 = 0b100, + MS_500 = 0b101, + S_1 = 0b110, + S_2 = 0b111, +}; + +enum class Status : uint8_t { + OK = 0, + SPI_FAILURE, + INVALID_PERIOD, + DATA_NOT_READY, +}; + +struct Config { + ConvPeriod conv_period {ConvPeriod::MS_62_5}; + bool averaging {true}; +}; + +struct Driver { + Driver(periph::Spi& spi, const Config& config); + ~Driver() = default; + + auto init() noexcept -> Status; + + auto softReset() noexcept -> Status; + auto setConvPeriod(ConvPeriod period) noexcept -> Status; + auto readTemperature() noexcept -> std::pair; + auto isDataReady() noexcept -> bool; + + auto readReg (reg r) noexcept -> std::pair; + auto writeReg(reg r, uint16_t data) noexcept -> Status; + +private: + auto buildFrame(bool write, reg r, uint16_t data) noexcept -> std::array; + + static auto rawToDegreesC(uint16_t raw) noexcept -> float; + + static constexpr uint16_t CFG_RESET_BIT = (1U << 8); + static constexpr uint16_t CFG_AVG_BIT = (1U << 7); + static constexpr uint16_t CFG_MODE_BIT = (1U << 3); + static constexpr uint16_t CFG_PERIOD_MASK = 0x0007U; + + static constexpr uint16_t ALERT_DATA_READY = (1U << 0); + + periph::Spi& _spi; + const Config _config; +}; + +} // namespace amber::tmp126 diff --git a/proto/base_station.proto b/proto/base_station.proto new file mode 100644 index 0000000..f3b87b7 --- /dev/null +++ b/proto/base_station.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +package base_station; + +message Command { + uint32 dummy = 1; +} + +message Status { + uint32 dummy_echo = 1; + // Diagnostics + optional uint32 tx_counter = 14; + optional uint32 rx_counter = 15; +} From 4972cfbefdf8c5026f2352de96845f8b0261ea2c Mon Sep 17 00:00:00 2001 From: Ivan Lange Date: Sun, 5 Apr 2026 00:42:00 -0400 Subject: [PATCH 09/13] more usb --- boards/cc1101_test/src/main.cpp | 12 ++++++------ boards/sensor/Src/stm32u0xx_hal_msp.c | 1 - boards/sensor/platformio.ini | 2 ++ boards/sensor/post_cubemx.sh | 0 boards/sensor/sensor.ioc | 18 +++++++++++++----- lib/rust/proto/build.rs | 1 + 6 files changed, 22 insertions(+), 12 deletions(-) mode change 100644 => 100755 boards/sensor/post_cubemx.sh diff --git a/boards/cc1101_test/src/main.cpp b/boards/cc1101_test/src/main.cpp index f8aa4ff..51751df 100644 --- a/boards/cc1101_test/src/main.cpp +++ b/boards/cc1101_test/src/main.cpp @@ -27,16 +27,16 @@ void setup() { cs_tx.setHigh(); cs_rx.setHigh(); - cc1101::Driver transmitter(SPI, miso, cs_tx); - cc1101::Driver receiver(SPI, miso, cs_rx); + amber::cc1101::Driver transmitter(SPI, miso, cs_tx); + amber::cc1101::Driver receiver(SPI, miso, cs_rx); transmitter.reset(); - transmitter.configure(cc1101::Driver::Frequency::MHZ_915); - transmitter.begin(cc1101::Driver::Direction::TX); + transmitter.configure(amber::cc1101::Driver::Frequency::MHZ_915); + transmitter.begin(amber::cc1101::Driver::Direction::TX); receiver.reset(); - receiver.configure(cc1101::Driver::Frequency::MHZ_915); - receiver.begin(cc1101::Driver::Direction::TX); + receiver.configure(amber::cc1101::Driver::Frequency::MHZ_915); + receiver.begin(amber::cc1101::Driver::Direction::TX); } void loop() { diff --git a/boards/sensor/Src/stm32u0xx_hal_msp.c b/boards/sensor/Src/stm32u0xx_hal_msp.c index 6f9f7d6..b168c2e 100644 --- a/boards/sensor/Src/stm32u0xx_hal_msp.c +++ b/boards/sensor/Src/stm32u0xx_hal_msp.c @@ -17,7 +17,6 @@ ****************************************************************************** */ /* USER CODE END Header */ - /* Includes ------------------------------------------------------------------*/ #include "main.h" /* USER CODE BEGIN Includes */ diff --git a/boards/sensor/platformio.ini b/boards/sensor/platformio.ini index b2c781d..860ed9f 100644 --- a/boards/sensor/platformio.ini +++ b/boards/sensor/platformio.ini @@ -48,7 +48,9 @@ lib_deps = nanopb/Nanopb custom_nanopb_protos = + + + + + custom_nanopb_options = --error-on-unmatched diff --git a/boards/sensor/post_cubemx.sh b/boards/sensor/post_cubemx.sh old mode 100644 new mode 100755 diff --git a/boards/sensor/sensor.ioc b/boards/sensor/sensor.ioc index c9cac8c..754c795 100644 --- a/boards/sensor/sensor.ioc +++ b/boards/sensor/sensor.ioc @@ -159,8 +159,8 @@ Mcu.ThirdParty0=STMicroelectronics.X-CUBE-FREERTOS.1.3.1 Mcu.ThirdPartyNb=1 Mcu.UserConstants= Mcu.UserName=STM32U083RCTx -MxCube.Version=6.15.0 -MxDb.Version=DB.6.0.150 +MxCube.Version=6.17.0 +MxDb.Version=DB.6.0.170 NVIC.DMA1_Ch4_7_DMA2_Ch1_5_DMAMUX_OVR_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true\:true NVIC.DMA1_Channel1_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:true\:true NVIC.ForceEnableDMAVector=true @@ -228,9 +228,9 @@ PA12\ [PA10].Locked=true PA12\ [PA10].Mode=Device PA12\ [PA10].PinAttribute=Free PA12\ [PA10].Signal=USB_DP -PA13\ (SWDIO).Mode=Trace_Asynchronous_SW +PA13\ (SWDIO).Mode=Serial_Wire PA13\ (SWDIO).Signal=DEBUG_JTMS-SWDIO -PA14\ (SWCLK).Mode=Trace_Asynchronous_SW +PA14\ (SWCLK).Mode=Serial_Wire PA14\ (SWCLK).Signal=DEBUG_JTCK-SWCLK PA15.Locked=true PB0.GPIOParameters=GPIO_Label @@ -246,7 +246,6 @@ PB2.GPIO_Label=FPGA_DRDY PB2.Locked=true PB2.Signal=GPIO_Input PB3.Locked=true -PB3.Mode=Trace_Asynchronous_SW PB3.Signal=DEBUG_JTDO-SWO PB4.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultOutputPP PB4.GPIO_Label=FLASH_CSn @@ -350,6 +349,14 @@ PC13.Locked=true PC13.Signal=GPIO_Output PC14-OSC32_IN.Locked=true PC15-OSC32_OUT.Locked=true +PCC.Checker=false +PCC.Display=Plot\: All Steps +PCC.Line=STM32U0x3 +PCC.MCU=STM32U083RCTx +PCC.PartNumber=STM32U083RCTx +PCC.Series=STM32U0 +PCC.Temperature=25 +PCC.Vdd=3.0 PD2.Locked=true PF0-OSC_IN.Locked=true PF1-OSC_OUT.Locked=true @@ -367,6 +374,7 @@ ProjectManager.DefaultFWLocation=true ProjectManager.DeletePrevious=true ProjectManager.DeviceId=STM32U083RCTx ProjectManager.FirmwarePackage=STM32Cube FW_U0 V1.3.0 +ProjectManager.FreePinsContext= ProjectManager.FreePins=false ProjectManager.HalAssertFull=false ProjectManager.HeapSize=0x300 diff --git a/lib/rust/proto/build.rs b/lib/rust/proto/build.rs index 40857cf..ba6f2d3 100644 --- a/lib/rust/proto/build.rs +++ b/lib/rust/proto/build.rs @@ -20,6 +20,7 @@ fn main() -> Result<()> { "sensor/fpga/image.proto", "sensor/measure.proto", "sensor/parameters.proto", + "base_station.proto", ]; for proto_file in &protos { From 0427e044c7cdcfc1c03be85a22fc55f01a52bd48 Mon Sep 17 00:00:00 2001 From: Blake Freer Date: Sun, 5 Apr 2026 01:41:43 -0400 Subject: [PATCH 10/13] Motherboard TUI --- Cargo.lock | 929 +++++++++++++++++++++++++++++++++-- Cargo.toml | 2 +- apps/motherboard/Cargo.toml | 20 + apps/motherboard/src/main.rs | 99 ++++ 4 files changed, 1017 insertions(+), 33 deletions(-) create mode 100644 apps/motherboard/Cargo.toml create mode 100644 apps/motherboard/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 03ed8ea..081d007 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,6 +35,12 @@ dependencies = [ "equator", ] +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "amber-connect" version = "0.1.0" @@ -131,7 +137,7 @@ checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -157,7 +163,7 @@ checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -173,6 +179,15 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "atomic" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89cbf775b137e9b968e67227ef7f775587cde3fd31b0d8599dbd0f598a48340" +dependencies = [ + "bytemuck", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -214,7 +229,7 @@ dependencies = [ "anyhow", "arrayvec", "log", - "nom", + "nom 8.0.0", "num-rational", "v_frame", ] @@ -351,6 +366,21 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + [[package]] name = "bit_field" version = "0.10.3" @@ -452,6 +482,15 @@ dependencies = [ "zeromq", ] +[[package]] +name = "castaway" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dec551ab6e7578819132c713a93c022a05d60159dc86e7a7050223577484c55a" +dependencies = [ + "rustversion", +] + [[package]] name = "cc" version = "1.2.57" @@ -537,7 +576,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -599,6 +638,20 @@ dependencies = [ "memchr", ] +[[package]] +name = "compact_str" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb1325a1cece981e8a296ab8f0f9b63ae357bd0784a9faaf548cc7b480707a" +dependencies = [ + "castaway", + "cfg-if", + "itoa", + "rustversion", + "ryu", + "static_assertions", +] + [[package]] name = "console" version = "0.16.3" @@ -611,6 +664,15 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "convert_case" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "633458d4ef8c78b72454de2d54fd6ab2e60f9e02be22f3c6104cdc8a4e0fceb9" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -722,6 +784,33 @@ version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" +[[package]] +name = "crossterm" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b9f2e4c67f833b660cdb0a3523065869fb35570177239812ed4c905aeff87b" +dependencies = [ + "bitflags 2.11.0", + "crossterm_winapi", + "derive_more", + "document-features", + "mio", + "parking_lot", + "rustix", + "signal-hook", + "signal-hook-mio", + "winapi", +] + +[[package]] +name = "crossterm_winapi" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" +dependencies = [ + "winapi", +] + [[package]] name = "crunchy" version = "0.2.4" @@ -738,6 +827,50 @@ dependencies = [ "typenum", ] +[[package]] +name = "csscolorparser" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb2a7d3066da2de787b7f032c736763eb7ae5d355f81a68bab2675a96008b0bf" +dependencies = [ + "lab", + "phf", +] + +[[package]] +name = "darling" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25ae13da2f202d56bd7f91c25fba009e7717a1e4a1cc98a76d844b65ae912e9d" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9865a50f7c335f53564bb694ef660825eb8610e0a53d3e11bf1b0d3df31e03b0" +dependencies = [ + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.117", +] + +[[package]] +name = "darling_macro" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.117", +] + [[package]] name = "data-encoding" version = "2.10.0" @@ -758,6 +891,43 @@ dependencies = [ "zeromq", ] +[[package]] +name = "deltae" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5729f5117e208430e437df2f4843f5e5952997175992d1414f94c57d61e270b4" + +[[package]] +name = "deranged" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "derive_more" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d751e9e49156b02b44f9c1815bcb94b984cdcc4396ecc32521c739452808b134" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.117", +] + [[package]] name = "digest" version = "0.10.7" @@ -776,7 +946,16 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", +] + +[[package]] +name = "document-features" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4b8a88685455ed29a21542a33abd9cb6510b6b129abadabdcef0f4c55bc8f61" +dependencies = [ + "litrs", ] [[package]] @@ -823,7 +1002,7 @@ checksum = "44f23cf4b44bfce11a86ace86f8a73ffdec849c9fd00a386a53d278bd9e81fb3" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -842,6 +1021,15 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "euclid" +version = "0.22.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1a05365e3b1c6d1650318537c7460c6923f1abdd272ad6842baa2b509957a06" +dependencies = [ + "num-traits", +] + [[package]] name = "exr" version = "1.74.0" @@ -857,6 +1045,16 @@ dependencies = [ "zune-inflate", ] +[[package]] +name = "fancy-regex" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b95f7c0680e4142284cf8b22c14a476e87d61b004a3a0861872b32ef7ead40a2" +dependencies = [ + "bit-set", + "regex", +] + [[package]] name = "fastrand" version = "2.3.0" @@ -880,7 +1078,7 @@ checksum = "a0aca10fb742cb43f9e7bb8467c91aa9bcb8e3ffbc6a6f7389bb93ffc920577d" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -892,12 +1090,35 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "filedescriptor" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e40758ed24c9b2eeb76c35fb0aebc66c626084edd827e07e1552279814c6682d" +dependencies = [ + "libc", + "thiserror 1.0.69", + "winapi", +] + [[package]] name = "find-msvc-tools" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" +[[package]] +name = "finl_unicode" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9844ddc3a6e533d62bba727eb6c28b5d360921d5175e9ff0f1e621a5c590a4d5" + +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + [[package]] name = "fixedbitset" version = "0.5.7" @@ -962,6 +1183,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + [[package]] name = "form_urlencoded" version = "1.2.2" @@ -1033,7 +1260,7 @@ checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -1184,7 +1411,7 @@ version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ - "foldhash", + "foldhash 0.1.5", ] [[package]] @@ -1192,6 +1419,11 @@ name = "hashbrown" version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash 0.2.0", +] [[package]] name = "headers" @@ -1233,6 +1465,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "http" version = "1.4.0" @@ -1453,6 +1691,12 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "1.1.0" @@ -1539,6 +1783,15 @@ dependencies = [ "web-time", ] +[[package]] +name = "indoc" +version = "2.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706" +dependencies = [ + "rustversion", +] + [[package]] name = "influx" version = "0.1.0" @@ -1553,6 +1806,19 @@ dependencies = [ "tracing", ] +[[package]] +name = "instability" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eb2d60ef19920a3a9193c3e371f726ec1dafc045dac788d0fb3704272458971" +dependencies = [ + "darling", + "indoc", + "proc-macro2", + "quote", + "syn 2.0.117", +] + [[package]] name = "interpolate_name" version = "0.2.4" @@ -1561,7 +1827,7 @@ checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -1652,7 +1918,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264" dependencies = [ "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -1675,6 +1941,23 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "kasuari" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bde5057d6143cc94e861d90f591b9303d6716c6b9602309150bd068853c10899" +dependencies = [ + "hashbrown 0.16.1", + "portable-atomic", + "thiserror 2.0.18", +] + +[[package]] +name = "lab" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf36173d4167ed999940f804952e6b08197cae5ad5d572eb4db150ce8ad5d58f" + [[package]] name = "lazy_static" version = "1.5.0" @@ -1729,6 +2012,15 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "line-clipping" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f50e8f47623268b5407192d26876c4d7f89d686ca130fdc53bced4814cd29f8" +dependencies = [ + "bitflags 2.11.0", +] + [[package]] name = "linux-raw-sys" version = "0.12.1" @@ -1741,6 +2033,12 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" +[[package]] +name = "litrs" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092" + [[package]] name = "lock_api" version = "0.4.14" @@ -1765,12 +2063,31 @@ dependencies = [ "imgref", ] +[[package]] +name = "lru" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1dc47f592c06f33f8e3aea9591776ec7c9f9e4124778ff8a3c3b87159f7e593" +dependencies = [ + "hashbrown 0.16.1", +] + [[package]] name = "lru-slab" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" +[[package]] +name = "mac_address" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0aeb26bf5e836cc1c341c8106051b573f1766dfa05aa87f0b98be5e51b02303" +dependencies = [ + "nix 0.29.0", + "winapi", +] + [[package]] name = "mach2" version = "0.4.3" @@ -1811,12 +2128,33 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" +[[package]] +name = "memmem" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a64a92489e2744ce060c349162be1c5f33c6969234104dbd99ddb5feb08b8c15" + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + [[package]] name = "mime" version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.8.9" @@ -1852,6 +2190,23 @@ dependencies = [ "winapi", ] +[[package]] +name = "motherboard" +version = "0.1.0" +dependencies = [ + "anyhow", + "crossterm", + "futures", + "prost", + "proto", + "ratatui", + "serde", + "serial", + "tokio", + "tokio-serial", + "tokio-util", +] + [[package]] name = "moxcms" version = "0.8.1" @@ -1895,6 +2250,17 @@ dependencies = [ "cfg-if", "cfg_aliases", "libc", + "memoffset", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", ] [[package]] @@ -1931,6 +2297,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6673768db2d862beb9b39a78fdcb1a69439615d5794a1be50caa9bc92c81967" + [[package]] name = "num-derive" version = "0.4.2" @@ -1939,7 +2311,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -1971,6 +2343,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "once_cell" version = "1.21.4" @@ -1989,6 +2370,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" +[[package]] +name = "ordered-float" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bb71e1b3fa6ca1c61f383464aaf2bb0e2f8e772a1f01d486832464de363b951" +dependencies = [ + "num-traits", +] + [[package]] name = "parking_lot" version = "0.12.5" @@ -2067,17 +2457,112 @@ version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" +[[package]] +name = "pest" +version = "2.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0848c601009d37dfa3430c4666e147e49cdcf1b92ecd3e63657d8a5f19da662" +dependencies = [ + "memchr", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11f486f1ea21e6c10ed15d5a7c77165d0ee443402f0780849d1768e7d9d6fe77" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8040c4647b13b210a963c1ed407c1ff4fdfa01c31d6d2a098218702e6664f94f" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "pest_meta" +version = "2.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89815c69d36021a140146f26659a81d6c2afa33d216d736dd4be5381a7362220" +dependencies = [ + "pest", + "sha2", +] + [[package]] name = "petgraph" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8701b58ea97060d5e5b155d383a69952a60943f0e6dfe30b04c287beb0b27455" dependencies = [ - "fixedbitset", + "fixedbitset 0.5.7", "hashbrown 0.15.5", "indexmap", ] +[[package]] +name = "phf" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" +dependencies = [ + "phf_macros", + "phf_shared", +] + +[[package]] +name = "phf_codegen" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aef8048c789fa5e851558d709946d6d79a8ff88c0440c587967f8e94bfb1216a" +dependencies = [ + "phf_generator", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" +dependencies = [ + "phf_shared", + "rand 0.8.5", +] + +[[package]] +name = "phf_macros" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f84ac04429c13a7ff43785d75ad27569f2951ce0ffd30a3321230db2fc727216" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "phf_shared" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" +dependencies = [ + "siphasher", +] + [[package]] name = "pin-project-lite" version = "0.2.17" @@ -2124,6 +2609,12 @@ dependencies = [ "zerovec", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.21" @@ -2140,7 +2631,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" dependencies = [ "proc-macro2", - "syn", + "syn 2.0.117", ] [[package]] @@ -2168,7 +2659,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52717f9a02b6965224f95ca2a81e2e0c5c43baacd28ca057577988930b6c3d5b" dependencies = [ "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -2196,7 +2687,7 @@ dependencies = [ "prost", "prost-types", "regex", - "syn", + "syn 2.0.117", "tempfile", ] @@ -2210,7 +2701,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -2333,6 +2824,15 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "rand_core 0.6.4", +] + [[package]] name = "rand" version = "0.9.2" @@ -2364,6 +2864,12 @@ dependencies = [ "rand_core 0.9.5", ] +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + [[package]] name = "rand_core" version = "0.9.5" @@ -2379,6 +2885,91 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c8d0fd677905edcbeedbf2edb6494d676f0e98d54d5cf9bda0b061cb8fb8aba" +[[package]] +name = "ratatui" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1ce67fb8ba4446454d1c8dbaeda0557ff5e94d39d5e5ed7f10a65eb4c8266bc" +dependencies = [ + "instability", + "ratatui-core", + "ratatui-crossterm", + "ratatui-macros", + "ratatui-termwiz", + "ratatui-widgets", +] + +[[package]] +name = "ratatui-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ef8dea09a92caaf73bff7adb70b76162e5937524058a7e5bff37869cbbec293" +dependencies = [ + "bitflags 2.11.0", + "compact_str", + "hashbrown 0.16.1", + "indoc", + "itertools", + "kasuari", + "lru", + "strum", + "thiserror 2.0.18", + "unicode-segmentation", + "unicode-truncate", + "unicode-width", +] + +[[package]] +name = "ratatui-crossterm" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "577c9b9f652b4c121fb25c6a391dd06406d3b092ba68827e6d2f09550edc54b3" +dependencies = [ + "cfg-if", + "crossterm", + "instability", + "ratatui-core", +] + +[[package]] +name = "ratatui-macros" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7f1342a13e83e4bb9d0b793d0ea762be633f9582048c892ae9041ef39c936f4" +dependencies = [ + "ratatui-core", + "ratatui-widgets", +] + +[[package]] +name = "ratatui-termwiz" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f76fe0bd0ed4295f0321b1676732e2454024c15a35d01904ddb315afd3d545c" +dependencies = [ + "ratatui-core", + "termwiz", +] + +[[package]] +name = "ratatui-widgets" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7dbfa023cd4e604c2553483820c5fe8aa9d71a42eea5aa77c6e7f35756612db" +dependencies = [ + "bitflags 2.11.0", + "hashbrown 0.16.1", + "indoc", + "instability", + "itertools", + "line-clipping", + "ratatui-core", + "strum", + "time", + "unicode-segmentation", + "unicode-width", +] + [[package]] name = "rav1e" version = "0.8.1" @@ -2551,6 +3142,15 @@ version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "1.1.4" @@ -2776,7 +3376,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -2859,6 +3459,17 @@ dependencies = [ "digest", ] +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "digest", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -2874,6 +3485,27 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "signal-hook" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d881a16cf4426aa584979d30bd82cb33429027e42122b169753d6ef1085ed6e2" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-mio" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b75a19a7a740b25bc7944bdee6172368f988763b744e3d4dfe753f6b4ece40cc" +dependencies = [ + "libc", + "mio", + "signal-hook", +] + [[package]] name = "signal-hook-registry" version = "1.4.8" @@ -2899,6 +3531,12 @@ dependencies = [ "quote", ] +[[package]] +name = "siphasher" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e" + [[package]] name = "slab" version = "0.4.12" @@ -2940,18 +3578,56 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "strsim" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "strum" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.117", +] + [[package]] name = "subtle" version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.117" @@ -2980,7 +3656,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3017,6 +3693,69 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "terminfo" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4ea810f0692f9f51b382fff5893887bb4580f5fa246fde546e0b13e7fcee662" +dependencies = [ + "fnv", + "nom 7.1.3", + "phf", + "phf_codegen", +] + +[[package]] +name = "termios" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "411c5bf740737c7918b8b1fe232dca4dc9f8e754b8ad5e20966814001ed0ac6b" +dependencies = [ + "libc", +] + +[[package]] +name = "termwiz" +version = "0.23.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4676b37242ccbd1aabf56edb093a4827dc49086c0ffd764a5705899e0f35f8f7" +dependencies = [ + "anyhow", + "base64", + "bitflags 2.11.0", + "fancy-regex", + "filedescriptor", + "finl_unicode", + "fixedbitset 0.4.2", + "hex", + "lazy_static", + "libc", + "log", + "memmem", + "nix 0.29.0", + "num-derive", + "num-traits", + "ordered-float", + "pest", + "pest_derive", + "phf", + "sha2", + "signal-hook", + "siphasher", + "terminfo", + "termios", + "thiserror 1.0.69", + "ucd-trie", + "unicode-segmentation", + "vtparse", + "wezterm-bidi", + "wezterm-blob-leases", + "wezterm-color-types", + "wezterm-dynamic", + "wezterm-input-types", + "winapi", +] + [[package]] name = "thiserror" version = "1.0.69" @@ -3043,7 +3782,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3054,7 +3793,7 @@ checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3080,6 +3819,27 @@ dependencies = [ "zune-jpeg", ] +[[package]] +name = "time" +version = "0.3.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" +dependencies = [ + "deranged", + "libc", + "num-conv", + "num_threads", + "powerfmt", + "serde_core", + "time-core", +] + +[[package]] +name = "time-core" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" + [[package]] name = "tinystr" version = "0.8.2" @@ -3130,7 +3890,7 @@ checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3252,7 +4012,7 @@ checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3323,6 +4083,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" +[[package]] +name = "ucd-trie" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" + [[package]] name = "unescaper" version = "0.1.8" @@ -3338,6 +4104,23 @@ version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +[[package]] +name = "unicode-segmentation" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9629274872b2bfaf8d66f5f15725007f635594914870f65218920345aa11aa8c" + +[[package]] +name = "unicode-truncate" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b380a1238663e5f8a691f9039c73e1cdae598a30e9855f541d29b08b53e9a5" +dependencies = [ + "itertools", + "unicode-segmentation", + "unicode-width", +] + [[package]] name = "unicode-width" version = "0.2.2" @@ -3398,6 +4181,7 @@ version = "1.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a68d3c8f01c0cfa54a75291d83601161799e4a89a39e0929f4b0354d88757a37" dependencies = [ + "atomic", "getrandom 0.4.2", "js-sys", "wasm-bindgen", @@ -3426,6 +4210,15 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "vtparse" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d9b2acfb050df409c972a37d3b8e08cdea3bddb0c09db9d53137e504cfabed0" +dependencies = [ + "utf8parse", +] + [[package]] name = "walkdir" version = "2.5.0" @@ -3515,7 +4308,7 @@ dependencies = [ "bumpalo", "proc-macro2", "quote", - "syn", + "syn 2.0.117", "wasm-bindgen-shared", ] @@ -3597,6 +4390,78 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88" +[[package]] +name = "wezterm-bidi" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0a6e355560527dd2d1cf7890652f4f09bb3433b6aadade4c9b5ed76de5f3ec" +dependencies = [ + "log", + "wezterm-dynamic", +] + +[[package]] +name = "wezterm-blob-leases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692daff6d93d94e29e4114544ef6d5c942a7ed998b37abdc19b17136ea428eb7" +dependencies = [ + "getrandom 0.3.4", + "mac_address", + "sha2", + "thiserror 1.0.69", + "uuid", +] + +[[package]] +name = "wezterm-color-types" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7de81ef35c9010270d63772bebef2f2d6d1f2d20a983d27505ac850b8c4b4296" +dependencies = [ + "csscolorparser", + "deltae", + "lazy_static", + "wezterm-dynamic", +] + +[[package]] +name = "wezterm-dynamic" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f2ab60e120fd6eaa68d9567f3226e876684639d22a4219b313ff69ec0ccd5ac" +dependencies = [ + "log", + "ordered-float", + "strsim", + "thiserror 1.0.69", + "wezterm-dynamic-derive", +] + +[[package]] +name = "wezterm-dynamic-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46c0cf2d539c645b448eaffec9ec494b8b19bd5077d9e58cb1ae7efece8d575b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "wezterm-input-types" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7012add459f951456ec9d6c7e6fc340b1ce15d6fc9629f8c42853412c029e57e" +dependencies = [ + "bitflags 1.3.2", + "euclid", + "lazy_static", + "serde", + "wezterm-dynamic", +] + [[package]] name = "winapi" version = "0.3.9" @@ -3649,7 +4514,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3660,7 +4525,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3950,7 +4815,7 @@ dependencies = [ "heck", "indexmap", "prettyplease", - "syn", + "syn 2.0.117", "wasm-metadata", "wit-bindgen-core", "wit-component", @@ -3966,7 +4831,7 @@ dependencies = [ "prettyplease", "proc-macro2", "quote", - "syn", + "syn 2.0.117", "wit-bindgen-core", "wit-bindgen-rust", ] @@ -4039,7 +4904,7 @@ checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", "synstructure", ] @@ -4060,7 +4925,7 @@ checksum = "0e8bc7269b54418e7aeeef514aa68f8690b8c0489a06b0136e5f57c4c5ccab89" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -4080,7 +4945,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", "synstructure", ] @@ -4144,7 +5009,7 @@ checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 8f91bf0..48bc067 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ members = [ "apps/client-tui", "apps/dashboard/backend", "apps/db-logger", - "apps/flasher", + "apps/flasher", "apps/motherboard", "apps/sensor-server", "apps/spiview", "lib/rust/amber-connect", diff --git a/apps/motherboard/Cargo.toml b/apps/motherboard/Cargo.toml new file mode 100644 index 0000000..56a88f1 --- /dev/null +++ b/apps/motherboard/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "motherboard" +version = "0.1.0" +edition = "2024" + +[dependencies] +anyhow = "1.0.102" +crossterm = "0.29.0" +futures = "0.3.32" +prost = "0.14.3" +proto = { version = "0.1.0", path = "../../lib/rust/proto" } +ratatui = "0.30.0" +serde = "1.0.228" +serial = { version = "0.1.0", path = "../../lib/rust/serial" } +tokio = { version = "1.50.0", features = ["rt", "time"] } +tokio-serial = "5.4.5" +tokio-util = "0.7.18" + +[lints] +workspace = true diff --git a/apps/motherboard/src/main.rs b/apps/motherboard/src/main.rs new file mode 100644 index 0000000..e4b7fcf --- /dev/null +++ b/apps/motherboard/src/main.rs @@ -0,0 +1,99 @@ +use crossterm::{ + event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers}, + execute, + terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode}, +}; +use futures::FutureExt; +use proto::sensor::{Command, Status}; +use ratatui::{ + Terminal, + prelude::CrosstermBackend, + widgets::{Block, Borders, Paragraph}, +}; +use tokio::{ + select, + sync::mpsc::{self, Receiver}, + task::JoinSet, +}; +use tokio_serial::UsbPortInfo; +use tokio_util::sync::CancellationToken; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let (status_tx, status_rx) = mpsc::channel::(100); + let (_command_tx, command_rx) = mpsc::channel::(100); // Unused + + let stop = CancellationToken::new(); + + let mut services = JoinSet::>::new(); + services.spawn(serial::run(command_rx, status_tx, is_base_station, stop.clone()).map(Ok)); + services.spawn(printer(status_rx, stop.clone())); + services.spawn(input_handler(stop.clone())); + + while services.join_next().await.is_some() { + stop.cancel(); + } + + services.join_all().await; + + Ok(()) +} + +async fn input_handler(stop: CancellationToken) -> anyhow::Result<()> { + stop.run_until_cancelled(async { + loop { + let event = tokio::task::spawn_blocking(event::read).await??; + if let Event::Key(KeyEvent { + code, + modifiers, + kind: KeyEventKind::Press, + .. + }) = event + { + match code { + KeyCode::Char('q') => break, + KeyCode::Char('c') if modifiers.contains(KeyModifiers::CONTROL) => break, + _ => {} + } + } + } + + Ok(()) + }) + .await + .unwrap_or(Ok(())) +} + +async fn printer(mut status_rx: Receiver, stop: CancellationToken) -> anyhow::Result<()> { + enable_raw_mode()?; + let mut stdout = std::io::stdout(); + execute!(stdout, EnterAlternateScreen)?; + let backend = CrosstermBackend::new(stdout); + let mut terminal = Terminal::new(backend)?; + + loop { + select! { + status = status_rx.recv() => { + let text = format!("{status:#?}"); + terminal.draw(|f| { + let area = f.area(); + let para = Paragraph::new(text).block(Block::default().borders(Borders::NONE)); + f.render_widget(para, area); + })?; + } + + () = stop.cancelled() => { + break; + } + } + } + + disable_raw_mode()?; + execute!(terminal.backend_mut(), LeaveAlternateScreen)?; + + Ok(()) +} + +fn is_base_station(info: &UsbPortInfo) -> bool { + info.manufacturer.as_deref() == Some("Amber") && info.product.as_deref() == Some("Base Station") +} From b3f07a9a68c7cb8a8826f493105a36310e7b27b2 Mon Sep 17 00:00:00 2001 From: Ivan Lange Date: Sun, 5 Apr 2026 22:02:56 -0400 Subject: [PATCH 11/13] Working with some power mux logic removed --- apps/motherboard/src/main.rs | 2 +- boards/motherboard/Inc/main.h | 6 +- boards/motherboard/Inc/stm32g0xx_hal_conf.h | 2 +- boards/motherboard/Inc/stm32g0xx_it.h | 1 + boards/motherboard/Inc/usart.h | 51 +++++ boards/motherboard/motherboard.ioc | 182 ++++++++++-------- .../src/backscatter/backscatter.cpp | 59 ++++++ .../src/backscatter/backscatter.hpp | 12 ++ boards/motherboard/src/carrier/carrier.cpp | 30 ++- boards/motherboard/src/gpio.c | 6 +- boards/motherboard/src/main.c | 4 + boards/motherboard/src/power/power.cpp | 15 +- boards/motherboard/src/serial/serial.cpp | 17 +- boards/motherboard/src/spi.c | 12 +- boards/motherboard/src/stm32g0xx_it.c | 15 ++ boards/motherboard/src/tasks.cpp | 9 +- boards/motherboard/src/thermal/thermal.cpp | 38 ++-- boards/motherboard/src/usart.c | 134 +++++++++++++ boards/motherboard/src/usbd_cdc_if.c | 35 ---- lib/periph/spi.hpp | 11 -- proto/base_station.proto | 3 + 21 files changed, 460 insertions(+), 184 deletions(-) create mode 100644 boards/motherboard/Inc/usart.h create mode 100644 boards/motherboard/src/backscatter/backscatter.cpp create mode 100644 boards/motherboard/src/backscatter/backscatter.hpp create mode 100644 boards/motherboard/src/usart.c diff --git a/apps/motherboard/src/main.rs b/apps/motherboard/src/main.rs index e4b7fcf..f252f99 100644 --- a/apps/motherboard/src/main.rs +++ b/apps/motherboard/src/main.rs @@ -4,7 +4,7 @@ use crossterm::{ terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode}, }; use futures::FutureExt; -use proto::sensor::{Command, Status}; +use proto::base_station::{Command, Status}; use ratatui::{ Terminal, prelude::CrosstermBackend, diff --git a/boards/motherboard/Inc/main.h b/boards/motherboard/Inc/main.h index 33a7c13..e02e69f 100644 --- a/boards/motherboard/Inc/main.h +++ b/boards/motherboard/Inc/main.h @@ -79,8 +79,8 @@ void Error_Handler(void); #define DAC_ADJ_GPIO_Port GPIOA #define LPA_PWR_DET_Pin GPIO_PIN_7 #define LPA_PWR_DET_GPIO_Port GPIOA -#define COMPARATOR_Pin GPIO_PIN_5 -#define COMPARATOR_GPIO_Port GPIOC +#define BACKSCATTER_READ_Pin GPIO_PIN_5 +#define BACKSCATTER_READ_GPIO_Port GPIOC #define PWR_DOWN_Pin GPIO_PIN_0 #define PWR_DOWN_GPIO_Port GPIOB #define PWR_DOWN_EXTI_IRQn EXTI0_1_IRQn @@ -161,6 +161,8 @@ void Error_Handler(void); /* USER CODE BEGIN Private defines */ extern int pwr_down_flag; +extern uint8_t uartByte; +extern uint8_t uartReceiveCount; /* USER CODE END Private defines */ #ifdef __cplusplus diff --git a/boards/motherboard/Inc/stm32g0xx_hal_conf.h b/boards/motherboard/Inc/stm32g0xx_hal_conf.h index 75c244d..e81375d 100644 --- a/boards/motherboard/Inc/stm32g0xx_hal_conf.h +++ b/boards/motherboard/Inc/stm32g0xx_hal_conf.h @@ -55,7 +55,7 @@ extern "C" { /* #define HAL_SMBUS_MODULE_ENABLED */ #define HAL_SPI_MODULE_ENABLED #define HAL_TIM_MODULE_ENABLED -/* #define HAL_UART_MODULE_ENABLED */ +#define HAL_UART_MODULE_ENABLED /* #define HAL_USART_MODULE_ENABLED */ /* #define HAL_WWDG_MODULE_ENABLED */ #define HAL_GPIO_MODULE_ENABLED diff --git a/boards/motherboard/Inc/stm32g0xx_it.h b/boards/motherboard/Inc/stm32g0xx_it.h index 9216c45..ed5eee8 100644 --- a/boards/motherboard/Inc/stm32g0xx_it.h +++ b/boards/motherboard/Inc/stm32g0xx_it.h @@ -51,6 +51,7 @@ void HardFault_Handler(void); void EXTI0_1_IRQHandler(void); void USB_UCPD1_2_IRQHandler(void); void TIM1_BRK_UP_TRG_COM_IRQHandler(void); +void USART3_4_5_6_LPUART1_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/boards/motherboard/Inc/usart.h b/boards/motherboard/Inc/usart.h new file mode 100644 index 0000000..27f3ce5 --- /dev/null +++ b/boards/motherboard/Inc/usart.h @@ -0,0 +1,51 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file usart.h + * @brief This file contains all the function prototypes for + * the usart.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USART_H__ +#define __USART_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern UART_HandleTypeDef huart3; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_USART3_UART_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USART_H__ */ diff --git a/boards/motherboard/motherboard.ioc b/boards/motherboard/motherboard.ioc index 218b074..ead5229 100644 --- a/boards/motherboard/motherboard.ioc +++ b/boards/motherboard/motherboard.ioc @@ -31,9 +31,10 @@ Mcu.IP5=SPI2 Mcu.IP6=SPI3 Mcu.IP7=SYS Mcu.IP8=TIM2 -Mcu.IP9=USB_DEVICE -Mcu.IP10=USB_DRD_FS -Mcu.IPNb=11 +Mcu.IP9=USART3 +Mcu.IP10=USB_DEVICE +Mcu.IP11=USB_DRD_FS +Mcu.IPNb=12 Mcu.Name=STM32G0B1V(B-C-E)Tx Mcu.Package=LQFP100 Mcu.Pin0=PB9 @@ -64,77 +65,78 @@ Mcu.Pin24=PA4 Mcu.Pin25=PA5 Mcu.Pin26=PA6 Mcu.Pin27=PA7 -Mcu.Pin28=PC5 -Mcu.Pin29=PB0 -Mcu.Pin30=PB1 -Mcu.Pin31=PB2 -Mcu.Pin32=PF6 -Mcu.Pin33=PF7 -Mcu.Pin34=PE7 -Mcu.Pin35=PE8 -Mcu.Pin36=PE9 -Mcu.Pin37=PE10 -Mcu.Pin38=PE11 -Mcu.Pin39=PE12 -Mcu.Pin40=PE13 -Mcu.Pin41=PE14 -Mcu.Pin42=PE15 -Mcu.Pin43=PB10 -Mcu.Pin44=PB11 -Mcu.Pin45=PB12 -Mcu.Pin46=PB13 -Mcu.Pin47=PB14 -Mcu.Pin48=PB15 -Mcu.Pin49=PA8 -Mcu.Pin50=PA9 -Mcu.Pin51=PC6 -Mcu.Pin52=PC7 -Mcu.Pin53=PD8 -Mcu.Pin54=PD9 -Mcu.Pin55=PD10 -Mcu.Pin56=PD11 -Mcu.Pin57=PD12 -Mcu.Pin58=PD13 -Mcu.Pin59=PD14 -Mcu.Pin60=PD15 -Mcu.Pin61=PA10 -Mcu.Pin62=PA11 [PA9] -Mcu.Pin63=PA12 [PA10] -Mcu.Pin64=PF8 -Mcu.Pin65=PA13 -Mcu.Pin66=PA14-BOOT0 -Mcu.Pin67=PA15 -Mcu.Pin68=PC8 -Mcu.Pin69=PC9 -Mcu.Pin70=PD0 -Mcu.Pin71=PD1 -Mcu.Pin72=PD2 -Mcu.Pin73=PD3 -Mcu.Pin74=PD4 -Mcu.Pin75=PD5 -Mcu.Pin76=PD6 -Mcu.Pin77=PD7 -Mcu.Pin78=PF9 -Mcu.Pin79=PF10 -Mcu.Pin80=PF11 -Mcu.Pin81=PF12 -Mcu.Pin82=PF13 -Mcu.Pin83=PB3 -Mcu.Pin84=PB4 -Mcu.Pin85=PB5 -Mcu.Pin86=PE0 -Mcu.Pin87=PE1 -Mcu.Pin88=PE2 -Mcu.Pin89=PE3 -Mcu.Pin90=PB6 -Mcu.Pin91=PB7 -Mcu.Pin92=PB8 -Mcu.Pin93=VP_FREERTOS_VS_CMSIS_V1 -Mcu.Pin94=VP_SYS_VS_tim1 -Mcu.Pin95=VP_SYS_VS_DBSignals -Mcu.Pin96=VP_TIM2_VS_ClockSourceINT -Mcu.Pin97=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS -Mcu.PinsNb=98 +Mcu.Pin28=PC4 +Mcu.Pin29=PC5 +Mcu.Pin30=PB0 +Mcu.Pin31=PB1 +Mcu.Pin32=PB2 +Mcu.Pin33=PF6 +Mcu.Pin34=PF7 +Mcu.Pin35=PE7 +Mcu.Pin36=PE8 +Mcu.Pin37=PE9 +Mcu.Pin38=PE10 +Mcu.Pin39=PE11 +Mcu.Pin40=PE12 +Mcu.Pin41=PE13 +Mcu.Pin42=PE14 +Mcu.Pin43=PE15 +Mcu.Pin44=PB10 +Mcu.Pin45=PB11 +Mcu.Pin46=PB12 +Mcu.Pin47=PB13 +Mcu.Pin48=PB14 +Mcu.Pin49=PB15 +Mcu.Pin50=PA8 +Mcu.Pin51=PA9 +Mcu.Pin52=PC6 +Mcu.Pin53=PC7 +Mcu.Pin54=PD8 +Mcu.Pin55=PD9 +Mcu.Pin56=PD10 +Mcu.Pin57=PD11 +Mcu.Pin58=PD12 +Mcu.Pin59=PD13 +Mcu.Pin60=PD14 +Mcu.Pin61=PD15 +Mcu.Pin62=PA10 +Mcu.Pin63=PA11 [PA9] +Mcu.Pin64=PA12 [PA10] +Mcu.Pin65=PF8 +Mcu.Pin66=PA13 +Mcu.Pin67=PA14-BOOT0 +Mcu.Pin68=PA15 +Mcu.Pin69=PC8 +Mcu.Pin70=PC9 +Mcu.Pin71=PD0 +Mcu.Pin72=PD1 +Mcu.Pin73=PD2 +Mcu.Pin74=PD3 +Mcu.Pin75=PD4 +Mcu.Pin76=PD5 +Mcu.Pin77=PD6 +Mcu.Pin78=PD7 +Mcu.Pin79=PF9 +Mcu.Pin80=PF10 +Mcu.Pin81=PF11 +Mcu.Pin82=PF12 +Mcu.Pin83=PF13 +Mcu.Pin84=PB3 +Mcu.Pin85=PB4 +Mcu.Pin86=PB5 +Mcu.Pin87=PE0 +Mcu.Pin88=PE1 +Mcu.Pin89=PE2 +Mcu.Pin90=PE3 +Mcu.Pin91=PB6 +Mcu.Pin92=PB7 +Mcu.Pin93=PB8 +Mcu.Pin94=VP_FREERTOS_VS_CMSIS_V1 +Mcu.Pin95=VP_SYS_VS_tim1 +Mcu.Pin96=VP_SYS_VS_DBSignals +Mcu.Pin97=VP_TIM2_VS_ClockSourceINT +Mcu.Pin98=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS +Mcu.PinsNb=99 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32G0B1VETx @@ -153,6 +155,7 @@ NVIC.SysTick_IRQn=true\:3\:0\:false\:false\:false\:true\:false\:true\:false NVIC.TIM1_BRK_UP_TRG_COM_IRQn=true\:3\:0\:false\:false\:true\:false\:false\:true\:true NVIC.TimeBaseIP=TIM1 NVIC.TimeBase=TIM1_BRK_UP_TRG_COM_IRQn +NVIC.USART3_4_5_6_LPUART1_IRQn=true\:3\:0\:false\:false\:true\:true\:true\:true\:true NVIC.USB_UCPD1_2_IRQn=true\:3\:0\:false\:false\:true\:true\:true\:true\:true PA0.GPIOParameters=GPIO_Label PA0.GPIO_Label=LOG_VSENSE @@ -246,10 +249,12 @@ PC2.GPIO_Label=LOGAMP_EN PC2.Locked=true PC2.Signal=GPIO_Output PC3.Locked=true +PC4.Mode=Asynchronous +PC4.Signal=USART3_TX PC5.GPIOParameters=GPIO_Label -PC5.GPIO_Label=COMPARATOR -PC5.Locked=true -PC5.Signal=GPIO_Input +PC5.GPIO_Label=BACKSCATTER_READ +PC5.Mode=Asynchronous +PC5.Signal=USART3_RX PC6.GPIOParameters=GPIO_Label PC6.GPIO_Label=WARN_LIGHT PC6.Locked=true @@ -265,11 +270,10 @@ PC9.GPIOParameters=GPIO_Label PC9.GPIO_Label=P12V_VSENSE PC9.Locked=true PC9.Signal=GPIO_Input -PC10.Mode=Full_Duplex_Master +PC10.Mode=Simplex_Bidirectional_Master PC10.Signal=SPI3_SCK -PC11.Mode=Full_Duplex_Master -PC11.Signal=SPI3_MISO -PC12.Mode=Full_Duplex_Master +PC11.Locked=true +PC12.Mode=Simplex_Bidirectional_Master PC12.Signal=SPI3_MOSI PC13.GPIOParameters=GPIO_Label PC13.GPIO_Label=TEMP_ALERT_N @@ -445,7 +449,7 @@ ProjectManager.ToolChainLocation= ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=true -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USB_Device_Init-USB_DEVICE-false-HAL-false,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_DAC1_Init-DAC1-false-HAL-true,6-MX_SPI2_Init-SPI2-false-HAL-true,7-MX_SPI3_Init-SPI3-false-HAL-true,8-MX_TIM2_Init-TIM2-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USB_Device_Init-USB_DEVICE-false-HAL-false,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_DAC1_Init-DAC1-false-HAL-true,6-MX_SPI2_Init-SPI2-false-HAL-true,7-MX_SPI3_Init-SPI3-false-HAL-true,8-MX_TIM2_Init-TIM2-false-HAL-true,9-MX_USART3_UART_Init-USART3-false-HAL-true RCC.AHBFreq_Value=16000000 RCC.APBFreq_Value=16000000 RCC.APBTimFreq_Value=16000000 @@ -499,11 +503,13 @@ SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,NSSPMode SPI2.Mode=SPI_MODE_MASTER SPI2.NSSPMode=SPI_NSS_PULSE_DISABLE SPI2.VirtualType=VM_MASTER -SPI3.CalculateBaudRate=8.0 MBits/s +SPI3.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_16 +SPI3.CalculateBaudRate=1000.0 KBits/s SPI3.DataSize=SPI_DATASIZE_8BIT -SPI3.Direction=SPI_DIRECTION_2LINES -SPI3.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize +SPI3.Direction=SPI_DIRECTION_1LINE +SPI3.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,NSSPMode,BaudRatePrescaler SPI3.Mode=SPI_MODE_MASTER +SPI3.NSSPMode=SPI_NSS_PULSE_DISABLE SPI3.VirtualType=VM_MASTER TIM2.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE TIM2.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4 @@ -511,6 +517,12 @@ TIM2.IPParameters=Prescaler,Period,AutoReloadPreload,Channel-PWM Generation4 CH4 TIM2.OCPolarity_4=TIM_OCPOLARITY_LOW TIM2.Period=999 TIM2.Prescaler=16 +USART3.BaudRate=245 +USART3.IPParameters=VirtualMode-Asynchronous,BaudRate,StopBits,TxPinLevelInvertParam,Mode +USART3.Mode=MODE_RX +USART3.StopBits=STOPBITS_2 +USART3.TxPinLevelInvertParam=ADVFEATURE_TXINV_ENABLE +USART3.VirtualMode-Asynchronous=VM_ASYNC USB_DEVICE.CLASS_NAME_FS=CDC USB_DEVICE.IPParameters=VirtualMode,VirtualModeFS,CLASS_NAME_FS,MANUFACTURER_STRING,PRODUCT_STRING_CDC_FS USB_DEVICE.MANUFACTURER_STRING=Amber diff --git a/boards/motherboard/src/backscatter/backscatter.cpp b/boards/motherboard/src/backscatter/backscatter.cpp new file mode 100644 index 0000000..d56b2e0 --- /dev/null +++ b/boards/motherboard/src/backscatter/backscatter.cpp @@ -0,0 +1,59 @@ +#include "backscatter.hpp" + +#include "periph/analog_input.hpp" +#include "periph/analog_output.hpp" +#include "periph/digital.hpp" + +// CubeMX +#include "dac.h" +#include "gpio.h" +#include "usart.h" + +namespace backscatter { + +namespace { + +static amber::periph::AnalogOutput logv(hdac1, DAC1_CHANNEL_2); +static amber::periph::DigitalOutput debug2(*DEBUG2_GPIO_Port, DEBUG2_Pin); +static amber::periph::DigitalInput comparator(*BACKSCATTER_READ_GPIO_Port, + BACKSCATTER_READ_Pin); +} // namespace + +auto Init() noexcept -> void { + logv.SetVoltage(0.8f); + + HAL_UART_Receive_IT(&huart3, &uartByte, 1); +} + +auto Update1000hz() noexcept -> void { + static uint8_t counter = 0; + + if (comparator.Read()) { + counter = 10; + } + + if (counter > 0) { + debug2.SetHigh(); + counter--; + } else { + debug2.SetLow(); + } +} + +auto GetUartByte() noexcept -> uint8_t { + return uartByte; +} + +auto GetReceiveCount() noexcept -> uint8_t { + return uartReceiveCount; +} + +} // namespace backscatter + +extern "C" void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) { + if (huart != &huart3) { + return; + } + HAL_UART_Receive_IT(&huart3, &uartByte, 1); + uartReceiveCount++; +} diff --git a/boards/motherboard/src/backscatter/backscatter.hpp b/boards/motherboard/src/backscatter/backscatter.hpp new file mode 100644 index 0000000..9b646d4 --- /dev/null +++ b/boards/motherboard/src/backscatter/backscatter.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace backscatter { + +auto Init() noexcept -> void; +auto Update1000hz() noexcept -> void; +auto GetUartByte() noexcept -> uint8_t; +auto GetReceiveCount() noexcept -> uint8_t; + +} // namespace backscatter \ No newline at end of file diff --git a/boards/motherboard/src/carrier/carrier.cpp b/boards/motherboard/src/carrier/carrier.cpp index 2947475..ebcfb77 100644 --- a/boards/motherboard/src/carrier/carrier.cpp +++ b/boards/motherboard/src/carrier/carrier.cpp @@ -11,7 +11,14 @@ namespace { static amber::periph::DigitalOutput lpaEn(*LPA_EN_GPIO_Port, LPA_EN_Pin); +static amber::periph::DigitalOutput lnaEn(*LNA_EN_GPIO_Port, LNA_EN_Pin); +static amber::periph::DigitalOutput logampEn(*LOGAMP_EN_GPIO_Port, + LOGAMP_EN_Pin); static amber::periph::DigitalOutput vcoCe(*VCO_CE_GPIO_Port, VCO_CE_Pin); +static amber::periph::DigitalOutput fan1En(*FAN1_PWR_EN_GPIO_Port, + FAN1_PWR_EN_Pin); +static amber::periph::DigitalOutput fan1Pwm(*FAN1_PWN_GPIO_Port, FAN1_PWN_Pin); +static amber::periph::DigitalOutput vgaEn(*VGA_EN_GPIO_Port, VGA_EN_Pin); static amber::periph::DigitalInput vcoMuxOut(*VCO_MUXOUT_GPIO_Port, VCO_MUXOUT_Pin); static amber::periph::AnalogInput lpaPowerDetect(hadc1, ADC_CHANNEL_7); @@ -36,13 +43,13 @@ auto ADF5355() -> amber::adf5355::Driver& { namespace carrier { auto Init() noexcept -> void { - if (power::GetPowerMuxState() == power::PowerMuxState::USB_POWER) { - lpaEn.SetLow(); - vcoCe.SetLow(); - } - lpaEn.SetHigh(); + lnaEn.SetHigh(); + logampEn.SetLow(); + fan1En.SetHigh(); + fan1Pwm.SetHigh(); vcoCe.SetHigh(); + vgaEn.SetHigh(); HAL_Delay(10); @@ -52,10 +59,21 @@ auto Init() noexcept -> void { auto Update_100hz() noexcept -> void { vcoLocked = vcoMuxOut.Read(); - if (power::GetPowerMuxState() == power::PowerMuxState::USB_POWER) { + if (powerOffRequested) { lpaEn.SetLow(); + lnaEn.SetLow(); vcoCe.SetLow(); + fan1En.SetLow(); + logampEn.SetHigh(); + vgaEn.SetLow(); return; + } else { + lpaEn.SetHigh(); + lnaEn.SetHigh(); + vcoCe.SetHigh(); + fan1En.SetHigh(); + logampEn.SetLow(); + vgaEn.SetHigh(); } if (pwr_down_flag) { diff --git a/boards/motherboard/src/gpio.c b/boards/motherboard/src/gpio.c index b3a7116..3ab0db2 100644 --- a/boards/motherboard/src/gpio.c +++ b/boards/motherboard/src/gpio.c @@ -85,10 +85,8 @@ void MX_GPIO_Init(void) { GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); - /*Configure GPIO pins : TEMP_ALERT_N_Pin COMPARATOR_Pin P5V_VSENSE_Pin - * P12V_VSENSE_Pin */ - GPIO_InitStruct.Pin = - TEMP_ALERT_N_Pin | COMPARATOR_Pin | P5V_VSENSE_Pin | P12V_VSENSE_Pin; + /*Configure GPIO pins : TEMP_ALERT_N_Pin P5V_VSENSE_Pin P12V_VSENSE_Pin */ + GPIO_InitStruct.Pin = TEMP_ALERT_N_Pin | P5V_VSENSE_Pin | P12V_VSENSE_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); diff --git a/boards/motherboard/src/main.c b/boards/motherboard/src/main.c index fdaa92a..53903ac 100644 --- a/boards/motherboard/src/main.c +++ b/boards/motherboard/src/main.c @@ -25,6 +25,7 @@ #include "gpio.h" #include "spi.h" #include "tim.h" +#include "usart.h" #include "usb_device.h" /* Private includes ----------------------------------------------------------*/ @@ -51,6 +52,8 @@ /* USER CODE BEGIN PV */ int pwr_down_flag = 0; +uint8_t uartByte = 1; +uint8_t uartReceiveCount = 0; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -98,6 +101,7 @@ int main(void) { MX_SPI2_Init(); MX_SPI3_Init(); MX_TIM2_Init(); + MX_USART3_UART_Init(); /* USER CODE BEGIN 2 */ MX_USB_Device_Init(); /* USER CODE END 2 */ diff --git a/boards/motherboard/src/power/power.cpp b/boards/motherboard/src/power/power.cpp index 71f409f..9b428c4 100644 --- a/boards/motherboard/src/power/power.cpp +++ b/boards/motherboard/src/power/power.cpp @@ -134,12 +134,12 @@ auto P12VHsd() -> amber::tps1h100::Driver& { namespace power { auto Init() noexcept -> void { - if (GetPowerMuxState() == PowerMuxState::USB_POWER) { - P6VHsd1().disableAll(); - P6VHsd2().disableAll(); - P6VScatter().disable(); - return; - } + // if (GetPowerMuxState() == PowerMuxState::USB_POWER) { + // P6VHsd1().disableAll(); + // P6VHsd2().disableAll(); + // P6VScatter().disable(); + // return; + // } P6VHsd1().enableAll(); P6VHsd2().enableAll(); @@ -155,8 +155,7 @@ auto Update_100hz() noexcept -> void { powerMuxState = powerMux.Read() ? PowerMuxState::BARREL_JACK : PowerMuxState::USB_POWER; - if (GetPowerMuxState() == PowerMuxState::USB_POWER || - carrier::GetPowerDown()) { + if (carrier::GetPowerDown()) { P6VHsd1().disableAll(); P6VHsd2().disableAll(); P6VScatter().disable(); diff --git a/boards/motherboard/src/serial/serial.cpp b/boards/motherboard/src/serial/serial.cpp index fac1b7f..c43e133 100644 --- a/boards/motherboard/src/serial/serial.cpp +++ b/boards/motherboard/src/serial/serial.cpp @@ -1,5 +1,8 @@ #include "serial.hpp" +#include "Src/backscatter/backscatter.hpp" +#include "Src/power/power.hpp" +#include "Src/thermal/thermal.hpp" #include "cobs.hpp" #include "common_macros.hpp" @@ -34,15 +37,15 @@ static amber::cobs::Decoder<1024> rx_decoder; // TX State static uint8_t tx_counter = 0; static uint8_t pb_buffer[BASE_STATION_STATUS_SIZE]; -static uint8_t cobs_buffer[amber::cobs::MaxEncodedLength(BASE_STATION_STATUS_SIZE)]; +static uint8_t + cobs_buffer[amber::cobs::MaxEncodedLength(BASE_STATION_STATUS_SIZE)]; static base_station_command_t last_command; static void HandleCommand(base_station_command_t* cmd); static void SendStatus(void); -void Init(void) { -} +void Init(void) {} void Update_100hz(void) { SendStatus(); @@ -70,9 +73,15 @@ void Receive(void) { void SendStatus(void) { base_station_status_t status = BASE_STATION_STATUS_INIT_ZERO; status.has_tx_counter = true; - status.tx_counter = tx_counter; + status.tx_counter = tx_counter++; status.has_rx_counter = true; status.rx_counter = rx_counter; + status.has_temperature = true; + status.temperature = thermal::GetCarrierTemp(); + status.has_uart_byte = true; + status.uart_byte = backscatter::GetUartByte(); + status.has_uart_receive_count = true; + status.uart_receive_count = backscatter::GetReceiveCount(); pb_ostream_s ostream = pb_ostream_from_buffer(pb_buffer, COUNTOF(pb_buffer)); diff --git a/boards/motherboard/src/spi.c b/boards/motherboard/src/spi.c index 2b75832..383ab77 100644 --- a/boards/motherboard/src/spi.c +++ b/boards/motherboard/src/spi.c @@ -68,18 +68,18 @@ void MX_SPI3_Init(void) { /* USER CODE END SPI3_Init 1 */ hspi3.Instance = SPI3; hspi3.Init.Mode = SPI_MODE_MASTER; - hspi3.Init.Direction = SPI_DIRECTION_2LINES; + hspi3.Init.Direction = SPI_DIRECTION_1LINE; hspi3.Init.DataSize = SPI_DATASIZE_8BIT; hspi3.Init.CLKPolarity = SPI_POLARITY_LOW; hspi3.Init.CLKPhase = SPI_PHASE_1EDGE; hspi3.Init.NSS = SPI_NSS_SOFT; - hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; + hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi3.Init.TIMode = SPI_TIMODE_DISABLE; hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; hspi3.Init.CRCPolynomial = 7; hspi3.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; - hspi3.Init.NSSPMode = SPI_NSS_PULSE_ENABLE; + hspi3.Init.NSSPMode = SPI_NSS_PULSE_DISABLE; if (HAL_SPI_Init(&hspi3) != HAL_OK) { Error_Handler(); } @@ -122,10 +122,9 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) { __HAL_RCC_GPIOC_CLK_ENABLE(); /**SPI3 GPIO Configuration PC10 ------> SPI3_SCK - PC11 ------> SPI3_MISO PC12 ------> SPI3_MOSI */ - GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12; + GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_12; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; @@ -164,10 +163,9 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) { /**SPI3 GPIO Configuration PC10 ------> SPI3_SCK - PC11 ------> SPI3_MISO PC12 ------> SPI3_MOSI */ - HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12); + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10 | GPIO_PIN_12); /* USER CODE BEGIN SPI3_MspDeInit 1 */ diff --git a/boards/motherboard/src/stm32g0xx_it.c b/boards/motherboard/src/stm32g0xx_it.c index e1e444b..efbb158 100644 --- a/boards/motherboard/src/stm32g0xx_it.c +++ b/boards/motherboard/src/stm32g0xx_it.c @@ -57,6 +57,7 @@ /* External variables --------------------------------------------------------*/ extern PCD_HandleTypeDef hpcd_USB_DRD_FS; +extern UART_HandleTypeDef huart3; extern TIM_HandleTypeDef htim1; /* USER CODE BEGIN EV */ @@ -139,6 +140,20 @@ void TIM1_BRK_UP_TRG_COM_IRQHandler(void) { /* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 1 */ } +/** + * @brief This function handles USART3, USART4, USART5, USART6, LPUART1 globlal + * Interrupts (combined with EXTI 28). + */ +void USART3_4_5_6_LPUART1_IRQHandler(void) { + /* USER CODE BEGIN USART3_4_5_6_LPUART1_IRQn 0 */ + + /* USER CODE END USART3_4_5_6_LPUART1_IRQn 0 */ + HAL_UART_IRQHandler(&huart3); + /* USER CODE BEGIN USART3_4_5_6_LPUART1_IRQn 1 */ + + /* USER CODE END USART3_4_5_6_LPUART1_IRQn 1 */ +} + /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ diff --git a/boards/motherboard/src/tasks.cpp b/boards/motherboard/src/tasks.cpp index eb89840..6e13064 100644 --- a/boards/motherboard/src/tasks.cpp +++ b/boards/motherboard/src/tasks.cpp @@ -1,13 +1,14 @@ #include "tasks.hpp" #include "FreeRTOS.h" +#include "backscatter/backscatter.hpp" #include "carrier/carrier.hpp" #include "lib/periph/digital.hpp" #include "main.h" #include "power/power.hpp" +#include "serial/serial.hpp" #include "task.h" #include "thermal/thermal.hpp" -#include "serial/serial.hpp" #include "tim.h" enum { @@ -37,6 +38,7 @@ auto task_1000hz(void* argument) -> void { while (true) { serial::Receive(); + backscatter::Update1000hz(); vTaskDelayUntil(&wake_time, pdMS_TO_TICKS(1)); } } @@ -79,10 +81,11 @@ auto task_1hz(void* argument) -> void { }; auto MX_FREERTOS_Init() -> void { - serial::Init(); power::Init(); + backscatter::Init(); carrier::Init(); thermal::Init(); + serial::Init(); xTaskCreateStatic(task_1hz, "1Hz", STACK_SIZE_WORDS, NULL, PRIORITY_1HZ, t1hz_stack, &t1hz_ctrl); @@ -113,4 +116,4 @@ void vApplicationGetIdleTaskMemory(StaticTask_t** ppxIdleTaskTCBBuffer, *ppxIdleTaskStackBuffer = uxIdleTaskStack; *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; } -} \ No newline at end of file +} diff --git a/boards/motherboard/src/thermal/thermal.cpp b/boards/motherboard/src/thermal/thermal.cpp index fa986c8..02b8075 100644 --- a/boards/motherboard/src/thermal/thermal.cpp +++ b/boards/motherboard/src/thermal/thermal.cpp @@ -2,6 +2,7 @@ #include +#include "Src/power/power.hpp" #include "lib/tmp126/tmp126.hpp" #include "periph/pwm.hpp" #include "spi.h" @@ -16,7 +17,7 @@ static amber::periph::DigitalOutput fan2En(*FAN2_PWR_EN_GPIO_Port, FAN2_PWR_EN_Pin); static amber::periph::Pwm fan2Pwm(htim2, TIM_CHANNEL_4); -static amber::periph::Spi tempSpi(hspi2, tempCs); +static amber::periph::Spi tempSpi(hspi3, tempCs); static amber::tmp126::Driver tempSensor(tempSpi, amber::tmp126::Config{}); static bool tempSensorReady = false; @@ -25,6 +26,7 @@ constexpr float kAlpha = 0.1f; // EMA smoothing factor constexpr uint8_t kTempRegions = 5; float filteredTemp = 0.0f; +float lastReading = 0.0f; struct Point { float temperature; @@ -32,7 +34,7 @@ struct Point { }; constexpr std::array kThermalCurve{{ - {40.0f, 0}, + {40.0f, 10}, {55.0f, 25}, {70.0f, 55}, {85.0f, 85}, @@ -66,30 +68,32 @@ auto LookupDuty(float temp) -> uint8_t { auto Init() noexcept -> void { filteredTemp = 25.0f; + fan2En.SetHigh(); fan2Pwm.Start(); - fan2Pwm.SetDutyCycle(0.0f); + fan2Pwm.SetDutyCycle(100.0f); - tempSensorReady = (tempSensor.init() == amber::tmp126::Status::OK); - if (!tempSensorReady) { - fan2Pwm.SetDutyCycle(100.0f); - } + // tempSensorReady = (tempSensor.init() == amber::tmp126::Status::OK); + // if (!tempSensorReady) { + // fan2Pwm.SetDutyCycle(100.0f); + // } }; auto Update10Hz() noexcept -> void { - if (!tempSensorReady) { - return; + if (pwr_down_flag) { + fan2Pwm.SetDutyCycle(50.0f); } + // const auto [status, temperature] = tempSensor.readTemperature(); + // if (status != amber::tmp126::Status::OK) { + // tempSensorReady = false; + // fan2Pwm.SetDutyCycle(100.0f); + // return; + // } - const auto [status, temperature] = tempSensor.readTemperature(); - if (status != amber::tmp126::Status::OK) { - tempSensorReady = false; - fan2Pwm.SetDutyCycle(100.0f); - return; - } + // lastReading = temperature; - filteredTemp += kAlpha * (temperature - filteredTemp); - fan2Pwm.SetDutyCycle(LookupDuty(filteredTemp)); + // filteredTemp += kAlpha * (temperature - filteredTemp); + // fan2Pwm.SetDutyCycle(LookupDuty(filteredTemp)); }; auto GetCarrierTemp() noexcept -> float { diff --git a/boards/motherboard/src/usart.c b/boards/motherboard/src/usart.c new file mode 100644 index 0000000..558629d --- /dev/null +++ b/boards/motherboard/src/usart.c @@ -0,0 +1,134 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file usart.c + * @brief This file provides code for the configuration + * of the USART instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2026 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "usart.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +UART_HandleTypeDef huart3; + +/* USART3 init function */ + +void MX_USART3_UART_Init(void) { + /* USER CODE BEGIN USART3_Init 0 */ + + /* USER CODE END USART3_Init 0 */ + + /* USER CODE BEGIN USART3_Init 1 */ + + /* USER CODE END USART3_Init 1 */ + huart3.Instance = USART3; + huart3.Init.BaudRate = 245; + huart3.Init.WordLength = UART_WORDLENGTH_8B; + huart3.Init.StopBits = UART_STOPBITS_2; + huart3.Init.Parity = UART_PARITY_NONE; + huart3.Init.Mode = UART_MODE_RX; + huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart3.Init.OverSampling = UART_OVERSAMPLING_16; + huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; + huart3.Init.ClockPrescaler = UART_PRESCALER_DIV1; + huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_TXINVERT_INIT; + huart3.AdvancedInit.TxPinLevelInvert = UART_ADVFEATURE_TXINV_ENABLE; + if (HAL_UART_Init(&huart3) != HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetTxFifoThreshold(&huart3, UART_TXFIFO_THRESHOLD_1_8) != + HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_SetRxFifoThreshold(&huart3, UART_RXFIFO_THRESHOLD_1_8) != + HAL_OK) { + Error_Handler(); + } + if (HAL_UARTEx_DisableFifoMode(&huart3) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN USART3_Init 2 */ + + /* USER CODE END USART3_Init 2 */ +} + +void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; + if (uartHandle->Instance == USART3) { + /* USER CODE BEGIN USART3_MspInit 0 */ + + /* USER CODE END USART3_MspInit 0 */ + + /** Initializes the peripherals clocks + */ + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART3; + PeriphClkInit.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { + Error_Handler(); + } + + /* USART3 clock enable */ + __HAL_RCC_USART3_CLK_ENABLE(); + + __HAL_RCC_GPIOC_CLK_ENABLE(); + /**USART3 GPIO Configuration + PC4 ------> USART3_TX + PC5 ------> USART3_RX + */ + GPIO_InitStruct.Pin = GPIO_PIN_4 | BACKSCATTER_READ_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF0_USART3; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /* USART3 interrupt Init */ + HAL_NVIC_SetPriority(USART3_4_5_6_LPUART1_IRQn, 3, 0); + HAL_NVIC_EnableIRQ(USART3_4_5_6_LPUART1_IRQn); + /* USER CODE BEGIN USART3_MspInit 1 */ + + /* USER CODE END USART3_MspInit 1 */ + } +} + +void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { + if (uartHandle->Instance == USART3) { + /* USER CODE BEGIN USART3_MspDeInit 0 */ + + /* USER CODE END USART3_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_USART3_CLK_DISABLE(); + + /**USART3 GPIO Configuration + PC4 ------> USART3_TX + PC5 ------> USART3_RX + */ + HAL_GPIO_DeInit(GPIOC, GPIO_PIN_4 | BACKSCATTER_READ_Pin); + + /* USART3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(USART3_4_5_6_LPUART1_IRQn); + /* USER CODE BEGIN USART3_MspDeInit 1 */ + + /* USER CODE END USART3_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/boards/motherboard/src/usbd_cdc_if.c b/boards/motherboard/src/usbd_cdc_if.c index e17508b..ceb28ee 100644 --- a/boards/motherboard/src/usbd_cdc_if.c +++ b/boards/motherboard/src/usbd_cdc_if.c @@ -98,9 +98,6 @@ uint8_t UserRxBufferFS[APP_RX_DATA_SIZE]; uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; /* USER CODE BEGIN PRIVATE_VARIABLES */ -static char cdcCommandBuffer[32]; -static uint8_t cdcCommandLength = 0; - /* USER CODE END PRIVATE_VARIABLES */ /** @@ -135,9 +132,6 @@ static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t* Len); static int8_t CDC_TransmitCplt_FS(uint8_t* pbuf, uint32_t* Len, uint8_t epnum); /* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ -static void CDC_ProcessCommand(const char* command); -static void CDC_SendTemperature(void); - /* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */ /** @@ -321,35 +315,6 @@ static int8_t CDC_TransmitCplt_FS(uint8_t* Buf, uint32_t* Len, uint8_t epnum) { } /* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ - -static void CDC_ProcessCommand(const char* command) { - if (strcmp(command, "temp") == 0 || strcmp(command, "temp?") == 0) { - CDC_SendTemperature(); - return; - } - - static uint8_t unknownResponse[] = "ERR unknown command\r\n"; - (void)CDC_Transmit_FS(unknownResponse, sizeof(unknownResponse) - 1U); -} - -static void CDC_SendTemperature(void) { - const float temperature = Thermal_GetCarrierTempC(); - const int32_t centiC = (int32_t)(temperature * 100.0f + - ((temperature >= 0.0f) ? 0.5f : -0.5f)); - const int32_t whole = centiC / 100; - const int32_t fractional = (centiC < 0 ? -centiC : centiC) % 100; - - static uint8_t response[32]; - const int length = - snprintf((char*)response, sizeof(response), "TEMP %ld.%02ld C\r\n", - (long)whole, (long)fractional); - if (length <= 0) { - return; - } - - (void)CDC_Transmit_FS(response, (uint16_t)length); -} - /* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ /** diff --git a/lib/periph/spi.hpp b/lib/periph/spi.hpp index 9ca0667..2b59e4d 100644 --- a/lib/periph/spi.hpp +++ b/lib/periph/spi.hpp @@ -51,17 +51,6 @@ struct Spi { return status; } - auto transmitThenReceive(const uint8_t* tx, uint16_t txLen, - uint8_t* rx, uint16_t rxLen) noexcept -> HAL_StatusTypeDef { - csAssert(); - auto status = HAL_SPI_Transmit(&_hspi, const_cast(tx), txLen, HAL_MAX_DELAY); - if (status == HAL_OK) { - status = HAL_SPI_Receive(&_hspi, rx, rxLen, HAL_MAX_DELAY); - } - csRelease(); - return status; - } - private: void csAssert() { _csPin.SetLow(); diff --git a/proto/base_station.proto b/proto/base_station.proto index f3b87b7..9284477 100644 --- a/proto/base_station.proto +++ b/proto/base_station.proto @@ -11,4 +11,7 @@ message Status { // Diagnostics optional uint32 tx_counter = 14; optional uint32 rx_counter = 15; + optional float temperature = 16; + optional uint32 uart_byte = 17; + optional uint32 uart_receive_count = 18; } From 84d192fdb26716779c81bc180537ef59b4ad541d Mon Sep 17 00:00:00 2001 From: Ivan Lange Date: Mon, 6 Apr 2026 01:39:07 -0400 Subject: [PATCH 12/13] Update usb diags --- boards/motherboard/src/power/power.cpp | 10 ++- boards/motherboard/src/serial/serial.cpp | 43 +++++++--- boards/motherboard/src/thermal/thermal.cpp | 96 ++++++++++++---------- boards/motherboard/src/thermal/thermal.hpp | 3 +- lib/tmp126/tmp126.cpp | 44 ++++++---- lib/tps274160b/tps274160b.cpp | 2 +- proto/base_station.proto | 44 ++++++++-- 7 files changed, 160 insertions(+), 82 deletions(-) diff --git a/boards/motherboard/src/power/power.cpp b/boards/motherboard/src/power/power.cpp index 9b428c4..e3f4d17 100644 --- a/boards/motherboard/src/power/power.cpp +++ b/boards/motherboard/src/power/power.cpp @@ -8,6 +8,8 @@ namespace { +constexpr float kMilliampsPerAmp = 1000.0f; + static amber::periph::DigitalInput powerMux(*MUX_ST_GPIO_Port, MUX_ST_Pin); static uint8_t hsd1CsIdx = 0; @@ -169,10 +171,10 @@ auto Update_100hz() noexcept -> void { P6VHsd1().selectDiagPin(hsd1CsIdx); P6VHsd2().selectDiagPin(hsd2CsIdx); - hsd1Currents[hsd1CsIdx] = P6VHsd1().getCurrent(); - hsd2Currents[hsd2CsIdx] = P6VHsd2().getCurrent(); - scatterCurrent = P6VScatter().getCurrent(); - p12vCurrent = P12VHsd().getCurrent(); + hsd1Currents[hsd1CsIdx] = P6VHsd1().getCurrent() * kMilliampsPerAmp; + hsd2Currents[hsd2CsIdx] = P6VHsd2().getCurrent() * kMilliampsPerAmp; + scatterCurrent = P6VScatter().getCurrent() * kMilliampsPerAmp; + p12vCurrent = P12VHsd().getCurrent() * kMilliampsPerAmp; hsd1CsIdx = (hsd1CsIdx + 1) % amber::tps274160b::kNumChannels; hsd2CsIdx = (hsd2CsIdx + 1) % amber::tps274160b::kNumChannels; diff --git a/boards/motherboard/src/serial/serial.cpp b/boards/motherboard/src/serial/serial.cpp index c43e133..0f6c5f2 100644 --- a/boards/motherboard/src/serial/serial.cpp +++ b/boards/motherboard/src/serial/serial.cpp @@ -1,6 +1,7 @@ #include "serial.hpp" #include "Src/backscatter/backscatter.hpp" +#include "Src/carrier/carrier.hpp" #include "Src/power/power.hpp" #include "Src/thermal/thermal.hpp" #include "cobs.hpp" @@ -72,16 +73,38 @@ void Receive(void) { void SendStatus(void) { base_station_status_t status = BASE_STATION_STATUS_INIT_ZERO; - status.has_tx_counter = true; - status.tx_counter = tx_counter++; - status.has_rx_counter = true; - status.rx_counter = rx_counter; - status.has_temperature = true; - status.temperature = thermal::GetCarrierTemp(); - status.has_uart_byte = true; - status.uart_byte = backscatter::GetUartByte(); - status.has_uart_receive_count = true; - status.uart_receive_count = backscatter::GetReceiveCount(); + const auto& p6v_hsd1_currents = power::GetP6VHsd1Currents(); + const auto& p6v_hsd2_currents = power::GetP6VHsd2Currents(); + const bool powered_down = carrier::GetPowerDown(); + + status.has_debug = true; + status.debug.tx_counter = tx_counter++; + status.debug.rx_counter = rx_counter; + status.debug.uart_byte = backscatter::GetUartByte(); + status.debug.uart_receive_count = backscatter::GetReceiveCount(); + + status.has_thermal = true; + status.thermal.fan_duty_percent = thermal::GetCurrentFanDuty(); + + status.has_power = true; + status.power.mux_state = + static_cast(power::GetPowerMuxState()); + status.power.powered_down = powered_down; + + if (!powered_down) { + status.power.has_p6v_hsd1 = true; + status.power.p6v_hsd1.channel_1 = p6v_hsd1_currents[0]; + status.power.p6v_hsd1.channel_2 = p6v_hsd1_currents[1]; + status.power.p6v_hsd1.channel_3 = p6v_hsd1_currents[2]; + status.power.p6v_hsd1.channel_4 = p6v_hsd1_currents[3]; + status.power.has_p6v_hsd2 = true; + status.power.p6v_hsd2.channel_1 = p6v_hsd2_currents[0]; + status.power.p6v_hsd2.channel_2 = p6v_hsd2_currents[1]; + status.power.p6v_hsd2.channel_3 = p6v_hsd2_currents[2]; + status.power.p6v_hsd2.channel_4 = p6v_hsd2_currents[3]; + status.power.p6v_scatter_current = power::GetP6VScatterCurrent(); + status.power.p12v_current = power::GetP12VCurrent(); + } pb_ostream_s ostream = pb_ostream_from_buffer(pb_buffer, COUNTOF(pb_buffer)); diff --git a/boards/motherboard/src/thermal/thermal.cpp b/boards/motherboard/src/thermal/thermal.cpp index 02b8075..5207827 100644 --- a/boards/motherboard/src/thermal/thermal.cpp +++ b/boards/motherboard/src/thermal/thermal.cpp @@ -20,58 +20,64 @@ static amber::periph::Pwm fan2Pwm(htim2, TIM_CHANNEL_4); static amber::periph::Spi tempSpi(hspi3, tempCs); static amber::tmp126::Driver tempSensor(tempSpi, amber::tmp126::Config{}); -static bool tempSensorReady = false; -constexpr float kAlpha = 0.1f; // EMA smoothing factor -constexpr uint8_t kTempRegions = 5; +static float currentDuty = 0.0f; -float filteredTemp = 0.0f; -float lastReading = 0.0f; +// static bool tempSensorReady = false; -struct Point { - float temperature; - uint8_t duty; -}; +// constexpr float kAlpha = 0.1f; // EMA smoothing factor +// constexpr uint8_t kTempRegions = 5; -constexpr std::array kThermalCurve{{ - {40.0f, 10}, - {55.0f, 25}, - {70.0f, 55}, - {85.0f, 85}, - {95.0f, 100}, -}}; - -auto LookupDuty(float temp) -> uint8_t { - if (temp <= kThermalCurve[0].temperature) { - return kThermalCurve[0].duty; - } +// float filteredTemp = 0.0f; +// float lastReading = 0.0f; - if (temp >= kThermalCurve[kTempRegions - 1].temperature) { - return kThermalCurve[kTempRegions - 1].duty; - } +/* TMP126 is currently not functional on the motherboard*/ +// struct Point { +// float temperature; +// uint8_t duty; +// }; - for (size_t i = 0; i < kTempRegions - 1; ++i) { - const auto& p1 = kThermalCurve[i]; - const auto& p2 = kThermalCurve[i + 1]; +// constexpr std::array kThermalCurve{{ +// {40.0f, 10}, +// {55.0f, 25}, +// {70.0f, 55}, +// {85.0f, 85}, +// {95.0f, 100}, +// }}; - if (temp >= p1.temperature && temp <= p2.temperature) { - float ratio = - (temp - p1.temperature) / (p2.temperature - p1.temperature); - return static_cast(p1.duty + ratio * (p2.duty - p1.duty)); - } - } +/* TMP126 is currently not functional on the motherboard*/ +// auto LookupDuty(float temp) -> uint8_t { +// if (temp <= kThermalCurve[0].temperature) { +// return kThermalCurve[0].duty; +// } - return 100; // should never reach here -}; +// if (temp >= kThermalCurve[kTempRegions - 1].temperature) { +// return kThermalCurve[kTempRegions - 1].duty; +// } + +// for (size_t i = 0; i < kTempRegions - 1; ++i) { +// const auto& p1 = kThermalCurve[i]; +// const auto& p2 = kThermalCurve[i + 1]; + +// if (temp >= p1.temperature && temp <= p2.temperature) { +// float ratio = +// (temp - p1.temperature) / (p2.temperature - p1.temperature); +// return static_cast(p1.duty + ratio * (p2.duty - p1.duty)); +// } +// } + +// return 100; // should never reach here +// }; } // namespace auto Init() noexcept -> void { - filteredTemp = 25.0f; - fan2En.SetHigh(); fan2Pwm.Start(); - fan2Pwm.SetDutyCycle(100.0f); + + currentDuty = 80.0f; + + fan2Pwm.SetDutyCycle(currentDuty); // tempSensorReady = (tempSensor.init() == amber::tmp126::Status::OK); // if (!tempSensorReady) { @@ -81,8 +87,10 @@ auto Init() noexcept -> void { auto Update10Hz() noexcept -> void { if (pwr_down_flag) { - fan2Pwm.SetDutyCycle(50.0f); + currentDuty = 50.0f; + fan2Pwm.SetDutyCycle(currentDuty); } + /* TMP126 is currently not functional on the motherboard*/ // const auto [status, temperature] = tempSensor.readTemperature(); // if (status != amber::tmp126::Status::OK) { // tempSensorReady = false; @@ -96,8 +104,12 @@ auto Update10Hz() noexcept -> void { // fan2Pwm.SetDutyCycle(LookupDuty(filteredTemp)); }; -auto GetCarrierTemp() noexcept -> float { - return filteredTemp; -} +// auto GetCarrierTemp() noexcept -> float { +// return filteredTemp; +// } + +auto GetCurrentFanDuty() noexcept -> float { + return currentDuty; +}; } // namespace thermal diff --git a/boards/motherboard/src/thermal/thermal.hpp b/boards/motherboard/src/thermal/thermal.hpp index 5a02653..5d16ee2 100644 --- a/boards/motherboard/src/thermal/thermal.hpp +++ b/boards/motherboard/src/thermal/thermal.hpp @@ -4,6 +4,7 @@ namespace thermal { auto Init() noexcept -> void; auto Update10Hz() noexcept -> void; -auto GetCarrierTemp() noexcept -> float; +// auto GetCarrierTemp() noexcept -> float; +auto GetCurrentFanDuty() noexcept -> float; } // namespace thermal \ No newline at end of file diff --git a/lib/tmp126/tmp126.cpp b/lib/tmp126/tmp126.cpp index 71576ac..6fb09b6 100644 --- a/lib/tmp126/tmp126.cpp +++ b/lib/tmp126/tmp126.cpp @@ -6,11 +6,6 @@ Driver::Driver(periph::Spi& spi, const Config& config) : _spi(spi), _config(config) {} auto Driver::init() noexcept -> Status { - auto status = softReset(); - if (status != Status::OK) { - return status; - } - uint16_t cfg = 0x0000U; if (_config.averaging) { @@ -21,11 +16,13 @@ auto Driver::init() noexcept -> Status { cfg |= (static_cast(_config.conv_period) & CFG_PERIOD_MASK); - status = writeReg(reg::CONFIGURATION, cfg); + auto status = writeReg(reg::CONFIGURATION, cfg); if (status != Status::OK) { return status; } + status = writeReg(reg::THIGH_LIMIT, 0x500); + return Status::OK; } @@ -63,15 +60,15 @@ auto Driver::isDataReady() noexcept -> bool { auto Driver::readReg(const reg r) noexcept -> std::pair { auto txFrame = buildFrame(false, r, 0x0000U); - std::array rxFrame {}; + std::array rxFrame {}; - auto status = _spi.transmitThenReceive(txFrame.data(), 2U, rxFrame.data(), 2U); + auto status = _spi.transceive(txFrame.data(), rxFrame.data(), SPI_NUM_BYTES); if (status != HAL_OK) { return {Status::SPI_FAILURE, 0U}; } - uint16_t data = (static_cast(rxFrame[0]) << 8) - | static_cast(rxFrame[1]); + uint16_t data = (static_cast(rxFrame[2]) << 8) + | static_cast(rxFrame[3]); return {Status::OK, data}; } @@ -87,18 +84,33 @@ auto Driver::writeReg(const reg r, const uint16_t data) noexcept -> Status { return Status::OK; } -auto Driver::buildFrame(const bool write, const reg r, const uint16_t data) +auto Driver::buildFrame(const bool write, const reg r, const uint16_t data = 0U) noexcept -> std::array { - std::array frame {0}; + std::array frame{0}; - uint16_t cmd = write ? CMD_WRITE : CMD_READ; - cmd |= static_cast(r); + uint16_t cmd = 0U; + + if (!write) { + cmd |= (1U << 8); // R/W = 1 for Read + } + // Auto-increment bit (bit 9) can be added here if you need burst reads later: + // if (autoIncrement) cmd |= (1U << 9); + + cmd |= (static_cast(r) & 0xFFU); // Sub-Address goes in bits [7:0] frame[0] = static_cast(cmd >> 8); frame[1] = static_cast(cmd & 0xFFU); - frame[2] = static_cast(data >> 8); - frame[3] = static_cast(data & 0xFFU); + + if (!write) { + // Read → send dummy bytes (peripheral drives SIO) + frame[2] = 0x00U; + frame[3] = 0x00U; + } else { + // Write → send actual data + frame[2] = static_cast(data >> 8); + frame[3] = static_cast(data & 0xFFU); + } return frame; } diff --git a/lib/tps274160b/tps274160b.cpp b/lib/tps274160b/tps274160b.cpp index 486c745..8d27247 100644 --- a/lib/tps274160b/tps274160b.cpp +++ b/lib/tps274160b/tps274160b.cpp @@ -40,7 +40,7 @@ auto Driver::diagEnable(bool en) noexcept -> void { }; auto Driver::selectDiagPin(uint8_t pin) noexcept -> void { - if (pin >= kNumDiagPins) { return; } + if (pin >= kNumChannels) { return; } _cfg.diagSelect[0U].Set(pin & 0x1); _cfg.diagSelect[1U].Set((pin >> 1) & 0x1); diff --git a/proto/base_station.proto b/proto/base_station.proto index 9284477..13ca675 100644 --- a/proto/base_station.proto +++ b/proto/base_station.proto @@ -2,16 +2,44 @@ syntax = "proto3"; package base_station; +enum PowerMuxState { + POWER_MUX_STATE_USB_POWER = 0; + POWER_MUX_STATE_BARREL_JACK = 1; +} + message Command { uint32 dummy = 1; } -message Status { - uint32 dummy_echo = 1; - // Diagnostics - optional uint32 tx_counter = 14; - optional uint32 rx_counter = 15; - optional float temperature = 16; - optional uint32 uart_byte = 17; - optional uint32 uart_receive_count = 18; +message DebugStatus { + uint32 tx_counter = 1; + uint32 rx_counter = 2; + uint32 uart_byte = 3; + uint32 uart_receive_count = 4; } + +message ThermalStatus { + float fan_duty_percent = 1; +} + +message HsdCurrents { + float channel_1 = 1; // mA + float channel_2 = 2; // mA + float channel_3 = 3; // mA + float channel_4 = 4; // mA +} + +message PowerStatus { + PowerMuxState mux_state = 1; + bool powered_down = 2; + HsdCurrents p6v_hsd1 = 3; + HsdCurrents p6v_hsd2 = 4; + float p6v_scatter_current = 5; // mA + float p12v_current = 6; // mA +} + +message Status { + DebugStatus debug = 1; + ThermalStatus thermal = 2; + PowerStatus power = 3; +} \ No newline at end of file From c63210a56c08a7b14852e8f6cda505d0d3b491b0 Mon Sep 17 00:00:00 2001 From: Ivan Lange Date: Mon, 6 Apr 2026 02:07:52 -0400 Subject: [PATCH 13/13] Working code and usb comms --- boards/motherboard/Inc/main.h | 4 ++-- boards/motherboard/motherboard.ioc | 2 +- boards/motherboard/src/carrier/carrier.cpp | 21 +++++++++++++++++---- boards/motherboard/src/carrier/carrier.hpp | 1 + boards/motherboard/src/gpio.c | 8 ++++---- boards/motherboard/src/power/power.cpp | 7 ------- boards/motherboard/src/serial/serial.cpp | 4 ++++ boards/motherboard/src/thermal/thermal.cpp | 3 ++- proto/base_station.proto | 6 ++++++ 9 files changed, 37 insertions(+), 19 deletions(-) diff --git a/boards/motherboard/Inc/main.h b/boards/motherboard/Inc/main.h index e02e69f..38d5d18 100644 --- a/boards/motherboard/Inc/main.h +++ b/boards/motherboard/Inc/main.h @@ -94,8 +94,8 @@ void Error_Handler(void); #define DEBUG1_GPIO_Port GPIOE #define P12V_CS_Pin GPIO_PIN_10 #define P12V_CS_GPIO_Port GPIOB -#define FAN1_PWN_Pin GPIO_PIN_9 -#define FAN1_PWN_GPIO_Port GPIOA +#define FAN1_PWM_Pin GPIO_PIN_9 +#define FAN1_PWM_GPIO_Port GPIOA #define WARN_LIGHT_Pin GPIO_PIN_6 #define WARN_LIGHT_GPIO_Port GPIOC #define FAN2_PWM_Pin GPIO_PIN_7 diff --git a/boards/motherboard/motherboard.ioc b/boards/motherboard/motherboard.ioc index ead5229..31ab323 100644 --- a/boards/motherboard/motherboard.ioc +++ b/boards/motherboard/motherboard.ioc @@ -179,7 +179,7 @@ PA7.Mode=IN7 PA7.Signal=ADC1_IN7 PA8.Locked=true PA9.GPIOParameters=GPIO_Label -PA9.GPIO_Label=FAN1_PWN +PA9.GPIO_Label=FAN1_PWM PA9.Locked=true PA9.Signal=GPIO_Output PA10.Locked=true diff --git a/boards/motherboard/src/carrier/carrier.cpp b/boards/motherboard/src/carrier/carrier.cpp index ebcfb77..2894cfe 100644 --- a/boards/motherboard/src/carrier/carrier.cpp +++ b/boards/motherboard/src/carrier/carrier.cpp @@ -17,8 +17,11 @@ static amber::periph::DigitalOutput logampEn(*LOGAMP_EN_GPIO_Port, static amber::periph::DigitalOutput vcoCe(*VCO_CE_GPIO_Port, VCO_CE_Pin); static amber::periph::DigitalOutput fan1En(*FAN1_PWR_EN_GPIO_Port, FAN1_PWR_EN_Pin); -static amber::periph::DigitalOutput fan1Pwm(*FAN1_PWN_GPIO_Port, FAN1_PWN_Pin); +static amber::periph::DigitalOutput fan1Pwm(*FAN1_PWM_GPIO_Port, FAN1_PWM_Pin); static amber::periph::DigitalOutput vgaEn(*VGA_EN_GPIO_Port, VGA_EN_Pin); +static amber::periph::DigitalOutput warnLight(*WARN_LIGHT_GPIO_Port, + WARN_LIGHT_Pin); + static amber::periph::DigitalInput vcoMuxOut(*VCO_MUXOUT_GPIO_Port, VCO_MUXOUT_Pin); static amber::periph::AnalogInput lpaPowerDetect(hadc1, ADC_CHANNEL_7); @@ -26,6 +29,8 @@ static amber::periph::AnalogInput lpaPowerDetect(hadc1, ADC_CHANNEL_7); static bool vcoLocked = false; static bool powerOffRequested = false; +static float lpaPower = 0.0f; + auto ADF5355Config() -> amber::adf5355::Driver::InitParam& { static amber::adf5355::Driver::InitParam cfg{}; return cfg; @@ -54,25 +59,29 @@ auto Init() noexcept -> void { HAL_Delay(10); ADF5355().setup(); + + warnLight.SetHigh(); }; auto Update_100hz() noexcept -> void { vcoLocked = vcoMuxOut.Read(); + lpaPower = lpaPowerDetect.ReadVoltage(); if (powerOffRequested) { lpaEn.SetLow(); lnaEn.SetLow(); - vcoCe.SetLow(); fan1En.SetLow(); logampEn.SetHigh(); vgaEn.SetLow(); + warnLight.SetLow(); return; } else { lpaEn.SetHigh(); lnaEn.SetHigh(); - vcoCe.SetHigh(); - fan1En.SetHigh(); logampEn.SetLow(); + fan1En.SetHigh(); + fan1Pwm.SetHigh(); + vcoCe.SetHigh(); vgaEn.SetHigh(); } @@ -83,6 +92,10 @@ auto Update_100hz() noexcept -> void { } }; +auto GetLpaPowerDetect() noexcept -> float { + return lpaPower; +} + auto GetVcoLocked() noexcept -> bool { return vcoLocked; }; diff --git a/boards/motherboard/src/carrier/carrier.hpp b/boards/motherboard/src/carrier/carrier.hpp index 78dc26a..a467e07 100644 --- a/boards/motherboard/src/carrier/carrier.hpp +++ b/boards/motherboard/src/carrier/carrier.hpp @@ -4,6 +4,7 @@ namespace carrier { auto Init() noexcept -> void; auto Update_100hz() noexcept -> void; +auto GetLpaPowerDetect() noexcept -> float; auto GetVcoLocked() noexcept -> bool; auto GetPowerDown() noexcept -> bool; diff --git a/boards/motherboard/src/gpio.c b/boards/motherboard/src/gpio.c index 3ab0db2..3e4d15a 100644 --- a/boards/motherboard/src/gpio.c +++ b/boards/motherboard/src/gpio.c @@ -64,7 +64,7 @@ void MX_GPIO_Init(void) { GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(FAN1_PWN_GPIO_Port, FAN1_PWN_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(FAN1_PWM_GPIO_Port, FAN1_PWM_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOD, @@ -125,12 +125,12 @@ void MX_GPIO_Init(void) { GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); - /*Configure GPIO pin : FAN1_PWN_Pin */ - GPIO_InitStruct.Pin = FAN1_PWN_Pin; + /*Configure GPIO pin : FAN1_PWM_Pin */ + GPIO_InitStruct.Pin = FAN1_PWM_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(FAN1_PWN_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(FAN1_PWM_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pins : LPA_EN_Pin VGA_ATTSEL0_Pin VGA_EN_Pin VGA_ATTSEL1_Pin P12V_HSD_DIAG_EN_Pin FAN1_PWR_EN_Pin FAN2_PWR_EN_Pin diff --git a/boards/motherboard/src/power/power.cpp b/boards/motherboard/src/power/power.cpp index e3f4d17..fc7a440 100644 --- a/boards/motherboard/src/power/power.cpp +++ b/boards/motherboard/src/power/power.cpp @@ -136,13 +136,6 @@ auto P12VHsd() -> amber::tps1h100::Driver& { namespace power { auto Init() noexcept -> void { - // if (GetPowerMuxState() == PowerMuxState::USB_POWER) { - // P6VHsd1().disableAll(); - // P6VHsd2().disableAll(); - // P6VScatter().disable(); - // return; - // } - P6VHsd1().enableAll(); P6VHsd2().enableAll(); P6VScatter().enable(); diff --git a/boards/motherboard/src/serial/serial.cpp b/boards/motherboard/src/serial/serial.cpp index 0f6c5f2..e151fef 100644 --- a/boards/motherboard/src/serial/serial.cpp +++ b/boards/motherboard/src/serial/serial.cpp @@ -86,6 +86,10 @@ void SendStatus(void) { status.has_thermal = true; status.thermal.fan_duty_percent = thermal::GetCurrentFanDuty(); + status.has_carrier = true; + status.carrier.vco_locked = carrier::GetVcoLocked(); + status.carrier.lpa_power_detect = carrier::GetLpaPowerDetect(); + status.has_power = true; status.power.mux_state = static_cast(power::GetPowerMuxState()); diff --git a/boards/motherboard/src/thermal/thermal.cpp b/boards/motherboard/src/thermal/thermal.cpp index 5207827..6d55367 100644 --- a/boards/motherboard/src/thermal/thermal.cpp +++ b/boards/motherboard/src/thermal/thermal.cpp @@ -62,7 +62,8 @@ static float currentDuty = 0.0f; // if (temp >= p1.temperature && temp <= p2.temperature) { // float ratio = // (temp - p1.temperature) / (p2.temperature - p1.temperature); -// return static_cast(p1.duty + ratio * (p2.duty - p1.duty)); +// return static_cast(p1.duty + ratio * (p2.duty - +// p1.duty)); // } // } diff --git a/proto/base_station.proto b/proto/base_station.proto index 13ca675..6a14d28 100644 --- a/proto/base_station.proto +++ b/proto/base_station.proto @@ -22,6 +22,11 @@ message ThermalStatus { float fan_duty_percent = 1; } +message CarrierStatus { + bool vco_locked = 1; + float lpa_power_detect = 2; // V +} + message HsdCurrents { float channel_1 = 1; // mA float channel_2 = 2; // mA @@ -42,4 +47,5 @@ message Status { DebugStatus debug = 1; ThermalStatus thermal = 2; PowerStatus power = 3; + CarrierStatus carrier = 4; } \ No newline at end of file