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构建系统
This commit is contained in:
2026-05-11 19:55:43 +08:00
commit b49c9ab0c6
55 changed files with 5011 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
#ifndef __CMSIS_COMPILER_H__
#define __CMSIS_COMPILER_H__
#include <stdint.h>
#define __I volatile const
#define __O volatile
#define __IO volatile
#define __IM volatile const
#define __OM volatile
#define __IOM volatile
#define __CLZ __builtin_clz
#ifndef __ASM
#define __ASM __asm
#endif
#ifndef __INLINE
#define __INLINE inline
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline
#endif
#ifndef __NO_RETURN
#define __NO_RETURN __attribute__((__noreturn__))
#endif
#ifndef __USED
#define __USED __attribute__((used))
#endif
#ifndef __WEAK
#define __WEAK __attribute__((weak))
#endif
#ifndef __UNALIGNED_UINT32
#define __UNALIGNED_UINT32(x) (*((volatile uint32_t *)(x)))
#endif
#ifndef __PACKED
#define __PACKED __attribute__((packed))
#endif
#ifndef __ALIGNED
#define __ALIGNED(x) __attribute__((aligned(x)))
#endif
#endif
+161
View File
@@ -0,0 +1,161 @@
#ifndef __CMSIS_GCC_H__
#define __CMSIS_GCC_H__
#include <stdint.h>
#define __DMB() __asm volatile ("dmb" ::: "memory")
#define __DSB() __asm volatile ("dsb" ::: "memory")
#define __ISB() __asm volatile ("isb" ::: "memory")
#define __NOP() __asm volatile ("nop")
#define __WFI() __asm volatile ("wfi")
#define __WFE() __asm volatile ("wfe")
#define __SEV() __asm volatile ("sev")
__STATIC_INLINE uint32_t __get_PSP(void)
{
uint32_t result;
__ASM volatile ("MRS %0, psp" : "=r" (result));
return result;
}
__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
{
__ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack));
}
__STATIC_INLINE uint32_t __get_MSP(void)
{
uint32_t result;
__ASM volatile ("MRS %0, msp" : "=r" (result));
return result;
}
__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
{
__ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack));
}
__STATIC_INLINE uint32_t __get_PRIMASK(void)
{
uint32_t result;
__ASM volatile ("MRS %0, primask" : "=r" (result));
return result;
}
__STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
{
__ASM volatile ("MSR primask, %0" : : "r" (priMask));
}
__STATIC_INLINE void __enable_irq(void)
{
__ASM volatile ("cpsie i" ::: "memory");
}
__STATIC_INLINE void __disable_irq(void)
{
__ASM volatile ("cpsid i" ::: "memory");
}
__STATIC_INLINE uint32_t __get_CONTROL(void)
{
uint32_t result;
__ASM volatile ("MRS %0, control" : "=r" (result));
return result;
}
__STATIC_INLINE void __set_CONTROL(uint32_t control)
{
__ASM volatile ("MSR control, %0" : : "r" (control));
}
__STATIC_INLINE void __BKPT(uint32_t value)
{
__ASM volatile ("bkpt %0" : : "i" (value));
}
__STATIC_INLINE uint32_t __RBIT(uint32_t value)
{
uint32_t result;
__ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value));
return result;
}
__STATIC_INLINE uint32_t __REV(uint32_t value)
{
uint32_t result;
__ASM volatile ("rev %0, %1" : "=r" (result) : "r" (value));
return result;
}
__STATIC_INLINE uint32_t __REV16(uint32_t value)
{
uint32_t result;
__ASM volatile ("rev16 %0, %1" : "=r" (result) : "r" (value));
return result;
}
__STATIC_INLINE int32_t __REVSH(int32_t value)
{
int32_t result;
__ASM volatile ("revsh %0, %1" : "=r" (result) : "r" (value));
return result;
}
__STATIC_INLINE uint32_t __RRX(uint32_t value)
{
uint32_t result;
__ASM volatile ("rrx %0, %1" : "=r" (result) : "r" (value));
return result;
}
__STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
{
uint32_t result;
__ASM volatile ("ror %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2));
return result;
}
__STATIC_INLINE uint32_t __LDREXB(uint8_t *addr)
{
uint32_t result;
__ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr));
return result;
}
__STATIC_INLINE uint32_t __LDREXH(uint16_t *addr)
{
uint32_t result;
__ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr));
return result;
}
__STATIC_INLINE uint32_t __LDREXW(uint32_t *addr)
{
uint32_t result;
__ASM volatile ("ldrex %0, [%1]" : "=r" (result) : "r" (addr));
return result;
}
__STATIC_INLINE uint32_t __STREXB(uint8_t value, uint8_t *addr)
{
uint32_t result;
__ASM volatile ("strexb %0, %2, [%1]" : "=&r" (result) : "r" (addr), "r" (value));
return result;
}
__STATIC_INLINE uint32_t __STREXH(uint16_t value, uint16_t *addr)
{
uint32_t result;
__ASM volatile ("strexh %0, %2, [%1]" : "=&r" (result) : "r" (addr), "r" (value));
return result;
}
__STATIC_INLINE uint32_t __STREXW(uint32_t value, uint32_t *addr)
{
uint32_t result;
__ASM volatile ("strex %0, %2, [%1]" : "=&r" (result) : "r" (addr), "r" (value));
return result;
}
#endif
+11
View File
@@ -0,0 +1,11 @@
#ifndef __CMSIS_VERSION_H__
#define __CMSIS_VERSION_H__
#define __CMSIS_VERSION_MAIN (5U)
#define __CMSIS_VERSION_SUB (1U)
#define __CMSIS_VERSION_PATCH (0U)
#define __CMSIS_VERSION ((__CMSIS_VERSION_MAIN << 16U) | \
(__CMSIS_VERSION_SUB << 8U) | \
(__CMSIS_VERSION_PATCH))
#endif
+240
View File
@@ -0,0 +1,240 @@
#ifndef __CORE_CM0PLUS_H__
#define __CORE_CM0PLUS_H__
#include <stdint.h>
#include "cmsis_version.h"
#include "cmsis_compiler.h"
#include "cmsis_gcc.h"
#ifdef __cplusplus
extern "C" {
#endif
#define __CM0PLUS_REV 0x0000U
#define __MPU_PRESENT 0U
#define __VTOR_PRESENT 1U
#define __NVIC_PRIO_BITS 2U
#define __Vendor_SysTickConfig 0U
typedef struct {
__IOM uint32_t ISER[1U];
uint32_t RESERVED0[31U];
__IOM uint32_t ICER[1U];
uint32_t RESERVED1[31U];
__IOM uint32_t ISPR[1U];
uint32_t RESERVED2[31U];
__IOM uint32_t ICPR[1U];
uint32_t RESERVED3[31U];
uint32_t RESERVED4[64U];
__IOM uint32_t IPR[8U];
} NVIC_Type;
typedef struct {
__IM uint32_t CPUID;
__IOM uint32_t ICSR;
uint32_t RESERVED0;
__IOM uint32_t AIRCR;
__IOM uint32_t SCR;
__IOM uint32_t CCR;
uint32_t RESERVED1;
__IOM uint32_t SHP[2U];
__IOM uint32_t SHCSR;
} SCB_Type;
typedef struct {
__IOM uint32_t CTRL;
__IOM uint32_t LOAD;
__IOM uint32_t VAL;
__IM uint32_t CALIB;
} SysTick_Type;
#define SCB_ACTLR_SPLISCIE_Pos 0U
#define SCB_ACTLR_SPLISCIE_Msk (1UL << SCB_ACTLR_SPLISCIE_Pos)
#define SCB_ACTLR_DISOOFP_Pos 1U
#define SCB_ACTLR_DISOOFP_Msk (1UL << SCB_ACTLR_DISOOFP_Pos)
#define SCB_ACTLR_DISFPCA_Pos 2U
#define SCB_ACTLR_DISFPCA_Msk (1UL << SCB_ACTLR_DISFPCA_Pos)
#define SCB_CPUID_REVISION_Pos 20U
#define SCB_CPUID_REVISION_Msk (0xFU << SCB_CPUID_REVISION_Pos)
#define SCB_CPUID_PARTNO_Pos 4U
#define SCB_CPUID_PARTNO_Msk (0xFFFU << SCB_CPUID_PARTNO_Pos)
#define SCB_CPUID_CONSTANT_Pos 0U
#define SCB_CPUID_CONSTANT_Msk (0xFU << SCB_CPUID_CONSTANT_Pos)
#define SCB_ICSR_NMIPENDSET_Pos 31U
#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos)
#define SCB_ICSR_PENDSVSET_Pos 28U
#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos)
#define SCB_ICSR_PENDSVCLR_Pos 27U
#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos)
#define SCB_ICSR_PENDSTSET_Pos 26U
#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos)
#define SCB_ICSR_PENDSTCLR_Pos 25U
#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos)
#define SCB_ICSR_ISRPREEMPT_Pos 23U
#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos)
#define SCB_ICSR_ISRPENDING_Pos 22U
#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos)
#define SCB_ICSR_VECTPENDING_Pos 12U
#define SCB_ICSR_VECTPENDING_Msk (0x3FFUL << SCB_ICSR_VECTPENDING_Pos)
#define SCB_ICSR_VECTACTIVE_Pos 0U
#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos)
#define SCB_AIRCR_VECTKEY_Pos 16U
#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos)
#define SCB_AIRCR_SYSRESETREQ_Pos 2U
#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos)
#define SCB_AIRCR_VECTCLRACTIVE_Pos 1U
#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos)
#define SCB_AIRCR_ENDIANESS_Pos 0U
#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos)
#define SCB_SCR_SEVONPEND_Pos 4U
#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos)
#define SCB_SCR_SLEEPDEEP_Pos 2U
#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos)
#define SCB_SCR_SLEEPONEXIT_Pos 1U
#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos)
#define SCB_CCR_STKALIGN_Pos 9U
#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos)
#define SCB_CCR_UNALIGN_TRP_Pos 3U
#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos)
#define SCB_SHCSR_SVCALLPENDED_Pos 15U
#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos)
#define SysTick_CTRL_COUNTFLAG_Pos 16U
#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos)
#define SysTick_CTRL_CLKSOURCE_Pos 2U
#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos)
#define SysTick_CTRL_TICKINT_Pos 1U
#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos)
#define SysTick_CTRL_ENABLE_Pos 0U
#define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos)
#define SysTick_LOAD_RELOAD_Pos 0U
#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos)
#define SysTick_VAL_CURRENT_Pos 0U
#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos)
#define SysTick_CALIB_TENMS_Pos 0U
#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_CALIB_TENMS_Pos)
#define SysTick_CALIB_SKEW_Pos 30U
#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos)
#define SysTick_CALIB_NOREF_Pos 31U
#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos)
#define SHP_START_ADDR 0xE000ED18U
#define VTOR_ADDR 0xE000ED08U
#define NVIC_BASE 0xE000E100U
#define SCB_BASE 0xE000ED00U
#define SysTick_BASE 0xE000E010U
#define NVIC ((NVIC_Type *)NVIC_BASE)
#define SCB ((SCB_Type *)SCB_BASE)
#define SysTick ((SysTick_Type *)SysTick_BASE)
#define NonMaskableInt_IRQn (-14)
#define HardFault_IRQn (-13)
#define SVCall_IRQn (-5)
#define PendSV_IRQn (-2)
#define SysTick_IRQn (-1)
typedef int32_t IRQn_Type;
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
{
if ((int32_t)(IRQn) >= 0)
{
NVIC->IPR[(uint32_t)IRQn] = (uint32_t)(priority << (8U - __NVIC_PRIO_BITS));
}
else
{
SCB->SHP[(uint32_t)((int32_t)(IRQn) & 0xFUL) - 4UL] = (uint32_t)(priority << (8U - __NVIC_PRIO_BITS));
}
}
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
{
return 1UL;
}
SysTick->LOAD = (uint32_t)(ticks - 1UL);
NVIC_SetPriority(SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL);
SysTick->VAL = 0UL;
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk;
return 0UL;
}
__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
{
if ((int32_t)(IRQn) >= 0)
{
return ((uint32_t)(NVIC->IPR[(uint32_t)IRQn] >> (8U - __NVIC_PRIO_BITS)));
}
else
{
return ((uint32_t)(SCB->SHP[(uint32_t)((int32_t)(IRQn) & 0xFUL) - 4UL] >> (8U - __NVIC_PRIO_BITS)));
}
}
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
{
NVIC->ISER[0U] = (uint32_t)(1UL << ((uint32_t)(int32_t)IRQn) & 0x1FUL);
}
__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
{
NVIC->ICER[0U] = (uint32_t)(1UL << ((uint32_t)(int32_t)IRQn) & 0x1FUL);
}
__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
{
return ((uint32_t)((NVIC->ISPR[0U] >> ((uint32_t)(int32_t)IRQn)) & 1UL));
}
__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
{
NVIC->ISPR[0U] = (uint32_t)(1UL << ((uint32_t)(int32_t)IRQn) & 0x1FUL);
}
__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
{
NVIC->ICPR[0U] = (uint32_t)(1UL << ((uint32_t)(int32_t)IRQn) & 0x1FUL);
}
__STATIC_INLINE void NVIC_SystemReset(void)
{
__DSB();
SCB->AIRCR = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
(SCB->AIRCR & SCB_AIRCR_ENDIANESS_Msk) |
SCB_AIRCR_SYSRESETREQ_Msk);
__DSB();
for (;;) { __NOP(); }
}
__STATIC_INLINE uint32_t SCB_GetVTOR(void)
{
return (*(volatile uint32_t *)VTOR_ADDR);
}
__STATIC_INLINE void SCB_SetVTOR(uint32_t offset)
{
*(volatile uint32_t *)VTOR_ADDR = offset;
}
#ifdef __cplusplus
}
#endif
#endif
+644
View File
@@ -0,0 +1,644 @@
#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
+77
View File
@@ -0,0 +1,77 @@
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 8K
}
_estack = ORIGIN(RAM) + LENGTH(RAM);
SECTIONS
{
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector))
. = ALIGN(4);
} > FLASH
.text :
{
. = ALIGN(4);
*(.text)
*(.text*)
*(.glue_7)
*(.glue_7t)
*(.eh_frame)
KEEP(*(.init))
KEEP(*(.fini))
. = ALIGN(4);
_etext = .;
} > FLASH
.ARM.exidx :
{
*(.ARM.exidx*)
. = ALIGN(4);
} > FLASH
.rodata :
{
. = ALIGN(4);
*(.rodata)
*(.rodata*)
. = ALIGN(4);
} > FLASH
_sidata = .;
.data : AT(_sidata)
{
. = ALIGN(4);
_sdata = .;
*(.data)
*(.data*)
. = ALIGN(4);
_edata = .;
} > RAM
.bss :
{
. = ALIGN(4);
_sbss = .;
__bss_start = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .;
__bss_end = _ebss;
} > RAM
.ARM.attributes 0 : { *(.ARM.attributes) }
_end = .;
PROVIDE(end = .);
}
+261
View File
@@ -0,0 +1,261 @@
.syntax unified
.cpu cortex-m0plus
.fpu softvfp
.thumb
.global g_pfnVectors
.global Default_Handler
.word _sidata
.word _sdata
.word _edata
.word _sbss
.word _ebss
.equ BootRAM, 0xF108F85F
.macro def_irq_handler handler_name
.weak \handler_name
.set \handler_name, Default_Handler
.endm
.section .text.Default_Handler,"ax",%progbits
Default_Handler:
b Default_Handler
.section .text.Reset_Handler,"ax",%progbits
.global Reset_Handler
Reset_Handler:
ldr r0, =_estack
mov sp, r0
ldr r1, =_sbss
ldr r2, =_ebss
movs r3, #0
b FillZeroLoop
FillZero:
str r3, [r1]
adds r1, r1, #4
FillZeroLoop:
cmp r1, r2
bcc FillZero
ldr r0, =_sidata
ldr r1, =_sdata
ldr r2, =_edata
b CopyDataLoop
CopyData:
ldr r3, [r0]
str r3, [r1]
adds r0, r0, #4
adds r1, r1, #4
CopyDataLoop:
cmp r1, r2
bcc CopyData
bl SystemInit
bl main
LoopForever:
b LoopForever
def_irq_handler NMI_Handler
def_irq_handler HardFault_Handler
def_irq_handler SVCall_Handler
def_irq_handler PendSV_Handler
def_irq_handler SysTick_Handler
def_irq_handler WWDG_IRQHandler
def_irq_handler RCC_IRQHandler
def_irq_handler EXTI0_1_IRQHandler
def_irq_handler EXTI2_3_IRQHandler
def_irq_handler EXTI4_15_IRQHandler
def_irq_handler DMA1_Ch1_IRQHandler
def_irq_handler DMA1_Ch2_3_IRQHandler
def_irq_handler DMA1_Ch4_5_IRQHandler
def_irq_handler ADC1_IRQHandler
def_irq_handler TIM1_BRK_IRQHandler
def_irq_handler TIM1_UP_IRQHandler
def_irq_handler TIM1_TRG_LVL_IRQHandler
def_irq_handler TIM1_CC_IRQHandler
def_irq_handler TIM3_IRQHandler
def_irq_handler TIM14_IRQHandler
def_irq_handler TIM16_IRQHandler
def_irq_handler TIM17_IRQHandler
def_irq_handler I2C1_IRQHandler
def_irq_handler SPI1_IRQHandler
def_irq_handler USART1_IRQHandler
def_irq_handler UART1_IRQHandler
def_irq_handler LPUART1_IRQHandler
.section .isr_vector,"a",%progbits
.type g_pfnVectors, %object
.size g_pfnVectors, .-g_pfnVectors
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 SVCall_Handler
.word 0
.word 0
.word PendSV_Handler
.word SysTick_Handler
.word WWDG_IRQHandler
.word RCC_IRQHandler
.word EXTI0_1_IRQHandler
.word EXTI2_3_IRQHandler
.word EXTI4_15_IRQHandler
.word 0
.word 0
.word DMA1_Ch1_IRQHandler
.word DMA1_Ch2_3_IRQHandler
.word DMA1_Ch4_5_IRQHandler
.word ADC1_IRQHandler
.word TIM1_BRK_IRQHandler
.word TIM1_UP_IRQHandler
.word TIM1_TRG_LVL_IRQHandler
.word TIM1_CC_IRQHandler
.word TIM3_IRQHandler
.word 0
.word TIM14_IRQHandler
.word 0
.word TIM16_IRQHandler
.word TIM17_IRQHandler
.word I2C1_IRQHandler
.word SPI1_IRQHandler
.word USART1_IRQHandler
.word 0
.word 0
.word UART1_IRQHandler
.word LPUART1_IRQHandler
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
+68
View File
@@ -0,0 +1,68 @@
#include "system_py32md530.h"
#include "py32md530.h"
uint32_t SystemCoreClock = 8000000UL;
static void HSI_Setup(void)
{
RCC->CR |= ((uint32_t)RCC_CR_HSION);
while ((RCC->CR & RCC_CR_HSIRDY) == 0);
}
static void PLL_Setup(void)
{
RCC->CFGR &= ~RCC_CFGR_PLLSRC;
RCC->CFGR |= RCC_CFGR_PLLSRC;
RCC->CFGR2 &= ~RCC_CFGR2_PLLMUL;
RCC->CFGR2 |= RCC_CFGR2_PLLMUL9;
RCC->CR |= RCC_CR_PLLON;
while ((RCC->CR & RCC_CR_PLLRDY) == 0);
}
static void Flash_Setup(void)
{
#define FLASH_ACR_LATENCY_Pos 0
#define FLASH_ACR_LATENCY_Msk (0x1UL << FLASH_ACR_LATENCY_Pos)
#define FLASH_ACR_PRFTBE_Pos 4
#define FLASH_ACR_PRFTBE_Msk (0x1UL << FLASH_ACR_PRFTBE_Pos)
uint32_t acr = *((uint32_t *)0x40022000);
acr |= FLASH_ACR_LATENCY_Msk;
acr |= FLASH_ACR_PRFTBE_Msk;
*((uint32_t *)0x40022000) = acr;
}
void SystemInit(void)
{
HSI_Setup();
PLL_Setup();
Flash_Setup();
RCC->CFGR &= ~RCC_CFGR_SW;
RCC->CFGR |= RCC_CFGR_SW_PLL;
while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL);
SystemCoreClock = 72000000UL;
RCC->APB1ENR |= RCC_APB1ENR_PWREN;
}
void SystemCoreClockUpdate(void)
{
uint32_t tmp;
tmp = RCC->CFGR & RCC_CFGR_SWS;
switch (tmp) {
case RCC_CFGR_SWS_HSI:
SystemCoreClock = 8000000UL;
break;
case RCC_CFGR_SWS_PLL:
SystemCoreClock = 72000000UL;
break;
default:
SystemCoreClock = 8000000UL;
break;
}
}
+19
View File
@@ -0,0 +1,19 @@
#ifndef SYSTEM_PY32MD530_H__
#define SYSTEM_PY32MD530_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
extern uint32_t SystemCoreClock;
void SystemInit(void);
void SystemCoreClockUpdate(void);
#ifdef __cplusplus
}
#endif
#endif