Files
StepMotorCtrl/libs/device/py32md530.h
T
hm b49c9ab0c6 Initial commit: PY32MD530H28U7TR步进电机控制器项目
完整实现了以下模块:
- 系统数据总线(sys_data_bus)模块间通信
- UART/USART/LPUART驱动 + RS485半双工
- I2C驱动(AS5600角度传感器 + AT24C02 EEPROM)
- Modbus RTU从站协议
- 步进电机微步进控制(正弦/余弦换相+S曲线加减速)
- 到位开关驱动(DI_MIN/DI_MAX)
- PGA+ADC电流检测
- 系统监控任务(内存/串口/传感器/任务状态)
- LED/Key外设驱动
- 基于CMake + arm-none-eabi-gcc构建系统
2026-05-11 19:55:43 +08:00

645 lines
24 KiB
C

#ifndef __PY32MD530_H__
#define __PY32MD530_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "core_cm0plus.h"
#define __PY32MD530_H_VERSION 0x0100U
#define FLASH_BASE 0x08000000UL
#define SRAM_BASE 0x20000000UL
#define PERIPH_BASE 0x40000000UL
#define APB1PERIPH_BASE PERIPH_BASE
#define APB2PERIPH_BASE (PERIPH_BASE + 0x10000UL)
#define AHB1PERIPH_BASE (PERIPH_BASE + 0x20000UL)
#define AHB2PERIPH_BASE (PERIPH_BASE + 0x200000UL)
#define GPIOA_BASE (AHB2PERIPH_BASE + 0x00000000UL)
#define GPIOB_BASE (AHB2PERIPH_BASE + 0x00000400UL)
#define GPIOC_BASE (AHB2PERIPH_BASE + 0x00000800UL)
#define GPIOD_BASE (AHB2PERIPH_BASE + 0x00000C00UL)
#define GPIOF_BASE (AHB2PERIPH_BASE + 0x00001400UL)
#define RCC_BASE (AHB1PERIPH_BASE + 0x00001000UL)
#define USART1_BASE (APB2PERIPH_BASE + 0x3800UL)
#define UART1_BASE (APB1PERIPH_BASE + 0x4400UL)
#define LPUART1_BASE (APB1PERIPH_BASE + 0x4800UL)
#define I2C1_BASE (APB1PERIPH_BASE + 0x5400UL)
#define SPI1_BASE (APB2PERIPH_BASE + 0x3000UL)
#define TIM1_BASE (APB2PERIPH_BASE + 0x2C00UL)
#define TIM3_BASE (APB1PERIPH_BASE + 0x0400UL)
#define TIM14_BASE (APB1PERIPH_BASE + 0x2000UL)
#define TIM16_BASE (APB1PERIPH_BASE + 0x2800UL)
#define TIM17_BASE (APB1PERIPH_BASE + 0x2C00UL)
#define LPTIM_BASE (APB1PERIPH_BASE + 0x7C00UL)
#define ADC1_BASE (APB2PERIPH_BASE + 0x2400UL)
#define DMA1_BASE (AHB1PERIPH_BASE + 0x00000UL)
#define WWDG_BASE (APB1PERIPH_BASE + 0x2C00UL)
#define IWDG_BASE (APB1PERIPH_BASE + 0x3000UL)
#define RTC_BASE (APB1PERIPH_BASE + 0x2800UL)
#define SYSCFG_BASE (APB2PERIPH_BASE + 0x0000UL)
#define EXTI_BASE (APB2PERIPH_BASE + 0x0400UL)
#define COMP_BASE (APB2PERIPH_BASE + 0x0200UL)
#define FLASH_SIZE 0x00010000UL
#define SRAM_SIZE 0x00002000UL
typedef struct {
__IOM uint32_t MODER;
__IOM uint32_t OTYPER;
__IOM uint32_t OSPEEDR;
__IOM uint32_t PUPDR;
__IM uint32_t IDR;
__IOM uint32_t ODR;
__IOM uint32_t BSRR;
__IOM uint32_t LCKR;
__IOM uint32_t AFRL;
__IOM uint32_t AFRH;
__IOM uint32_t BRR;
} GPIO_TypeDef;
typedef struct {
__IOM uint32_t CR;
__IOM uint32_t CFGR;
__IOM uint32_t CIR;
__IOM uint32_t APB2RSTR;
__IOM uint32_t APB1RSTR;
__IOM uint32_t AHBENR;
__IOM uint32_t APB2ENR;
__IOM uint32_t APB1ENR;
__IOM uint32_t BDCR;
__IOM uint32_t CSR;
__IOM uint32_t AHBRSTR;
__IOM uint32_t CFGR2;
__IOM uint32_t CFGR3;
} RCC_TypeDef;
typedef struct {
__IOM uint32_t SR;
__IOM uint32_t DR;
__IOM uint32_t BRR;
__IOM uint32_t CR1;
__IOM uint32_t CR2;
__IOM uint32_t CR3;
__IOM uint32_t GTPR;
} USART_TypeDef;
typedef struct {
__IOM uint32_t ISR;
__IOM uint32_t DR;
__IOM uint32_t BRR;
__IOM uint32_t CR1;
__IOM uint32_t CR2;
__IOM uint32_t CR3;
__IOM uint32_t CR4;
} LPUART_TypeDef;
typedef struct {
__IOM uint32_t CR1;
__IOM uint32_t CR2;
__IOM uint32_t OAR1;
__IOM uint32_t OAR2;
__IOM uint32_t TIMINGR;
__IOM uint32_t TIMEOUTR;
__IOM uint32_t ISR;
__IOM uint32_t ICR;
__IOM uint32_t PECR;
__IOM uint32_t RXDR;
__IOM uint32_t TXDR;
} I2C_TypeDef;
typedef struct {
__IOM uint32_t CR1;
__IOM uint32_t CR2;
__IOM uint32_t SMCR;
__IOM uint32_t DIER;
__IOM uint32_t SR;
__IOM uint32_t EGR;
__IOM uint32_t CCMR1;
__IOM uint32_t CCMR2;
__IOM uint32_t CCER;
__IOM uint32_t CNT;
__IOM uint32_t PSC;
__IOM uint32_t ARR;
uint32_t RESERVED0;
__IOM uint32_t CCR1;
__IOM uint32_t CCR2;
__IOM uint32_t CCR3;
__IOM uint32_t CCR4;
uint32_t RESERVED1;
__IOM uint32_t DCR;
__IOM uint32_t DMAR;
__IOM uint32_t OR1;
__IOM uint32_t OR2;
} TIM_TypeDef;
typedef struct {
__IOM uint32_t CR1;
__IOM uint32_t CR2;
__IOM uint32_t CFGR;
__IOM uint32_t SMCR;
__IOM uint32_t DIER;
__IOM uint32_t SR;
__IOM uint32_t EGR;
__IOM uint32_t CCMR1;
__IOM uint32_t CCMR2;
__IOM uint32_t CCER;
__IOM uint32_t CNT;
__IOM uint32_t PSC;
__IOM uint32_t ARR;
__IOM uint32_t RCR;
__IOM uint32_t CCR1;
__IOM uint32_t CCR2;
__IOM uint32_t CCR3;
__IOM uint32_t CCR4;
__IOM uint32_t BDTR;
__IOM uint32_t DCR;
__IOM uint32_t DMAR;
__IOM uint32_t OR1;
__IOM uint32_t CCMR3;
__IOM uint32_t CCR5;
__IOM uint32_t CCR6;
__IOM uint32_t OR2;
__IOM uint32_t OR3;
} TIM1_TypeDef;
typedef struct {
__IOM uint32_t ISR;
__IOM uint32_t IER;
__IOM uint32_t CR;
__IOM uint32_t CFGR1;
__IOM uint32_t CFGR2;
__IOM uint32_t SMPR1;
__IOM uint32_t SMPR2;
__IOM uint32_t TR1;
__IOM uint32_t TR2;
__IOM uint32_t CHSMPR1;
__IOM uint32_t CHSMPR2;
__IOM uint32_t CHDR1;
__IOM uint32_t CHDR2;
__IOM uint32_t CHDR3;
__IOM uint32_t CHDR4;
__IOM uint32_t CHDR5;
__IOM uint32_t CHDR6;
__IOM uint32_t CHDR7;
} ADC_TypeDef;
typedef struct {
__IOM uint32_t CCR;
__IOM uint32_t CNDTR;
__IOM uint32_t CPAR;
__IOM uint32_t CMAR;
} DMA_Channel_TypeDef;
typedef struct {
__IOM uint32_t ISR;
__IOM uint32_t IFCR;
} DMA_TypeDef;
typedef struct {
__IOM uint32_t CR;
__IOM uint32_t CFGR;
__IOM uint32_t CFG2;
__IOM uint32_t EXTICR[4];
__IOM uint32_t CFG3;
} SYSCFG_TypeDef;
typedef struct {
__IOM uint32_t IMR;
__IOM uint32_t EMR;
__IOM uint32_t RTSR;
__IOM uint32_t FTSR;
__IOM uint32_t SWIER;
__IOM uint32_t PR;
} EXTI_TypeDef;
typedef struct {
__IOM uint32_t KR;
__IOM uint32_t PR;
__IOM uint32_t RLR;
__IOM uint32_t SR;
} IWDG_TypeDef;
typedef struct {
__IOM uint32_t CR;
__IOM uint32_t CFR;
__IOM uint32_t SR;
} WWDG_TypeDef;
typedef struct {
__IOM uint32_t TR;
__IOM uint32_t DR;
__IOM uint32_t CR;
__IOM uint32_t ISR;
__IOM uint32_t PRER;
__IOM uint32_t WUTR;
__IOM uint32_t ALRMAR;
__IOM uint32_t ALRMBR;
__IOM uint32_t WPR;
__IOM uint32_t SSR;
__IOM uint32_t SHIFTR;
__IOM uint32_t TSTR;
__IOM uint32_t TSDR;
__IOM uint32_t TSSSR;
__IOM uint32_t CALR;
__IOM uint32_t TAMPCR;
__IOM uint32_t ALRMASSR;
__IOM uint32_t ALRMBSSR;
__IOM uint32_t OR;
} RTC_TypeDef;
typedef struct {
__IOM uint32_t CR1;
__IOM uint32_t CR2;
__IOM uint32_t CFGR1;
__IOM uint32_t CFGR2;
__IOM uint32_t BRR;
__IOM uint32_t RESERVED0;
__IOM uint32_t DIER;
__IOM uint32_t SR;
__IOM uint32_t ICFR;
__IOM uint32_t IER;
} SPI_TypeDef;
typedef struct {
__IOM uint32_t CR;
__IOM uint32_t CSR;
} COMP_TypeDef;
#define GPIOA ((GPIO_TypeDef *)GPIOA_BASE)
#define GPIOB ((GPIO_TypeDef *)GPIOB_BASE)
#define GPIOC ((GPIO_TypeDef *)GPIOC_BASE)
#define GPIOD ((GPIO_TypeDef *)GPIOD_BASE)
#define GPIOF ((GPIO_TypeDef *)GPIOF_BASE)
#define RCC ((RCC_TypeDef *)RCC_BASE)
#define USART1 ((USART_TypeDef *)USART1_BASE)
#define UART1 ((USART_TypeDef *)UART1_BASE)
#define LPUART1 ((LPUART_TypeDef *)LPUART1_BASE)
#define I2C1 ((I2C_TypeDef *)I2C1_BASE)
#define SPI1 ((SPI_TypeDef *)SPI1_BASE)
#define TIM1 ((TIM1_TypeDef *)TIM1_BASE)
#define TIM3 ((TIM_TypeDef *)TIM3_BASE)
#define TIM14 ((TIM_TypeDef *)TIM14_BASE)
#define TIM16 ((TIM_TypeDef *)TIM16_BASE)
#define TIM17 ((TIM_TypeDef *)TIM17_BASE)
#define LPTIM ((TIM_TypeDef *)LPTIM_BASE)
#define ADC1 ((ADC_TypeDef *)ADC1_BASE)
#define DMA1_Channel1 ((DMA_Channel_TypeDef *)(DMA1_BASE + 0x08))
#define DMA1_Channel2 ((DMA_Channel_TypeDef *)(DMA1_BASE + 0x1C))
#define DMA1_Channel3 ((DMA_Channel_TypeDef *)(DMA1_BASE + 0x30))
#define DMA1 ((DMA_TypeDef *)DMA1_BASE)
#define SYSCFG ((SYSCFG_TypeDef *)SYSCFG_BASE)
#define EXTI ((EXTI_TypeDef *)EXTI_BASE)
#define COMP ((COMP_TypeDef *)COMP_BASE)
#define IWDG ((IWDG_TypeDef *)IWDG_BASE)
#define WWDG ((WWDG_TypeDef *)WWDG_BASE)
#define RTC ((RTC_TypeDef *)RTC_BASE)
#define GPIO_MODER_MODE0_Pos 0U
#define GPIO_MODER_MODE0_Msk (0x3UL << GPIO_MODER_MODE0_Pos)
#define GPIO_MODER_MODE0_0 (0x1UL << GPIO_MODER_MODE0_Pos)
#define GPIO_MODER_MODE0_1 (0x2UL << GPIO_MODER_MODE0_Pos)
#define GPIO_OTYPER_OT0_Pos 0U
#define GPIO_OTYPER_OT0_Msk (0x1UL << GPIO_OTYPER_OT0_Pos)
#define GPIO_OTYPER_OT0_0 (0x1UL << GPIO_OTYPER_OT0_Pos)
#define GPIO_OSPEEDR_OSPEED0_Pos 0U
#define GPIO_OSPEEDR_OSPEED0_Msk (0x3UL << GPIO_OSPEEDR_OSPEED0_Pos)
#define GPIO_OSPEEDR_OSPEED0_0 (0x1UL << GPIO_OSPEEDR_OSPEED0_Pos)
#define GPIO_OSPEEDR_OSPEED0_1 (0x2UL << GPIO_OSPEEDR_OSPEED0_Pos)
#define GPIO_PUPDR_PUPD0_Pos 0U
#define GPIO_PUPDR_PUPD0_Msk (0x3UL << GPIO_PUPDR_PUPD0_Pos)
#define GPIO_PUPDR_PUPD0_0 (0x1UL << GPIO_PUPDR_PUPD0_Pos)
#define GPIO_PUPDR_PUPD0_1 (0x2UL << GPIO_PUPDR_PUPD0_Pos)
#define GPIO_BSRR_BS0_Pos 0U
#define GPIO_BSRR_BS0_Msk (0x1UL << GPIO_BSRR_BS0_Pos)
#define GPIO_BSRR_BR0_Pos 16U
#define GPIO_BSRR_BR0_Msk (0x1UL << GPIO_BSRR_BR0_Pos)
#define RCC_AHBENR_GPIOAEN_Pos 17U
#define RCC_AHBENR_GPIOAEN_Msk (0x1UL << RCC_AHBENR_GPIOAEN_Pos)
#define RCC_AHBENR_GPIOAEN RCC_AHBENR_GPIOAEN_Msk
#define RCC_AHBENR_GPIOBEN_Pos 18U
#define RCC_AHBENR_GPIOBEN_Msk (0x1UL << RCC_AHBENR_GPIOBEN_Pos)
#define RCC_AHBENR_GPIOBEN RCC_AHBENR_GPIOBEN_Msk
#define RCC_AHBENR_GPIOCEN_Pos 19U
#define RCC_AHBENR_GPIOCEN_Msk (0x1UL << RCC_AHBENR_GPIOCEN_Pos)
#define RCC_AHBENR_GPIOCEN RCC_AHBENR_GPIOCEN_Msk
#define RCC_AHBENR_GPIOFEN_Pos 22U
#define RCC_AHBENR_GPIOFEN_Msk (0x1UL << RCC_AHBENR_GPIOFEN_Pos)
#define RCC_AHBENR_GPIOFEN RCC_AHBENR_GPIOFEN_Msk
#define RCC_AHBENR_DMAEN_Pos 0U
#define RCC_AHBENR_DMAEN_Msk (0x1UL << RCC_AHBENR_DMAEN_Pos)
#define RCC_AHBENR_DMAEN RCC_AHBENR_DMAEN_Msk
#define RCC_APB2ENR_USART1EN_Pos 14U
#define RCC_APB2ENR_USART1EN_Msk (0x1UL << RCC_APB2ENR_USART1EN_Pos)
#define RCC_APB2ENR_USART1EN RCC_APB2ENR_USART1EN_Msk
#define RCC_APB2ENR_SPI1EN_Pos 12U
#define RCC_APB2ENR_SPI1EN_Msk (0x1UL << RCC_APB2ENR_SPI1EN_Pos)
#define RCC_APB2ENR_TIM1EN_Pos 11U
#define RCC_APB2ENR_TIM1EN_Msk (0x1UL << RCC_APB2ENR_TIM1EN_Pos)
#define RCC_APB2ENR_TIM1EN RCC_APB2ENR_TIM1EN_Msk
#define RCC_APB2ENR_SYSCFGEN_Pos 0U
#define RCC_APB2ENR_SYSCFGEN_Msk (0x1UL << RCC_APB2ENR_SYSCFGEN_Pos)
#define RCC_APB2ENR_SYSCFGEN RCC_APB2ENR_SYSCFGEN_Msk
#define RCC_APB2ENR_ADCEN_Pos 9U
#define RCC_APB2ENR_ADCEN_Msk (0x1UL << RCC_APB2ENR_ADCEN_Pos)
#define RCC_APB2ENR_ADCEN RCC_APB2ENR_ADCEN_Msk
#define RCC_APB1ENR_TIM3EN_Pos 1U
#define RCC_APB1ENR_TIM3EN_Msk (0x1UL << RCC_APB1ENR_TIM3EN_Pos)
#define RCC_APB1ENR_TIM3EN RCC_APB1ENR_TIM3EN_Msk
#define RCC_APB1ENR_TIM14EN_Pos 8U
#define RCC_APB1ENR_TIM14EN_Msk (0x1UL << RCC_APB1ENR_TIM14EN_Pos)
#define RCC_APB1ENR_TIM14EN RCC_APB1ENR_TIM14EN_Msk
#define RCC_APB1ENR_UART1EN_Pos 18U
#define RCC_APB1ENR_UART1EN_Msk (0x1UL << RCC_APB1ENR_UART1EN_Pos)
#define RCC_APB1ENR_UART1EN RCC_APB1ENR_UART1EN_Msk
#define RCC_APB1ENR_LPUART1EN_Pos 19U
#define RCC_APB1ENR_LPUART1EN_Msk (0x1UL << RCC_APB1ENR_LPUART1EN_Pos)
#define RCC_APB1ENR_LPUART1EN RCC_APB1ENR_LPUART1EN_Msk
#define RCC_APB1ENR_I2C1EN_Pos 21U
#define RCC_APB1ENR_I2C1EN_Msk (0x1UL << RCC_APB1ENR_I2C1EN_Pos)
#define RCC_APB1ENR_I2C1EN RCC_APB1ENR_I2C1EN_Msk
#define RCC_APB1ENR_LPTIMEN_Pos 31U
#define RCC_APB1ENR_LPTIMEN_Msk (0x1UL << RCC_APB1ENR_LPTIMEN_Pos)
#define RCC_APB1ENR_PWREN_Pos 28U
#define RCC_APB1ENR_PWREN_Msk (0x1UL << RCC_APB1ENR_PWREN_Pos)
#define RCC_APB1ENR_PWREN RCC_APB1ENR_PWREN_Msk
/* RCC CR register bit definitions */
#define RCC_CR_HSION_Pos 0U
#define RCC_CR_HSION_Msk (0x1UL << RCC_CR_HSION_Pos)
#define RCC_CR_HSION RCC_CR_HSION_Msk
#define RCC_CR_HSIRDY_Pos 1U
#define RCC_CR_HSIRDY_Msk (0x1UL << RCC_CR_HSIRDY_Pos)
#define RCC_CR_HSIRDY RCC_CR_HSIRDY_Msk
#define RCC_CR_HSITRIM_Pos 3U
#define RCC_CR_HSITRIM_Msk (0x1FUL << RCC_CR_HSITRIM_Pos)
#define RCC_CR_HSICAL_Pos 8U
#define RCC_CR_HSICAL_Msk (0xFFUL << RCC_CR_HSICAL_Pos)
#define RCC_CR_HSEON_Pos 16U
#define RCC_CR_HSEON_Msk (0x1UL << RCC_CR_HSEON_Pos)
#define RCC_CR_HSERDY_Pos 17U
#define RCC_CR_HSERDY_Msk (0x1UL << RCC_CR_HSERDY_Pos)
#define RCC_CR_PLLON_Pos 24U
#define RCC_CR_PLLON_Msk (0x1UL << RCC_CR_PLLON_Pos)
#define RCC_CR_PLLON RCC_CR_PLLON_Msk
#define RCC_CR_PLLRDY_Pos 25U
#define RCC_CR_PLLRDY_Msk (0x1UL << RCC_CR_PLLRDY_Pos)
#define RCC_CR_PLLRDY RCC_CR_PLLRDY_Msk
/* RCC CFGR register bit definitions */
#define RCC_CFGR_SW_Pos 0U
#define RCC_CFGR_SW_Msk (0x3UL << RCC_CFGR_SW_Pos)
#define RCC_CFGR_SW RCC_CFGR_SW_Msk
#define RCC_CFGR_SW_0 (0x1UL << RCC_CFGR_SW_Pos)
#define RCC_CFGR_SW_1 (0x2UL << RCC_CFGR_SW_Pos)
#define RCC_CFGR_SW_HSI (0x0UL << RCC_CFGR_SW_Pos)
#define RCC_CFGR_SW_HSE (0x1UL << RCC_CFGR_SW_Pos)
#define RCC_CFGR_SW_PLL (0x2UL << RCC_CFGR_SW_Pos)
#define RCC_CFGR_SWS_Pos 2U
#define RCC_CFGR_SWS_Msk (0x3UL << RCC_CFGR_SWS_Pos)
#define RCC_CFGR_SWS RCC_CFGR_SWS_Msk
#define RCC_CFGR_SWS_0 (0x1UL << RCC_CFGR_SWS_Pos)
#define RCC_CFGR_SWS_1 (0x2UL << RCC_CFGR_SWS_Pos)
#define RCC_CFGR_SWS_HSI (0x0UL << RCC_CFGR_SWS_Pos)
#define RCC_CFGR_SWS_HSE (0x1UL << RCC_CFGR_SWS_Pos)
#define RCC_CFGR_SWS_PLL (0x2UL << RCC_CFGR_SWS_Pos)
#define RCC_CFGR_HPRE_Pos 4U
#define RCC_CFGR_HPRE_Msk (0xFUL << RCC_CFGR_HPRE_Pos)
#define RCC_CFGR_PPRE_Pos 8U
#define RCC_CFGR_PPRE_Msk (0x7UL << RCC_CFGR_PPRE_Pos)
#define RCC_CFGR_PLLSRC_Pos 16U
#define RCC_CFGR_PLLSRC_Msk (0x1UL << RCC_CFGR_PLLSRC_Pos)
#define RCC_CFGR_PLLSRC RCC_CFGR_PLLSRC_Msk
#define RCC_CFGR_PLLXTPRE_Pos 17U
#define RCC_CFGR_PLLXTPRE_Msk (0x1UL << RCC_CFGR_PLLXTPRE_Pos)
/* RCC CFGR2 register bit definitions */
#define RCC_CFGR2_PLLMUL_Pos 0U
#define RCC_CFGR2_PLLMUL_Msk (0xFUL << RCC_CFGR2_PLLMUL_Pos)
#define RCC_CFGR2_PLLMUL RCC_CFGR2_PLLMUL_Msk
#define RCC_CFGR2_PLLMUL2 (0x0UL << RCC_CFGR2_PLLMUL_Pos)
#define RCC_CFGR2_PLLMUL3 (0x1UL << RCC_CFGR2_PLLMUL_Pos)
#define RCC_CFGR2_PLLMUL4 (0x2UL << RCC_CFGR2_PLLMUL_Pos)
#define RCC_CFGR2_PLLMUL5 (0x3UL << RCC_CFGR2_PLLMUL_Pos)
#define RCC_CFGR2_PLLMUL6 (0x4UL << RCC_CFGR2_PLLMUL_Pos)
#define RCC_CFGR2_PLLMUL7 (0x5UL << RCC_CFGR2_PLLMUL_Pos)
#define RCC_CFGR2_PLLMUL8 (0x6UL << RCC_CFGR2_PLLMUL_Pos)
#define RCC_CFGR2_PLLMUL9 (0x7UL << RCC_CFGR2_PLLMUL_Pos)
#define RCC_CFGR2_PLLMUL10 (0x8UL << RCC_CFGR2_PLLMUL_Pos)
#define RCC_CFGR2_PLLMUL11 (0x9UL << RCC_CFGR2_PLLMUL_Pos)
#define RCC_CFGR2_PLLMUL12 (0xAUL << RCC_CFGR2_PLLMUL_Pos)
#define RCC_CFGR2_PLLMUL13 (0xBUL << RCC_CFGR2_PLLMUL_Pos)
#define RCC_CFGR2_PLLMUL14 (0xCUL << RCC_CFGR2_PLLMUL_Pos)
#define RCC_CFGR2_PLLMUL15 (0xDUL << RCC_CFGR2_PLLMUL_Pos)
#define RCC_CFGR2_PLLMUL16 (0xEUL << RCC_CFGR2_PLLMUL_Pos)
#define RCC_CFGR2_PREDIV_Pos 4U
#define RCC_CFGR2_PREDIV_Msk (0x1UL << RCC_CFGR2_PREDIV_Pos)
#define RCC_APB2RST_TIM1RST_Pos 11U
#define RCC_APB2RST_TIM1RST_Msk (0x1UL << RCC_APB2RST_TIM1RST_Pos)
#define RCC_APB2RST_USART1RST_Pos 14U
#define RCC_APB2RST_USART1RST_Msk (0x1UL << RCC_APB2RST_USART1RST_Pos)
#define RCC_APB2RST_ADCRST_Pos 9U
#define RCC_APB2RST_ADCRST_Msk (0x1UL << RCC_APB2RST_ADCRST_Pos)
#define RCC_APB1RST_UART1RST_Pos 18U
#define RCC_APB1RST_UART1RST_Msk (0x1UL << RCC_APB1RST_UART1RST_Pos)
#define RCC_APB1RST_LPUART1RST_Pos 19U
#define RCC_APB1RST_LPUART1RST_Msk (0x1UL << RCC_APB1RST_LPUART1RST_Pos)
#define RCC_APB1RST_I2C1RST_Pos 21U
#define RCC_APB1RST_I2C1RST_Msk (0x1UL << RCC_APB1RST_I2C1RST_Pos)
#define RCC_APB1RST_TIM3RST_Pos 1U
#define RCC_APB1RST_TIM3RST_Msk (0x1UL << RCC_APB1RST_TIM3RST_Pos)
/* USART registers bit definitions */
#define USART_CR1_UE_Pos 0U
#define USART_CR1_UE_Msk (0x1UL << USART_CR1_UE_Pos)
#define USART_CR1_RE_Pos 2U
#define USART_CR1_RE_Msk (0x1UL << USART_CR1_RE_Pos)
#define USART_CR1_TE_Pos 3U
#define USART_CR1_TE_Msk (0x1UL << USART_CR1_TE_Pos)
#define USART_CR1_RXNEIE_Pos 5U
#define USART_CR1_RXNEIE_Msk (0x1UL << USART_CR1_RXNEIE_Pos)
#define USART_CR1_TCIE_Pos 6U
#define USART_CR1_TCIE_Msk (0x1UL << USART_CR1_TCIE_Pos)
#define USART_CR1_TXNEIE_Pos 7U
#define USART_CR1_TXNEIE_Msk (0x1UL << USART_CR1_TXNEIE_Pos)
#define USART_CR1_M_Pos 12U
#define USART_CR1_M_Msk (0x1UL << USART_CR1_M_Pos)
#define USART_CR1_M0_Pos 12U
#define USART_CR1_M0_Msk (0x1UL << USART_CR1_M0_Pos)
#define USART_CR1_M1_Pos 28U
#define USART_CR1_M1_Msk (0x1UL << USART_CR1_M1_Pos)
#define USART_CR1_OVER8_Pos 15U
#define USART_CR1_OVER8_Msk (0x1UL << USART_CR1_OVER8_Pos)
#define USART_CR3_DMAR_Pos 6U
#define USART_CR3_DMAR_Msk (0x1UL << USART_CR3_DMAR_Pos)
#define USART_CR3_DMAT_Pos 7U
#define USART_CR3_DMAT_Msk (0x1UL << USART_CR3_DMAT_Pos)
#define USART_SR_RXNE_Pos 5U
#define USART_SR_RXNE_Msk (0x1UL << USART_SR_RXNE_Pos)
#define USART_SR_TC_Pos 6U
#define USART_SR_TC_Msk (0x1UL << USART_SR_TC_Pos)
#define USART_SR_TXE_Pos 7U
#define USART_SR_TXE_Msk (0x1UL << USART_SR_TXE_Pos)
/* I2C registers bit definitions */
#define I2C_CR1_PE_Pos 0U
#define I2C_CR1_PE_Msk (0x1UL << I2C_CR1_PE_Pos)
#define I2C_ISR_TXIS_Pos 1U
#define I2C_ISR_TXIS_Msk (0x1UL << I2C_ISR_TXIS_Pos)
#define I2C_ISR_RXNE_Pos 2U
#define I2C_ISR_RXNE_Msk (0x1UL << I2C_ISR_RXNE_Pos)
#define I2C_ISR_STOPF_Pos 5U
#define I2C_ISR_STOPF_Msk (0x1UL << I2C_ISR_STOPF_Pos)
#define I2C_ISR_NACKF_Pos 4U
#define I2C_ISR_NACKF_Msk (0x1UL << I2C_ISR_NACKF_Pos)
/* ADC registers bit definitions */
#define ADC_CR_ADEN_Pos 0U
#define ADC_CR_ADEN_Msk (0x1UL << ADC_CR_ADEN_Pos)
#define ADC_CR_ADDIS_Pos 1U
#define ADC_CR_ADDIS_Msk (0x1UL << ADC_CR_ADDIS_Pos)
#define ADC_CR_ADSTART_Pos 2U
#define ADC_CR_ADSTART_Msk (0x1UL << ADC_CR_ADSTART_Pos)
#define ADC_CFGR1_RES_Pos 3U
#define ADC_CFGR1_RES_Msk (0x3UL << ADC_CFGR1_RES_Pos)
#define ADC_CFGR1_RES_1 (0x2UL << ADC_CFGR1_RES_Pos)
#define ADC_CFGR1_DMAEN_Pos 8U
#define ADC_CFGR1_DMAEN_Msk (0x1UL << ADC_CFGR1_DMAEN_Pos)
#define ADC_CFGR1_DMACFG_Pos 9U
#define ADC_CFGR1_DMACFG_Msk (0x1UL << ADC_CFGR1_DMACFG_Pos)
#define ADC_ISR_ADRDY_Pos 0U
#define ADC_ISR_ADRDY_Msk (0x1UL << ADC_ISR_ADRDY_Pos)
#define ADC_ISR_EOC_Pos 2U
#define ADC_ISR_EOC_Msk (0x1UL << ADC_ISR_EOC_Pos)
/* COMP (PGA) registers bit definitions */
#define COMP_CR_EN_Pos 0U
#define COMP_CR_EN_Msk (0x1UL << COMP_CR_EN_Pos)
#define COMP_CR_PGA_MODE_Pos 4U
#define COMP_CR_PGA_MODE_Msk (0x1UL << COMP_CR_PGA_MODE_Pos)
#define COMP_CR_PGA_GAIN_Pos 5U
#define COMP_CR_PGA_GAIN_Msk (0x7UL << COMP_CR_PGA_GAIN_Pos)
#define COMP_CSR_OUT_Pos 0U
#define COMP_CSR_OUT_Msk (0x1UL << COMP_CSR_OUT_Pos)
/* TIM registers bit definitions */
#define TIM_CR1_CEN_Pos 0U
#define TIM_CR1_CEN_Msk (0x1UL << TIM_CR1_CEN_Pos)
#define TIM_CR1_CEN TIM_CR1_CEN_Msk
#define TIM_CR1_OPM_Pos 3U
#define TIM_CR1_OPM_Msk (0x1UL << TIM_CR1_OPM_Pos)
#define TIM_CR1_ARPE_Pos 7U
#define TIM_CR1_ARPE_Msk (0x1UL << TIM_CR1_ARPE_Pos)
#define TIM_DIER_UIE_Pos 0U
#define TIM_DIER_UIE_Msk (0x1UL << TIM_DIER_UIE_Pos)
#define TIM_DIER_CC1IE_Pos 1U
#define TIM_DIER_CC1IE_Msk (0x1UL << TIM_DIER_CC1IE_Pos)
#define TIM_DIER_CC2IE_Pos 2U
#define TIM_DIER_CC2IE_Msk (0x1UL << TIM_DIER_CC2IE_Pos)
#define TIM_DIER_CC3IE_Pos 3U
#define TIM_DIER_CC3IE_Msk (0x1UL << TIM_DIER_CC3IE_Pos)
#define TIM_DIER_CC4IE_Pos 4U
#define TIM_DIER_CC4IE_Msk (0x1UL << TIM_DIER_CC4IE_Pos)
#define TIM_SR_UIF_Pos 0U
#define TIM_SR_UIF_Msk (0x1UL << TIM_SR_UIF_Pos)
#define TIM_SR_CC1IF_Pos 1U
#define TIM_SR_CC1IF_Msk (0x1UL << TIM_SR_CC1IF_Pos)
#define TIM_SR_CC2IF_Pos 2U
#define TIM_SR_CC2IF_Msk (0x1UL << TIM_SR_CC2IF_Pos)
#define TIM_SR_CC3IF_Pos 3U
#define TIM_SR_CC3IF_Msk (0x1UL << TIM_SR_CC3IF_Pos)
#define TIM_SR_CC4IF_Pos 4U
#define TIM_SR_CC4IF_Msk (0x1UL << TIM_SR_CC4IF_Pos)
#define TIM_EGR_UG_Pos 0U
#define TIM_EGR_UG_Msk (0x1UL << TIM_EGR_UG_Pos)
#define TIM_CCER_CC1E_Pos 0U
#define TIM_CCER_CC1E_Msk (0x1UL << TIM_CCER_CC1E_Pos)
#define TIM_CCER_CC1NE_Pos 2U
#define TIM_CCER_CC1NE_Msk (0x1UL << TIM_CCER_CC1NE_Pos)
#define TIM_CCER_CC2E_Pos 4U
#define TIM_CCER_CC2E_Msk (0x1UL << TIM_CCER_CC2E_Pos)
#define TIM_CCER_CC2NE_Pos 6U
#define TIM_CCER_CC2NE_Msk (0x1UL << TIM_CCER_CC2NE_Pos)
#define TIM_CCER_CC3E_Pos 8U
#define TIM_CCER_CC3E_Msk (0x1UL << TIM_CCER_CC3E_Pos)
#define TIM_CCER_CC3NE_Pos 10U
#define TIM_CCER_CC3NE_Msk (0x1UL << TIM_CCER_CC3NE_Pos)
#define TIM_CCER_CC4E_Pos 12U
#define TIM_CCER_CC4E_Msk (0x1UL << TIM_CCER_CC4E_Pos)
#define TIM_BDTR_BKE_Pos 12U
#define TIM_BDTR_BKE_Msk (0x1UL << TIM_BDTR_BKE_Pos)
#define TIM_BDTR_BKP_Pos 13U
#define TIM_BDTR_BKP_Msk (0x1UL << TIM_BDTR_BKP_Pos)
#define TIM_BDTR_AOE_Pos 14U
#define TIM_BDTR_AOE_Msk (0x1UL << TIM_BDTR_AOE_Pos)
#define TIM_BDTR_MOE_Pos 15U
#define TIM_BDTR_MOE_Msk (0x1UL << TIM_BDTR_MOE_Pos)
#define TIM_BDTR_DTG_Pos 0U
#define TIM_BDTR_DTG_Msk (0xFFUL << TIM_BDTR_DTG_Pos)
/* Interrupt numbers */
enum IRQn {
WWDG_IRQn = 0,
PVD_IRQn = 1,
RTC_IRQn = 2,
FLASH_IRQn = 3,
RCC_IRQn = 4,
EXTI0_1_IRQn = 5,
EXTI2_3_IRQn = 6,
EXTI4_15_IRQn = 7,
DMA1_Ch1_IRQn = 9,
DMA1_Ch2_3_IRQn = 10,
DMA1_Ch4_5_IRQn = 11,
ADC1_IRQn = 12,
TIM1_BRK_IRQn = 13,
TIM1_UP_IRQn = 14,
TIM1_TRG_LVL_IRQn = 15,
TIM1_CC_IRQn = 16,
TIM3_IRQn = 17,
TIM14_IRQn = 19,
TIM16_IRQn = 21,
TIM17_IRQn = 22,
I2C1_IRQn = 23,
SPI1_IRQn = 24,
USART1_IRQn = 25,
UART1_IRQn = 28,
LPUART1_IRQn = 29,
};
#ifdef __cplusplus
}
#endif
#endif