diff --git a/.platformio/packages/framework-cmsis-at32f40/libraries/AT32_USB-FS-Device_Driver/library.properties b/.platformio/packages/framework-cmsis-at32f40/libraries/AT32_USB-FS-Device_Driver/library.properties index 8e4ec24..6c28cac 100644 --- a/.platformio/packages/framework-cmsis-at32f40/libraries/AT32_USB-FS-Device_Driver/library.properties +++ b/.platformio/packages/framework-cmsis-at32f40/libraries/AT32_USB-FS-Device_Driver/library.properties @@ -1,4 +1,4 @@ -name=AT32_USB-FS-Device_Driver +name=AT32F435_427_USB-FS-Device_Driver version=1.0.0 author=AT maintainer=AT diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_acc.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_acc.h deleted file mode 100644 index 061da6e..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_acc.h +++ /dev/null @@ -1,205 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_acc.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 acc header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_ACC_H -#define __AT32F435_437_ACC_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup ACC - * @{ - */ - -/** @defgroup ACC_exported_constants - * @{ - */ - -#define ACC_CAL_HICKCAL ((uint16_t)0x0000) /*!< acc hick calibration */ -#define ACC_CAL_HICKTRIM ((uint16_t)0x0002) /*!< acc hick trim */ - -#define ACC_RSLOST_FLAG ((uint16_t)0x0002) /*!< acc reference signal lost error flag */ -#define ACC_CALRDY_FLAG ((uint16_t)0x0001) /*!< acc internal high-speed clock calibration ready error flag */ - -#define ACC_CALRDYIEN_INT ((uint16_t)0x0020) /*!< acc internal high-speed clock calibration ready interrupt enable */ -#define ACC_EIEN_INT ((uint16_t)0x0010) /*!< acc reference signal lost interrupt enable */ - -#define ACC_SOF_OTG1 ((uint16_t)0x0000) /*!< acc sof signal select: otg1 */ -#define ACC_SOF_OTG2 ((uint16_t)0x0004) /*!< acc sof signal select: otg2 */ - -/** - * @} - */ - -/** @defgroup ACC_exported_types - * @{ - */ - -/** - * @brief type define acc register all - */ -typedef struct -{ - - /** - * @brief acc sts register, offset:0x00 - */ - union - { - __IO uint32_t sts; - struct - { - __IO uint32_t calrdy : 1; /* [0] */ - __IO uint32_t rslost : 1; /* [1] */ - __IO uint32_t reserved1 : 30;/* [31:2] */ - } sts_bit; - }; - - /** - * @brief acc ctrl1 register, offset:0x04 - */ - union - { - __IO uint32_t ctrl1; - struct - { - __IO uint32_t calon : 1; /* [0] */ - __IO uint32_t entrim : 1; /* [1] */ - __IO uint32_t reserved1 : 2; /* [3:2] */ - __IO uint32_t eien : 1; /* [4] */ - __IO uint32_t calrdyien : 1; /* [5] */ - __IO uint32_t reserved2 : 2; /* [7:6] */ - __IO uint32_t step : 4; /* [11:8] */ - __IO uint32_t reserved3 : 20;/* [31:12] */ - } ctrl1_bit; - }; - - /** - * @brief acc ctrl2 register, offset:0x08 - */ - union - { - __IO uint32_t ctrl2; - struct - { - __IO uint32_t hickcal : 8; /* [7:0] */ - __IO uint32_t hicktrim : 6; /* [13:8] */ - __IO uint32_t reserved1 : 18;/* [31:14] */ - } ctrl2_bit; - }; - - /** - * @brief acc acc_c1 register, offset:0x0C - */ - union - { - __IO uint32_t c1; - struct - { - __IO uint32_t c1 : 16;/* [15:0] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } c1_bit; - }; - - /** - * @brief acc acc_c2 register, offset:0x10 - */ - union - { - __IO uint32_t c2; - struct - { - __IO uint32_t c2 : 16;/* [15:0] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } c2_bit; - }; - - /** - * @brief acc acc_c3 register, offset:0x14 - */ - union - { - __IO uint32_t c3; - struct - { - __IO uint32_t c3 : 16;/* [15:0] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } c3_bit; - }; -} acc_type; - -/** - * @} - */ - -#define ACC ((acc_type *) ACC_BASE) - -/** @defgroup ACC_exported_functions - * @{ - */ - -void acc_calibration_mode_enable(uint16_t acc_trim, confirm_state new_state); -void acc_step_set(uint8_t step_value); -void acc_sof_select(uint16_t sof_sel); -void acc_interrupt_enable(uint16_t acc_int, confirm_state new_state); -uint8_t acc_hicktrim_get(void); -uint8_t acc_hickcal_get(void); -void acc_write_c1(uint16_t acc_c1_value); -void acc_write_c2(uint16_t acc_c2_value); -void acc_write_c3(uint16_t acc_c3_value); -uint16_t acc_read_c1(void); -uint16_t acc_read_c2(void); -uint16_t acc_read_c3(void); -flag_status acc_flag_get(uint16_t acc_flag); -void acc_flag_clear(uint16_t acc_flag); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_adc.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_adc.h deleted file mode 100644 index 53510b9..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_adc.h +++ /dev/null @@ -1,938 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_adc.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 adc header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_ADC_H -#define __AT32F435_437_ADC_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup ADC - * @{ - */ - -/** @defgroup ADC_interrupts_definition - * @brief adc interrupt - * @{ - */ - -#define ADC_OCCE_INT ((uint32_t)0x00000020) /*!< ordinary channels conversion end interrupt */ -#define ADC_VMOR_INT ((uint32_t)0x00000040) /*!< voltage monitoring out of range interrupt */ -#define ADC_PCCE_INT ((uint32_t)0x00000080) /*!< preempt channels conversion end interrupt */ -#define ADC_OCCO_INT ((uint32_t)0x04000000) /*!< ordinary channel conversion overflow interrupt */ - -/** - * @} - */ - -/** @defgroup ADC_flags_definition - * @brief adc flag - * @{ - */ - -#define ADC_VMOR_FLAG ((uint8_t)0x01) /*!< voltage monitoring out of range flag */ -#define ADC_OCCE_FLAG ((uint8_t)0x02) /*!< ordinary channels conversion end flag */ -#define ADC_PCCE_FLAG ((uint8_t)0x04) /*!< preempt channels conversion end flag */ -#define ADC_PCCS_FLAG ((uint8_t)0x08) /*!< preempt channel conversion start flag */ -#define ADC_OCCS_FLAG ((uint8_t)0x10) /*!< ordinary channel conversion start flag */ -#define ADC_OCCO_FLAG ((uint8_t)0x20) /*!< ordinary channel conversion overflow flag */ -#define ADC_RDY_FLAG ((uint8_t)0x40) /*!< adc ready to conversion flag */ - -/** - * @} - */ - -/** @defgroup ADC_exported_types - * @{ - */ - -/** - * @brief adc division type - */ -typedef enum -{ - ADC_HCLK_DIV_2 = 0x00, /*!< adcclk is hclk/2 */ - ADC_HCLK_DIV_3 = 0x01, /*!< adcclk is hclk/3 */ - ADC_HCLK_DIV_4 = 0x02, /*!< adcclk is hclk/4 */ - ADC_HCLK_DIV_5 = 0x03, /*!< adcclk is hclk/5 */ - ADC_HCLK_DIV_6 = 0x04, /*!< adcclk is hclk/6 */ - ADC_HCLK_DIV_7 = 0x05, /*!< adcclk is hclk/7 */ - ADC_HCLK_DIV_8 = 0x06, /*!< adcclk is hclk/8 */ - ADC_HCLK_DIV_9 = 0x07, /*!< adcclk is hclk/9 */ - ADC_HCLK_DIV_10 = 0x08, /*!< adcclk is hclk/10 */ - ADC_HCLK_DIV_11 = 0x09, /*!< adcclk is hclk/11 */ - ADC_HCLK_DIV_12 = 0x0A, /*!< adcclk is hclk/12 */ - ADC_HCLK_DIV_13 = 0x0B, /*!< adcclk is hclk/13 */ - ADC_HCLK_DIV_14 = 0x0C, /*!< adcclk is hclk/14 */ - ADC_HCLK_DIV_15 = 0x0D, /*!< adcclk is hclk/15 */ - ADC_HCLK_DIV_16 = 0x0E, /*!< adcclk is hclk/16 */ - ADC_HCLK_DIV_17 = 0x0F /*!< adcclk is hclk/17 */ -} adc_div_type; - -/** - * @brief adc combine mode type - */ -typedef enum -{ - ADC_INDEPENDENT_MODE = 0x00, /*!< independent mode */ - ADC_ORDINARY_SMLT_PREEMPT_SMLT_ONESLAVE_MODE = 0x01, /*!< single slaver combined ordinary simultaneous + preempt simultaneous mode */ - ADC_ORDINARY_SMLT_PREEMPT_INTERLTRIG_ONESLAVE_MODE = 0x02, /*!< single slaver combined ordinary simultaneous + preempt interleaved trigger mode */ - ADC_PREEMPT_SMLT_ONLY_ONESLAVE_MODE = 0x05, /*!< single slaver preempt simultaneous mode only */ - ADC_ORDINARY_SMLT_ONLY_ONESLAVE_MODE = 0x06, /*!< single slaver ordinary simultaneous mode only */ - ADC_ORDINARY_SHIFT_ONLY_ONESLAVE_MODE = 0x07, /*!< single slaver ordinary shifting mode only */ - ADC_PREEMPT_INTERLTRIG_ONLY_ONESLAVE_MODE = 0x09, /*!< single slaver preempt interleaved trigger mode only */ - ADC_ORDINARY_SMLT_PREEMPT_SMLT_TWOSLAVE_MODE = 0x11, /*!< double slaver combined ordinary simultaneous + preempt simultaneous mode */ - ADC_ORDINARY_SMLT_PREEMPT_INTERLTRIG_TWOSLAVE_MODE = 0x12, /*!< double slaver combined ordinary simultaneous + preempt interleaved trigger mode */ - ADC_PREEMPT_SMLT_ONLY_TWOSLAVE_MODE = 0x15, /*!< double slaver preempt simultaneous mode only */ - ADC_ORDINARY_SMLT_ONLY_TWOSLAVE_MODE = 0x16, /*!< double slaver ordinary simultaneous mode only */ - ADC_ORDINARY_SHIFT_ONLY_TWOSLAVE_MODE = 0x17, /*!< double slaver ordinary shifting mode only */ - ADC_PREEMPT_INTERLTRIG_ONLY_TWOSLAVE_MODE = 0x19 /*!< double slaver preempt interleaved trigger mode only */ -} adc_combine_mode_type; - -/** - * @brief adc common dma mode type - */ -typedef enum -{ - ADC_COMMON_DMAMODE_DISABLE = 0x00, /*!< dma mode disabled */ - ADC_COMMON_DMAMODE_1 = 0x01, /*!< dma mode1: each dma request trans a half-word data(reference manual account the rule of data package) */ - ADC_COMMON_DMAMODE_2 = 0x02, /*!< dma mode2: each dma request trans two half-word data(reference manual account the rule of data package) */ - ADC_COMMON_DMAMODE_3 = 0x03, /*!< dma mode3: each dma request trans two bytes data(reference manual account the rule of data package) */ - ADC_COMMON_DMAMODE_4 = 0x04, /*!< dma mode4: each dma request trans three bytes data(reference manual account the rule of data package) */ - ADC_COMMON_DMAMODE_5 = 0x05 /*!< dma mode5: odd dma request trans two half-word data,even dma request trans a half-word data(reference manual account the rule of data package) */ -} adc_common_dma_mode_type; - -/** - * @brief adc common sampling interval type - */ -typedef enum -{ - ADC_SAMPLING_INTERVAL_5CYCLES = 0x00, /*!< ordinary shifting mode adjacent adc sampling interval 5 adcclk */ - ADC_SAMPLING_INTERVAL_6CYCLES = 0x01, /*!< ordinary shifting mode adjacent adc sampling interval 6 adcclk */ - ADC_SAMPLING_INTERVAL_7CYCLES = 0x02, /*!< ordinary shifting mode adjacent adc sampling interval 7 adcclk */ - ADC_SAMPLING_INTERVAL_8CYCLES = 0x03, /*!< ordinary shifting mode adjacent adc sampling interval 8 adcclk */ - ADC_SAMPLING_INTERVAL_9CYCLES = 0x04, /*!< ordinary shifting mode adjacent adc sampling interval 9 adcclk */ - ADC_SAMPLING_INTERVAL_10CYCLES = 0x05, /*!< ordinary shifting mode adjacent adc sampling interval 10 adcclk */ - ADC_SAMPLING_INTERVAL_11CYCLES = 0x06, /*!< ordinary shifting mode adjacent adc sampling interval 11 adcclk */ - ADC_SAMPLING_INTERVAL_12CYCLES = 0x07, /*!< ordinary shifting mode adjacent adc sampling interval 12 adcclk */ - ADC_SAMPLING_INTERVAL_13CYCLES = 0x08, /*!< ordinary shifting mode adjacent adc sampling interval 13 adcclk */ - ADC_SAMPLING_INTERVAL_14CYCLES = 0x09, /*!< ordinary shifting mode adjacent adc sampling interval 14 adcclk */ - ADC_SAMPLING_INTERVAL_15CYCLES = 0x0A, /*!< ordinary shifting mode adjacent adc sampling interval 15 adcclk */ - ADC_SAMPLING_INTERVAL_16CYCLES = 0x0B, /*!< ordinary shifting mode adjacent adc sampling interval 16 adcclk */ - ADC_SAMPLING_INTERVAL_17CYCLES = 0x0C, /*!< ordinary shifting mode adjacent adc sampling interval 17 adcclk */ - ADC_SAMPLING_INTERVAL_18CYCLES = 0x0D, /*!< ordinary shifting mode adjacent adc sampling interval 18 adcclk */ - ADC_SAMPLING_INTERVAL_19CYCLES = 0x0E, /*!< ordinary shifting mode adjacent adc sampling interval 19 adcclk */ - ADC_SAMPLING_INTERVAL_20CYCLES = 0x0F /*!< ordinary shifting mode adjacent adc sampling interval 20 adcclk */ -} adc_sampling_interval_type; - -/** - * @brief adc conversion resolution type - */ -typedef enum -{ - ADC_RESOLUTION_12B = 0x00, /*!< conversion resolution 12 bit */ - ADC_RESOLUTION_10B = 0x01, /*!< conversion resolution 10 bit */ - ADC_RESOLUTION_8B = 0x02, /*!< conversion resolution 8 bit */ - ADC_RESOLUTION_6B = 0x03 /*!< conversion resolution 6 bit */ -} adc_resolution_type; - -/** - * @brief adc data align type - */ -typedef enum -{ - ADC_RIGHT_ALIGNMENT = 0x00, /*!< data right alignment */ - ADC_LEFT_ALIGNMENT = 0x01 /*!< data left alignment */ -} adc_data_align_type; - -/** - * @brief adc channel select type - */ -typedef enum -{ - ADC_CHANNEL_0 = 0x00, /*!< adc channel 0 */ - ADC_CHANNEL_1 = 0x01, /*!< adc channel 1 */ - ADC_CHANNEL_2 = 0x02, /*!< adc channel 2 */ - ADC_CHANNEL_3 = 0x03, /*!< adc channel 3 */ - ADC_CHANNEL_4 = 0x04, /*!< adc channel 4 */ - ADC_CHANNEL_5 = 0x05, /*!< adc channel 5 */ - ADC_CHANNEL_6 = 0x06, /*!< adc channel 6 */ - ADC_CHANNEL_7 = 0x07, /*!< adc channel 7 */ - ADC_CHANNEL_8 = 0x08, /*!< adc channel 8 */ - ADC_CHANNEL_9 = 0x09, /*!< adc channel 9 */ - ADC_CHANNEL_10 = 0x0A, /*!< adc channel 10 */ - ADC_CHANNEL_11 = 0x0B, /*!< adc channel 11 */ - ADC_CHANNEL_12 = 0x0C, /*!< adc channel 12 */ - ADC_CHANNEL_13 = 0x0D, /*!< adc channel 13 */ - ADC_CHANNEL_14 = 0x0E, /*!< adc channel 14 */ - ADC_CHANNEL_15 = 0x0F, /*!< adc channel 15 */ - ADC_CHANNEL_16 = 0x10, /*!< adc channel 16 */ - ADC_CHANNEL_17 = 0x11, /*!< adc channel 17 */ - ADC_CHANNEL_18 = 0x12 /*!< adc channel 18 */ -} adc_channel_select_type; - -/** - * @brief adc sampletime select type - */ -typedef enum -{ - ADC_SAMPLETIME_2_5 = 0x00, /*!< adc sample time 2.5 cycle */ - ADC_SAMPLETIME_6_5 = 0x01, /*!< adc sample time 6.5 cycle */ - ADC_SAMPLETIME_12_5 = 0x02, /*!< adc sample time 12.5 cycle */ - ADC_SAMPLETIME_24_5 = 0x03, /*!< adc sample time 24.5 cycle */ - ADC_SAMPLETIME_47_5 = 0x04, /*!< adc sample time 47.5 cycle */ - ADC_SAMPLETIME_92_5 = 0x05, /*!< adc sample time 92.5 cycle */ - ADC_SAMPLETIME_247_5 = 0x06, /*!< adc sample time 247.5 cycle */ - ADC_SAMPLETIME_640_5 = 0x07 /*!< adc sample time 640.5 cycle */ -} adc_sampletime_select_type; - -/** - * @brief adc ordinary group trigger event select type - */ -typedef enum -{ - ADC_ORDINARY_TRIG_TMR1CH1 = 0x00, /*!< timer1 ch1 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR1CH2 = 0x01, /*!< timer1 ch2 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR1CH3 = 0x02, /*!< timer1 ch3 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR2CH2 = 0x03, /*!< timer2 ch2 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR2CH3 = 0x04, /*!< timer2 ch3 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR2CH4 = 0x05, /*!< timer2 ch4 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR2TRGOUT = 0x06, /*!< timer2 trgout event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR3CH1 = 0x07, /*!< timer3 ch1 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR3TRGOUT = 0x08, /*!< timer3 trgout event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR4CH4 = 0x09, /*!< timer4 ch4 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR5CH1 = 0x0A, /*!< timer5 ch1 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR5CH2 = 0x0B, /*!< timer5 ch2 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR5CH3 = 0x0C, /*!< timer5 ch3 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR8CH1 = 0x0D, /*!< timer8 ch1 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR8TRGOUT = 0x0E, /*!< timer8 trgout event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_EXINT11 = 0x0F, /*!< exint line11 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR20TRGOUT = 0x10, /*!< timer20 trgout event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR20TRGOUT2 = 0x11, /*!< timer20 trgout2 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR20CH1 = 0x12, /*!< timer20 ch1 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR20CH2 = 0x13, /*!< timer20 ch2 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR20CH3 = 0x14, /*!< timer20 ch3 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR8TRGOUT2 = 0x15, /*!< timer8 trgout2 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR1TRGOUT2 = 0x16, /*!< timer1 trgout2 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR4TRGOUT = 0x17, /*!< timer4 trgout event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR6TRGOUT = 0x18, /*!< timer6 trgout event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR3CH4 = 0x19, /*!< timer3 ch4 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR4CH1 = 0x1A, /*!< timer4 ch1 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR1TRGOUT = 0x1B, /*!< timer1 trgout event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR2CH1 = 0x1C, /*!< timer2 ch1 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR7TRGOUT = 0x1E /*!< timer7 trgout event as trigger source of ordinary sequence */ -} adc_ordinary_trig_select_type; - -/** - * @brief adc ordinary channel conversion's external_trigger_edge type - */ -typedef enum -{ - ADC_ORDINARY_TRIG_EDGE_NONE = 0x00, /*!< ordinary channels trigger detection disabled */ - ADC_ORDINARY_TRIG_EDGE_RISING = 0x01, /*!< ordinary channels trigger detection on the rising edge */ - ADC_ORDINARY_TRIG_EDGE_FALLING = 0x02, /*!< ordinary channels trigger detection on the falling edge */ - ADC_ORDINARY_TRIG_EDGE_RISING_FALLING = 0x03 /*!< ordinary channels trigger detection on both the rising and falling edges */ -} adc_ordinary_trig_edge_type; - -/** - * @brief adc preempt group external trigger event select type - */ -typedef enum -{ - ADC_PREEMPT_TRIG_TMR1CH4 = 0x00, /*!< timer1 ch4 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR1TRGOUT = 0x01, /*!< timer1 trgout event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR2CH1 = 0x02, /*!< timer2 ch1 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR2TRGOUT = 0x03, /*!< timer2 trgout event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR3CH2 = 0x04, /*!< timer3 ch2 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR3CH4 = 0x05, /*!< timer3 ch4 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR4CH1 = 0x06, /*!< timer4 ch1 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR4CH2 = 0x07, /*!< timer4 ch2 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR4CH3 = 0x08, /*!< timer4 ch3 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR4TRGOUT = 0x09, /*!< timer4 trgout event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR5CH4 = 0x0A, /*!< timer5 ch4 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR5TRGOUT = 0x0B, /*!< timer5 trgout event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR8CH2 = 0x0C, /*!< timer8 ch2 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR8CH3 = 0x0D, /*!< timer8 ch3 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR8CH4 = 0x0E, /*!< timer8 ch4 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_EXINT15 = 0x0F, /*!< exint line15 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR20TRGOUT = 0x10, /*!< timer20 trgout event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR20TRGOUT2 = 0x11, /*!< timer20 trgout2 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR20CH4 = 0x12, /*!< timer20 ch4 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR1TRGOUT2 = 0x13, /*!< timer1 trgout2 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR8TRGOUT = 0x14, /*!< timer8 trgout event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR8TRGOUT2 = 0x15, /*!< timer8 trgout2 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR3CH3 = 0x16, /*!< timer3 ch3 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR3TRGOUT = 0x17, /*!< timer3 trgout event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR3CH1 = 0x18, /*!< timer3 ch1 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR6TRGOUT = 0x19, /*!< timer6 trgout event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR4CH4 = 0x1A, /*!< timer4 ch4 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR1CH3 = 0x1B, /*!< timer1 ch3 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR20CH2 = 0x1C, /*!< timer20 ch2 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR7TRGOUT = 0x1E /*!< timer7 trgout event as trigger source of preempt sequence */ -} adc_preempt_trig_select_type; - -/** - * @brief adc preempt channel conversion's external_trigger_edge type - */ -typedef enum -{ - ADC_PREEMPT_TRIG_EDGE_NONE = 0x00, /*!< preempt channels trigger detection disabled */ - ADC_PREEMPT_TRIG_EDGE_RISING = 0x01, /*!< preempt channels trigger detection on the rising edge */ - ADC_PREEMPT_TRIG_EDGE_FALLING = 0x02, /*!< preempt channels trigger detection on the falling edge */ - ADC_PREEMPT_TRIG_EDGE_RISING_FALLING = 0x03 /*!< preempt channels trigger detection on both the rising and falling edges */ -} adc_preempt_trig_edge_type; - -/** - * @brief adc preempt channel type - */ -typedef enum -{ - ADC_PREEMPT_CHANNEL_1 = 0x00, /*!< adc preempt channel 1 */ - ADC_PREEMPT_CHANNEL_2 = 0x01, /*!< adc preempt channel 2 */ - ADC_PREEMPT_CHANNEL_3 = 0x02, /*!< adc preempt channel 3 */ - ADC_PREEMPT_CHANNEL_4 = 0x03 /*!< adc preempt channel 4 */ -} adc_preempt_channel_type; - -/** - * @brief adc voltage_monitoring type - */ -typedef enum -{ - ADC_VMONITOR_SINGLE_ORDINARY = 0x00800200, /*!< voltage_monitoring on a single ordinary channel */ - ADC_VMONITOR_SINGLE_PREEMPT = 0x00400200, /*!< voltage_monitoring on a single preempt channel */ - ADC_VMONITOR_SINGLE_ORDINARY_PREEMPT = 0x00C00200, /*!< voltage_monitoring on a single ordinary or preempt channel */ - ADC_VMONITOR_ALL_ORDINARY = 0x00800000, /*!< voltage_monitoring on all ordinary channel */ - ADC_VMONITOR_ALL_PREEMPT = 0x00400000, /*!< voltage_monitoring on all preempt channel */ - ADC_VMONITOR_ALL_ORDINARY_PREEMPT = 0x00C00000, /*!< voltage_monitoring on all ordinary and preempt channel */ - ADC_VMONITOR_NONE = 0x00000000 /*!< no channel guarded by the voltage_monitoring */ -} adc_voltage_monitoring_type; - -/** - * @brief adc oversample ratio type - */ -typedef enum -{ - ADC_OVERSAMPLE_RATIO_2 = 0x00, /*!< adc oversample ratio 2 */ - ADC_OVERSAMPLE_RATIO_4 = 0x01, /*!< adc oversample ratio 4 */ - ADC_OVERSAMPLE_RATIO_8 = 0x02, /*!< adc oversample ratio 8 */ - ADC_OVERSAMPLE_RATIO_16 = 0x03, /*!< adc oversample ratio 16 */ - ADC_OVERSAMPLE_RATIO_32 = 0x04, /*!< adc oversample ratio 32 */ - ADC_OVERSAMPLE_RATIO_64 = 0x05, /*!< adc oversample ratio 64 */ - ADC_OVERSAMPLE_RATIO_128 = 0x06, /*!< adc oversample ratio 128 */ - ADC_OVERSAMPLE_RATIO_256 = 0x07 /*!< adc oversample ratio 256 */ -} adc_oversample_ratio_type; - -/** - * @brief adc oversample shift type - */ -typedef enum -{ - ADC_OVERSAMPLE_SHIFT_0 = 0x00, /*!< adc oversample shift 0 */ - ADC_OVERSAMPLE_SHIFT_1 = 0x01, /*!< adc oversample shift 1 */ - ADC_OVERSAMPLE_SHIFT_2 = 0x02, /*!< adc oversample shift 2 */ - ADC_OVERSAMPLE_SHIFT_3 = 0x03, /*!< adc oversample shift 3 */ - ADC_OVERSAMPLE_SHIFT_4 = 0x04, /*!< adc oversample shift 4 */ - ADC_OVERSAMPLE_SHIFT_5 = 0x05, /*!< adc oversample shift 5 */ - ADC_OVERSAMPLE_SHIFT_6 = 0x06, /*!< adc oversample shift 6 */ - ADC_OVERSAMPLE_SHIFT_7 = 0x07, /*!< adc oversample shift 7 */ - ADC_OVERSAMPLE_SHIFT_8 = 0x08 /*!< adc oversample shift 8 */ -} adc_oversample_shift_type; - -/** - * @brief adc ordinary oversample recover type - */ -typedef enum -{ - ADC_OVERSAMPLE_CONTINUE = 0x00, /*!< continue mode:when preempt triggered,oversampling is temporary stopped and continued after preempt sequence */ - ADC_OVERSAMPLE_RESTART = 0x01 /*!< restart mode:when preempt triggered,oversampling is aborted and resumed from start after preempt sequence */ -} adc_ordinary_oversample_restart_type; - -/** - * @brief adc common config type - */ -typedef struct -{ - adc_combine_mode_type combine_mode; /*!< adc combine mode select */ - adc_div_type div; /*!< adc division select */ - adc_common_dma_mode_type common_dma_mode; /*!< adc common dma mode select */ - confirm_state common_dma_request_repeat_state; /*!< adc common dma repeat state */ - adc_sampling_interval_type sampling_interval; /*!< ordinary shifting mode adjacent adc sampling interval select */ - confirm_state tempervintrv_state; /*!< adc temperature sensor and vintrv state */ - confirm_state vbat_state; /*!< adc voltage battery state */ -} adc_common_config_type; - -/** - * @brief adc base config type - */ -typedef struct -{ - confirm_state sequence_mode; /*!< adc sequence mode */ - confirm_state repeat_mode; /*!< adc repeat mode */ - adc_data_align_type data_align; /*!< adc data alignment */ - uint8_t ordinary_channel_length; /*!< adc ordinary channel sequence length*/ -} adc_base_config_type; - -/** - * @brief type define adc register all - */ -typedef struct -{ - - /** - * @brief adc sts register, offset:0x00 - */ - union - { - __IO uint32_t sts; - struct - { - __IO uint32_t vmor : 1; /* [0] */ - __IO uint32_t occe : 1; /* [1] */ - __IO uint32_t pcce : 1; /* [2] */ - __IO uint32_t pccs : 1; /* [3] */ - __IO uint32_t occs : 1; /* [4] */ - __IO uint32_t occo : 1; /* [5] */ - __IO uint32_t rdy : 1; /* [6] */ - __IO uint32_t reserved1 : 25;/* [31:7] */ - } sts_bit; - }; - - /** - * @brief adc ctrl1 register, offset:0x04 - */ - union - { - __IO uint32_t ctrl1; - struct - { - __IO uint32_t vmcsel : 5; /* [4:0] */ - __IO uint32_t occeien : 1; /* [5] */ - __IO uint32_t vmorien : 1; /* [6] */ - __IO uint32_t pcceien : 1; /* [7] */ - __IO uint32_t sqen : 1; /* [8] */ - __IO uint32_t vmsgen : 1; /* [9] */ - __IO uint32_t pcautoen : 1; /* [10] */ - __IO uint32_t ocpen : 1; /* [11] */ - __IO uint32_t pcpen : 1; /* [12] */ - __IO uint32_t ocpcnt : 3; /* [15:13] */ - __IO uint32_t reserved1 : 6; /* [21:16] */ - __IO uint32_t pcvmen : 1; /* [22] */ - __IO uint32_t ocvmen : 1; /* [23] */ - __IO uint32_t crsel : 2; /* [25:24] */ - __IO uint32_t occoien : 1; /* [26] */ - __IO uint32_t reserved2 : 5; /* [31:27] */ - } ctrl1_bit; - }; - - /** - * @brief adc ctrl2 register, offset:0x08 - */ - union - { - __IO uint32_t ctrl2; - struct - { - __IO uint32_t adcen : 1; /* [0] */ - __IO uint32_t rpen : 1; /* [1] */ - __IO uint32_t adcal : 1; /* [2] */ - __IO uint32_t adcalinit : 1; /* [3] */ - __IO uint32_t adabrt : 1; /* [4] */ - __IO uint32_t reserved1 : 3; /* [7:5] */ - __IO uint32_t ocdmaen : 1; /* [8] */ - __IO uint32_t ocdrcen : 1; /* [9] */ - __IO uint32_t eocsfen : 1; /* [10] */ - __IO uint32_t dtalign : 1; /* [11] */ - __IO uint32_t reserved2 : 4; /* [15:12] */ - __IO uint32_t pctesel_l : 4; /* [19:16] */ - __IO uint32_t pcete : 2; /* [21:20] */ - __IO uint32_t pcswtrg : 1; /* [22] */ - __IO uint32_t pctesel_h : 1; /* [23] */ - __IO uint32_t octesel_l : 4; /* [27:24] */ - __IO uint32_t ocete : 2; /* [29:28] */ - __IO uint32_t ocswtrg : 1; /* [30] */ - __IO uint32_t octesel_h : 1; /* [31] */ - } ctrl2_bit; - }; - - /** - * @brief adc spt1 register, offset:0x0C - */ - union - { - __IO uint32_t spt1; - struct - { - __IO uint32_t cspt10 : 3; /* [2:0] */ - __IO uint32_t cspt11 : 3; /* [5:3] */ - __IO uint32_t cspt12 : 3; /* [8:6] */ - __IO uint32_t cspt13 : 3; /* [11:9] */ - __IO uint32_t cspt14 : 3; /* [14:12] */ - __IO uint32_t cspt15 : 3; /* [17:15] */ - __IO uint32_t cspt16 : 3; /* [20:18] */ - __IO uint32_t cspt17 : 3; /* [23:21] */ - __IO uint32_t cspt18 : 3; /* [26:24] */ - __IO uint32_t reserved1 : 5;/* [31:27] */ - } spt1_bit; - }; - - /** - * @brief adc spt2 register, offset:0x10 - */ - union - { - __IO uint32_t spt2; - struct - { - __IO uint32_t cspt0 : 3;/* [2:0] */ - __IO uint32_t cspt1 : 3;/* [5:3] */ - __IO uint32_t cspt2 : 3;/* [8:6] */ - __IO uint32_t cspt3 : 3;/* [11:9] */ - __IO uint32_t cspt4 : 3;/* [14:12] */ - __IO uint32_t cspt5 : 3;/* [17:15] */ - __IO uint32_t cspt6 : 3;/* [20:18] */ - __IO uint32_t cspt7 : 3;/* [23:21] */ - __IO uint32_t cspt8 : 3;/* [26:24] */ - __IO uint32_t cspt9 : 3;/* [29:27] */ - __IO uint32_t reserved1 : 2;/* [31:30] */ - } spt2_bit; - }; - - /** - * @brief adc pcdto1 register, offset:0x14 - */ - union - { - __IO uint32_t pcdto1; - struct - { - __IO uint32_t pcdto1 : 12; /* [11:0] */ - __IO uint32_t reserved1 : 20; /* [31:12] */ - } pcdto1_bit; - }; - - /** - * @brief adc pcdto2 register, offset:0x18 - */ - union - { - __IO uint32_t pcdto2; - struct - { - __IO uint32_t pcdto2 : 12; /* [11:0] */ - __IO uint32_t reserved1 : 20; /* [31:12] */ - } pcdto2_bit; - }; - - /** - * @brief adc pcdto3 register, offset:0x1C - */ - union - { - __IO uint32_t pcdto3; - struct - { - __IO uint32_t pcdto3 : 12; /* [11:0] */ - __IO uint32_t reserved1 : 20; /* [31:12] */ - } pcdto3_bit; - }; - - /** - * @brief adc pcdto4 register, offset:0x20 - */ - union - { - __IO uint32_t pcdto4; - struct - { - __IO uint32_t pcdto4 : 12; /* [11:0] */ - __IO uint32_t reserved1 : 20; /* [31:12] */ - } pcdto4_bit; - }; - - /** - * @brief adc vmhb register, offset:0x24 - */ - union - { - __IO uint32_t vmhb; - struct - { - __IO uint32_t vmhb : 12; /* [11:0] */ - __IO uint32_t reserved1 : 20; /* [31:12] */ - } vmhb_bit; - }; - - /** - * @brief adc vmlb register, offset:0x28 - */ - union - { - __IO uint32_t vmlb; - struct - { - __IO uint32_t vmlb : 12; /* [11:0] */ - __IO uint32_t reserved1 : 20; /* [31:12] */ - } vmlb_bit; - }; - - /** - * @brief adc osq1 register, offset:0x2C - */ - union - { - __IO uint32_t osq1; - struct - { - __IO uint32_t osn13 : 5; /* [4:0] */ - __IO uint32_t osn14 : 5; /* [9:5] */ - __IO uint32_t osn15 : 5; /* [14:10] */ - __IO uint32_t osn16 : 5; /* [19:15] */ - __IO uint32_t oclen : 4; /* [23:20] */ - __IO uint32_t reserved1 : 8; /* [31:24] */ - } osq1_bit; - }; - - /** - * @brief adc osq2 register, offset:0x30 - */ - union - { - __IO uint32_t osq2; - struct - { - __IO uint32_t osn7 : 5; /* [4:0] */ - __IO uint32_t osn8 : 5; /* [9:5] */ - __IO uint32_t osn9 : 5; /* [14:10] */ - __IO uint32_t osn10 : 5; /* [19:15] */ - __IO uint32_t osn11 : 5; /* [24:20] */ - __IO uint32_t osn12 : 5; /* [29:25] */ - __IO uint32_t reserved1 : 2; /* [31:30] */ - } osq2_bit; - }; - - /** - * @brief adc osq3 register, offset:0x34 - */ - union - { - __IO uint32_t osq3; - struct - { - __IO uint32_t osn1 : 5; /* [4:0] */ - __IO uint32_t osn2 : 5; /* [9:5] */ - __IO uint32_t osn3 : 5; /* [14:10] */ - __IO uint32_t osn4 : 5; /* [19:15] */ - __IO uint32_t osn5 : 5; /* [24:20] */ - __IO uint32_t osn6 : 5; /* [29:25] */ - __IO uint32_t reserved1 : 2; /* [31:30] */ - } osq3_bit; - }; - - /** - * @brief adc psq register, offset:0x38 - */ - union - { - __IO uint32_t psq; - struct - { - __IO uint32_t psn1 : 5; /* [4:0] */ - __IO uint32_t psn2 : 5; /* [9:5] */ - __IO uint32_t psn3 : 5; /* [14:10] */ - __IO uint32_t psn4 : 5; /* [19:15] */ - __IO uint32_t pclen : 2; /* [21:20] */ - __IO uint32_t reserved1 : 10;/* [31:22] */ - } psq_bit; - }; - - /** - * @brief adc pdt1 register, offset:0x3C - */ - union - { - __IO uint32_t pdt1; - struct - { - __IO uint32_t pdt1 : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [31:16] */ - } pdt1_bit; - }; - - /** - * @brief adc pdt2 register, offset:0x40 - */ - union - { - __IO uint32_t pdt2; - struct - { - __IO uint32_t pdt2 : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [31:16] */ - } pdt2_bit; - }; - - /** - * @brief adc pdt3 register, offset:0x44 - */ - union - { - __IO uint32_t pdt3; - struct - { - __IO uint32_t pdt3 : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [31:16] */ - } pdt3_bit; - }; - - /** - * @brief adc pdt4 register, offset:0x48 - */ - union - { - __IO uint32_t pdt4; - struct - { - __IO uint32_t pdt4 : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [31:16] */ - } pdt4_bit; - }; - - /** - * @brief adc odt register, offset:0x4C - */ - union - { - __IO uint32_t odt; - struct - { - __IO uint32_t odt : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [31:16] */ - } odt_bit; - }; - - __IO uint32_t reserved1[12]; - - /** - * @brief adc ovsp register, offset:0x80 - */ - union - { - __IO uint32_t ovsp; - struct - { - __IO uint32_t oosen : 1; /* [0] */ - __IO uint32_t posen : 1; /* [1] */ - __IO uint32_t osrsel : 3; /* [4:2] */ - __IO uint32_t osssel : 4; /* [8:5] */ - __IO uint32_t oostren : 1; /* [9] */ - __IO uint32_t oosrsel : 1; /* [10] */ - __IO uint32_t reserved1 : 21; /* [31:11] */ - } ovsp_bit; - }; - - __IO uint32_t reserved2[12]; - - /** - * @brief adc calval register, offset:0xB4 - */ - union - { - __IO uint32_t calval; - struct - { - __IO uint32_t calval : 7; /* [6:0] */ - __IO uint32_t reserved1 : 25; /* [31:7] */ - } calval_bit; - }; -} adc_type; - -/** - * @brief type define adc register all - */ -typedef struct -{ - - /** - * @brief adc csts register, offset:0x00 - */ - union - { - __IO uint32_t csts; - struct - { - __IO uint32_t vmor1 : 1; /* [0] */ - __IO uint32_t occe1 : 1; /* [1] */ - __IO uint32_t pcce1 : 1; /* [2] */ - __IO uint32_t pccs1 : 1; /* [3] */ - __IO uint32_t occs1 : 1; /* [4] */ - __IO uint32_t occo1 : 1; /* [5] */ - __IO uint32_t rdy1 : 1; /* [6] */ - __IO uint32_t reserved1 : 1; /* [7] */ - __IO uint32_t vmor2 : 1; /* [8] */ - __IO uint32_t occe2 : 1; /* [9] */ - __IO uint32_t pcce2 : 1; /* [10] */ - __IO uint32_t pccs2 : 1; /* [11] */ - __IO uint32_t occs2 : 1; /* [12] */ - __IO uint32_t occo2 : 1; /* [13] */ - __IO uint32_t rdy2 : 1; /* [14] */ - __IO uint32_t reserved2 : 1; /* [15] */ - __IO uint32_t vmor3 : 1; /* [16] */ - __IO uint32_t occe3 : 1; /* [17] */ - __IO uint32_t pcce3 : 1; /* [18] */ - __IO uint32_t pccs3 : 1; /* [19] */ - __IO uint32_t occs3 : 1; /* [20] */ - __IO uint32_t occo3 : 1; /* [21] */ - __IO uint32_t rdy3 : 1; /* [22] */ - __IO uint32_t reserved3 : 9; /* [31:23] */ - } csts_bit; - }; - - /** - * @brief adc cctrl register, offset:0x04 - */ - union - { - __IO uint32_t cctrl; - struct - { - __IO uint32_t mssel : 5; /* [4_0] */ - __IO uint32_t reserved1 : 3; /* [7:5] */ - __IO uint32_t asisel : 4; /* [11:8] */ - __IO uint32_t reserved2 : 1; /* [12] */ - __IO uint32_t msdrcen : 1; /* [13] */ - __IO uint32_t msdmasel_l : 2; /* [15:14] */ - __IO uint32_t adcdiv : 4; /* [19:16] */ - __IO uint32_t reserved3 : 2; /* [21:20] */ - __IO uint32_t vbaten : 1; /* [22] */ - __IO uint32_t itsrven : 1; /* [23] */ - __IO uint32_t reserved4 : 4; /* [27:24] */ - __IO uint32_t msdmasel_h : 1; /* [28] */ - __IO uint32_t reserved5 : 3; /* [31:29] */ - } cctrl_bit; - }; - - /** - * @brief adc codt register, offset:0x08 - */ - union - { - __IO uint32_t codt; - struct - { - __IO uint32_t codtl : 16; /* [15:0] */ - __IO uint32_t codth : 16; /* [31:16] */ - } codt_bit; - }; -} adccom_type; - -/** - * @} - */ - -#define ADC1 ((adc_type *) ADC1_BASE) -#define ADC2 ((adc_type *) ADC2_BASE) -#define ADC3 ((adc_type *) ADC3_BASE) -#define ADCCOM ((adccom_type *) ADCCOM_BASE) - -/** @defgroup ADC_exported_functions - * @{ - */ - -void adc_reset(void); -void adc_enable(adc_type *adc_x, confirm_state new_state); -void adc_base_default_para_init(adc_base_config_type *adc_base_struct); -void adc_base_config(adc_type *adc_x, adc_base_config_type *adc_base_struct); -void adc_common_default_para_init(adc_common_config_type *adc_common_struct); -void adc_common_config(adc_common_config_type *adc_common_struct); -void adc_resolution_set(adc_type *adc_x, adc_resolution_type resolution); -void adc_voltage_battery_enable(confirm_state new_state); -void adc_dma_mode_enable(adc_type *adc_x, confirm_state new_state); -void adc_dma_request_repeat_enable(adc_type *adc_x, confirm_state new_state); -void adc_interrupt_enable(adc_type *adc_x, uint32_t adc_int, confirm_state new_state); -void adc_calibration_value_set(adc_type *adc_x, uint8_t adc_calibration_value); -void adc_calibration_init(adc_type *adc_x); -flag_status adc_calibration_init_status_get(adc_type *adc_x); -void adc_calibration_start(adc_type *adc_x); -flag_status adc_calibration_status_get(adc_type *adc_x); -void adc_voltage_monitor_enable(adc_type *adc_x, adc_voltage_monitoring_type adc_voltage_monitoring); -void adc_voltage_monitor_threshold_value_set(adc_type *adc_x, uint16_t adc_high_threshold, uint16_t adc_low_threshold); -void adc_voltage_monitor_single_channel_select(adc_type *adc_x, adc_channel_select_type adc_channel); -void adc_ordinary_channel_set(adc_type *adc_x, adc_channel_select_type adc_channel, uint8_t adc_sequence, adc_sampletime_select_type adc_sampletime); -void adc_preempt_channel_length_set(adc_type *adc_x, uint8_t adc_channel_lenght); -void adc_preempt_channel_set(adc_type *adc_x, adc_channel_select_type adc_channel, uint8_t adc_sequence, adc_sampletime_select_type adc_sampletime); -void adc_ordinary_conversion_trigger_set(adc_type *adc_x, adc_ordinary_trig_select_type adc_ordinary_trig, adc_ordinary_trig_edge_type adc_ordinary_trig_edge); -void adc_preempt_conversion_trigger_set(adc_type *adc_x, adc_preempt_trig_select_type adc_preempt_trig, adc_preempt_trig_edge_type adc_preempt_trig_edge); -void adc_preempt_offset_value_set(adc_type *adc_x, adc_preempt_channel_type adc_preempt_channel, uint16_t adc_offset_value); -void adc_ordinary_part_count_set(adc_type *adc_x, uint8_t adc_channel_count); -void adc_ordinary_part_mode_enable(adc_type *adc_x, confirm_state new_state); -void adc_preempt_part_mode_enable(adc_type *adc_x, confirm_state new_state); -void adc_preempt_auto_mode_enable(adc_type *adc_x, confirm_state new_state); -void adc_conversion_stop(adc_type *adc_x); -flag_status adc_conversion_stop_status_get(adc_type *adc_x); -void adc_occe_each_conversion_enable(adc_type *adc_x, confirm_state new_state); -void adc_ordinary_software_trigger_enable(adc_type *adc_x, confirm_state new_state); -flag_status adc_ordinary_software_trigger_status_get(adc_type *adc_x); -void adc_preempt_software_trigger_enable(adc_type *adc_x, confirm_state new_state); -flag_status adc_preempt_software_trigger_status_get(adc_type *adc_x); -uint16_t adc_ordinary_conversion_data_get(adc_type *adc_x); -uint32_t adc_combine_ordinary_conversion_data_get(void); -uint16_t adc_preempt_conversion_data_get(adc_type *adc_x, adc_preempt_channel_type adc_preempt_channel); -flag_status adc_flag_get(adc_type *adc_x, uint8_t adc_flag); -void adc_flag_clear(adc_type *adc_x, uint32_t adc_flag); -void adc_ordinary_oversample_enable(adc_type *adc_x, confirm_state new_state); -void adc_preempt_oversample_enable(adc_type *adc_x, confirm_state new_state); -void adc_oversample_ratio_shift_set(adc_type *adc_x, adc_oversample_ratio_type adc_oversample_ratio, adc_oversample_shift_type adc_oversample_shift); -void adc_ordinary_oversample_trig_enable(adc_type *adc_x, confirm_state new_state); -void adc_ordinary_oversample_restart_set(adc_type *adc_x, adc_ordinary_oversample_restart_type adc_ordinary_oversample_restart); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_can.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_can.h deleted file mode 100644 index ab47b9c..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_can.h +++ /dev/null @@ -1,1042 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_can.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 can header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_CAN_H -#define __AT32F435_437_CAN_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup CAN - * @{ - */ - - -/** @defgroup CAN_timeout_count - * @{ - */ - -#define FZC_TIMEOUT ((uint32_t)0x0000FFFF) /*!< time out for fzc bit */ -#define DZC_TIMEOUT ((uint32_t)0x0000FFFF) /*!< time out for dzc bit */ - -/** - * @} - */ - -/** @defgroup CAN_flags_definition - * @brief can flag - * @{ - */ - -#define CAN_EAF_FLAG ((uint32_t)0x01) /*!< error active flag */ -#define CAN_EPF_FLAG ((uint32_t)0x02) /*!< error passive flag */ -#define CAN_BOF_FLAG ((uint32_t)0x03) /*!< bus-off flag */ -#define CAN_ETR_FLAG ((uint32_t)0x04) /*!< error type record flag */ -#define CAN_EOIF_FLAG ((uint32_t)0x05) /*!< error occur interrupt flag */ -#define CAN_TM0TCF_FLAG ((uint32_t)0x06) /*!< transmit mailbox 0 transmission completed flag */ -#define CAN_TM1TCF_FLAG ((uint32_t)0x07) /*!< transmit mailbox 1 transmission completed flag */ -#define CAN_TM2TCF_FLAG ((uint32_t)0x08) /*!< transmit mailbox 2 transmission completed flag */ -#define CAN_RF0MN_FLAG ((uint32_t)0x09) /*!< receive fifo 0 message num flag */ -#define CAN_RF0FF_FLAG ((uint32_t)0x0A) /*!< receive fifo 0 full flag */ -#define CAN_RF0OF_FLAG ((uint32_t)0x0B) /*!< receive fifo 0 overflow flag */ -#define CAN_RF1MN_FLAG ((uint32_t)0x0C) /*!< receive fifo 1 message num flag */ -#define CAN_RF1FF_FLAG ((uint32_t)0x0D) /*!< receive fifo 1 full flag */ -#define CAN_RF1OF_FLAG ((uint32_t)0x0E) /*!< receive fifo 1 overflow flag */ -#define CAN_QDZIF_FLAG ((uint32_t)0x0F) /*!< quit doze mode interrupt flag */ -#define CAN_EDZC_FLAG ((uint32_t)0x10) /*!< enter doze mode confirm flag */ -#define CAN_TMEF_FLAG ((uint32_t)0x11) /*!< transmit mailbox empty flag */ - -/** - * @} - */ - -/** @defgroup CAN_interrupts_definition - * @brief can interrupt - * @{ - */ - -#define CAN_TCIEN_INT ((uint32_t)0x00000001) /*!< transmission complete interrupt */ -#define CAN_RF0MIEN_INT ((uint32_t)0x00000002) /*!< receive fifo 0 message interrupt */ -#define CAN_RF0FIEN_INT ((uint32_t)0x00000004) /*!< receive fifo 0 full interrupt */ -#define CAN_RF0OIEN_INT ((uint32_t)0x00000008) /*!< receive fifo 0 overflow interrupt */ -#define CAN_RF1MIEN_INT ((uint32_t)0x00000010) /*!< receive fifo 1 message interrupt */ -#define CAN_RF1FIEN_INT ((uint32_t)0x00000020) /*!< receive fifo 1 full interrupt */ -#define CAN_RF1OIEN_INT ((uint32_t)0x00000040) /*!< receive fifo 1 overflow interrupt */ -#define CAN_EAIEN_INT ((uint32_t)0x00000100) /*!< error active interrupt */ -#define CAN_EPIEN_INT ((uint32_t)0x00000200) /*!< error passive interrupt */ -#define CAN_BOIEN_INT ((uint32_t)0x00000400) /*!< bus-off interrupt */ -#define CAN_ETRIEN_INT ((uint32_t)0x00000800) /*!< error type record interrupt */ -#define CAN_EOIEN_INT ((uint32_t)0x00008000) /*!< error occur interrupt */ -#define CAN_QDZIEN_INT ((uint32_t)0x00010000) /*!< quit doze mode interrupt */ -#define CAN_EDZIEN_INT ((uint32_t)0x00020000) /*!< enter doze mode confirm interrupt */ - -/** - * @} - */ - -/** - * @brief can flag clear operation macro definition val - */ -#define CAN_MSTS_EOIF_VAL ((uint32_t)0x00000004) /*!< eoif bit value, it clear by writing 1 */ -#define CAN_MSTS_QDZIF_VAL ((uint32_t)0x00000008) /*!< qdzif bit value, it clear by writing 1 */ -#define CAN_MSTS_EDZIF_VAL ((uint32_t)0x00000010) /*!< edzif bit value, it clear by writing 1 */ -#define CAN_TSTS_TM0TCF_VAL ((uint32_t)0x00000001) /*!< tm0tcf bit value, it clear by writing 1 */ -#define CAN_TSTS_TM1TCF_VAL ((uint32_t)0x00000100) /*!< tm1tcf bit value, it clear by writing 1 */ -#define CAN_TSTS_TM2TCF_VAL ((uint32_t)0x00010000) /*!< tm2tcf bit value, it clear by writing 1 */ -#define CAN_TSTS_TM0CT_VAL ((uint32_t)0x00000080) /*!< tm0ct bit value, it clear by writing 1 */ -#define CAN_TSTS_TM1CT_VAL ((uint32_t)0x00008000) /*!< tm1ct bit value, it clear by writing 1 */ -#define CAN_TSTS_TM2CT_VAL ((uint32_t)0x00800000) /*!< tm2ct bit value, it clear by writing 1 */ -#define CAN_RF0_RF0FF_VAL ((uint32_t)0x00000008) /*!< rf0ff bit value, it clear by writing 1 */ -#define CAN_RF0_RF0OF_VAL ((uint32_t)0x00000010) /*!< rf0of bit value, it clear by writing 1 */ -#define CAN_RF0_RF0R_VAL ((uint32_t)0x00000020) /*!< rf0r bit value, it clear by writing 1 */ -#define CAN_RF1_RF1FF_VAL ((uint32_t)0x00000008) /*!< rf1ff bit value, it clear by writing 1 */ -#define CAN_RF1_RF1OF_VAL ((uint32_t)0x00000010) /*!< rf1of bit value, it clear by writing 1 */ -#define CAN_RF1_RF1R_VAL ((uint32_t)0x00000020) /*!< rf1r bit value, it clear by writing 1 */ - -/** @defgroup CAN_exported_types - * @{ - */ - -/** - * @brief can filter fifo - */ -typedef enum -{ - CAN_FILTER_FIFO0 = 0x00, /*!< filter fifo 0 assignment for filter x */ - CAN_FILTER_FIFO1 = 0x01 /*!< filter fifo 1 assignment for filter x */ -} can_filter_fifo_type; - -/** - * @brief can filter mode - */ -typedef enum -{ - CAN_FILTER_MODE_ID_MASK = 0x00, /*!< identifier mask mode */ - CAN_FILTER_MODE_ID_LIST = 0x01 /*!< identifier list mode */ -} can_filter_mode_type; - -/** - * @brief can filter bit width select - */ -typedef enum -{ - CAN_FILTER_16BIT = 0x00, /*!< two 16-bit filters */ - CAN_FILTER_32BIT = 0x01 /*!< one 32-bit filter */ -} can_filter_bit_width_type; - -/** - * @brief can mode - */ -typedef enum -{ - CAN_MODE_COMMUNICATE = 0x00, /*!< communication mode */ - CAN_MODE_LOOPBACK = 0x01, /*!< loopback mode */ - CAN_MODE_LISTENONLY = 0x02, /*!< listen-only mode */ - CAN_MODE_LISTENONLY_LOOPBACK = 0x03 /*!< loopback combined with listen-only mode */ -} can_mode_type; - -/** - * @brief can operating mode - */ -typedef enum -{ - CAN_OPERATINGMODE_FREEZE = 0x00, /*!< freeze mode */ - CAN_OPERATINGMODE_DOZE = 0x01, /*!< doze mode */ - CAN_OPERATINGMODE_COMMUNICATE = 0x02 /*!< communication mode */ -} can_operating_mode_type; - -/** - * @brief can resynchronization adjust width - */ -typedef enum -{ - CAN_RSAW_1TQ = 0x00, /*!< 1 time quantum */ - CAN_RSAW_2TQ = 0x01, /*!< 2 time quantum */ - CAN_RSAW_3TQ = 0x02, /*!< 3 time quantum */ - CAN_RSAW_4TQ = 0x03 /*!< 4 time quantum */ -} can_rsaw_type; - -/** - * @brief can bit time segment 1 - */ -typedef enum -{ - CAN_BTS1_1TQ = 0x00, /*!< 1 time quantum */ - CAN_BTS1_2TQ = 0x01, /*!< 2 time quantum */ - CAN_BTS1_3TQ = 0x02, /*!< 3 time quantum */ - CAN_BTS1_4TQ = 0x03, /*!< 4 time quantum */ - CAN_BTS1_5TQ = 0x04, /*!< 5 time quantum */ - CAN_BTS1_6TQ = 0x05, /*!< 6 time quantum */ - CAN_BTS1_7TQ = 0x06, /*!< 7 time quantum */ - CAN_BTS1_8TQ = 0x07, /*!< 8 time quantum */ - CAN_BTS1_9TQ = 0x08, /*!< 9 time quantum */ - CAN_BTS1_10TQ = 0x09, /*!< 10 time quantum */ - CAN_BTS1_11TQ = 0x0A, /*!< 11 time quantum */ - CAN_BTS1_12TQ = 0x0B, /*!< 12 time quantum */ - CAN_BTS1_13TQ = 0x0C, /*!< 13 time quantum */ - CAN_BTS1_14TQ = 0x0D, /*!< 14 time quantum */ - CAN_BTS1_15TQ = 0x0E, /*!< 15 time quantum */ - CAN_BTS1_16TQ = 0x0F /*!< 16 time quantum */ -} can_bts1_type; - -/** - * @brief can bit time segment 2 - */ -typedef enum -{ - CAN_BTS2_1TQ = 0x00, /*!< 1 time quantum */ - CAN_BTS2_2TQ = 0x01, /*!< 2 time quantum */ - CAN_BTS2_3TQ = 0x02, /*!< 3 time quantum */ - CAN_BTS2_4TQ = 0x03, /*!< 4 time quantum */ - CAN_BTS2_5TQ = 0x04, /*!< 5 time quantum */ - CAN_BTS2_6TQ = 0x05, /*!< 6 time quantum */ - CAN_BTS2_7TQ = 0x06, /*!< 7 time quantum */ - CAN_BTS2_8TQ = 0x07 /*!< 8 time quantum */ -} can_bts2_type; - -/** - * @brief can identifier type - */ -typedef enum -{ - CAN_ID_STANDARD = 0x00, /*!< standard Id */ - CAN_ID_EXTENDED = 0x01 /*!< extended Id */ -} can_identifier_type; - -/** - * @brief can transmission frame type - */ -typedef enum -{ - CAN_TFT_DATA = 0x00, /*!< data frame */ - CAN_TFT_REMOTE = 0x01 /*!< remote frame */ -} can_trans_frame_type; - -/** - * @brief can tx mailboxes - */ -typedef enum -{ - CAN_TX_MAILBOX0 = 0x00, /*!< can tx mailbox 0 */ - CAN_TX_MAILBOX1 = 0x01, /*!< can tx mailbox 1 */ - CAN_TX_MAILBOX2 = 0x02 /*!< can tx mailbox 2 */ -} can_tx_mailbox_num_type; - -/** - * @brief can receive fifo - */ -typedef enum -{ - CAN_RX_FIFO0 = 0x00, /*!< can fifo 0 used to receive */ - CAN_RX_FIFO1 = 0x01 /*!< can fifo 1 used to receive */ -} can_rx_fifo_num_type; - -/** - * @brief can transmit status - */ -typedef enum -{ - CAN_TX_STATUS_FAILED = 0x00, /*!< can transmission failed */ - CAN_TX_STATUS_SUCCESSFUL = 0x01, /*!< can transmission successful */ - CAN_TX_STATUS_PENDING = 0x02, /*!< can transmission pending */ - CAN_TX_STATUS_NO_EMPTY = 0x04 /*!< can transmission no empty mailbox */ -} can_transmit_status_type; - -/** - * @brief can enter doze mode status - */ -typedef enum -{ - CAN_ENTER_DOZE_FAILED = 0x00, /*!< can enter the doze mode failed */ - CAN_ENTER_DOZE_SUCCESSFUL = 0x01 /*!< can enter the doze mode successful */ -} can_enter_doze_status_type; - -/** - * @brief can quit doze mode status - */ -typedef enum -{ - CAN_QUIT_DOZE_FAILED = 0x00, /*!< can quit doze mode failed */ - CAN_QUIT_DOZE_SUCCESSFUL = 0x01 /*!< can quit doze mode successful */ -} can_quit_doze_status_type; - -/** - * @brief can message discarding rule select when overflow - */ -typedef enum -{ - CAN_DISCARDING_FIRST_RECEIVED = 0x00, /*!< can discarding the first received message */ - CAN_DISCARDING_LAST_RECEIVED = 0x01 /*!< can discarding the last received message */ -} can_msg_discarding_rule_type; - -/** - * @brief can multiple message sending sequence rule - */ -typedef enum -{ - CAN_SENDING_BY_ID = 0x00, /*!< can sending the minimum id message first*/ - CAN_SENDING_BY_REQUEST = 0x01 /*!< can sending the first request message first */ -} can_msg_sending_rule_type; - -/** - * @brief can error type record - */ -typedef enum -{ - CAN_ERRORRECORD_NOERR = 0x00, /*!< no error */ - CAN_ERRORRECORD_STUFFERR = 0x01, /*!< stuff error */ - CAN_ERRORRECORD_FORMERR = 0x02, /*!< form error */ - CAN_ERRORRECORD_ACKERR = 0x03, /*!< acknowledgment error */ - CAN_ERRORRECORD_BITRECESSIVEERR = 0x04, /*!< bit recessive error */ - CAN_ERRORRECORD_BITDOMINANTERR = 0x05, /*!< bit dominant error */ - CAN_ERRORRECORD_CRCERR = 0x06, /*!< crc error */ - CAN_ERRORRECORD_SOFTWARESETERR = 0x07 /*!< software set error */ -} can_error_record_type; - -/** - * @brief can init structure definition - */ -typedef struct -{ - can_mode_type mode_selection; /*!< specifies the can mode.*/ - - confirm_state ttc_enable; /*!< time triggered communication mode enable */ - - confirm_state aebo_enable; /*!< automatic exit bus-off enable */ - - confirm_state aed_enable; /*!< automatic exit doze mode enable */ - - confirm_state prsf_enable; /*!< prohibit retransmission when sending fails enable */ - - can_msg_discarding_rule_type mdrsel_selection; /*!< message discarding rule select when overflow */ - - can_msg_sending_rule_type mmssr_selection; /*!< multiple message sending sequence rule */ - -} can_base_type; - -/** - * @brief can baudrate structure definition - */ -typedef struct -{ - uint16_t baudrate_div; /*!< baudrate division,this parameter can be 0x001~0x400.*/ - - can_rsaw_type rsaw_size; /*!< resynchronization adjust width */ - - can_bts1_type bts1_size; /*!< bit time segment 1 */ - - can_bts2_type bts2_size; /*!< bit time segment 2 */ - -} can_baudrate_type; - -/** - * @brief can filter init structure definition - */ -typedef struct -{ - confirm_state filter_activate_enable; /*!< enable or disable the filter activate.*/ - - can_filter_mode_type filter_mode; /*!< config the filter mode mask or list.*/ - - can_filter_fifo_type filter_fifo; /*!< config the fifo which will be assigned to the filter. */ - - uint8_t filter_number; /*!< config the filter number, parameter ranges from 0 to 13. */ - - can_filter_bit_width_type filter_bit; /*!< config the filter bit width 16bit or 32bit.*/ - - uint16_t filter_id_high; /*!< config the filter identification, for 32-bit configuration - it's high 16 bits, for 16-bit configuration it's first. */ - - uint16_t filter_id_low; /*!< config the filter identification, for 32-bit configuration - it's low 16 bits, for 16-bit configuration it's second. */ - - uint16_t filter_mask_high; /*!< config the filter mask or identification, according to the filtering mode, - for 32-bit configuration it's high 16 bits, for 16-bit configuration it's first. */ - - uint16_t filter_mask_low; /*!< config the filter mask or identification, according to the filtering mode, - for 32-bit configuration it's low 16 bits, for 16-bit configuration it's second. */ -} can_filter_init_type; - -/** - * @brief can tx message structure definition - */ -typedef struct -{ - uint32_t standard_id; /*!< specifies the 11 bits standard identifier. - this parameter can be a value between 0 to 0x7FF. */ - - uint32_t extended_id; /*!< specifies the 29 bits extended identifier. - this parameter can be a value between 0 to 0x1FFFFFFF. */ - - can_identifier_type id_type; /*!< specifies identifier type for the transmit message.*/ - - can_trans_frame_type frame_type; /*!< specifies frame type for the transmit message.*/ - - uint8_t dlc; /*!< specifies frame data length that will be transmitted. - this parameter can be a value between 0 to 8 */ - - uint8_t data[8]; /*!< contains the transmit data. it ranges from 0 to 0xFF. */ - -} can_tx_message_type; - -/** - * @brief can rx message structure definition - */ -typedef struct -{ - uint32_t standard_id; /*!< specifies the 11 bits standard identifier - this parameter can be a value between 0 to 0x7FF. */ - - uint32_t extended_id; /*!< specifies the 29 bits extended identifier. - this parameter can be a value between 0 to 0x1FFFFFFF. */ - - can_identifier_type id_type; /*!< specifies identifier type for the receive message.*/ - - can_trans_frame_type frame_type; /*!< specifies frame type for the receive message.*/ - - uint8_t dlc; /*!< specifies the frame data length that will be received. - this parameter can be a value between 0 to 8 */ - - uint8_t data[8]; /*!< contains the receive data. it ranges from 0 to 0xFF.*/ - - uint8_t filter_index; /*!< specifies the message stored in which filter - this parameter can be a value between 0 to 0xFF */ -} can_rx_message_type; - -/** - * @brief can controller area network tx mailbox - */ -typedef struct -{ - /** - * @brief can tmi register - */ - union - { - __IO uint32_t tmi; - struct - { - __IO uint32_t tmsr : 1; /* [0] */ - __IO uint32_t tmfrsel : 1; /* [1] */ - __IO uint32_t tmidsel : 1; /* [2] */ - __IO uint32_t tmeid : 18;/* [20:3] */ - __IO uint32_t tmsid : 11;/* [31:21] */ - } tmi_bit; - }; - - /** - * @brief can tmc register - */ - union - { - __IO uint32_t tmc; - struct - { - __IO uint32_t tmdtbl : 4; /* [3:0] */ - __IO uint32_t reserved1 : 4; /* [7:4] */ - __IO uint32_t tmtsten : 1; /* [8] */ - __IO uint32_t reserved2 : 7; /* [15:9] */ - __IO uint32_t tmts : 16;/* [31:16] */ - } tmc_bit; - }; - - /** - * @brief can tmdtl register - */ - union - { - __IO uint32_t tmdtl; - struct - { - __IO uint32_t tmdt0 : 8; /* [7:0] */ - __IO uint32_t tmdt1 : 8; /* [15:8] */ - __IO uint32_t tmdt2 : 8; /* [23:16] */ - __IO uint32_t tmdt3 : 8; /* [31:24] */ - } tmdtl_bit; - }; - - /** - * @brief can tmdth register - */ - union - { - __IO uint32_t tmdth; - struct - { - __IO uint32_t tmdt4 : 8; /* [7:0] */ - __IO uint32_t tmdt5 : 8; /* [15:8] */ - __IO uint32_t tmdt6 : 8; /* [23:16] */ - __IO uint32_t tmdt7 : 8; /* [31:24] */ - } tmdth_bit; - }; -} can_tx_mailbox_type; - -/** - * @brief can controller area network fifo mailbox - */ -typedef struct -{ - /** - * @brief can rfi register - */ - union - { - __IO uint32_t rfi; - struct - { - __IO uint32_t reserved1 : 1; /* [0] */ - __IO uint32_t rffri : 1; /* [1] */ - __IO uint32_t rfidi : 1; /* [2] */ - __IO uint32_t rfeid : 18;/* [20:3] */ - __IO uint32_t rfsid : 11;/* [31:21] */ - } rfi_bit; - }; - - /** - * @brief can rfc register - */ - union - { - __IO uint32_t rfc; - struct - { - __IO uint32_t rfdtl : 4; /* [3:0] */ - __IO uint32_t reserved1 : 4; /* [7:4] */ - __IO uint32_t rffmn : 8; /* [15:8] */ - __IO uint32_t rfts : 16;/* [31:16] */ - } rfc_bit; - }; - - /** - * @brief can rfdtl register - */ - union - { - __IO uint32_t rfdtl; - struct - { - __IO uint32_t rfdt0 : 8; /* [7:0] */ - __IO uint32_t rfdt1 : 8; /* [15:8] */ - __IO uint32_t rfdt2 : 8; /* [23:16] */ - __IO uint32_t rfdt3 : 8; /* [31:24] */ - } rfdtl_bit; - }; - - /** - * @brief can rfdth register - */ - union - { - __IO uint32_t rfdth; - struct - { - __IO uint32_t rfdt4 : 8; /* [7:0] */ - __IO uint32_t rfdt5 : 8; /* [15:8] */ - __IO uint32_t rfdt6 : 8; /* [23:16] */ - __IO uint32_t rfdt7 : 8; /* [31:24] */ - } rfdth_bit; - }; -} can_fifo_mailbox_type; - -/** - * @brief can controller area network filter bit register - */ -typedef struct -{ - __IO uint32_t ffdb1; - __IO uint32_t ffdb2; -} can_filter_register_type; - -/** - * @brief type define can register all - */ -typedef struct -{ - - /** - * @brief can mctrl register, offset:0x00 - */ - union - { - __IO uint32_t mctrl; - struct - { - __IO uint32_t fzen : 1; /* [0] */ - __IO uint32_t dzen : 1; /* [1] */ - __IO uint32_t mmssr : 1; /* [2] */ - __IO uint32_t mdrsel : 1; /* [3] */ - __IO uint32_t prsfen : 1; /* [4] */ - __IO uint32_t aeden : 1; /* [5] */ - __IO uint32_t aeboen : 1; /* [6] */ - __IO uint32_t ttcen : 1; /* [7] */ - __IO uint32_t reserved1 : 7; /* [14:8] */ - __IO uint32_t sprst : 1; /* [15] */ - __IO uint32_t ptd : 1; /* [16] */ - __IO uint32_t reserved2 : 15;/*[31:17] */ - } mctrl_bit; - }; - - /** - * @brief can msts register, offset:0x04 - */ - union - { - __IO uint32_t msts; - struct - { - __IO uint32_t fzc : 1; /* [0] */ - __IO uint32_t dzc : 1; /* [1] */ - __IO uint32_t eoif : 1; /* [2] */ - __IO uint32_t qdzif : 1; /* [3] */ - __IO uint32_t edzif : 1; /* [4] */ - __IO uint32_t reserved1 : 3; /* [7:5] */ - __IO uint32_t cuss : 1; /* [8] */ - __IO uint32_t curs : 1; /* [9] */ - __IO uint32_t lsamprx : 1; /* [10] */ - __IO uint32_t realrx : 1; /* [11] */ - __IO uint32_t reserved2 : 20;/*[31:12] */ - } msts_bit; - }; - - /** - * @brief can tsts register, offset:0x08 - */ - union - { - __IO uint32_t tsts; - struct - { - __IO uint32_t tm0tcf : 1; /* [0] */ - __IO uint32_t tm0tsf : 1; /* [1] */ - __IO uint32_t tm0alf : 1; /* [2] */ - __IO uint32_t tm0tef : 1; /* [3] */ - __IO uint32_t reserved1 : 3; /* [6:4] */ - __IO uint32_t tm0ct : 1; /* [7] */ - __IO uint32_t tm1tcf : 1; /* [8] */ - __IO uint32_t tm1tsf : 1; /* [9] */ - __IO uint32_t tm1alf : 1; /* [10] */ - __IO uint32_t tm1tef : 1; /* [11] */ - __IO uint32_t reserved2 : 3; /* [14:12] */ - __IO uint32_t tm1ct : 1; /* [15] */ - __IO uint32_t tm2tcf : 1; /* [16] */ - __IO uint32_t tm2tsf : 1; /* [17] */ - __IO uint32_t tm2alf : 1; /* [18] */ - __IO uint32_t tm2tef : 1; /* [19] */ - __IO uint32_t reserved3 : 3; /* [22:20] */ - __IO uint32_t tm2ct : 1; /* [23] */ - __IO uint32_t tmnr : 2; /* [25:24] */ - __IO uint32_t tm0ef : 1; /* [26] */ - __IO uint32_t tm1ef : 1; /* [27] */ - __IO uint32_t tm2ef : 1; /* [28] */ - __IO uint32_t tm0lpf : 1; /* [29] */ - __IO uint32_t tm1lpf : 1; /* [30] */ - __IO uint32_t tm2lpf : 1; /* [31] */ - } tsts_bit; - }; - - /** - * @brief can rf0 register, offset:0x0C - */ - union - { - __IO uint32_t rf0; - struct - { - __IO uint32_t rf0mn : 2; /* [1:0] */ - __IO uint32_t reserved1 : 1; /* [2] */ - __IO uint32_t rf0ff : 1; /* [3] */ - __IO uint32_t rf0of : 1; /* [4] */ - __IO uint32_t rf0r : 1; /* [5] */ - __IO uint32_t reserved2 : 26;/* [31:6] */ - } rf0_bit; - }; - - /** - * @brief can rf1 register, offset:0x10 - */ - union - { - __IO uint32_t rf1; - struct - { - __IO uint32_t rf1mn : 2; /* [1:0] */ - __IO uint32_t reserved1 : 1; /* [2] */ - __IO uint32_t rf1ff : 1; /* [3] */ - __IO uint32_t rf1of : 1; /* [4] */ - __IO uint32_t rf1r : 1; /* [5] */ - __IO uint32_t reserved2 : 26;/* [31:6] */ - } rf1_bit; - }; - - /** - * @brief can inten register, offset:0x14 - */ - union - { - __IO uint32_t inten; - struct - { - __IO uint32_t tcien : 1; /* [0] */ - __IO uint32_t rf0mien : 1; /* [1] */ - __IO uint32_t rf0fien : 1; /* [2] */ - __IO uint32_t rf0oien : 1; /* [3] */ - __IO uint32_t rf1mien : 1; /* [4] */ - __IO uint32_t rf1fien : 1; /* [5] */ - __IO uint32_t rf1oien : 1; /* [6] */ - __IO uint32_t reserved1 : 1; /* [7] */ - __IO uint32_t eaien : 1; /* [8] */ - __IO uint32_t epien : 1; /* [9] */ - __IO uint32_t boien : 1; /* [10] */ - __IO uint32_t etrien : 1; /* [11] */ - __IO uint32_t reserved2 : 3; /* [14:12] */ - __IO uint32_t eoien : 1; /* [15] */ - __IO uint32_t qdzien : 1; /* [16] */ - __IO uint32_t edzien : 1; /* [17] */ - __IO uint32_t reserved3 : 14;/* [31:18] */ - } inten_bit; - }; - - /** - * @brief can ests register, offset:0x18 - */ - union - { - __IO uint32_t ests; - struct - { - __IO uint32_t eaf : 1; /* [0] */ - __IO uint32_t epf : 1; /* [1] */ - __IO uint32_t bof : 1; /* [2] */ - __IO uint32_t reserved1 : 1; /* [3] */ - __IO uint32_t etr : 3; /* [6:4] */ - __IO uint32_t reserved2 : 9; /* [15:7] */ - __IO uint32_t tec : 8; /* [23:16] */ - __IO uint32_t rec : 8; /* [31:24] */ - } ests_bit; - }; - - /** - * @brief can btmg register, offset:0x1C - */ - union - { - __IO uint32_t btmg; - struct - { - __IO uint32_t brdiv : 12;/* [11:0] */ - __IO uint32_t reserved1 : 4; /* [15:12] */ - __IO uint32_t bts1 : 4; /* [19:16] */ - __IO uint32_t bts2 : 3; /* [22:20] */ - __IO uint32_t reserved2 : 1; /* [23] */ - __IO uint32_t rsaw : 2; /* [25:24] */ - __IO uint32_t reserved3 : 4; /* [29:26] */ - __IO uint32_t lben : 1; /* [30] */ - __IO uint32_t loen : 1; /* [31] */ - } btmg_bit; - }; - - /** - * @brief can reserved register, offset:0x20~0x17C - */ - __IO uint32_t reserved1[88]; - - /** - * @brief can controller area network tx mailbox register, offset:0x180~0x1AC - */ - can_tx_mailbox_type tx_mailbox[3]; - - /** - * @brief can controller area network fifo mailbox register, offset:0x1B0~0x1CC - */ - can_fifo_mailbox_type fifo_mailbox[2]; - - /** - * @brief can reserved register, offset:0x1D0~0x1FC - */ - __IO uint32_t reserved2[12]; - - /** - * @brief can fctrl register, offset:0x200 - */ - union - { - __IO uint32_t fctrl; - struct - { - __IO uint32_t fcs : 1; /* [0] */ - __IO uint32_t reserved1 : 31;/* [31:1] */ - } fctrl_bit; - }; - - /** - * @brief can fmcfg register, offset:0x204 - */ - union - { - __IO uint32_t fmcfg; - struct - { - __IO uint32_t fmsel0 : 1; /* [0] */ - __IO uint32_t fmsel1 : 1; /* [1] */ - __IO uint32_t fmsel2 : 1; /* [2] */ - __IO uint32_t fmsel3 : 1; /* [3] */ - __IO uint32_t fmsel4 : 1; /* [4] */ - __IO uint32_t fmsel5 : 1; /* [5] */ - __IO uint32_t fmsel6 : 1; /* [6] */ - __IO uint32_t fmsel7 : 1; /* [7] */ - __IO uint32_t fmsel8 : 1; /* [8] */ - __IO uint32_t fmsel9 : 1; /* [9] */ - __IO uint32_t fmsel10 : 1; /* [10] */ - __IO uint32_t fmsel11 : 1; /* [11] */ - __IO uint32_t fmsel12 : 1; /* [12] */ - __IO uint32_t fmsel13 : 1; /* [13] */ - __IO uint32_t fmsel14 : 1; /* [14] */ - __IO uint32_t fmsel15 : 1; /* [15] */ - __IO uint32_t fmsel16 : 1; /* [16] */ - __IO uint32_t fmsel17 : 1; /* [17] */ - __IO uint32_t fmsel18 : 1; /* [18] */ - __IO uint32_t fmsel19 : 1; /* [19] */ - __IO uint32_t fmsel20 : 1; /* [20] */ - __IO uint32_t fmsel21 : 1; /* [21] */ - __IO uint32_t fmsel22 : 1; /* [22] */ - __IO uint32_t fmsel23 : 1; /* [23] */ - __IO uint32_t fmsel24 : 1; /* [24] */ - __IO uint32_t fmsel25 : 1; /* [25] */ - __IO uint32_t fmsel26 : 1; /* [26] */ - __IO uint32_t fmsel27 : 1; /* [27] */ - __IO uint32_t reserved1 : 4;/* [31:28] */ - } fmcfg_bit; - }; - - /** - * @brief can reserved register, offset:0x208 - */ - __IO uint32_t reserved3; - - /** - * @brief can fbwcfg register, offset:0x20C - */ - union - { - __IO uint32_t fbwcfg; - struct - { - __IO uint32_t fbwsel0 : 1; /* [0] */ - __IO uint32_t fbwsel1 : 1; /* [1] */ - __IO uint32_t fbwsel2 : 1; /* [2] */ - __IO uint32_t fbwsel3 : 1; /* [3] */ - __IO uint32_t fbwsel4 : 1; /* [4] */ - __IO uint32_t fbwsel5 : 1; /* [5] */ - __IO uint32_t fbwsel6 : 1; /* [6] */ - __IO uint32_t fbwsel7 : 1; /* [7] */ - __IO uint32_t fbwsel8 : 1; /* [8] */ - __IO uint32_t fbwsel9 : 1; /* [9] */ - __IO uint32_t fbwsel10 : 1; /* [10] */ - __IO uint32_t fbwsel11 : 1; /* [11] */ - __IO uint32_t fbwsel12 : 1; /* [12] */ - __IO uint32_t fbwsel13 : 1; /* [13] */ - __IO uint32_t fbwsel14 : 1; /* [14] */ - __IO uint32_t fbwsel15 : 1; /* [15] */ - __IO uint32_t fbwsel16 : 1; /* [16] */ - __IO uint32_t fbwsel17 : 1; /* [17] */ - __IO uint32_t fbwsel18 : 1; /* [18] */ - __IO uint32_t fbwsel19 : 1; /* [19] */ - __IO uint32_t fbwsel20 : 1; /* [20] */ - __IO uint32_t fbwsel21 : 1; /* [21] */ - __IO uint32_t fbwsel22 : 1; /* [22] */ - __IO uint32_t fbwsel23 : 1; /* [23] */ - __IO uint32_t fbwsel24 : 1; /* [24] */ - __IO uint32_t fbwsel25 : 1; /* [25] */ - __IO uint32_t fbwsel26 : 1; /* [26] */ - __IO uint32_t fbwsel27 : 1; /* [27] */ - __IO uint32_t reserved1 : 4;/* [31:28] */ - } fbwcfg_bit; - }; - - /** - * @brief can reserved register, offset:0x210 - */ - __IO uint32_t reserved4; - - /** - * @brief can frf register, offset:0x214 - */ - union - { - __IO uint32_t frf; - struct - { - __IO uint32_t frfsel0 : 1; /* [0] */ - __IO uint32_t frfsel1 : 1; /* [1] */ - __IO uint32_t frfsel2 : 1; /* [2] */ - __IO uint32_t frfsel3 : 1; /* [3] */ - __IO uint32_t frfsel4 : 1; /* [4] */ - __IO uint32_t frfsel5 : 1; /* [5] */ - __IO uint32_t frfsel6 : 1; /* [6] */ - __IO uint32_t frfsel7 : 1; /* [7] */ - __IO uint32_t frfsel8 : 1; /* [8] */ - __IO uint32_t frfsel9 : 1; /* [9] */ - __IO uint32_t frfsel10 : 1; /* [10] */ - __IO uint32_t frfsel11 : 1; /* [11] */ - __IO uint32_t frfsel12 : 1; /* [12] */ - __IO uint32_t frfsel13 : 1; /* [13] */ - __IO uint32_t frfsel14 : 1; /* [14] */ - __IO uint32_t frfsel15 : 1; /* [15] */ - __IO uint32_t frfsel16 : 1; /* [16] */ - __IO uint32_t frfsel17 : 1; /* [17] */ - __IO uint32_t frfsel18 : 1; /* [18] */ - __IO uint32_t frfsel19 : 1; /* [19] */ - __IO uint32_t frfsel20 : 1; /* [20] */ - __IO uint32_t frfsel21 : 1; /* [21] */ - __IO uint32_t frfsel22 : 1; /* [22] */ - __IO uint32_t frfsel23 : 1; /* [23] */ - __IO uint32_t frfsel24 : 1; /* [24] */ - __IO uint32_t frfsel25 : 1; /* [25] */ - __IO uint32_t frfsel26 : 1; /* [26] */ - __IO uint32_t frfsel27 : 1; /* [27] */ - __IO uint32_t reserved1 : 4;/* [31:28] */ - } frf_bit; - }; - - /** - * @brief can reserved register, offset:0x218 - */ - __IO uint32_t reserved5; - - /** - * @brief can facfg register, offset:0x21C - */ - union - { - __IO uint32_t facfg; - struct - { - __IO uint32_t faen0 : 1; /* [0] */ - __IO uint32_t faen1 : 1; /* [1] */ - __IO uint32_t faen2 : 1; /* [2] */ - __IO uint32_t faen3 : 1; /* [3] */ - __IO uint32_t faen4 : 1; /* [4] */ - __IO uint32_t faen5 : 1; /* [5] */ - __IO uint32_t faen6 : 1; /* [6] */ - __IO uint32_t faen7 : 1; /* [7] */ - __IO uint32_t faen8 : 1; /* [8] */ - __IO uint32_t faen9 : 1; /* [9] */ - __IO uint32_t faen10 : 1; /* [10] */ - __IO uint32_t faen11 : 1; /* [11] */ - __IO uint32_t faen12 : 1; /* [12] */ - __IO uint32_t faen13 : 1; /* [13] */ - __IO uint32_t faen14 : 1; /* [14] */ - __IO uint32_t faen15 : 1; /* [15] */ - __IO uint32_t faen16 : 1; /* [16] */ - __IO uint32_t faen17 : 1; /* [17] */ - __IO uint32_t faen18 : 1; /* [18] */ - __IO uint32_t faen19 : 1; /* [19] */ - __IO uint32_t faen20 : 1; /* [20] */ - __IO uint32_t faen21 : 1; /* [21] */ - __IO uint32_t faen22 : 1; /* [22] */ - __IO uint32_t faen23 : 1; /* [23] */ - __IO uint32_t faen24 : 1; /* [24] */ - __IO uint32_t faen25 : 1; /* [25] */ - __IO uint32_t faen26 : 1; /* [26] */ - __IO uint32_t faen27 : 1; /* [27] */ - __IO uint32_t reserved1 : 4;/* [31:28] */ - } facfg_bit; - }; - - /** - * @brief can reserved register, offset:0x220~0x23C - */ - __IO uint32_t reserved6[8]; - - /** - * @brief can ffb register, offset:0x240~0x2AC - */ - can_filter_register_type ffb[28]; -} can_type; - -/** - * @} - */ - -#define CAN1 ((can_type *) CAN1_BASE) -#define CAN2 ((can_type *) CAN2_BASE) - -/** @defgroup CAN_exported_functions - * @{ - */ - -void can_reset(can_type* can_x); -void can_baudrate_default_para_init(can_baudrate_type* can_baudrate_struct); -error_status can_baudrate_set(can_type* can_x, can_baudrate_type* can_baudrate_struct); -void can_default_para_init(can_base_type* can_base_struct); -error_status can_base_init(can_type* can_x, can_base_type* can_base_struct); -void can_filter_default_para_init(can_filter_init_type* can_filter_init_struct); -void can_filter_init(can_type* can_x, can_filter_init_type* can_filter_init_struct); -void can_debug_transmission_prohibit(can_type* can_x, confirm_state new_state); -void can_ttc_mode_enable(can_type* can_x, confirm_state new_state); -uint8_t can_message_transmit(can_type* can_x, can_tx_message_type* tx_message_struct); -can_transmit_status_type can_transmit_status_get(can_type* can_x, can_tx_mailbox_num_type transmit_mailbox); -void can_transmit_cancel(can_type* can_x, can_tx_mailbox_num_type transmit_mailbox); -void can_message_receive(can_type* can_x, can_rx_fifo_num_type fifo_number, can_rx_message_type* rx_message_struct); -void can_receive_fifo_release(can_type* can_x, can_rx_fifo_num_type fifo_number); -uint8_t can_receive_message_pending_get(can_type* can_x, can_rx_fifo_num_type fifo_number); -error_status can_operating_mode_set(can_type* can_x, can_operating_mode_type can_operating_mode); -can_enter_doze_status_type can_doze_mode_enter(can_type* can_x); -can_quit_doze_status_type can_doze_mode_exit(can_type* can_x); -can_error_record_type can_error_type_record_get(can_type* can_x); -uint8_t can_receive_error_counter_get(can_type* can_x); -uint8_t can_transmit_error_counter_get(can_type* can_x); -void can_interrupt_enable(can_type* can_x, uint32_t can_int, confirm_state new_state); -flag_status can_flag_get(can_type* can_x, uint32_t can_flag); -void can_flag_clear(can_type* can_x, uint32_t can_flag); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_crc.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_crc.h deleted file mode 100644 index 6fdadc8..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_crc.h +++ /dev/null @@ -1,172 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_crc.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 crc header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_CRC_H -#define __AT32F435_437_CRC_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup CRC - * @{ - */ - -/** @defgroup CRC_exported_types - * @{ - */ - -/** - * @brief crc reverse input data - */ -typedef enum -{ - CRC_REVERSE_INPUT_NO_AFFECTE = 0x00, /*!< input data no reverse */ - CRC_REVERSE_INPUT_BY_BYTE = 0x01, /*!< input data reverse by byte */ - CRC_REVERSE_INPUT_BY_HALFWORD = 0x02, /*!< input data reverse by half word */ - CRC_REVERSE_INPUT_BY_WORD = 0x03 /*!< input data reverse by word */ -} crc_reverse_input_type; - -/** - * @brief crc reverse output data - */ -typedef enum -{ - CRC_REVERSE_OUTPUT_NO_AFFECTE = 0x00, /*!< output data no reverse */ - CRC_REVERSE_OUTPUT_DATA = 0x01 /*!< output data reverse by word */ -} crc_reverse_output_type; - -/** - * @brief type define crc register all - */ -typedef struct -{ - /** - * @brief crc dt register, offset:0x00 - */ - union - { - __IO uint32_t dt; - struct - { - __IO uint32_t dt : 32; /* [31:0] */ - } dt_bit; - }; - - /** - * @brief crc cdt register, offset:0x04 - */ - union - { - __IO uint32_t cdt; - struct - { - __IO uint32_t cdt : 8 ; /* [7:0] */ - __IO uint32_t reserved1 : 24 ;/* [31:8] */ - } cdt_bit; - }; - - /** - * @brief crc ctrl register, offset:0x08 - */ - union - { - __IO uint32_t ctrl; - struct - { - __IO uint32_t rst : 1 ; /* [0] */ - __IO uint32_t reserved1 : 4 ; /* [4:1] */ - __IO uint32_t revid : 2 ; /* [6:5] */ - __IO uint32_t revod : 1 ; /* [7] */ - __IO uint32_t reserved2 : 24 ;/* [31:8] */ - } ctrl_bit; - }; - - /** - * @brief crm reserved1 register, offset:0x0C - */ - __IO uint32_t reserved1; - - /** - * @brief crc idt register, offset:0x10 - */ - union - { - __IO uint32_t idt; - struct - { - __IO uint32_t idt : 32; /* [31:0] */ - } idt_bit; - }; - -} crc_type; - -/** - * @} - */ - -#define CRC ((crc_type *) CRC_BASE) - -/** @defgroup CRC_exported_functions - * @{ - */ - -void crc_data_reset(void); -uint32_t crc_one_word_calculate(uint32_t data); -uint32_t crc_block_calculate(uint32_t *pbuffer, uint32_t length); -uint32_t crc_data_get(void); -void crc_common_data_set(uint8_t cdt_value); -uint8_t crc_common_date_get(void); -void crc_init_data_set(uint32_t value); -void crc_reverse_input_data_set(crc_reverse_input_type value); -void crc_reverse_output_data_set(crc_reverse_output_type value); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_crm.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_crm.h deleted file mode 100644 index 01833a9..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_crm.h +++ /dev/null @@ -1,1565 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_crm.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 crm header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_CRM_H -#define __AT32F435_437_CRM_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup CRM - * @{ - */ - -#define CRM_REG(value) PERIPH_REG(CRM_BASE, value) -#define CRM_REG_BIT(value) PERIPH_REG_BIT(value) - -/** @defgroup CRM_flags_definition - * @brief crm flag - * @{ - */ - -#define CRM_HICK_STABLE_FLAG MAKE_VALUE(0x00, 1) /*!< high speed internal clock stable flag */ -#define CRM_HEXT_STABLE_FLAG MAKE_VALUE(0x00, 17) /*!< high speed external crystal stable flag */ -#define CRM_PLL_STABLE_FLAG MAKE_VALUE(0x00, 25) /*!< phase locking loop stable flag */ -#define CRM_LEXT_STABLE_FLAG MAKE_VALUE(0x70, 1) /*!< low speed external crystal stable flag */ -#define CRM_LICK_STABLE_FLAG MAKE_VALUE(0x74, 1) /*!< low speed internal clock stable flag */ -#define CRM_NRST_RESET_FLAG MAKE_VALUE(0x74, 26) /*!< nrst pin reset flag */ -#define CRM_POR_RESET_FLAG MAKE_VALUE(0x74, 27) /*!< power on reset flag */ -#define CRM_SW_RESET_FLAG MAKE_VALUE(0x74, 28) /*!< software reset flag */ -#define CRM_WDT_RESET_FLAG MAKE_VALUE(0x74, 29) /*!< watchdog timer reset flag */ -#define CRM_WWDT_RESET_FLAG MAKE_VALUE(0x74, 30) /*!< window watchdog timer reset flag */ -#define CRM_LOWPOWER_RESET_FLAG MAKE_VALUE(0x74, 31) /*!< low-power reset flag */ -#define CRM_LICK_READY_INT_FLAG MAKE_VALUE(0x0C, 0) /*!< low speed internal clock stable interrupt ready flag */ -#define CRM_LEXT_READY_INT_FLAG MAKE_VALUE(0x0C, 1) /*!< low speed external crystal stable interrupt ready flag */ -#define CRM_HICK_READY_INT_FLAG MAKE_VALUE(0x0C, 2) /*!< high speed internal clock stable interrupt ready flag */ -#define CRM_HEXT_READY_INT_FLAG MAKE_VALUE(0x0C, 3) /*!< high speed external crystal stable interrupt ready flag */ -#define CRM_PLL_READY_INT_FLAG MAKE_VALUE(0x0C, 4) /*!< phase locking loop stable interrupt ready flag */ -#define CRM_CLOCK_FAILURE_INT_FLAG MAKE_VALUE(0x0C, 7) /*!< clock failure interrupt ready flag */ - -/** - * @} - */ - -/** @defgroup CRM_interrupts_definition - * @brief crm interrupt - * @{ - */ - -#define CRM_LICK_STABLE_INT ((uint32_t)0x00000100) /*!< low speed internal clock stable interrupt */ -#define CRM_LEXT_STABLE_INT ((uint32_t)0x00000200) /*!< low speed external crystal stable interrupt */ -#define CRM_HICK_STABLE_INT ((uint32_t)0x00000400) /*!< high speed internal clock stable interrupt */ -#define CRM_HEXT_STABLE_INT ((uint32_t)0x00000800) /*!< high speed external crystal stable interrupt */ -#define CRM_PLL_STABLE_INT ((uint32_t)0x00001000) /*!< phase locking loop stable interrupt */ -#define CRM_CLOCK_FAILURE_INT ((uint32_t)0x00800000) /*!< clock failure interrupt */ - -/** - * @} - */ - -/** @defgroup CRM_exported_types - * @{ - */ - -/** - * @brief crm periph clock - */ -typedef enum -{ -#if defined (AT32F435xx) - /* ahb periph1 */ - CRM_GPIOA_PERIPH_CLOCK = MAKE_VALUE(0x30, 0), /*!< gpioa periph clock */ - CRM_GPIOB_PERIPH_CLOCK = MAKE_VALUE(0x30, 1), /*!< gpiob periph clock */ - CRM_GPIOC_PERIPH_CLOCK = MAKE_VALUE(0x30, 2), /*!< gpioc periph clock */ - CRM_GPIOD_PERIPH_CLOCK = MAKE_VALUE(0x30, 3), /*!< gpiod periph clock */ - CRM_GPIOE_PERIPH_CLOCK = MAKE_VALUE(0x30, 4), /*!< gpioe periph clock */ - CRM_GPIOF_PERIPH_CLOCK = MAKE_VALUE(0x30, 5), /*!< gpiof periph clock */ - CRM_GPIOG_PERIPH_CLOCK = MAKE_VALUE(0x30, 6), /*!< gpiog periph clock */ - CRM_GPIOH_PERIPH_CLOCK = MAKE_VALUE(0x30, 7), /*!< gpioh periph clock */ - CRM_CRC_PERIPH_CLOCK = MAKE_VALUE(0x30, 12), /*!< crc periph clock */ - CRM_EDMA_PERIPH_CLOCK = MAKE_VALUE(0x30, 21), /*!< edma periph clock */ - CRM_DMA1_PERIPH_CLOCK = MAKE_VALUE(0x30, 22), /*!< dma1 periph clock */ - CRM_DMA2_PERIPH_CLOCK = MAKE_VALUE(0x30, 24), /*!< dma2 periph clock */ - CRM_OTGFS2_PERIPH_CLOCK = MAKE_VALUE(0x30, 29), /*!< otgfs2 periph clock */ - /* ahb periph2 */ - CRM_DVP_PERIPH_CLOCK = MAKE_VALUE(0x34, 0), /*!< dvp periph clock */ - CRM_OTGFS1_PERIPH_CLOCK = MAKE_VALUE(0x34, 7), /*!< otgfs1 periph clock */ - CRM_SDIO1_PERIPH_CLOCK = MAKE_VALUE(0x34, 15), /*!< sdio1 periph clock */ - /* ahb periph3 */ - CRM_XMC_PERIPH_CLOCK = MAKE_VALUE(0x38, 0), /*!< xmc periph clock */ - CRM_QSPI1_PERIPH_CLOCK = MAKE_VALUE(0x38, 1), /*!< qspi1 periph clock */ - CRM_QSPI2_PERIPH_CLOCK = MAKE_VALUE(0x38, 14), /*!< qspi2 periph clock */ - CRM_SDIO2_PERIPH_CLOCK = MAKE_VALUE(0x38, 15), /*!< sdio2 periph clock */ - /* apb1 periph */ - CRM_TMR2_PERIPH_CLOCK = MAKE_VALUE(0x40, 0), /*!< tmr2 periph clock */ - CRM_TMR3_PERIPH_CLOCK = MAKE_VALUE(0x40, 1), /*!< tmr3 periph clock */ - CRM_TMR4_PERIPH_CLOCK = MAKE_VALUE(0x40, 2), /*!< tmr4 periph clock */ - CRM_TMR5_PERIPH_CLOCK = MAKE_VALUE(0x40, 3), /*!< tmr5 periph clock */ - CRM_TMR6_PERIPH_CLOCK = MAKE_VALUE(0x40, 4), /*!< tmr6 periph clock */ - CRM_TMR7_PERIPH_CLOCK = MAKE_VALUE(0x40, 5), /*!< tmr7 periph clock */ - CRM_TMR12_PERIPH_CLOCK = MAKE_VALUE(0x40, 6), /*!< tmr12 periph clock */ - CRM_TMR13_PERIPH_CLOCK = MAKE_VALUE(0x40, 7), /*!< tmr13 periph clock */ - CRM_TMR14_PERIPH_CLOCK = MAKE_VALUE(0x40, 8), /*!< tmr14 periph clock */ - CRM_WWDT_PERIPH_CLOCK = MAKE_VALUE(0x40, 11), /*!< wwdt periph clock */ - CRM_SPI2_PERIPH_CLOCK = MAKE_VALUE(0x40, 14), /*!< spi2 periph clock */ - CRM_SPI3_PERIPH_CLOCK = MAKE_VALUE(0x40, 15), /*!< spi3 periph clock */ - CRM_USART2_PERIPH_CLOCK = MAKE_VALUE(0x40, 17), /*!< usart2 periph clock */ - CRM_USART3_PERIPH_CLOCK = MAKE_VALUE(0x40, 18), /*!< usart3 periph clock */ - CRM_UART4_PERIPH_CLOCK = MAKE_VALUE(0x40, 19), /*!< uart4 periph clock */ - CRM_UART5_PERIPH_CLOCK = MAKE_VALUE(0x40, 20), /*!< uart5 periph clock */ - CRM_I2C1_PERIPH_CLOCK = MAKE_VALUE(0x40, 21), /*!< i2c1 periph clock */ - CRM_I2C2_PERIPH_CLOCK = MAKE_VALUE(0x40, 22), /*!< i2c2 periph clock */ - CRM_I2C3_PERIPH_CLOCK = MAKE_VALUE(0x40, 23), /*!< i2c3 periph clock */ - CRM_CAN1_PERIPH_CLOCK = MAKE_VALUE(0x40, 25), /*!< can1 periph clock */ - CRM_CAN2_PERIPH_CLOCK = MAKE_VALUE(0x40, 26), /*!< can2 periph clock */ - CRM_PWC_PERIPH_CLOCK = MAKE_VALUE(0x40, 28), /*!< pwc periph clock */ - CRM_DAC_PERIPH_CLOCK = MAKE_VALUE(0x40, 29), /*!< dac periph clock */ - CRM_UART7_PERIPH_CLOCK = MAKE_VALUE(0x40, 30), /*!< uart7 periph clock */ - CRM_UART8_PERIPH_CLOCK = MAKE_VALUE(0x40, 31), /*!< uart8 periph clock */ - /* apb2 periph */ - CRM_TMR1_PERIPH_CLOCK = MAKE_VALUE(0x44, 0), /*!< tmr1 periph clock */ - CRM_TMR8_PERIPH_CLOCK = MAKE_VALUE(0x44, 1), /*!< tmr8 periph clock */ - CRM_USART1_PERIPH_CLOCK = MAKE_VALUE(0x44, 4), /*!< usart1 periph clock */ - CRM_USART6_PERIPH_CLOCK = MAKE_VALUE(0x44, 5), /*!< usart6 periph clock */ - CRM_ADC1_PERIPH_CLOCK = MAKE_VALUE(0x44, 8), /*!< adc1 periph clock */ - CRM_ADC2_PERIPH_CLOCK = MAKE_VALUE(0x44, 9), /*!< adc2 periph clock */ - CRM_ADC3_PERIPH_CLOCK = MAKE_VALUE(0x44, 10), /*!< adc3 periph clock */ - CRM_SPI1_PERIPH_CLOCK = MAKE_VALUE(0x44, 12), /*!< spi1 periph clock */ - CRM_SPI4_PERIPH_CLOCK = MAKE_VALUE(0x44, 13), /*!< spi4 periph clock */ - CRM_SCFG_PERIPH_CLOCK = MAKE_VALUE(0x44, 14), /*!< scfg periph clock */ - CRM_TMR9_PERIPH_CLOCK = MAKE_VALUE(0x44, 16), /*!< tmr9 periph clock */ - CRM_TMR10_PERIPH_CLOCK = MAKE_VALUE(0x44, 17), /*!< tmr10 periph clock */ - CRM_TMR11_PERIPH_CLOCK = MAKE_VALUE(0x44, 18), /*!< tmr11 periph clock */ - CRM_TMR20_PERIPH_CLOCK = MAKE_VALUE(0x44, 20), /*!< tmr20 periph clock */ - CRM_ACC_PERIPH_CLOCK = MAKE_VALUE(0x44, 29) /*!< acc periph clock */ -#endif - -#if defined (AT32F437xx) - /* ahb periph1 */ - CRM_GPIOA_PERIPH_CLOCK = MAKE_VALUE(0x30, 0), /*!< gpioa periph clock */ - CRM_GPIOB_PERIPH_CLOCK = MAKE_VALUE(0x30, 1), /*!< gpiob periph clock */ - CRM_GPIOC_PERIPH_CLOCK = MAKE_VALUE(0x30, 2), /*!< gpioc periph clock */ - CRM_GPIOD_PERIPH_CLOCK = MAKE_VALUE(0x30, 3), /*!< gpiod periph clock */ - CRM_GPIOE_PERIPH_CLOCK = MAKE_VALUE(0x30, 4), /*!< gpioe periph clock */ - CRM_GPIOF_PERIPH_CLOCK = MAKE_VALUE(0x30, 5), /*!< gpiof periph clock */ - CRM_GPIOG_PERIPH_CLOCK = MAKE_VALUE(0x30, 6), /*!< gpiog periph clock */ - CRM_GPIOH_PERIPH_CLOCK = MAKE_VALUE(0x30, 7), /*!< gpioh periph clock */ - CRM_CRC_PERIPH_CLOCK = MAKE_VALUE(0x30, 12), /*!< crc periph clock */ - CRM_EDMA_PERIPH_CLOCK = MAKE_VALUE(0x30, 21), /*!< edma periph clock */ - CRM_DMA1_PERIPH_CLOCK = MAKE_VALUE(0x30, 22), /*!< dma1 periph clock */ - CRM_DMA2_PERIPH_CLOCK = MAKE_VALUE(0x30, 24), /*!< dma2 periph clock */ - CRM_EMAC_PERIPH_CLOCK = MAKE_VALUE(0x30, 25), /*!< emac periph clock */ - CRM_EMACTX_PERIPH_CLOCK = MAKE_VALUE(0x30, 26), /*!< emac tx periph clock */ - CRM_EMACRX_PERIPH_CLOCK = MAKE_VALUE(0x30, 27), /*!< emac rx periph clock */ - CRM_EMACPTP_PERIPH_CLOCK = MAKE_VALUE(0x30, 28), /*!< emac ptp periph clock */ - CRM_OTGFS2_PERIPH_CLOCK = MAKE_VALUE(0x30, 29), /*!< otgfs2 periph clock */ - /* ahb periph2 */ - CRM_DVP_PERIPH_CLOCK = MAKE_VALUE(0x34, 0), /*!< dvp periph clock */ - CRM_OTGFS1_PERIPH_CLOCK = MAKE_VALUE(0x34, 7), /*!< otgfs1 periph clock */ - CRM_SDIO1_PERIPH_CLOCK = MAKE_VALUE(0x34, 15), /*!< sdio1 periph clock */ - /* ahb periph3 */ - CRM_XMC_PERIPH_CLOCK = MAKE_VALUE(0x38, 0), /*!< xmc periph clock */ - CRM_QSPI1_PERIPH_CLOCK = MAKE_VALUE(0x38, 1), /*!< qspi1 periph clock */ - CRM_QSPI2_PERIPH_CLOCK = MAKE_VALUE(0x38, 14), /*!< qspi2 periph clock */ - CRM_SDIO2_PERIPH_CLOCK = MAKE_VALUE(0x38, 15), /*!< sdio2 periph clock */ - /* apb1 periph */ - CRM_TMR2_PERIPH_CLOCK = MAKE_VALUE(0x40, 0), /*!< tmr2 periph clock */ - CRM_TMR3_PERIPH_CLOCK = MAKE_VALUE(0x40, 1), /*!< tmr3 periph clock */ - CRM_TMR4_PERIPH_CLOCK = MAKE_VALUE(0x40, 2), /*!< tmr4 periph clock */ - CRM_TMR5_PERIPH_CLOCK = MAKE_VALUE(0x40, 3), /*!< tmr5 periph clock */ - CRM_TMR6_PERIPH_CLOCK = MAKE_VALUE(0x40, 4), /*!< tmr6 periph clock */ - CRM_TMR7_PERIPH_CLOCK = MAKE_VALUE(0x40, 5), /*!< tmr7 periph clock */ - CRM_TMR12_PERIPH_CLOCK = MAKE_VALUE(0x40, 6), /*!< tmr12 periph clock */ - CRM_TMR13_PERIPH_CLOCK = MAKE_VALUE(0x40, 7), /*!< tmr13 periph clock */ - CRM_TMR14_PERIPH_CLOCK = MAKE_VALUE(0x40, 8), /*!< tmr14 periph clock */ - CRM_WWDT_PERIPH_CLOCK = MAKE_VALUE(0x40, 11), /*!< wwdt periph clock */ - CRM_SPI2_PERIPH_CLOCK = MAKE_VALUE(0x40, 14), /*!< spi2 periph clock */ - CRM_SPI3_PERIPH_CLOCK = MAKE_VALUE(0x40, 15), /*!< spi3 periph clock */ - CRM_USART2_PERIPH_CLOCK = MAKE_VALUE(0x40, 17), /*!< usart2 periph clock */ - CRM_USART3_PERIPH_CLOCK = MAKE_VALUE(0x40, 18), /*!< usart3 periph clock */ - CRM_UART4_PERIPH_CLOCK = MAKE_VALUE(0x40, 19), /*!< uart4 periph clock */ - CRM_UART5_PERIPH_CLOCK = MAKE_VALUE(0x40, 20), /*!< uart5 periph clock */ - CRM_I2C1_PERIPH_CLOCK = MAKE_VALUE(0x40, 21), /*!< i2c1 periph clock */ - CRM_I2C2_PERIPH_CLOCK = MAKE_VALUE(0x40, 22), /*!< i2c2 periph clock */ - CRM_I2C3_PERIPH_CLOCK = MAKE_VALUE(0x40, 23), /*!< i2c3 periph clock */ - CRM_CAN1_PERIPH_CLOCK = MAKE_VALUE(0x40, 25), /*!< can1 periph clock */ - CRM_CAN2_PERIPH_CLOCK = MAKE_VALUE(0x40, 26), /*!< can2 periph clock */ - CRM_PWC_PERIPH_CLOCK = MAKE_VALUE(0x40, 28), /*!< pwc periph clock */ - CRM_DAC_PERIPH_CLOCK = MAKE_VALUE(0x40, 29), /*!< dac periph clock */ - CRM_UART7_PERIPH_CLOCK = MAKE_VALUE(0x40, 30), /*!< uart7 periph clock */ - CRM_UART8_PERIPH_CLOCK = MAKE_VALUE(0x40, 31), /*!< uart8 periph clock */ - /* apb2 periph */ - CRM_TMR1_PERIPH_CLOCK = MAKE_VALUE(0x44, 0), /*!< tmr1 periph clock */ - CRM_TMR8_PERIPH_CLOCK = MAKE_VALUE(0x44, 1), /*!< tmr8 periph clock */ - CRM_USART1_PERIPH_CLOCK = MAKE_VALUE(0x44, 4), /*!< usart1 periph clock */ - CRM_USART6_PERIPH_CLOCK = MAKE_VALUE(0x44, 5), /*!< usart6 periph clock */ - CRM_ADC1_PERIPH_CLOCK = MAKE_VALUE(0x44, 8), /*!< adc1 periph clock */ - CRM_ADC2_PERIPH_CLOCK = MAKE_VALUE(0x44, 9), /*!< adc2 periph clock */ - CRM_ADC3_PERIPH_CLOCK = MAKE_VALUE(0x44, 10), /*!< adc3 periph clock */ - CRM_SPI1_PERIPH_CLOCK = MAKE_VALUE(0x44, 12), /*!< spi1 periph clock */ - CRM_SPI4_PERIPH_CLOCK = MAKE_VALUE(0x44, 13), /*!< spi4 periph clock */ - CRM_SCFG_PERIPH_CLOCK = MAKE_VALUE(0x44, 14), /*!< scfg periph clock */ - CRM_TMR9_PERIPH_CLOCK = MAKE_VALUE(0x44, 16), /*!< tmr9 periph clock */ - CRM_TMR10_PERIPH_CLOCK = MAKE_VALUE(0x44, 17), /*!< tmr10 periph clock */ - CRM_TMR11_PERIPH_CLOCK = MAKE_VALUE(0x44, 18), /*!< tmr11 periph clock */ - CRM_TMR20_PERIPH_CLOCK = MAKE_VALUE(0x44, 20), /*!< tmr20 periph clock */ - CRM_ACC_PERIPH_CLOCK = MAKE_VALUE(0x44, 29) /*!< acc periph clock */ -#endif - -} crm_periph_clock_type; - -/** - * @brief crm periph reset - */ -typedef enum -{ -#if defined (AT32F435xx) - /* ahb periph1 */ - CRM_GPIOA_PERIPH_RESET = MAKE_VALUE(0x10, 0), /*!< gpioa periph reset */ - CRM_GPIOB_PERIPH_RESET = MAKE_VALUE(0x10, 1), /*!< gpiob periph reset */ - CRM_GPIOC_PERIPH_RESET = MAKE_VALUE(0x10, 2), /*!< gpioc periph reset */ - CRM_GPIOD_PERIPH_RESET = MAKE_VALUE(0x10, 3), /*!< gpiod periph reset */ - CRM_GPIOE_PERIPH_RESET = MAKE_VALUE(0x10, 4), /*!< gpioe periph reset */ - CRM_GPIOF_PERIPH_RESET = MAKE_VALUE(0x10, 5), /*!< gpiof periph reset */ - CRM_GPIOG_PERIPH_RESET = MAKE_VALUE(0x10, 6), /*!< gpiog periph reset */ - CRM_GPIOH_PERIPH_RESET = MAKE_VALUE(0x10, 7), /*!< gpioh periph reset */ - CRM_CRC_PERIPH_RESET = MAKE_VALUE(0x10, 12), /*!< crc periph reset */ - CRM_EDMA_PERIPH_RESET = MAKE_VALUE(0x10, 21), /*!< edma periph reset */ - CRM_DMA1_PERIPH_RESET = MAKE_VALUE(0x10, 22), /*!< dma1 periph reset */ - CRM_DMA2_PERIPH_RESET = MAKE_VALUE(0x10, 24), /*!< dma2 periph reset */ - CRM_OTGFS2_PERIPH_RESET = MAKE_VALUE(0x10, 29), /*!< otgfs2 periph reset */ - /* ahb periph2 */ - CRM_DVP_PERIPH_RESET = MAKE_VALUE(0x14, 0), /*!< dvp periph reset */ - CRM_OTGFS1_PERIPH_RESET = MAKE_VALUE(0x14, 7), /*!< otgfs1 periph reset */ - CRM_SDIO1_PERIPH_RESET = MAKE_VALUE(0x14, 15), /*!< sdio1 periph reset */ - /* ahb periph3 */ - CRM_XMC_PERIPH_RESET = MAKE_VALUE(0x18, 0), /*!< xmc periph reset */ - CRM_QSPI1_PERIPH_RESET = MAKE_VALUE(0x18, 1), /*!< qspi1 periph reset */ - CRM_QSPI2_PERIPH_RESET = MAKE_VALUE(0x18, 14), /*!< qspi2 periph reset */ - CRM_SDIO2_PERIPH_RESET = MAKE_VALUE(0x18, 15), /*!< sdio2 periph reset */ - /* apb1 periph */ - CRM_TMR2_PERIPH_RESET = MAKE_VALUE(0x20, 0), /*!< tmr2 periph reset */ - CRM_TMR3_PERIPH_RESET = MAKE_VALUE(0x20, 1), /*!< tmr3 periph reset */ - CRM_TMR4_PERIPH_RESET = MAKE_VALUE(0x20, 2), /*!< tmr4 periph reset */ - CRM_TMR5_PERIPH_RESET = MAKE_VALUE(0x20, 3), /*!< tmr5 periph reset */ - CRM_TMR6_PERIPH_RESET = MAKE_VALUE(0x20, 4), /*!< tmr6 periph reset */ - CRM_TMR7_PERIPH_RESET = MAKE_VALUE(0x20, 5), /*!< tmr7 periph reset */ - CRM_TMR12_PERIPH_RESET = MAKE_VALUE(0x20, 6), /*!< tmr12 periph reset */ - CRM_TMR13_PERIPH_RESET = MAKE_VALUE(0x20, 7), /*!< tmr13 periph reset */ - CRM_TMR14_PERIPH_RESET = MAKE_VALUE(0x20, 8), /*!< tmr14 periph reset */ - CRM_WWDT_PERIPH_RESET = MAKE_VALUE(0x20, 11), /*!< wwdt periph reset */ - CRM_SPI2_PERIPH_RESET = MAKE_VALUE(0x20, 14), /*!< spi2 periph reset */ - CRM_SPI3_PERIPH_RESET = MAKE_VALUE(0x20, 15), /*!< spi3 periph reset */ - CRM_USART2_PERIPH_RESET = MAKE_VALUE(0x20, 17), /*!< usart2 periph reset */ - CRM_USART3_PERIPH_RESET = MAKE_VALUE(0x20, 18), /*!< usart3 periph reset */ - CRM_UART4_PERIPH_RESET = MAKE_VALUE(0x20, 19), /*!< uart4 periph reset */ - CRM_UART5_PERIPH_RESET = MAKE_VALUE(0x20, 20), /*!< uart5 periph reset */ - CRM_I2C1_PERIPH_RESET = MAKE_VALUE(0x20, 21), /*!< i2c1 periph reset */ - CRM_I2C2_PERIPH_RESET = MAKE_VALUE(0x20, 22), /*!< i2c2 periph reset */ - CRM_I2C3_PERIPH_RESET = MAKE_VALUE(0x20, 23), /*!< i2c3 periph reset */ - CRM_CAN1_PERIPH_RESET = MAKE_VALUE(0x20, 25), /*!< can1 periph reset */ - CRM_CAN2_PERIPH_RESET = MAKE_VALUE(0x20, 26), /*!< can2 periph reset */ - CRM_PWC_PERIPH_RESET = MAKE_VALUE(0x20, 28), /*!< pwc periph reset */ - CRM_DAC_PERIPH_RESET = MAKE_VALUE(0x20, 29), /*!< dac periph reset */ - CRM_UART7_PERIPH_RESET = MAKE_VALUE(0x20, 30), /*!< uart7 periph reset */ - CRM_UART8_PERIPH_RESET = MAKE_VALUE(0x20, 31), /*!< uart8 periph reset */ - /* apb2 periph */ - CRM_TMR1_PERIPH_RESET = MAKE_VALUE(0x24, 0), /*!< tmr1 periph reset */ - CRM_TMR8_PERIPH_RESET = MAKE_VALUE(0x24, 1), /*!< tmr8 periph reset */ - CRM_USART1_PERIPH_RESET = MAKE_VALUE(0x24, 4), /*!< usart1 periph reset */ - CRM_USART6_PERIPH_RESET = MAKE_VALUE(0x24, 5), /*!< usart6 periph reset */ - CRM_ADC_PERIPH_RESET = MAKE_VALUE(0x24, 8), /*!< adc periph reset */ - CRM_SPI1_PERIPH_RESET = MAKE_VALUE(0x24, 12), /*!< spi1 periph reset */ - CRM_SPI4_PERIPH_RESET = MAKE_VALUE(0x24, 13), /*!< spi4 periph reset */ - CRM_SCFG_PERIPH_RESET = MAKE_VALUE(0x24, 14), /*!< scfg periph reset */ - CRM_TMR9_PERIPH_RESET = MAKE_VALUE(0x24, 16), /*!< tmr9 periph reset */ - CRM_TMR10_PERIPH_RESET = MAKE_VALUE(0x24, 17), /*!< tmr10 periph reset */ - CRM_TMR11_PERIPH_RESET = MAKE_VALUE(0x24, 18), /*!< tmr11 periph reset */ - CRM_TMR20_PERIPH_RESET = MAKE_VALUE(0x24, 20), /*!< tmr20 periph reset */ - CRM_ACC_PERIPH_RESET = MAKE_VALUE(0x24, 29) /*!< acc periph reset */ -#endif - -#if defined (AT32F437xx) - /* ahb periph1 */ - CRM_GPIOA_PERIPH_RESET = MAKE_VALUE(0x10, 0), /*!< gpioa periph reset */ - CRM_GPIOB_PERIPH_RESET = MAKE_VALUE(0x10, 1), /*!< gpiob periph reset */ - CRM_GPIOC_PERIPH_RESET = MAKE_VALUE(0x10, 2), /*!< gpioc periph reset */ - CRM_GPIOD_PERIPH_RESET = MAKE_VALUE(0x10, 3), /*!< gpiod periph reset */ - CRM_GPIOE_PERIPH_RESET = MAKE_VALUE(0x10, 4), /*!< gpioe periph reset */ - CRM_GPIOF_PERIPH_RESET = MAKE_VALUE(0x10, 5), /*!< gpiof periph reset */ - CRM_GPIOG_PERIPH_RESET = MAKE_VALUE(0x10, 6), /*!< gpiog periph reset */ - CRM_GPIOH_PERIPH_RESET = MAKE_VALUE(0x10, 7), /*!< gpioh periph reset */ - CRM_CRC_PERIPH_RESET = MAKE_VALUE(0x10, 12), /*!< crc periph reset */ - CRM_EDMA_PERIPH_RESET = MAKE_VALUE(0x10, 21), /*!< edma periph reset */ - CRM_DMA1_PERIPH_RESET = MAKE_VALUE(0x10, 22), /*!< dma1 periph reset */ - CRM_DMA2_PERIPH_RESET = MAKE_VALUE(0x10, 24), /*!< dma2 periph reset */ - CRM_EMAC_PERIPH_RESET = MAKE_VALUE(0x10, 25), /*!< emac periph reset */ - CRM_OTGFS2_PERIPH_RESET = MAKE_VALUE(0x10, 29), /*!< otgfs2 periph reset */ - /* ahb periph2 */ - CRM_DVP_PERIPH_RESET = MAKE_VALUE(0x14, 0), /*!< dvp periph reset */ - CRM_OTGFS1_PERIPH_RESET = MAKE_VALUE(0x14, 7), /*!< otgfs1 periph reset */ - CRM_SDIO1_PERIPH_RESET = MAKE_VALUE(0x14, 15), /*!< sdio1 periph reset */ - /* ahb periph3 */ - CRM_XMC_PERIPH_RESET = MAKE_VALUE(0x18, 0), /*!< xmc periph reset */ - CRM_QSPI1_PERIPH_RESET = MAKE_VALUE(0x18, 1), /*!< qspi1 periph reset */ - CRM_QSPI2_PERIPH_RESET = MAKE_VALUE(0x18, 14), /*!< qspi2 periph reset */ - CRM_SDIO2_PERIPH_RESET = MAKE_VALUE(0x18, 15), /*!< sdio2 periph reset */ - /* apb1 periph */ - CRM_TMR2_PERIPH_RESET = MAKE_VALUE(0x20, 0), /*!< tmr2 periph reset */ - CRM_TMR3_PERIPH_RESET = MAKE_VALUE(0x20, 1), /*!< tmr3 periph reset */ - CRM_TMR4_PERIPH_RESET = MAKE_VALUE(0x20, 2), /*!< tmr4 periph reset */ - CRM_TMR5_PERIPH_RESET = MAKE_VALUE(0x20, 3), /*!< tmr5 periph reset */ - CRM_TMR6_PERIPH_RESET = MAKE_VALUE(0x20, 4), /*!< tmr6 periph reset */ - CRM_TMR7_PERIPH_RESET = MAKE_VALUE(0x20, 5), /*!< tmr7 periph reset */ - CRM_TMR12_PERIPH_RESET = MAKE_VALUE(0x20, 6), /*!< tmr12 periph reset */ - CRM_TMR13_PERIPH_RESET = MAKE_VALUE(0x20, 7), /*!< tmr13 periph reset */ - CRM_TMR14_PERIPH_RESET = MAKE_VALUE(0x20, 8), /*!< tmr14 periph reset */ - CRM_WWDT_PERIPH_RESET = MAKE_VALUE(0x20, 11), /*!< wwdt periph reset */ - CRM_SPI2_PERIPH_RESET = MAKE_VALUE(0x20, 14), /*!< spi2 periph reset */ - CRM_SPI3_PERIPH_RESET = MAKE_VALUE(0x20, 15), /*!< spi3 periph reset */ - CRM_USART2_PERIPH_RESET = MAKE_VALUE(0x20, 17), /*!< usart2 periph reset */ - CRM_USART3_PERIPH_RESET = MAKE_VALUE(0x20, 18), /*!< usart3 periph reset */ - CRM_UART4_PERIPH_RESET = MAKE_VALUE(0x20, 19), /*!< uart4 periph reset */ - CRM_UART5_PERIPH_RESET = MAKE_VALUE(0x20, 20), /*!< uart5 periph reset */ - CRM_I2C1_PERIPH_RESET = MAKE_VALUE(0x20, 21), /*!< i2c1 periph reset */ - CRM_I2C2_PERIPH_RESET = MAKE_VALUE(0x20, 22), /*!< i2c2 periph reset */ - CRM_I2C3_PERIPH_RESET = MAKE_VALUE(0x20, 23), /*!< i2c3 periph reset */ - CRM_CAN1_PERIPH_RESET = MAKE_VALUE(0x20, 25), /*!< can1 periph reset */ - CRM_CAN2_PERIPH_RESET = MAKE_VALUE(0x20, 26), /*!< can2 periph reset */ - CRM_PWC_PERIPH_RESET = MAKE_VALUE(0x20, 28), /*!< pwc periph reset */ - CRM_DAC_PERIPH_RESET = MAKE_VALUE(0x20, 29), /*!< dac periph reset */ - CRM_UART7_PERIPH_RESET = MAKE_VALUE(0x20, 30), /*!< uart7 periph reset */ - CRM_UART8_PERIPH_RESET = MAKE_VALUE(0x20, 31), /*!< uart8 periph reset */ - /* apb2 periph */ - CRM_TMR1_PERIPH_RESET = MAKE_VALUE(0x24, 0), /*!< tmr1 periph reset */ - CRM_TMR8_PERIPH_RESET = MAKE_VALUE(0x24, 1), /*!< tmr8 periph reset */ - CRM_USART1_PERIPH_RESET = MAKE_VALUE(0x24, 4), /*!< usart1 periph reset */ - CRM_USART6_PERIPH_RESET = MAKE_VALUE(0x24, 5), /*!< usart6 periph reset */ - CRM_ADC_PERIPH_RESET = MAKE_VALUE(0x24, 8), /*!< adc periph reset */ - CRM_SPI1_PERIPH_RESET = MAKE_VALUE(0x24, 12), /*!< spi1 periph reset */ - CRM_SPI4_PERIPH_RESET = MAKE_VALUE(0x24, 13), /*!< spi4 periph reset */ - CRM_SCFG_PERIPH_RESET = MAKE_VALUE(0x24, 14), /*!< scfg periph reset */ - CRM_TMR9_PERIPH_RESET = MAKE_VALUE(0x24, 16), /*!< tmr9 periph reset */ - CRM_TMR10_PERIPH_RESET = MAKE_VALUE(0x24, 17), /*!< tmr10 periph reset */ - CRM_TMR11_PERIPH_RESET = MAKE_VALUE(0x24, 18), /*!< tmr11 periph reset */ - CRM_TMR20_PERIPH_RESET = MAKE_VALUE(0x24, 20), /*!< tmr20 periph reset */ - CRM_ACC_PERIPH_RESET = MAKE_VALUE(0x24, 29) /*!< acc periph reset */ -#endif - -} crm_periph_reset_type; - -/** - * @brief crm periph clock in low power mode - */ -typedef enum -{ -#if defined (AT32F435xx) - /* ahb periph1 */ - CRM_GPIOA_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 0), /*!< gpioa sleep mode periph clock */ - CRM_GPIOB_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 1), /*!< gpiob sleep mode periph clock */ - CRM_GPIOC_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 2), /*!< gpioc sleep mode periph clock */ - CRM_GPIOD_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 3), /*!< gpiod sleep mode periph clock */ - CRM_GPIOE_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 4), /*!< gpioe sleep mode periph clock */ - CRM_GPIOF_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 5), /*!< gpiof sleep mode periph clock */ - CRM_GPIOG_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 6), /*!< gpiog sleep mode periph clock */ - CRM_GPIOH_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 7), /*!< gpioh sleep mode periph clock */ - CRM_CRC_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 12), /*!< crc sleep mode periph clock */ - CRM_EDMA_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 21), /*!< edma sleep mode periph clock */ - CRM_DMA1_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 22), /*!< dma1 sleep mode periph clock */ - CRM_DMA2_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 24), /*!< dma2 sleep mode periph clock */ - CRM_EMAC_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 25), /*!< emac sleep mode periph clock */ - CRM_EMACTX_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 26), /*!< emac tx sleep mode periph clock */ - CRM_EMACRX_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 27), /*!< emac rx sleep mode periph clock */ - CRM_EMACPTP_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 28), /*!< emac ptp sleep mode periph clock */ - CRM_OTGFS2_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 29), /*!< otgfs2 sleep mode periph clock */ - /* ahb periph2 */ - CRM_DVP_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 0), /*!< dvp sleep mode periph clock */ - CRM_OTGFS1_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 7), /*!< otgfs1 sleep mode periph clock */ - CRM_SDIO1_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 15), /*!< sdio1 sleep mode periph clock */ - /* ahb periph3 */ - CRM_XMC_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 0), /*!< xmc sleep mode periph clock */ - CRM_QSPI1_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 1), /*!< qspi1 sleep mode periph clock */ - CRM_QSPI2_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 14), /*!< qspi2 sleep mode periph clock */ - CRM_SDIO2_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 15), /*!< sdio2 sleep mode periph clock */ - /* apb1 periph */ - CRM_TMR2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 0), /*!< tmr2 sleep mode periph clock */ - CRM_TMR3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 1), /*!< tmr3 sleep mode periph clock */ - CRM_TMR4_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 2), /*!< tmr4 sleep mode periph clock */ - CRM_TMR5_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 3), /*!< tmr5 sleep mode periph clock */ - CRM_TMR6_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 4), /*!< tmr6 sleep mode periph clock */ - CRM_TMR7_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 5), /*!< tmr7 sleep mode periph clock */ - CRM_TMR12_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 6), /*!< tmr12 sleep mode periph clock */ - CRM_TMR13_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 7), /*!< tmr13 sleep mode periph clock */ - CRM_TMR14_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 8), /*!< tmr14 sleep mode periph clock */ - CRM_WWDT_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 11), /*!< wwdt sleep mode periph clock */ - CRM_SPI2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 14), /*!< spi2 sleep mode periph clock */ - CRM_SPI3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 15), /*!< spi3 sleep mode periph clock */ - CRM_USART2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 17), /*!< usart2 sleep mode periph clock */ - CRM_USART3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 18), /*!< usart3 sleep mode periph clock */ - CRM_UART4_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 19), /*!< uart4 sleep mode periph clock */ - CRM_UART5_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 20), /*!< uart5 sleep mode periph clock */ - CRM_I2C1_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 21), /*!< i2c1 sleep mode periph clock */ - CRM_I2C2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 22), /*!< i2c2 sleep mode periph clock */ - CRM_I2C3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 23), /*!< i2c3 sleep mode periph clock */ - CRM_CAN1_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 25), /*!< can1 sleep mode periph clock */ - CRM_CAN2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 26), /*!< can2 sleep mode periph clock */ - CRM_PWC_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 28), /*!< pwc sleep mode periph clock */ - CRM_DAC_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 29), /*!< dac sleep mode periph clock */ - CRM_UART7_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 30), /*!< uart7 sleep mode periph clock */ - CRM_UART8_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 31), /*!< uart8 sleep mode periph clock */ - /* apb2 periph */ - CRM_TMR1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 0), /*!< tmr1 sleep mode periph clock */ - CRM_TMR8_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 1), /*!< tmr8 sleep mode periph clock */ - CRM_USART1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 4), /*!< usart1 sleep mode periph clock */ - CRM_USART6_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 5), /*!< usart6 sleep mode periph clock */ - CRM_ADC1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 8), /*!< adc1 sleep mode periph clock */ - CRM_ADC2_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 9), /*!< adc2 sleep mode periph clock */ - CRM_ADC3_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 10), /*!< adc3 sleep mode periph clock */ - CRM_SPI1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 12), /*!< spi1 sleep mode periph clock */ - CRM_SPI4_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 13), /*!< spi4 sleep mode periph clock */ - CRM_SCFG_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 14), /*!< scfg sleep mode periph clock */ - CRM_TMR9_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 16), /*!< tmr9 sleep mode periph clock */ - CRM_TMR10_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 17), /*!< tmr10 sleep mode periph clock */ - CRM_TMR11_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 18), /*!< tmr11 sleep mode periph clock */ - CRM_TMR20_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 20), /*!< tmr20 sleep mode periph clock */ - CRM_ACC_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 29) /*!< acc sleep mode periph clock */ -#endif - -#if defined (AT32F437xx) - /* ahb periph1 */ - CRM_GPIOA_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 0), /*!< gpioa sleep mode periph clock */ - CRM_GPIOB_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 1), /*!< gpiob sleep mode periph clock */ - CRM_GPIOC_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 2), /*!< gpioc sleep mode periph clock */ - CRM_GPIOD_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 3), /*!< gpiod sleep mode periph clock */ - CRM_GPIOE_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 4), /*!< gpioe sleep mode periph clock */ - CRM_GPIOF_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 5), /*!< gpiof sleep mode periph clock */ - CRM_GPIOG_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 6), /*!< gpiog sleep mode periph clock */ - CRM_GPIOH_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 7), /*!< gpioh sleep mode periph clock */ - CRM_CRC_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 12), /*!< crc sleep mode periph clock */ - CRM_EDMA_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 21), /*!< edma sleep mode periph clock */ - CRM_DMA1_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 22), /*!< dma1 sleep mode periph clock */ - CRM_DMA2_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 24), /*!< dma2 sleep mode periph clock */ - CRM_OTGFS2_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 29), /*!< otgfs2 sleep mode periph clock */ - /* ahb periph2 */ - CRM_DVP_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 0), /*!< dvp sleep mode periph clock */ - CRM_OTGFS1_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 7), /*!< otgfs1 sleep mode periph clock */ - CRM_SDIO1_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 15), /*!< sdio1 sleep mode periph clock */ - /* ahb periph3 */ - CRM_XMC_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 0), /*!< xmc sleep mode periph clock */ - CRM_QSPI1_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 1), /*!< qspi1 sleep mode periph clock */ - CRM_QSPI2_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 14), /*!< qspi2 sleep mode periph clock */ - CRM_SDIO2_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 15), /*!< sdio2 sleep mode periph clock */ - /* apb1 periph */ - CRM_TMR2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 0), /*!< tmr2 sleep mode periph clock */ - CRM_TMR3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 1), /*!< tmr3 sleep mode periph clock */ - CRM_TMR4_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 2), /*!< tmr4 sleep mode periph clock */ - CRM_TMR5_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 3), /*!< tmr5 sleep mode periph clock */ - CRM_TMR6_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 4), /*!< tmr6 sleep mode periph clock */ - CRM_TMR7_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 5), /*!< tmr7 sleep mode periph clock */ - CRM_TMR12_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 6), /*!< tmr12 sleep mode periph clock */ - CRM_TMR13_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 7), /*!< tmr13 sleep mode periph clock */ - CRM_TMR14_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 8), /*!< tmr14 sleep mode periph clock */ - CRM_WWDT_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 11), /*!< wwdt sleep mode periph clock */ - CRM_SPI2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 14), /*!< spi2 sleep mode periph clock */ - CRM_SPI3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 15), /*!< spi3 sleep mode periph clock */ - CRM_USART2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 17), /*!< usart2 sleep mode periph clock */ - CRM_USART3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 18), /*!< usart3 sleep mode periph clock */ - CRM_UART4_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 19), /*!< uart4 sleep mode periph clock */ - CRM_UART5_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 20), /*!< uart5 sleep mode periph clock */ - CRM_I2C1_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 21), /*!< i2c1 sleep mode periph clock */ - CRM_I2C2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 22), /*!< i2c2 sleep mode periph clock */ - CRM_I2C3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 23), /*!< i2c3 sleep mode periph clock */ - CRM_CAN1_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 25), /*!< can1 sleep mode periph clock */ - CRM_CAN2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 26), /*!< can2 sleep mode periph clock */ - CRM_PWC_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 28), /*!< pwc sleep mode periph clock */ - CRM_DAC_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 29), /*!< dac sleep mode periph clock */ - CRM_UART7_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 30), /*!< uart7 sleep mode periph clock */ - CRM_UART8_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 31), /*!< uart8 sleep mode periph clock */ - /* apb2 periph */ - CRM_TMR1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 0), /*!< tmr1 sleep mode periph clock */ - CRM_TMR8_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 1), /*!< tmr8 sleep mode periph clock */ - CRM_USART1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 4), /*!< usart1 sleep mode periph clock */ - CRM_USART6_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 5), /*!< usart6 sleep mode periph clock */ - CRM_ADC1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 8), /*!< adc1 sleep mode periph clock */ - CRM_ADC2_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 9), /*!< adc2 sleep mode periph clock */ - CRM_ADC3_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 10), /*!< adc3 sleep mode periph clock */ - CRM_SPI1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 12), /*!< spi1 sleep mode periph clock */ - CRM_SPI4_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 13), /*!< spi4 sleep mode periph clock */ - CRM_SCFG_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 14), /*!< scfg sleep mode periph clock */ - CRM_TMR9_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 16), /*!< tmr9 sleep mode periph clock */ - CRM_TMR10_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 17), /*!< tmr10 sleep mode periph clock */ - CRM_TMR11_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 18), /*!< tmr11 sleep mode periph clock */ - CRM_TMR20_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 20), /*!< tmr20 sleep mode periph clock */ - CRM_ACC_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 29) /*!< acc sleep mode periph clock */ -#endif - -} crm_periph_clock_lowpower_type; - -/** - * @brief crm pll clock source - */ -typedef enum -{ - CRM_PLL_SOURCE_HICK = 0x00, /*!< high speed internal clock as pll reference clock source */ - CRM_PLL_SOURCE_HEXT = 0x01 /*!< high speed external crystal as pll reference clock source */ -} crm_pll_clock_source_type; - -/** - * @brief crm pll fr - */ -typedef enum -{ - CRM_PLL_FR_1 = 0x00, /*!< pll post-division div1 */ - CRM_PLL_FR_2 = 0x01, /*!< pll post-division div2 */ - CRM_PLL_FR_4 = 0x02, /*!< pll post-division div4 */ - CRM_PLL_FR_8 = 0x03, /*!< pll post-division div8 */ - CRM_PLL_FR_16 = 0x04, /*!< pll post-division div16 */ - CRM_PLL_FR_32 = 0x05 /*!< pll post-division div32 */ -} crm_pll_fr_type; - -/** - * @brief crm clock source - */ -typedef enum -{ - CRM_CLOCK_SOURCE_HICK = 0x00, /*!< high speed internal clock */ - CRM_CLOCK_SOURCE_HEXT = 0x01, /*!< high speed external crystal */ - CRM_CLOCK_SOURCE_PLL = 0x02, /*!< phase locking loop */ - CRM_CLOCK_SOURCE_LEXT = 0x03, /*!< low speed external crystal */ - CRM_CLOCK_SOURCE_LICK = 0x04 /*!< low speed internal clock */ -} crm_clock_source_type; - -/** - * @brief crm ahb division - */ -typedef enum -{ - CRM_AHB_DIV_1 = 0x00, /*!< sclk div1 to ahbclk */ - CRM_AHB_DIV_2 = 0x08, /*!< sclk div2 to ahbclk */ - CRM_AHB_DIV_4 = 0x09, /*!< sclk div4 to ahbclk */ - CRM_AHB_DIV_8 = 0x0A, /*!< sclk div8 to ahbclk */ - CRM_AHB_DIV_16 = 0x0B, /*!< sclk div16 to ahbclk */ - CRM_AHB_DIV_64 = 0x0C, /*!< sclk div64 to ahbclk */ - CRM_AHB_DIV_128 = 0x0D, /*!< sclk div128 to ahbclk */ - CRM_AHB_DIV_256 = 0x0E, /*!< sclk div256 to ahbclk */ - CRM_AHB_DIV_512 = 0x0F /*!< sclk div512 to ahbclk */ -} crm_ahb_div_type; - -/** - * @brief crm apb1 division - */ -typedef enum -{ - CRM_APB1_DIV_1 = 0x00, /*!< ahbclk div1 to apb1clk */ - CRM_APB1_DIV_2 = 0x04, /*!< ahbclk div2 to apb1clk */ - CRM_APB1_DIV_4 = 0x05, /*!< ahbclk div4 to apb1clk */ - CRM_APB1_DIV_8 = 0x06, /*!< ahbclk div8 to apb1clk */ - CRM_APB1_DIV_16 = 0x07 /*!< ahbclk div16 to apb1clk */ -} crm_apb1_div_type; - -/** - * @brief crm apb2 division - */ -typedef enum -{ - CRM_APB2_DIV_1 = 0x00, /*!< ahbclk div1 to apb2clk */ - CRM_APB2_DIV_2 = 0x04, /*!< ahbclk div2 to apb2clk */ - CRM_APB2_DIV_4 = 0x05, /*!< ahbclk div4 to apb2clk */ - CRM_APB2_DIV_8 = 0x06, /*!< ahbclk div8 to apb2clk */ - CRM_APB2_DIV_16 = 0x07 /*!< ahbclk div16 to apb2clk */ -} crm_apb2_div_type; - -/** - * @brief crm usb division - */ -typedef enum -{ - CRM_USB_DIV_1_5 = 0x00, /*!< pllclk div1.5 to usbclk */ - CRM_USB_DIV_1 = 0x01, /*!< pllclk div1 to usbclk */ - CRM_USB_DIV_2_5 = 0x02, /*!< pllclk div2.5 to usbclk */ - CRM_USB_DIV_2 = 0x03, /*!< pllclk div2 to usbclk */ - CRM_USB_DIV_3_5 = 0x04, /*!< pllclk div3.5 to usbclk */ - CRM_USB_DIV_3 = 0x05, /*!< pllclk div3 to usbclk */ - CRM_USB_DIV_4_5 = 0x06, /*!< pllclk div4.5 to usbclk */ - CRM_USB_DIV_4 = 0x07, /*!< pllclk div4 to usbclk */ - CRM_USB_DIV_5_5 = 0x08, /*!< pllclk div5.5 to usbclk */ - CRM_USB_DIV_5 = 0x09, /*!< pllclk div5 to usbclk */ - CRM_USB_DIV_6_5 = 0x0A, /*!< pllclk div6.5 to usbclk */ - CRM_USB_DIV_6 = 0x0B, /*!< pllclk div6 to usbclk */ - CRM_USB_DIV_7 = 0x0C /*!< pllclk div7 to usbclk */ -} crm_usb_div_type; - -/** - * @brief crm ertc clock - */ -typedef enum -{ - CRM_ERTC_CLOCK_NOCLK = 0x000, /*!< no clock as ertc clock source */ - CRM_ERTC_CLOCK_LEXT = 0x001, /*!< low speed external crystal as ertc clock source */ - CRM_ERTC_CLOCK_LICK = 0x002, /*!< low speed internal clock as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_2 = 0x023, /*!< high speed external crystal div2 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_3 = 0x033, /*!< high speed external crystal div3 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_4 = 0x043, /*!< high speed external crystal div4 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_5 = 0x053, /*!< high speed external crystal div5 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_6 = 0x063, /*!< high speed external crystal div6 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_7 = 0x073, /*!< high speed external crystal div7 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_8 = 0x083, /*!< high speed external crystal div8 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_9 = 0x093, /*!< high speed external crystal div9 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_10 = 0x0A3, /*!< high speed external crystal div10 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_11 = 0x0B3, /*!< high speed external crystal div11 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_12 = 0x0C3, /*!< high speed external crystal div12 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_13 = 0x0D3, /*!< high speed external crystal div13 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_14 = 0x0E3, /*!< high speed external crystal div14 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_15 = 0x0F3, /*!< high speed external crystal div15 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_16 = 0x103, /*!< high speed external crystal div16 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_17 = 0x113, /*!< high speed external crystal div17 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_18 = 0x123, /*!< high speed external crystal div18 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_19 = 0x133, /*!< high speed external crystal div19 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_20 = 0x143, /*!< high speed external crystal div20 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_21 = 0x153, /*!< high speed external crystal div21 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_22 = 0x163, /*!< high speed external crystal div22 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_23 = 0x173, /*!< high speed external crystal div23 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_24 = 0x183, /*!< high speed external crystal div24 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_25 = 0x193, /*!< high speed external crystal div25 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_26 = 0x1A3, /*!< high speed external crystal div26 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_27 = 0x1B3, /*!< high speed external crystal div27 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_28 = 0x1C3, /*!< high speed external crystal div28 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_29 = 0x1D3, /*!< high speed external crystal div29 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_30 = 0x1E3, /*!< high speed external crystal div30 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_31 = 0x1F3 /*!< high speed external crystal div31 as ertc clock source */ -} crm_ertc_clock_type; - -/** - * @brief crm hick 48mhz division - */ -typedef enum -{ - CRM_HICK48_DIV6 = 0x00, /*!< fixed 8 mhz when hick is selected as sclk */ - CRM_HICK48_NODIV = 0x01 /*!< 8 mhz or 48 mhz depend on hickdiv when hick is selected as sclk */ -} crm_hick_div_6_type; - -/** - * @brief crm sclk select - */ -typedef enum -{ - CRM_SCLK_HICK = 0x00, /*!< select high speed internal clock as sclk */ - CRM_SCLK_HEXT = 0x01, /*!< select high speed external crystal as sclk */ - CRM_SCLK_PLL = 0x02 /*!< select phase locking loop clock as sclk */ -} crm_sclk_type; - -/** - * @brief crm clkout index - */ -typedef enum -{ - CRM_CLKOUT_INDEX_1 = 0x00, /*!< clkout1 */ - CRM_CLKOUT_INDEX_2 = 0x01 /*!< clkout2 */ -} crm_clkout_index_type; - -/** - * @brief crm clkout1 select - */ -typedef enum -{ - CRM_CLKOUT1_HICK = 0x00, /*!< output high speed internal clock to clkout1 pin */ - CRM_CLKOUT1_LEXT = 0x01, /*!< output low speed external crystal to clkout1 pin */ - CRM_CLKOUT1_HEXT = 0x02, /*!< output high speed external crystal to clkout1 pin */ - CRM_CLKOUT1_PLL = 0x03 /*!< output phase locking loop clock to clkout1 pin */ -} crm_clkout1_select_type; - -/** - * @brief crm clkout2 select - */ -typedef enum -{ - CRM_CLKOUT2_SCLK = 0x00, /*!< output system clock to clkout2 pin */ - CRM_CLKOUT2_HEXT = 0x02, /*!< output high speed external crystal to clkout2 pin */ - CRM_CLKOUT2_PLL = 0x03, /*!< output phase locking loop clock to clkout2 pin */ - CRM_CLKOUT2_USB = 0x10, /*!< output usbclk to clkout2 pin */ - CRM_CLKOUT2_ADC = 0x11, /*!< output adcclk to clkout2 pin */ - CRM_CLKOUT2_HICK = 0x12, /*!< output high speed internal clock to clkout2 pin */ - CRM_CLKOUT2_LICK = 0x13, /*!< output low speed internal clock to clkout2 pin */ - CRM_CLKOUT2_LEXT = 0x14 /*!< output low speed external crystal to clkout2 pin */ -} crm_clkout2_select_type; - -/** - * @brief crm clkout division1 - */ -typedef enum -{ - CRM_CLKOUT_DIV1_1 = 0x00, /*!< clkout division1 div1 */ - CRM_CLKOUT_DIV1_2 = 0x04, /*!< clkout division1 div2 */ - CRM_CLKOUT_DIV1_3 = 0x05, /*!< clkout division1 div3 */ - CRM_CLKOUT_DIV1_4 = 0x06, /*!< clkout division1 div4 */ - CRM_CLKOUT_DIV1_5 = 0x07 /*!< clkout division1 div5 */ -} crm_clkout_div1_type; - -/** - * @brief crm clkout division2 - */ -typedef enum -{ - CRM_CLKOUT_DIV2_1 = 0x00, /*!< clkout division2 div1 */ - CRM_CLKOUT_DIV2_2 = 0x08, /*!< clkout division2 div2 */ - CRM_CLKOUT_DIV2_4 = 0x09, /*!< clkout division2 div4 */ - CRM_CLKOUT_DIV2_8 = 0x0A, /*!< clkout division2 div8 */ - CRM_CLKOUT_DIV2_16 = 0x0B, /*!< clkout division2 div16 */ - CRM_CLKOUT_DIV2_64 = 0x0C, /*!< clkout division2 div64 */ - CRM_CLKOUT_DIV2_128 = 0x0D, /*!< clkout division2 div128 */ - CRM_CLKOUT_DIV2_256 = 0x0E, /*!< clkout division2 div256 */ - CRM_CLKOUT_DIV2_512 = 0x0F /*!< clkout division2 div512 */ -} crm_clkout_div2_type; - -/** - * @brief crm auto step mode - */ -typedef enum -{ - CRM_AUTO_STEP_MODE_DISABLE = 0x00, /*!< disable auto step mode */ - CRM_AUTO_STEP_MODE_ENABLE = 0x03 /*!< enable auto step mode */ -} crm_auto_step_mode_type; - -/** - * @brief crm usb 48 mhz clock source select - */ -typedef enum -{ - CRM_USB_CLOCK_SOURCE_PLL = 0x00, /*!< select phase locking loop clock as usb clock source */ - CRM_USB_CLOCK_SOURCE_HICK = 0x01 /*!< select high speed internal clock as usb clock source */ -} crm_usb_clock_source_type; - -/** - * @brief crm hick as system clock frequency select - */ -typedef enum -{ - CRM_HICK_SCLK_8MHZ = 0x00, /*!< fixed 8 mhz when hick is selected as sclk */ - CRM_HICK_SCLK_48MHZ = 0x01 /*!< 8 mhz or 48 mhz depend on hickdiv when hick is selected as sclk */ -} crm_hick_sclk_frequency_type; - -/** - * @brief crm emac output pulse width - */ -typedef enum -{ - CRM_EMAC_PULSE_125MS = 0x00, /*!< emac output pulse width 125ms */ - CRM_EMAC_PULSE_1SCLK = 0x01 /*!< emac output pulse width 1 system clock */ -} crm_emac_output_pulse_type; - -/** - * @brief crm clocks freqency structure - */ -typedef struct -{ - uint32_t sclk_freq; /*!< system clock frequency */ - uint32_t ahb_freq; /*!< ahb bus clock frequency */ - uint32_t apb2_freq; /*!< apb2 bus clock frequency */ - uint32_t apb1_freq; /*!< apb1 bus clock frequency */ -} crm_clocks_freq_type; - -/** - * @brief type define crm register all - */ -typedef struct -{ - /** - * @brief crm ctrl register, offset:0x00 - */ - union - { - __IO uint32_t ctrl; - struct - { - __IO uint32_t hicken : 1; /* [0] */ - __IO uint32_t hickstbl : 1; /* [1] */ - __IO uint32_t hicktrim : 6; /* [7:2] */ - __IO uint32_t hickcal : 8; /* [15:8] */ - __IO uint32_t hexten : 1; /* [16] */ - __IO uint32_t hextstbl : 1; /* [17] */ - __IO uint32_t hextbyps : 1; /* [18] */ - __IO uint32_t cfden : 1; /* [19] */ - __IO uint32_t reserved1 : 4; /* [23:20] */ - __IO uint32_t pllen : 1; /* [24] */ - __IO uint32_t pllstbl : 1; /* [25] */ - __IO uint32_t reserved2 : 6; /* [31:26] */ - } ctrl_bit; - }; - - /** - * @brief crm pllcfg register, offset:0x04 - */ - union - { - __IO uint32_t pllcfg; - struct - { - __IO uint32_t pllms : 4; /* [3:0] */ - __IO uint32_t reserved1 : 2; /* [5:4] */ - __IO uint32_t pllns : 9; /* [14:6] */ - __IO uint32_t reserved2 : 1; /* [15] */ - __IO uint32_t pllfr : 3; /* [18:16] */ - __IO uint32_t reserved3 : 3; /* [21:19] */ - __IO uint32_t pllrcs : 1; /* [22] */ - __IO uint32_t reserved4 : 9; /* [31:23] */ - } pllcfg_bit; - }; - - /** - * @brief crm cfg register, offset:0x08 - */ - union - { - __IO uint32_t cfg; - struct - { - __IO uint32_t sclksel : 2; /* [1:0] */ - __IO uint32_t sclksts : 2; /* [3:2] */ - __IO uint32_t ahbdiv : 4; /* [7:4] */ - __IO uint32_t reserved1 : 2; /* [9:8] */ - __IO uint32_t apb1div : 3; /* [12:10] */ - __IO uint32_t apb2div : 3; /* [15:13] */ - __IO uint32_t ertcdiv : 5; /* [20:16] */ - __IO uint32_t clkout1_sel : 2; /* [22:21] */ - __IO uint32_t reserved2 : 1; /* [23] */ - __IO uint32_t clkout1div1 : 3; /* [26:24] */ - __IO uint32_t clkout2div1 : 3; /* [29:27] */ - __IO uint32_t clkout2_sel1 : 2; /* [31:30] */ - } cfg_bit; - }; - - /** - * @brief crm clkint register, offset:0x0C - */ - union - { - __IO uint32_t clkint; - struct - { - __IO uint32_t lickstblf : 1; /* [0] */ - __IO uint32_t lextstblf : 1; /* [1] */ - __IO uint32_t hickstblf : 1; /* [2] */ - __IO uint32_t hextstblf : 1; /* [3] */ - __IO uint32_t pllstblf : 1; /* [4] */ - __IO uint32_t reserved1 : 2; /* [6:5] */ - __IO uint32_t cfdf : 1; /* [7] */ - __IO uint32_t lickstblien : 1; /* [8] */ - __IO uint32_t lextstblien : 1; /* [9] */ - __IO uint32_t hickstblien : 1; /* [10] */ - __IO uint32_t hextstblien : 1; /* [11] */ - __IO uint32_t pllstblien : 1; /* [12] */ - __IO uint32_t reserved2 : 3; /* [15:13] */ - __IO uint32_t lickstblfc : 1; /* [16] */ - __IO uint32_t lextstblfc : 1; /* [17] */ - __IO uint32_t hickstblfc : 1; /* [18] */ - __IO uint32_t hextstblfc : 1; /* [19] */ - __IO uint32_t pllstblfc : 1; /* [20] */ - __IO uint32_t reserved3 : 2; /* [22:21] */ - __IO uint32_t cfdfc : 1; /* [23] */ - __IO uint32_t reserved4 : 8; /* [31:24] */ - } clkint_bit; - }; - - /** - * @brief crm ahbrst1 register, offset:0x10 - */ - union - { - __IO uint32_t ahbrst1; -#if defined (AT32F435xx) - struct - { - __IO uint32_t gpioarst : 1; /* [0] */ - __IO uint32_t gpiobrst : 1; /* [1] */ - __IO uint32_t gpiocrst : 1; /* [2] */ - __IO uint32_t gpiodrst : 1; /* [3] */ - __IO uint32_t gpioerst : 1; /* [4] */ - __IO uint32_t gpiofrst : 1; /* [5] */ - __IO uint32_t gpiogrst : 1; /* [6] */ - __IO uint32_t gpiohrst : 1; /* [7] */ - __IO uint32_t reserved1 : 4; /* [11:8] */ - __IO uint32_t crcrst : 1; /* [12] */ - __IO uint32_t reserved2 : 8; /* [20:13] */ - __IO uint32_t edmarst : 1; /* [21] */ - __IO uint32_t dma1rst : 1; /* [22] */ - __IO uint32_t reserved3 : 1; /* [23] */ - __IO uint32_t dma2rst : 1; /* [24] */ - __IO uint32_t reserved4 : 4; /* [28:25] */ - __IO uint32_t otgfs2rst : 1; /* [29] */ - __IO uint32_t reserved5 : 2; /* [31:30] */ - } ahbrst1_bit; -#endif - -#if defined (AT32F437xx) - struct - { - __IO uint32_t gpioarst : 1; /* [0] */ - __IO uint32_t gpiobrst : 1; /* [1] */ - __IO uint32_t gpiocrst : 1; /* [2] */ - __IO uint32_t gpiodrst : 1; /* [3] */ - __IO uint32_t gpioerst : 1; /* [4] */ - __IO uint32_t gpiofrst : 1; /* [5] */ - __IO uint32_t gpiogrst : 1; /* [6] */ - __IO uint32_t gpiohrst : 1; /* [7] */ - __IO uint32_t reserved1 : 4; /* [11:8] */ - __IO uint32_t crcrst : 1; /* [12] */ - __IO uint32_t reserved2 : 8; /* [20:13] */ - __IO uint32_t edmarst : 1; /* [21] */ - __IO uint32_t dma1rst : 1; /* [22] */ - __IO uint32_t reserved3 : 1; /* [23] */ - __IO uint32_t dma2rst : 1; /* [24] */ - __IO uint32_t emacrst : 1; /* [25] */ - __IO uint32_t reserved4 : 3; /* [28:26] */ - __IO uint32_t otgfs2rst : 1; /* [29] */ - __IO uint32_t reserved5 : 2; /* [31:30] */ - } ahbrst1_bit; -#endif - }; - - /** - * @brief crm ahbrst2 register, offset:0x14 - */ - union - { - __IO uint32_t ahbrst2; - struct - { - __IO uint32_t dvprst : 1; /* [0] */ - __IO uint32_t reserved1 : 6; /* [6:1] */ - __IO uint32_t otgfs1rst : 1; /* [7] */ - __IO uint32_t reserved2 : 7; /* [14:8] */ - __IO uint32_t sdio1rst : 1; /* [15] */ - __IO uint32_t reserved3 : 16;/* [31:16] */ - } ahbrst2_bit; - }; - - /** - * @brief crm ahbrst3 register, offset:0x18 - */ - union - { - __IO uint32_t ahbrst3; - struct - { - __IO uint32_t xmcrst : 1; /* [0] */ - __IO uint32_t qspi1rst : 1; /* [1] */ - __IO uint32_t reserved1 : 12;/* [13:2] */ - __IO uint32_t qspi2rst : 1; /* [14] */ - __IO uint32_t sdio2rst : 1; /* [15] */ - __IO uint32_t reserved3 : 16;/* [31:16] */ - } ahbrst3_bit; - }; - - /** - * @brief crm reserved1 register, offset:0x1C - */ - __IO uint32_t reserved1; - - /** - * @brief crm apb1rst register, offset:0x20 - */ - union - { - __IO uint32_t apb1rst; - struct - { - __IO uint32_t tmr2rst : 1; /* [0] */ - __IO uint32_t tmr3rst : 1; /* [1] */ - __IO uint32_t tmr4rst : 1; /* [2] */ - __IO uint32_t tmr5rst : 1; /* [3] */ - __IO uint32_t tmr6rst : 1; /* [4] */ - __IO uint32_t tmr7rst : 1; /* [5] */ - __IO uint32_t tmr12rst : 1; /* [6] */ - __IO uint32_t tmr13rst : 1; /* [7] */ - __IO uint32_t adc14rst : 1; /* [8] */ - __IO uint32_t reserved1 : 2; /* [10:9] */ - __IO uint32_t wwdtrst : 1; /* [11] */ - __IO uint32_t reserved2 : 2; /* [13:12] */ - __IO uint32_t spi2rst : 1; /* [14] */ - __IO uint32_t spi3rst : 1; /* [15] */ - __IO uint32_t reserved3 : 1; /* [16] */ - __IO uint32_t usart2rst : 1; /* [17] */ - __IO uint32_t usart3rst : 1; /* [18] */ - __IO uint32_t uart4rst : 1; /* [19] */ - __IO uint32_t uart5rst : 1; /* [20] */ - __IO uint32_t i2c1rst : 1; /* [21] */ - __IO uint32_t i2c2rst : 1; /* [22] */ - __IO uint32_t i2c3rst : 1; /* [23] */ - __IO uint32_t reserved4 : 1; /* [24] */ - __IO uint32_t can1rst : 1; /* [25] */ - __IO uint32_t can2rst : 1; /* [26] */ - __IO uint32_t reserved5 : 1; /* [27] */ - __IO uint32_t pwcrst : 1; /* [28] */ - __IO uint32_t dacrst : 1; /* [29] */ - __IO uint32_t uart7rst : 1; /* [30] */ - __IO uint32_t uart8rst : 1; /* [31] */ - } apb1rst_bit; - }; - - /** - * @brief crm apb2rst register, offset:0x24 - */ - union - { - __IO uint32_t apb2rst; - struct - { - __IO uint32_t tmr1rst : 1; /* [0] */ - __IO uint32_t tmr8rst : 1; /* [1] */ - __IO uint32_t reserved1 : 2; /* [3:2] */ - __IO uint32_t usart1rst : 1; /* [4] */ - __IO uint32_t usart6rst : 1; /* [5] */ - __IO uint32_t reserved2 : 2; /* [7:6] */ - __IO uint32_t adcrst : 1; /* [8] */ - __IO uint32_t reserved3 : 3; /* [11:9] */ - __IO uint32_t spi1rst : 1; /* [12] */ - __IO uint32_t spi4rst : 1; /* [13] */ - __IO uint32_t scfgrst : 1; /* [14] */ - __IO uint32_t reserved4 : 1; /* [15] */ - __IO uint32_t tmr9rst : 1; /* [16] */ - __IO uint32_t tmr10rst : 1; /* [17] */ - __IO uint32_t tmr11rst : 1; /* [18] */ - __IO uint32_t reserved5 : 1; /* [19] */ - __IO uint32_t tmr20rst : 1; /* [20] */ - __IO uint32_t reserved6 : 8; /* [28:21] */ - __IO uint32_t accrst : 1; /* [29] */ - __IO uint32_t reserved7 : 2; /* [31:30] */ - } apb2rst_bit; - }; - - /** - * @brief crm reserved2 register, offset:0x28~0x2C - */ - __IO uint32_t reserved2[2]; - - /** - * @brief crm ahben1 register, offset:0x30 - */ - union - { - __IO uint32_t ahben1; -#if defined (AT32F435xx) - struct - { - __IO uint32_t gpioaen : 1; /* [0] */ - __IO uint32_t gpioben : 1; /* [1] */ - __IO uint32_t gpiocen : 1; /* [2] */ - __IO uint32_t gpioden : 1; /* [3] */ - __IO uint32_t gpioeen : 1; /* [4] */ - __IO uint32_t gpiofen : 1; /* [5] */ - __IO uint32_t gpiogen : 1; /* [6] */ - __IO uint32_t gpiohen : 1; /* [7] */ - __IO uint32_t reserved1 : 4; /* [11:8] */ - __IO uint32_t crcen : 1; /* [12] */ - __IO uint32_t reserved2 : 8; /* [20:13] */ - __IO uint32_t edmaen : 1; /* [21] */ - __IO uint32_t dma1en : 1; /* [22] */ - __IO uint32_t reserved3 : 1; /* [23] */ - __IO uint32_t dma2en : 1; /* [24] */ - __IO uint32_t reserved4 : 4; /* [28:25] */ - __IO uint32_t otgfs2en : 1; /* [29] */ - __IO uint32_t reserved5 : 2; /* [31:30] */ - } ahben1_bit; -#endif - -#if defined (AT32F437xx) - struct - { - __IO uint32_t gpioaen : 1; /* [0] */ - __IO uint32_t gpioben : 1; /* [1] */ - __IO uint32_t gpiocen : 1; /* [2] */ - __IO uint32_t gpioden : 1; /* [3] */ - __IO uint32_t gpioeen : 1; /* [4] */ - __IO uint32_t gpiofen : 1; /* [5] */ - __IO uint32_t gpiogen : 1; /* [6] */ - __IO uint32_t gpiohen : 1; /* [7] */ - __IO uint32_t reserved1 : 4; /* [11:8] */ - __IO uint32_t crcen : 1; /* [12] */ - __IO uint32_t reserved2 : 8; /* [20:13] */ - __IO uint32_t edmaen : 1; /* [21] */ - __IO uint32_t dma1en : 1; /* [22] */ - __IO uint32_t reserved3 : 1; /* [23] */ - __IO uint32_t dma2en : 1; /* [24] */ - __IO uint32_t emacen : 1; /* [25] */ - __IO uint32_t reserved4 : 3; /* [28:26] */ - __IO uint32_t otgfs2en : 1; /* [29] */ - __IO uint32_t reserved5 : 2; /* [31:30] */ - } ahben1_bit; -#endif - }; - - /** - * @brief crm ahben2 register, offset:0x34 - */ - union - { - __IO uint32_t ahben2; - struct - { - __IO uint32_t dvpen : 1; /* [0] */ - __IO uint32_t reserved1 : 6; /* [6:1] */ - __IO uint32_t otgfs1en : 1; /* [7] */ - __IO uint32_t reserved2 : 7; /* [14:8] */ - __IO uint32_t sdio1en : 1; /* [15] */ - __IO uint32_t reserved3 : 16;/* [31:16] */ - } ahben2_bit; - }; - - /** - * @brief crm ahben3 register, offset:0x38 - */ - union - { - __IO uint32_t ahben3; - struct - { - __IO uint32_t xmcen : 1; /* [0] */ - __IO uint32_t qspi1en : 1; /* [1] */ - __IO uint32_t reserved1 : 12;/* [13:2] */ - __IO uint32_t qspi2en : 1; /* [14] */ - __IO uint32_t sdio2en : 1; /* [15] */ - __IO uint32_t reserved3 : 16;/* [31:16] */ - } ahben3_bit; - }; - - /** - * @brief crm reserved3 register, offset:0x3C - */ - __IO uint32_t reserved3; - - /** - * @brief crm apb1en register, offset:0x40 - */ - union - { - __IO uint32_t apb1en; - struct - { - __IO uint32_t tmr2en : 1; /* [0] */ - __IO uint32_t tmr3en : 1; /* [1] */ - __IO uint32_t tmr4en : 1; /* [2] */ - __IO uint32_t tmr5en : 1; /* [3] */ - __IO uint32_t tmr6en : 1; /* [4] */ - __IO uint32_t tmr7en : 1; /* [5] */ - __IO uint32_t tmr12en : 1; /* [6] */ - __IO uint32_t tmr13en : 1; /* [7] */ - __IO uint32_t adc14en : 1; /* [8] */ - __IO uint32_t reserved1 : 2; /* [10:9] */ - __IO uint32_t wwdten : 1; /* [11] */ - __IO uint32_t reserved2 : 2; /* [13:12] */ - __IO uint32_t spi2en : 1; /* [14] */ - __IO uint32_t spi3en : 1; /* [15] */ - __IO uint32_t reserved3 : 1; /* [16] */ - __IO uint32_t usart2en : 1; /* [17] */ - __IO uint32_t usart3en : 1; /* [18] */ - __IO uint32_t uart4en : 1; /* [19] */ - __IO uint32_t uart5en : 1; /* [20] */ - __IO uint32_t i2c1en : 1; /* [21] */ - __IO uint32_t i2c2en : 1; /* [22] */ - __IO uint32_t i2c3en : 1; /* [23] */ - __IO uint32_t reserved4 : 1; /* [24] */ - __IO uint32_t can1en : 1; /* [25] */ - __IO uint32_t can2en : 1; /* [26] */ - __IO uint32_t reserved5 : 1; /* [27] */ - __IO uint32_t pwcen : 1; /* [28] */ - __IO uint32_t dacen : 1; /* [29] */ - __IO uint32_t uart7en : 1; /* [30] */ - __IO uint32_t uart8en : 1; /* [31] */ - } apb1en_bit; - }; - - /** - * @brief crm apb2en register, offset:0x44 - */ - union - { - __IO uint32_t apb2en; - struct - { - __IO uint32_t tmr1en : 1; /* [0] */ - __IO uint32_t tmr8en : 1; /* [1] */ - __IO uint32_t reserved1 : 2; /* [3:2] */ - __IO uint32_t usart1en : 1; /* [4] */ - __IO uint32_t usart6en : 1; /* [5] */ - __IO uint32_t reserved2 : 2; /* [7:6] */ - __IO uint32_t adcen : 1; /* [8] */ - __IO uint32_t reserved3 : 3; /* [11:9] */ - __IO uint32_t spi1en : 1; /* [12] */ - __IO uint32_t spi4en : 1; /* [13] */ - __IO uint32_t scfgen : 1; /* [14] */ - __IO uint32_t reserved4 : 1; /* [15] */ - __IO uint32_t tmr9en : 1; /* [16] */ - __IO uint32_t tmr10en : 1; /* [17] */ - __IO uint32_t tmr11en : 1; /* [18] */ - __IO uint32_t reserved5 : 1; /* [19] */ - __IO uint32_t tmr20en : 1; /* [20] */ - __IO uint32_t reserved6 : 8; /* [28:21] */ - __IO uint32_t accen : 1; /* [29] */ - __IO uint32_t reserved7 : 2; /* [31:30] */ - } apb2en_bit; - }; - - /** - * @brief crm reserved4 register, offset:0x48~0x4C - */ - __IO uint32_t reserved4[2]; - - /** - * @brief crm ahblpen1 register, offset:0x50 - */ - union - { - __IO uint32_t ahblpen1; -#if defined (AT32F435xx) - struct - { - __IO uint32_t gpioalpen : 1; /* [0] */ - __IO uint32_t gpioblpen : 1; /* [1] */ - __IO uint32_t gpioclpen : 1; /* [2] */ - __IO uint32_t gpiodlpen : 1; /* [3] */ - __IO uint32_t gpioelpen : 1; /* [4] */ - __IO uint32_t gpioflpen : 1; /* [5] */ - __IO uint32_t gpioglpen : 1; /* [6] */ - __IO uint32_t gpiohlpen : 1; /* [7] */ - __IO uint32_t reserved1 : 4; /* [11:8] */ - __IO uint32_t crclpen : 1; /* [12] */ - __IO uint32_t reserved2 : 8; /* [20:13] */ - __IO uint32_t edmalpen : 1; /* [21] */ - __IO uint32_t dma1lpen : 1; /* [22] */ - __IO uint32_t reserved3 : 1; /* [23] */ - __IO uint32_t dma2lpen : 1; /* [24] */ - __IO uint32_t reserved4 : 4; /* [28:25] */ - __IO uint32_t otgfs2lpen : 1; /* [29] */ - __IO uint32_t reserved5 : 2; /* [31:30] */ - } ahblpen1_bit; -#endif - -#if defined (AT32F437xx) - struct - { - __IO uint32_t gpioalpen : 1; /* [0] */ - __IO uint32_t gpioblpen : 1; /* [1] */ - __IO uint32_t gpioclpen : 1; /* [2] */ - __IO uint32_t gpiodlpen : 1; /* [3] */ - __IO uint32_t gpioelpen : 1; /* [4] */ - __IO uint32_t gpioflpen : 1; /* [5] */ - __IO uint32_t gpioglpen : 1; /* [6] */ - __IO uint32_t gpiohlpen : 1; /* [7] */ - __IO uint32_t reserved1 : 4; /* [11:8] */ - __IO uint32_t crclpen : 1; /* [12] */ - __IO uint32_t reserved2 : 8; /* [20:13] */ - __IO uint32_t edmalpen : 1; /* [21] */ - __IO uint32_t dma1lpen : 1; /* [22] */ - __IO uint32_t reserved3 : 1; /* [23] */ - __IO uint32_t dma2lpen : 1; /* [24] */ - __IO uint32_t emaclpen : 1; /* [25] */ - __IO uint32_t reserved4 : 3; /* [28:26] */ - __IO uint32_t otgfs2lpen : 1; /* [29] */ - __IO uint32_t reserved5 : 2; /* [31:30] */ - } ahblpen1_bit; -#endif - }; - - /** - * @brief crm ahblpen2 register, offset:0x54 - */ - union - { - __IO uint32_t ahblpen2; - struct - { - __IO uint32_t dvplpen : 1; /* [0] */ - __IO uint32_t reserved1 : 6; /* [6:1] */ - __IO uint32_t otgfs1lpen : 1; /* [7] */ - __IO uint32_t reserved2 : 7; /* [14:8] */ - __IO uint32_t sdio1lpen : 1; /* [15] */ - __IO uint32_t reserved3 : 16;/* [31:16] */ - } ahblpen2_bit; - }; - - /** - * @brief crm ahblpen3 register, offset:0x58 - */ - union - { - __IO uint32_t ahblpen3; - struct - { - __IO uint32_t xmclpen : 1; /* [0] */ - __IO uint32_t qspi1lpen : 1; /* [1] */ - __IO uint32_t reserved1 : 12;/* [13:2] */ - __IO uint32_t qspi2lpen : 1; /* [14] */ - __IO uint32_t sdio2lpen : 1; /* [15] */ - __IO uint32_t reserved3 : 16;/* [31:16] */ - } ahblpen3_bit; - }; - - /** - * @brief crm reserved5 register, offset:0x5C - */ - __IO uint32_t reserved5; - - /** - * @brief crm apb1lpen register, offset:0x60 - */ - union - { - __IO uint32_t apb1lpen; - struct - { - __IO uint32_t tmr2lpen : 1; /* [0] */ - __IO uint32_t tmr3lpen : 1; /* [1] */ - __IO uint32_t tmr4lpen : 1; /* [2] */ - __IO uint32_t tmr5lpen : 1; /* [3] */ - __IO uint32_t tmr6lpen : 1; /* [4] */ - __IO uint32_t tmr7lpen : 1; /* [5] */ - __IO uint32_t tmr12lpen : 1; /* [6] */ - __IO uint32_t tmr13lpen : 1; /* [7] */ - __IO uint32_t adc14lpen : 1; /* [8] */ - __IO uint32_t reserved1 : 2; /* [10:9] */ - __IO uint32_t wwdtlpen : 1; /* [11] */ - __IO uint32_t reserved2 : 2; /* [13:12] */ - __IO uint32_t spi2lpen : 1; /* [14] */ - __IO uint32_t spi3lpen : 1; /* [15] */ - __IO uint32_t reserved3 : 1; /* [16] */ - __IO uint32_t usart2lpen : 1; /* [17] */ - __IO uint32_t usart3lpen : 1; /* [18] */ - __IO uint32_t uart4lpen : 1; /* [19] */ - __IO uint32_t uart5lpen : 1; /* [20] */ - __IO uint32_t i2c1lpen : 1; /* [21] */ - __IO uint32_t i2c2lpen : 1; /* [22] */ - __IO uint32_t i2c3lpen : 1; /* [23] */ - __IO uint32_t reserved4 : 1; /* [24] */ - __IO uint32_t can1lpen : 1; /* [25] */ - __IO uint32_t can2lpen : 1; /* [26] */ - __IO uint32_t reserved5 : 1; /* [27] */ - __IO uint32_t pwclpen : 1; /* [28] */ - __IO uint32_t daclpen : 1; /* [29] */ - __IO uint32_t uart7lpen : 1; /* [30] */ - __IO uint32_t uart8lpen : 1; /* [31] */ - } apb1lpen_bit; - }; - - /** - * @brief crm apb2lpen register, offset:0x64 - */ - union - { - __IO uint32_t apb2lpen; - struct - { - __IO uint32_t tmr1lpen : 1; /* [0] */ - __IO uint32_t tmr8lpen : 1; /* [1] */ - __IO uint32_t reserved1 : 2; /* [3:2] */ - __IO uint32_t usart1lpen : 1; /* [4] */ - __IO uint32_t usart6lpen : 1; /* [5] */ - __IO uint32_t reserved2 : 2; /* [7:6] */ - __IO uint32_t adclpen : 1; /* [8] */ - __IO uint32_t reserved3 : 3; /* [11:9] */ - __IO uint32_t spi1lpen : 1; /* [12] */ - __IO uint32_t spi4lpen : 1; /* [13] */ - __IO uint32_t scfglpen : 1; /* [14] */ - __IO uint32_t reserved4 : 1; /* [15] */ - __IO uint32_t tmr9lpen : 1; /* [16] */ - __IO uint32_t tmr10lpen : 1; /* [17] */ - __IO uint32_t tmr11lpen : 1; /* [18] */ - __IO uint32_t reserved5 : 1; /* [19] */ - __IO uint32_t tmr20lpen : 1; /* [20] */ - __IO uint32_t reserved6 : 8; /* [28:21] */ - __IO uint32_t acclpen : 1; /* [29] */ - __IO uint32_t reserved7 : 2; /* [31:30] */ - } apb2lpen_bit; - }; - - /** - * @brief crm reserved6 register, offset:0x68~0x6C - */ - __IO uint32_t reserved6[2]; - - /** - * @brief crm bpdc register, offset:0x70 - */ - union - { - __IO uint32_t bpdc; - struct - { - __IO uint32_t lexten : 1; /* [0] */ - __IO uint32_t lextstbl : 1; /* [1] */ - __IO uint32_t lextbyps : 1; /* [2] */ - __IO uint32_t reserved1 : 5; /* [7:3] */ - __IO uint32_t ertcsel : 2; /* [9:8] */ - __IO uint32_t reserved2 : 5; /* [14:10] */ - __IO uint32_t ertcen : 1; /* [15] */ - __IO uint32_t bpdrst : 1; /* [16] */ - __IO uint32_t reserved3 : 15;/* [31:17] */ - } bpdc_bit; - }; - - /** - * @brief crm ctrlsts register, offset:0x74 - */ - union - { - __IO uint32_t ctrlsts; - struct - { - __IO uint32_t licken : 1; /* [0] */ - __IO uint32_t lickstbl : 1; /* [1] */ - __IO uint32_t reserved1 : 22;/* [23:2] */ - __IO uint32_t rstfc : 1; /* [24] */ - __IO uint32_t reserved2 : 1; /* [25] */ - __IO uint32_t nrstf : 1; /* [26] */ - __IO uint32_t porrstf : 1; /* [27] */ - __IO uint32_t swrstf : 1; /* [28] */ - __IO uint32_t wdtrstf : 1; /* [29] */ - __IO uint32_t wwdtrstf : 1; /* [30] */ - __IO uint32_t lprstf : 1; /* [31] */ - } ctrlsts_bit; - }; - - /** - * @brief crm reserved7 register, offset:0x78~0x9C - */ - __IO uint32_t reserved7[10]; - - /** - * @brief crm misc1 register, offset:0xA0 - */ - union - { - __IO uint32_t misc1; - struct - { - __IO uint32_t hickcal_key : 8; /* [7:0] */ - __IO uint32_t reserved1 : 4; /* [11:8] */ - __IO uint32_t hickdiv : 1; /* [12] */ - __IO uint32_t hick_to_usb : 1; /* [13] */ - __IO uint32_t hick_to_sclk : 1; /* [14] */ - __IO uint32_t reserved2 : 1; /* [15] */ - __IO uint32_t clkout2_sel2 : 4; /* [19:16] */ - __IO uint32_t reserved3 : 4; /* [23:20] */ - __IO uint32_t clkout1div2 : 4; /* [27:24] */ - __IO uint32_t clkout2div2 : 4; /* [31:28] */ - } misc1_bit; - }; - - /** - * @brief crm misc2 register, offset:0xA4 - */ - union - { - __IO uint32_t misc2; - struct - { - __IO uint32_t reserved1 : 4; /* [3:0] */ - __IO uint32_t auto_step_en : 2; /* [5:4] */ - __IO uint32_t reserved2 : 2; /* [7:6] */ - __IO uint32_t clk_to_tmr : 1; /* [8] */ - __IO uint32_t emac_pps_sel : 1; /* [9] */ - __IO uint32_t reserved3 : 2; /* [11:10] */ - __IO uint32_t usbdiv : 4; /* [15:12] */ - __IO uint32_t reserved4 : 16;/* [31:16] */ - } misc2_bit; - }; - -} crm_type; - -/** - * @} - */ - -#define CRM ((crm_type *) CRM_BASE) - -/** @defgroup CRM_exported_functions - * @{ - */ - -void crm_reset(void); -void crm_lext_bypass(confirm_state new_state); -void crm_hext_bypass(confirm_state new_state); -flag_status crm_flag_get(uint32_t flag); -error_status crm_hext_stable_wait(void); -void crm_hick_clock_trimming_set(uint8_t trim_value); -void crm_hick_clock_calibration_set(uint8_t cali_value); -void crm_periph_clock_enable(crm_periph_clock_type value, confirm_state new_state); -void crm_periph_reset(crm_periph_reset_type value, confirm_state new_state); -void crm_periph_lowpower_mode_enable(crm_periph_clock_lowpower_type value, confirm_state new_state); -void crm_clock_source_enable(crm_clock_source_type source, confirm_state new_state); -void crm_flag_clear(uint32_t flag); -void crm_ertc_clock_select(crm_ertc_clock_type value); -void crm_ertc_clock_enable(confirm_state new_state); -void crm_ahb_div_set(crm_ahb_div_type value); -void crm_apb1_div_set(crm_apb1_div_type value); -void crm_apb2_div_set(crm_apb2_div_type value); -void crm_usb_clock_div_set(crm_usb_div_type value); -void crm_clock_failure_detection_enable(confirm_state new_state); -void crm_battery_powered_domain_reset(confirm_state new_state); -void crm_auto_step_mode_enable(confirm_state new_state); -void crm_hick_divider_select(crm_hick_div_6_type value); -void crm_hick_sclk_frequency_select(crm_hick_sclk_frequency_type value); -void crm_usb_clock_source_select(crm_usb_clock_source_type value); -void crm_clkout_to_tmr10_enable(confirm_state new_state); -void crm_pll_config(crm_pll_clock_source_type clock_source, uint16_t pll_ns, \ - uint16_t pll_ms, crm_pll_fr_type pll_fr); -void crm_sysclk_switch(crm_sclk_type value); -crm_sclk_type crm_sysclk_switch_status_get(void); -void crm_clocks_freq_get(crm_clocks_freq_type *clocks_struct); -void crm_clock_out1_set(crm_clkout1_select_type clkout); -void crm_clock_out2_set(crm_clkout2_select_type clkout); -void crm_clkout_div_set(crm_clkout_index_type index, crm_clkout_div1_type div1, crm_clkout_div2_type div2); -void crm_emac_output_pulse_set(crm_emac_output_pulse_type width); -void crm_interrupt_enable(uint32_t crm_int, confirm_state new_state); -error_status crm_pll_parameter_calculate(crm_pll_clock_source_type pll_rcs, uint32_t target_sclk_freq, \ - uint16_t *ret_ms, uint16_t *ret_ns, uint16_t *ret_fr); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_dac.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_dac.h deleted file mode 100644 index a7ffee6..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_dac.h +++ /dev/null @@ -1,394 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_dac.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 dac header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_DAC_H -#define __AT32F435_437_DAC_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup DAC - * @{ - */ - -#define DAC1_D1DMAUDRF ((uint32_t)(0x00002000)) -#define DAC2_D2DMAUDRF ((uint32_t)(0x20000000)) - -/** @defgroup DAC_exported_types - * @{ - */ - -/** - * @brief dac select type - */ -typedef enum -{ - DAC1_SELECT = 0x01, /*!< dac1 select */ - DAC2_SELECT = 0x02 /*!< dac2 select */ -} dac_select_type; - -/** - * @brief dac trigger type - */ -typedef enum -{ - DAC_TMR6_TRGOUT_EVENT = 0x00, /*!< dac trigger selection:timer6 trgout event */ - DAC_TMR8_TRGOUT_EVENT = 0x01, /*!< dac trigger selection:timer8 trgout event */ - DAC_TMR7_TRGOUT_EVENT = 0x02, /*!< dac trigger selection:timer7 trgout event */ - DAC_TMR5_TRGOUT_EVENT = 0x03, /*!< dac trigger selection:timer5 trgout event */ - DAC_TMR2_TRGOUT_EVENT = 0x04, /*!< dac trigger selection:timer2 trgout event */ - DAC_TMR4_TRGOUT_EVENT = 0x05, /*!< dac trigger selection:timer4 trgout event */ - DAC_EXTERNAL_INTERRUPT_LINE_9 = 0x06, /*!< dac trigger selection:external line9 */ - DAC_SOFTWARE_TRIGGER = 0x07 /*!< dac trigger selection:software trigger */ -} dac_trigger_type; - -/** - * @brief dac wave type - */ -typedef enum -{ - DAC_WAVE_GENERATE_NONE = 0x00, /*!< dac wave generation disabled */ - DAC_WAVE_GENERATE_NOISE = 0x01, /*!< dac noise wave generation enabled */ - DAC_WAVE_GENERATE_TRIANGLE = 0x02 /*!< dac triangle wave generation enabled */ -} dac_wave_type; - -/** - * @brief dac mask amplitude type - */ -typedef enum -{ - DAC_LSFR_BIT0_AMPLITUDE_1 = 0x00, /*!< unmask bit0/ triangle amplitude equal to 1 */ - DAC_LSFR_BIT10_AMPLITUDE_3 = 0x01, /*!< unmask bit[1:0]/ triangle amplitude equal to 3 */ - DAC_LSFR_BIT20_AMPLITUDE_7 = 0x02, /*!< unmask bit[2:0]/ triangle amplitude equal to 7 */ - DAC_LSFR_BIT30_AMPLITUDE_15 = 0x03, /*!< unmask bit[3:0]/ triangle amplitude equal to 15 */ - DAC_LSFR_BIT40_AMPLITUDE_31 = 0x04, /*!< unmask bit[4:0]/ triangle amplitude equal to 31 */ - DAC_LSFR_BIT50_AMPLITUDE_63 = 0x05, /*!< unmask bit[5:0]/ triangle amplitude equal to 63 */ - DAC_LSFR_BIT60_AMPLITUDE_127 = 0x06, /*!< unmask bit[6:0]/ triangle amplitude equal to 127 */ - DAC_LSFR_BIT70_AMPLITUDE_255 = 0x07, /*!< unmask bit[7:0]/ triangle amplitude equal to 255 */ - DAC_LSFR_BIT80_AMPLITUDE_511 = 0x08, /*!< unmask bit[8:0]/ triangle amplitude equal to 511 */ - DAC_LSFR_BIT90_AMPLITUDE_1023 = 0x09, /*!< unmask bit[9:0]/ triangle amplitude equal to 1023 */ - DAC_LSFR_BITA0_AMPLITUDE_2047 = 0x0A, /*!< unmask bit[10:0]/ triangle amplitude equal to 2047 */ - DAC_LSFR_BITB0_AMPLITUDE_4095 = 0x0B /*!< unmask bit[11:0]/ triangle amplitude equal to 4095 */ -} dac_mask_amplitude_type; - -/** - * @brief dac1 aligned data type - */ -typedef enum -{ - DAC1_12BIT_RIGHT = 0x40007408, /*!< dac1 12-bit data right-aligned */ - DAC1_12BIT_LEFT = 0x4000740C, /*!< dac1 12-bit data left-aligned */ - DAC1_8BIT_RIGHT = 0x40007410 /*!< dac1 8-bit data right-aligned */ -} dac1_aligned_data_type; - -/** - * @brief dac2 aligned data type - */ -typedef enum -{ - DAC2_12BIT_RIGHT = 0x40007414, /*!< dac2 12-bit data right-aligned */ - DAC2_12BIT_LEFT = 0x40007418, /*!< dac2 12-bit data left-aligned */ - DAC2_8BIT_RIGHT = 0x4000741C /*!< dac2 8-bit data right-aligned */ -} dac2_aligned_data_type; - -/** - * @brief dac dual data type - */ -typedef enum -{ - DAC_DUAL_12BIT_RIGHT = 0x40007420, /*!divr_bit.fdiv = div) - -/** - * @} - */ - -/** @defgroup FLASH_exported_types - * @{ - */ - -/** - * @brief flash usd eopb0 type - */ -typedef enum -{ - FLASH_EOPB0_SRAM_512K = 0x00, /*!< sram 512k, flash zw area 128k */ - FLASH_EOPB0_SRAM_448K = 0x01, /*!< sram 448k, flash zw area 192k */ - FLASH_EOPB0_SRAM_384K = 0x02, /*!< sram 384k, flash zw area 256k */ - FLASH_EOPB0_SRAM_320K = 0x03, /*!< sram 320k, flash zw area 320k */ - FLASH_EOPB0_SRAM_256K = 0x04, /*!< sram 256k, flash zw area 384k */ - FLASH_EOPB0_SRAM_192K = 0x05, /*!< sram 192k, flash zw area 448k */ - FLASH_EOPB0_SRAM_128K = 0x06 /*!< sram 128k, flash zw area 512k */ -} flash_usd_eopb0_type; - -/** - * @brief flash clock divider type - */ -typedef enum -{ - FLASH_CLOCK_DIV_2 = 0x00, /*!< flash clock divide by 2 */ - FLASH_CLOCK_DIV_3 = 0x01, /*!< flash clock divide by 3 */ - FLASH_CLOCK_DIV_4 = 0x02 /*!< flash clock divide by 4 */ -} flash_clock_divider_type; - -/** - * @brief flash status type - */ -typedef enum -{ - FLASH_OPERATE_BUSY = 0x00, /*!< flash status is operate busy */ - FLASH_PROGRAM_ERROR = 0x01, /*!< flash status is program error */ - FLASH_EPP_ERROR = 0x02, /*!< flash status is epp error */ - FLASH_OPERATE_DONE = 0x03, /*!< flash status is operate done */ - FLASH_OPERATE_TIMEOUT = 0x04 /*!< flash status is operate timeout */ -} flash_status_type; - -/** - * @brief type define flash register all - */ -typedef struct -{ - /** - * @brief flash psr register, offset:0x00 - */ - union - { - __IO uint32_t psr; - struct - { - __IO uint32_t reserved1 : 12;/* [11:0] */ - __IO uint32_t nzw_bst : 1; /* [12] */ - __IO uint32_t nzw_bst_sts : 1; /* [13] */ - __IO uint32_t reserved2 : 18;/* [31:14] */ - } psr_bit; - }; - - /** - * @brief flash unlock register, offset:0x04 - */ - union - { - __IO uint32_t unlock; - struct - { - __IO uint32_t ukval : 32;/* [31:0] */ - } unlock_bit; - }; - - /** - * @brief flash usd unlock register, offset:0x08 - */ - union - { - __IO uint32_t usd_unlock; - struct - { - __IO uint32_t usd_ukval : 32;/* [31:0] */ - } usd_unlock_bit; - }; - - /** - * @brief flash sts register, offset:0x0C - */ - union - { - __IO uint32_t sts; - struct - { - __IO uint32_t obf : 1; /* [0] */ - __IO uint32_t reserved1 : 1; /* [1] */ - __IO uint32_t prgmerr : 1; /* [2] */ - __IO uint32_t reserved2 : 1; /* [3] */ - __IO uint32_t epperr : 1; /* [4] */ - __IO uint32_t odf : 1; /* [5] */ - __IO uint32_t reserved3 : 26;/* [31:6] */ - } sts_bit; - }; - - /** - * @brief flash ctrl register, offset:0x10 - */ - union - { - __IO uint32_t ctrl; - struct - { - __IO uint32_t fprgm : 1; /* [0] */ - __IO uint32_t secers : 1; /* [1] */ - __IO uint32_t bankers : 1; /* [2] */ - __IO uint32_t blkers : 1; /* [3] */ - __IO uint32_t usdprgm : 1; /* [4] */ - __IO uint32_t usders : 1; /* [5] */ - __IO uint32_t erstr : 1; /* [6] */ - __IO uint32_t oplk : 1; /* [7] */ - __IO uint32_t reserved1 : 1; /* [8] */ - __IO uint32_t usdulks : 1; /* [9] */ - __IO uint32_t errie : 1; /* [10] */ - __IO uint32_t reserved2 : 1; /* [11] */ - __IO uint32_t odfie : 1; /* [12] */ - __IO uint32_t reserved3 : 19;/* [31:13] */ - } ctrl_bit; - }; - - /** - * @brief flash addr register, offset:0x14 - */ - union - { - __IO uint32_t addr; - struct - { - __IO uint32_t fa : 32;/* [31:0] */ - } addr_bit; - }; - - /** - * @brief flash reserved1 register, offset:0x18 - */ - __IO uint32_t reserved1; - - /** - * @brief flash usd register, offset:0x1C - */ - union - { - __IO uint32_t usd; - struct - { - __IO uint32_t usderr : 1; /* [0] */ - __IO uint32_t fap : 1; /* [1] */ - __IO uint32_t wdt_ato_en : 1; /* [2] */ - __IO uint32_t depslp_rst : 1; /* [3] */ - __IO uint32_t stdby_rst : 1; /* [4] */ - __IO uint32_t btopt : 1; /* [5] */ - __IO uint32_t reserved1 : 1; /* [6] */ - __IO uint32_t wdt_depslp : 1; /* [7] */ - __IO uint32_t wdt_stdby : 1; /* [8] */ - __IO uint32_t reserved2 : 1; /* [9] */ - __IO uint32_t user_d0 : 8; /* [17:10] */ - __IO uint32_t user_d1 : 8; /* [25:18] */ - __IO uint32_t reserved3 : 6; /* [31:26] */ - } usd_bit; - }; - - /** - * @brief flash epps0 register, offset:0x20 - */ - union - { - __IO uint32_t epps0; - struct - { - __IO uint32_t epps : 32;/* [31:0] */ - } epps0_bit; - }; - - /** - * @brief flash reserved2 register, offset:0x28~0x24 - */ - __IO uint32_t reserved2[2]; - - /** - * @brief flash epps1 register, offset:0x2C - */ - union - { - __IO uint32_t epps1; - struct - { - __IO uint32_t epps : 32;/* [31:0] */ - } epps1_bit; - }; - - /** - * @brief flash reserved3 register, offset:0x40~0x30 - */ - __IO uint32_t reserved3[5]; - - /** - * @brief flash unlock2 register, offset:0x44 - */ - union - { - __IO uint32_t unlock2; - struct - { - __IO uint32_t ukval : 32;/* [31:0] */ - } unlock2_bit; - }; - - /** - * @brief flash reserved4 register, offset:0x48 - */ - __IO uint32_t reserved4; - - /** - * @brief flash sts2 register, offset:0x4C - */ - union - { - __IO uint32_t sts2; - struct - { - __IO uint32_t obf : 1; /* [0] */ - __IO uint32_t reserved1 : 1; /* [1] */ - __IO uint32_t prgmerr : 1; /* [2] */ - __IO uint32_t reserved2 : 1; /* [3] */ - __IO uint32_t epperr : 1; /* [4] */ - __IO uint32_t odf : 1; /* [5] */ - __IO uint32_t reserved3 : 26;/* [31:6] */ - } sts2_bit; - }; - - /** - * @brief flash ctrl2 register, offset:0x50 - */ - union - { - __IO uint32_t ctrl2; - struct - { - __IO uint32_t fprgm : 1; /* [0] */ - __IO uint32_t secers : 1; /* [1] */ - __IO uint32_t bankers : 1; /* [2] */ - __IO uint32_t blkers : 1; /* [3] */ - __IO uint32_t reserved1 : 2; /* [5:4] */ - __IO uint32_t erstr : 1; /* [6] */ - __IO uint32_t oplk : 1; /* [7] */ - __IO uint32_t reserved2 : 2; /* [9:8] */ - __IO uint32_t errie : 1; /* [10] */ - __IO uint32_t reserved3 : 1; /* [11] */ - __IO uint32_t odfie : 1; /* [12] */ - __IO uint32_t reserved4 : 19;/* [31:13] */ - } ctrl2_bit; - }; - - /** - * @brief flash addr2 register, offset:0x54 - */ - union - { - __IO uint32_t addr2; - struct - { - __IO uint32_t fa : 32;/* [31:0] */ - } addr2_bit; - }; - - /** - * @brief flash contr register, offset:0x58 - */ - union - { - __IO uint32_t contr; - struct - { - __IO uint32_t reserved1 : 31;/* [30:0] */ - __IO uint32_t fcontr_en : 1; /* [31] */ - } contr_bit; - }; - - /** - * @brief flash reserved5 register, offset:0x5C - */ - __IO uint32_t reserved5; - - /** - * @brief flash divr register, offset:0x60 - */ - union - { - __IO uint32_t divr; - struct - { - __IO uint32_t fdiv : 2; /* [1:0] */ - __IO uint32_t reserved1 : 2; /* [3:2] */ - __IO uint32_t fdiv_sts : 2; /* [5:4] */ - __IO uint32_t reserved2 : 26;/* [31:6] */ - } divr_bit; - }; - - /** - * @brief flash reserved6 register, offset:0xC4~0x64 - */ - __IO uint32_t reserved6[25]; - - /** - * @brief flash slib_sts2 register, offset:0xC8 - */ - union - { - __IO uint32_t slib_sts2; - struct - { - __IO uint32_t slib_inst_ss : 16;/* [15:0] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } slib_sts2_bit; - }; - - /** - * @brief flash slib_sts0 register, offset:0xCC - */ - union - { - __IO uint32_t slib_sts0; - struct - { - __IO uint32_t reserved1 : 3; /* [2:0] */ - __IO uint32_t slib_enf : 1; /* [3] */ - __IO uint32_t reserved2 : 28;/* [31:4] */ - } slib_sts0_bit; - }; - - /** - * @brief flash slib_sts1 register, offset:0xD0 - */ - union - { - __IO uint32_t slib_sts1; - struct - { - __IO uint32_t slib_ss : 16;/* [15:0] */ - __IO uint32_t slib_es : 16;/* [31:16] */ - } slib_sts1_bit; - }; - - /** - * @brief flash slib_pwd_clr register, offset:0xD4 - */ - union - { - __IO uint32_t slib_pwd_clr; - struct - { - __IO uint32_t slib_pclr_val : 32;/* [31:0] */ - } slib_pwd_clr_bit; - }; - - /** - * @brief flash slib_misc_sts register, offset:0xD8 - */ - union - { - __IO uint32_t slib_misc_sts; - struct - { - __IO uint32_t slib_pwd_err : 1; /* [0] */ - __IO uint32_t slib_pwd_ok : 1; /* [1] */ - __IO uint32_t slib_ulkf : 1; /* [2] */ - __IO uint32_t reserved1 : 13;/* [15:3] */ - __IO uint32_t slib_rcnt : 9; /* [24:16] */ - __IO uint32_t reserved2 : 7; /* [31:25] */ - } slib_misc_sts_bit; - }; - - /** - * @brief flash slib_set_pwd register, offset:0xDC - */ - union - { - __IO uint32_t slib_set_pwd; - struct - { - __IO uint32_t slib_pset_val : 32;/* [31:0] */ - } slib_set_pwd_bit; - }; - - /** - * @brief flash slib_set_range0 register, offset:0xE0 - */ - union - { - __IO uint32_t slib_set_range0; - struct - { - __IO uint32_t slib_ss_set : 16;/* [15:0] */ - __IO uint32_t slib_es_set : 16;/* [31:16] */ - } slib_set_range0_bit; - }; - - /** - * @brief flash slib_set_range1 register, offset:0xE4 - */ - union - { - __IO uint32_t slib_set_range1; - struct - { - __IO uint32_t slib_iss_set : 16;/* [15:0] */ - __IO uint32_t reserved1 : 15;/* [30:16] */ - __IO uint32_t set_slib_strt : 1; /* [31] */ - } slib_set_range1_bit; - }; - - /** - * @brief flash reserved7 register, offset:0xEC~0xE8 - */ - __IO uint32_t reserved7[2]; - - /** - * @brief flash slib_unlock register, offset:0xF0 - */ - union - { - __IO uint32_t slib_unlock; - struct - { - __IO uint32_t slib_ukval : 32;/* [31:0] */ - } slib_unlock_bit; - }; - - /** - * @brief flash crc_ctrl register, offset:0xF4 - */ - union - { - __IO uint32_t crc_ctrl; - struct - { - __IO uint32_t crc_ss : 12;/* [11:0] */ - __IO uint32_t crc_sn : 12;/* [23:12] */ - __IO uint32_t reserved1 : 7; /* [30:24] */ - __IO uint32_t crc_strt : 1; /* [31] */ - } crc_ctrl_bit; - }; - - /** - * @brief flash crc_chkr register, offset:0xF8 - */ - union - { - __IO uint32_t crc_chkr; - struct - { - __IO uint32_t crc_chkr : 32;/* [31:0] */ - } crc_chkr_bit; - }; - -} flash_type; - -/** - * @brief user system data - */ -typedef struct -{ - __IO uint16_t fap; - __IO uint16_t ssb; - __IO uint16_t data0; - __IO uint16_t data1; - __IO uint16_t epp0; - __IO uint16_t epp1; - __IO uint16_t epp2; - __IO uint16_t epp3; - __IO uint16_t eopb0; - __IO uint16_t reserved1; - __IO uint16_t epp4; - __IO uint16_t epp5; - __IO uint16_t epp6; - __IO uint16_t epp7; - __IO uint16_t reserved2[12]; - __IO uint16_t qspikey[8]; -} usd_type; - -/** - * @} - */ - -#define FLASH ((flash_type *) FLASH_REG_BASE) -#define USD ((usd_type *) USD_BASE) - -/** @defgroup FLASH_exported_functions - * @{ - */ - -flag_status flash_flag_get(uint32_t flash_flag); -void flash_flag_clear(uint32_t flash_flag); -flash_status_type flash_operation_status_get(void); -flash_status_type flash_bank1_operation_status_get(void); -flash_status_type flash_bank2_operation_status_get(void); -flash_status_type flash_operation_wait_for(uint32_t time_out); -flash_status_type flash_bank1_operation_wait_for(uint32_t time_out); -flash_status_type flash_bank2_operation_wait_for(uint32_t time_out); -void flash_unlock(void); -void flash_bank1_unlock(void); -void flash_bank2_unlock(void); -void flash_lock(void); -void flash_bank1_lock(void); -void flash_bank2_lock(void); -flash_status_type flash_sector_erase(uint32_t sector_address); -flash_status_type flash_block_erase(uint32_t block_address); -flash_status_type flash_internal_all_erase(void); -flash_status_type flash_bank1_erase(void); -flash_status_type flash_bank2_erase(void); -flash_status_type flash_user_system_data_erase(void); -flash_status_type flash_eopb0_config(flash_usd_eopb0_type data); -flash_status_type flash_word_program(uint32_t address, uint32_t data); -flash_status_type flash_halfword_program(uint32_t address, uint16_t data); -flash_status_type flash_byte_program(uint32_t address, uint8_t data); -flash_status_type flash_user_system_data_program(uint32_t address, uint8_t data); -flash_status_type flash_epp_set(uint32_t *sector_bits); -void flash_epp_status_get(uint32_t *sector_bits); -flash_status_type flash_fap_enable(confirm_state new_state); -flag_status flash_fap_status_get(void); -flash_status_type flash_ssb_set(uint8_t usd_ssb); -uint8_t flash_ssb_status_get(void); -void flash_interrupt_enable(uint32_t flash_int, confirm_state new_state); -flash_status_type flash_slib_enable(uint32_t pwd, uint16_t start_sector, uint16_t inst_start_sector, uint16_t end_sector); -error_status flash_slib_disable(uint32_t pwd); -uint32_t flash_slib_remaining_count_get(void); -flag_status flash_slib_state_get(void); -uint16_t flash_slib_start_sector_get(void); -uint16_t flash_slib_inststart_sector_get(void); -uint16_t flash_slib_end_sector_get(void); -uint32_t flash_crc_calibrate(uint32_t start_sector, uint32_t sector_cnt); -void flash_nzw_boost_enable(confirm_state new_state); -void flash_continue_read_enable(confirm_state new_state); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_gpio.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_gpio.h deleted file mode 100644 index edc2b06..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_gpio.h +++ /dev/null @@ -1,565 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_gpio.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 gpio header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_GPIO_H -#define __AT32F435_437_GPIO_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup GPIO - * @{ - */ - -/** @defgroup GPIO_pins_number_definition - * @{ - */ - -#define GPIO_PINS_0 0x0001 /*!< gpio pins number 0 */ -#define GPIO_PINS_1 0x0002 /*!< gpio pins number 1 */ -#define GPIO_PINS_2 0x0004 /*!< gpio pins number 2 */ -#define GPIO_PINS_3 0x0008 /*!< gpio pins number 3 */ -#define GPIO_PINS_4 0x0010 /*!< gpio pins number 4 */ -#define GPIO_PINS_5 0x0020 /*!< gpio pins number 5 */ -#define GPIO_PINS_6 0x0040 /*!< gpio pins number 6 */ -#define GPIO_PINS_7 0x0080 /*!< gpio pins number 7 */ -#define GPIO_PINS_8 0x0100 /*!< gpio pins number 8 */ -#define GPIO_PINS_9 0x0200 /*!< gpio pins number 9 */ -#define GPIO_PINS_10 0x0400 /*!< gpio pins number 10 */ -#define GPIO_PINS_11 0x0800 /*!< gpio pins number 11 */ -#define GPIO_PINS_12 0x1000 /*!< gpio pins number 12 */ -#define GPIO_PINS_13 0x2000 /*!< gpio pins number 13 */ -#define GPIO_PINS_14 0x4000 /*!< gpio pins number 14 */ -#define GPIO_PINS_15 0x8000 /*!< gpio pins number 15 */ -#define GPIO_PINS_ALL 0xFFFF /*!< gpio all pins */ - -/** - * @} - */ - -/** @defgroup GPIO_exported_types - * @{ - */ - -/** - * @brief gpio mode select - */ -typedef enum -{ - GPIO_MODE_INPUT = 0x00, /*!< gpio input mode */ - GPIO_MODE_OUTPUT = 0x01, /*!< gpio output mode */ - GPIO_MODE_MUX = 0x02, /*!< gpio mux function mode */ - GPIO_MODE_ANALOG = 0x03 /*!< gpio analog in/out mode */ -} gpio_mode_type; - -/** - * @brief gpio output drive strength select - */ -typedef enum -{ - GPIO_DRIVE_STRENGTH_STRONGER = 0x01, /*!< stronger sourcing/sinking strength */ - GPIO_DRIVE_STRENGTH_MODERATE = 0x02 /*!< moderate sourcing/sinking strength */ -} gpio_drive_type; - -/** - * @brief gpio output type - */ -typedef enum -{ - GPIO_OUTPUT_PUSH_PULL = 0x00, /*!< output push-pull */ - GPIO_OUTPUT_OPEN_DRAIN = 0x01 /*!< output open-drain */ -} gpio_output_type; - -/** - * @brief gpio pull type - */ -typedef enum -{ - GPIO_PULL_NONE = 0x00, /*!< floating for input, no pull for output */ - GPIO_PULL_UP = 0x01, /*!< pull-up */ - GPIO_PULL_DOWN = 0x02 /*!< pull-down */ -} gpio_pull_type; - -/** - * @brief gpio init type - */ -typedef struct -{ - uint32_t gpio_pins; /*!< pins number selection */ - gpio_output_type gpio_out_type; /*!< output type selection */ - gpio_pull_type gpio_pull; /*!< pull type selection */ - gpio_mode_type gpio_mode; /*!< mode selection */ - gpio_drive_type gpio_drive_strength; /*!< drive strength selection */ -} gpio_init_type; - -/** - * @brief gpio pins source type - */ -typedef enum -{ - GPIO_PINS_SOURCE0 = 0x00, /*!< gpio pins source number 0 */ - GPIO_PINS_SOURCE1 = 0x01, /*!< gpio pins source number 1 */ - GPIO_PINS_SOURCE2 = 0x02, /*!< gpio pins source number 2 */ - GPIO_PINS_SOURCE3 = 0x03, /*!< gpio pins source number 3 */ - GPIO_PINS_SOURCE4 = 0x04, /*!< gpio pins source number 4 */ - GPIO_PINS_SOURCE5 = 0x05, /*!< gpio pins source number 5 */ - GPIO_PINS_SOURCE6 = 0x06, /*!< gpio pins source number 6 */ - GPIO_PINS_SOURCE7 = 0x07, /*!< gpio pins source number 7 */ - GPIO_PINS_SOURCE8 = 0x08, /*!< gpio pins source number 8 */ - GPIO_PINS_SOURCE9 = 0x09, /*!< gpio pins source number 9 */ - GPIO_PINS_SOURCE10 = 0x0A, /*!< gpio pins source number 10 */ - GPIO_PINS_SOURCE11 = 0x0B, /*!< gpio pins source number 11 */ - GPIO_PINS_SOURCE12 = 0x0C, /*!< gpio pins source number 12 */ - GPIO_PINS_SOURCE13 = 0x0D, /*!< gpio pins source number 13 */ - GPIO_PINS_SOURCE14 = 0x0E, /*!< gpio pins source number 14 */ - GPIO_PINS_SOURCE15 = 0x0F /*!< gpio pins source number 15 */ -} gpio_pins_source_type; - -/** - * @brief gpio muxing function selection type - */ -typedef enum -{ - GPIO_MUX_0 = 0x00, /*!< gpio muxing function selection 0 */ - GPIO_MUX_1 = 0x01, /*!< gpio muxing function selection 1 */ - GPIO_MUX_2 = 0x02, /*!< gpio muxing function selection 2 */ - GPIO_MUX_3 = 0x03, /*!< gpio muxing function selection 3 */ - GPIO_MUX_4 = 0x04, /*!< gpio muxing function selection 4 */ - GPIO_MUX_5 = 0x05, /*!< gpio muxing function selection 5 */ - GPIO_MUX_6 = 0x06, /*!< gpio muxing function selection 6 */ - GPIO_MUX_7 = 0x07, /*!< gpio muxing function selection 7 */ - GPIO_MUX_8 = 0x08, /*!< gpio muxing function selection 8 */ - GPIO_MUX_9 = 0x09, /*!< gpio muxing function selection 9 */ - GPIO_MUX_10 = 0x0A, /*!< gpio muxing function selection 10 */ - GPIO_MUX_11 = 0x0B, /*!< gpio muxing function selection 11 */ - GPIO_MUX_12 = 0x0C, /*!< gpio muxing function selection 12 */ - GPIO_MUX_13 = 0x0D, /*!< gpio muxing function selection 13 */ - GPIO_MUX_14 = 0x0E, /*!< gpio muxing function selection 14 */ - GPIO_MUX_15 = 0x0F /*!< gpio muxing function selection 15 */ -} gpio_mux_sel_type; - -/** - * @brief type define gpio register all - */ -typedef struct -{ - /** - * @brief gpio mode register, offset:0x00 - */ - union - { - __IO uint32_t cfgr; - struct - { - __IO uint32_t iomc0 : 2; /* [1:0] */ - __IO uint32_t iomc1 : 2; /* [3:2] */ - __IO uint32_t iomc2 : 2; /* [5:4] */ - __IO uint32_t iomc3 : 2; /* [7:6] */ - __IO uint32_t iomc4 : 2; /* [9:8] */ - __IO uint32_t iomc5 : 2; /* [11:10] */ - __IO uint32_t iomc6 : 2; /* [13:12] */ - __IO uint32_t iomc7 : 2; /* [15:14] */ - __IO uint32_t iomc8 : 2; /* [17:16] */ - __IO uint32_t iomc9 : 2; /* [19:18] */ - __IO uint32_t iomc10 : 2; /* [21:20] */ - __IO uint32_t iomc11 : 2; /* [23:22] */ - __IO uint32_t iomc12 : 2; /* [25:24] */ - __IO uint32_t iomc13 : 2; /* [27:26] */ - __IO uint32_t iomc14 : 2; /* [29:28] */ - __IO uint32_t iomc15 : 2; /* [31:30] */ - } cfgr_bit; - }; - - /** - * @brief gpio output type register, offset:0x04 - */ - union - { - __IO uint32_t omode; - struct - { - __IO uint32_t om0 : 1; /* [0] */ - __IO uint32_t om1 : 1; /* [1] */ - __IO uint32_t om2 : 1; /* [2] */ - __IO uint32_t om3 : 1; /* [3] */ - __IO uint32_t om4 : 1; /* [4] */ - __IO uint32_t om5 : 1; /* [5] */ - __IO uint32_t om6 : 1; /* [6] */ - __IO uint32_t om7 : 1; /* [7] */ - __IO uint32_t om8 : 1; /* [8] */ - __IO uint32_t om9 : 1; /* [9] */ - __IO uint32_t om10 : 1; /* [10] */ - __IO uint32_t om11 : 1; /* [11] */ - __IO uint32_t om12 : 1; /* [12] */ - __IO uint32_t om13 : 1; /* [13] */ - __IO uint32_t om14 : 1; /* [14] */ - __IO uint32_t om15 : 1; /* [15] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } omode_bit; - }; - - /** - * @brief gpio output driver register, offset:0x08 - */ - union - { - __IO uint32_t odrvr; - struct - { - __IO uint32_t odrv0 : 2; /* [1:0] */ - __IO uint32_t odrv1 : 2; /* [3:2] */ - __IO uint32_t odrv2 : 2; /* [5:4] */ - __IO uint32_t odrv3 : 2; /* [7:6] */ - __IO uint32_t odrv4 : 2; /* [9:8] */ - __IO uint32_t odrv5 : 2; /* [11:10] */ - __IO uint32_t odrv6 : 2; /* [13:12] */ - __IO uint32_t odrv7 : 2; /* [15:14] */ - __IO uint32_t odrv8 : 2; /* [17:16] */ - __IO uint32_t odrv9 : 2; /* [19:18] */ - __IO uint32_t odrv10 : 2; /* [21:20] */ - __IO uint32_t odrv11 : 2; /* [23:22] */ - __IO uint32_t odrv12 : 2; /* [25:24] */ - __IO uint32_t odrv13 : 2; /* [27:26] */ - __IO uint32_t odrv14 : 2; /* [29:28] */ - __IO uint32_t odrv15 : 2; /* [31:30] */ - } odrvr_bit; - }; - - /** - * @brief gpio pull up/down register, offset:0x0C - */ - union - { - __IO uint32_t pull; - struct - { - __IO uint32_t pull0 : 2; /* [1:0] */ - __IO uint32_t pull1 : 2; /* [3:2] */ - __IO uint32_t pull2 : 2; /* [5:4] */ - __IO uint32_t pull3 : 2; /* [7:6] */ - __IO uint32_t pull4 : 2; /* [9:8] */ - __IO uint32_t pull5 : 2; /* [11:10] */ - __IO uint32_t pull6 : 2; /* [13:12] */ - __IO uint32_t pull7 : 2; /* [15:14] */ - __IO uint32_t pull8 : 2; /* [17:16] */ - __IO uint32_t pull9 : 2; /* [19:18] */ - __IO uint32_t pull10 : 2; /* [21:20] */ - __IO uint32_t pull11 : 2; /* [23:22] */ - __IO uint32_t pull12 : 2; /* [25:24] */ - __IO uint32_t pull13 : 2; /* [27:26] */ - __IO uint32_t pull14 : 2; /* [29:28] */ - __IO uint32_t pull15 : 2; /* [31:30] */ - } pull_bit; - }; - - /** - * @brief gpio input data register, offset:0x10 - */ - union - { - __IO uint32_t idt; - struct - { - __IO uint32_t idt0 : 1; /* [0] */ - __IO uint32_t idt1 : 1; /* [1] */ - __IO uint32_t idt2 : 1; /* [2] */ - __IO uint32_t idt3 : 1; /* [3] */ - __IO uint32_t idt4 : 1; /* [4] */ - __IO uint32_t idt5 : 1; /* [5] */ - __IO uint32_t idt6 : 1; /* [6] */ - __IO uint32_t idt7 : 1; /* [7] */ - __IO uint32_t idt8 : 1; /* [8] */ - __IO uint32_t idt9 : 1; /* [9] */ - __IO uint32_t idt10 : 1; /* [10] */ - __IO uint32_t idt11 : 1; /* [11] */ - __IO uint32_t idt12 : 1; /* [12] */ - __IO uint32_t idt13 : 1; /* [13] */ - __IO uint32_t idt14 : 1; /* [14] */ - __IO uint32_t idt15 : 1; /* [15] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } idt_bit; - }; - - /** - * @brief gpio output data register, offset:0x14 - */ - union - { - __IO uint32_t odt; - struct - { - __IO uint32_t odt0 : 1; /* [0] */ - __IO uint32_t odt1 : 1; /* [1] */ - __IO uint32_t odt2 : 1; /* [2] */ - __IO uint32_t odt3 : 1; /* [3] */ - __IO uint32_t odt4 : 1; /* [4] */ - __IO uint32_t odt5 : 1; /* [5] */ - __IO uint32_t odt6 : 1; /* [6] */ - __IO uint32_t odt7 : 1; /* [7] */ - __IO uint32_t odt8 : 1; /* [8] */ - __IO uint32_t odt9 : 1; /* [9] */ - __IO uint32_t odt10 : 1; /* [10] */ - __IO uint32_t odt11 : 1; /* [11] */ - __IO uint32_t odt12 : 1; /* [12] */ - __IO uint32_t odt13 : 1; /* [13] */ - __IO uint32_t odt14 : 1; /* [14] */ - __IO uint32_t odt15 : 1; /* [15] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } odt_bit; - }; - - /** - * @brief gpio scr register, offset:0x18 - */ - union - { - __IO uint32_t scr; - struct - { - __IO uint32_t iosb0 : 1; /* [0] */ - __IO uint32_t iosb1 : 1; /* [1] */ - __IO uint32_t iosb2 : 1; /* [2] */ - __IO uint32_t iosb3 : 1; /* [3] */ - __IO uint32_t iosb4 : 1; /* [4] */ - __IO uint32_t iosb5 : 1; /* [5] */ - __IO uint32_t iosb6 : 1; /* [6] */ - __IO uint32_t iosb7 : 1; /* [7] */ - __IO uint32_t iosb8 : 1; /* [8] */ - __IO uint32_t iosb9 : 1; /* [9] */ - __IO uint32_t iosb10 : 1; /* [10] */ - __IO uint32_t iosb11 : 1; /* [11] */ - __IO uint32_t iosb12 : 1; /* [12] */ - __IO uint32_t iosb13 : 1; /* [13] */ - __IO uint32_t iosb14 : 1; /* [14] */ - __IO uint32_t iosb15 : 1; /* [15] */ - __IO uint32_t iocb0 : 1; /* [16] */ - __IO uint32_t iocb1 : 1; /* [17] */ - __IO uint32_t iocb2 : 1; /* [18] */ - __IO uint32_t iocb3 : 1; /* [19] */ - __IO uint32_t iocb4 : 1; /* [20] */ - __IO uint32_t iocb5 : 1; /* [21] */ - __IO uint32_t iocb6 : 1; /* [22] */ - __IO uint32_t iocb7 : 1; /* [23] */ - __IO uint32_t iocb8 : 1; /* [24] */ - __IO uint32_t iocb9 : 1; /* [25] */ - __IO uint32_t iocb10 : 1; /* [26] */ - __IO uint32_t iocb11 : 1; /* [27] */ - __IO uint32_t iocb12 : 1; /* [28] */ - __IO uint32_t iocb13 : 1; /* [29] */ - __IO uint32_t iocb14 : 1; /* [30] */ - __IO uint32_t iocb15 : 1; /* [31] */ - } scr_bit; - }; - - /** - * @brief gpio wpen register, offset:0x1C - */ - union - { - __IO uint32_t wpr; - struct - { - __IO uint32_t wpen0 : 1; /* [0] */ - __IO uint32_t wpen1 : 1; /* [1] */ - __IO uint32_t wpen2 : 1; /* [2] */ - __IO uint32_t wpen3 : 1; /* [3] */ - __IO uint32_t wpen4 : 1; /* [4] */ - __IO uint32_t wpen5 : 1; /* [5] */ - __IO uint32_t wpen6 : 1; /* [6] */ - __IO uint32_t wpen7 : 1; /* [7] */ - __IO uint32_t wpen8 : 1; /* [8] */ - __IO uint32_t wpen9 : 1; /* [9] */ - __IO uint32_t wpen10 : 1; /* [10] */ - __IO uint32_t wpen11 : 1; /* [11] */ - __IO uint32_t wpen12 : 1; /* [12] */ - __IO uint32_t wpen13 : 1; /* [13] */ - __IO uint32_t wpen14 : 1; /* [14] */ - __IO uint32_t wpen15 : 1; /* [15] */ - __IO uint32_t wpseq : 1; /* [16] */ - __IO uint32_t reserved1 : 15;/* [31:17] */ - } wpr_bit; - }; - - /** - * @brief gpio muxl register, offset:0x20 - */ - union - { - __IO uint32_t muxl; - struct - { - __IO uint32_t muxl0 : 4; /* [3:0] */ - __IO uint32_t muxl1 : 4; /* [7:4] */ - __IO uint32_t muxl2 : 4; /* [11:8] */ - __IO uint32_t muxl3 : 4; /* [15:12] */ - __IO uint32_t muxl4 : 4; /* [19:16] */ - __IO uint32_t muxl5 : 4; /* [23:20] */ - __IO uint32_t muxl6 : 4; /* [27:24] */ - __IO uint32_t muxl7 : 4; /* [31:28] */ - } muxl_bit; - }; - - /** - * @brief gpio muxh register, offset:0x24 - */ - union - { - __IO uint32_t muxh; - struct - { - __IO uint32_t muxh8 : 4; /* [3:0] */ - __IO uint32_t muxh9 : 4; /* [7:4] */ - __IO uint32_t muxh10 : 4; /* [11:8] */ - __IO uint32_t muxh11 : 4; /* [15:12] */ - __IO uint32_t muxh12 : 4; /* [19:16] */ - __IO uint32_t muxh13 : 4; /* [23:20] */ - __IO uint32_t muxh14 : 4; /* [27:24] */ - __IO uint32_t muxh15 : 4; /* [31:28] */ - } muxh_bit; - }; - - /** - * @brief gpio clr register, offset:0x28 - */ - union - { - __IO uint32_t clr; - struct - { - __IO uint32_t iocb0 : 1; /* [0] */ - __IO uint32_t iocb1 : 1; /* [1] */ - __IO uint32_t iocb2 : 1; /* [2] */ - __IO uint32_t iocb3 : 1; /* [3] */ - __IO uint32_t iocb4 : 1; /* [4] */ - __IO uint32_t iocb5 : 1; /* [5] */ - __IO uint32_t iocb6 : 1; /* [6] */ - __IO uint32_t iocb7 : 1; /* [7] */ - __IO uint32_t iocb8 : 1; /* [8] */ - __IO uint32_t iocb9 : 1; /* [9] */ - __IO uint32_t iocb10 : 1; /* [10] */ - __IO uint32_t iocb11 : 1; /* [11] */ - __IO uint32_t iocb12 : 1; /* [12] */ - __IO uint32_t iocb13 : 1; /* [13] */ - __IO uint32_t iocb14 : 1; /* [14] */ - __IO uint32_t iocb15 : 1; /* [15] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } clr_bit; - }; - - /** - * @brief gpio reserved1 register, offset:0x2C~0x38 - */ - __IO uint32_t reserved1[4]; - - /** - * @brief gpio hdrv register, offset:0x3C - */ - union - { - __IO uint32_t hdrv; - struct - { - __IO uint32_t hdrv0 : 1; /* [0] */ - __IO uint32_t hdrv1 : 1; /* [1] */ - __IO uint32_t hdrv2 : 1; /* [2] */ - __IO uint32_t hdrv3 : 1; /* [3] */ - __IO uint32_t hdrv4 : 1; /* [4] */ - __IO uint32_t hdrv5 : 1; /* [5] */ - __IO uint32_t hdrv6 : 1; /* [6] */ - __IO uint32_t hdrv7 : 1; /* [7] */ - __IO uint32_t hdrv8 : 1; /* [8] */ - __IO uint32_t hdrv9 : 1; /* [9] */ - __IO uint32_t hdrv10 : 1; /* [10] */ - __IO uint32_t hdrv11 : 1; /* [11] */ - __IO uint32_t hdrv12 : 1; /* [12] */ - __IO uint32_t hdrv13 : 1; /* [13] */ - __IO uint32_t hdrv14 : 1; /* [14] */ - __IO uint32_t hdrv15 : 1; /* [15] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } hdrv_bit; - }; - -} gpio_type; - -/** - * @} - */ - -#define GPIOA ((gpio_type *) GPIOA_BASE) -#define GPIOB ((gpio_type *) GPIOB_BASE) -#define GPIOC ((gpio_type *) GPIOC_BASE) -#define GPIOD ((gpio_type *) GPIOD_BASE) -#define GPIOE ((gpio_type *) GPIOE_BASE) -#define GPIOF ((gpio_type *) GPIOF_BASE) -#define GPIOG ((gpio_type *) GPIOG_BASE) -#define GPIOH ((gpio_type *) GPIOH_BASE) - -/** @defgroup GPIO_exported_functions - * @{ - */ - -void gpio_reset(gpio_type *gpio_x); -void gpio_init(gpio_type *gpio_x, gpio_init_type *gpio_init_struct); -void gpio_default_para_init(gpio_init_type *gpio_init_struct); -flag_status gpio_input_data_bit_read(gpio_type *gpio_x, uint16_t pins); -uint16_t gpio_input_data_read(gpio_type *gpio_x); -flag_status gpio_output_data_bit_read(gpio_type *gpio_x, uint16_t pins); -uint16_t gpio_output_data_read(gpio_type *gpio_x); -void gpio_bits_set(gpio_type *gpio_x, uint16_t pins); -void gpio_bits_reset(gpio_type *gpio_x, uint16_t pins); -void gpio_bits_write(gpio_type *gpio_x, uint16_t pins, confirm_state bit_state); -void gpio_port_wirte(gpio_type *gpio_x, uint16_t port_value); -void gpio_pin_wp_config(gpio_type *gpio_x, uint16_t pins); -void gpio_pins_huge_driven_config(gpio_type *gpio_x, uint16_t pins, confirm_state new_state); -void gpio_pin_mux_config(gpio_type *gpio_x, gpio_pins_source_type gpio_pin_source, gpio_mux_sel_type gpio_mux); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_i2c.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_i2c.h deleted file mode 100644 index b5a136c..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_i2c.h +++ /dev/null @@ -1,479 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_i2c.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 i2c header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_I2C_H -#define __AT32F435_437_I2C_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup I2C - * @{ - */ - -/** - * @brief maximum number of single transfers - */ -#define MAX_TRANSFER_CNT 255 /*!< maximum number of single transfers */ - -/** @defgroup I2C_interrupts_definition - * @brief i2c interrupt - * @{ - */ - -#define I2C_TD_INT ((uint32_t)0x00000002) /*!< i2c transmit data interrupt */ -#define I2C_RD_INT ((uint32_t)0x00000004) /*!< i2c receive data interrupt */ -#define I2C_ADDR_INT ((uint32_t)0x00000008) /*!< i2c address match interrupt */ -#define I2C_ACKFIAL_INT ((uint32_t)0x00000010) /*!< i2c ack fail interrupt */ -#define I2C_STOP_INT ((uint32_t)0x00000020) /*!< i2c stop detect interrupt */ -#define I2C_TDC_INT ((uint32_t)0x00000040) /*!< i2c transmit data complete interrupt */ -#define I2C_ERR_INT ((uint32_t)0x00000080) /*!< i2c bus error interrupt */ - -/** - * @} - */ - -/** @defgroup I2C_flags_definition - * @brief i2c flag - * @{ - */ - -#define I2C_TDBE_FLAG ((uint32_t)0x00000001) /*!< i2c transmit data buffer empty flag */ -#define I2C_TDIS_FLAG ((uint32_t)0x00000002) /*!< i2c send interrupt status */ -#define I2C_RDBF_FLAG ((uint32_t)0x00000004) /*!< i2c receive data buffer full flag */ -#define I2C_ADDRF_FLAG ((uint32_t)0x00000008) /*!< i2c 0~7 bit address match flag */ -#define I2C_ACKFAIL_FLAG ((uint32_t)0x00000010) /*!< i2c acknowledge failure flag */ -#define I2C_STOPF_FLAG ((uint32_t)0x00000020) /*!< i2c stop condition generation complete flag */ -#define I2C_TDC_FLAG ((uint32_t)0x00000040) /*!< i2c transmit data complete flag */ -#define I2C_TCRLD_FLAG ((uint32_t)0x00000080) /*!< i2c transmission is complete, waiting to load data */ -#define I2C_BUSERR_FLAG ((uint32_t)0x00000100) /*!< i2c bus error flag */ -#define I2C_ARLOST_FLAG ((uint32_t)0x00000200) /*!< i2c arbitration lost flag */ -#define I2C_OUF_FLAG ((uint32_t)0x00000400) /*!< i2c overflow or underflow flag */ -#define I2C_PECERR_FLAG ((uint32_t)0x00000800) /*!< i2c pec receive error flag */ -#define I2C_TMOUT_FLAG ((uint32_t)0x00001000) /*!< i2c smbus timeout flag */ -#define I2C_ALERTF_FLAG ((uint32_t)0x00002000) /*!< i2c smbus alert flag */ -#define I2C_BUSYF_FLAG ((uint32_t)0x00008000) /*!< i2c bus busy flag transmission mode */ -#define I2C_SDIR_FLAG ((uint32_t)0x00010000) /*!< i2c slave data transmit direction */ - -/** - * @} - */ - -/** @defgroup I2C_exported_types - * @{ - */ - -/** - * @brief i2c smbus mode set - */ -typedef enum -{ - I2C_SMBUS_MODE_DEVICE = 0x00, /*!< smbus device mode */ - I2C_SMBUS_MODE_HOST = 0x01 /*!< smbus host mode */ -} i2c_smbus_mode_type; - -/** - * @brief i2c address mode - */ -typedef enum -{ - I2C_ADDRESS_MODE_7BIT = 0x00, /*!< 7bit address mode */ - I2C_ADDRESS_MODE_10BIT = 0x01 /*!< 10bit address mode */ -} i2c_address_mode_type; - -/** - * @brief i2c transfer direction - */ -typedef enum -{ - I2C_DIR_TRANSMIT = 0x00, /*!< master request a write transfer */ - I2C_DIR_RECEIVE = 0x01 /*!< master request a read transfer */ -} i2c_transfer_dir_type; - -/** - * @brief i2c dma requests direction - */ -typedef enum -{ - I2C_DMA_REQUEST_TX = 0x00, /*!< dma transmit request */ - I2C_DMA_REQUEST_RX = 0x01 /*!< dma receive request */ -} i2c_dma_request_type; - -/** - * @brief i2c smbus alert pin set - */ -typedef enum -{ - I2C_SMBUS_ALERT_HIGH = 0x00, /*!< smbus alert pin set high */ - I2C_SMBUS_ALERT_LOW = 0x01 /*!< smbus alert pin set low */ -} i2c_smbus_alert_set_type; - -/** - * @brief i2c clock timeout detection mode - */ -typedef enum -{ - I2C_TIMEOUT_DETCET_LOW = 0x00, /*!< detect low level timeout */ - I2C_TIMEOUT_DETCET_HIGH = 0x01 /*!< detect high level timeout */ -} i2c_timeout_detcet_type; - -/** - * @brief i2c own address2 mask - */ -typedef enum -{ - I2C_ADDR2_NOMASK = 0x00, /*!< compare bit [7:1] */ - I2C_ADDR2_MASK01 = 0x01, /*!< only compare bit [7:2] */ - I2C_ADDR2_MASK02 = 0x02, /*!< only compare bit [7:2] */ - I2C_ADDR2_MASK03 = 0x03, /*!< only compare bit [7:3] */ - I2C_ADDR2_MASK04 = 0x04, /*!< only compare bit [7:4] */ - I2C_ADDR2_MASK05 = 0x05, /*!< only compare bit [7:5] */ - I2C_ADDR2_MASK06 = 0x06, /*!< only compare bit [7:6] */ - I2C_ADDR2_MASK07 = 0x07 /*!< only compare bit [7] */ -} i2c_addr2_mask_type; - -/** - * @brief i2c reload end mode - */ -typedef enum -{ - I2C_AUTO_STOP_MODE = 0x00, /*!< auto generate stop mode */ - I2C_SOFT_STOP_MODE = 0x01, /*!< soft generate stop mode */ - I2C_RELOAD_MODE = 0x02 /*!< reload mode */ -} i2c_reload_stop_mode_type; - -/** - * @brief i2c start stop mode - */ -typedef enum -{ - I2C_WITHOUT_START = 0x00, /*!< transfer data without start condition */ - I2C_GEN_START_READ = 0x01, /*!< read data and generate start */ - I2C_GEN_START_WRITE = 0x02 /*!< send data and generate start */ -} i2c_start_stop_mode_type; - -/** - * @brief type define i2c register all - */ -typedef struct -{ - /** - * @brief i2c ctrl1 register, offset:0x00 - */ - union - { - __IO uint32_t ctrl1; - struct - { - __IO uint32_t i2cen : 1; /* [0] */ - __IO uint32_t tdien : 1; /* [1] */ - __IO uint32_t rdien : 1; /* [2] */ - __IO uint32_t addrien : 1; /* [3] */ - __IO uint32_t ackfailien : 1; /* [4] */ - __IO uint32_t stopien : 1; /* [5] */ - __IO uint32_t tdcien : 1; /* [6] */ - __IO uint32_t errien : 1; /* [7] */ - __IO uint32_t dflt : 4; /* [11:8] */ - __IO uint32_t reserved1 : 2; /* [13:12] */ - __IO uint32_t dmaten : 1; /* [14] */ - __IO uint32_t dmaren : 1; /* [15] */ - __IO uint32_t sctrl : 1; /* [16] */ - __IO uint32_t stretch : 1; /* [17] */ - __IO uint32_t reserved2 : 1; /* [18] */ - __IO uint32_t gcaen : 1; /* [19] */ - __IO uint32_t haddren : 1; /* [20] */ - __IO uint32_t devaddren : 1; /* [21] */ - __IO uint32_t smbalert : 1; /* [22] */ - __IO uint32_t pecen : 1; /* [23] */ - __IO uint32_t reserved3 : 8; /* [31:24] */ - } ctrl1_bit; - }; - - /** - * @brief i2c ctrl2 register, offset:0x04 - */ - union - { - __IO uint32_t ctrl2; - struct - { - __IO uint32_t saddr : 10;/* [9:0] */ - __IO uint32_t dir : 1; /* [10] */ - __IO uint32_t addr10 : 1; /* [11] */ - __IO uint32_t readh10 : 1; /* [12] */ - __IO uint32_t genstart : 1; /* [13] */ - __IO uint32_t genstop : 1; /* [14] */ - __IO uint32_t nacken : 1; /* [15] */ - __IO uint32_t cnt : 8; /* [23:16] */ - __IO uint32_t rlden : 1; /* [24] */ - __IO uint32_t astopen : 1; /* [25] */ - __IO uint32_t pecten : 1; /* [26] */ - __IO uint32_t reserved1 : 5; /* [31:27] */ - } ctrl2_bit; - }; - - /** - * @brief i2c oaddr1 register, offset:0x08 - */ - union - { - __IO uint32_t oaddr1; - struct - { - __IO uint32_t addr1 : 10;/* [9:0] */ - __IO uint32_t addr1mode : 1; /* [10] */ - __IO uint32_t reserved1 : 4; /* [14:11] */ - __IO uint32_t addr1en : 1; /* [15] */ - __IO uint32_t reserved2 : 16;/* [31:16] */ - } oaddr1_bit; - }; - - /** - * @brief i2c oaddr2 register, offset:0x0c - */ - union - { - __IO uint32_t oaddr2; - struct - { - __IO uint32_t reserved1 : 1; /* [0] */ - __IO uint32_t addr2 : 7; /* [7:1] */ - __IO uint32_t addr2mask : 3; /* [10:8] */ - __IO uint32_t reserved2 : 4; /* [14:11] */ - __IO uint32_t addr2en : 1; /* [15] */ - __IO uint32_t reserved3 : 16;/* [31:16] */ - } oaddr2_bit; - }; - - /** - * @brief i2c clkctrl register, offset:0x10 - */ - union - { - __IO uint32_t clkctrl; - struct - { - __IO uint32_t scll : 8; /* [7:0] */ - __IO uint32_t sclh : 8; /* [15:8] */ - __IO uint32_t sdad : 4; /* [19:16] */ - __IO uint32_t scld : 4; /* [23:20] */ - __IO uint32_t divh : 4; /* [27:24] */ - __IO uint32_t divl : 4; /* [31:28] */ - } clkctrl_bit; - }; - - /** - * @brief i2c timeout register, offset:0x14 - */ - union - { - __IO uint32_t timeout; - struct - { - __IO uint32_t totime : 12;/* [11:0] */ - __IO uint32_t tomode : 1; /* [12] */ - __IO uint32_t reserved1 : 2; /* [14:13] */ - __IO uint32_t toen : 1; /* [15] */ - __IO uint32_t exttime : 12;/* [27:16] */ - __IO uint32_t reserved2 : 3; /* [30:28] */ - __IO uint32_t exten : 1; /* [31] */ - } timeout_bit; - }; - - /** - * @brief i2c sts register, offset:0x18 - */ - union - { - __IO uint32_t sts; - struct - { - __IO uint32_t tdbe : 1; /* [0] */ - __IO uint32_t tdis : 1; /* [1] */ - __IO uint32_t rdbf : 1; /* [2] */ - __IO uint32_t addrf : 1; /* [3] */ - __IO uint32_t ackfail : 1; /* [4] */ - __IO uint32_t stopf : 1; /* [5] */ - __IO uint32_t tdc : 1; /* [6] */ - __IO uint32_t tcrld : 1; /* [7] */ - __IO uint32_t buserr : 1; /* [8] */ - __IO uint32_t arlost : 1; /* [9] */ - __IO uint32_t ouf : 1; /* [10] */ - __IO uint32_t pecerr : 1; /* [11] */ - __IO uint32_t tmout : 1; /* [12] */ - __IO uint32_t alertf : 1; /* [13] */ - __IO uint32_t reserved1 : 1; /* [14] */ - __IO uint32_t busyf : 1; /* [15] */ - __IO uint32_t sdir : 1; /* [16] */ - __IO uint32_t addr : 7; /* [23:17] */ - __IO uint32_t reserved2 : 8; /* [31:24] */ - } sts_bit; - }; - - /** - * @brief i2c clr register, offset:0x1c - */ - union - { - __IO uint32_t clr; - struct - { - __IO uint32_t reserved1 : 3; /* [2:0] */ - __IO uint32_t addrc : 1; /* [3] */ - __IO uint32_t ackfailc : 1; /* [4] */ - __IO uint32_t stopc : 1; /* [5] */ - __IO uint32_t reserved2 : 2; /* [6:7] */ - __IO uint32_t buserrc : 1; /* [8] */ - __IO uint32_t arlostc : 1; /* [9] */ - __IO uint32_t oufc : 1; /* [10] */ - __IO uint32_t pecerrc : 1; /* [11] */ - __IO uint32_t tmoutc : 1; /* [12] */ - __IO uint32_t alertc : 1; /* [13] */ - __IO uint32_t reserved3 : 18;/* [31:14] */ - } clr_bit; - }; - - /** - * @brief i2c pec register, offset:0x20 - */ - union - { - __IO uint32_t pec; - struct - { - __IO uint32_t pecval : 8; /* [7:0] */ - __IO uint32_t reserved1 : 24;/* [31:8] */ - } pec_bit; - }; - - /** - * @brief i2c rxdt register, offset:0x20 - */ - union - { - __IO uint32_t rxdt; - struct - { - __IO uint32_t dt : 8; /* [7:0] */ - __IO uint32_t reserved1 : 24;/* [31:8] */ - } rxdt_bit; - }; - - /** - * @brief i2c txdt register, offset:0x20 - */ - union - { - __IO uint32_t txdt; - struct - { - __IO uint32_t dt : 8; /* [7:0] */ - __IO uint32_t reserved1 : 24;/* [31:8] */ - } txdt_bit; - }; - -} i2c_type; - -/** - * @} - */ - -#define I2C1 ((i2c_type *) I2C1_BASE) -#define I2C2 ((i2c_type *) I2C2_BASE) -#define I2C3 ((i2c_type *) I2C3_BASE) - -/** @defgroup I2C_exported_functions - * @{ - */ - -void i2c_reset(i2c_type *i2c_x); -void i2c_init(i2c_type *i2c_x, uint8_t dfilters, uint32_t clk); -void i2c_own_address1_set(i2c_type *i2c_x, i2c_address_mode_type mode, uint16_t address); -void i2c_own_address2_set(i2c_type *i2c_x, uint8_t address, i2c_addr2_mask_type mask); -void i2c_own_address2_enable(i2c_type *i2c_x, confirm_state new_state); -void i2c_smbus_enable(i2c_type *i2c_x, i2c_smbus_mode_type mode, confirm_state new_state); -void i2c_enable(i2c_type *i2c_x, confirm_state new_state); -void i2c_clock_stretch_enable(i2c_type *i2c_x, confirm_state new_state); -void i2c_ack_enable(i2c_type *i2c_x, confirm_state new_state); -void i2c_addr10_mode_enable(i2c_type *i2c_x, confirm_state new_state); -void i2c_transfer_addr_set(i2c_type *i2c_x, uint16_t address); -uint16_t i2c_transfer_addr_get(i2c_type *i2c_x); -void i2c_transfer_dir_set(i2c_type *i2c_x, i2c_transfer_dir_type i2c_direction); -i2c_transfer_dir_type i2c_transfer_dir_get(i2c_type *i2c_x); -uint8_t i2c_matched_addr_get(i2c_type *i2c_x); -void i2c_auto_stop_enable(i2c_type *i2c_x, confirm_state new_state); -void i2c_reload_enable(i2c_type *i2c_x, confirm_state new_state); -void i2c_cnt_set(i2c_type *i2c_x, uint8_t cnt); -void i2c_addr10_header_enable(i2c_type *i2c_x, confirm_state new_state); -void i2c_general_call_enable(i2c_type *i2c_x, confirm_state new_state); -void i2c_smbus_alert_set(i2c_type *i2c_x, i2c_smbus_alert_set_type level); -void i2c_slave_data_ctrl_enable(i2c_type *i2c_x, confirm_state new_state); -void i2c_pec_calculate_enable(i2c_type *i2c_x, confirm_state new_state); -void i2c_pec_transmit_enable(i2c_type *i2c_x, confirm_state new_state); -uint8_t i2c_pec_value_get(i2c_type *i2c_x); -void i2c_timeout_set(i2c_type *i2c_x, uint16_t timeout); -void i2c_timeout_detcet_set(i2c_type *i2c_x, i2c_timeout_detcet_type mode); -void i2c_timeout_enable(i2c_type *i2c_x, confirm_state new_state); -void i2c_ext_timeout_set(i2c_type *i2c_x, uint16_t timeout); -void i2c_ext_timeout_enable(i2c_type *i2c_x, confirm_state new_state); -void i2c_interrupt_enable(i2c_type *i2c_x, uint32_t source, confirm_state new_state); -flag_status i2c_interrupt_get(i2c_type *i2c_x, uint16_t source); -void i2c_dma_enable(i2c_type *i2c_x, i2c_dma_request_type dma_req, confirm_state new_state); -void i2c_transmit_set(i2c_type *i2c_x, uint16_t address, uint8_t cnt, i2c_reload_stop_mode_type rld_stop, i2c_start_stop_mode_type start_stop); -void i2c_start_generate(i2c_type *i2c_x); -void i2c_stop_generate(i2c_type *i2c_x); -void i2c_data_send(i2c_type *i2c_x, uint8_t data); -uint8_t i2c_data_receive(i2c_type *i2c_x); -flag_status i2c_flag_get(i2c_type *i2c_x, uint32_t flag); -void i2c_flag_clear(i2c_type *i2c_x, uint32_t flag); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_misc.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_misc.h deleted file mode 100644 index 9c5edaa..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_misc.h +++ /dev/null @@ -1,125 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_misc.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 misc header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_MISC_H -#define __AT32F435_437_MISC_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup MISC - * @{ - */ - -/** @defgroup MISC_vector_table_base_address - * @{ - */ - -#define NVIC_VECTTAB_RAM ((uint32_t)0x20000000) /*!< nvic vector table based ram address */ -#define NVIC_VECTTAB_FLASH ((uint32_t)0x08000000) /*!< nvic vector table based flash address */ - -/** - * @} - */ - -/** @defgroup MISC_exported_types - * @{ - */ - -/** - * @brief nvic interrupt priority group - */ -typedef enum -{ - NVIC_PRIORITY_GROUP_0 = ((uint32_t)0x7), /*!< 0 bits for preemption priority, 4 bits for subpriority */ - NVIC_PRIORITY_GROUP_1 = ((uint32_t)0x6), /*!< 1 bits for preemption priority, 3 bits for subpriority */ - NVIC_PRIORITY_GROUP_2 = ((uint32_t)0x5), /*!< 2 bits for preemption priority, 2 bits for subpriority */ - NVIC_PRIORITY_GROUP_3 = ((uint32_t)0x4), /*!< 3 bits for preemption priority, 1 bits for subpriority */ - NVIC_PRIORITY_GROUP_4 = ((uint32_t)0x3) /*!< 4 bits for preemption priority, 0 bits for subpriority */ -} nvic_priority_group_type; - -/** - * @brief nvic low power mode - */ -typedef enum -{ - NVIC_LP_SLEEPONEXIT = 0x02, /*!< send event on pending */ - NVIC_LP_SLEEPDEEP = 0x04, /*!< enable sleep-deep output signal when entering sleep mode */ - NVIC_LP_SEVONPEND = 0x10 /*!< enable sleep-on-exit feature */ -} nvic_lowpower_mode_type; - -/** - * @brief systick clock source - */ -typedef enum -{ - SYSTICK_CLOCK_SOURCE_AHBCLK_DIV8 = ((uint32_t)0x00000000), /*!< systick clock source from core clock div8 */ - SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV = ((uint32_t)0x00000004) /*!< systick clock source from core clock */ -} systick_clock_source_type; - -/** - * @} - */ - -/** @defgroup MISC_exported_functions - * @{ - */ - -void nvic_system_reset(void); -void nvic_irq_enable(uint32_t irqn, uint32_t preempt_priority, uint32_t sub_priority); -void nvic_irq_disable(uint32_t irqn); -void nvic_priority_group_config(nvic_priority_group_type priority_group); -void nvic_vector_table_set(uint32_t base, uint32_t offset); -void nvic_lowpower_mode_config(nvic_lowpower_mode_type lp_mode, confirm_state new_state); -void systick_clock_source_config(systick_clock_source_type source); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_pwc.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_pwc.h deleted file mode 100644 index 76b5e4b..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_pwc.h +++ /dev/null @@ -1,230 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_pwc.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 pwr header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_PWC_H -#define __AT32F435_437_PWC_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup PWC - * @{ - */ - -/** @defgroup PWC_flags_definition - * @brief pwc flag - * @{ - */ - -#define PWC_WAKEUP_FLAG ((uint32_t)0x00000001) /*!< wakeup flag */ -#define PWC_STANDBY_FLAG ((uint32_t)0x00000002) /*!< standby flag */ -#define PWC_PVM_OUTPUT_FLAG ((uint32_t)0x00000004) /*!< pvm output flag */ - -/** - * @} - */ - -/** - * @brief pwc wakeup pin num definition - */ -#define PWC_WAKEUP_PIN_1 ((uint32_t)0x00000100) /*!< standby wake-up pin1 */ -#define PWC_WAKEUP_PIN_2 ((uint32_t)0x00000200) /*!< standby wake-up pin2 */ - -/** - * @brief select ldo output voltage. - * @param val: set the ldo output voltage. - * this parameter can be one of the following values: - * - PWC_LDO_OUTPUT_1V2 - * - PWC_LDO_OUTPUT_1V3 - * - PWC_LDO_OUTPUT_1V1 - * - PWC_LDO_OUTPUT_1V0 - */ -#define pwc_ldo_output_voltage_set(val) (PWC->ldoov_bit.ldoovsel = val) - -/** @defgroup PWC_exported_types - * @{ - */ - -/** - * @brief pwc pvm voltage type - */ -typedef enum -{ - PWC_PVM_VOLTAGE_2V3 = 0x01, /*!< power voltage monitoring boundary 2.3v */ - PWC_PVM_VOLTAGE_2V4 = 0x02, /*!< power voltage monitoring boundary 2.4v */ - PWC_PVM_VOLTAGE_2V5 = 0x03, /*!< power voltage monitoring boundary 2.5v */ - PWC_PVM_VOLTAGE_2V6 = 0x04, /*!< power voltage monitoring boundary 2.6v */ - PWC_PVM_VOLTAGE_2V7 = 0x05, /*!< power voltage monitoring boundary 2.7v */ - PWC_PVM_VOLTAGE_2V8 = 0x06, /*!< power voltage monitoring boundary 2.8v */ - PWC_PVM_VOLTAGE_2V9 = 0x07 /*!< power voltage monitoring boundary 2.9v */ -} pwc_pvm_voltage_type; - -/** - * @brief pwc ldo output voltage type - */ -typedef enum -{ - PWC_LDO_OUTPUT_1V2 = 0x00, /*!< ldo output voltage is 1.2v */ - PWC_LDO_OUTPUT_1V3 = 0x01, /*!< ldo output voltage is 1.3v */ - PWC_LDO_OUTPUT_1V1 = 0x04, /*!< ldo output voltage is 1.1v */ - PWC_LDO_OUTPUT_1V0 = 0x05, /*!< ldo output voltage is 1.0v */ -} pwc_ldo_output_voltage_type; - -/** - * @brief pwc sleep enter type - */ -typedef enum -{ - PWC_SLEEP_ENTER_WFI = 0x00, /*!< use wfi enter sleep mode */ - PWC_SLEEP_ENTER_WFE = 0x01 /*!< use wfe enter sleep mode */ -} pwc_sleep_enter_type ; - -/** - * @brief pwc deep sleep enter type - */ -typedef enum -{ - PWC_DEEP_SLEEP_ENTER_WFI = 0x00, /*!< use wfi enter deepsleep mode */ - PWC_DEEP_SLEEP_ENTER_WFE = 0x01 /*!< use wfe enter deepsleep mode */ -} pwc_deep_sleep_enter_type ; - -/** - * @brief pwc regulator type - */ -typedef enum -{ - PWC_REGULATOR_ON = 0x00, /*!< voltage regulator state on when deepsleep mode */ - PWC_REGULATOR_LOW_POWER = 0x01 /*!< voltage regulator state low power when deepsleep mode */ -} pwc_regulator_type ; - -/** - * @brief type define pwc register all - */ -typedef struct -{ - /** - * @brief pwc ctrl register, offset:0x00 - */ - union - { - __IO uint32_t ctrl; - struct - { - __IO uint32_t vrsel : 1; /* [0] */ - __IO uint32_t lpsel : 1; /* [1] */ - __IO uint32_t clswef : 1; /* [2] */ - __IO uint32_t clsef : 1; /* [3] */ - __IO uint32_t pvmen : 1; /* [4] */ - __IO uint32_t pvmsel : 3; /* [7:5] */ - __IO uint32_t bpwen : 1; /* [8] */ - __IO uint32_t reserved1 : 23;/* [31:9] */ - } ctrl_bit; - }; - - /** - * @brief pwc ctrlsts register, offset:0x04 - */ - union - { - __IO uint32_t ctrlsts; - struct - { - __IO uint32_t swef : 1; /* [0] */ - __IO uint32_t sef : 1; /* [1] */ - __IO uint32_t pvmof : 1; /* [2] */ - __IO uint32_t reserved1 : 5; /* [7:3] */ - __IO uint32_t swpen1 : 1; /* [8] */ - __IO uint32_t swpen2 : 1; /* [9] */ - __IO uint32_t reserved2 : 22;/* [31:10] */ - } ctrlsts_bit; - }; - - __IO uint32_t reserved1[2]; - - /** - * @brief pwc ldoov register, offset:0x10 - */ - union - { - __IO uint32_t ldoov; - struct - { - __IO uint32_t ldoovsel : 3; /* [2:0] */ - __IO uint32_t reserved1 : 29;/* [31:3] */ - } ldoov_bit; - }; - -} pwc_type; - -/** - * @} - */ - -#define PWC ((pwc_type *) PWC_BASE) - -/** @defgroup PWC_exported_functions - * @{ - */ - -void pwc_reset(void); -void pwc_battery_powered_domain_access(confirm_state new_state); -void pwc_pvm_level_select(pwc_pvm_voltage_type pvm_voltage); -void pwc_power_voltage_monitor_enable(confirm_state new_state); -void pwc_wakeup_pin_enable(uint32_t pin_num, confirm_state new_state); -void pwc_flag_clear(uint32_t pwc_flag); -flag_status pwc_flag_get(uint32_t pwc_flag); -void pwc_sleep_mode_enter(pwc_sleep_enter_type pwc_sleep_enter); -void pwc_deep_sleep_mode_enter(pwc_deep_sleep_enter_type pwc_deep_sleep_enter); -void pwc_voltage_regulate_set(pwc_regulator_type pwc_regulator); -void pwc_standby_mode_enter(void); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_qspi.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_qspi.h deleted file mode 100644 index d73e823..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_qspi.h +++ /dev/null @@ -1,555 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_qspi.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 qspi header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_QSPI_H -#define __AT32F435_437_QSPI_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup QSPI - * @{ - */ - -/** @defgroup QSPI_flags_definition - * @brief qspi flag - * @{ - */ - -#define QSPI_CMDSTS_FLAG ((uint32_t)0x00000001) /*!< qspi command complete status flag */ -#define QSPI_RXFIFORDY_FLAG ((uint32_t)0x00000002) /*!< qspi rxfifo ready status flag */ -#define QSPI_TXFIFORDY_FLAG ((uint32_t)0x00000004) /*!< qspi txfifo ready status flag */ - -/** - * @} - */ - -/** @defgroup QSPI_exported_types - * @{ - */ - -/** - * @brief qspi xip read access mode type - */ -typedef enum -{ - QSPI_XIPR_SEL_MODED = 0x00, /*!< qspi xip read select mode d */ - QSPI_XIPR_SEL_MODET = 0x01 /*!< qspi xip read select mode t */ -} qspi_xip_read_sel_type; - -/** - * @brief qspi xip write access mode type - */ -typedef enum -{ - QSPI_XIPW_SEL_MODED = 0x00, /*!< qspi xip write select mode d */ - QSPI_XIPW_SEL_MODET = 0x01 /*!< qspi xip write select mode t */ -} qspi_xip_write_sel_type; - -/** - * @brief qspi busy bit offset position in status register type - */ -typedef enum -{ - QSPI_BUSY_OFFSET_0 = 0x00, /*!< qspi busy bit offset position 0 */ - QSPI_BUSY_OFFSET_1 = 0x01, /*!< qspi busy bit offset position 1 */ - QSPI_BUSY_OFFSET_2 = 0x02, /*!< qspi busy bit offset position 2 */ - QSPI_BUSY_OFFSET_3 = 0x03, /*!< qspi busy bit offset position 3 */ - QSPI_BUSY_OFFSET_4 = 0x04, /*!< qspi busy bit offset position 4 */ - QSPI_BUSY_OFFSET_5 = 0x05, /*!< qspi busy bit offset position 5 */ - QSPI_BUSY_OFFSET_6 = 0x06, /*!< qspi busy bit offset position 6 */ - QSPI_BUSY_OFFSET_7 = 0x07 /*!< qspi busy bit offset position 7 */ -} qspi_busy_pos_type; - -/** - * @brief qspi read status configure type - */ -typedef enum -{ - QSPI_RSTSC_HW_AUTO = 0x00, /*!< qspi read status by hardware */ - QSPI_RSTSC_SW_ONCE = 0x01 /*!< qspi read status by software */ -} qspi_read_status_conf_type; - -/** - * @brief qspi operate mode type - */ -typedef enum -{ - QSPI_OPERATE_MODE_111 = 0x00, /*!< qspi serial mode */ - QSPI_OPERATE_MODE_112 = 0x01, /*!< qspi dual mode */ - QSPI_OPERATE_MODE_114 = 0x02, /*!< qspi quad mode */ - QSPI_OPERATE_MODE_122 = 0x03, /*!< qspi dual i/o mode */ - QSPI_OPERATE_MODE_144 = 0x04, /*!< qspi quad i/o mode */ - QSPI_OPERATE_MODE_222 = 0x05, /*!< qspi instruction 2-bit mode */ - QSPI_OPERATE_MODE_444 = 0x06 /*!< qspi instruction 4-bit mode(qpi) */ -} qspi_operate_mode_type; - -/** - * @brief qspi clock division type - */ -typedef enum -{ - QSPI_CLK_DIV_2 = 0x00, /*!< qspi clk divide by 2 */ - QSPI_CLK_DIV_4 = 0x01, /*!< qspi clk divide by 4 */ - QSPI_CLK_DIV_6 = 0x02, /*!< qspi clk divide by 6 */ - QSPI_CLK_DIV_8 = 0x03, /*!< qspi clk divide by 8 */ - QSPI_CLK_DIV_3 = 0x04, /*!< qspi clk divide by 3 */ - QSPI_CLK_DIV_5 = 0x05, /*!< qspi clk divide by 5 */ - QSPI_CLK_DIV_10 = 0x06, /*!< qspi clk divide by 10 */ - QSPI_CLK_DIV_12 = 0x07 /*!< qspi clk divide by 12 */ -} qspi_clk_div_type; - -/** - * @brief qspi command port address length type - */ -typedef enum -{ - QSPI_CMD_ADRLEN_0_BYTE = 0x00, /*!< qspi no address */ - QSPI_CMD_ADRLEN_1_BYTE = 0x01, /*!< qspi address length 1 byte */ - QSPI_CMD_ADRLEN_2_BYTE = 0x02, /*!< qspi address length 2 byte */ - QSPI_CMD_ADRLEN_3_BYTE = 0x03, /*!< qspi address length 3 byte */ - QSPI_CMD_ADRLEN_4_BYTE = 0x04 /*!< qspi address length 4 byte */ -} qspi_cmd_adrlen_type; - -/** - * @brief qspi command port instruction length type - */ -typedef enum -{ - QSPI_CMD_INSLEN_0_BYTE = 0x00, /*!< qspi no instruction code */ - QSPI_CMD_INSLEN_1_BYTE = 0x01, /*!< qspi instruction code 1 byte */ - QSPI_CMD_INSLEN_2_BYTE = 0x02 /*!< qspi instruction code 2 byte(repeat) */ -} qspi_cmd_inslen_type; - -/** - * @brief qspi xip r/w address length type - */ -typedef enum -{ - QSPI_XIP_ADDRLEN_3_BYTE = 0x00, /*!< qspi xip address length 3 byte */ - QSPI_XIP_ADDRLEN_4_BYTE = 0x01 /*!< qspi xip address length 4 byte */ -} qspi_xip_addrlen_type; - -/** - * @brief qspi sckout mode type - */ -typedef enum -{ - QSPI_SCK_MODE_0 = 0x00, /*!< qspi sck mode 0 */ - QSPI_SCK_MODE_3 = 0x01 /*!< qspi sck mode 3 */ -} qspi_clk_mode_type; - -/** - * @brief qspi dma tx/rx fifo threshold type - */ -typedef enum -{ - QSPI_DMA_FIFO_THOD_WORD08 = 0x00, /*!< qspi dma fifo threshold 8 words */ - QSPI_DMA_FIFO_THOD_WORD16 = 0x01, /*!< qspi dma fifo threshold 16 words */ - QSPI_DMA_FIFO_THOD_WORD32 = 0x02 /*!< qspi dma fifo threshold 32 words */ -} qspi_dma_fifo_thod_type; - -/** - * @brief qspi cmd type - */ -typedef struct -{ - confirm_state pe_mode_enable; /*!< perfornance enhance mode enable */ - uint8_t pe_mode_operate_code; /*!< performance enhance mode operate code */ - uint8_t instruction_code; /*!< instruction code */ - qspi_cmd_inslen_type instruction_length; /*!< instruction code length */ - uint32_t address_code; /*!< address code */ - qspi_cmd_adrlen_type address_length; /*!< address legnth */ - uint32_t data_counter; /*!< read/write data counter */ - uint8_t second_dummy_cycle_num; /*!< number of second dummy state cycle 0~32 */ - qspi_operate_mode_type operation_mode; /*!< operation mode */ - qspi_read_status_conf_type read_status_config; /*!< config to read status */ - confirm_state read_status_enable; /*!< config to read status */ - confirm_state write_data_enable; /*!< enable to write data */ -} qspi_cmd_type; - -/** - * @brief qspi xip type - */ -typedef struct -{ - uint8_t read_instruction_code; /*!< read instruction code */ - qspi_xip_addrlen_type read_address_length; /*!< read address legnth */ - qspi_operate_mode_type read_operation_mode; /*!< read operation mode */ - uint8_t read_second_dummy_cycle_num; /*!< read number of second dummy state cycle 0~32 */ - uint8_t write_instruction_code; /*!< write instruction code */ - qspi_xip_addrlen_type write_address_length; /*!< write address legnth */ - qspi_operate_mode_type write_operation_mode; /*!< write operation mode */ - uint8_t write_second_dummy_cycle_num; /*!< write number of second dummy state cycle 0~32 */ - qspi_xip_write_sel_type write_select_mode; /*!< write mode d or mode t selection */ - uint8_t write_time_counter; /*!< write count for mode t */ - uint8_t write_data_counter; /*!< write count for mode d */ - qspi_xip_read_sel_type read_select_mode; /*!< read mode d or mode t selection */ - uint8_t read_time_counter; /*!< read count for mode t */ - uint8_t read_data_counter; /*!< read count for mode d */ -} qspi_xip_type; - -/** - * @brief type define qspi register all - */ -typedef struct -{ - /** - * @brief qspi cmd_w0 register, offset:0x00 - */ - union - { - __IO uint32_t cmd_w0; - struct - { - - __IO uint32_t spiadr : 32;/* [31:0] */ - } cmd_w0_bit; - }; - - /** - * @brief qspi cmd_w1 register, offset:0x04 - */ - union - { - __IO uint32_t cmd_w1; - struct - { - __IO uint32_t adrlen : 3; /* [2:0] */ - __IO uint32_t reserved1 : 13;/* [15:3] */ - __IO uint32_t dum2 : 8; /* [23:16] */ - __IO uint32_t inslen : 2; /* [25:24] */ - __IO uint32_t reserved2 : 2; /* [27:26] */ - __IO uint32_t pemen : 1; /* [28] */ - __IO uint32_t reserved3 : 3; /* [31:29] */ - } cmd_w1_bit; - }; - - /** - * @brief qspi cmd_w2 register, offset:0x08 - */ - union - { - __IO uint32_t cmd_w2; - struct - { - __IO uint32_t dcnt : 32;/* [31:0] */ - } cmd_w2_bit; - }; - - /** - * @brief qspi cmd_w3 register, offset:0x0C - */ - union - { - __IO uint32_t cmd_w3; - struct - { - __IO uint32_t reserved1 : 1; /* [0] */ - __IO uint32_t wen : 1; /* [1] */ - __IO uint32_t rstsen : 1; /* [2] */ - __IO uint32_t rstsc : 1; /* [3] */ - __IO uint32_t reserved2 : 1; /* [4] */ - __IO uint32_t opmode : 3; /* [7:5] */ - __IO uint32_t reserved3 : 8; /* [15:8] */ - __IO uint32_t pemopc : 8; /* [23:16] */ - __IO uint32_t insc : 8; /* [31:24] */ - } cmd_w3_bit; - }; - - /** - * @brief qspi ctrl register, offset:0x10 - */ - union - { - __IO uint32_t ctrl; - struct - { - __IO uint32_t clkdiv : 3; /* [2:0] */ - __IO uint32_t reserved1 : 1; /* [3] */ - __IO uint32_t sckmode : 1; /* [4] */ - __IO uint32_t reserved2 : 2; /* [6:5] */ - __IO uint32_t xipidle : 1; /* [7] */ - __IO uint32_t abort : 1; /* [8] */ - __IO uint32_t reserved3 : 7; /* [15:9] */ - __IO uint32_t busy : 3; /* [18:16] */ - __IO uint32_t xiprcmdf : 1; /* [19] */ - __IO uint32_t xipsel : 1; /* [20] */ - __IO uint32_t keyen : 1; /* [21] */ - __IO uint32_t reserved4 : 10;/* [31:22] */ - } ctrl_bit; - }; - - /** - * @brief qspi actr register, offset:0x14 - */ - union - { - __IO uint32_t actr; - struct - { - __IO uint32_t csdly : 4; /* [3:0] */ - __IO uint32_t reserved1 : 28;/* [31:4] */ - } actr_bit; - }; - - /** - * @brief qspi fifosts register, offset:0x18 - */ - union - { - __IO uint32_t fifosts; - struct - { - __IO uint32_t txfifordy : 1; /* [0] */ - __IO uint32_t rxfifordy : 1; /* [1] */ - __IO uint32_t reserved1 : 30;/* [31:2] */ - } fifosts_bit; - }; - - /** - * @brief qspi reserved register, offset:0x1C - */ - __IO uint32_t reserved1; - - /** - * @brief qspi ctrl2 register, offset:0x20 - */ - union - { - __IO uint32_t ctrl2; - struct - { - __IO uint32_t dmaen : 1; /* [0] */ - __IO uint32_t cmdie : 1; /* [1] */ - __IO uint32_t reserved1 : 6; /* [7:2] */ - __IO uint32_t txfifo_thod : 2; /* [9:8] */ - __IO uint32_t reserved2 : 2; /* [11:10] */ - __IO uint32_t rxfifo_thod : 2; /* [13:12] */ - __IO uint32_t reserved3 : 18;/* [31:14] */ - } ctrl2_bit; - }; - - /** - * @brief qspi cmdsts register, offset:0x24 - */ - union - { - __IO uint32_t cmdsts; - struct - { - __IO uint32_t cmdsts : 1; /* [0] */ - __IO uint32_t reserved1 : 31;/* [31:1] */ - } cmdsts_bit; - }; - - /** - * @brief qspi rsts register, offset:0x28 - */ - union - { - __IO uint32_t rsts; - struct - { - __IO uint32_t spists : 8; /* [7:0] */ - __IO uint32_t reserved1 : 24;/* [31:8] */ - } rsts_bit; - }; - - /** - * @brief qspi fsize register, offset:0x2C - */ - union - { - __IO uint32_t fsize; - struct - { - __IO uint32_t spifsize : 32;/* [31:0] */ - } fsize_bit; - }; - - /** - * @brief qspi xip_cmd_w0 register, offset:0x30 - */ - union - { - __IO uint32_t xip_cmd_w0; - struct - { - __IO uint32_t xipr_dum2 : 8; /* [7:0] */ - __IO uint32_t xipr_opmode : 3; /* [10:8] */ - __IO uint32_t xipr_adrlen : 1; /* [11] */ - __IO uint32_t xipr_insc : 8; /* [19:12] */ - __IO uint32_t reserved1 : 12;/* [31:20] */ - } xip_cmd_w0_bit; - }; - - /** - * @brief qspi xip_cmd_w1 register, offset:0x34 - */ - union - { - __IO uint32_t xip_cmd_w1; - struct - { - __IO uint32_t xipr_dum2 : 8; /* [7:0] */ - __IO uint32_t xipr_opmode : 3; /* [10:8] */ - __IO uint32_t xipr_adrlen : 1; /* [11] */ - __IO uint32_t xipr_insc : 8; /* [19:12] */ - __IO uint32_t reserved1 : 12;/* [31:20] */ - } xip_cmd_w1_bit; - }; - - /** - * @brief qspi xip_cmd_w2 register, offset:0x38 - */ - union - { - __IO uint32_t xip_cmd_w2; - struct - { - __IO uint32_t xipr_dcnt : 6; /* [5:0] */ - __IO uint32_t reserved1 : 2; /* [7:6] */ - __IO uint32_t xipr_tcnt : 7; /* [14:8] */ - __IO uint32_t xipr_sel : 1; /* [15] */ - __IO uint32_t xipw_dcnt : 6; /* [21:16] */ - __IO uint32_t reserved2 : 2; /* [23:22] */ - __IO uint32_t xipw_tcnt : 7; /* [30:24] */ - __IO uint32_t xipw_sel : 1; /* [31] */ - } xip_cmd_w2_bit; - }; - - /** - * @brief qspi xip_cmd_w3 register, offset:0x3C - */ - union - { - __IO uint32_t xip_cmd_w3; - struct - { - __IO uint32_t bypassc : 1; /* [0] */ - __IO uint32_t reserved1 : 2; /* [2:1] */ - __IO uint32_t csts : 1; /* [3] */ - __IO uint32_t reserved2 : 28;/* [31:4] */ - } xip_cmd_w3_bit; - }; - - /** - * @brief qspi reserved register, offset:0x40~4C - */ - __IO uint32_t reserved2[4]; - - /** - * @brief qspi rev register, offset:0x50 - */ - union - { - __IO uint32_t rev; - struct - { - __IO uint32_t rev : 32;/* [31:0] */ - } rev_bit; - }; - - /** - * @brief qspi reserved register, offset:0x54~FC - */ - __IO uint32_t reserved3[43]; - - /** - * @brief qspi dt register, offset:0x100 - */ - union - { - __IO uint8_t dt_u8; - __IO uint16_t dt_u16; - __IO uint32_t dt; - struct - { - __IO uint32_t dt : 32;/* [31:0] */ - } dt_bit; - }; - -} qspi_type; - -/** - * @} - */ - -#define QSPI1 ((qspi_type*)QSPI1_REG_BASE) -#define QSPI2 ((qspi_type*)QSPI2_REG_BASE) - -/** @defgroup QSPI_exported_functions - * @{ - */ - -void qspi_encryption_enable(qspi_type* qspi_x, confirm_state new_state); -void qspi_sck_mode_set( qspi_type* qspi_x, qspi_clk_mode_type new_mode); -void qspi_clk_division_set(qspi_type* qspi_x, qspi_clk_div_type new_clkdiv); -void qspi_xip_cache_bypass_set(qspi_type* qspi_x, confirm_state new_state); -void qspi_interrupt_enable(qspi_type* qspi_x, confirm_state new_state); -flag_status qspi_flag_get(qspi_type* qspi_x, uint32_t flag); -void qspi_flag_clear( qspi_type* qspi_x, uint32_t flag); -void qspi_dma_rx_threshold_set(qspi_type* qspi_x, qspi_dma_fifo_thod_type new_threshold); -void qspi_dma_tx_threshold_set(qspi_type* qspi_x, qspi_dma_fifo_thod_type new_threshold); -void qspi_dma_enable(qspi_type* qspi_x, confirm_state new_state); -void qspi_busy_config(qspi_type* qspi_x, qspi_busy_pos_type busy_pos); -void qspi_xip_enable(qspi_type* qspi_x, confirm_state new_state); -void qspi_cmd_operation_kick(qspi_type* qspi_x, qspi_cmd_type* qspi_cmd_struct); -void qspi_xip_init(qspi_type* qspi_x, qspi_xip_type* xip_init_struct); -uint8_t qspi_byte_read(qspi_type* qspi_x); -uint16_t qspi_half_word_read(qspi_type* qspi_x); -uint32_t qspi_word_read(qspi_type* qspi_x); -void qspi_word_write(qspi_type* qspi_x, uint32_t value); -void qspi_half_word_write(qspi_type* qspi_x, uint16_t value); -void qspi_byte_write(qspi_type* qspi_x, uint8_t value); -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_scfg.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_scfg.h deleted file mode 100644 index 332098f..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_scfg.h +++ /dev/null @@ -1,323 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_scfg.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 system config header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_SCFG_H -#define __AT32F435_437_SCFG_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup SCFG - * @{ - */ - -#define SCFG_REG(value) PERIPH_REG(SCFG_BASE, value) -#define SCFG_REG_BIT(value) PERIPH_REG_BIT(value) - -/** @defgroup SCFG_exported_types - * @{ - */ - -/** - * @brief scfg xmc addres mapping swap type - */ -typedef enum -{ - SCFG_XMC_SWAP_NONE = 0x00, /* no swap */ - SCFG_XMC_SWAP_MODE1 = 0x01, /* sdram nor psram sram nand2 swap */ - SCFG_XMC_SWAP_MODE2 = 0x02, /* nand3 qspi2 swap */ - SCFG_XMC_SWAP_MODE3 = 0x03 /* sdram nor psram sram nand2 nand3 qspi2 swap */ -} scfg_xmc_swap_type; - -/** - * @brief scfg infrared modulation signal source selecting type - */ -typedef enum -{ - SCFG_IR_SOURCE_TMR10 = 0x00, /* infrared signal source select tmr10 */ - SCFG_IR_SOURCE_USART1 = 0x01, /* infrared signal source select usart1 */ - SCFG_IR_SOURCE_USART2 = 0x02 /* infrared signal source select usart2 */ -} scfg_ir_source_type; - -/** - * @brief scfg infrared output polarity selecting type - */ -typedef enum -{ - SCFG_IR_POLARITY_NO_AFFECTE = 0x00, /* infrared output polarity no affecte */ - SCFG_IR_POLARITY_REVERSE = 0x01 /* infrared output polarity reverse */ -} scfg_ir_polarity_type; - -/** - * @brief scfg memory address mapping selecting type - */ -typedef enum -{ - SCFG_MEM_MAP_MAIN_MEMORY = 0x00, /* 0x00000000 address mapping from main memory */ - SCFG_MEM_MAP_BOOT_MEMORY = 0x01, /* 0x00000000 address mapping from boot memory */ - SCFG_MEM_MAP_XMC_BANK1 = 0x02, /* 0x00000000 address mapping from xmc bank1 */ - SCFG_MEM_MAP_INTERNAL_SRAM = 0x03, /* 0x00000000 address mapping from internal sram */ - SCFG_MEM_MAP_XMC_SDRAM_BANK1 = 0x04 /* 0x00000000 address mapping from xmc sdram bank1 */ -} scfg_mem_map_type; - -/** - * @brief scfg pin source type - */ -typedef enum -{ - SCFG_PINS_SOURCE0 = 0x00, - SCFG_PINS_SOURCE1 = 0x01, - SCFG_PINS_SOURCE2 = 0x02, - SCFG_PINS_SOURCE3 = 0x03, - SCFG_PINS_SOURCE4 = 0x04, - SCFG_PINS_SOURCE5 = 0x05, - SCFG_PINS_SOURCE6 = 0x06, - SCFG_PINS_SOURCE7 = 0x07, - SCFG_PINS_SOURCE8 = 0x08, - SCFG_PINS_SOURCE9 = 0x09, - SCFG_PINS_SOURCE10 = 0x0A, - SCFG_PINS_SOURCE11 = 0x0B, - SCFG_PINS_SOURCE12 = 0x0C, - SCFG_PINS_SOURCE13 = 0x0D, - SCFG_PINS_SOURCE14 = 0x0E, - SCFG_PINS_SOURCE15 = 0x0F -} scfg_pins_source_type; - -/** - * @brief gpio port source type - */ -typedef enum -{ - SCFG_PORT_SOURCE_GPIOA = 0x00, - SCFG_PORT_SOURCE_GPIOB = 0x01, - SCFG_PORT_SOURCE_GPIOC = 0x02, - SCFG_PORT_SOURCE_GPIOD = 0x03, - SCFG_PORT_SOURCE_GPIOE = 0x04, - SCFG_PORT_SOURCE_GPIOF = 0x05, - SCFG_PORT_SOURCE_GPIOG = 0x06, - SCFG_PORT_SOURCE_GPIOH = 0x07 -} scfg_port_source_type; - -/** - * @brief scfg emac interface selecting type - */ -typedef enum -{ - SCFG_EMAC_SELECT_MII = 0x00, /* emac interface select mii mode */ - SCFG_EMAC_SELECT_RMII = 0x01 /* emac interface select rmii mode */ -} scfg_emac_interface_type; - -/** - * @brief scfg ultra high sourcing/sinking strength pins type - */ -typedef enum -{ - SCFG_ULTRA_DRIVEN_PB3 = MAKE_VALUE(0x2C, 0), - SCFG_ULTRA_DRIVEN_PB9 = MAKE_VALUE(0x2C, 1), - SCFG_ULTRA_DRIVEN_PB10 = MAKE_VALUE(0x2C, 2), - SCFG_ULTRA_DRIVEN_PD12 = MAKE_VALUE(0x2C, 5), - SCFG_ULTRA_DRIVEN_PD13 = MAKE_VALUE(0x2C, 6), - SCFG_ULTRA_DRIVEN_PD14 = MAKE_VALUE(0x2C, 7), - SCFG_ULTRA_DRIVEN_PD15 = MAKE_VALUE(0x2C, 8), - SCFG_ULTRA_DRIVEN_PF14 = MAKE_VALUE(0x2C, 9), - SCFG_ULTRA_DRIVEN_PF15 = MAKE_VALUE(0x2C, 10) -} scfg_ultra_driven_pins_type; - -/** - * @brief type define system config register all - */ -typedef struct -{ - /** - * @brief scfg cfg1 register, offset:0x00 - */ - union - { - __IO uint32_t cfg1; - struct - { - __IO uint32_t mem_map_sel : 3; /* [2:0] */ - __IO uint32_t reserved1 : 2; /* [4:3] */ - __IO uint32_t ir_pol : 1; /* [5] */ - __IO uint32_t ir_src_sel : 2; /* [7:6] */ - __IO uint32_t reserved2 : 2; /* [9:8] */ - __IO uint32_t swap_xmc : 2; /* [11:10] */ - __IO uint32_t reserved3 : 20;/* [31:12] */ - } cfg1_bit; - }; - - /** - * @brief scfg cfg2 register, offset:0x04 - */ - union - { - __IO uint32_t cfg2; - struct - { - __IO uint32_t reserved1 : 23;/* [22:0] */ - __IO uint32_t mii_rmii_sel : 1; /* [23] */ - __IO uint32_t reserved2 : 8; /* [31:24] */ - } cfg2_bit; - }; - - /** - * @brief scfg exintc1 register, offset:0x08 - */ - union - { - __IO uint32_t exintc1; - struct - { - __IO uint32_t exint0 : 4; /* [3:0] */ - __IO uint32_t exint1 : 4; /* [7:4] */ - __IO uint32_t exint2 : 4; /* [11:8] */ - __IO uint32_t exint3 : 4; /* [15:12] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } exintc1_bit; - }; - - /** - * @brief scfg exintc2 register, offset:0x0C - */ - union - { - __IO uint32_t exintc2; - struct - { - __IO uint32_t exint4 : 4; /* [3:0] */ - __IO uint32_t exint5 : 4; /* [7:4] */ - __IO uint32_t exint6 : 4; /* [11:8] */ - __IO uint32_t exint7 : 4; /* [15:12] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } exintc2_bit; - }; - - /** - * @brief scfg exintc3 register, offset:0x10 - */ - union - { - __IO uint32_t exintc3; - struct - { - __IO uint32_t exint8 : 4; /* [3:0] */ - __IO uint32_t exint9 : 4; /* [7:4] */ - __IO uint32_t exint10 : 4; /* [11:8] */ - __IO uint32_t exint11 : 4; /* [15:12] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } exintc3_bit; - }; - - /** - * @brief scfg exintc4 register, offset:0x14 - */ - union - { - __IO uint32_t exintc4; - struct - { - __IO uint32_t exint12 : 4; /* [3:0] */ - __IO uint32_t exint13 : 4; /* [7:4] */ - __IO uint32_t exint14 : 4; /* [11:8] */ - __IO uint32_t exint15 : 4; /* [15:12] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } exintc4_bit; - }; - - /** - * @brief crm reserved1 register, offset:0x18~0x28 - */ - __IO uint32_t reserved1[5]; - - /** - * @brief scfg uhdrv register, offset:0x2C - */ - union - { - __IO uint32_t uhdrv; - struct - { - __IO uint32_t pb3_uh : 1; /* [0] */ - __IO uint32_t pb9_uh : 1; /* [1] */ - __IO uint32_t pb10_uh : 1; /* [2] */ - __IO uint32_t reserved1 : 2; /* [4:3] */ - __IO uint32_t pd12_uh : 1; /* [5] */ - __IO uint32_t pd13_uh : 1; /* [6] */ - __IO uint32_t pd14_uh : 1; /* [7] */ - __IO uint32_t pd15_uh : 1; /* [8] */ - __IO uint32_t pf14_uh : 1; /* [9] */ - __IO uint32_t pf15_uh : 1; /* [10] */ - __IO uint32_t reserved2 : 21;/* [31:11] */ - } uhdrv_bit; - }; - -} scfg_type; - -/** - * @} - */ - -#define SCFG ((scfg_type *) SCFG_BASE) - -/** @defgroup SCFG_exported_functions - * @{ - */ - -void scfg_reset(void); -void scfg_xmc_mapping_swap_set(scfg_xmc_swap_type xmc_swap); -void scfg_infrared_config(scfg_ir_source_type source, scfg_ir_polarity_type polarity); -void scfg_mem_map_set(scfg_mem_map_type mem_map); -void scfg_emac_interface_set(scfg_emac_interface_type mode); -void scfg_exint_line_config(scfg_port_source_type port_source, scfg_pins_source_type pin_source); -void scfg_pins_ultra_driven_enable(scfg_ultra_driven_pins_type value, confirm_state new_state); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_sdio.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_sdio.h deleted file mode 100644 index babd040..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_sdio.h +++ /dev/null @@ -1,624 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_sdio.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 sdio header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_SDIO_H -#define __AT32F435_437_SDIO_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup SDIO - * @{ - */ - -/** @defgroup SDIO_interrupts_definition - * @brief sdio interrupt - * @{ - */ - -#define SDIO_CMDFAIL_INT ((uint32_t)0x00000001) /*!< command response received check failed interrupt */ -#define SDIO_DTFAIL_INT ((uint32_t)0x00000002) /*!< data block sent/received check failed interrupt */ -#define SDIO_CMDTIMEOUT_INT ((uint32_t)0x00000004) /*!< command response timerout interrupt */ -#define SDIO_DTTIMEOUT_INT ((uint32_t)0x00000008) /*!< data timeout interrupt */ -#define SDIO_TXERRU_INT ((uint32_t)0x00000010) /*!< transmit underrun error interrupt */ -#define SDIO_RXERRO_INT ((uint32_t)0x00000020) /*!< received overrun error interrupt */ -#define SDIO_CMDRSPCMPL_INT ((uint32_t)0x00000040) /*!< command response received interrupt */ -#define SDIO_CMDCMPL_INT ((uint32_t)0x00000080) /*!< command sent interrupt */ -#define SDIO_DTCMP_INT ((uint32_t)0x00000100) /*!< data sent interrupt */ -#define SDIO_SBITERR_INT ((uint32_t)0x00000200) /*!< start bit not detected on data bus interrupt */ -#define SDIO_DTBLKCMPL_INT ((uint32_t)0x00000400) /*!< data block sent/received interrupt */ -#define SDIO_DOCMD_INT ((uint32_t)0x00000800) /*!< command transfer in progress interrupt */ -#define SDIO_DOTX_INT ((uint32_t)0x00001000) /*!< data transmit in progress interrupt */ -#define SDIO_DORX_INT ((uint32_t)0x00002000) /*!< data receive in progress interrupt */ -#define SDIO_TXBUFH_INT ((uint32_t)0x00004000) /*!< transmit buf half empty interrupt */ -#define SDIO_RXBUFH_INT ((uint32_t)0x00008000) /*!< receive buf half full interrupt */ -#define SDIO_TXBUFF_INT ((uint32_t)0x00010000) /*!< transmit buf full interrupt */ -#define SDIO_RXBUFF_INT ((uint32_t)0x00020000) /*!< receive buf full interrupt */ -#define SDIO_TXBUFE_INT ((uint32_t)0x00040000) /*!< transmit buf empty interrupt */ -#define SDIO_RXBUFE_INT ((uint32_t)0x00080000) /*!< receive buf empty interrupt */ -#define SDIO_TXBUF_INT ((uint32_t)0x00100000) /*!< data available in transmit interrupt */ -#define SDIO_RXBUF_INT ((uint32_t)0x00200000) /*!< data available in receive interrupt */ -#define SDIO_SDIOIF_INT ((uint32_t)0x00400000) /*!< sdio interface received interrupt */ - -/** - * @} - */ - -/** @defgroup SDIO_flags_definition - * @brief sdio flag - * @{ - */ - -#define SDIO_CMDFAIL_FLAG ((uint32_t)0x00000001) /*!< command response received check failed flag */ -#define SDIO_DTFAIL_FLAG ((uint32_t)0x00000002) /*!< data block sent/received check failed flag */ -#define SDIO_CMDTIMEOUT_FLAG ((uint32_t)0x00000004) /*!< command response timerout flag */ -#define SDIO_DTTIMEOUT_FLAG ((uint32_t)0x00000008) /*!< data timeout flag */ -#define SDIO_TXERRU_FLAG ((uint32_t)0x00000010) /*!< transmit underrun error flag */ -#define SDIO_RXERRO_FLAG ((uint32_t)0x00000020) /*!< received overrun error flag */ -#define SDIO_CMDRSPCMPL_FLAG ((uint32_t)0x00000040) /*!< command response received flag */ -#define SDIO_CMDCMPL_FLAG ((uint32_t)0x00000080) /*!< command sent flag */ -#define SDIO_DTCMPL_FLAG ((uint32_t)0x00000100) /*!< data sent flag */ -#define SDIO_SBITERR_FLAG ((uint32_t)0x00000200) /*!< start bit not detected on data bus flag */ -#define SDIO_DTBLKCMPL_FLAG ((uint32_t)0x00000400) /*!< data block sent/received flag */ -#define SDIO_DOCMD_FLAG ((uint32_t)0x00000800) /*!< command transfer in progress flag */ -#define SDIO_DOTX_FLAG ((uint32_t)0x00001000) /*!< data transmit in progress flag */ -#define SDIO_DORX_FLAG ((uint32_t)0x00002000) /*!< data receive in progress flag */ -#define SDIO_TXBUFH_FLAG ((uint32_t)0x00004000) /*!< transmit buf half empty flag */ -#define SDIO_RXBUFH_FLAG ((uint32_t)0x00008000) /*!< receive buf half full flag */ -#define SDIO_TXBUFF_FLAG ((uint32_t)0x00010000) /*!< transmit buf full flag */ -#define SDIO_RXBUFF_FLAG ((uint32_t)0x00020000) /*!< receive buf full flag */ -#define SDIO_TXBUFE_FLAG ((uint32_t)0x00040000) /*!< transmit buf empty flag */ -#define SDIO_RXBUFE_FLAG ((uint32_t)0x00080000) /*!< receive buf empty flag */ -#define SDIO_TXBUF_FLAG ((uint32_t)0x00100000) /*!< data available in transmit flag */ -#define SDIO_RXBUF_FLAG ((uint32_t)0x00200000) /*!< data available in receive flag */ -#define SDIO_SDIOIF_FLAG ((uint32_t)0x00400000) /*!< sdio interface received flag */ - -/** - * @} - */ - -/** @defgroup SDIO_exported_types - * @{ - */ - -/** - * @brief sdio power state - */ -typedef enum -{ - SDIO_POWER_OFF = 0x00, /*!< power-off, clock to card is stopped */ - SDIO_POWER_ON = 0x03 /*!< power-on, the card is clocked */ -} sdio_power_state_type; - -/** - * @brief sdio edge phase - */ -typedef enum -{ - SDIO_CLOCK_EDGE_RISING = 0x00, /*!< sdio bus clock generated on the rising edge of the master clock */ - SDIO_CLOCK_EDGE_FALLING = 0x01 /*!< sdio bus clock generated on the falling edge of the master clock */ -} sdio_edge_phase_type; - -/** - * @brief sdio bus width - */ -typedef enum -{ - SDIO_BUS_WIDTH_D1 = 0x00, /*!< sdio wide bus select 1-bit */ - SDIO_BUS_WIDTH_D4 = 0x01, /*!< sdio wide bus select 4-bit */ - SDIO_BUS_WIDTH_D8 = 0x02 /*!< sdio wide bus select 8-bit */ -} sdio_bus_width_type; - -/** - * @brief sdio response type - */ -typedef enum -{ - SDIO_RESPONSE_NO = 0x00, /*!< no response */ - SDIO_RESPONSE_SHORT = 0x01, /*!< short response */ - SDIO_RESPONSE_LONG = 0x03 /*!< long response */ -} sdio_reponse_type; - -/** - * @brief sdio wait type - */ -typedef enum -{ - SDIO_WAIT_FOR_NO = 0x00, /*!< no wait */ - SDIO_WAIT_FOR_INT = 0x01, /*!< wait interrupt request */ - SDIO_WAIT_FOR_PEND = 0x02 /*!< wait end of transfer */ -} sdio_wait_type; - -/** - * @brief sdio response register index - */ -typedef enum -{ - SDIO_RSP1_INDEX = 0x00, /*!< response index 1, corresponding to sdio_rsp register 1 */ - SDIO_RSP2_INDEX = 0x01, /*!< response index 2, corresponding to sdio_rsp register 2 */ - SDIO_RSP3_INDEX = 0x02, /*!< response index 3, corresponding to sdio_rsp register 3 */ - SDIO_RSP4_INDEX = 0x03 /*!< response index 4, corresponding to sdio_rsp register 4 */ -} sdio_rsp_index_type; - -/** - * @brief sdio data block size - */ -typedef enum -{ - SDIO_DATA_BLOCK_SIZE_1B = 0x00, /*!< data block size 1 byte */ - SDIO_DATA_BLOCK_SIZE_2B = 0x01, /*!< data block size 2 bytes */ - SDIO_DATA_BLOCK_SIZE_4B = 0x02, /*!< data block size 4 bytes */ - SDIO_DATA_BLOCK_SIZE_8B = 0x03, /*!< data block size 8 bytes */ - SDIO_DATA_BLOCK_SIZE_16B = 0x04, /*!< data block size 16 bytes */ - SDIO_DATA_BLOCK_SIZE_32B = 0x05, /*!< data block size 32 bytes */ - SDIO_DATA_BLOCK_SIZE_64B = 0x06, /*!< data block size 64 bytes */ - SDIO_DATA_BLOCK_SIZE_128B = 0x07, /*!< data block size 128 bytes */ - SDIO_DATA_BLOCK_SIZE_256B = 0x08, /*!< data block size 256 bytes */ - SDIO_DATA_BLOCK_SIZE_512B = 0x09, /*!< data block size 512 bytes */ - SDIO_DATA_BLOCK_SIZE_1024B = 0x0A, /*!< data block size 1024 bytes */ - SDIO_DATA_BLOCK_SIZE_2048B = 0x0B, /*!< data block size 2048 bytes */ - SDIO_DATA_BLOCK_SIZE_4096B = 0x0C, /*!< data block size 4096 bytes */ - SDIO_DATA_BLOCK_SIZE_8192B = 0x0D, /*!< data block size 8192 bytes */ - SDIO_DATA_BLOCK_SIZE_16384B = 0x0E /*!< data block size 16384 bytes */ -} sdio_block_size_type; - -/** - * @brief sdio data transfer mode - */ -typedef enum -{ - SDIO_DATA_BLOCK_TRANSFER = 0x00, /*!< the sdio block transfer mode */ - SDIO_DATA_STREAM_TRANSFER = 0x01 /*!< the sdio stream transfer mode */ -} sdio_transfer_mode_type; - -/** - * @brief sdio data transfer direction - */ -typedef enum -{ - SDIO_DATA_TRANSFER_TO_CARD = 0x00, /*!< the sdio controller write */ - SDIO_DATA_TRANSFER_TO_CONTROLLER = 0x01 /*!< the sdio controller read */ -} sdio_transfer_direction_type; - -/** - * @brief sdio read wait mode - */ -typedef enum -{ - SDIO_READ_WAIT_CONTROLLED_BY_D2 = 0x00, /*!< the sdio read wait on data2 line */ - SDIO_READ_WAIT_CONTROLLED_BY_CK = 0x01 /*!< the sdio read wait on clock line */ -} sdio_read_wait_mode_type; - -/** - * @brief sdio command structure - */ -typedef struct -{ - uint32_t argument; /*!< the sdio command argument is sent to a card as part of command message */ - uint8_t cmd_index; /*!< the sdio command index */ - sdio_reponse_type rsp_type; /*!< the sdio response type */ - sdio_wait_type wait_type; /*!< the sdio wait for interrupt request is enabled or disable */ -} sdio_command_struct_type; - -/** - * @brief sdio data structure - */ -typedef struct -{ - uint32_t timeout; /*!< the sdio data timeout period in car bus clock periods */ - uint32_t data_length; /*!< the sdio data length */ - sdio_block_size_type block_size; /*!< the sdio data block size of block transfer mode */ - sdio_transfer_mode_type transfer_mode; /*!< the sdio transfer mode, block or stream */ - sdio_transfer_direction_type transfer_direction; /*!< the sdio data transfer direction */ -} sdio_data_struct_type; - -/** - * @brief type define sdio register all - */ -typedef struct -{ - /** - * @brief sdio pwrctrl register, offset:0x00 - */ - union - { - __IO uint32_t pwrctrl; - struct - { - __IO uint32_t ps : 2; /* [1:0] */ - __IO uint32_t reserved1 : 30;/* [31:2] */ - } pwrctrl_bit; - }; - - /** - * @brief sdio clkctrl register, offset:0x04 - */ - union - { - __IO uint32_t clkctrl; - struct - { - __IO uint32_t clkdiv_l : 8; /* [7:0] */ - __IO uint32_t clkoen : 1; /* [8] */ - __IO uint32_t pwrsven : 1; /* [9] */ - __IO uint32_t bypsen : 1; /* [10] */ - __IO uint32_t busws : 2; /* [12:11] */ - __IO uint32_t clkegs : 1; /* [13] */ - __IO uint32_t hfcen : 1; /* [14] */ - __IO uint32_t clkdiv_h : 2; /* [16:15] */ - __IO uint32_t reserved1 : 15;/* [31:17] */ - } clkctrl_bit; - }; - - /** - * @brief sdio argu register, offset:0x08 - */ - union - { - __IO uint32_t argu; - struct - { - __IO uint32_t argu : 32;/* [31:0] */ - } argu_bit; - }; - - /** - * @brief sdio cmdctrl register, offset:0x0C - */ - union - { - __IO uint32_t cmdctrl; - struct - { - __IO uint32_t cmdidx : 6; /* [5:0] */ - __IO uint32_t rspwt : 2; /* [7:6] */ - __IO uint32_t intwt : 1; /* [8] */ - __IO uint32_t pndwt : 1; /* [9] */ - __IO uint32_t ccsmen : 1; /* [10] */ - __IO uint32_t iosusp : 1; /* [11] */ - __IO uint32_t reserved1 : 20;/* [31:12] */ - } cmdctrl_bit; - }; - - /** - * @brief sdio rspcmd register, offset:0x10 - */ - union - { - __IO uint32_t rspcmd; - struct - { - __IO uint32_t rspcmd : 6; /* [5:0] */ - __IO uint32_t reserved1 : 26;/* [31:6] */ - } rspcmd_bit; - }; - - /** - * @brief sdio rsp1 register, offset:0x14 - */ - union - { - __IO uint32_t rsp1; - struct - { - __IO uint32_t cardsts1 : 32;/* [31:0] */ - } rsp1_bit; - }; - - /** - * @brief sdio rsp2 register, offset:0x18 - */ - union - { - __IO uint32_t rsp2; - struct - { - __IO uint32_t cardsts2 : 32;/* [31:0] */ - } rsp2_bit; - }; - - /** - * @brief sdio rsp3 register, offset:0x1C - */ - union - { - __IO uint32_t rsp3; - struct - { - __IO uint32_t cardsts3 : 32;/* [31:0] */ - } rsp3_bit; - }; - - /** - * @brief sdio rsp4 register, offset:0x20 - */ - union - { - __IO uint32_t rsp4; - struct - { - __IO uint32_t cardsts4 : 32;/* [31:0] */ - } rsp4_bit; - }; - - /** - * @brief sdio dttmr register, offset:0x24 - */ - union - { - __IO uint32_t dttmr; - struct - { - __IO uint32_t timeout : 32;/* [31:0] */ - } dttmr_bit; - }; - - /** - * @brief sdio dtlen register, offset:0x28 - */ - union - { - __IO uint32_t dtlen; - struct - { - __IO uint32_t dtlen : 25;/* [24:0] */ - __IO uint32_t reserved1 : 7; /* [31:25] */ - } dtlen_bit; - }; - - /** - * @brief sdio dtctrl register, offset:0x2C - */ - union - { - __IO uint32_t dtctrl; - struct - { - __IO uint32_t tfren : 1; /* [0] */ - __IO uint32_t tfrdir : 1; /* [1] */ - __IO uint32_t tfrmode : 1; /* [2] */ - __IO uint32_t dmaen : 1; /* [3] */ - __IO uint32_t blksize : 4; /* [7:4] */ - __IO uint32_t rdwtstart : 1; /* [8] */ - __IO uint32_t rdwtstop : 1; /* [9] */ - __IO uint32_t rdwtmode : 1; /* [10] */ - __IO uint32_t ioen : 1; /* [11] */ - __IO uint32_t reserved1 : 20;/* [31:12] */ - } dtctrl_bit; - }; - - /** - * @brief sdio dtcnt register, offset:0x30 - */ - union - { - __IO uint32_t dtcnt; - struct - { - __IO uint32_t cnt : 25;/* [24:0] */ - __IO uint32_t reserved1 : 7; /* [31:25] */ - } dtcnt_bit; - }; - - /** - * @brief sdio sts register, offset:0x34 - */ - union - { - __IO uint32_t sts; - struct - { - __IO uint32_t cmdfail : 1; /* [0] */ - __IO uint32_t dtfail : 1; /* [1] */ - __IO uint32_t cmdtimeout : 1; /* [2] */ - __IO uint32_t dttimeout : 1; /* [3] */ - __IO uint32_t txerru : 1; /* [4] */ - __IO uint32_t rxerro : 1; /* [5] */ - __IO uint32_t cmdrspcmpl : 1; /* [6] */ - __IO uint32_t cmdcmpl : 1; /* [7] */ - __IO uint32_t dtcmpl : 1; /* [8] */ - __IO uint32_t sbiterr : 1; /* [9] */ - __IO uint32_t dtblkcmpl : 1; /* [10] */ - __IO uint32_t docmd : 1; /* [11] */ - __IO uint32_t dotx : 1; /* [12] */ - __IO uint32_t dorx : 1; /* [13] */ - __IO uint32_t txbufh : 1; /* [14] */ - __IO uint32_t rxbufh : 1; /* [15] */ - __IO uint32_t txbuff : 1; /* [16] */ - __IO uint32_t rxbuff : 1; /* [17] */ - __IO uint32_t txbufe : 1; /* [18] */ - __IO uint32_t rxbufe : 1; /* [19] */ - __IO uint32_t txbuf : 1; /* [20] */ - __IO uint32_t rxbuf : 1; /* [21] */ - __IO uint32_t ioif : 1; /* [22] */ - __IO uint32_t reserved1 : 9; /* [31:23] */ - } sts_bit; - }; - - /** - * @brief sdio intclr register, offset:0x38 - */ - union - { - __IO uint32_t intclr; - struct - { - __IO uint32_t cmdfail : 1; /* [0] */ - __IO uint32_t dtfail : 1; /* [1] */ - __IO uint32_t cmdtimeout : 1; /* [2] */ - __IO uint32_t dttimeout : 1; /* [3] */ - __IO uint32_t txerru : 1; /* [4] */ - __IO uint32_t rxerro : 1; /* [5] */ - __IO uint32_t cmdrspcmpl : 1; /* [6] */ - __IO uint32_t cmdcmpl : 1; /* [7] */ - __IO uint32_t dtcmpl : 1; /* [8] */ - __IO uint32_t sbiterr : 1; /* [9] */ - __IO uint32_t dtblkcmpl : 1; /* [10] */ - __IO uint32_t reserved1 : 11;/* [21:11] */ - __IO uint32_t ioif : 1; /* [22] */ - __IO uint32_t reserved2 : 9; /* [31:23] */ - } intclr_bit; - }; - - /** - * @brief sdio inten register, offset:0x3C - */ - union - { - __IO uint32_t inten; - struct - { - __IO uint32_t cmdfailien : 1; /* [0] */ - __IO uint32_t dtfailien : 1; /* [1] */ - __IO uint32_t cmdtimeoutien : 1; /* [2] */ - __IO uint32_t dttimeoutien : 1; /* [3] */ - __IO uint32_t txerruien : 1; /* [4] */ - __IO uint32_t rxerroien : 1; /* [5] */ - __IO uint32_t cmdrspcmplien : 1; /* [6] */ - __IO uint32_t cmdcmplien : 1; /* [7] */ - __IO uint32_t dtcmplien : 1; /* [8] */ - __IO uint32_t sbiterrien : 1; /* [9] */ - __IO uint32_t dtblkcmplien : 1; /* [10] */ - __IO uint32_t docmdien : 1; /* [11] */ - __IO uint32_t dotxien : 1; /* [12] */ - __IO uint32_t dorxien : 1; /* [13] */ - __IO uint32_t txbufhien : 1; /* [14] */ - __IO uint32_t rxbufhien : 1; /* [15] */ - __IO uint32_t txbuffien : 1; /* [16] */ - __IO uint32_t rxbuffien : 1; /* [17] */ - __IO uint32_t txbufeien : 1; /* [18] */ - __IO uint32_t rxbufeien : 1; /* [19] */ - __IO uint32_t txbufien : 1; /* [20] */ - __IO uint32_t rxbufien : 1; /* [21] */ - __IO uint32_t ioifien : 1; /* [22] */ - __IO uint32_t reserved1 : 9; /* [31:23] */ - } inten_bit; - }; - - /** - * @brief sdio reserved1 register, offset:0x40~0x44 - */ - __IO uint32_t reserved1[2]; - - /** - * @brief sdio bufcnt register, offset:0x48 - */ - union - { - __IO uint32_t bufcnt; - struct - { - __IO uint32_t cnt : 24;/* [23:0] */ - __IO uint32_t reserved1 : 8; /* [31:24] */ - } bufcnt_bit; - }; - - /** - * @brief sdio reserved2 register, offset:0x4C~0x7C - */ - __IO uint32_t reserved2[13]; - - /** - * @brief sdio buf register, offset:0x80 - */ - union - { - __IO uint32_t buf; - struct - { - __IO uint32_t dt : 32;/* [31:0] */ - } buf_bit; - }; - -} sdio_type; - -/** - * @} - */ - -#define SDIO1 ((sdio_type *) SDIO1_BASE) -#define SDIO2 ((sdio_type *) SDIO2_BASE) - -/** @defgroup SDIO_exported_functions - * @{ - */ - -void sdio_reset(sdio_type *sdio_x); -void sdio_power_set(sdio_type *sdio_x, sdio_power_state_type power_state); -flag_status sdio_power_status_get(sdio_type *sdio_x); -void sdio_clock_config(sdio_type *sdio_x, uint16_t clk_div, sdio_edge_phase_type clk_edg); -void sdio_bus_width_config(sdio_type *sdio_x, sdio_bus_width_type width); -void sdio_clock_bypass(sdio_type *sdio_x, confirm_state new_state); -void sdio_power_saving_mode_enable(sdio_type *sdio_x, confirm_state new_state); -void sdio_flow_control_enable(sdio_type *sdio_x, confirm_state new_state); -void sdio_clock_enable(sdio_type *sdio_x, confirm_state new_state); -void sdio_dma_enable(sdio_type *sdio_x, confirm_state new_state); -void sdio_interrupt_enable(sdio_type *sdio_x, uint32_t int_opt, confirm_state new_state); -flag_status sdio_flag_get(sdio_type *sdio_x, uint32_t flag); -void sdio_flag_clear(sdio_type *sdio_x, uint32_t flag); -void sdio_command_config(sdio_type *sdio_x, sdio_command_struct_type *command_struct); -void sdio_command_state_machine_enable(sdio_type *sdio_x, confirm_state new_state); -uint8_t sdio_command_response_get(sdio_type *sdio_x); -uint32_t sdio_response_get(sdio_type *sdio_x, sdio_rsp_index_type reg_index); -void sdio_data_config(sdio_type *sdio_x, sdio_data_struct_type *data_struct); -void sdio_data_state_machine_enable(sdio_type *sdio_x, confirm_state new_state); -uint32_t sdio_data_counter_get(sdio_type *sdio_x); -uint32_t sdio_data_read(sdio_type *sdio_x); -uint32_t sdio_buffer_counter_get(sdio_type *sdio_x); -void sdio_data_write(sdio_type *sdio_x, uint32_t data); -void sdio_read_wait_mode_set(sdio_type *sdio_x, sdio_read_wait_mode_type mode); -void sdio_read_wait_start(sdio_type *sdio_x, confirm_state new_state); -void sdio_read_wait_stop(sdio_type *sdio_x, confirm_state new_state); -void sdio_io_function_enable(sdio_type *sdio_x, confirm_state new_state); -void sdio_io_suspend_command_set(sdio_type *sdio_x, confirm_state new_state); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_spi.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_spi.h deleted file mode 100644 index 6c65846..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_spi.h +++ /dev/null @@ -1,505 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_spi.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 spi header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_SPI_H -#define __AT32F435_437_SPI_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup SPI - * @{ - */ - -/** - * @defgroup SPI_I2S_flags_definition - * @brief spi i2s flag - * @{ - */ - -#define SPI_I2S_RDBF_FLAG 0x0001 /*!< spi or i2s receive data buffer full flag */ -#define SPI_I2S_TDBE_FLAG 0x0002 /*!< spi or i2s transmit data buffer empty flag */ -#define I2S_ACS_FLAG 0x0004 /*!< i2s audio channel state flag */ -#define I2S_TUERR_FLAG 0x0008 /*!< i2s transmitter underload error flag */ -#define SPI_CCERR_FLAG 0x0010 /*!< spi crc calculation error flag */ -#define SPI_MMERR_FLAG 0x0020 /*!< spi master mode error flag */ -#define SPI_I2S_ROERR_FLAG 0x0040 /*!< spi or i2s receiver overflow error flag */ -#define SPI_I2S_BF_FLAG 0x0080 /*!< spi or i2s busy flag */ -#define SPI_CSPAS_FLAG 0x0100 /*!< spi cs pulse abnormal setting fiag */ - -/** - * @} - */ - -/** - * @defgroup SPI_I2S_interrupts_definition - * @brief spi i2s interrupt - * @{ - */ - -#define SPI_I2S_ERROR_INT 0x0020 /*!< error interrupt */ -#define SPI_I2S_RDBF_INT 0x0040 /*!< receive data buffer full interrupt */ -#define SPI_I2S_TDBE_INT 0x0080 /*!< transmit data buffer empty interrupt */ - -/** - * @} - */ - -/** @defgroup SPI_exported_types - * @{ - */ - -/** - * @brief spi frame bit num type - */ -typedef enum -{ - SPI_FRAME_8BIT = 0x00, /*!< 8-bit data frame format */ - SPI_FRAME_16BIT = 0x01 /*!< 16-bit data frame format */ -} spi_frame_bit_num_type; - -/** - * @brief spi master/slave mode type - */ -typedef enum -{ - SPI_MODE_SLAVE = 0x00, /*!< select as slave mode */ - SPI_MODE_MASTER = 0x01 /*!< select as master mode */ -} spi_master_slave_mode_type; - -/** - * @brief spi clock polarity (clkpol) type - */ -typedef enum -{ - SPI_CLOCK_POLARITY_LOW = 0x00, /*!< sck keeps low at idle state */ - SPI_CLOCK_POLARITY_HIGH = 0x01 /*!< sck keeps high at idle state */ -} spi_clock_polarity_type; - -/** - * @brief spi clock phase (clkpha) type - */ -typedef enum -{ - SPI_CLOCK_PHASE_1EDGE = 0x00, /*!< data capture start from the first clock edge */ - SPI_CLOCK_PHASE_2EDGE = 0x01 /*!< data capture start from the second clock edge */ -} spi_clock_phase_type; - -/** - * @brief spi cs mode type - */ -typedef enum -{ - SPI_CS_HARDWARE_MODE = 0x00, /*!< cs is hardware mode */ - SPI_CS_SOFTWARE_MODE = 0x01 /*!< cs is software mode */ -} spi_cs_mode_type; - -/** - * @brief spi master clock frequency division type - */ -typedef enum -{ - SPI_MCLK_DIV_2 = 0x00, /*!< master clock frequency division 2 */ - SPI_MCLK_DIV_3 = 0x0A, /*!< master clock frequency division 3 */ - SPI_MCLK_DIV_4 = 0x01, /*!< master clock frequency division 4 */ - SPI_MCLK_DIV_8 = 0x02, /*!< master clock frequency division 8 */ - SPI_MCLK_DIV_16 = 0x03, /*!< master clock frequency division 16 */ - SPI_MCLK_DIV_32 = 0x04, /*!< master clock frequency division 32 */ - SPI_MCLK_DIV_64 = 0x05, /*!< master clock frequency division 64 */ - SPI_MCLK_DIV_128 = 0x06, /*!< master clock frequency division 128 */ - SPI_MCLK_DIV_256 = 0x07, /*!< master clock frequency division 256 */ - SPI_MCLK_DIV_512 = 0x08, /*!< master clock frequency division 512 */ - SPI_MCLK_DIV_1024 = 0x09 /*!< master clock frequency division 1024 */ -} spi_mclk_freq_div_type; - -/** - * @brief spi transmit first bit (lsb/msb) type - */ -typedef enum -{ - SPI_FIRST_BIT_MSB = 0x00, /*!< the frame format is msb first */ - SPI_FIRST_BIT_LSB = 0x01 /*!< the frame format is lsb first */ -} spi_first_bit_type; - -/** - * @brief spi transmission mode type - */ -typedef enum -{ - SPI_TRANSMIT_FULL_DUPLEX = 0x00, /*!< dual line unidirectional full-duplex mode(slben = 0 and ora = 0) */ - SPI_TRANSMIT_SIMPLEX_RX = 0x01, /*!< dual line unidirectional simplex receive-only mode(slben = 0 and ora = 1) */ - SPI_TRANSMIT_HALF_DUPLEX_RX = 0x02, /*!< single line bidirectional half duplex mode-receiving(slben = 1 and slbtd = 0) */ - SPI_TRANSMIT_HALF_DUPLEX_TX = 0x03 /*!< single line bidirectional half duplex mode-transmitting(slben = 1 and slbtd = 1) */ -} spi_transmission_mode_type; - -/** - * @brief spi crc direction type - */ -typedef enum -{ - SPI_CRC_RX = 0x0014, /*!< crc direction is rx */ - SPI_CRC_TX = 0x0018 /*!< crc direction is tx */ -} spi_crc_direction_type; - -/** - * @brief spi single line bidirectional direction type - */ -typedef enum -{ - SPI_HALF_DUPLEX_DIRECTION_RX = 0x00, /*!< single line bidirectional half duplex mode direction: receive(slbtd = 0) */ - SPI_HALF_DUPLEX_DIRECTION_TX = 0x01 /*!< single line bidirectional half duplex mode direction: transmit(slbtd = 1) */ -} spi_half_duplex_direction_type; - -/** - * @brief spi software cs internal level type - */ -typedef enum -{ - SPI_SWCS_INTERNAL_LEVEL_LOW = 0x00, /*!< internal level low */ - SPI_SWCS_INTERNAL_LEVEL_HIGHT = 0x01 /*!< internal level high */ -} spi_software_cs_level_type; - -/** - * @brief i2s audio protocol type - */ -typedef enum -{ - I2S_AUDIO_PROTOCOL_PHILLIPS = 0x00, /*!< i2s philip standard */ - I2S_AUDIO_PROTOCOL_MSB = 0x01, /*!< msb-justified standard */ - I2S_AUDIO_PROTOCOL_LSB = 0x02, /*!< lsb-justified standard */ - I2S_AUDIO_PROTOCOL_PCM_SHORT = 0x03, /*!< pcm standard-short frame */ - I2S_AUDIO_PROTOCOL_PCM_LONG = 0x04 /*!< pcm standard-long frame */ -} i2s_audio_protocol_type; - -/** - * @brief i2s audio frequency type - */ -typedef enum -{ - I2S_AUDIO_FREQUENCY_DEFAULT = 2, /*!< i2s audio sampling frequency default */ - I2S_AUDIO_FREQUENCY_8K = 8000, /*!< i2s audio sampling frequency 8k */ - I2S_AUDIO_FREQUENCY_11_025K = 11025, /*!< i2s audio sampling frequency 11.025k */ - I2S_AUDIO_FREQUENCY_16K = 16000, /*!< i2s audio sampling frequency 16k */ - I2S_AUDIO_FREQUENCY_22_05K = 22050, /*!< i2s audio sampling frequency 22.05k */ - I2S_AUDIO_FREQUENCY_32K = 32000, /*!< i2s audio sampling frequency 32k */ - I2S_AUDIO_FREQUENCY_44_1K = 44100, /*!< i2s audio sampling frequency 44.1k */ - I2S_AUDIO_FREQUENCY_48K = 48000, /*!< i2s audio sampling frequency 48k */ - I2S_AUDIO_FREQUENCY_96K = 96000, /*!< i2s audio sampling frequency 96k */ - I2S_AUDIO_FREQUENCY_192K = 192000 /*!< i2s audio sampling frequency 192k */ -} i2s_audio_sampling_freq_type; - -/** - * @brief i2s data bit num and channel bit num type - */ -typedef enum -{ - I2S_DATA_16BIT_CHANNEL_16BIT = 0x01, /*!< 16-bit data packed in 16-bit channel frame */ - I2S_DATA_16BIT_CHANNEL_32BIT = 0x02, /*!< 16-bit data packed in 32-bit channel frame */ - I2S_DATA_24BIT_CHANNEL_32BIT = 0x03, /*!< 24-bit data packed in 32-bit channel frame */ - I2S_DATA_32BIT_CHANNEL_32BIT = 0x04 /*!< 32-bit data packed in 32-bit channel frame */ -} i2s_data_channel_format_type; - -/** - * @brief i2s operation mode type - */ -typedef enum -{ - I2S_MODE_SLAVE_TX = 0x00, /*!< slave transmission mode */ - I2S_MODE_SLAVE_RX = 0x01, /*!< slave reception mode */ - I2S_MODE_MASTER_TX = 0x02, /*!< master transmission mode */ - I2S_MODE_MASTER_RX = 0x03 /*!< master reception mode */ -} i2s_operation_mode_type; - -/** - * @brief i2s clock polarity type - */ -typedef enum -{ - I2S_CLOCK_POLARITY_LOW = 0x00, /*!< i2s clock steady state is low level */ - I2S_CLOCK_POLARITY_HIGH = 0x01 /*!< i2s clock steady state is high level */ -} i2s_clock_polarity_type; - -/** - * @brief spi init type - */ -typedef struct -{ - spi_transmission_mode_type transmission_mode; /*!< transmission mode selection */ - spi_master_slave_mode_type master_slave_mode; /*!< master or slave mode selection */ - spi_mclk_freq_div_type mclk_freq_division; /*!< master clock frequency division selection */ - spi_first_bit_type first_bit_transmission;/*!< transmit lsb or msb selection */ - spi_frame_bit_num_type frame_bit_num; /*!< frame bit num 8 or 16 bit selection */ - spi_clock_polarity_type clock_polarity; /*!< clock polarity selection */ - spi_clock_phase_type clock_phase; /*!< clock phase selection */ - spi_cs_mode_type cs_mode_selection; /*!< hardware or software cs mode selection */ -} spi_init_type; - -/** - * @brief i2s init type - */ -typedef struct -{ - i2s_operation_mode_type operation_mode; /*!< operation mode selection */ - i2s_audio_protocol_type audio_protocol; /*!< audio protocol selection */ - i2s_audio_sampling_freq_type audio_sampling_freq; /*!< audio frequency selection */ - i2s_data_channel_format_type data_channel_format; /*!< data bit num and channel bit num selection */ - i2s_clock_polarity_type clock_polarity; /*!< clock polarity selection */ - confirm_state mclk_output_enable; /*!< mclk_output selection */ -} i2s_init_type; - -/** - * @brief type define spi register all - */ -typedef struct -{ - - /** - * @brief spi ctrl1 register, offset:0x00 - */ - union - { - __IO uint32_t ctrl1; - struct - { - __IO uint32_t clkpha : 1; /* [0] */ - __IO uint32_t clkpol : 1; /* [1] */ - __IO uint32_t msten : 1; /* [2] */ - __IO uint32_t mdiv_l : 3; /* [5:3] */ - __IO uint32_t spien : 1; /* [6] */ - __IO uint32_t ltf : 1; /* [7] */ - __IO uint32_t swcsil : 1; /* [8] */ - __IO uint32_t swcsen : 1; /* [9] */ - __IO uint32_t ora : 1; /* [10] */ - __IO uint32_t fbn : 1; /* [11] */ - __IO uint32_t ntc : 1; /* [12] */ - __IO uint32_t ccen : 1; /* [13] */ - __IO uint32_t slbtd : 1; /* [14] */ - __IO uint32_t slben : 1; /* [15] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } ctrl1_bit; - }; - - /** - * @brief spi ctrl2 register, offset:0x04 - */ - union - { - __IO uint32_t ctrl2; - struct - { - __IO uint32_t dmaren : 1; /* [0] */ - __IO uint32_t dmaten : 1; /* [1] */ - __IO uint32_t hwcsoe : 1; /* [2] */ - __IO uint32_t reserved1 : 1; /* [3] */ - __IO uint32_t tien : 1; /* [4] */ - __IO uint32_t errie : 1; /* [5] */ - __IO uint32_t rdbfie : 1; /* [6] */ - __IO uint32_t tdbeie : 1; /* [7] */ - __IO uint32_t mdiv_h : 1; /* [8] */ - __IO uint32_t mdiv3en : 1; /* [9] */ - __IO uint32_t reserved2 : 22;/* [31:10] */ - } ctrl2_bit; - }; - - /** - * @brief spi sts register, offset:0x08 - */ - union - { - __IO uint32_t sts; - struct - { - __IO uint32_t rdbf : 1; /* [0] */ - __IO uint32_t tdbe : 1; /* [1] */ - __IO uint32_t acs : 1; /* [2] */ - __IO uint32_t tuerr : 1; /* [3] */ - __IO uint32_t ccerr : 1; /* [4] */ - __IO uint32_t mmerr : 1; /* [5] */ - __IO uint32_t roerr : 1; /* [6] */ - __IO uint32_t bf : 1; /* [7] */ - __IO uint32_t cspas : 1; /* [8] */ - __IO uint32_t reserved1 : 23;/* [31:9] */ - } sts_bit; - }; - - /** - * @brief spi dt register, offset:0x0C - */ - union - { - __IO uint32_t dt; - struct - { - __IO uint32_t dt : 16;/* [15:0] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } dt_bit; - }; - - /** - * @brief spi cpoly register, offset:0x10 - */ - union - { - __IO uint32_t cpoly; - struct - { - __IO uint32_t cpoly : 16;/* [15:0] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } cpoly_bit; - }; - - /** - * @brief spi rcrc register, offset:0x14 - */ - union - { - __IO uint32_t rcrc; - struct - { - __IO uint32_t rcrc : 16;/* [15:0] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } rcrc_bit; - }; - - /** - * @brief spi tcrc register, offset:0x18 - */ - union - { - __IO uint32_t tcrc; - struct - { - __IO uint32_t tcrc : 16;/* [15:0] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } tcrc_bit; - }; - - /** - * @brief spi i2sctrl register, offset:0x1C - */ - union - { - __IO uint32_t i2sctrl; - struct - { - __IO uint32_t i2scbn : 1; /* [0] */ - __IO uint32_t i2sdbn : 2; /* [2:1] */ - __IO uint32_t i2sclkpol : 1; /* [3] */ - __IO uint32_t stdsel : 2; /* [5:4] */ - __IO uint32_t reserved1 : 1; /* [6] */ - __IO uint32_t pcmfssel : 1; /* [7] */ - __IO uint32_t opersel : 2; /* [9:8] */ - __IO uint32_t i2sen : 1; /* [10] */ - __IO uint32_t i2smsel : 1; /* [11] */ - __IO uint32_t reserved2 : 20;/* [31:12] */ - } i2sctrl_bit; - }; - - /** - * @brief spi i2sclk register, offset:0x20 - */ - union - { - __IO uint32_t i2sclk; - struct - { - __IO uint32_t i2sdiv_l : 8; /* [7:0] */ - __IO uint32_t i2sodd : 1; /* [8] */ - __IO uint32_t i2smclkoe : 1; /* [9] */ - __IO uint32_t i2sdiv_h : 2; /* [11:10] */ - __IO uint32_t reserved1 : 20;/* [31:12] */ - } i2sclk_bit; - }; - -} spi_type; - -/** - * @} - */ - -#define SPI1 ((spi_type *) SPI1_BASE) -#define SPI2 ((spi_type *) SPI2_BASE) -#define SPI3 ((spi_type *) SPI3_BASE) -#define SPI4 ((spi_type *) SPI4_BASE) -#define I2S2EXT ((spi_type *) I2S2EXT_BASE) -#define I2S3EXT ((spi_type *) I2S3EXT_BASE) - -/** @defgroup SPI_exported_functions - * @{ - */ - -void spi_i2s_reset(spi_type *spi_x); -void spi_default_para_init(spi_init_type* spi_init_struct); -void spi_init(spi_type* spi_x, spi_init_type* spi_init_struct); -void spi_ti_mode_enable(spi_type* spi_x, confirm_state new_state); -void spi_crc_next_transmit(spi_type* spi_x); -void spi_crc_polynomial_set(spi_type* spi_x, uint16_t crc_poly); -uint16_t spi_crc_polynomial_get(spi_type* spi_x); -void spi_crc_enable(spi_type* spi_x, confirm_state new_state); -uint16_t spi_crc_value_get(spi_type* spi_x, spi_crc_direction_type crc_direction); -void spi_hardware_cs_output_enable(spi_type* spi_x, confirm_state new_state); -void spi_software_cs_internal_level_set(spi_type* spi_x, spi_software_cs_level_type level); -void spi_frame_bit_num_set(spi_type* spi_x, spi_frame_bit_num_type bit_num); -void spi_half_duplex_direction_set(spi_type* spi_x, spi_half_duplex_direction_type direction); -void spi_enable(spi_type* spi_x, confirm_state new_state); -void i2s_default_para_init(i2s_init_type* i2s_init_struct); -void i2s_init(spi_type* spi_x, i2s_init_type* i2s_init_struct); -void i2s_enable(spi_type* spi_x, confirm_state new_state); -void spi_i2s_interrupt_enable(spi_type* spi_x, uint32_t spi_i2s_int, confirm_state new_state); -void spi_i2s_dma_transmitter_enable(spi_type* spi_x, confirm_state new_state); -void spi_i2s_dma_receiver_enable(spi_type* spi_x, confirm_state new_state); -void spi_i2s_data_transmit(spi_type* spi_x, uint16_t tx_data); -uint16_t spi_i2s_data_receive(spi_type* spi_x); -flag_status spi_i2s_flag_get(spi_type* spi_x, uint32_t spi_i2s_flag); -void spi_i2s_flag_clear(spi_type* spi_x, uint32_t spi_i2s_flag); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_tmr.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_tmr.h deleted file mode 100644 index 4e5e86b..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_tmr.h +++ /dev/null @@ -1,1017 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_tmr.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 tmr header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_TMR_H -#define __AT32F435_437_TMR_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup TMR - * @{ - */ - -/** @defgroup TMR_flags_definition - * @brief tmr flag - * @{ - */ - -#define TMR_OVF_FLAG ((uint32_t)0x000001) /*!< tmr flag overflow */ -#define TMR_C1_FLAG ((uint32_t)0x000002) /*!< tmr flag channel 1 */ -#define TMR_C2_FLAG ((uint32_t)0x000004) /*!< tmr flag channel 2 */ -#define TMR_C3_FLAG ((uint32_t)0x000008) /*!< tmr flag channel 3 */ -#define TMR_C4_FLAG ((uint32_t)0x000010) /*!< tmr flag channel 4 */ -#define TMR_HALL_FLAG ((uint32_t)0x000020) /*!< tmr flag hall */ -#define TMR_TRIGGER_FLAG ((uint32_t)0x000040) /*!< tmr flag trigger */ -#define TMR_BRK_FLAG ((uint32_t)0x000080) /*!< tmr flag brake */ -#define TMR_C1_RECAPTURE_FLAG ((uint32_t)0x000200) /*!< tmr flag channel 1 recapture */ -#define TMR_C2_RECAPTURE_FLAG ((uint32_t)0x000400) /*!< tmr flag channel 2 recapture */ -#define TMR_C3_RECAPTURE_FLAG ((uint32_t)0x000800) /*!< tmr flag channel 3 recapture */ -#define TMR_C4_RECAPTURE_FLAG ((uint32_t)0x001000) /*!< tmr flag channel 4 recapture */ - -/** - * @} - */ - -/** @defgroup TMR_interrupt_select_type_definition - * @brief tmr interrupt select type - * @{ - */ - -#define TMR_OVF_INT ((uint32_t)0x000001) /*!< tmr interrupt overflow */ -#define TMR_C1_INT ((uint32_t)0x000002) /*!< tmr interrupt channel 1 */ -#define TMR_C2_INT ((uint32_t)0x000004) /*!< tmr interrupt channel 2 */ -#define TMR_C3_INT ((uint32_t)0x000008) /*!< tmr interrupt channel 3 */ -#define TMR_C4_INT ((uint32_t)0x000010) /*!< tmr interrupt channel 4 */ -#define TMR_HALL_INT ((uint32_t)0x000020) /*!< tmr interrupt hall */ -#define TMR_TRIGGER_INT ((uint32_t)0x000040) /*!< tmr interrupt trigger */ -#define TMR_BRK_INT ((uint32_t)0x000080) /*!< tmr interrupt brake */ - -/** - * @} - */ - -/** @defgroup TMR_exported_types - * @{ - */ - -/** - * @brief tmr clock division type - */ -typedef enum -{ - TMR_CLOCK_DIV1 = 0x00, /*!< tmr clock division 1 */ - TMR_CLOCK_DIV2 = 0x01, /*!< tmr clock division 2 */ - TMR_CLOCK_DIV4 = 0x02 /*!< tmr clock division 4 */ -} tmr_clock_division_type; - -/** - * @brief tmr counter mode type - */ -typedef enum -{ - TMR_COUNT_UP = 0x00, /*!< tmr counter mode up */ - TMR_COUNT_DOWN = 0x01, /*!< tmr counter mode down */ - TMR_COUNT_TWO_WAY_1 = 0x02, /*!< tmr counter mode two way 1 */ - TMR_COUNT_TWO_WAY_2 = 0x04, /*!< tmr counter mode two way 2 */ - TMR_COUNT_TWO_WAY_3 = 0x06 /*!< tmr counter mode two way 3 */ -} tmr_count_mode_type; - -/** - * @brief tmr primary mode select type - */ -typedef enum -{ - TMR_PRIMARY_SEL_RESET = 0x00, /*!< tmr primary mode select reset */ - TMR_PRIMARY_SEL_ENABLE = 0x01, /*!< tmr primary mode select enable */ - TMR_PRIMARY_SEL_OVERFLOW = 0x02, /*!< tmr primary mode select overflow */ - TMR_PRIMARY_SEL_COMPARE = 0x03, /*!< tmr primary mode select compare */ - TMR_PRIMARY_SEL_C1ORAW = 0x04, /*!< tmr primary mode select c1oraw */ - TMR_PRIMARY_SEL_C2ORAW = 0x05, /*!< tmr primary mode select c2oraw */ - TMR_PRIMARY_SEL_C3ORAW = 0x06, /*!< tmr primary mode select c3oraw */ - TMR_PRIMARY_SEL_C4ORAW = 0x07 /*!< tmr primary mode select c4oraw */ -} tmr_primary_select_type; - -/** - * @brief tmr subordinate mode input select type - */ -typedef enum -{ - TMR_SUB_INPUT_SEL_IS0 = 0x00, /*!< subordinate mode input select is0 */ - TMR_SUB_INPUT_SEL_IS1 = 0x01, /*!< subordinate mode input select is1 */ - TMR_SUB_INPUT_SEL_IS2 = 0x02, /*!< subordinate mode input select is2 */ - TMR_SUB_INPUT_SEL_IS3 = 0x03, /*!< subordinate mode input select is3 */ - TMR_SUB_INPUT_SEL_C1INC = 0x04, /*!< subordinate mode input select c1inc */ - TMR_SUB_INPUT_SEL_C1DF1 = 0x05, /*!< subordinate mode input select c1df1 */ - TMR_SUB_INPUT_SEL_C2DF2 = 0x06, /*!< subordinate mode input select c2df2 */ - TMR_SUB_INPUT_SEL_EXTIN = 0x07 /*!< subordinate mode input select extin */ -} sub_tmr_input_sel_type; - -/** - * @brief tmr subordinate mode select type - */ -typedef enum -{ - TMR_SUB_MODE_DIABLE = 0x00, /*!< subordinate mode disable */ - TMR_SUB_ENCODER_MODE_A = 0x01, /*!< subordinate mode select encoder mode a */ - TMR_SUB_ENCODER_MODE_B = 0x02, /*!< subordinate mode select encoder mode b */ - TMR_SUB_ENCODER_MODE_C = 0x03, /*!< subordinate mode select encoder mode c */ - TMR_SUB_RESET_MODE = 0x04, /*!< subordinate mode select reset */ - TMR_SUB_HANG_MODE = 0x05, /*!< subordinate mode select hang */ - TMR_SUB_TRIGGER_MODE = 0x06, /*!< subordinate mode select trigger */ - TMR_SUB_EXTERNAL_CLOCK_MODE_A = 0x07 /*!< subordinate mode external clock mode a */ -} tmr_sub_mode_select_type; - -/** - * @brief tmr encoder mode type - */ -typedef enum -{ - TMR_ENCODER_MODE_A = TMR_SUB_ENCODER_MODE_A, /*!< tmr encoder mode a */ - TMR_ENCODER_MODE_B = TMR_SUB_ENCODER_MODE_B, /*!< tmr encoder mode b */ - TMR_ENCODER_MODE_C = TMR_SUB_ENCODER_MODE_C /*!< tmr encoder mode c */ -} tmr_encoder_mode_type; - -/** - * @brief tmr output control mode type - */ -typedef enum -{ - TMR_OUTPUT_CONTROL_OFF = 0x00, /*!< tmr output control mode off */ - TMR_OUTPUT_CONTROL_HIGH = 0x01, /*!< tmr output control mode high */ - TMR_OUTPUT_CONTROL_LOW = 0x02, /*!< tmr output control mode low */ - TMR_OUTPUT_CONTROL_SWITCH = 0x03, /*!< tmr output control mode switch */ - TMR_OUTPUT_CONTROL_FORCE_HIGH = 0x04, /*!< tmr output control mode force high */ - TMR_OUTPUT_CONTROL_FORCE_LOW = 0x05, /*!< tmr output control mode force low */ - TMR_OUTPUT_CONTROL_PWM_MODE_A = 0x06, /*!< tmr output control mode pwm a */ - TMR_OUTPUT_CONTROL_PWM_MODE_B = 0x07 /*!< tmr output control mode pwm b */ -} tmr_output_control_mode_type; - -/** - * @brief tmr force output type - */ -typedef enum -{ - TMR_FORCE_OUTPUT_HIGH = TMR_OUTPUT_CONTROL_FORCE_HIGH, /*!< tmr force output high */ - TMR_FORCE_OUTPUT_LOW = TMR_OUTPUT_CONTROL_FORCE_LOW /*!< tmr force output low */ -} tmr_force_output_type; - -/** - * @brief tmr output channel polarity type - */ -typedef enum -{ - TMR_OUTPUT_ACTIVE_HIGH = 0x00, /*!< tmr output channel polarity high */ - TMR_OUTPUT_ACTIVE_LOW = 0x01 /*!< tmr output channel polarity low */ -} tmr_output_polarity_type; - -/** - * @brief tmr input channel polarity type - */ -typedef enum -{ - TMR_INPUT_RISING_EDGE = 0x00, /*!< tmr input channel polarity rising */ - TMR_INPUT_FALLING_EDGE = 0x01, /*!< tmr input channel polarity falling */ - TMR_INPUT_BOTH_EDGE = 0x03 /*!< tmr input channel polarity both edge */ -} tmr_input_polarity_type; - -/** - * @brief tmr channel select type - */ -typedef enum -{ - TMR_SELECT_CHANNEL_1 = 0x00, /*!< tmr channel select channel 1 */ - TMR_SELECT_CHANNEL_1C = 0x01, /*!< tmr channel select channel 1 complementary */ - TMR_SELECT_CHANNEL_2 = 0x02, /*!< tmr channel select channel 2 */ - TMR_SELECT_CHANNEL_2C = 0x03, /*!< tmr channel select channel 2 complementary */ - TMR_SELECT_CHANNEL_3 = 0x04, /*!< tmr channel select channel 3 */ - TMR_SELECT_CHANNEL_3C = 0x05, /*!< tmr channel select channel 3 complementary */ - TMR_SELECT_CHANNEL_4 = 0x06, /*!< tmr channel select channel 4 */ - TMR_SELECT_CHANNEL_5 = 0x07 /*!< tmr channel select channel 5 */ -} tmr_channel_select_type; - -/** - * @brief tmr channel1 input connected type - */ -typedef enum -{ - TMR_CHANEL1_CONNECTED_C1IRAW = 0x00, /*!< channel1 pins is only connected to C1IRAW input */ - TMR_CHANEL1_2_3_CONNECTED_C1IRAW_XOR = 0x01 /*!< channel1/2/3 pins are connected to C1IRAW input after xored */ -} tmr_channel1_input_connected_type; - -/** - * @brief tmr input channel mapped type channel direction - */ -typedef enum -{ - TMR_CC_CHANNEL_MAPPED_DIRECT = 0x01, /*!< channel is configured as input, mapped direct */ - TMR_CC_CHANNEL_MAPPED_INDIRECT = 0x02, /*!< channel is configured as input, mapped indirect */ - TMR_CC_CHANNEL_MAPPED_STI = 0x03 /*!< channel is configured as input, mapped trc */ -} tmr_input_direction_mapped_type; - -/** - * @brief tmr input divider type - */ -typedef enum -{ - TMR_CHANNEL_INPUT_DIV_1 = 0x00, /*!< tmr channel input divider 1 */ - TMR_CHANNEL_INPUT_DIV_2 = 0x01, /*!< tmr channel input divider 2 */ - TMR_CHANNEL_INPUT_DIV_4 = 0x02, /*!< tmr channel input divider 4 */ - TMR_CHANNEL_INPUT_DIV_8 = 0x03 /*!< tmr channel input divider 8 */ -} tmr_channel_input_divider_type; - -/** - * @brief tmr dma request source select type - */ -typedef enum -{ - TMR_DMA_REQUEST_BY_CHANNEL = 0x00, /*!< tmr dma request source select channel */ - TMR_DMA_REQUEST_BY_OVERFLOW = 0x01 /*!< tmr dma request source select overflow */ -} tmr_dma_request_source_type; - -/** - * @brief tmr dma request type - */ -typedef enum -{ - TMR_OVERFLOW_DMA_REQUEST = 0x00000100, /*!< tmr dma request select overflow */ - TMR_C1_DMA_REQUEST = 0x00000200, /*!< tmr dma request select channel 1 */ - TMR_C2_DMA_REQUEST = 0x00000400, /*!< tmr dma request select channel 2 */ - TMR_C3_DMA_REQUEST = 0x00000800, /*!< tmr dma request select channel 3 */ - TMR_C4_DMA_REQUEST = 0x00001000, /*!< tmr dma request select channel 4 */ - TMR_HALL_DMA_REQUEST = 0x00002000, /*!< tmr dma request select hall */ - TMR_TRIGGER_DMA_REQUEST = 0x00004000 /*!< tmr dma request select trigger */ -} tmr_dma_request_type; - -/** - * @brief tmr event triggered by software type - */ -typedef enum -{ - TMR_OVERFLOW_SWTRIG = 0x00000001, /*!< tmr event triggered by software of overflow */ - TMR_C1_SWTRIG = 0x00000002, /*!< tmr event triggered by software of channel 1 */ - TMR_C2_SWTRIG = 0x00000004, /*!< tmr event triggered by software of channel 2 */ - TMR_C3_SWTRIG = 0x00000008, /*!< tmr event triggered by software of channel 3 */ - TMR_C4_SWTRIG = 0x00000010, /*!< tmr event triggered by software of channel 4 */ - TMR_HALL_SWTRIG = 0x00000020, /*!< tmr event triggered by software of hall */ - TMR_TRIGGER_SWTRIG = 0x00000040, /*!< tmr event triggered by software of trigger */ - TMR_BRK_SWTRIG = 0x00000080 /*!< tmr event triggered by software of brake */ -}tmr_event_trigger_type; - -/** - * @brief tmr channel output fast type - */ -typedef enum -{ - TMR_CHANNEL1_OUTPUT_FAST = MAKE_VALUE(0x18, 2), /*!< tmr channel 1 output fast mode */ - TMR_CHANNEL2_OUTPUT_FAST = MAKE_VALUE(0x18, 10), /*!< tmr channel 2 output fast mode */ - TMR_CHANNEL3_OUTPUT_FAST = MAKE_VALUE(0x1c, 2), /*!< tmr channel 3 output fast mode */ - TMR_CHANNEL4_OUTPUT_FAST = MAKE_VALUE(0x1c, 10) /*!< tmr channel 4 output fast mode */ -}tmr_channel_output_fast_type; - -/** - * @brief tmr polarity active type - */ -typedef enum -{ - TMR_POLARITY_ACTIVE_HIGH = 0x00, /*!< tmr polarity active high */ - TMR_POLARITY_ACTIVE_LOW = 0x01, /*!< tmr polarity active low */ - TMR_POLARITY_ACTIVE_BOTH = 0x02 /*!< tmr polarity active both high ande low */ -}tmr_polarity_active_type; - -/** - * @brief tmr external signal divider type - */ -typedef enum -{ - TMR_ES_FREQUENCY_DIV_1 = 0x00, /*!< tmr external signal frequency divider 1 */ - TMR_ES_FREQUENCY_DIV_2 = 0x01, /*!< tmr external signal frequency divider 2 */ - TMR_ES_FREQUENCY_DIV_4 = 0x02, /*!< tmr external signal frequency divider 4 */ - TMR_ES_FREQUENCY_DIV_8 = 0x03 /*!< tmr external signal frequency divider 8 */ -}tmr_external_signal_divider_type; - -/** - * @brief tmr external signal polarity type - */ -typedef enum -{ - TMR_ES_POLARITY_NON_INVERTED = 0x00, /*!< tmr external signal polarity non-inerted */ - TMR_ES_POLARITY_INVERTED = 0x01 /*!< tmr external signal polarity inerted */ -}tmr_external_signal_polarity_type; - -/** - * @brief tmr dma transfer length type - */ -typedef enum -{ - TMR_DMA_TRANSFER_1BYTE = 0x00, /*!< tmr dma transfer length 1 byte */ - TMR_DMA_TRANSFER_2BYTES = 0x01, /*!< tmr dma transfer length 2 bytes */ - TMR_DMA_TRANSFER_3BYTES = 0x02, /*!< tmr dma transfer length 3 bytes */ - TMR_DMA_TRANSFER_4BYTES = 0x03, /*!< tmr dma transfer length 4 bytes */ - TMR_DMA_TRANSFER_5BYTES = 0x04, /*!< tmr dma transfer length 5 bytes */ - TMR_DMA_TRANSFER_6BYTES = 0x05, /*!< tmr dma transfer length 6 bytes */ - TMR_DMA_TRANSFER_7BYTES = 0x06, /*!< tmr dma transfer length 7 bytes */ - TMR_DMA_TRANSFER_8BYTES = 0x07, /*!< tmr dma transfer length 8 bytes */ - TMR_DMA_TRANSFER_9BYTES = 0x08, /*!< tmr dma transfer length 9 bytes */ - TMR_DMA_TRANSFER_10BYTES = 0x09, /*!< tmr dma transfer length 10 bytes */ - TMR_DMA_TRANSFER_11BYTES = 0x0A, /*!< tmr dma transfer length 11 bytes */ - TMR_DMA_TRANSFER_12BYTES = 0x0B, /*!< tmr dma transfer length 12 bytes */ - TMR_DMA_TRANSFER_13BYTES = 0x0C, /*!< tmr dma transfer length 13 bytes */ - TMR_DMA_TRANSFER_14BYTES = 0x0D, /*!< tmr dma transfer length 14 bytes */ - TMR_DMA_TRANSFER_15BYTES = 0x0E, /*!< tmr dma transfer length 15 bytes */ - TMR_DMA_TRANSFER_16BYTES = 0x0F, /*!< tmr dma transfer length 16 bytes */ - TMR_DMA_TRANSFER_17BYTES = 0x10, /*!< tmr dma transfer length 17 bytes */ - TMR_DMA_TRANSFER_18BYTES = 0x11 /*!< tmr dma transfer length 18 bytes */ -}tmr_dma_transfer_length_type; - -/** - * @brief tmr dma base address type - */ -typedef enum -{ - TMR_CTRL1_ADDRESS = 0x0000, /*!< tmr dma base address ctrl1 */ - TMR_CTRL2_ADDRESS = 0x0001, /*!< tmr dma base address ctrl2 */ - TMR_STCTRL_ADDRESS = 0x0002, /*!< tmr dma base address stctrl */ - TMR_IDEN_ADDRESS = 0x0003, /*!< tmr dma base address iden */ - TMR_ISTS_ADDRESS = 0x0004, /*!< tmr dma base address ists */ - TMR_SWEVT_ADDRESS = 0x0005, /*!< tmr dma base address swevt */ - TMR_CM1_ADDRESS = 0x0006, /*!< tmr dma base address cm1 */ - TMR_CM2_ADDRESS = 0x0007, /*!< tmr dma base address cm2 */ - TMR_CCTRL_ADDRESS = 0x0008, /*!< tmr dma base address cctrl */ - TMR_CVAL_ADDRESS = 0x0009, /*!< tmr dma base address cval */ - TMR_DIV_ADDRESS = 0x000A, /*!< tmr dma base address div */ - TMR_PR_ADDRESS = 0x000B, /*!< tmr dma base address pr */ - TMR_RPR_ADDRESS = 0x000C, /*!< tmr dma base address rpr */ - TMR_C1DT_ADDRESS = 0x000D, /*!< tmr dma base address c1dt */ - TMR_C2DT_ADDRESS = 0x000E, /*!< tmr dma base address c2dt */ - TMR_C3DT_ADDRESS = 0x000F, /*!< tmr dma base address c3dt */ - TMR_C4DT_ADDRESS = 0x0010, /*!< tmr dma base address c4dt */ - TMR_BRK_ADDRESS = 0x0011, /*!< tmr dma base address brake */ - TMR_DMACTRL_ADDRESS = 0x0012 /*!< tmr dma base address dmactrl */ -}tmr_dma_address_type; - -/** - * @brief tmr brk polarity type - */ -typedef enum -{ - TMR_BRK_INPUT_ACTIVE_LOW = 0x00, /*!< tmr brk input channel active low */ - TMR_BRK_INPUT_ACTIVE_HIGH = 0x01 /*!< tmr brk input channel active high */ -}tmr_brk_polarity_type; - -/** - * @brief tmr write protect level type - */ -typedef enum -{ - TMR_WP_OFF = 0x00, /*!< tmr write protect off */ - TMR_WP_LEVEL_3 = 0x01, /*!< tmr write protect level 3 */ - TMR_WP_LEVEL_2 = 0x02, /*!< tmr write protect level 2 */ - TMR_WP_LEVEL_1 = 0x03 /*!< tmr write protect level 1 */ -}tmr_wp_level_type; - -/** - * @brief tmr input remap type - */ -typedef enum -{ - TMR2_TMR8TRGOUT_TMR5_GPIO = 0x00, /*!< tmr2 input remap to tmr8_trgout or tmr5 remap to gpio */ - TMR2_PTP_TMR5_LICK = 0x01, /*!< tmr2 input remap to ptp or tmr5 remap to lick */ - TMR2_OTG1FS_TMR5_LEXT = 0x02, /*!< tmr2 input remap to otg1fs or tmr5 remap to lext */ - TMR2_OTG2FS_TMR5_ERTC = 0x03 /*!< tmr2 input remap to otg2fs or tmr5 remap to ertc */ -}tmr_input_remap_type ; -/** - - * @brief tmr output config type - */ -typedef struct -{ - tmr_output_control_mode_type oc_mode; /*!< output channel mode */ - confirm_state oc_idle_state; /*!< output channel idle state */ - confirm_state occ_idle_state; /*!< output channel complementary idle state */ - tmr_output_polarity_type oc_polarity; /*!< output channel polarity */ - tmr_output_polarity_type occ_polarity; /*!< output channel complementary polarity */ - confirm_state oc_output_state; /*!< output channel enable */ - confirm_state occ_output_state; /*!< output channel complementary enable */ -} tmr_output_config_type; - -/** - * @brief tmr input capture config type - */ -typedef struct -{ - tmr_channel_select_type input_channel_select; /*!< tmr input channel select */ - tmr_input_polarity_type input_polarity_select; /*!< tmr input polarity select */ - tmr_input_direction_mapped_type input_mapped_select; /*!< tmr channel mapped direct or indirect */ - uint8_t input_filter_value; /*!< tmr channel filter value */ -} tmr_input_config_type; - -/** - * @brief tmr brkdt config type - */ -typedef struct -{ - uint8_t deadtime; /*!< dead-time generator setup */ - tmr_brk_polarity_type brk_polarity; /*!< tmr brake polarity */ - tmr_wp_level_type wp_level; /*!< write protect configuration */ - confirm_state auto_output_enable; /*!< automatic output enable */ - confirm_state fcsoen_state; /*!< frozen channel status when output enable */ - confirm_state fcsodis_state; /*!< frozen channel status when output disable */ - confirm_state brk_enable; /*!< tmr brk enale */ -} tmr_brkdt_config_type; - -/** - * @brief type define tmr register all - */ -typedef struct -{ - /** - * @brief tmr ctrl1 register, offset:0x00 - */ - union - { - __IO uint32_t ctrl1; - struct - { - __IO uint32_t tmren : 1; /* [0] */ - __IO uint32_t ovfen : 1; /* [1] */ - __IO uint32_t ovfs : 1; /* [2] */ - __IO uint32_t ocmen : 1; /* [3] */ - __IO uint32_t cnt_dir : 3; /* [6:4] */ - __IO uint32_t prben : 1; /* [7] */ - __IO uint32_t clkdiv : 2; /* [9:8] */ - __IO uint32_t pmen : 1; /* [10] */ - __IO uint32_t reserved1 : 21;/* [31:11] */ - } ctrl1_bit; - }; - - /** - * @brief tmr ctrl2 register, offset:0x04 - */ - union - { - __IO uint32_t ctrl2; - struct - { - __IO uint32_t cbctrl : 1; /* [0] */ - __IO uint32_t reserved1 : 1; /* [1] */ - __IO uint32_t ccfs : 1; /* [2] */ - __IO uint32_t drs : 1; /* [3] */ - __IO uint32_t ptos : 3; /* [6:4] */ - __IO uint32_t c1insel : 1; /* [7] */ - __IO uint32_t c1ios : 1; /* [8] */ - __IO uint32_t c1cios : 1; /* [9] */ - __IO uint32_t c2ios : 1; /* [10] */ - __IO uint32_t c2cios : 1; /* [11] */ - __IO uint32_t c3ios : 1; /* [12] */ - __IO uint32_t c3cios : 1; /* [13] */ - __IO uint32_t c4ios : 1; /* [14] */ - __IO uint32_t reserved2 : 16;/* [30:15] */ - __IO uint32_t trgout2en : 1; /* [31] */ - } ctrl2_bit; - }; - - /** - * @brief tmr smc register, offset:0x08 - */ - union - { - __IO uint32_t stctrl; - struct - { - __IO uint32_t smsel : 3; /* [2:0] */ - __IO uint32_t reserved1 : 1; /* [3] */ - __IO uint32_t stis : 3; /* [6:4] */ - __IO uint32_t sts : 1; /* [7] */ - __IO uint32_t esf : 4; /* [11:8] */ - __IO uint32_t esdiv : 2; /* [13:12] */ - __IO uint32_t ecmben : 1; /* [14] */ - __IO uint32_t esp : 1; /* [15] */ - __IO uint32_t reserved2 : 16;/* [31:16] */ - } stctrl_bit; - }; - - /** - * @brief tmr die register, offset:0x0C - */ - union - { - __IO uint32_t iden; - struct - { - __IO uint32_t ovfien : 1; /* [0] */ - __IO uint32_t c1ien : 1; /* [1] */ - __IO uint32_t c2ien : 1; /* [2] */ - __IO uint32_t c3ien : 1; /* [3] */ - __IO uint32_t c4ien : 1; /* [4] */ - __IO uint32_t hallien : 1; /* [5] */ - __IO uint32_t tien : 1; /* [6] */ - __IO uint32_t brkie : 1; /* [7] */ - __IO uint32_t ovfden : 1; /* [8] */ - __IO uint32_t c1den : 1; /* [9] */ - __IO uint32_t c2den : 1; /* [10] */ - __IO uint32_t c3den : 1; /* [11] */ - __IO uint32_t c4den : 1; /* [12] */ - __IO uint32_t hallde : 1; /* [13] */ - __IO uint32_t tden : 1; /* [14] */ - __IO uint32_t reserved1 : 17;/* [31:15] */ - } iden_bit; - }; - - /** - * @brief tmr ists register, offset:0x10 - */ - union - { - __IO uint32_t ists; - struct - { - __IO uint32_t ovfif : 1; /* [0] */ - __IO uint32_t c1if : 1; /* [1] */ - __IO uint32_t c2if : 1; /* [2] */ - __IO uint32_t c3if : 1; /* [3] */ - __IO uint32_t c4if : 1; /* [4] */ - __IO uint32_t hallif : 1; /* [5] */ - __IO uint32_t trgif : 1; /* [6] */ - __IO uint32_t brkif : 1; /* [7] */ - __IO uint32_t reserved1 : 1; /* [8] */ - __IO uint32_t c1rf : 1; /* [9] */ - __IO uint32_t c2rf : 1; /* [10] */ - __IO uint32_t c3rf : 1; /* [11] */ - __IO uint32_t c4rf : 1; /* [12] */ - __IO uint32_t reserved2 : 19;/* [31:13] */ - } ists_bit; - }; - - /** - * @brief tmr eveg register, offset:0x14 - */ - union - { - __IO uint32_t swevt; - struct - { - __IO uint32_t ovfswtr : 1; /* [0] */ - __IO uint32_t c1swtr : 1; /* [1] */ - __IO uint32_t c2swtr : 1; /* [2] */ - __IO uint32_t c3swtr : 1; /* [3] */ - __IO uint32_t c4swtr : 1; /* [4] */ - __IO uint32_t hallswtr : 1; /* [5] */ - __IO uint32_t trgswtr : 1; /* [6] */ - __IO uint32_t brkswtr : 1; /* [7] */ - __IO uint32_t reserved : 24;/* [31:8] */ - } swevt_bit; - }; - - /** - * @brief tmr ccm1 register, offset:0x18 - */ - union - { - __IO uint32_t cm1; - - /** - * @brief channel mode - */ - struct - { - __IO uint32_t c1c : 2; /* [1:0] */ - __IO uint32_t c1oien : 1; /* [2] */ - __IO uint32_t c1oben : 1; /* [3] */ - __IO uint32_t c1octrl : 3; /* [6:4] */ - __IO uint32_t c1osen : 1; /* [7] */ - __IO uint32_t c2c : 2; /* [9:8] */ - __IO uint32_t c2oien : 1; /* [10] */ - __IO uint32_t c2oben : 1; /* [11] */ - __IO uint32_t c2octrl : 3; /* [14:12] */ - __IO uint32_t c2osen : 1; /* [15] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } cm1_output_bit; - - /** - * @brief input capture mode - */ - struct - { - __IO uint32_t c1c : 2; /* [1:0] */ - __IO uint32_t c1idiv : 2; /* [3:2] */ - __IO uint32_t c1df : 4; /* [7:4] */ - __IO uint32_t c2c : 2; /* [9:8] */ - __IO uint32_t c2idiv : 2; /* [11:10] */ - __IO uint32_t c2df : 4; /* [15:12] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } cm1_input_bit; - }; - - /** - * @brief tmr ccm2 register, offset:0x1C - */ - union - { - __IO uint32_t cm2; - - /** - * @brief channel mode - */ - struct - { - __IO uint32_t c3c : 2; /* [1:0] */ - __IO uint32_t c3oien : 1; /* [2] */ - __IO uint32_t c3oben : 1; /* [3] */ - __IO uint32_t c3octrl : 3; /* [6:4] */ - __IO uint32_t c3osen : 1; /* [7] */ - __IO uint32_t c4c : 2; /* [9:8] */ - __IO uint32_t c4oien : 1; /* [10] */ - __IO uint32_t c4oben : 1; /* [11] */ - __IO uint32_t c4octrl : 3; /* [14:12] */ - __IO uint32_t c4osen : 1; /* [15] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } cm2_output_bit; - - /** - * @brief input capture mode - */ - struct - { - __IO uint32_t c3c : 2; /* [1:0] */ - __IO uint32_t c3idiv : 2; /* [3:2] */ - __IO uint32_t c3df : 4; /* [7:4] */ - __IO uint32_t c4c : 2; /* [9:8] */ - __IO uint32_t c4idiv : 2; /* [11:10] */ - __IO uint32_t c4df : 4; /* [15:12] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } cm2_input_bit; - }; - - /** - * @brief tmr cce register, offset:0x20 - */ - union - { - uint32_t cctrl; - struct - { - __IO uint32_t c1en : 1; /* [0] */ - __IO uint32_t c1p : 1; /* [1] */ - __IO uint32_t c1cen : 1; /* [2] */ - __IO uint32_t c1cp : 1; /* [3] */ - __IO uint32_t c2en : 1; /* [4] */ - __IO uint32_t c2p : 1; /* [5] */ - __IO uint32_t c2cen : 1; /* [6] */ - __IO uint32_t c2cp : 1; /* [7] */ - __IO uint32_t c3en : 1; /* [8] */ - __IO uint32_t c3p : 1; /* [9] */ - __IO uint32_t c3cen : 1; /* [10] */ - __IO uint32_t c3cp : 1; /* [11] */ - __IO uint32_t c4en : 1; /* [12] */ - __IO uint32_t c4p : 1; /* [13] */ - __IO uint32_t reserved1 : 18;/* [31:14] */ - } cctrl_bit; - }; - - /** - * @brief tmr cnt register, offset:0x24 - */ - union - { - __IO uint32_t cval; - struct - { - __IO uint32_t cval : 32;/* [31:0] */ - } cval_bit; - }; - - /** - * @brief tmr div, offset:0x28 - */ - union - { - __IO uint32_t div; - struct - { - __IO uint32_t div : 16;/* [15:0] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } div_bit; - }; - - /** - * @brief tmr pr register, offset:0x2C - */ - union - { - __IO uint32_t pr; - struct - { - __IO uint32_t pr : 32;/* [31:0] */ - } pr_bit; - }; - - /** - * @brief tmr rpr register, offset:0x30 - */ - union - { - __IO uint32_t rpr; - struct - { - __IO uint32_t rpr : 16;/* [15:0] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } rpr_bit; - }; - - /** - * @brief tmr c1dt register, offset:0x34 - */ - union - { - uint32_t c1dt; - struct - { - __IO uint32_t c1dt : 32;/* [31:0] */ - } c1dt_bit; - }; - - /** - * @brief tmr c2dt register, offset:0x38 - */ - union - { - uint32_t c2dt; - struct - { - __IO uint32_t c2dt : 32;/* [31:0] */ - } c2dt_bit; - }; - - /** - * @brief tmr c3dt register, offset:0x3C - */ - union - { - __IO uint32_t c3dt; - struct - { - __IO uint32_t c3dt : 32;/* [31:0] */ - } c3dt_bit; - }; - - /** - * @brief tmr c4dt register, offset:0x40 - */ - union - { - __IO uint32_t c4dt; - struct - { - __IO uint32_t c4dt : 32;/* [31:0] */ - } c4dt_bit; - }; - - /** - * @brief tmr brk register, offset:0x44 - */ - union - { - __IO uint32_t brk; - struct - { - __IO uint32_t dtc : 8; /* [7:0] */ - __IO uint32_t wpc : 2; /* [9:8] */ - __IO uint32_t fcsodis : 1; /* [10] */ - __IO uint32_t fcsoen : 1; /* [11] */ - __IO uint32_t brken : 1; /* [12] */ - __IO uint32_t brkv : 1; /* [13] */ - __IO uint32_t aoen : 1; /* [14] */ - __IO uint32_t oen : 1; /* [15] */ - __IO uint32_t reserved1 : 16; /* [31:16] */ - } brk_bit; - }; - /** - * @brief tmr dmactrl register, offset:0x48 - */ - union - { - __IO uint32_t dmactrl; - struct - { - __IO uint32_t addr : 5; /* [4:0] */ - __IO uint32_t reserved1 : 3; /* [7:5] */ - __IO uint32_t dtb : 5; /* [12:8] */ - __IO uint32_t reserved2 : 19;/* [31:13] */ - } dmactrl_bit; - }; - - /** - * @brief tmr dmadt register, offset:0x4C - */ - union - { - __IO uint32_t dmadt; - struct - { - __IO uint32_t dmadt : 16;/* [15:0] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } dmadt_bit; - }; - - /** - * @brief tmr rmp register, offset:0x50 - */ - union - { - __IO uint32_t rmp; - struct - { - __IO uint32_t reserved1 : 6; /* [5:0] */ - __IO uint32_t tmr5_ch4_irmp : 2; /* [7:6] */ - __IO uint32_t reserved2 : 2; /* [9:8] */ - __IO uint32_t tmr2_ch1_irmp : 2; /* [11:10] */ - __IO uint32_t reserved3 : 20;/* [31:16] */ - } rmp_bit; - }; - - /** - * @brief tmr reserved0 register, offset:0x54-0x6C - */ - __IO uint32_t reserved1[7]; - - /** - * @brief tmr cm3 register, offset:0x70 - */ - union - { - __IO uint32_t cm3; - struct - { - __IO uint32_t reserved1 : 2; /* [1:0] */ - __IO uint32_t c5oien : 1; /* [2] */ - __IO uint32_t c5oben : 1; /* [3] */ - __IO uint32_t c5octrl : 3; /* [6:4] */ - __IO uint32_t c5osen : 1; /* [7] */ - __IO uint32_t reserved2 : 24;/* [31:8] */ - } cm3_output_bit; - }; - - /** - * @brief tmr c5dt register, offset:0x74 - */ - union - { - __IO uint32_t c5dt; - struct - { - __IO uint32_t c5dt : 32;/* [31:0] */ - } c5dt_bit; - }; -} tmr_type; - -/** - * @} - */ - -#define TMR1 ((tmr_type *) TMR1_BASE) -#define TMR2 ((tmr_type *) TMR2_BASE) -#define TMR3 ((tmr_type *) TMR3_BASE) -#define TMR4 ((tmr_type *) TMR4_BASE) -#define TMR5 ((tmr_type *) TMR5_BASE) -#define TMR6 ((tmr_type *) TMR6_BASE) -#define TMR7 ((tmr_type *) TMR7_BASE) -#define TMR8 ((tmr_type *) TMR8_BASE) -#define TMR9 ((tmr_type *) TMR9_BASE) -#define TMR10 ((tmr_type *) TMR10_BASE) -#define TMR11 ((tmr_type *) TMR11_BASE) -#define TMR12 ((tmr_type *) TMR12_BASE) -#define TMR13 ((tmr_type *) TMR13_BASE) -#define TMR14 ((tmr_type *) TMR14_BASE) -#define TMR20 ((tmr_type *) TMR20_BASE) - -/** @defgroup TMR_exported_functions - * @{ - */ - -void tmr_reset(tmr_type *tmr_x); -void tmr_counter_enable(tmr_type *tmr_x, confirm_state new_state); -void tmr_output_default_para_init(tmr_output_config_type *tmr_output_struct); -void tmr_input_default_para_init(tmr_input_config_type *tmr_input_struct); -void tmr_brkdt_default_para_init(tmr_brkdt_config_type *tmr_brkdt_struct); -void tmr_base_init(tmr_type* tmr_x, uint32_t tmr_pr, uint32_t tmr_div); -void tmr_clock_source_div_set(tmr_type *tmr_x, tmr_clock_division_type tmr_clock_div); -void tmr_cnt_dir_set(tmr_type *tmr_x, tmr_count_mode_type tmr_cnt_dir); -void tmr_repetition_counter_set(tmr_type *tmr_x, uint8_t tmr_rpr_value); -void tmr_counter_value_set(tmr_type *tmr_x, uint32_t tmr_cnt_value); -uint32_t tmr_counter_value_get(tmr_type *tmr_x); -void tmr_div_value_set(tmr_type *tmr_x, uint32_t tmr_div_value); -uint32_t tmr_div_value_get(tmr_type *tmr_x); -void tmr_output_channel_config(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - tmr_output_config_type *tmr_output_struct); -void tmr_output_channel_mode_select(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - tmr_output_control_mode_type oc_mode); -void tmr_period_value_set(tmr_type *tmr_x, uint32_t tmr_pr_value); -uint32_t tmr_period_value_get(tmr_type *tmr_x); -void tmr_channel_value_set(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - uint32_t tmr_channel_value); -uint32_t tmr_channel_value_get(tmr_type *tmr_x, tmr_channel_select_type tmr_channel); -void tmr_period_buffer_enable(tmr_type *tmr_x, confirm_state new_state); -void tmr_output_channel_buffer_enable(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - confirm_state new_state); -void tmr_output_channel_immediately_set(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - confirm_state new_state); -void tmr_output_channel_switch_set(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - confirm_state new_state); -void tmr_one_cycle_mode_enable(tmr_type *tmr_x, confirm_state new_state); -void tmr_32_bit_function_enable (tmr_type *tmr_x, confirm_state new_state); -void tmr_overflow_request_source_set(tmr_type *tmr_x, confirm_state new_state); -void tmr_overflow_event_disable(tmr_type *tmr_x, confirm_state new_state); -void tmr_input_channel_init(tmr_type *tmr_x, tmr_input_config_type *input_struct, \ - tmr_channel_input_divider_type divider_factor); -void tmr_channel_enable(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, confirm_state new_state); -void tmr_input_channel_filter_set(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - uint16_t filter_value); -void tmr_pwm_input_config(tmr_type *tmr_x, tmr_input_config_type *input_struct, \ - tmr_channel_input_divider_type divider_factor); -void tmr_channel1_input_select(tmr_type *tmr_x, tmr_channel1_input_connected_type ti1_connect); -void tmr_input_channel_divider_set(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - tmr_channel_input_divider_type divider_factor); -void tmr_primary_mode_select(tmr_type *tmr_x, tmr_primary_select_type primary_mode); -void tmr_sub_mode_select(tmr_type *tmr_x, tmr_sub_mode_select_type sub_mode); -void tmr_channel_dma_select(tmr_type *tmr_x, tmr_dma_request_source_type cc_dma_select); -void tmr_hall_select(tmr_type *tmr_x, confirm_state new_state); -void tmr_channel_buffer_enable(tmr_type *tmr_x, confirm_state new_state); -void tmr_trgout2_enable(tmr_type *tmr_x, confirm_state new_state); -void tmr_trigger_input_select(tmr_type *tmr_x, sub_tmr_input_sel_type trigger_select); -void tmr_sub_sync_mode_set(tmr_type *tmr_x, confirm_state new_state); -void tmr_dma_request_enable(tmr_type *tmr_x, tmr_dma_request_type dma_request, confirm_state new_state); -void tmr_interrupt_enable(tmr_type *tmr_x, uint32_t tmr_interrupt, confirm_state new_state); -flag_status tmr_flag_get(tmr_type *tmr_x, uint32_t tmr_flag); -void tmr_flag_clear(tmr_type *tmr_x, uint32_t tmr_flag); -void tmr_event_sw_trigger(tmr_type *tmr_x, tmr_event_trigger_type tmr_event); -void tmr_output_enable(tmr_type *tmr_x, confirm_state new_state); -void tmr_internal_clock_set(tmr_type *tmr_x); -void tmr_output_channel_fast_set(tmr_type *tmr_x, tmr_channel_output_fast_type oc_fast); -void tmr_output_channel_polarity_set(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - tmr_polarity_active_type oc_polarity); -void tmr_external_clock_config(tmr_type *tmr_x, tmr_external_signal_divider_type es_divide, \ - tmr_external_signal_polarity_type es_polarity, uint16_t es_filter); -void tmr_external_clock_mode1_config(tmr_type *tmr_x, tmr_external_signal_divider_type es_divide, \ - tmr_external_signal_polarity_type es_polarity, uint16_t es_filter); -void tmr_external_clock_mode2_config(tmr_type *tmr_x, tmr_external_signal_divider_type es_divide, \ - tmr_external_signal_polarity_type es_polarity, uint16_t es_filter); -void tmr_encoder_mode_config(tmr_type *tmr_x, tmr_encoder_mode_type encoder_mode, tmr_input_polarity_type \ - ic1_polarity, tmr_input_polarity_type ic2_polarity); -void tmr_force_output_set(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - tmr_force_output_type force_output); -void tmr_dma_control_config(tmr_type *tmr_x, tmr_dma_transfer_length_type dma_length, \ - tmr_dma_address_type dma_base_address); -void tmr_brkdt_config(tmr_type *tmr_x, tmr_brkdt_config_type *brkdt_struct); -void tmr_iremap_config(tmr_type *tmr_x, tmr_input_remap_type input_remap); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_usart.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_usart.h deleted file mode 100644 index d7c6176..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_usart.h +++ /dev/null @@ -1,412 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_usart.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 usart header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_USART_H -#define __AT32F435_437_USART_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup USART - * @{ - */ - -/** @defgroup USART_flags_definition - * @brief usart flag - * @{ - */ - -#define USART_PERR_FLAG ((uint32_t)0x00000001) /*!< usart parity error flag */ -#define USART_FERR_FLAG ((uint32_t)0x00000002) /*!< usart framing error flag */ -#define USART_NERR_FLAG ((uint32_t)0x00000004) /*!< usart noise error flag */ -#define USART_ROERR_FLAG ((uint32_t)0x00000008) /*!< usart receiver overflow error flag */ -#define USART_IDLEF_FLAG ((uint32_t)0x00000010) /*!< usart idle flag */ -#define USART_RDBF_FLAG ((uint32_t)0x00000020) /*!< usart receive data buffer full flag */ -#define USART_TDC_FLAG ((uint32_t)0x00000040) /*!< usart transmit data complete flag */ -#define USART_TDBE_FLAG ((uint32_t)0x00000080) /*!< usart transmit data buffer empty flag */ -#define USART_BFF_FLAG ((uint32_t)0x00000100) /*!< usart break frame flag */ -#define USART_CTSCF_FLAG ((uint32_t)0x00000200) /*!< usart cts change flag */ - -/** - * @} - */ - -/** @defgroup USART_interrupts_definition - * @brief usart interrupt - * @{ - */ - -#define USART_IDLE_INT MAKE_VALUE(0x0C,0x04) /*!< usart idle interrupt */ -#define USART_RDBF_INT MAKE_VALUE(0x0C,0x05) /*!< usart receive data buffer full interrupt */ -#define USART_TDC_INT MAKE_VALUE(0x0C,0x06) /*!< usart transmit data complete interrupt */ -#define USART_TDBE_INT MAKE_VALUE(0x0C,0x07) /*!< usart transmit data buffer empty interrupt */ -#define USART_PERR_INT MAKE_VALUE(0x0C,0x08) /*!< usart parity error interrupt */ -#define USART_BF_INT MAKE_VALUE(0x10,0x06) /*!< usart break frame interrupt */ -#define USART_ERR_INT MAKE_VALUE(0x14,0x00) /*!< usart error interrupt */ -#define USART_CTSCF_INT MAKE_VALUE(0x14,0x0A) /*!< usart cts change interrupt */ - -/** - * @} - */ - -/** @defgroup USART_exported_types - * @{ - */ - -/** - * @brief usart parity selection type - */ -typedef enum -{ - USART_PARITY_NONE = 0x00, /*!< usart no parity */ - USART_PARITY_EVEN = 0x01, /*!< usart even parity */ - USART_PARITY_ODD = 0x02 /*!< usart odd parity */ -} usart_parity_selection_type; - -/** - * @brief usart wakeup mode type - */ -typedef enum -{ - USART_WAKEUP_BY_IDLE_FRAME = 0x00, /*!< usart wakeup by idle frame */ - USART_WAKEUP_BY_MATCHING_ID = 0x01 /*!< usart wakeup by matching id */ -} usart_wakeup_mode_type; - -/** - * @brief usart data bit num type - */ -typedef enum -{ - USART_DATA_7BITS = 0x00, /*!< usart data size is 7 bits */ - USART_DATA_8BITS = 0x01, /*!< usart data size is 8 bits */ - USART_DATA_9BITS = 0x02 /*!< usart data size is 9 bits */ -} usart_data_bit_num_type; - -/** - * @brief usart break frame bit num type - */ -typedef enum -{ - USART_BREAK_10BITS = 0x00, /*!< usart lin mode berak frame detection 10 bits */ - USART_BREAK_11BITS = 0x01 /*!< usart lin mode berak frame detection 11 bits */ -} usart_break_bit_num_type; - -/** - * @brief usart phase of the clock type - */ -typedef enum -{ - USART_CLOCK_PHASE_1EDGE = 0x00, /*!< usart data capture is done on the clock leading edge */ - USART_CLOCK_PHASE_2EDGE = 0x01 /*!< usart data capture is done on the clock trailing edge */ -} usart_clock_phase_type; - -/** - * @brief usart polarity of the clock type - */ -typedef enum -{ - USART_CLOCK_POLARITY_LOW = 0x00, /*!< usart clock stay low level outside transmission window */ - USART_CLOCK_POLARITY_HIGH = 0x01 /*!< usart clock stay high level outside transmission window */ -} usart_clock_polarity_type; - -/** - * @brief usart last bit clock pulse type - */ -typedef enum -{ - USART_CLOCK_LAST_BIT_NONE = 0x00, /*!< usart clock pulse of the last data bit is not outputted */ - USART_CLOCK_LAST_BIT_OUTPUT = 0x01 /*!< usart clock pulse of the last data bit is outputted */ -} usart_lbcp_type; - -/** - * @brief usart stop bit num type - */ -typedef enum -{ - USART_STOP_1_BIT = 0x00, /*!< usart stop bits num is 1 */ - USART_STOP_0_5_BIT = 0x01, /*!< usart stop bits num is 0.5 */ - USART_STOP_2_BIT = 0x02, /*!< usart stop bits num is 2 */ - USART_STOP_1_5_BIT = 0x03 /*!< usart stop bits num is 1.5 */ -} usart_stop_bit_num_type; - -/** - * @brief usart hardware flow control type - */ -typedef enum -{ - USART_HARDWARE_FLOW_NONE = 0x00, /*!< usart without hardware flow */ - USART_HARDWARE_FLOW_RTS = 0x01, /*!< usart hardware flow only rts */ - USART_HARDWARE_FLOW_CTS = 0x02, /*!< usart hardware flow only cts */ - USART_HARDWARE_FLOW_RTS_CTS = 0x03 /*!< usart hardware flow both rts and cts */ -} usart_hardware_flow_control_type; - -/** - * @brief usart identification bit num type - */ -typedef enum -{ - USART_ID_FIXED_4_BIT = 0x00, /*!< usart id bit num fixed 4 bits */ - USART_ID_RELATED_DATA_BIT = 0x01 /*!< usart id bit num related data bits */ -} usart_identification_bit_num_type; - -/** - * @brief usart de polarity type - */ -typedef enum -{ - USART_DE_POLARITY_HIGH = 0x00, /*!< usart de polarity high */ - USART_DE_POLARITY_LOW = 0x01 /*!< usart de polarity low */ -} usart_de_polarity_type; - -/** - * @brief type define usart register all - */ -typedef struct -{ - /** - * @brief usart sts register, offset:0x00 - */ - union - { - __IO uint32_t sts; - struct - { - __IO uint32_t perr : 1; /* [0] */ - __IO uint32_t ferr : 1; /* [1] */ - __IO uint32_t nerr : 1; /* [2] */ - __IO uint32_t roerr : 1; /* [3] */ - __IO uint32_t idlef : 1; /* [4] */ - __IO uint32_t rdbf : 1; /* [5] */ - __IO uint32_t tdc : 1; /* [6] */ - __IO uint32_t tdbe : 1; /* [7] */ - __IO uint32_t bff : 1; /* [8] */ - __IO uint32_t ctscf : 1; /* [9] */ - __IO uint32_t reserved1 : 22;/* [31:10] */ - } sts_bit; - }; - - /** - * @brief usart dt register, offset:0x04 - */ - union - { - __IO uint32_t dt; - struct - { - __IO uint32_t dt : 9; /* [8:0] */ - __IO uint32_t reserved1 : 23;/* [31:9] */ - } dt_bit; - }; - - /** - * @brief usart baudr register, offset:0x08 - */ - union - { - __IO uint32_t baudr; - struct - { - __IO uint32_t div : 16;/* [15:0] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } baudr_bit; - }; - - /** - * @brief usart ctrl1 register, offset:0x0C - */ - union - { - __IO uint32_t ctrl1; - struct - { - __IO uint32_t sbf : 1; /* [0] */ - __IO uint32_t rm : 1; /* [1] */ - __IO uint32_t ren : 1; /* [2] */ - __IO uint32_t ten : 1; /* [3] */ - __IO uint32_t idleien : 1; /* [4] */ - __IO uint32_t rdbfien : 1; /* [5] */ - __IO uint32_t tdcien : 1; /* [6] */ - __IO uint32_t tdbeien : 1; /* [7] */ - __IO uint32_t perrien : 1; /* [8] */ - __IO uint32_t psel : 1; /* [9] */ - __IO uint32_t pen : 1; /* [10] */ - __IO uint32_t wum : 1; /* [11] */ - __IO uint32_t dbn_l : 1; /* [12] */ - __IO uint32_t uen : 1; /* [13] */ - __IO uint32_t reserved1 : 2; /* [15:14] */ - __IO uint32_t tcdt : 5; /* [20:16] */ - __IO uint32_t tsdt : 5; /* [25:21] */ - __IO uint32_t reserved2 : 2; /* [27:26] */ - __IO uint32_t dbn_h : 1; /* [28] */ - __IO uint32_t reserved3 : 3; /* [31:29] */ - } ctrl1_bit; - }; - - /** - * @brief usart ctrl2 register, offset:0x10 - */ - union - { - __IO uint32_t ctrl2; - struct - { - __IO uint32_t id_l : 4; /* [3:0] */ - __IO uint32_t idbn : 1; /* [4] */ - __IO uint32_t bfbn : 1; /* [5] */ - __IO uint32_t bfien : 1; /* [6] */ - __IO uint32_t reserved1 : 1; /* [7] */ - __IO uint32_t lbcp : 1; /* [8] */ - __IO uint32_t clkpha : 1; /* [9] */ - __IO uint32_t clkpol : 1; /* [10] */ - __IO uint32_t clken : 1; /* [11] */ - __IO uint32_t stopbn : 2; /* [13:12] */ - __IO uint32_t linen : 1; /* [14] */ - __IO uint32_t trpswap : 1; /* [15] */ - __IO uint32_t reserved2 : 12;/* [27:16] */ - __IO uint32_t id_h : 4; /* [31:28] */ - } ctrl2_bit; - }; - - /** - * @brief usart ctrl3 register, offset:0x14 - */ - union - { - __IO uint32_t ctrl3; - struct - { - __IO uint32_t errien : 1; /* [0] */ - __IO uint32_t irdaen : 1; /* [1] */ - __IO uint32_t irdalp : 1; /* [2] */ - __IO uint32_t slben : 1; /* [3] */ - __IO uint32_t scnacken : 1; /* [4] */ - __IO uint32_t scmen : 1; /* [5] */ - __IO uint32_t dmaren : 1; /* [6] */ - __IO uint32_t dmaten : 1; /* [7] */ - __IO uint32_t rtsen : 1; /* [8] */ - __IO uint32_t ctsen : 1; /* [9] */ - __IO uint32_t ctscfien : 1; /* [10] */ - __IO uint32_t reserved1 : 3; /* [13:11] */ - __IO uint32_t rs485en : 1; /* [14] */ - __IO uint32_t dep : 1; /* [15] */ - __IO uint32_t reserved2 : 16;/* [31:16] */ - } ctrl3_bit; - }; - - /** - * @brief usart gdiv register, offset:0x18 - */ - union - { - __IO uint32_t gdiv; - struct - { - __IO uint32_t isdiv : 8; /* [7:0] */ - __IO uint32_t scgt : 8; /* [15:8] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } gdiv_bit; - }; -} usart_type; - -/** - * @} - */ - -#define USART1 ((usart_type *) USART1_BASE) -#define USART2 ((usart_type *) USART2_BASE) -#define USART3 ((usart_type *) USART3_BASE) -#define UART4 ((usart_type *) UART4_BASE) -#define UART5 ((usart_type *) UART5_BASE) -#define USART6 ((usart_type *) USART6_BASE) -#define UART7 ((usart_type *) UART7_BASE) -#define UART8 ((usart_type *) UART8_BASE) - -/** @defgroup USART_exported_functions - * @{ - */ - -void usart_reset(usart_type* usart_x); -void usart_init(usart_type* usart_x, uint32_t baud_rate, usart_data_bit_num_type data_bit, usart_stop_bit_num_type stop_bit); -void usart_parity_selection_config(usart_type* usart_x, usart_parity_selection_type parity); -void usart_enable(usart_type* usart_x, confirm_state new_state); -void usart_transmitter_enable(usart_type* usart_x, confirm_state new_state); -void usart_receiver_enable(usart_type* usart_x, confirm_state new_state); -void usart_clock_config(usart_type* usart_x, usart_clock_polarity_type clk_pol, usart_clock_phase_type clk_pha, usart_lbcp_type clk_lb); -void usart_clock_enable(usart_type* usart_x, confirm_state new_state); -void usart_interrupt_enable(usart_type* usart_x, uint32_t usart_int, confirm_state new_state); -void usart_dma_transmitter_enable(usart_type* usart_x, confirm_state new_state); -void usart_dma_receiver_enable(usart_type* usart_x, confirm_state new_state); -void usart_wakeup_id_set(usart_type* usart_x, uint8_t usart_id); -void usart_wakeup_mode_set(usart_type* usart_x, usart_wakeup_mode_type wakeup_mode); -void usart_receiver_mute_enable(usart_type* usart_x, confirm_state new_state); -void usart_break_bit_num_set(usart_type* usart_x, usart_break_bit_num_type break_bit); -void usart_lin_mode_enable(usart_type* usart_x, confirm_state new_state); -void usart_data_transmit(usart_type* usart_x, uint16_t data); -uint16_t usart_data_receive(usart_type* usart_x); -void usart_break_send(usart_type* usart_x); -void usart_smartcard_guard_time_set(usart_type* usart_x, uint8_t guard_time_val); -void usart_irda_smartcard_division_set(usart_type* usart_x, uint8_t div_val); -void usart_smartcard_mode_enable(usart_type* usart_x, confirm_state new_state); -void usart_smartcard_nack_set(usart_type* usart_x, confirm_state new_state); -void usart_single_line_halfduplex_select(usart_type* usart_x, confirm_state new_state); -void usart_irda_mode_enable(usart_type* usart_x, confirm_state new_state); -void usart_irda_low_power_enable(usart_type* usart_x, confirm_state new_state); -void usart_hardware_flow_control_set(usart_type* usart_x,usart_hardware_flow_control_type flow_state); -flag_status usart_flag_get(usart_type* usart_x, uint32_t flag); -void usart_flag_clear(usart_type* usart_x, uint32_t flag); -void usart_rs485_delay_time_config(usart_type* usart_x, uint8_t start_delay_time, uint8_t complete_delay_time); -void usart_transmit_receive_pin_swap(usart_type* usart_x, confirm_state new_state); -void usart_id_bit_num_set(usart_type* usart_x, usart_identification_bit_num_type id_bit_num); -void usart_de_polarity_set(usart_type* usart_x, usart_de_polarity_type de_polarity); -void usart_rs485_mode_enable(usart_type* usart_x, confirm_state new_state); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_usb.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_usb.h deleted file mode 100644 index c5fb3fc..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_usb.h +++ /dev/null @@ -1,1422 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_usb.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 usb header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_USB_H -#define __AT32F435_437_USB_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup USB - * @{ - */ - -/** @defgroup USB_global_interrupts_definition - * @brief usb global interrupt mask - * @{ - */ - -#define USB_OTG_MODEMIS_INT ((uint32_t)0x00000002) /*!< usb otg mode mismatch interrupt */ -#define USB_OTG_OTGINT_INT ((uint32_t)0x00000004) /*!< usb otg interrupt */ -#define USB_OTG_SOF_INT ((uint32_t)0x00000008) /*!< usb otg sof interrupt */ -#define USB_OTG_RXFLVL_INT ((uint32_t)0x00000010) /*!< usb otg receive fifo non-empty interrupt */ -#define USB_OTG_NPTXFEMP_INT ((uint32_t)0x00000020) /*!< usb otg non-periodic tx fifo empty interrupt */ -#define USB_OTG_GINNAKEFF_INT ((uint32_t)0x00000040) /*!< usb otg global non-periodic in nak effective interrupt */ -#define USB_OTG_GOUTNAKEFF_INT ((uint32_t)0x00000080) /*!< usb otg global out nak effective interrupt */ -#define USB_OTG_ERLYSUSP_INT ((uint32_t)0x00000400) /*!< usb otg early suspend interrupt */ -#define USB_OTG_USBSUSP_INT ((uint32_t)0x00000800) /*!< usb otg suspend interrupt */ -#define USB_OTG_USBRST_INT ((uint32_t)0x00001000) /*!< usb otg reset interrupt */ -#define USB_OTG_ENUMDONE_INT ((uint32_t)0x00002000) /*!< usb otg enumeration done interrupt */ -#define USB_OTG_ISOOUTDROP_INT ((uint32_t)0x00004000) /*!< usb otg isochronous out packet dropped interrut */ -#define USB_OTG_EOPF_INT ((uint32_t)0x00008000) /*!< usb otg eop interrupt */ -#define USB_OTG_IEPT_INT ((uint32_t)0x00040000) /*!< usb otg in endpoint interrupt */ -#define USB_OTG_OEPT_INT ((uint32_t)0x00080000) /*!< usb otg out endpoint interrupt */ -#define USB_OTG_INCOMISOIN_INT ((uint32_t)0x00100000) /*!< usb otg incomplete isochronous in transfer interrupt */ -#define USB_OTG_INCOMPIP_INCOMPISOOUT_INT ((uint32_t)0x00200000) /*!< usb otg incomplete periodic transfer/isochronous out interrupt */ -#define USB_OTG_PRT_INT ((uint32_t)0x01000000) /*!< usb otg host port interrupt */ -#define USB_OTG_HCH_INT ((uint32_t)0x02000000) /*!< usb otg host channel interrupt */ -#define USB_OTG_PTXFEMP_INT ((uint32_t)0x04000000) /*!< usb otg periodic txfifo empty interrupt */ -#define USB_OTG_CONIDSCHG_INT ((uint32_t)0x10000000) /*!< usb otg connector id status change interrupt */ -#define USB_OTG_DISCON_INT ((uint32_t)0x20000000) /*!< usb otg disconnect detected interrupt */ -#define USB_OTG_WKUP_INT ((uint32_t)0x80000000) /*!< usb otg wakeup interrupt */ - -/** - * @} - */ - -/** @defgroup USB_global_interrupt_flags_definition - * @brief usb global interrupt flag - * @{ - */ - -#define USB_OTG_CURMODE ((uint32_t)0x00000001) /*!< usb otg current mode */ -#define USB_OTG_MODEMIS_FLAG ((uint32_t)0x00000002) /*!< usb otg mode mismatch flag */ -#define USB_OTG_OTGINT_FLAG ((uint32_t)0x00000004) /*!< usb otg flag */ -#define USB_OTG_SOF_FLAG ((uint32_t)0x00000008) /*!< usb otg sof flag */ -#define USB_OTG_RXFLVL_FLAG ((uint32_t)0x00000010) /*!< usb otg receive fifo non-empty flag */ -#define USB_OTG_NPTXFEMP_FLAG ((uint32_t)0x00000020) /*!< usb otg non-periodic tx fifo empty flag */ -#define USB_OTG_GINNAKEFF_FLAG ((uint32_t)0x00000040) /*!< usb otg global non-periodic in nak effective flag */ -#define USB_OTG_GOUTNAKEFF_FLAG ((uint32_t)0x00000080) /*!< usb otg global out nak effective flag */ -#define USB_OTG_ERLYSUSP_FLAG ((uint32_t)0x00000400) /*!< usb otg early suspend flag */ -#define USB_OTG_USBSUSP_FLAG ((uint32_t)0x00000800) /*!< usb otg suspend flag */ -#define USB_OTG_USBRST_FLAG ((uint32_t)0x00001000) /*!< usb otg reset flag */ -#define USB_OTG_ENUMDONE_FLAG ((uint32_t)0x00002000) /*!< usb otg enumeration done flag */ -#define USB_OTG_ISOOUTDROP_FLAG ((uint32_t)0x00004000) /*!< usb otg isochronous out packet dropped flag */ -#define USB_OTG_EOPF_FLAG ((uint32_t)0x00008000) /*!< usb otg eop flag */ -#define USB_OTG_IEPT_FLAG ((uint32_t)0x00040000) /*!< usb otg in endpoint flag */ -#define USB_OTG_OEPT_FLAG ((uint32_t)0x00080000) /*!< usb otg out endpoint flag */ -#define USB_OTG_INCOMISOIN_FLAG ((uint32_t)0x00100000) /*!< usb otg incomplete isochronous in transfer flag */ -#define USB_OTG_INCOMPIP_INCOMPISOOUT_FLAG ((uint32_t)0x00200000) /*!< usb otg incomplete periodic transfer/isochronous out flag */ -#define USB_OTG_PRT_FLAG ((uint32_t)0x01000000) /*!< usb otg host port flag */ -#define USB_OTG_HCH_FLAG ((uint32_t)0x02000000) /*!< usb otg host channel flag */ -#define USB_OTG_PTXFEMP_FLAG ((uint32_t)0x04000000) /*!< usb otg periodic txfifo empty flag */ -#define USB_OTG_CONIDSCHG_FLAG ((uint32_t)0x10000000) /*!< usb otg connector id status change flag */ -#define USB_OTG_DISCON_FLAG ((uint32_t)0x20000000) /*!< usb otg disconnect detected flag */ -#define USB_OTG_WKUP_FLAG ((uint32_t)0x80000000) /*!< usb otg wakeup flag */ - -/** - * @} - */ - - -/** @defgroup USB_global_setting_definition - * @brief usb global setting - * @{ - */ - -/** - * @brief usb turnaround time - */ -#define USB_TRDTIM_8 0x9 /*!< usb turn around time 8 */ -#define USB_TRDTIM_16 0x5 /*!< usb turn around time 16 */ - -/** - * @brief usb receive status - */ -#define USB_OTG_GRXSTSP_EPTNUM ((uint32_t)0x0000000F) /*!< usb device receive packet endpoint number*/ -#define USB_OTG_GRXSTSP_CHNUM ((uint32_t)0x0000000F) /*!< usb host receive packet channel number*/ -#define USB_OTG_GRXSTSP_BCNT ((uint32_t)0x00007FF0) /*!< usb receive packet byte count */ -#define USB_OTG_GRXSTSP_DPID ((uint32_t)0x00018000) /*!< usb receive packet pid */ -#define USB_OTG_GRXSTSP_PKTSTS ((uint32_t)0x001E0000) /*!< usb receive packet status */ - -/** - * @brief usb host packet status - */ -#define PKTSTS_IN_DATA_PACKET_RECV 0x2 /*!< usb host in data packet received */ -#define PKTSTS_IN_TRANSFER_COMPLETE 0x3 /*!< usb host in transfer completed */ -#define PKTSTS_DATA_BIT_ERROR 0x5 /*!< usb host data toggle error */ -#define PKTSTS_CHANNEL_STOP 0x7 /*!< usb host channel halted */ - -/** - * @brief usb device packet status - */ -#define USB_OUT_STS_NAK 0x1 /*!< usb device global out nak */ -#define USB_OUT_STS_DATA 0x2 /*!< usb device out data packet received */ -#define USB_OUT_STS_COMP 0x3 /*!< usb device out transfer completed */ -#define USB_SETUP_STS_COMP 0x4 /*!< usb device setup transcation completed */ -#define USB_SETUP_STS_DATA 0x6 /*!< usb device setup data packet received */ - -/** - * @} - */ - -/** @defgroup USB_host_config_definition - * @{ - */ - -/** - * @brief usb host phy clock - */ -#define USB_HCFG_CLK_60M 0 /*!< usb host phy clock 60mhz */ -#define USB_HCFG_CLK_48M 1 /*!< usb host phy clock 48mhz */ -#define USB_HCFG_CLK_6M 2 /*!< usb host phy clock 6mhz */ - -/** - * @brief usb host port status - */ -#define USB_OTG_HPRT_PRTCONSTS ((uint32_t)0x00000001) /*!< usb host port connect status */ -#define USB_OTG_HPRT_PRTCONDET ((uint32_t)0x00000002) /*!< usb host port connect detected */ -#define USB_OTG_HPRT_PRTENA ((uint32_t)0x00000004) /*!< usb host port enable */ -#define USB_OTG_HPRT_PRTENCHNG ((uint32_t)0x00000008) /*!< usb host port enable/disable change */ -#define USB_OTG_HPRT_PRTOVRCACT ((uint32_t)0x00000010) /*!< usb host port overcurrent active */ -#define USB_OTG_HPRT_PRTOVRCCHNG ((uint32_t)0x00000020) /*!< usb host port overcurrent change */ -#define USB_OTG_HPRT_PRTRES ((uint32_t)0x00000040) /*!< usb host port resume */ -#define USB_OTG_HPRT_PRTSUSP ((uint32_t)0x00000080) /*!< usb host port suspend */ -#define USB_OTG_HPRT_PRTRST ((uint32_t)0x00000100) /*!< usb host port reset */ -#define USB_OTG_HPRT_PRTLNSTS ((uint32_t)0x00000C00) /*!< usb host port line status */ -#define USB_OTG_HPRT_PRTPWR ((uint32_t)0x00001000) /*!< usb host port power */ -#define USB_OTG_HPRT_PRTSPD ((uint32_t)0x00060000) /*!< usb host port speed */ - -/** - * @brief usb port speed - */ -#define USB_PRTSPD_HIGH_SPEED 0 /*!< usb host port high speed */ -#define USB_PRTSPD_FULL_SPEED 1 /*!< usb host port full speed */ -#define USB_PRTSPD_LOW_SPEED 2 /*!< usb host port low speed */ - -/** - * @brief usb host register hcchar bit define - */ -#define USB_OTG_HCCHAR_MPS ((uint32_t)0x000007FF) /*!< channel maximum packet size */ -#define USB_OTG_HCCHAR_EPTNUM ((uint32_t)0x00007800) /*!< endpoint number */ -#define USB_OTG_HCCHAR_EPTDIR ((uint32_t)0x00008000) /*!< endpoint direction */ -#define USB_OTG_HCCHAR_LSPDDEV ((uint32_t)0x00020000) /*!< low speed device */ -#define USB_OTG_HCCHAR_EPTYPE ((uint32_t)0x000C0000) /*!< endpoint type */ -#define USB_OTG_HCCHAR_MC ((uint32_t)0x00300000) /*!< multi count */ -#define USB_OTG_HCCHAR_DEVADDR ((uint32_t)0x1FC00000) /*!< device address */ -#define USB_OTG_HCCHAR_ODDFRM ((uint32_t)0x20000000) /*!< odd frame */ -#define USB_OTG_HCCHAR_CHDIS ((uint32_t)0x40000000) /*!< channel disable */ -#define USB_OTG_HCCHAR_CHENA ((uint32_t)0x80000000) /*!< channel enable */ - -/** - * @brief usb host register hctsiz bit define - */ -#define USB_OTG_HCTSIZ_XFERSIZE ((uint32_t)0x0007FFFF) /*!< channel transfer size */ -#define USB_OTG_HCTSIZ_PKTCNT ((uint32_t)0x1FF80000) /*!< channel packet count */ -#define USB_OTG_HCTSIZ_PID ((uint32_t)0x60000000) /*!< channel pid */ - -/** - * @brief usb host channel interrupt mask - */ -#define USB_OTG_HC_XFERCM_INT ((uint32_t)0x00000001) /*!< channel transfer complete interrupt */ -#define USB_OTG_HC_CHHLTDM_INT ((uint32_t)0x00000002) /*!< channel halted interrupt */ -#define USB_OTG_HC_STALLM_INT ((uint32_t)0x00000008) /*!< channel stall interrupt */ -#define USB_OTG_HC_NAKM_INT ((uint32_t)0x00000010) /*!< channel nak interrupt */ -#define USB_OTG_HC_ACKM_INT ((uint32_t)0x00000020) /*!< channel ack interrupt */ -#define USB_OTG_HC_NYETM_INT ((uint32_t)0x00000040) /*!< channel nyet interrupt */ -#define USB_OTG_HC_XACTERRM_INT ((uint32_t)0x00000080) /*!< channel transaction error interrupt */ -#define USB_OTG_HC_BBLERRM_INT ((uint32_t)0x00000100) /*!< channel babble error interrupt */ -#define USB_OTG_HC_FRMOVRRUN_INT ((uint32_t)0x00000200) /*!< channel frame overrun interrupt */ -#define USB_OTG_HC_DTGLERRM_INT ((uint32_t)0x00000400) /*!< channel data toggle interrupt */ - -/** - * @brief usb host channel interrupt flag - */ -#define USB_OTG_HC_XFERC_FLAG ((uint32_t)0x00000001) /*!< channel transfer complete flag */ -#define USB_OTG_HC_CHHLTD_FLAG ((uint32_t)0x00000002) /*!< channel halted flag */ -#define USB_OTG_HC_STALL_FLAG ((uint32_t)0x00000008) /*!< channel stall flag */ -#define USB_OTG_HC_NAK_FLAG ((uint32_t)0x00000010) /*!< channel nak flag */ -#define USB_OTG_HC_ACK_FLAG ((uint32_t)0x00000020) /*!< channel ack flag */ -#define USB_OTG_HC_NYET_FLAG ((uint32_t)0x00000040) /*!< channel nyet flag */ -#define USB_OTG_HC_XACTERR_FLAG ((uint32_t)0x00000080) /*!< channel transaction error flag */ -#define USB_OTG_HC_BBLERR_FLAG ((uint32_t)0x00000100) /*!< channel babble error flag */ -#define USB_OTG_HC_FRMOVRRUN_FLAG ((uint32_t)0x00000200) /*!< channel frame overrun flag */ -#define USB_OTG_HC_DTGLERR_FLAG ((uint32_t)0x00000400) /*!< channel data toggle flag */ - -/** - * @} - */ - - -/** @defgroup USB_device_config_definition - * @{ - */ -/** - * @brief usb device periodic frame interval - */ -typedef enum -{ - DCFG_PERFRINT_80 = 0x00, /*!< periodic frame interval 80% */ - DCFG_PERFRINT_85 = 0x01, /*!< periodic frame interval 85% */ - DCFG_PERFRINT_90 = 0x02, /*!< periodic frame interval 90% */ - DCFG_PERFRINT_95 = 0x03 /*!< periodic frame interval 95% */ -} dcfg_perfrint_type; - - -/** - * @brief usb device full speed - */ -#define USB_DCFG_FULL_SPEED 3 /*!< device full speed */ - -/** - * @brief usb device ctrl define - */ -#define USB_OTG_DCTL_RWKUPSIG ((uint32_t)0x00000001) /*!< usb device remote wakeup signaling */ -#define USB_OTG_DCTL_SFTDISCON ((uint32_t)0x00000002) /*!< usb device soft disconnect */ -#define USB_OTG_DCTL_GNPINNAKSTS ((uint32_t)0x00000004) /*!< usb device global non-periodic in nak status */ -#define USB_OTG_DCTL_GOUTNAKSTS ((uint32_t)0x00000008) /*!< usb device global out nak status */ -#define USB_OTG_DCTL_SGNPINNAK ((uint32_t)0x00000080) /*!< usb device set global non-periodic in nak */ -#define USB_OTG_DCTL_CGNPINNAK ((uint32_t)0x00000100) /*!< usb device clear global non-periodic in nak */ -#define USB_OTG_DCTL_SGOUTNAK ((uint32_t)0x00000200) /*!< usb device set global out nak status */ -#define USB_OTG_DCTL_CGOUTNAK ((uint32_t)0x00000400) /*!< usb device clear global out nak status */ -#define USB_OTG_DCTL_PWROPRGDNE ((uint32_t)0x00000800) /*!< usb device power on programming done */ - -/** - * @brief usb device in endpoint flag - */ -#define USB_OTG_DIEPINT_XFERC_FLAG ((uint32_t)0x00000001) /*!< usb device in transfer completed flag */ -#define USB_OTG_DIEPINT_EPTDISD_FLAG ((uint32_t)0x00000002) /*!< usb device endpoint disable flag */ -#define USB_OTG_DIEPINT_TIMEOUT_FLAG ((uint32_t)0x00000008) /*!< usb device in timeout */ -#define USB_OTG_DIEPINT_INTKNTXFEMP_FLAG ((uint32_t)0x00000010) /*!< usb device in token received when tx fifo is empty flag */ -#define USB_OTG_DIEPINT_INEPTNAK_FLAG ((uint32_t)0x00000040) /*!< usb device in endpoint nak effective flag */ -#define USB_OTG_DIEPINT_TXFEMP_FLAG ((uint32_t)0x00000080) /*!< usb device transmit fifo empty flag */ - -/** - * @brief usb device out endpoint flag - */ -#define USB_OTG_DOEPINT_XFERC_FLAG ((uint32_t)0x00000001) /*!< usb device out transfer completed flag */ -#define USB_OTG_DOEPINT_EPTDISD_FLAG ((uint32_t)0x00000002) /*!< usb device endpoint disable flag */ -#define USB_OTG_DOEPINT_SETUP_FLAG ((uint32_t)0x00000008) /*!< usb device setup flag */ -#define USB_OTG_DOEPINT_OUTTEPD_FLAG ((uint32_t)0x00000010) /*!< usb device out token recevied when endpoint disable flag */ -#define USB_OTG_DOEPINT_B2BSTUP_FLAG ((uint32_t)0x00000040) /*!< back-to-back setup packets received */ - -/** - * @brief usb device in endpoint fifo space mask - */ -#define USB_OTG_DTXFSTS_INEPTFSAV ((uint32_t)0x0000FFFF) /*!< usb device in endpoint tx fifo space avail */ - -/** - * @brief endpoint0 maximum packet size - */ -#define USB_EPT0_MPS_64 0 /*!< usb device endpoint 0 maximum packet size 64byte */ -#define USB_EPT0_MPS_32 1 /*!< usb device endpoint 0 maximum packet size 32byte */ -#define USB_EPT0_MPS_16 2 /*!< usb device endpoint 0 maximum packet size 16byte */ -#define USB_EPT0_MPS_8 3 /*!< usb device endpoint 0 maximum packet size 8byte */ - -/** - * @} - */ - -/** - * @brief otg fifo size (word) - */ -#define OTG_FIFO_SIZE 320 /*!< otg usb total fifo size */ - -/** - * @brief otg host max buffer length (byte) - */ -#define USB_MAX_DATA_LENGTH 0x200 /*!< usb host maximum buffer size */ - -#define OTGFS_USB_GLOBAL -#define OTGFS_USB_DEVICE -#define OTGFS_USB_HOST - -/** @defgroup USB_exported_enum_types - * @{ - */ - -/** - * @brief usb mode define(device, host, drd) - */ -typedef enum -{ - OTG_DEVICE_MODE, /*!< usb device mode */ - OTG_HOST_MODE, /*!< usb host mode */ - OTG_DRD_MODE /*!< usb drd mode */ -} otg_mode_type; - -/** - * @brief endpoint type define - */ -typedef enum -{ - EPT_CONTROL_TYPE = 0x00, /*!< usb endpoint type control */ - EPT_ISO_TYPE = 0x01, /*!< usb endpoint type iso */ - EPT_BULK_TYPE = 0x02, /*!< usb endpoint type bulk */ - EPT_INT_TYPE = 0x03 /*!< usb endpoint type interrupt */ -} endpoint_trans_type; - -/** - * @brief usb endpoint number define type - */ -typedef enum -{ - USB_EPT0 = 0x00, /*!< usb endpoint 0 */ - USB_EPT1 = 0x01, /*!< usb endpoint 1 */ - USB_EPT2 = 0x02, /*!< usb endpoint 2 */ - USB_EPT3 = 0x03, /*!< usb endpoint 3 */ - USB_EPT4 = 0x04, /*!< usb endpoint 4 */ - USB_EPT5 = 0x05, /*!< usb endpoint 5 */ - USB_EPT6 = 0x06, /*!< usb endpoint 6 */ - USB_EPT7 = 0x07 /*!< usb endpoint 7 */ -} usb_endpoint_number_type; - -/** - * @brief usb endpoint max num define - */ -#ifndef USB_EPT_MAX_NUM -#define USB_EPT_MAX_NUM 8 /*!< usb device support endpoint number */ -#endif -/** - * @brief usb channel max num define - */ -#ifndef USB_HOST_CHANNEL_NUM -#define USB_HOST_CHANNEL_NUM 16 /*!< usb host support channel number */ -#endif - -/** - * @brief endpoint trans dir type - */ -typedef enum -{ - EPT_DIR_IN = 0x00, /*!< usb transfer direction in */ - EPT_DIR_OUT = 0x01 /*!< usb transfer direction out */ -} endpoint_dir_type; - -/** - * @brief otgfs1 and otgfs2 select type - */ -typedef enum -{ - USB_OTG1_ID, /*!< usb otg 1 id */ - USB_OTG2_ID /*!< usb otg 2 id */ -} otg_id_type; - -/** - * @brief usb clock select - */ -typedef enum -{ - USB_CLK_HICK, /*!< usb clock use hick */ - USB_CLK_HEXT /*!< usb clock use hext */ -}usb_clk48_s; - -/** - * @} - */ - - - -/** @defgroup USB_exported_types - * @{ - */ - -/** - * @brief usb endpoint infomation structure definition - */ -typedef struct -{ - uint8_t eptn; /*!< endpoint register number (0~7) */ - uint8_t ept_address; /*!< endpoint address */ - uint8_t inout; /*!< endpoint dir EPT_DIR_IN or EPT_DIR_OUT */ - uint8_t trans_type; /*!< endpoint type: - EPT_CONTROL_TYPE, EPT_BULK_TYPE, EPT_INT_TYPE, EPT_ISO_TYPE*/ - uint16_t tx_addr; /*!< endpoint tx buffer offset address */ - uint16_t rx_addr; /*!< endpoint rx buffer offset address */ - uint32_t maxpacket; /*!< endpoint max packet*/ - uint8_t is_double_buffer; /*!< endpoint double buffer flag */ - uint8_t stall; /*!< endpoint is stall state */ - uint32_t status; - - /* transmission buffer and count */ - uint8_t *trans_buf; /*!< endpoint transmission buffer */ - uint32_t total_len; /*!< endpoint transmission lengtg */ - uint32_t trans_len; /*!< endpoint transmission length*/ - - uint32_t last_len; /*!< last transfer length */ - uint32_t ept0_slen; /*!< endpoint 0 transfer sum length */ -} usb_ept_info; - - -/** - * @brief usb host channel infomation structure definition - */ -typedef struct -{ - uint8_t ch_num; /*!< host channel number */ - uint8_t address; /*!< device address */ - uint8_t dir; /*!< transmission direction */ - uint8_t ept_num; /*!< device endpoint number */ - uint8_t ept_type; /*!< channel transmission type */ - uint32_t maxpacket; /*!< support max packet size */ - uint8_t data_pid; /*!< data pid */ - uint8_t speed; /*!< usb speed */ - uint8_t stall; /*!< channel stall flag */ - uint32_t status; /*!< channel status */ - uint32_t state; /*!< channel state */ - uint32_t urb_sts; /*!< usb channel request block state */ - - uint8_t toggle_in; /*!< channel in transfer toggle */ - uint8_t toggle_out; /*!< channel out transfer toggle */ - - /* transmission buffer and count */ - uint8_t *trans_buf; /* host channel buffer */ - uint32_t trans_len; /* host channel transmission len */ - uint32_t trans_count; /* host channel transmission count*/ -} usb_hch_type; - - -typedef struct -{ - /** - * @brief otgfs control and status register, offset:0x00 - */ - union - { - __IO uint32_t gotgctrl; - struct - { - __IO uint32_t reserved1 : 16; /* [15:0] */ - __IO uint32_t cidsts : 1; /* [16] */ - __IO uint32_t reserved2 : 4; /* [20:17] */ - __IO uint32_t curmod : 1; /* [21] */ - __IO uint32_t reserved3 : 10; /* [31:22] */ - } gotgctrl_bit; - }; - - /** - * @brief otgfs interrupt register, offset:0x04 - */ - union - { - __IO uint32_t gotgint; - struct - { - __IO uint32_t reserved1 : 2; /* [1:0] */ - __IO uint32_t sesenddet : 1; /* [2] */ - __IO uint32_t reserved2 : 29; /* [31:3] */ - - } gotgint_bit; - }; - - /** - * @brief otgfs gahbcfg configuration register, offset:0x08 - */ - union - { - __IO uint32_t gahbcfg; - struct - { - __IO uint32_t glbintmsk : 1; /* [0] */ - __IO uint32_t reserved1 : 6; /* [6:1] */ - __IO uint32_t nptxfemplvl : 1; /* [7] */ - __IO uint32_t ptxfemplvl : 1; /* [8] */ - __IO uint32_t reserved2 : 23; /* [31:9] */ - } gahbcfg_bit; - }; - - /** - * @brief otgfs usb configuration register, offset:0x0C - */ - union - { - __IO uint32_t gusbcfg; - struct - { - __IO uint32_t toutcal : 3; /* [2:0] */ - __IO uint32_t reserved1 : 7; /* [9:3] */ - __IO uint32_t usbtrdtim : 4; /* [13:10] */ - __IO uint32_t reserved2 : 15; /* [28:14] */ - __IO uint32_t fhstmode : 1; /* [29] */ - __IO uint32_t fdevmode : 1; /* [30] */ - __IO uint32_t cotxpkt : 1; /* [31] */ - } gusbcfg_bit; - }; - - /** - * @brief otgfs reset register, offset:0x10 - */ - union - { - __IO uint32_t grstctl; - struct - { - __IO uint32_t csftrst : 1; /* [0] */ - __IO uint32_t piusftrst : 1; /* [1] */ - __IO uint32_t frmcntrst : 1; /* [2] */ - __IO uint32_t reserved1 : 1; /* [3] */ - __IO uint32_t rxfflsh : 1; /* [4] */ - __IO uint32_t txfflsh : 1; /* [5] */ - __IO uint32_t txfnum : 5; /* [10:6] */ - __IO uint32_t reserved2 : 20; /* [30:11] */ - __IO uint32_t ahbidle : 1; /* [31] */ - } grstctl_bit; - }; - - /** - * @brief otgfs core interrupt register, offset:0x14 - */ - union - { - __IO uint32_t gintsts; - struct - { - __IO uint32_t curmode : 1; /* [0] */ - __IO uint32_t modemis : 1; /* [1] */ - __IO uint32_t otgint : 1; /* [2] */ - __IO uint32_t sof : 1; /* [3] */ - __IO uint32_t rxflvl : 1; /* [4] */ - __IO uint32_t nptxfemp : 1; /* [5] */ - __IO uint32_t ginnakeff : 1; /* [6] */ - __IO uint32_t goutnakeff : 1; /* [7] */ - __IO uint32_t reserved1 : 2; /* [9:8]] */ - __IO uint32_t erlysusp : 1; /* [10] */ - __IO uint32_t usbsusp : 1; /* [11] */ - __IO uint32_t usbrst : 1; /* [12] */ - __IO uint32_t enumdone : 1; /* [13] */ - __IO uint32_t isooutdrop : 1; /* [14] */ - __IO uint32_t eopf : 1; /* [15] */ - __IO uint32_t reserved2 : 2; /* [17:16]] */ - __IO uint32_t ieptint : 1; /* [18] */ - __IO uint32_t oeptint : 1; /* [19] */ - __IO uint32_t incompisoin : 1; /* [20] */ - __IO uint32_t incompip_incompisoout : 1; /* [21] */ - __IO uint32_t reserved3 : 2; /* [23:22] */ - __IO uint32_t prtint : 1; /* [24] */ - __IO uint32_t hchint : 1; /* [25] */ - __IO uint32_t ptxfemp : 1; /* [26] */ - __IO uint32_t reserved4 : 1; /* [27] */ - __IO uint32_t conidschg : 1; /* [28] */ - __IO uint32_t disconint : 1; /* [29] */ - __IO uint32_t reserved5 : 1; /* [30] */ - __IO uint32_t wkupint : 1; /* [31] */ - } gintsts_bit; - }; - - /** - * @brief otgfs interrupt mask register, offset:0x18 - */ - union - { - __IO uint32_t gintmsk; - struct - { - __IO uint32_t reserved1 : 1; /* [0] */ - __IO uint32_t modemismsk : 1; /* [1] */ - __IO uint32_t otgintmsk : 1; /* [2] */ - __IO uint32_t sofmsk : 1; /* [3] */ - __IO uint32_t rxflvlmsk : 1; /* [4] */ - __IO uint32_t nptxfempmsk : 1; /* [5] */ - __IO uint32_t ginnakeffmsk : 1; /* [6] */ - __IO uint32_t goutnakeffmsk : 1; /* [7] */ - __IO uint32_t reserved2 : 2; /* [9:8]] */ - __IO uint32_t erlysuspmsk : 1; /* [10] */ - __IO uint32_t usbsuspmsk : 1; /* [11] */ - __IO uint32_t usbrstmsk : 1; /* [12] */ - __IO uint32_t enumdonemsk : 1; /* [13] */ - __IO uint32_t isooutdropmsk : 1; /* [14] */ - __IO uint32_t eopfmsk : 1; /* [15] */ - __IO uint32_t reserved3 : 2; /* [17:16]] */ - __IO uint32_t ieptintmsk : 1; /* [18] */ - __IO uint32_t oeptintmsk : 1; /* [19] */ - __IO uint32_t incompisoinmsk : 1; /* [20] */ - __IO uint32_t incompip_incompisooutmsk : 1; /* [21] */ - __IO uint32_t reserved4 : 2; /* [23:22] */ - __IO uint32_t prtintmsk : 1; /* [24] */ - __IO uint32_t hchintmsk : 1; /* [25] */ - __IO uint32_t ptxfempmsk : 1; /* [26] */ - __IO uint32_t reserved5 : 1; /* [27] */ - __IO uint32_t conidschgmsk : 1; /* [28] */ - __IO uint32_t disconintmsk : 1; /* [29] */ - __IO uint32_t reserved6 : 1; /* [30] */ - __IO uint32_t wkupintmsk : 1; /* [31] */ - } gintmsk_bit; - }; - - /** - * @brief otgfs rx status debug read register, offset:0x1C - */ - union - { - __IO uint32_t grxstsr; - struct - { - __IO uint32_t eptnum : 4; /* [3:0] */ - __IO uint32_t bcnt : 11; /* [14:4] */ - __IO uint32_t dpid : 2; /* [16:15] */ - __IO uint32_t pktsts : 4; /* [20:17] */ - __IO uint32_t fn : 4; /* [24:21] */ - __IO uint32_t reserved1 : 7; /* [31:25] */ - } grxstsr_bit; - }; - - /** - * @brief otgfs rx status read and pop register, offset:0x20 - */ - union - { - __IO uint32_t grxstsp; - struct - { - __IO uint32_t chnum : 4; /* [3:0] */ - __IO uint32_t bcnt : 11; /* [14:4] */ - __IO uint32_t dpid : 2; /* [16:15] */ - __IO uint32_t pktsts : 4; /* [20:17] */ - __IO uint32_t reserved1 : 11; /* [31:21] */ - } grxstsp_bit; - }; - - /** - * @brief otgfs rx fifo size register, offset:0x24 - */ - union - { - __IO uint32_t grxfsiz; - struct - { - __IO uint32_t rxfdep : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [31:16] */ - } grxfsiz_bit; - }; - - /** - * @brief otgfs non-periodic and ept0 tx fifo size register, offset:0x28 - */ - union - { - __IO uint32_t gnptxfsiz_ept0tx; - struct - { - __IO uint32_t nptxfstaddr : 16; /* [15:0] */ - __IO uint32_t nptxfdep : 16; /* [31:16] */ - } gnptxfsiz_ept0tx_bit; - }; - - /** - * @brief otgfs non-periodic tx fifo request queue status register, offset:0x2C - */ - union - { - __IO uint32_t gnptxsts; - struct - { - __IO uint32_t nptxfspcavail : 16; /* [15:0] */ - __IO uint32_t nptxqspcavail : 8; /* [23:16] */ - __IO uint32_t nptxqtop : 7; /* [30:24] */ - } gnptxsts_bit; - }; - - __IO uint32_t reserved2[2]; - - /** - * @brief otgfs general core configuration register, offset:0x38 - */ - union - { - __IO uint32_t gccfg; - struct - { - __IO uint32_t reserved1 : 16; /* [15:0] */ - __IO uint32_t pwrdown : 1; /* [16] */ - __IO uint32_t lp_mode : 1; /* [17] */ - __IO uint32_t reserved2 : 2; /* [19:18] */ - __IO uint32_t sofouten : 1; /* [20] */ - __IO uint32_t vbusig : 1; /* [21] */ - __IO uint32_t reserved3 : 10; /* [31:22] */ - } gccfg_bit; - }; - - /** - * @brief otgfs core id register, offset:0x3C - */ - union - { - __IO uint32_t guid; - struct - { - __IO uint32_t userid : 32; /* [31:0] */ - } guid_bit; - }; - - __IO uint32_t reserved3[48]; - - /** - * @brief otgfs host periodic tx fifo size register, offset:0x100 - */ - union - { - __IO uint32_t hptxfsiz; - struct - { - __IO uint32_t ptxfstaddr : 16; /* [15:0] */ - __IO uint32_t ptxfsize : 16; /* [31:16] */ - } hptxfsiz_bit; - }; - - /** - * @brief otgfs host periodic tx fifo size register, offset:0x100 - */ - union - { - __IO uint32_t dieptxfn[7]; - struct - { - __IO uint32_t ineptxfstaddr : 16; /* [15:0] */ - __IO uint32_t ineptxfdep : 16; /* [31:16] */ - } dieptxfn_bit[7]; - }; -} otg_global_type; - - -typedef struct -{ - /** - * @brief otgfs host mode configuration register, offset:0x400 - */ - union - { - __IO uint32_t hcfg; - struct - { - __IO uint32_t fslspclksel : 2; /* [1:0] */ - __IO uint32_t fslssupp : 1; /* [2] */ - __IO uint32_t reserved1 : 29; /* [31:3] */ - } hcfg_bit; - }; - - /** - * @brief otgfs host frame interval register, offset:0x404 - */ - union - { - __IO uint32_t hfir; - struct - { - __IO uint32_t frint : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [31:15] */ - } hfir_bit; - }; - - /** - * @brief otgfs host frame number and time remaining register, offset:0x408 - */ - union - { - __IO uint32_t hfnum; - struct - { - __IO uint32_t frnum : 16; /* [15:0] */ - __IO uint32_t ftrem : 16; /* [31:15] */ - } hfnum_bit; - }; - - __IO uint32_t reserved1; - - /** - * @brief otgfs host periodic tx fifo request queue register, offset:0x410 - */ - union - { - __IO uint32_t hptxsts; - struct - { - __IO uint32_t ptxfspcavil : 16; /* [15:0] */ - __IO uint32_t ptxqspcavil : 8; /* [23:16] */ - __IO uint32_t ptxqtop : 8; /* [31:24] */ - } hptxsts_bit; - }; - - /** - * @brief otgfs host all channel interrupt register, offset:0x414 - */ - union - { - __IO uint32_t haint; - struct - { - __IO uint32_t haint : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [32:16] */ - } haint_bit; - }; - - /** - * @brief otgfs host all channel interrupt mask register, offset:0x418 - */ - union - { - __IO uint32_t haintmsk; - struct - { - __IO uint32_t haintmsk : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [32:16] */ - } haintmsk_bit; - }; - - __IO uint32_t reserved2[9]; - - /** - * @brief otgfs host port control and status register, offset:0x440 - */ - union - { - __IO uint32_t hprt; - struct - { - __IO uint32_t prtconsts : 1; /* [0] */ - __IO uint32_t prtcondet : 1; /* [1] */ - __IO uint32_t prtena : 1; /* [2] */ - __IO uint32_t prtenchng : 1; /* [3] */ - __IO uint32_t prtovrcact : 1; /* [4] */ - __IO uint32_t prtovrcchng : 1; /* [5] */ - __IO uint32_t prtres : 1; /* [6] */ - __IO uint32_t prtsusp : 1; /* [7] */ - __IO uint32_t prtrst : 1; /* [8] */ - __IO uint32_t reserved1 : 1; /* [9] */ - __IO uint32_t prtlnsts : 2; /* [11:10] */ - __IO uint32_t prtpwr : 1; /* [12] */ - __IO uint32_t prttsctl : 4; /* [16:13] */ - __IO uint32_t prtspd : 2; /* [18:17] */ - __IO uint32_t reserved2 : 13; /* [31:19] */ - - } hprt_bit; - }; -} otg_host_type; - -typedef struct -{ - /** - * @brief otgfs host channel x characterisic register, offset:0x500 - */ - union - { - __IO uint32_t hcchar; - struct - { - __IO uint32_t mps : 11; /* [10:0] */ - __IO uint32_t eptnum : 4; /* [14:11] */ - __IO uint32_t eptdir : 1; /* [15] */ - __IO uint32_t reserved1 : 1; /* [16] */ - __IO uint32_t lspddev : 1; /* [17] */ - __IO uint32_t eptype : 2; /* [19:18] */ - __IO uint32_t mc : 2; /* [21:20] */ - __IO uint32_t devaddr : 7; /* [28:22] */ - __IO uint32_t oddfrm : 1; /* [29] */ - __IO uint32_t chdis : 1; /* [30] */ - __IO uint32_t chena : 1; /* [31] */ - } hcchar_bit; - }; - - /** - * @brief otgfs host channel split control register, offset:0x504 - */ - union - { - __IO uint32_t hcsplt; - struct - { - __IO uint32_t prtaddr : 7; /* [6:0] */ - __IO uint32_t hubaddr : 7; /* [13:7] */ - __IO uint32_t xactpos : 2; /* [15:14] */ - __IO uint32_t compsplt : 1; /* [16] */ - __IO uint32_t reserved1 : 14; /* [30:17] */ - __IO uint32_t spltena : 1; /* [31] */ - } hcsplt_bit; - }; - - /** - * @brief otgfs host channel interrupt register, offset:0x508 - */ - union - { - __IO uint32_t hcint; - struct - { - __IO uint32_t xferc : 1; /* [0] */ - __IO uint32_t chhltd : 1; /* [1] */ - __IO uint32_t reserved1 : 1; /* [2] */ - __IO uint32_t stall : 1; /* [3] */ - __IO uint32_t nak : 1; /* [4] */ - __IO uint32_t ack : 1; /* [5] */ - __IO uint32_t reserved2 : 1; /* [6] */ - __IO uint32_t xacterr : 1; /* [7] */ - __IO uint32_t bblerr : 1; /* [8] */ - __IO uint32_t frmovrun : 1; /* [9] */ - __IO uint32_t dtglerr : 1; /* [10] */ - __IO uint32_t reserved3 : 21; /* [31:11] */ - } hcint_bit; - }; - - /** - * @brief otgfs host channel interrupt mask register, offset:0x50C - */ - union - { - __IO uint32_t hcintmsk; - struct - { - __IO uint32_t xfercmsk : 1; /* [0] */ - __IO uint32_t chhltdmsk : 1; /* [1] */ - __IO uint32_t reserved1 : 1; /* [2] */ - __IO uint32_t stallmsk : 1; /* [3] */ - __IO uint32_t nakmsk : 1; /* [4] */ - __IO uint32_t ackmsk : 1; /* [5] */ - __IO uint32_t reserved2 : 1; /* [6] */ - __IO uint32_t xacterrmsk : 1; /* [7] */ - __IO uint32_t bblerrmsk : 1; /* [8] */ - __IO uint32_t frmovrunmsk : 1; /* [9] */ - __IO uint32_t dtglerrmsk : 1; /* [10] */ - __IO uint32_t reserved3 : 21; /* [31:11] */ - } hcintmsk_bit; - }; - - /** - * @brief otgfs host channel transfer size register, offset:0x510 - */ - union - { - __IO uint32_t hctsiz; - struct - { - __IO uint32_t xfersize : 19; /* [18:0] */ - __IO uint32_t pktcnt : 10; /* [28:19] */ - __IO uint32_t pid : 2; /* [30:29] */ - __IO uint32_t reserved1 : 1; /* [31] */ - } hctsiz_bit; - }; - __IO uint32_t reserved3[3]; - -}otg_hchannel_type; - - -typedef struct -{ - /** - * @brief otgfs device configuration register, offset:0x800 - */ - union - { - __IO uint32_t dcfg; - struct - { - __IO uint32_t devspd : 2; /* [1:0] */ - __IO uint32_t nzstsouthshk : 1; /* [2] */ - __IO uint32_t reserved1 : 1; /* [3] */ - __IO uint32_t devaddr : 7; /* [10:4] */ - __IO uint32_t perfrint : 2; /* [12:11] */ - __IO uint32_t reserved2 : 19; /* [31:13] */ - } dcfg_bit; - }; - - /** - * @brief otgfs device controls register, offset:0x804 - */ - union - { - __IO uint32_t dctl; - struct - { - __IO uint32_t rwkupsig : 1; /* [0] */ - __IO uint32_t sftdiscon : 1; /* [1] */ - __IO uint32_t gnpinnaksts : 1; /* [2] */ - __IO uint32_t goutnaksts : 1; /* [3] */ - __IO uint32_t tstctl : 3; /* [6:4] */ - __IO uint32_t sgnpinak : 1; /* [7] */ - __IO uint32_t cgnpinak : 1; /* [8] */ - __IO uint32_t sgoutnak : 1; /* [9] */ - __IO uint32_t cgoutnak : 1; /* [10] */ - __IO uint32_t pwroprgdne : 1; /* [11] */ - __IO uint32_t reserved1 : 20; /* [31:12] */ - } dctl_bit; - }; - - /** - * @brief otgfs device status register, offset:0x80C - */ - union - { - __IO uint32_t dsts; - struct - { - __IO uint32_t suspsts : 1; /* [0] */ - __IO uint32_t enumspd : 2; /* [2:1] */ - __IO uint32_t eticerr : 1; /* [3] */ - __IO uint32_t reserved1 : 4; /* [7:4] */ - __IO uint32_t soffn : 14; /* [21:8] */ - __IO uint32_t reserved2 : 10; /* [31:22] */ - } dsts_bit; - }; - - __IO uint32_t reserved1; - /** - * @brief otgfs device in endpoint general interrupt mask register, offset:0x810 - */ - union - { - __IO uint32_t diepmsk; - struct - { - __IO uint32_t xfercmsk : 1; /* [0] */ - __IO uint32_t eptdismsk : 1; /* [1] */ - __IO uint32_t reserved1 : 1; /* [2] */ - __IO uint32_t timeoutmsk : 1; /* [3] */ - __IO uint32_t intkntxfempmsk : 1; /* [4] */ - __IO uint32_t intkneptmismsk : 1; /* [5] */ - __IO uint32_t ineptnakmsk : 1; /* [6] */ - __IO uint32_t reserved2 : 1; /* [7] */ - __IO uint32_t txfifoudrmsk : 1; /* [8] */ - __IO uint32_t bnainmsk : 1; /* [9] */ - __IO uint32_t reserved3 : 22; /* [31:10] */ - } diepmsk_bit; - }; - - /** - * @brief otgfs device out endpoint general interrupt mask register, offset:0x814 - */ - union - { - __IO uint32_t doepmsk; - struct - { - __IO uint32_t xfercmsk : 1; /* [0] */ - __IO uint32_t eptdismsk : 1; /* [1] */ - __IO uint32_t reserved1 : 1; /* [2] */ - __IO uint32_t setupmsk : 1; /* [3] */ - __IO uint32_t outtepdmsk : 1; /* [4] */ - __IO uint32_t reserved2 : 1; /* [5] */ - __IO uint32_t b2bsetupmsk : 1; /* [6] */ - __IO uint32_t reserved3 : 1; /* [7] */ - __IO uint32_t outperrmsk : 1; /* [8] */ - __IO uint32_t bnaoutmsk : 1; /* [9] */ - __IO uint32_t reserved4 : 22; /* [31:10] */ - } doepmsk_bit; - }; - - /** - * @brief otgfs device all endpoint interrupt register, offset:0x818 - */ - union - { - __IO uint32_t daint; - struct - { - __IO uint32_t ineptint : 16; /* [15:0] */ - __IO uint32_t outeptint : 16; /* [31:16] */ - } daint_bit; - }; - - /** - * @brief otgfs device all endpoint interrupt mask register, offset:0x81C - */ - union - { - __IO uint32_t daintmsk; - struct - { - __IO uint32_t ineptmsk : 16; /* [15:0] */ - __IO uint32_t outeptmsk : 16; /* [31:16] */ - } daintmsk_bit; - }; - - __IO uint32_t reserved2[5]; - - /** - * @brief otgfs device in endpoint fifo empty interrupt mask register, offset:0x834 - */ - union - { - __IO uint32_t diepempmsk; - struct - { - __IO uint32_t ineptxfemsk : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [31:16] */ - } diepempmsk_bit; - }; - -} otg_device_type; - -typedef struct -{ - /** - * @brief otgfs device out endpoint control register, offset:0x900 - */ - union - { - __IO uint32_t diepctl; - struct - { - __IO uint32_t mps : 11; /* [10:0] */ - __IO uint32_t reserved1 : 4; /* [14:11] */ - __IO uint32_t usbacept : 1; /* [15] */ - __IO uint32_t dpid : 1; /* [16] */ - __IO uint32_t naksts : 1; /* [17] */ - __IO uint32_t eptype : 2; /* [19:18] */ - __IO uint32_t reserved2 : 1; /* [20] */ - __IO uint32_t stall : 1; /* [21] */ - __IO uint32_t txfnum : 4; /* [25:22] */ - __IO uint32_t cnak : 1; /* [26] */ - __IO uint32_t snak : 1; /* [27] */ - __IO uint32_t setd0pid : 1; /* [28] */ - __IO uint32_t setd1pid : 1; /* [29] */ - __IO uint32_t eptdis : 1; /* [30] */ - __IO uint32_t eptena : 1; /* [31] */ - } diepctl_bit; - }; - __IO uint32_t reserved1; - - /** - * @brief otgfs device in endpoint interrupt register, offset:0x908 - */ - union - { - __IO uint32_t diepint; - struct - { - __IO uint32_t xferc : 1; /* [0] */ - __IO uint32_t epdisd : 1; /* [1] */ - __IO uint32_t reserved1 : 1; /* [2] */ - __IO uint32_t timeout : 1; /* [3] */ - __IO uint32_t intkntxfemp : 1; /* [4] */ - __IO uint32_t reserved2 : 1; /* [5] */ - __IO uint32_t ineptnak : 1; /* [6] */ - __IO uint32_t txfemp : 1; /* [7] */ - __IO uint32_t reserved3 : 24; /* [31:8] */ - } diepint_bit; - }; - __IO uint32_t reserved2; - - /** - * @brief otgfs device in endpoint transfer size register, offset:0x910 + endpoint number * 0x20 - */ - union - { - __IO uint32_t dieptsiz; - struct - { - __IO uint32_t xfersize : 19; /* [18:0] */ - __IO uint32_t pktcnt : 10; /* [28:19] */ - __IO uint32_t mc : 2; /* [30:29] */ - __IO uint32_t reserved1 : 1; /* [31] */ - } dieptsiz_bit; - }; - - __IO uint32_t reserved3; - - /** - * @brief otgfs device in endpoint tx fifo status register, offset:0x918 + endpoint number * 0x20 - */ - union - { - __IO uint32_t dtxfsts; - struct - { - __IO uint32_t ineptxfsav : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [31:16] */ - } dtxfsts_bit; - }; - -} otg_eptin_type; - -typedef struct -{ - /** - * @brief otgfs device out endpoint control register, offset:0xb00 + endpoint number * 0x20 - */ - union - { - __IO uint32_t doepctl; - struct - { - __IO uint32_t mps : 11; /* [10:0] */ - __IO uint32_t reserved1 : 4; /* [14:11] */ - __IO uint32_t usbacept : 1; /* [15] */ - __IO uint32_t dpid : 1; /* [16] */ - __IO uint32_t naksts : 1; /* [17] */ - __IO uint32_t eptype : 2; /* [19:18] */ - __IO uint32_t snpm : 1; /* [20] */ - __IO uint32_t stall : 1; /* [21] */ - __IO uint32_t reserved2 : 4; /* [25:22] */ - __IO uint32_t cnak : 1; /* [26] */ - __IO uint32_t snak : 1; /* [27] */ - __IO uint32_t setd0pid : 1; /* [28] */ - __IO uint32_t setd1pid : 1; /* [29] */ - __IO uint32_t eptdis : 1; /* [30] */ - __IO uint32_t eptena : 1; /* [31] */ - } doepctl_bit; - }; - __IO uint32_t reserved1; - - /** - * @brief otgfs device out endpoint interrupt register, offset:0xb08 + endpoint number * 0x20 - */ - union - { - __IO uint32_t doepint; - struct - { - __IO uint32_t xferc : 1; /* [0] */ - __IO uint32_t epdisd : 1; /* [1] */ - __IO uint32_t reserved1 : 1; /* [2] */ - __IO uint32_t setup : 1; /* [3] */ - __IO uint32_t outtepd : 1; /* [4] */ - __IO uint32_t reserved2 : 1; /* [5] */ - __IO uint32_t b2pstup : 1; /* [6] */ - __IO uint32_t reserved3 : 25; /* [31:7] */ - } doepint_bit; - }; - __IO uint32_t reserved2; - - /** - * @brief otgfs device out endpoint transfer size register, offset:0xb10 + endpoint number * 0x20 - */ - union - { - __IO uint32_t doeptsiz; - struct - { - __IO uint32_t xfersize : 19; /* [18:0] */ - __IO uint32_t pktcnt : 10; /* [28:19] */ - __IO uint32_t rxdpid_setupcnt : 2; /* [30:29] */ - __IO uint32_t reserved1 : 1; /* [31] */ - } doeptsiz_bit; - }; -} otg_eptout_type; - -typedef struct -{ - /** - * @brief otgfs power and clock gating control registers, offset:0xe00 - */ - union - { - __IO uint32_t pcgcctl; - struct - { - __IO uint32_t stoppclk : 1; /* [0] */ - __IO uint32_t reserved1 : 3; /* [3:1] */ - __IO uint32_t suspendm : 1; /* [4] */ - __IO uint32_t reserved2 : 27; /* [31:5] */ - } pcgcctl_bit; - }; -} otg_pcgcctl_type; - -/** - * @} - */ - -/** @defgroup USB_exported_functions - * @{ - */ - -/** - * @brief usb host and device offset address - */ -#define OTG_HOST_ADDR_OFFSET 0x400 /*!< usb host register offset address */ -#define OTG_HOST_CHANNEL_ADDR_OFFSET 0x500 /*!< usb host channel register offset address */ -#define OTG_DEVICE_ADDR_OFFSET 0x800 /*!< usb device register offset address */ -#define OTG_DEVICE_EPTIN_ADDR_OFFSET 0x900 /*!< usb device endpoint in register offset address */ -#define OTG_DEVICE_EPTOUT_ADDR_OFFSET 0xB00 /*!< usb device endpoint out register offset address */ -#define OTG_PCGCCTL_ADDR_OFFSET 0xE00 /*!< usb power and clock control register offset address */ -#define OTG_FIFO_ADDR_OFFSET 0x1000 /*!< usb fifo offset address */ - -/** - * @brief usb host and device register define - */ -#define OTG1_GLOBAL ((otg_global_type *)(OTGFS1_BASE)) /*!< usb otg1 global register */ -#define OTG2_GLOBAL ((otg_global_type *)(OTGFS2_BASE)) /*!< usb otg2 global register */ -#define OTG_PCGCCTL(usbx) ((otg_pcgcctl_type *)((uint32_t)usbx + OTG_PCGCCTL_ADDR_OFFSET)) /*!< usb power and clock control register */ -#define OTG_DEVICE(usbx) ((otg_device_type *)((uint32_t)usbx + OTG_DEVICE_ADDR_OFFSET)) /*!< usb device register */ -#define OTG_HOST(usbx) ((otg_host_type *)((uint32_t)usbx + OTG_HOST_ADDR_OFFSET)) /*!< usb host register */ -#define USB_CHL(usbx, n) ((otg_hchannel_type *)((uint32_t)usbx + OTG_HOST_CHANNEL_ADDR_OFFSET + n * 0x20)) /*!< usb channel n register */ -#define USB_INEPT(usbx, eptn) ((otg_eptin_type *)((uint32_t)usbx + OTG_DEVICE_EPTIN_ADDR_OFFSET + eptn * 0x20)) /*!< usb device endpoint in register */ -#define USB_OUTEPT(usbx, eptn) ((otg_eptout_type *)((uint32_t)usbx + OTG_DEVICE_EPTOUT_ADDR_OFFSET + eptn * 0x20)) /*!< usb device endpoint out register */ -#define USB_FIFO(usbx, eptn) *(__IO uint32_t *)((uint32_t)usbx + OTG_FIFO_ADDR_OFFSET + eptn * 0x1000) /*!< usb fifo address */ - - - -typedef otg_global_type usb_reg_type; - -/** @defgroup USB_exported_functions - * @{ - */ - -#ifdef OTGFS_USB_GLOBAL -error_status usb_global_reset(otg_global_type *usbx); -void usb_global_init(otg_global_type *usbx); -otg_global_type *usb_global_select_core(uint8_t usb_id); -void usb_flush_tx_fifo(otg_global_type *usbx, uint32_t fifo_num); -void usb_flush_rx_fifo(otg_global_type *usbx); -void usb_global_interrupt_enable(otg_global_type *usbx, uint16_t interrupt, confirm_state new_state); -uint32_t usb_global_get_all_interrupt(otg_global_type *usbx); -void usb_global_clear_interrupt(otg_global_type *usbx, uint32_t flag); -void usb_interrupt_enable(otg_global_type *usbx); -void usb_interrupt_disable(otg_global_type *usbx); -void usb_set_rx_fifo(otg_global_type *usbx, uint16_t size); -void usb_set_tx_fifo(otg_global_type *usbx, uint8_t txfifo, uint16_t size); -void usb_global_set_mode(otg_global_type *usbx, uint32_t mode); -void usb_global_power_on(otg_global_type *usbx); -void usb_write_packet(otg_global_type *usbx, uint8_t *pusr_buf, uint16_t num, uint16_t nbytes); -void usb_read_packet(otg_global_type *usbx, uint8_t *pusr_buf, uint16_t num, uint16_t nbytes); -void usb_stop_phy_clk(otg_global_type *usbx); -void usb_open_phy_clk(otg_global_type *usbx); -#endif - -#ifdef OTGFS_USB_DEVICE -void usb_ept_open(otg_global_type *usbx, usb_ept_info *ept_info); -void usb_ept_close(otg_global_type *usbx, usb_ept_info *ept_info); -void usb_ept_stall(otg_global_type *usbx, usb_ept_info *ept_info); -void usb_ept_clear_stall(otg_global_type *usbx, usb_ept_info *ept_info); -uint32_t usb_get_all_out_interrupt(otg_global_type *usbx); -uint32_t usb_get_all_in_interrupt(otg_global_type *usbx); -uint32_t usb_ept_out_interrupt(otg_global_type *usbx, uint32_t eptn); -uint32_t usb_ept_in_interrupt(otg_global_type *usbx, uint32_t eptn); -void usb_ept_out_clear(otg_global_type *usbx, uint32_t eptn, uint32_t flag); -void usb_ept_in_clear(otg_global_type *usbx, uint32_t eptn, uint32_t flag); -void usb_set_address(otg_global_type *usbx, uint8_t address); -void usb_ept0_start(otg_global_type *usbx); -void usb_ept0_setup(otg_global_type *usbx); -void usb_connect(otg_global_type *usbx); -void usb_disconnect(otg_global_type *usbx); -void usb_remote_wkup_set(otg_global_type *usbx); -void usb_remote_wkup_clear(otg_global_type *usbx); -uint8_t usb_suspend_status_get(otg_global_type *usbx); -#endif - -#ifdef OTGFS_USB_HOST -void usb_port_power_on(otg_global_type *usbx, confirm_state state); -uint32_t usbh_get_frame(otg_global_type *usbx); -void usb_hc_enable(otg_global_type *usbx, - uint8_t chn, - uint8_t ept_num, - uint8_t dev_address, - uint8_t type, - uint8_t maxpacket, - uint8_t speed); -uint32_t usb_hch_read_interrupt(otg_global_type *usbx); -void usb_host_disable(otg_global_type *usbx); -void usb_hch_halt(otg_global_type *usbx, uint8_t chn); -void usbh_fsls_clksel(otg_global_type *usbx, uint8_t clk); -#endif -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_wdt.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_wdt.h deleted file mode 100644 index e217c84..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_wdt.h +++ /dev/null @@ -1,197 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_wdt.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 wdt header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_WDT_H -#define __AT32F435_437_WDT_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup WDT - * @{ - */ - - -/** @defgroup WDT_flags_definition - * @brief wdt flag - * @{ - */ - -#define WDT_DIVF_UPDATE_FLAG ((uint16_t)0x0001) /*!< wdt division value update complete flag */ -#define WDT_RLDF_UPDATE_FLAG ((uint16_t)0x0002) /*!< wdt reload value update complete flag */ -#define WDT_WINF_UPDATE_FLAG ((uint16_t)0x0004) /*!< wdt window value update complete flag */ - -/** - * @} - */ - -/** @defgroup WDT_exported_types - * @{ - */ - -/** - * @brief wdt division value type - */ -typedef enum -{ - WDT_CLK_DIV_4 = 0x00, /*!< wdt clock divider value is 4 */ - WDT_CLK_DIV_8 = 0x01, /*!< wdt clock divider value is 8 */ - WDT_CLK_DIV_16 = 0x02, /*!< wdt clock divider value is 16 */ - WDT_CLK_DIV_32 = 0x03, /*!< wdt clock divider value is 32 */ - WDT_CLK_DIV_64 = 0x04, /*!< wdt clock divider value is 64 */ - WDT_CLK_DIV_128 = 0x05, /*!< wdt clock divider value is 128 */ - WDT_CLK_DIV_256 = 0x06 /*!< wdt clock divider value is 256 */ -} wdt_division_type; - -/** - * @brief wdt cmd value type - */ -typedef enum -{ - WDT_CMD_LOCK = 0x0000, /*!< disable write protection command */ - WDT_CMD_UNLOCK = 0x5555, /*!< enable write protection command */ - WDT_CMD_ENABLE = 0xCCCC, /*!< enable wdt command */ - WDT_CMD_RELOAD = 0xAAAA /*!< reload command */ -} wdt_cmd_value_type; - -/** - * @brief type define wdt register all - */ -typedef struct -{ - - /** - * @brief wdt cmd register, offset:0x00 - */ - union - { - __IO uint32_t cmd; - struct - { - __IO uint32_t cmd : 16;/* [15:0] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } cmd_bit; - }; - - /** - * @brief wdt div register, offset:0x04 - */ - union - { - __IO uint32_t div; - struct - { - __IO uint32_t div : 3; /* [2:0] */ - __IO uint32_t reserved1 : 29;/* [31:3] */ - } div_bit; - }; - - /** - * @brief wdt rld register, offset:0x08 - */ - union - { - __IO uint32_t rld; - struct - { - __IO uint32_t rld : 12;/* [11:0] */ - __IO uint32_t reserved1 : 20;/* [31:12] */ - } rld_bit; - }; - - /** - * @brief wdt sts register, offset:0x0C - */ - union - { - __IO uint32_t sts; - struct - { - __IO uint32_t divf : 1; /* [0] */ - __IO uint32_t rldf : 1; /* [1] */ - __IO uint32_t reserved1 : 30;/* [31:2] */ - } sts_bit; - }; - - /** - * @brief wdt win register, offset:0x10 - */ - union - { - __IO uint32_t win; - struct - { - __IO uint32_t win : 12;/* [11:0] */ - __IO uint32_t reserved1 : 20;/* [31:12] */ - } win_bit; - }; -} wdt_type; - -/** - * @} - */ - -#define WDT ((wdt_type *) WDT_BASE) - -/** @defgroup WDT_exported_functions - * @{ - */ - -void wdt_enable(void); -void wdt_counter_reload(void); -void wdt_reload_value_set(uint16_t reload_value); -void wdt_divider_set(wdt_division_type division); -void wdt_register_write_enable( confirm_state new_state); -flag_status wdt_flag_get(uint16_t wdt_flag); -void wdt_window_counter_set(uint16_t window_cnt); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_wwdt.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_wwdt.h deleted file mode 100644 index 01ab449..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_wwdt.h +++ /dev/null @@ -1,158 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_wwdt.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 wwdt header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_WWDT_H -#define __AT32F435_437_WWDT_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup WWDT - * @{ - */ - -/** @defgroup WWDT_enable_bit_definition - * @brief wwdt enable bit - * @{ - */ - -#define WWDT_EN_BIT ((uint32_t)0x00000080) /*!< wwdt enable bit */ - -/** - * @} - */ - -/** @defgroup WWDT_exported_types - * @{ - */ - -/** - * @brief wwdt division type - */ -typedef enum -{ - WWDT_PCLK1_DIV_4096 = 0x00, /*!< wwdt counter clock = (pclk1/4096)/1) */ - WWDT_PCLK1_DIV_8192 = 0x01, /*!< wwdt counter clock = (pclk1/4096)/2) */ - WWDT_PCLK1_DIV_16384 = 0x02, /*!< wwdt counter clock = (pclk1/4096)/4) */ - WWDT_PCLK1_DIV_32768 = 0x03 /*!< wwdt counter clock = (pclk1/4096)/8) */ -} wwdt_division_type; - -/** - * @brief type define wwdt register all - */ -typedef struct -{ - - /** - * @brief wwdt ctrl register, offset:0x00 - */ - union - { - __IO uint32_t ctrl; - struct - { - __IO uint32_t cnt : 7; /* [6:0] */ - __IO uint32_t wwdten : 1; /* [7] */ - __IO uint32_t reserved1 : 24;/* [31:8] */ - } ctrl_bit; - }; - - /** - * @brief wwdt cfg register, offset:0x04 - */ - union - { - __IO uint32_t cfg; - struct - { - __IO uint32_t win : 7; /* [6:0] */ - __IO uint32_t div : 2; /* [8:7] */ - __IO uint32_t rldien : 1; /* [9] */ - __IO uint32_t reserved1 : 22;/* [31:10] */ - } cfg_bit; - }; - - /** - * @brief wwdt cfg register, offset:0x08 - */ - union - { - __IO uint32_t sts; - struct - { - __IO uint32_t rldf : 1; /* [0] */ - __IO uint32_t reserved1 : 31;/* [31:1] */ - } sts_bit; - }; - -} wwdt_type; - -/** - * @} - */ - -#define WWDT ((wwdt_type *) WWDT_BASE) - -/** @defgroup WWDT_exported_functions - * @{ - */ - -void wwdt_reset(void); -void wwdt_divider_set(wwdt_division_type division); -void wwdt_flag_clear(void); -void wwdt_enable(uint8_t wwdt_cnt); -void wwdt_interrupt_enable(void); -flag_status wwdt_flag_get(void); -void wwdt_counter_set(uint8_t wwdt_cnt); -void wwdt_window_counter_set(uint8_t window_cnt); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_xmc.h b/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_xmc.h deleted file mode 100644 index 1c9bbca..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_xmc.h +++ /dev/null @@ -1,1075 +0,0 @@ -/** - ************************************************************************** - * @file at32f435_437_xmc.h - * @version v2.0.4 - * @date 2021-12-31 - * @brief at32f435_437 xmc header file - ************************************************************************** - * Copyright notice & Disclaimer - * - * The software Board Support Package (BSP) that is made available to - * download from Artery official website is the copyrighted work of Artery. - * Artery authorizes customers to use, copy, and distribute the BSP - * software and its related documentation for the purpose of design and - * development in conjunction with Artery microcontrollers. Use of the - * software is governed by this copyright notice and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, - * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, - * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR - * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, - * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. - * - ************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_XMC_H -#define __AT32F435_437_XMC_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Includes ------------------------------------------------------------------*/ -#include "at32f435_437.h" - -/** @addtogroup AT32F435_437_periph_driver - * @{ - */ - -/** @addtogroup XMC - * @{ - */ - -/** @defgroup XMC_exported_types - * @{ - */ - -/** - * @brief xmc data address bus multiplexing type - */ -typedef enum -{ - XMC_DATA_ADDR_MUX_DISABLE = 0x00000000, /*!< xmc address/data multiplexing disable */ - XMC_DATA_ADDR_MUX_ENABLE = 0x00000002 /*!< xmc address/data multiplexing enable */ -} xmc_data_addr_mux_type; - -/** - * @brief xmc burst access mode type - */ -typedef enum -{ - XMC_BURST_MODE_DISABLE = 0x00000000, /*!< xmc burst mode disable */ - XMC_BURST_MODE_ENABLE = 0x00000100 /*!< xmc burst mode enable */ -} xmc_burst_access_mode_type; - -/** - * @brief xmc asynchronous wait type - */ -typedef enum -{ - XMC_ASYN_WAIT_DISABLE = 0x00000000, /*!< xmc wait signal during asynchronous transfers disbale */ - XMC_ASYN_WAIT_ENABLE = 0x00008000 /*!< xmc wait signal during asynchronous transfers enable */ -} xmc_asyn_wait_type; - -/** - * @brief xmc wrapped mode type - */ -typedef enum -{ - XMC_WRAPPED_MODE_DISABLE = 0x00000000, /*!< xmc direct wrapped burst is disbale */ - XMC_WRAPPED_MODE_ENABLE = 0x00000400 /*!< xmc direct wrapped burst is enable */ -} xmc_wrap_mode_type; - -/** - * @brief xmc write operation type - */ -typedef enum -{ - XMC_WRITE_OPERATION_DISABLE = 0x00000000, /*!< xmc write operations is disable */ - XMC_WRITE_OPERATION_ENABLE = 0x00001000 /*!< xmc write operations is enable */ -} xmc_write_operation_type; - -/** - * @brief xmc wait signal type - */ -typedef enum -{ - XMC_WAIT_SIGNAL_DISABLE = 0x00000000, /*!< xmc nwait signal is disable */ - XMC_WAIT_SIGNAL_ENABLE = 0x00002000 /*!< xmc nwait signal is enable */ -} xmc_wait_signal_type; - -/** - * @brief xmc write burst type - */ -typedef enum -{ - XMC_WRITE_BURST_SYN_DISABLE = 0x00000000, /*!< xmc write operations are always performed in asynchronous mode */ - XMC_WRITE_BURST_SYN_ENABLE = 0x00080000 /*!< xmc write operations are performed in synchronous mode */ -} xmc_write_burst_type; - -/** - * @brief xmc extended mode type - */ -typedef enum -{ - XMC_WRITE_TIMING_DISABLE = 0x00000000, /*!< xmc write timing disable */ - XMC_WRITE_TIMING_ENABLE = 0x00004000 /*!< xmc write timing enable */ -} xmc_extended_mode_type; - -/** - * @brief xmc pccard wait type - */ -typedef enum -{ - XMC_WAIT_OPERATION_DISABLE = 0x00000000, /*!< xmc wait operation for the pc card/nand flash memory bank disable */ - XMC_WAIT_OPERATION_ENABLE = 0x00000002 /*!< xmc wait operation for the pc card/nand flash memory bank enable */ -} xmc_nand_pccard_wait_type; - -/** - * @brief xmc ecc enable type - */ -typedef enum -{ - XMC_ECC_OPERATION_DISABLE = 0x00000000, /*!< xmc ecc module disable */ - XMC_ECC_OPERATION_ENABLE = 0x00000040 /*!< xmc ecc module enable */ -} xmc_ecc_enable_type; - -/** - * @brief xmc nor/sram subbank type - */ -typedef enum -{ - XMC_BANK1_NOR_SRAM1 = 0x00000000, /*!< xmc nor/sram subbank1 */ - XMC_BANK1_NOR_SRAM2 = 0x00000001, /*!< xmc nor/sram subbank2 */ - XMC_BANK1_NOR_SRAM3 = 0x00000002, /*!< xmc nor/sram subbank3 */ - XMC_BANK1_NOR_SRAM4 = 0x00000003 /*!< xmc nor/sram subbank4 */ -} xmc_nor_sram_subbank_type; - -/** - * @brief xmc class bank type - */ -typedef enum -{ - XMC_BANK2_NAND = 0x00000000, /*!< xmc nand flash bank2 */ - XMC_BANK3_NAND = 0x00000001, /*!< xmc nand flash bank3 */ - XMC_BANK4_PCCARD = 0x00000002, /*!< xmc pc card bank4 */ - XMC_BANK5_6_SDRAM = 0x00000003 /*!< xmc sdram bank5/6 */ -} xmc_class_bank_type; - -/** - * @brief xmc memory type - */ -typedef enum -{ - XMC_DEVICE_SRAM = 0x00000000, /*!< xmc device choice sram */ - XMC_DEVICE_PSRAM = 0x00000004, /*!< xmc device choice psram */ - XMC_DEVICE_NOR = 0x00000008 /*!< xmc device choice nor flash */ -} xmc_memory_type; - -/** - * @brief xmc data width type - */ -typedef enum -{ - XMC_BUSTYPE_8_BITS = 0x00000000, /*!< xmc databuss width 8bits */ - XMC_BUSTYPE_16_BITS = 0x00000010 /*!< xmc databuss width 16bits */ -} xmc_data_width_type; - -/** - * @brief xmc wait signal polarity type - */ -typedef enum -{ - XMC_WAIT_SIGNAL_LEVEL_LOW = 0x00000000, /*!< xmc nwait active low */ - XMC_WAIT_SIGNAL_LEVEL_HIGH = 0x00000200 /*!< xmc nwait active high */ -} xmc_wait_signal_polarity_type; - -/** - * @brief xmc wait timing type - */ -typedef enum -{ - XMC_WAIT_SIGNAL_SYN_BEFORE = 0x00000000, /*!< xmc nwait signal is active one data cycle before wait state */ - XMC_WAIT_SIGNAL_SYN_DURING = 0x00000800 /*!< xmc nwait signal is active during wait state */ -} xmc_wait_timing_type; - -/** - * @brief xmc access mode type - */ -typedef enum -{ - XMC_ACCESS_MODE_A = 0x00000000, /*!< xmc access mode A */ - XMC_ACCESS_MODE_B = 0x10000000, /*!< xmc access mode B */ - XMC_ACCESS_MODE_C = 0x20000000, /*!< xmc access mode C */ - XMC_ACCESS_MODE_D = 0x30000000 /*!< xmc access mode D */ -} xmc_access_mode_type; - -/** - * @brief xmc ecc page size type - */ -typedef enum -{ - XMC_ECC_PAGESIZE_256_BYTES = 0x00000000, /*!< xmc ecc page size 256 bytes */ - XMC_ECC_PAGESIZE_512_BYTES = 0x00020000, /*!< xmc ecc page size 512 bytes */ - XMC_ECC_PAGESIZE_1024_BYTES = 0x00040000, /*!< xmc ecc page size 1024 bytes */ - XMC_ECC_PAGESIZE_2048_BYTES = 0x00060000, /*!< xmc ecc page size 2048 bytes */ - XMC_ECC_PAGESIZE_4096_BYTES = 0x00080000, /*!< xmc ecc page size 4096 bytes */ - XMC_ECC_PAGESIZE_8192_BYTES = 0x000A0000 /*!< xmc ecc page size 8192 bytes */ -} xmc_ecc_pagesize_type; - -/** - * @brief xmc interrupt sources type - */ -typedef enum -{ - XMC_INT_RISING_EDGE = 0x00000008, /*!< xmc rising edge detection interrupt enable */ - XMC_INT_LEVEL = 0x00000010, /*!< xmc high-level edge detection interrupt enable */ - XMC_INT_FALLING_EDGE = 0x00000020, /*!< xmc falling edge detection interrupt enable */ - XMC_INT_ERR = 0x00004000 /*!< xmc sdram error interrupt enable */ -} xmc_interrupt_sources_type; - -/** - * @brief xmc interrupt flag type - */ -typedef enum -{ - XMC_RISINGEDGE_FLAG = 0x00000001, /*!< xmc interrupt rising edge detection flag */ - XMC_LEVEL_FLAG = 0x00000002, /*!< xmc interrupt high-level edge detection flag */ - XMC_FALLINGEDGE_FLAG = 0x00000004, /*!< xmc interrupt falling edge detection flag */ - XMC_FEMPT_FLAG = 0x00000040, /*!< xmc fifo empty flag */ - XMC_ERR_FLAG = 0x00000001, /*!< xmc sdram error flag */ - XMC_BUSY_FLAG = 0x00000020 /*!< xmc sdram busy flag */ -} xmc_interrupt_flag_type; - -/** - * @brief xmc sdram number of column address type - */ -typedef enum -{ - XMC_COLUMN_8 = 0x00000000, /*!< xmc sdram column address 8bit */ - XMC_COLUMN_9 = 0x00000001, /*!< xmc sdram column address 9bit */ - XMC_COLUMN_10 = 0x00000002, /*!< xmc sdram column address 10bit */ - XMC_COLUMN_11 = 0x00000003 /*!< xmc sdram column address 11bit */ -}xmc_sdram_column_type; - -/** - * @brief xmc sdram number of row address type - */ -typedef enum -{ - XMC_ROW_11 = 0x00000000, /*!< xmc sdram row address 11bit */ - XMC_ROW_12 = 0x00000001, /*!< xmc sdram row address 12bit */ - XMC_ROW_13 = 0x00000002 /*!< xmc sdram row address 13bit */ -}xmc_sdram_row_type; - -/** - * @brief xmc sdram memory data bus width type - */ -typedef enum -{ - XMC_MEM_WIDTH_8 = 0x00000000, /*!< xmc sdram data bus width 8 */ - XMC_MEM_WIDTH_16 = 0x00000001 /*!< xmc sdram data bus width 16 */ -}xmc_sdram_width_type; - -/** - * @brief xmc sdram number of internal banks type - */ -typedef enum -{ - XMC_INBK_2 = 0x00000000, /*!< xmc sdram 2 internal banks */ - XMC_INBK_4 = 0x00000001 /*!< xmc sdram 4 internal banks */ -}xmc_sdram_inbk_type; - -/** - * @brief xmc sdram cas latency type - */ -typedef enum -{ - XMC_CAS_1 = 0x00000001, /*!< xmc sdram cas 1 */ - XMC_CAS_2 = 0x00000002, /*!< xmc sdram cas 2 */ - XMC_CAS_3 = 0x00000003 /*!< xmc sdram cas 3 */ -}xmc_sdram_cas_type; - -/** - * @brief xmc sdram clock div type - */ -typedef enum -{ - XMC_NO_CLK = 0x00000000, /*!< xmc sdram disable clock */ - XMC_CLKDIV_2 = 0x00000002, /*!< xmc sdram clock div 2 */ - XMC_CLKDIV_3 = 0x00000003, /*!< xmc sdram clock div 3 */ - XMC_CLKDIV_4 = 0x00000001 /*!< xmc sdram clock div 4 */ -}xmc_sdram_clkdiv_type; - -/** - * @brief xmc sdram read delay - */ -typedef enum -{ - XMC_READ_DELAY_0 = 0x00000000, /*!< xmc sdram no delay */ - XMC_READ_DELAY_1 = 0x00000001, /*!< xmc sdram delay 1 clock*/ - XMC_READ_DELAY_2 = 0x00000002, /*!< xmc sdram delay 2 clock */ -}xmc_sdram_rd_delay_type; - -/** - * @brief xmc sdram bank type - */ -typedef enum -{ - XMC_SDRAM_BANK1 = 0x00000000, /*!< xmc sdram bank 1 */ - XMC_SDRAM_BANK2 = 0x00000001 /*!< xmc sdram bank 2 */ -}xmc_sdram_bank_type; - - -/** - * @brief xmc sdram timing delay cycle type - */ -typedef enum -{ - XMC_DELAY_CYCLE_1 = 0x00000000, /*!< xmc sdram timming delay 1 cycle */ - XMC_DELAY_CYCLE_2 = 0x00000001, /*!< xmc sdram timming delay 2 cycle */ - XMC_DELAY_CYCLE_3 = 0x00000002, /*!< xmc sdram timming delay 3 cycle */ - XMC_DELAY_CYCLE_4 = 0x00000003, /*!< xmc sdram timming delay 4 cycle */ - XMC_DELAY_CYCLE_5 = 0x00000004, /*!< xmc sdram timming delay 5 cycle */ - XMC_DELAY_CYCLE_6 = 0x00000005, /*!< xmc sdram timming delay 6 cycle */ - XMC_DELAY_CYCLE_7 = 0x00000006, /*!< xmc sdram timming delay 7 cycle */ - XMC_DELAY_CYCLE_8 = 0x00000007, /*!< xmc sdram timming delay 8 cycle */ - XMC_DELAY_CYCLE_9 = 0x00000008, /*!< xmc sdram timming delay 9 cycle */ - XMC_DELAY_CYCLE_10 = 0x00000009, /*!< xmc sdram timming delay 10 cycle */ - XMC_DELAY_CYCLE_11 = 0x0000000A, /*!< xmc sdram timming delay 11 cycle */ - XMC_DELAY_CYCLE_12 = 0x0000000B, /*!< xmc sdram timming delay 12 cycle */ - XMC_DELAY_CYCLE_13 = 0x0000000C, /*!< xmc sdram timming delay 13 cycle */ - XMC_DELAY_CYCLE_14 = 0x0000000D, /*!< xmc sdram timming delay 14 cycle */ - XMC_DELAY_CYCLE_15 = 0x0000000E, /*!< xmc sdram timming delay 15 cycle */ - XMC_DELAY_CYCLE_16 = 0x0000000F /*!< xmc sdram timming delay 16 cycle */ -}xmc_sdram_delay_type; - - -/** - * @brief xmc sdram command type - */ -typedef enum -{ - XMC_CMD_NORMAL = 0x00000000, /*!< xmc sdram command normal */ - XMC_CMD_CLK = 0x00000001, /*!< xmc sdram command clock enable */ - XMC_CMD_PRECHARG_ALL = 0x00000002, /*!< xmc sdram command precharg all bank */ - XMC_CMD_AUTO_REFRESH = 0x00000003, /*!< xmc sdram command auto refresh */ - XMC_CMD_LOAD_MODE = 0x00000004, /*!< xmc sdram command load mode register */ - XMC_CMD_SELF_REFRESH = 0x00000005, /*!< xmc sdram command self refresh */ - XMC_CMD_POWER_DOWN = 0x00000006 /*!< xmc sdram command power down */ -}xmc_command_type; - -/** - * @brief xmc sdram command bank select type - */ -typedef enum -{ - XMC_CMD_BANK1 = 0x00000010, /*!< send xmc sdram command to bank1 */ - XMC_CMD_BANK2 = 0x00000008, /*!< send xmc sdram command to bank2 */ - XMC_CMD_BANK1_2 = 0x00000018 /*!< send xmc sdram command to bank1 and bank2 */ -}xmc_cmd_bank1_2_type; - - -/** - * @brief xmc sdram bank status type - */ -typedef enum -{ - XMC_STATUS_NORMAL = 0x00000000, /*!< xmc sdram status normal */ - XMC_STATUS_SELF_REFRESH = 0x00000001, /*!< xmc sdram status self refresh */ - XMC_STATUS_POWER_DOWN = 0x00000002, /*!< xmc sdram power down */ - XMC_STATUS_MASK = 0x00000003 /*!< xmc sdram mask */ -}xmc_bank_status_type; - - -/** - * @brief nor/sram banks timing parameters - */ -typedef struct -{ - xmc_nor_sram_subbank_type subbank; /*!< xmc nor/sram subbank */ - xmc_extended_mode_type write_timing_enable; /*!< xmc nor/sram write timing enable */ - uint32_t addr_setup_time; /*!< xmc nor/sram address setup time */ - uint32_t addr_hold_time; /*!< xmc nor/sram address hold time */ - uint32_t data_setup_time; /*!< xmc nor/sram data setup time */ - uint32_t bus_latency_time; /*!< xmc nor/sram bus latency time */ - uint32_t clk_psc; /*!< xmc nor/sram clock prescale */ - uint32_t data_latency_time; /*!< xmc nor/sram data latency time */ - xmc_access_mode_type mode; /*!< xmc nor/sram access mode */ -} xmc_norsram_timing_init_type; - -/** - * @brief xmc nor/sram init structure definition - */ -typedef struct -{ - xmc_nor_sram_subbank_type subbank; /*!< xmc nor/sram subbank */ - xmc_data_addr_mux_type data_addr_multiplex; /*!< xmc nor/sram address/data multiplexing enable */ - xmc_memory_type device; /*!< xmc nor/sram memory device */ - xmc_data_width_type bus_type; /*!< xmc nor/sram data bus width */ - xmc_burst_access_mode_type burst_mode_enable; /*!< xmc nor/sram burst mode enable */ - xmc_asyn_wait_type asynwait_enable; /*!< xmc nor/sram nwait in asynchronous transfer enable */ - xmc_wait_signal_polarity_type wait_signal_lv; /*!< xmc nor/sram nwait polarity */ - xmc_wrap_mode_type wrapped_mode_enable; /*!< xmc nor/sram wrapped enable */ - xmc_wait_timing_type wait_signal_config; /*!< xmc nor/sram nwait timing configuration */ - xmc_write_operation_type write_enable; /*!< xmc nor/sram write enable */ - xmc_wait_signal_type wait_signal_enable; /*!< xmc nor/sram nwait in synchronous transfer enable */ - xmc_extended_mode_type write_timing_enable; /*!< xmc nor/sram read-write timing different */ - xmc_write_burst_type write_burst_syn; /*!< xmc nor/sram memory write mode control */ -} xmc_norsram_init_type; - -/** - * @brief nand and pccard timing parameters xmc - */ - -typedef struct -{ - xmc_class_bank_type class_bank; /*!< xmc nand/pccard bank */ - uint32_t mem_setup_time; /*!< xmc nand/pccard memory setup time */ - uint32_t mem_waite_time; /*!< xmc nand/pccard memory wait time */ - uint32_t mem_hold_time; /*!< xmc nand/pccard memory hold time */ - uint32_t mem_hiz_time; /*!< xmc nand/pccard memory databus high resistance time */ -} xmc_nand_pccard_timinginit_type; - -/** - * @brief xmc nand init structure definition - */ - -typedef struct -{ - xmc_class_bank_type nand_bank; /*!< xmc nand bank */ - xmc_nand_pccard_wait_type wait_enable; /*!< xmc wait feature enable */ - xmc_data_width_type bus_type; /*!< xmc nand bus width */ - xmc_ecc_enable_type ecc_enable; /*!< xmc nand ecc enable */ - xmc_ecc_pagesize_type ecc_pagesize; /*!< xmc nand ecc page size */ - uint32_t delay_time_cycle; /*!< xmc nand cle to re delay */ - uint32_t delay_time_ar; /*!< xmc nand ale to re delay */ -} xmc_nand_init_type; - -/** - * @brief xmc pccard init structure definition - */ - -typedef struct -{ - xmc_nand_pccard_wait_type enable_wait; /*!< xmc pccard wait feature enable */ - uint32_t delay_time_cr; /*!< xmc pccard cle to re delay */ - uint32_t delay_time_ar; /*!< xmc pccard ale to re delay */ -} xmc_pccard_init_type; - -/** - * @brief xmc sdram init structure definition - */ - -typedef struct -{ - xmc_sdram_bank_type sdram_bank; /*!< xmc sdram bank bype */ - xmc_sdram_inbk_type internel_banks; /*!< xmc sdram internal banks */ - xmc_sdram_clkdiv_type clkdiv; /*!< xmc sdram clock div */ - uint8_t write_protection; /*!< xmc sdram write protection */ - uint8_t burst_read; /*!< xmc sdram burst read */ - uint8_t read_delay; /*!< xmc sdram read delay */ - xmc_sdram_column_type column_address; /*!< xmc sdram column address */ - xmc_sdram_row_type row_address; /*!< xmc sdram row address */ - xmc_sdram_cas_type cas; /*!< xmc sdram cas */ - xmc_sdram_width_type width; /*!< xmc sdram data width */ -} xmc_sdram_init_type; - -/** - * @brief xmc sdram timing structure definition - */ - -typedef struct -{ - xmc_sdram_delay_type tmrd; /*!< mode register program to active delay */ - xmc_sdram_delay_type txsr; /*!< exit self-refresh to active delay */ - xmc_sdram_delay_type tras; /*!< self refresh */ - xmc_sdram_delay_type trc; /*!< refresh to active delay */ - xmc_sdram_delay_type twr; /*!< write recovery delay */ - xmc_sdram_delay_type trp; /*!< precharge to active delay */ - xmc_sdram_delay_type trcd; /*!< row active to read/write delay */ -} xmc_sdram_timing_type; - -/** - * @brief xmc sdram command structure definition - */ - -typedef struct -{ - xmc_command_type cmd; /*!< sdram command */ - xmc_cmd_bank1_2_type cmd_banks; /*!< which bank send command */ - uint32_t auto_refresh; /*!< auto refresh times */ - uint32_t data; /*!< mode register data */ -} xmc_sdram_cmd_type; - -typedef struct -{ - /** - * @brief xmc bank1 bk1ctrl register, offset:0x00+0x08*(x-1) x= 1...4 - */ - union - { - __IO uint32_t bk1ctrl; - struct - { - __IO uint32_t en : 1; /* [0] */ - __IO uint32_t admuxen : 1; /* [1] */ - __IO uint32_t dev : 2; /* [3:2] */ - __IO uint32_t extmdbw : 2; /* [5:4] */ - __IO uint32_t noren : 1; /* [6] */ - __IO uint32_t reserved1 : 1; /* [7] */ - __IO uint32_t syncben : 1; /* [8] */ - __IO uint32_t nwpol : 1; /* [9] */ - __IO uint32_t wrapen : 1; /* [10] */ - __IO uint32_t nwtcfg : 1; /* [11] */ - __IO uint32_t wen : 1; /* [12] */ - __IO uint32_t nwsen : 1; /* [13] */ - __IO uint32_t rwtd : 1; /* [14] */ - __IO uint32_t nwasen : 1; /* [15] */ - __IO uint32_t crpgs : 3; /* [18:16] */ - __IO uint32_t mwmc : 1; /* [19] */ - __IO uint32_t reserved2 : 12;/* [31:20] */ - } bk1ctrl_bit; - }; - - /** - * @brief xmc bank1 bk1tmg register, offset:0x04+0x08*(x-1) x= 1...4 - */ - union - { - __IO uint32_t bk1tmg; - struct - { - __IO uint32_t addrst : 4; /* [3:0] */ - __IO uint32_t addrht : 4; /* [7:4] */ - __IO uint32_t dtst : 8; /* [15:8] */ - __IO uint32_t buslat : 4; /* [19:16] */ - __IO uint32_t clkpsc : 4; /* [23:20] */ - __IO uint32_t dtlat : 4; /* [27:24] */ - __IO uint32_t asyncm : 2; /* [29:28] */ - __IO uint32_t reserved1 : 2; /* [31:30] */ - } bk1tmg_bit; - }; - -} xmc_bank1_ctrl_tmg_reg_type; - -typedef struct -{ - /** - * @brief xmc bank1 bk1tmgwr register, offset:0x104+0x08*(x-1) x= 1...4 - */ - union - { - __IO uint32_t bk1tmgwr; - struct - { - __IO uint32_t addrst : 4; /* [3:0] */ - __IO uint32_t addrht : 4; /* [7:4] */ - __IO uint32_t dtst : 8; /* [15:8] */ - __IO uint32_t buslat : 4; /* [19:16] */ - __IO uint32_t reserved1 : 8; /* [27:20] */ - __IO uint32_t asyncm : 2; /* [29:28] */ - __IO uint32_t reserved2 : 2; /* [31:30] */ - } bk1tmgwr_bit; - }; - - /** - * @brief xmc bank1 reserved register - */ - __IO uint32_t reserved1; - -} xmc_bank1_tmgwr_reg_type; - -/** - * @brief xmc bank1 registers - */ -typedef struct -{ - /** - * @brief xmc bank1 ctrl and tmg register, offset:0x00~0x1C - */ - xmc_bank1_ctrl_tmg_reg_type ctrl_tmg_group[4]; - - /** - * @brief xmc bank1 reserved register, offset:0x20~0x100 - */ - __IO uint32_t reserved1[57]; - - /** - * @brief xmc bank1 tmgwr register, offset:0x104~0x11C - */ - xmc_bank1_tmgwr_reg_type tmgwr_group[4]; - - /** - * @brief xmc bank1 reserved register, offset:0x120~0x21C - */ - __IO uint32_t reserved2[64]; - - /** - * @brief xmc bank1 ext register, offset:0x220~0x22C - */ - union - { - __IO uint32_t ext[4]; - struct - { - __IO uint32_t buslatw2w : 8; /* [7:0] */ - __IO uint32_t buslatr2r : 8; /* [15:8] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } ext_bit[4]; - }; - -} xmc_bank1_type; - -/** - * @brief xmc bank2 registers - */ -typedef struct -{ - /** - * @brief xmc bk2ctrl register, offset:0x60 - */ - union - { - __IO uint32_t bk2ctrl; - struct - { - __IO uint32_t reserved1 : 1; /* [0] */ - __IO uint32_t nwen : 1; /* [1] */ - __IO uint32_t en : 1; /* [2] */ - __IO uint32_t dev : 1; /* [3] */ - __IO uint32_t extmdbw : 2; /* [5:4] */ - __IO uint32_t eccen : 1; /* [6] */ - __IO uint32_t reserved2 : 2; /* [8:7] */ - __IO uint32_t tcr : 4; /* [12:9] */ - __IO uint32_t tar : 4; /* [16:13] */ - __IO uint32_t eccpgs : 3; /* [19:17] */ - __IO uint32_t reserved3 : 12;/* [31:20] */ - } bk2ctrl_bit; - }; - - /** - * @brief xmc bk2is register, offset:0x64 - */ - union - { - __IO uint32_t bk2is; - struct - { - __IO uint32_t res : 1; /* [0] */ - __IO uint32_t hls : 1; /* [1] */ - __IO uint32_t fes : 1; /* [2] */ - __IO uint32_t reien : 1; /* [3] */ - __IO uint32_t hlien : 1; /* [4] */ - __IO uint32_t feien : 1; /* [5] */ - __IO uint32_t fifoe : 1; /* [6] */ - __IO uint32_t reserved1 : 25;/* [31:7] */ - } bk2is_bit; - }; - - /** - * @brief xmc bk2tmgmem register, offset:0x68 - */ - union - { - __IO uint32_t bk2tmgmem; - struct - { - __IO uint32_t cmst : 8; /* [7:0] */ - __IO uint32_t cmwt : 8; /* [15:8] */ - __IO uint32_t cmht : 8; /* [23:16] */ - __IO uint32_t cmdhizt : 8; /* [31:24] */ - } bk2tmgmem_bit; - }; - - /** - * @brief xmc bk2tmgatt register, offset:0x6C - */ - union - { - __IO uint32_t bk2tmgatt; - struct - { - __IO uint32_t amst : 8; /* [7:0] */ - __IO uint32_t amwt : 8; /* [15:8] */ - __IO uint32_t amht : 8; /* [23:16] */ - __IO uint32_t amdhizt : 8; /* [31:24] */ - } bk2tmgatt_bit; - }; - - /** - * @brief xmc reserved register, offset:0x70 - */ - __IO uint32_t reserved1; - - /** - * @brief xmc bk2ecc register, offset:0x74 - */ - union - { - __IO uint32_t bk2ecc; - struct - { - __IO uint32_t ecc : 32; /* [31:0] */ - } bk2ecc_bit; - }; - -} xmc_bank2_type; - -/** - * @brief xmc bank3 registers - */ -typedef struct -{ - /** - * @brief xmc bk3ctrl register, offset:0x80 - */ - union - { - __IO uint32_t bk3ctrl; - struct - { - __IO uint32_t reserved1 : 1; /* [0] */ - __IO uint32_t nwen : 1; /* [1] */ - __IO uint32_t en : 1; /* [2] */ - __IO uint32_t dev : 1; /* [3] */ - __IO uint32_t extmdbw : 2; /* [5:4] */ - __IO uint32_t eccen : 1; /* [6] */ - __IO uint32_t reserved2 : 2; /* [8:7] */ - __IO uint32_t tcr : 4; /* [12:9] */ - __IO uint32_t tar : 4; /* [16:13] */ - __IO uint32_t eccpgs : 3; /* [19:17] */ - __IO uint32_t reserved3 : 12;/* [31:20] */ - } bk3ctrl_bit; - }; - - /** - * @brief xmc bk3is register, offset:0x84 - */ - union - { - __IO uint32_t bk3is; - struct - { - __IO uint32_t res : 1; /* [0] */ - __IO uint32_t hls : 1; /* [1] */ - __IO uint32_t fes : 1; /* [2] */ - __IO uint32_t reien : 1; /* [3] */ - __IO uint32_t hlien : 1; /* [4] */ - __IO uint32_t feien : 1; /* [5] */ - __IO uint32_t fifoe : 1; /* [6] */ - __IO uint32_t reserved1 : 25;/* [31:7] */ - } bk3is_bit; - }; - - /** - * @brief xmc bk3tmgmem register, offset:0x88 - */ - union - { - __IO uint32_t bk3tmgmem; - struct - { - __IO uint32_t cmst : 8; /* [7:0] */ - __IO uint32_t cmwt : 8; /* [15:8] */ - __IO uint32_t cmht : 8; /* [23:16] */ - __IO uint32_t cmdhizt : 8; /* [31:24] */ - } bk3tmgmem_bit; - }; - - /** - * @brief xmc bk3tmgatt register, offset:0x8C - */ - union - { - __IO uint32_t bk3tmgatt; - struct - { - __IO uint32_t amst : 8; /* [7:0] */ - __IO uint32_t amwt : 8; /* [15:8] */ - __IO uint32_t amht : 8; /* [23:16] */ - __IO uint32_t amdhizt : 8; /* [31:24] */ - } bk3tmgatt_bit; - }; - - /** - * @brief xmc reserved register, offset:0x90 - */ - __IO uint32_t reserved1; - - /** - * @brief xmc bk3ecc register, offset:0x94 - */ - union - { - __IO uint32_t bk3ecc; - struct - { - __IO uint32_t ecc : 32; /* [31:0] */ - } bk3ecc_bit; - }; -} xmc_bank3_type; - -/** - * @brief xmc bank4 registers - */ -typedef struct -{ - - /** - * @brief xmc bk4ctrl register, offset:0xA0 - */ - union - { - __IO uint32_t bk4ctrl; - struct - { - __IO uint32_t reserved1 : 1; /* [0] */ - __IO uint32_t nwen : 1; /* [1] */ - __IO uint32_t en : 1; /* [2] */ - __IO uint32_t dev : 1; /* [3] */ - __IO uint32_t extmdbw : 2; /* [5:4] */ - __IO uint32_t eccen : 1; /* [6] */ - __IO uint32_t reserved2 : 2; /* [8:7] */ - __IO uint32_t tcr : 4; /* [12:9] */ - __IO uint32_t tar : 4; /* [16:13] */ - __IO uint32_t eccpgs : 3; /* [19:17] */ - __IO uint32_t reserved3 : 12;/* [31:20] */ - } bk4ctrl_bit; - }; - - /** - * @brief xmc bk4is register, offset:0xA4 - */ - union - { - __IO uint32_t bk4is; - struct - { - __IO uint32_t res : 1; /* [0] */ - __IO uint32_t hls : 1; /* [1] */ - __IO uint32_t fes : 1; /* [2] */ - __IO uint32_t reien : 1; /* [3] */ - __IO uint32_t hlien : 1; /* [4] */ - __IO uint32_t feien : 1; /* [5] */ - __IO uint32_t fifoe : 1; /* [6] */ - __IO uint32_t reserved1 : 25;/* [31:7] */ - } bk4is_bit; - }; - - /** - * @brief xmc bk4tmgmem register, offset:0xA8 - */ - union - { - __IO uint32_t bk4tmgmem; - struct - { - __IO uint32_t cmst : 8; /* [7:0] */ - __IO uint32_t cmwt : 8; /* [15:8] */ - __IO uint32_t cmht : 8; /* [23:16] */ - __IO uint32_t cmdhizt : 8; /* [31:24] */ - } bk4tmgmem_bit; - }; - - /** - * @brief xmc bk4tmgatt register, offset:0xAC - */ - union - { - __IO uint32_t bk4tmgatt; - struct - { - __IO uint32_t amst : 8; /* [7:0] */ - __IO uint32_t amwt : 8; /* [15:8] */ - __IO uint32_t amht : 8; /* [23:16] */ - __IO uint32_t amdhizt : 8; /* [31:24] */ - } bk4tmgatt_bit; - }; - - /** - * @brief xmc bk4tmgio register, offset:0xB0 - */ - union - { - __IO uint32_t bk4tmgio; - struct - { - __IO uint32_t iost : 8; /* [7:0] */ - __IO uint32_t iowt : 8; /* [15:8] */ - __IO uint32_t ioht : 8; /* [23:16] */ - __IO uint32_t iohizt : 8; /* [31:24] */ - } bk4tmgio_bit; - }; -} xmc_bank4_type; - -/** - * @brief xmc sdram type - */ -typedef struct -{ - /** - * @brief xmc sdram ctrl register, offset:0x140~0x144 - */ - union - { - __IO uint32_t ctrl[2]; - struct - { - __IO uint32_t ca : 2; /* [1:0] */ - __IO uint32_t ra : 2; /* [3:2] */ - __IO uint32_t db : 2; /* [5:4] */ - __IO uint32_t inbk : 1; /* [6] */ - __IO uint32_t cas : 2; /* [8:7] */ - __IO uint32_t wrp : 1; /* [9] */ - __IO uint32_t clkdiv : 2; /* [11:10] */ - __IO uint32_t bstr : 1; /* [12] */ - __IO uint32_t rd : 2; /* [14:13] */ - __IO uint32_t reserved1 : 17;/* [31:15] */ - } ctrl_bit[2]; - }; - - /** - * @brief xmc sdram tm register, offset:0x148~0x14C - */ - union - { - __IO uint32_t tm[2]; - struct - { - __IO uint32_t tmrd : 4; /* [3:0] */ - __IO uint32_t txsr : 4; /* [7:4] */ - __IO uint32_t tras : 4; /* [11:8] */ - __IO uint32_t trc : 4; /* [15:12] */ - __IO uint32_t twr : 4; /* [19:16] */ - __IO uint32_t trp : 4; /* [23:20] */ - __IO uint32_t trcd : 4; /* [27:24] */ - __IO uint32_t reserved1 : 4; /* [31:28] */ - } tm_bit[2]; - - }; - -/** - * @brief xmc sdram cmd register, offset:0x150 - */ - union - { - __IO uint32_t cmd; - struct - { - __IO uint32_t cmd : 3; /* [2:0] */ - __IO uint32_t bk2 : 1; /* [3] */ - __IO uint32_t bk1 : 1; /* [4] */ - __IO uint32_t art : 4; /* [8:5] */ - __IO uint32_t mrd : 13;/* [21:9] */ - __IO uint32_t reserved1 : 10;/* [31:22] */ - } cmd_bit; - }; - - /** - * @brief xmc sdram rcnt register, offset:0x154 - */ - union - { - __IO uint32_t rcnt; - struct - { - __IO uint32_t errc : 1; /* [0] */ - __IO uint32_t rc : 13;/* [13:1] */ - __IO uint32_t erien : 1; /* [14] */ - __IO uint32_t reserved1 : 17;/* [31:15] */ - } rcnt_bit; - }; - - /** - * @brief xmc sdram sts register, offset:0x158 - */ - union - { - __IO uint32_t sts; - struct - { - __IO uint32_t err : 1; /* [0] */ - __IO uint32_t bk1sts : 2; /* [2:1] */ - __IO uint32_t bk2sts : 2; /* [4:3] */ - __IO uint32_t busy : 1; /* [5] */ - __IO uint32_t reserved1 : 26;/* [31:6] */ - } sts_bit; - }; -}xmc_sdram_type; - -/** - * @} - */ - -#define XMC_BANK1 ((xmc_bank1_type *) XMC_BANK1_REG_BASE) -#define XMC_BANK2 ((xmc_bank2_type *) XMC_BANK2_REG_BASE) -#define XMC_BANK3 ((xmc_bank3_type *) XMC_BANK3_REG_BASE) -#define XMC_BANK4 ((xmc_bank4_type *) XMC_BANK4_REG_BASE) -#define XMC_SDRAM ((xmc_sdram_type *) XMC_SDRAM_REG_BASE) - -/** @defgroup XMC_exported_functions - * @{ - */ - -void xmc_nor_sram_reset(xmc_nor_sram_subbank_type xmc_subbank); -void xmc_nor_sram_init(xmc_norsram_init_type* xmc_norsram_init_struct); -void xmc_nor_sram_timing_config(xmc_norsram_timing_init_type* xmc_rw_timing_struct, - xmc_norsram_timing_init_type* xmc_w_timing_struct); -void xmc_norsram_default_para_init(xmc_norsram_init_type* xmc_nor_sram_init_struct); -void xmc_norsram_timing_default_para_init(xmc_norsram_timing_init_type* xmc_rw_timing_struct, - xmc_norsram_timing_init_type* xmc_w_timing_struct); -void xmc_nor_sram_enable(xmc_nor_sram_subbank_type xmc_subbank, confirm_state new_state); -void xmc_ext_timing_config(xmc_nor_sram_subbank_type xmc_sub_bank, uint16_t w2w_timing, uint16_t r2r_timing); -void xmc_nand_reset(xmc_class_bank_type xmc_bank); -void xmc_nand_init(xmc_nand_init_type* xmc_nand_init_struct); -void xmc_nand_timing_config(xmc_nand_pccard_timinginit_type* xmc_common_spacetiming_struct, - xmc_nand_pccard_timinginit_type* xmc_attribute_spacetiming_struct); -void xmc_nand_default_para_init(xmc_nand_init_type* xmc_nand_init_struct); -void xmc_nand_timing_default_para_init(xmc_nand_pccard_timinginit_type* xmc_common_spacetiming_struct, - xmc_nand_pccard_timinginit_type* xmc_attribute_spacetiming_struct); -void xmc_nand_enable(xmc_class_bank_type xmc_bank, confirm_state new_state); -void xmc_nand_ecc_enable(xmc_class_bank_type xmc_bank, confirm_state new_state); -uint32_t xmc_ecc_get(xmc_class_bank_type xmc_bank); -void xmc_interrupt_enable(xmc_class_bank_type xmc_bank, xmc_interrupt_sources_type xmc_int, confirm_state new_state); -flag_status xmc_flag_status_get(xmc_class_bank_type xmc_bank, xmc_interrupt_flag_type xmc_flag); -void xmc_flag_clear(xmc_class_bank_type xmc_bank, xmc_interrupt_flag_type xmc_flag); -void xmc_pccard_reset(void); -void xmc_pccard_init(xmc_pccard_init_type* xmc_pccard_init_struct); -void xmc_pccard_timing_config(xmc_nand_pccard_timinginit_type* xmc_common_spacetiming_struct, - xmc_nand_pccard_timinginit_type* xmc_attribute_spacetiming_struct, - xmc_nand_pccard_timinginit_type* xmc_iospace_timing_struct); -void xmc_pccard_default_para_init(xmc_pccard_init_type* xmc_pccard_init_struct); -void xmc_pccard_timing_default_para_init(xmc_nand_pccard_timinginit_type* xmc_common_spacetiming_struct, - xmc_nand_pccard_timinginit_type* xmc_attribute_spacetiming_struct, - xmc_nand_pccard_timinginit_type* xmc_iospace_timing_struct); -void xmc_pccard_enable(confirm_state new_state); -void xmc_sdram_reset(xmc_sdram_bank_type xmc_bank); -void xmc_sdram_init(xmc_sdram_init_type *xmc_sdram_init_struct, xmc_sdram_timing_type *xmc_sdram_timing_struct); -void xmc_sdram_default_para_init(xmc_sdram_init_type *xmc_sdram_init_struct, xmc_sdram_timing_type *xmc_sdram_timing_struct); -void xmc_sdram_cmd(xmc_sdram_cmd_type *xmc_sdram_cmd_struct); -uint32_t xmc_sdram_status_get(xmc_sdram_bank_type xmc_bank); -void xmc_sdram_refresh_counter_set(uint32_t counter); -void xmc_sdram_auto_refresh_set(uint32_t number); - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F435_437_board/at32f435_437_board.c b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F435_437_board/at32f435_437_board.c new file mode 100644 index 0000000..d72d773 --- /dev/null +++ b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F435_437_board/at32f435_437_board.c @@ -0,0 +1,375 @@ +/** + ************************************************************************** + * @file at32f435_437_board.c + * @version v2.0.4 + * @date 2021-12-31 + * @brief set of firmware functions to manage leds and push-button. + * initialize delay function. + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ + +#include "at32f435_437_board.h" + +/** @addtogroup AT32F435_437_board + * @{ + */ + +/** @defgroup BOARD + * @brief onboard periph driver + * @{ + */ + +/* delay macros */ +#define STEP_DELAY_MS 50 + +/* at-start led resouce array */ +gpio_type *led_gpio_port[LED_NUM] = {LED2_GPIO, LED3_GPIO, LED4_GPIO}; +uint16_t led_gpio_pin[LED_NUM] = {LED2_PIN, LED3_PIN, LED4_PIN}; +crm_periph_clock_type led_gpio_crm_clk[LED_NUM] = {LED2_GPIO_CRM_CLK, LED3_GPIO_CRM_CLK, LED4_GPIO_CRM_CLK}; + +/* delay variable */ +static __IO uint32_t fac_us; +static __IO uint32_t fac_ms; + +/* support printf function, usemicrolib is unnecessary */ +#if (__ARMCC_VERSION > 6000000) + __asm (".global __use_no_semihosting\n\t"); + void _sys_exit(int x) + { + x = x; + } + /* __use_no_semihosting was requested, but _ttywrch was */ + void _ttywrch(int ch) + { + ch = ch; + } + FILE __stdout; +#else + #ifdef __CC_ARM + #pragma import(__use_no_semihosting) + struct __FILE + { + int handle; + }; + FILE __stdout; + void _sys_exit(int x) + { + x = x; + } + /* __use_no_semihosting was requested, but _ttywrch was */ + void _ttywrch(int ch) + { + ch = ch; + } + #endif +#endif + +#if defined (__GNUC__) && !defined (__clang__) + #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) +#else + #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) +#endif + +/** + * @brief retargets the c library printf function to the usart. + * @param none + * @retval none + */ +PUTCHAR_PROTOTYPE +{ + while(usart_flag_get(PRINT_UART, USART_TDBE_FLAG) == RESET); + usart_data_transmit(PRINT_UART, ch); + return ch; +} + +/** + * @brief initialize uart + * @param baudrate: uart baudrate + * @retval none + */ +void uart_print_init(uint32_t baudrate) +{ + gpio_init_type gpio_init_struct; + + /* enable the uart and gpio clock */ + crm_periph_clock_enable(PRINT_UART_CRM_CLK, TRUE); + crm_periph_clock_enable(PRINT_UART_TX_GPIO_CRM_CLK, TRUE); + + gpio_default_para_init(&gpio_init_struct); + + /* configure the uart tx pin */ + gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_pins = PRINT_UART_TX_PIN; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init(PRINT_UART_TX_GPIO, &gpio_init_struct); + + gpio_pin_mux_config(PRINT_UART_TX_GPIO, PRINT_UART_TX_PIN_SOURCE, PRINT_UART_TX_PIN_MUX_NUM); + + /* configure uart param */ + usart_init(PRINT_UART, baudrate, USART_DATA_8BITS, USART_STOP_1_BIT); + usart_transmitter_enable(PRINT_UART, TRUE); + usart_enable(PRINT_UART, TRUE); +} + +/** + * @brief board initialize interface init led and button + * @param none + * @retval none + */ +void at32_board_init() +{ + /* initialize delay function */ + delay_init(); + + /* configure led in at_start_board */ + at32_led_init(LED2); + at32_led_init(LED3); + at32_led_init(LED4); + at32_led_off(LED2); + at32_led_off(LED3); + at32_led_off(LED4); + + /* configure button in at_start board */ + at32_button_init(); +} + +/** + * @brief configure button gpio + * @param button: specifies the button to be configured. + * @retval none + */ +void at32_button_init(void) +{ + gpio_init_type gpio_init_struct; + + /* enable the button clock */ + crm_periph_clock_enable(USER_BUTTON_CRM_CLK, TRUE); + + /* set default parameter */ + gpio_default_para_init(&gpio_init_struct); + + /* configure button pin as input with pull-up/pull-down */ + gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; + gpio_init_struct.gpio_pins = USER_BUTTON_PIN; + gpio_init_struct.gpio_pull = GPIO_PULL_DOWN; + gpio_init(USER_BUTTON_PORT, &gpio_init_struct); +} + +/** + * @brief returns the selected button state + * @param none + * @retval the button gpio pin value + */ +uint8_t at32_button_state(void) +{ + return gpio_input_data_bit_read(USER_BUTTON_PORT, USER_BUTTON_PIN); +} + +/** + * @brief returns which button have press down + * @param none + * @retval the button have press down + */ +button_type at32_button_press() +{ + static uint8_t pressed = 1; + /* get button state in at_start board */ + if((pressed == 1) && (at32_button_state() != RESET)) + { + /* debounce */ + pressed = 0; + delay_ms(10); + if(at32_button_state() != RESET) + return USER_BUTTON; + } + else if(at32_button_state() == RESET) + { + pressed = 1; + } + return NO_BUTTON; +} + +/** + * @brief configure led gpio + * @param led: specifies the led to be configured. + * @retval none + */ +void at32_led_init(led_type led) +{ + gpio_init_type gpio_init_struct; + + /* enable the led clock */ + crm_periph_clock_enable(led_gpio_crm_clk[led], TRUE); + + /* set default parameter */ + gpio_default_para_init(&gpio_init_struct); + + /* configure the led gpio */ + gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT; + gpio_init_struct.gpio_pins = led_gpio_pin[led]; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init(led_gpio_port[led], &gpio_init_struct); +} + +/** + * @brief turns selected led on. + * @param led: specifies the led to be set on. + * this parameter can be one of following parameters: + * @arg LED2 + * @arg LED3 + * @arg LED4 + * @retval none + */ +void at32_led_on(led_type led) +{ + if(led > (LED_NUM - 1)) + return; + if(led_gpio_pin[led]) + led_gpio_port[led]->clr = led_gpio_pin[led]; +} + +/** + * @brief turns selected led off. + * @param led: specifies the led to be set off. + * this parameter can be one of following parameters: + * @arg LED2 + * @arg LED3 + * @arg LED4 + * @retval none + */ +void at32_led_off(led_type led) +{ + if(led > (LED_NUM - 1)) + return; + if(led_gpio_pin[led]) + led_gpio_port[led]->scr = led_gpio_pin[led]; +} + +/** + * @brief turns selected led tooggle. + * @param led: specifies the led to be set off. + * this parameter can be one of following parameters: + * @arg LED2 + * @arg LED3 + * @arg LED4 + * @retval none + */ +void at32_led_toggle(led_type led) +{ + if(led > (LED_NUM - 1)) + return; + if(led_gpio_pin[led]) + led_gpio_port[led]->odt ^= led_gpio_pin[led]; +} + +/** + * @brief initialize delay function + * @param none + * @retval none + */ +void delay_init() +{ + /* configure systick */ + systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV); + fac_us = system_core_clock / (1000000U); + fac_ms = fac_us * (1000U); +} + +/** + * @brief inserts a delay time. + * @param nus: specifies the delay time length, in microsecond. + * @retval none + */ +void delay_us(uint32_t nus) +{ + uint32_t temp = 0; + SysTick->LOAD = (uint32_t)(nus * fac_us); + SysTick->VAL = 0x00; + SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk ; + do + { + temp = SysTick->CTRL; + }while((temp & 0x01) && !(temp & (1 << 16))); + + SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; + SysTick->VAL = 0x00; +} + +/** + * @brief inserts a delay time. + * @param nms: specifies the delay time length, in milliseconds. + * @retval none + */ +void delay_ms(uint16_t nms) +{ + uint32_t temp = 0; + while(nms) + { + if(nms > STEP_DELAY_MS) + { + SysTick->LOAD = (uint32_t)(STEP_DELAY_MS * fac_ms); + nms -= STEP_DELAY_MS; + } + else + { + SysTick->LOAD = (uint32_t)(nms * fac_ms); + nms = 0; + } + SysTick->VAL = 0x00; + SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; + do + { + temp = SysTick->CTRL; + }while((temp & 0x01) && !(temp & (1 << 16))); + + SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; + SysTick->VAL = 0x00; + } +} + +/** + * @brief inserts a delay time. + * @param sec: specifies the delay time, in seconds. + * @retval none + */ +void delay_sec(uint16_t sec) +{ + uint16_t index; + for(index = 0; index < sec; index++) + { + delay_ms(500); + delay_ms(500); + } +} + +/** + * @} + */ + +/** + * @} + */ + diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F435_437_board/at32f435_437_board.h b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F435_437_board/at32f435_437_board.h new file mode 100644 index 0000000..2fdca72 --- /dev/null +++ b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F435_437_board/at32f435_437_board.h @@ -0,0 +1,154 @@ +/** + ************************************************************************** + * @file at32f435_437_board.c + * @version v2.0.4 + * @date 2021-12-31 + * @brief header file for at-start board. set of firmware functions to + * manage leds and push-button. initialize delay function. + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ + +#ifndef __AT32F435_437_BOARD_H +#define __AT32F435_437_BOARD_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "stdio.h" +#include "at32f435_437.h" + +/** @addtogroup AT32F435_437_board + * @{ + */ + +/** @addtogroup BOARD + * @{ + */ + +/** @defgroup BOARD_pins_definition + * @{ + */ + +/** + * this header include define support list: + * 1. at-start-f435 v1.x board + * 2. at-start-f437 v1.x board + * if define AT_START_F435_V1, the header file support at-start-f437 v1.x board + * if define AT_START_F437_V1, the header file support at-start-f437 v1.x board + */ + +#if !defined (AT_START_F435_V1) && !defined (AT_START_F437_V1) +#error "please select first the board at-start device used in your application (in at32f435_437_board.h file)" +#endif + +/******************** define led ********************/ +typedef enum +{ + LED2 = 0, + LED3 = 1, + LED4 = 2 +}led_type; + +#define LED_NUM 3 + +#if defined (AT_START_F435_V1) || defined (AT_START_F437_V1) +#define LED2_PIN GPIO_PINS_13 +#define LED2_GPIO GPIOD +#define LED2_GPIO_CRM_CLK CRM_GPIOD_PERIPH_CLOCK + +#define LED3_PIN GPIO_PINS_14 +#define LED3_GPIO GPIOD +#define LED3_GPIO_CRM_CLK CRM_GPIOD_PERIPH_CLOCK + +#define LED4_PIN GPIO_PINS_15 +#define LED4_GPIO GPIOD +#define LED4_GPIO_CRM_CLK CRM_GPIOD_PERIPH_CLOCK +#endif + +/**************** define print uart ******************/ +#define PRINT_UART USART1 +#define PRINT_UART_CRM_CLK CRM_USART1_PERIPH_CLOCK +#define PRINT_UART_TX_PIN GPIO_PINS_9 +#define PRINT_UART_TX_GPIO GPIOA +#define PRINT_UART_TX_GPIO_CRM_CLK CRM_GPIOA_PERIPH_CLOCK +#define PRINT_UART_TX_PIN_SOURCE GPIO_PINS_SOURCE9 +#define PRINT_UART_TX_PIN_MUX_NUM GPIO_MUX_7 + +/******************* define button *******************/ +typedef enum +{ + USER_BUTTON = 0, + NO_BUTTON = 1 +} button_type; + +#define USER_BUTTON_PIN GPIO_PINS_0 +#define USER_BUTTON_PORT GPIOA +#define USER_BUTTON_CRM_CLK CRM_GPIOA_PERIPH_CLOCK + +/** + * @} + */ + +/** @defgroup BOARD_exported_functions + * @{ + */ + +/******************** functions ********************/ +void at32_board_init(void); + +/* led operation function */ +void at32_led_init(led_type led); +void at32_led_on(led_type led); +void at32_led_off(led_type led); +void at32_led_toggle(led_type led); + +/* button operation function */ +void at32_button_init(void); +button_type at32_button_press(void); +uint8_t at32_button_state(void); + +/* delay function */ +void delay_init(void); +void delay_us(uint32_t nus); +void delay_ms(uint16_t nms); +void delay_sec(uint16_t sec); + +/* printf uart init function */ +void uart_print_init(uint32_t baudrate); + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include/usb_core.h b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include/usb_core.h new file mode 100644 index 0000000..d8cd603 --- /dev/null +++ b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include/usb_core.h @@ -0,0 +1,136 @@ +/** + ************************************************************************** + * @file usb_core.h + * @version v2.0.4 + * @date 2021-12-31 + * @brief usb core header file + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ + +/* define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USB_CORE_H +#define __USB_CORE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include "usb_std.h" +#include "usb_conf.h" + +#ifdef USE_OTG_DEVICE_MODE +#include "usbd_core.h" +#endif +#ifdef USE_OTG_HOST_MODE +#include "usbh_core.h" +#endif + +/** @addtogroup AT32F435_437_middlewares_usb_drivers + * @{ + */ + +/** @addtogroup USB_drivers_core + * @{ + */ + +/** @defgroup USB_core_exported_types + * @{ + */ + +/** + * @brief usb core speed select + */ +typedef enum +{ + USB_LOW_SPEED_CORE_ID, /*!< usb low speed core id */ + USB_FULL_SPEED_CORE_ID, /*!< usb full speed core id */ + USB_HIGH_SPEED_CORE_ID, /*!< usb high speed core id */ +} usb_speed_type; + +/** + * @brief usb core cofig struct + */ +typedef struct +{ + uint8_t speed; /*!< otg speed */ + uint8_t dma_en; /*!< dma enable state, not use*/ + uint8_t hc_num; /*!< the otg host support number of channel */ + uint8_t ept_num; /*!< the otg device support number of endpoint */ + + uint16_t max_size; /*!< support max packet size */ + uint16_t fifo_size; /*!< the usb otg total file size */ + uint8_t phy_itface; /*!< usb phy select */ + uint8_t core_id; /*!< the usb otg core id */ + uint8_t low_power; /*!< the usb otg low power option */ + uint8_t sof_out; /*!< the sof signal output */ + uint8_t usb_id; /*!< select otgfs1 or otgfs2 */ + uint8_t vbusig; /*!< vbus ignore */ +} usb_core_cfg; + +/** + * @brief usb otg core struct type + */ +typedef struct +{ + usb_reg_type *usb_reg; /*!< the usb otg register type */ +#ifdef USE_OTG_DEVICE_MODE + usbd_core_type dev; /*!< the usb device core type */ +#endif + +#ifdef USE_OTG_HOST_MODE + usbh_core_type host; /*!< the usb host core type */ +#endif + + usb_core_cfg cfg; /*!< the usb otg core config type */ + +} otg_core_type; + +usb_sts_type usb_core_config(otg_core_type *otgdev, uint8_t core_id); +#ifdef USE_OTG_DEVICE_MODE +usb_sts_type usbd_init(otg_core_type *udev, + uint8_t core_id, uint8_t usb_id, + usbd_class_handler *class_handler, + usbd_desc_handler *desc_handler); +#endif + +#ifdef USE_OTG_HOST_MODE +usb_sts_type usbh_init(otg_core_type *hdev, + uint8_t core_id, uint8_t usb_id, + usbh_class_handler_type *class_handler, + usbh_user_handler_type *user_handler); +#endif +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include/usb_std.h b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include/usb_std.h new file mode 100644 index 0000000..ca78fc3 --- /dev/null +++ b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include/usb_std.h @@ -0,0 +1,335 @@ +/** + ************************************************************************** + * @file usb_std.h + * @version v2.0.4 + * @date 2021-12-31 + * @brief usb standard header file + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ + +/* define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USB_STD_H +#define __USB_STD_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* includes ------------------------------------------------------------------*/ +#include "usb_conf.h" + +/** @addtogroup AT32F435_437_middlewares_usb_drivers + * @{ + */ + +/** @addtogroup USB_standard + * @{ + */ + +/** @defgroup USB_standard_define + * @{ + */ + +/** + * @brief usb request recipient + */ +#define USB_REQ_RECIPIENT_DEVICE 0x00 /*!< usb request recipient device */ +#define USB_REQ_RECIPIENT_INTERFACE 0x01 /*!< usb request recipient interface */ +#define USB_REQ_RECIPIENT_ENDPOINT 0x02 /*!< usb request recipient endpoint */ +#define USB_REQ_RECIPIENT_OTHER 0x03 /*!< usb request recipient other */ +#define USB_REQ_RECIPIENT_MASK 0x1F /*!< usb request recipient mask */ + +/** + * @brief usb request type + */ +#define USB_REQ_TYPE_STANDARD 0x00 /*!< usb request type standard */ +#define USB_REQ_TYPE_CLASS 0x20 /*!< usb request type class */ +#define USB_REQ_TYPE_VENDOR 0x40 /*!< usb request type vendor */ +#define USB_REQ_TYPE_RESERVED 0x60 /*!< usb request type reserved */ + +/** + * @brief usb request data transfer direction + */ +#define USB_REQ_DIR_HTD 0x00 /*!< usb request data transfer direction host to device */ +#define USB_REQ_DIR_DTH 0x80 /*!< usb request data transfer direction device to host */ + +/** + * @brief usb standard device requests codes + */ +#define USB_STD_REQ_GET_STATUS 0 /*!< usb request code status */ +#define USB_STD_REQ_CLEAR_FEATURE 1 /*!< usb request code clear feature */ +#define USB_STD_REQ_SET_FEATURE 3 /*!< usb request code feature */ +#define USB_STD_REQ_SET_ADDRESS 5 /*!< usb request code address */ +#define USB_STD_REQ_GET_DESCRIPTOR 6 /*!< usb request code get descriptor */ +#define USB_STD_REQ_SET_DESCRIPTOR 7 /*!< usb request code set descriptor */ +#define USB_STD_REQ_GET_CONFIGURATION 8 /*!< usb request code get configuration */ +#define USB_STD_REQ_SET_CONFIGURATION 9 /*!< usb request code set configuration */ +#define USB_STD_REQ_GET_INTERFACE 10 /*!< usb request code get interface */ +#define USB_STD_REQ_SET_INTERFACE 11 /*!< usb request code set interface */ +#define USB_STD_REQ_SYNCH_FRAME 12 /*!< usb request code synch frame */ + +/** + * @brief usb standard device type + */ +#define USB_DESCIPTOR_TYPE_DEVICE 1 /*!< usb standard device type device */ +#define USB_DESCIPTOR_TYPE_CONFIGURATION 2 /*!< usb standard device type configuration */ +#define USB_DESCIPTOR_TYPE_STRING 3 /*!< usb standard device type string */ +#define USB_DESCIPTOR_TYPE_INTERFACE 4 /*!< usb standard device type interface */ +#define USB_DESCIPTOR_TYPE_ENDPOINT 5 /*!< usb standard device type endpoint */ +#define USB_DESCIPTOR_TYPE_DEVICE_QUALIFIER 6 /*!< usb standard device type qualifier */ +#define USB_DESCIPTOR_TYPE_OTHER_SPEED 7 /*!< usb standard device type other speed */ +#define USB_DESCIPTOR_TYPE_INTERFACE_POWER 8 /*!< usb standard device type interface power */ + +/** + * @brief usb standard string type + */ +#define USB_LANGID_STRING 0 /*!< usb standard string type lang id */ +#define USB_MFC_STRING 1 /*!< usb standard string type mfc */ +#define USB_PRODUCT_STRING 2 /*!< usb standard string type product */ +#define USB_SERIAL_STRING 3 /*!< usb standard string type serial */ +#define USB_CONFIG_STRING 4 /*!< usb standard string type config */ +#define USB_INTERFACE_STRING 5 /*!< usb standard string type interface */ + +/** + * @brief usb configuration attributes + */ +#define USB_CONF_REMOTE_WAKEUP 2 /*!< usb configuration attributes remote wakeup */ +#define USB_CONF_SELF_POWERED 1 /*!< usb configuration attributes self powered */ + +/** + * @brief usb standard feature selectors + */ +#define USB_FEATURE_EPT_HALT 0 /*!< usb standard feature selectors endpoint halt */ +#define USB_FEATURE_REMOTE_WAKEUP 1 /*!< usb standard feature selectors remote wakeup */ +#define USB_FEATURE_TEST_MODE 2 /*!< usb standard feature selectors test mode */ + +/** + * @brief usb device connect state + */ +typedef enum +{ + USB_CONN_STATE_DEFAULT =1, /*!< usb device connect state default */ + USB_CONN_STATE_ADDRESSED, /*!< usb device connect state address */ + USB_CONN_STATE_CONFIGURED, /*!< usb device connect state configured */ + USB_CONN_STATE_SUSPENDED /*!< usb device connect state suspend */ +}usbd_conn_state; + +/** + * @brief endpoint 0 state + */ +#define USB_EPT0_IDLE 0 /*!< usb endpoint state idle */ +#define USB_EPT0_SETUP 1 /*!< usb endpoint state setup */ +#define USB_EPT0_DATA_IN 2 /*!< usb endpoint state data in */ +#define USB_EPT0_DATA_OUT 3 /*!< usb endpoint state data out */ +#define USB_EPT0_STATUS_IN 4 /*!< usb endpoint state status in */ +#define USB_EPT0_STATUS_OUT 5 /*!< usb endpoint state status out */ +#define USB_EPT0_STALL 6 /*!< usb endpoint state stall */ + +/** + * @brief usb descriptor length + */ +#define USB_DEVICE_QUALIFIER_DESC_LEN 0x0A /*!< usb qualifier descriptor length */ +#define USB_DEVICE_DESC_LEN 0x12 /*!< usb device descriptor length */ +#define USB_DEVICE_CFG_DESC_LEN 0x09 /*!< usb configuration descriptor length */ +#define USB_DEVICE_IF_DESC_LEN 0x09 /*!< usb interface descriptor length */ +#define USB_DEVICE_EPT_LEN 0x07 /*!< usb endpoint descriptor length */ +#define USB_DEVICE_OTG_DESC_LEN 0x03 /*!< usb otg descriptor length */ +#define USB_DEVICE_LANGID_STR_DESC_LEN 0x04 /*!< usb lang id string descriptor length */ +#define USB_DEVICE_OTHER_SPEED_DESC_SIZ_LEN 0x09 /*!< usb other speed descriptor length */ + +/** + * @brief usb class code + */ +#define USB_CLASS_CODE_AUDIO 0x01 /*!< usb class code audio */ +#define USB_CLASS_CODE_CDC 0x02 /*!< usb class code cdc */ +#define USB_CLASS_CODE_HID 0x03 /*!< usb class code hid */ +#define USB_CLASS_CODE_PRINTER 0x07 /*!< usb class code printer */ +#define USB_CLASS_CODE_MSC 0x08 /*!< usb class code msc */ +#define USB_CLASS_CODE_HUB 0x09 /*!< usb class code hub */ +#define USB_CLASS_CODE_CDCDATA 0x0A /*!< usb class code cdc data */ +#define USB_CLASS_CODE_CCID 0x0B /*!< usb class code ccid */ +#define USB_CLASS_CODE_VIDEO 0x0E /*!< usb class code video */ +#define USB_CLASS_CODE_VENDOR 0xFF /*!< usb class code vendor */ + +/** + * @brief usb endpoint type + */ +#define USB_EPT_DESC_CONTROL 0x00 /*!< usb endpoint description type control */ +#define USB_EPT_DESC_ISO 0x01 /*!< usb endpoint description type iso */ +#define USB_EPT_DESC_BULK 0x02 /*!< usb endpoint description type bulk */ +#define USB_EPT_DESC_INTERRUPT 0x03 /*!< usb endpoint description type interrupt */ + +#define USB_EPT_DESC_NSYNC 0x00 /*!< usb endpoint description nsync */ +#define USB_ETP_DESC_ASYNC 0x04 /*!< usb endpoint description async */ +#define USB_ETP_DESC_ADAPTIVE 0x08 /*!< usb endpoint description adaptive */ +#define USB_ETP_DESC_SYNC 0x0C /*!< usb endpoint description sync */ + +#define USB_EPT_DESC_DATA_EPT 0x00 /*!< usb endpoint description data */ +#define USB_EPT_DESC_FD_EPT 0x10 /*!< usb endpoint description fd */ +#define USB_EPT_DESC_FDDATA_EPT 0x20 /*!< usb endpoint description fddata */ + +/** + * @brief endpoint 0 max size + */ +#define USB_MAX_EP0_SIZE 64 /*!< usb endpoint 0 max size */ + +/** + * @brief usb swap address + */ +#define SWAPBYTE(addr) (uint16_t)(((uint16_t)(*((uint8_t *)(addr)))) + \ + (((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8)) /*!< swap address */ + +/** + * @brief min and max define + */ +#define MIN(a, b) (uint16_t)(((a) < (b)) ? (a) : (b)) /*!< min define*/ +#define MAX(a, b) (uint16_t)(((a) > (b)) ? (a) : (b)) /*!< max define*/ + +/** + * @brief low byte and high byte define + */ +#define LBYTE(x) ((uint8_t)(x & 0x00FF)) /*!< low byte define */ +#define HBYTE(x) ((uint8_t)((x & 0xFF00) >>8)) /*!< high byte define*/ + +/** + * @brief usb return status + */ +typedef enum +{ + USB_OK, /*!< usb status ok */ + USB_FAIL, /*!< usb status fail */ + USB_WAIT, /*!< usb status wait */ + USB_NOT_SUPPORT, /*!< usb status not support */ + USB_ERROR, /*!< usb status error */ +}usb_sts_type; + + +/** + * @brief format of usb setup data + */ +typedef struct +{ + uint8_t bmRequestType; /*!< characteristics of request */ + uint8_t bRequest; /*!< specific request */ + uint16_t wValue; /*!< word-sized field that varies according to request */ + uint16_t wIndex; /*!< word-sized field that varies according to request + typically used to pass an index or offset */ + uint16_t wLength; /*!< number of bytes to transfer if there is a data stage */ +} usb_setup_type; + +/** + * @brief format of standard device descriptor + */ +typedef struct +{ + uint8_t bLength; /*!< size of this descriptor in bytes */ + uint8_t bDescriptorType; /*!< device descriptor type */ + uint16_t bcdUSB; /*!< usb specification release number */ + uint8_t bDeviceClass; /*!< class code (assigned by the usb-if) */ + uint8_t bDeviceSubClass; /*!< subclass code (assigned by the usb-if) */ + uint8_t bDeviceProtocol; /*!< protocol code ((assigned by the usb-if)) */ + uint8_t bMaxPacketSize0; /*!< maximum packet size for endpoint zero */ + uint16_t idVendor; /*!< verndor id ((assigned by the usb-if)) */ + uint16_t idProduct; /*!< product id ((assigned by the usb-if)) */ + uint16_t bcdDevice; /*!< device release number in binary-coded decimal */ + uint8_t iManufacturer; /*!< index of string descriptor describing manufacturer */ + uint8_t iProduct; /*!< index of string descriptor describing product */ + uint8_t iSerialNumber; /*!< index of string descriptor describing serial number */ + uint8_t bNumConfigurations; /*!< number of possible configurations */ +} usb_device_desc_type; + +/** + * @brief format of standard configuration descriptor + */ +typedef struct +{ + uint8_t bLength; /*!< size of this descriptor in bytes */ + uint8_t bDescriptorType; /*!< configuration descriptor type */ + uint16_t wTotalLength; /*!< total length of data returned for this configuration */ + uint8_t bNumInterfaces; /*!< number of interfaces supported by this configuration */ + uint8_t bConfigurationValue; /*!< value to use as an argument to the SetConfiguration() request */ + uint8_t iConfiguration; /*!< index of string descriptor describing this configuration */ + uint8_t bmAttributes; /*!< configuration characteristics + D7 reserved + D6 self-powered + D5 remote wakeup + D4~D0 reserved */ + uint8_t bMaxPower; /*!< maximum power consumption of the usb device from the bus */ + + +}usb_configuration_desc_type; + +/** + * @brief format of standard interface descriptor + */ +typedef struct +{ + uint8_t bLength; /*!< size of this descriptor in bytes */ + uint8_t bDescriptorType; /*!< interface descriptor type */ + uint8_t bInterfaceNumber; /*!< number of this interface */ + uint8_t bAlternateSetting; /*!< value used to select this alternate setting for the interface */ + uint8_t bNumEndpoints; /*!< number of endpoints used by this interface */ + uint8_t bInterfaceClass; /*!< class code (assigned by the usb-if) */ + uint8_t bInterfaceSubClass; /*!< subclass code (assigned by the usb-if) */ + uint8_t bInterfaceProtocol; /*!< protocol code (assigned by the usb-if) */ + uint8_t iInterface; /*!< index of string descriptor describing this interface */ +} usb_interface_desc_type; + +/** + * @brief format of standard endpoint descriptor + */ +typedef struct +{ + uint8_t bLength; /*!< size of this descriptor in bytes */ + uint8_t bDescriptorType; /*!< endpoint descriptor type */ + uint8_t bEndpointAddress; /*!< the address of the endpoint on the usb device described by this descriptor */ + uint8_t bmAttributes; /*!< describes the endpoints attributes when it is configured using bConfiguration value */ + uint16_t wMaxPacketSize; /*!< maximum packet size this endpoint */ + uint8_t bInterval; /*!< interval for polling endpoint for data transfers */ +} usb_endpoint_desc_type; + +/** + * @brief format of header + */ +typedef struct +{ + uint8_t bLength; /*!< size of this descriptor in bytes */ + uint8_t bDescriptorType; /*!< descriptor type */ +} usb_header_desc_type; + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include/usbd_core.h b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include/usbd_core.h new file mode 100644 index 0000000..8e4b5a6 --- /dev/null +++ b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include/usbd_core.h @@ -0,0 +1,186 @@ +/** + ************************************************************************** + * @file usbd_core.h + * @version v2.0.4 + * @date 2021-12-31 + * @brief usb device core header file + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ + +/* define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_CORE_H +#define __USBD_CORE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include "usb_conf.h" +#include "usb_std.h" + +/** @addtogroup AT32F435_437_middlewares_usbd_drivers + * @{ + */ + +/** @addtogroup USBD_drivers_core + * @{ + */ + +/** @defgroup USBD_core_exported_types + * @{ + */ + +#ifdef USE_OTG_DEVICE_MODE + +/** + * @brief usb device event + */ +typedef enum +{ + USBD_NOP_EVENT, /*!< usb device nop event */ + USBD_RESET_EVENT, /*!< usb device reset event */ + USBD_SUSPEND_EVENT, /*!< usb device suspend event */ + USBD_WAKEUP_EVENT, /*!< usb device wakeup event */ + USBD_DISCONNECT_EVNET, /*!< usb device disconnect event */ + USBD_INISOINCOM_EVENT, /*!< usb device inisoincom event */ + USBD_OUTISOINCOM_EVENT, /*!< usb device outisoincom event */ + USBD_ERR_EVENT /*!< usb device error event */ +}usbd_event_type; + +/** + * @brief usb device descriptor struct + */ +typedef struct +{ + uint16_t length; /*!< descriptor length */ + uint8_t *descriptor; /*!< descriptor string */ +}usbd_desc_t; + +/** + * @brief usb device descriptor handler + */ +typedef struct +{ + usbd_desc_t *(*get_device_descriptor)(void); /*!< get device descriptor callback */ + usbd_desc_t *(*get_device_qualifier)(void); /*!< get device qualifier callback */ + usbd_desc_t *(*get_device_configuration)(void); /*!< get device configuration callback */ + usbd_desc_t *(*get_device_other_speed)(void); /*!< get device other speed callback */ + usbd_desc_t *(*get_device_lang_id)(void); /*!< get device lang id callback */ + usbd_desc_t *(*get_device_manufacturer_string)(void); /*!< get device manufacturer callback */ + usbd_desc_t *(*get_device_product_string)(void); /*!< get device product callback */ + usbd_desc_t *(*get_device_serial_string)(void); /*!< get device serial callback */ + usbd_desc_t *(*get_device_interface_string)(void); /*!< get device interface string callback */ + usbd_desc_t *(*get_device_config_string)(void); /*!< get device device config callback */ +}usbd_desc_handler; + +/** + * @brief usb device class handler + */ +typedef struct +{ + usb_sts_type (*init_handler)(void *udev); /*!< usb class init handler */ + usb_sts_type (*clear_handler)(void *udev); /*!< usb class clear handler */ + usb_sts_type (*setup_handler)(void *udev, usb_setup_type *setup); /*!< usb class setup handler */ + usb_sts_type (*ept0_tx_handler)(void *udev); /*!< usb class endpoint 0 tx complete handler */ + usb_sts_type (*ept0_rx_handler)(void *udev); /*!< usb class endpoint 0 rx complete handler */ + usb_sts_type (*in_handler)(void *udev, uint8_t ept_num); /*!< usb class in transfer complete handler */ + usb_sts_type (*out_handler)(void *udev, uint8_t ept_num); /*!< usb class out transfer complete handler */ + usb_sts_type (*sof_handler)(void *udev); /*!< usb class sof handler */ + usb_sts_type (*event_handler)(void *udev, usbd_event_type event); /*!< usb class event handler */ +}usbd_class_handler; + +/** + * @brief usb device core struct type + */ +typedef struct +{ + usb_reg_type *usb_reg; /*!< usb register pointer */ + + usbd_class_handler *class_handler; /*!< usb device class handler pointer */ + usbd_desc_handler *desc_handler; /*!< usb device descriptor handler pointer */ + + usb_ept_info ept_in[USB_EPT_MAX_NUM]; /*!< usb in endpoint infomation struct */ + usb_ept_info ept_out[USB_EPT_MAX_NUM]; /*!< usb out endpoint infomation struct */ + + usb_setup_type setup; /*!< usb setup type struct */ + uint8_t setup_buffer[12]; /*!< usb setup request buffer */ + + uint8_t ept0_sts; /*!< usb control endpoint 0 state */ + uint8_t speed; /*!< usb speed */ + uint16_t ept0_wlength; /*!< usb endpoint 0 transfer length */ + + usbd_conn_state conn_state; /*!< usb current connect state */ + usbd_conn_state old_conn_state; /*!< usb save the previous connect state */ + + uint8_t device_addr; /*!< device address */ + uint8_t remote_wakup; /*!< remote wakeup state */ + uint8_t default_config; /*!< usb default config state */ + uint8_t dev_config; /*!< usb device config state */ + uint32_t config_status; /*!< usb configure status */ +}usbd_core_type; + +void usbd_core_in_handler(usbd_core_type *udev, uint8_t ept_num); +void usbd_core_out_handler(usbd_core_type *udev, uint8_t ept_num); +void usbd_core_setup_handler(usbd_core_type *udev, uint8_t ept_num); +void usbd_ctrl_unsupport(usbd_core_type *udev); +void usbd_ctrl_send(usbd_core_type *udev, uint8_t *buffer, uint16_t len); +void usbd_ctrl_recv(usbd_core_type *udev, uint8_t *buffer, uint16_t len); +void usbd_ctrl_send_status(usbd_core_type *udev); +void usbd_ctrl_recv_status(usbd_core_type *udev); +void usbd_set_stall(usbd_core_type *udev, uint8_t ept_addr); +void usbd_clear_stall(usbd_core_type *udev, uint8_t ept_addr); +void usbd_ept_open(usbd_core_type *udev, uint8_t ept_addr, uint8_t ept_type, uint16_t maxpacket); +void usbd_ept_close(usbd_core_type *udev, uint8_t ept_addr); +void usbd_ept_send(usbd_core_type *udev, uint8_t ept_num, uint8_t *buffer, uint16_t len); +void usbd_ept_recv(usbd_core_type *udev, uint8_t ept_num, uint8_t *buffer, uint16_t len); +void usbd_connect(usbd_core_type *udev); +void usbd_disconnect(usbd_core_type *udev); +void usbd_set_device_addr(usbd_core_type *udev, uint8_t address); +uint32_t usbd_get_recv_len(usbd_core_type *udev, uint8_t ept_addr); +void usb_ept_defaut_init(usbd_core_type *udev); +usbd_conn_state usbd_connect_state_get(usbd_core_type *udev); +void usbd_remote_wakeup(usbd_core_type *udev); +void usbd_enter_suspend(usbd_core_type *udev); +void usbd_flush_tx_fifo(usbd_core_type *udev, uint8_t ept_num); +void usbd_fifo_alloc(usbd_core_type *udev); +usb_sts_type usbd_core_init(usbd_core_type *udev, + usb_reg_type *usb_reg, + usbd_class_handler *class_handler, + usbd_desc_handler *desc_handler, + uint8_t core_id); +#endif + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ +#ifdef __cplusplus +} +#endif + +#endif diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include/usbd_int.h b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include/usbd_int.h new file mode 100644 index 0000000..e7748ef --- /dev/null +++ b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include/usbd_int.h @@ -0,0 +1,82 @@ +/** + ************************************************************************** + * @file usbd_int.h + * @version v2.0.4 + * @date 2021-12-31 + * @brief usb interrupt header file + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ + +/* define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USBD_INT_H +#define __USBD_INT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup AT32F435_437_middlewares_usbd_drivers + * @{ + */ + +/** @addtogroup USBD_drivers_int + * @{ + */ + +/** @defgroup USBD_interrupt_exported_types + * @{ + */ +/* includes ------------------------------------------------------------------*/ +#include "usbd_core.h" +#include "usb_core.h" + +void usbd_irq_handler(otg_core_type *udev); +void usbd_ept_handler(usbd_core_type *udev); +void usbd_reset_handler(usbd_core_type *udev); +void usbd_sof_handler(usbd_core_type *udev); +void usbd_suspend_handler(usbd_core_type *udev); +void usbd_wakeup_handler(usbd_core_type *udev); +void usbd_inept_handler(usbd_core_type *udev); +void usbd_outept_handler(usbd_core_type *udev); +void usbd_enumdone_handler(usbd_core_type *udev); +void usbd_rxflvl_handler(usbd_core_type *udev); +void usbd_incomisioin_handler(usbd_core_type *udev); +void usbd_discon_handler(usbd_core_type *udev); +void usbd_incomisoout_handler(usbd_core_type *udev); +void usb_write_empty_txfifo(usbd_core_type *udev, uint32_t ept_num); + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_def.h b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include/usbd_sdr.h similarity index 63% rename from .platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_def.h rename to .platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include/usbd_sdr.h index e9740ae..f9bc724 100644 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_def.h +++ b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include/usbd_sdr.h @@ -1,9 +1,9 @@ /** ************************************************************************** - * @file at32f435_437_def.h + * @file usb_sdr.h * @version v2.0.4 * @date 2021-12-31 - * @brief at32f435_437 macros header file + * @brief usb header file ************************************************************************** * Copyright notice & Disclaimer * @@ -24,44 +24,48 @@ ************************************************************************** */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AT32F435_437_DEF_H -#define __AT32F435_437_DEF_H +/* define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USB_SDR_H +#define __USB_SDR_H #ifdef __cplusplus extern "C" { #endif -/* gnu compiler */ -#if defined (__GNUC__) - #ifndef ALIGNED_HEAD - #define ALIGNED_HEAD - #endif - #ifndef ALIGNED_TAIL - #define ALIGNED_TAIL __attribute__ ((aligned (4))) - #endif -#endif -/* arm compiler */ -#if defined (__CC_ARM) - #ifndef ALIGNED_HEAD - #define ALIGNED_HEAD __align(4) - #endif - #ifndef ALIGNED_TAIL - #define ALIGNED_TAIL - #endif -#endif +/* includes ------------------------------------------------------------------*/ +#include "usb_conf.h" +#include "usb_core.h" +/** @addtogroup AT32F435_437_middlewares_usbd_drivers + * @{ + */ + +/** @addtogroup USBD_drivers_standard_request + * @{ + */ -/* iar compiler */ -#if defined (__ICCARM__) - #ifndef ALIGNED_HEAD - #define ALIGNED_HEAD - #endif - #ifndef ALIGNED_TAIL - #define ALIGNED_TAIL - #endif -#endif +/** @defgroup USBD_sdr_exported_functions + * @{ + */ + +void usbd_setup_request_parse(usb_setup_type *setup, uint8_t *buf); +usb_sts_type usbd_device_request(usbd_core_type *udev); +usb_sts_type usbd_interface_request(usbd_core_type *udev); +usb_sts_type usbd_endpoint_request(usbd_core_type *udev); + + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ #ifdef __cplusplus } #endif diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/library.properties b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/library.properties similarity index 90% rename from .platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/library.properties rename to .platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/library.properties index 8e4ec24..b6bab07 100644 --- a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/library.properties +++ b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/library.properties @@ -1,4 +1,4 @@ -name=AT32_USB-FS-Device_Driver +name=AT32F43x_USB-Device_Driver version=1.0.0 author=AT maintainer=AT diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/src/usb_core.c b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/src/usb_core.c new file mode 100644 index 0000000..e38e32e --- /dev/null +++ b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/src/usb_core.c @@ -0,0 +1,188 @@ +/** + ************************************************************************** + * @file usb_core.c + * @version v2.0.4 + * @date 2021-12-31 + * @brief usb driver + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ +#include "usb_core.h" + +/** @addtogroup AT32F435_437_middlewares_usb_drivers + * @{ + */ + +/** @defgroup USB_drivers_core + * @brief usb global drivers core + * @{ + */ + +/** @defgroup USB_core_private_functions + * @{ + */ + +usb_sts_type usb_core_config(otg_core_type *udev, uint8_t core_id); + +/** + * @brief usb core config + * @param otgdev: to the structure of otg_core_type + * @param core_id: usb core id number (USB_FULL_SPEED_CORE_ID) + * @retval usb_sts_type + */ +usb_sts_type usb_core_config(otg_core_type *otgdev, uint8_t core_id) +{ + /* set usb speed and core id */ + otgdev->cfg.speed = core_id; + otgdev->cfg.core_id = core_id; + + /* default sof out and vbus ignore */ + otgdev->cfg.sof_out = FALSE; + otgdev->cfg.vbusig = FALSE; + + /* set max size */ + otgdev->cfg.max_size = 64; + + /* set support number of channel and endpoint */ +#ifdef USE_OTG_HOST_MODE + otgdev->cfg.hc_num = USB_HOST_CHANNEL_NUM; +#endif +#ifdef USE_OTG_DEVICE_MODE + otgdev->cfg.ept_num = USB_EPT_MAX_NUM; +#endif + otgdev->cfg.fifo_size = OTG_FIFO_SIZE; + if(core_id == USB_FULL_SPEED_CORE_ID) + { + otgdev->cfg.phy_itface = 2; + } +#ifdef USB_SOF_OUTPUT_ENABLE + otgdev->cfg.sof_out = TRUE; +#endif + +#ifdef USB_VBUS_IGNORE + otgdev->cfg.vbusig = TRUE; +#endif + + return USB_OK; +} + +#ifdef USE_OTG_DEVICE_MODE +/** + * @brief usb device initialization + * @param otgdev: to the structure of otg_core_type + * @param core_id: usb core id number (USB_FULL_SPEED_CORE_ID) + * @param usb_id: select use OTG1 or OTG2 + * this parameter can be one of the following values: + * - USB_OTG1_ID + * - USB_OTG2_ID + * @param dev_handler: usb class callback handler + * @param desc_handler: device config callback handler + * @retval usb_sts_type + */ +usb_sts_type usbd_init(otg_core_type *otgdev, + uint8_t core_id, uint8_t usb_id, + usbd_class_handler *class_handler, + usbd_desc_handler *desc_handler) +{ + usb_sts_type usb_sts = USB_OK; + + /* select use OTG1 or OTG2 */ + otgdev->usb_reg = usb_global_select_core(usb_id); + + /* usb device core config */ + usb_core_config(otgdev, core_id); + + if(otgdev->cfg.sof_out) + { + otgdev->usb_reg->gccfg_bit.sofouten = TRUE; + } + + if(otgdev->cfg.vbusig) + { + otgdev->usb_reg->gccfg_bit.vbusig = TRUE; + } + + /* usb device core init */ + usbd_core_init(&(otgdev->dev), otgdev->usb_reg, + class_handler, + desc_handler, + core_id); + + return usb_sts; +} +#endif + +#ifdef USE_OTG_HOST_MODE + +/** + * @brief usb host initialization. + * @param otgdev: to the structure of otg_core_type + * @param core_id: usb core id number (USB_FULL_SPEED_CORE_ID) + * @param usb_id: select use OTG1 or OTG2 + * this parameter can be one of the following values: + * - USB_OTG1_ID + * - USB_OTG2_ID + * @param class_handler: usb class callback handler + * @param user_handler: user callback handler + * @retval usb_sts_type + */ +usb_sts_type usbh_init(otg_core_type *otgdev, + uint8_t core_id, uint8_t usb_id, + usbh_class_handler_type *class_handler, + usbh_user_handler_type *user_handler) +{ + usb_sts_type status = USB_OK; + + /* select use otg1 or otg2 */ + otgdev->usb_reg = usb_global_select_core(usb_id); + + /* usb core config */ + usb_core_config(otgdev, core_id); + + if(otgdev->cfg.sof_out) + { + otgdev->usb_reg->gccfg_bit.sofouten = TRUE; + } + + if(otgdev->cfg.vbusig) + { + otgdev->usb_reg->gccfg_bit.vbusig = TRUE; + } + + /* usb host core init */ + usbh_core_init(&otgdev->host, otgdev->usb_reg, + class_handler, + user_handler, + core_id); + + return status; +} +#endif + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/src/usbd_core.c b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/src/usbd_core.c new file mode 100644 index 0000000..cd73fa0 --- /dev/null +++ b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/src/usbd_core.c @@ -0,0 +1,876 @@ +/** + ************************************************************************** + * @file usbd_core.c + * @version v2.0.4 + * @date 2021-12-31 + * @brief usb device driver + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ + +#include "usb_core.h" +#include "usbd_core.h" +#include "usbd_sdr.h" + +/** @addtogroup AT32F435_437_middlewares_usbd_drivers + * @{ + */ + +/** @defgroup USBD_drivers_core + * @brief usb device drivers core + * @{ + */ + +/** @defgroup USBD_core_private_functions + * @{ + */ + +/** + * @brief usb core in transfer complete handler + * @param udev: to the structure of usbd_core_type + * @param ept_addr: endpoint number + * @retval none + */ +void usbd_core_in_handler(usbd_core_type *udev, uint8_t ept_addr) +{ + /* get endpoint info*/ + usb_ept_info *ept_info = &udev->ept_in[ept_addr & 0x7F]; + + if(ept_addr == 0) + { + if(udev->ept0_sts == USB_EPT0_DATA_IN) + { + if(ept_info->ept0_slen > ept_info->maxpacket) + { + ept_info->ept0_slen -= ept_info->maxpacket; + usbd_ept_send(udev, 0, ept_info->trans_buf, + MIN(ept_info->ept0_slen, ept_info->maxpacket)); + } + /* endpoint 0 */ + else if(ept_info->last_len == ept_info->maxpacket + && ept_info->ept0_slen <= udev->ept0_wlength) + { + ept_info->last_len = 0; + usbd_ept_send(udev, 0, 0, 0); + usbd_ept_recv(udev, ept_addr, 0, 0); + } + else + { + if(udev->class_handler->ept0_tx_handler != 0 && + udev->conn_state == USB_CONN_STATE_CONFIGURED) + { + udev->class_handler->ept0_tx_handler(udev); + } + usbd_ctrl_recv_status(udev); + } + } + } + else if(udev->class_handler->in_handler != 0 && + udev->conn_state == USB_CONN_STATE_CONFIGURED) + { + /* other user define endpoint */ + udev->class_handler->in_handler(udev, ept_addr); + } +} + +/** + * @brief usb core out transfer complete handler + * @param udev: to the structure of usbd_core_type + * @param ept_addr: endpoint number + * @retval none + */ +void usbd_core_out_handler(usbd_core_type *udev, uint8_t ept_addr) +{ + /* get endpoint info*/ + usb_ept_info *ept_info = &udev->ept_out[ept_addr & 0x7F]; + + if(ept_addr == 0) + { + /* endpoint 0 */ + if(udev->ept0_sts == USB_EPT0_DATA_OUT) + { + if(ept_info->ept0_slen > ept_info->maxpacket) + { + ept_info->ept0_slen -= ept_info->maxpacket; + usbd_ept_recv(udev, ept_addr, ept_info->trans_buf, + MIN(ept_info->ept0_slen, ept_info->maxpacket)); + } + else + { + if(udev->class_handler->ept0_rx_handler != 0) + { + udev->class_handler->ept0_rx_handler(udev); + } + usbd_ctrl_send_status(udev); + } + } + } + else if(udev->class_handler->out_handler != 0 && + udev->conn_state == USB_CONN_STATE_CONFIGURED) + { + /* other user define endpoint */ + udev->class_handler->out_handler(udev, ept_addr); + } +} + +/** + * @brief usb core setup transfer complete handler + * @param udev: to the structure of usbd_core_type + * @param ept_addr: endpoint number + * @retval none + */ +void usbd_core_setup_handler(usbd_core_type *udev, uint8_t ept_num) +{ + /* setup parse */ + usbd_setup_request_parse(&udev->setup, udev->setup_buffer); + + /* set ept0 status */ + udev->ept0_sts = USB_EPT0_SETUP; + udev->ept0_wlength = udev->setup.wLength; + + switch(udev->setup.bmRequestType & USB_REQ_RECIPIENT_MASK) + { + case USB_REQ_RECIPIENT_DEVICE: + /* recipient device request */ + usbd_device_request(udev); + break; + case USB_REQ_RECIPIENT_INTERFACE: + /* recipient interface request */ + usbd_interface_request(udev); + break; + case USB_REQ_RECIPIENT_ENDPOINT: + /* recipient endpoint request */ + usbd_endpoint_request(udev); + break; + default: + break; + } +} + +/** + * @brief usb control endpoint send data + * @param udev: to the structure of usbd_core_type + * @param ept_addr: endpoint number + * @param buffer: send data buffer + * @param len: send data length + * @retval none + */ +void usbd_ctrl_send(usbd_core_type *udev, uint8_t *buffer, uint16_t len) +{ + usb_ept_info *ept_info = &udev->ept_in[0]; + + ept_info->ept0_slen = len; + udev->ept0_sts = USB_EPT0_DATA_IN; + + usbd_ept_send(udev, 0, buffer, len); +} + +/** + * @brief usb control endpoint recv data + * @param udev: to the structure of usbd_core_type + * @param ept_addr: endpoint number + * @param buffer: recv data buffer + * @param len: recv data length + * @retval none + */ +void usbd_ctrl_recv(usbd_core_type *udev, uint8_t *buffer, uint16_t len) +{ + usb_ept_info *ept_info = &udev->ept_out[0]; + + ept_info->ept0_slen = len; + udev->ept0_sts = USB_EPT0_DATA_OUT; + + usbd_ept_recv(udev, 0, buffer, len); +} + +/** + * @brief usb control endpoint send in status + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_ctrl_send_status(usbd_core_type *udev) +{ + udev->ept0_sts = USB_EPT0_STATUS_IN; + + usbd_ept_send(udev, 0, 0, 0); +} + +/** + * @brief usb control endpoint send out status + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_ctrl_recv_status(usbd_core_type *udev) +{ + udev->ept0_sts = USB_EPT0_STATUS_OUT; + + usbd_ept_recv(udev, 0, 0, 0); +} + +/** + * @brief clear endpoint stall + * @param udev: to the structure of usbd_core_type + * @param ept_addr: endpoint number + * @retval none + */ +void usbd_clear_stall(usbd_core_type *udev, uint8_t ept_addr) +{ + usb_ept_info *ept_info; + usb_reg_type *usbx = udev->usb_reg; + + if(ept_addr & 0x80) + { + /* in endpoint */ + ept_info = &udev->ept_in[ept_addr & 0x7F]; + } + else + { + /* out endpoint */ + ept_info = &udev->ept_out[ept_addr & 0x7F]; + } + usb_ept_clear_stall(usbx, ept_info); + ept_info->stall = 0; +} + +/** + * @brief usb set endpoint to stall status + * @param udev: to the structure of usbd_core_type + * @param ept_addr: endpoint number + * @retval none + */ +void usbd_set_stall(usbd_core_type *udev, uint8_t ept_addr) +{ + usb_ept_info *ept_info; + usb_reg_type *usbx = udev->usb_reg; + + if(ept_addr & 0x80) + { + /* in endpoint */ + ept_info = &udev->ept_in[ept_addr & 0x7F]; + } + else + { + /* out endpoint */ + ept_info = &udev->ept_out[ept_addr & 0x7F]; + } + usb_ept_stall(usbx, ept_info); + + ept_info->stall = 1; +} + +/** + * @brief un-support device request + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_ctrl_unsupport(usbd_core_type *udev) +{ + /* return stall status */ + usbd_set_stall(udev, 0x00); + usbd_set_stall(udev, 0x80); +} + +/** + * @brief get endpoint receive data length + * @param udev: to the structure of usbd_core_type + * @param ept_addr: endpoint number + * @retval data receive len + */ +uint32_t usbd_get_recv_len(usbd_core_type *udev, uint8_t ept_addr) +{ + usb_ept_info *ept = &udev->ept_out[ept_addr & 0x7F]; + return ept->trans_len; +} + +/** + * @brief usb open endpoint + * @param udev: to the structure of usbd_core_type + * @param ept_addr: endpoint number + * @param ept_type: endpoint type + * @param maxpacket: endpoint support max buffer size + * @retval none + */ +void usbd_ept_open(usbd_core_type *udev, uint8_t ept_addr, uint8_t ept_type, uint16_t maxpacket) +{ + usb_reg_type *usbx = udev->usb_reg; + usb_ept_info *ept_info; + + if((ept_addr & 0x80) == 0) + { + /* out endpoint info */ + ept_info = &udev->ept_out[ept_addr & 0x7F]; + ept_info->inout = EPT_DIR_OUT; + } + else + { + /* in endpoint info */ + ept_info = &udev->ept_in[ept_addr & 0x7F]; + ept_info->inout = EPT_DIR_IN; + } + + /* set endpoint maxpacket and type */ + ept_info->maxpacket = maxpacket; + ept_info->trans_type = ept_type; + + /* open endpoint */ + usb_ept_open(usbx, ept_info); +} + +/** + * @brief usb close endpoint + * @param udev: to the structure of usbd_core_type + * @param ept_addr: endpoint number + * @retval none + */ +void usbd_ept_close(usbd_core_type *udev, uint8_t ept_addr) +{ + usb_ept_info *ept_info; + if(ept_addr & 0x80) + { + /* in endpoint */ + ept_info = &udev->ept_in[ept_addr & 0x7F]; + } + else + { + /* out endpoint */ + ept_info = &udev->ept_out[ept_addr & 0x7F]; + } + + /* close endpoint */ + usb_ept_close(udev->usb_reg, ept_info); +} + +/** + * @brief usb device connect to host + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_connect(usbd_core_type *udev) +{ + usb_connect(udev->usb_reg); +} + +/** + * @brief usb device disconnect to host + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_disconnect(usbd_core_type *udev) +{ + usb_disconnect(udev->usb_reg); +} + +/** + * @brief usb device set device address. + * @param udev: to the structure of usbd_core_type + * @param address: host assignment address + * @retval none + */ +void usbd_set_device_addr(usbd_core_type *udev, uint8_t address) +{ + usb_set_address(udev->usb_reg, address); +} + +/** + * @brief usb endpoint structure initialization + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usb_ept_default_init(usbd_core_type *udev) +{ + uint8_t i_index = 0; + /* init in endpoint info structure */ + for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) + { + udev->ept_in[i_index].eptn = i_index; + udev->ept_in[i_index].ept_address = i_index; + udev->ept_in[i_index].inout = EPT_DIR_IN; + udev->ept_in[i_index].maxpacket = 0; + udev->ept_in[i_index].trans_buf = 0; + udev->ept_in[i_index].total_len = 0; + } + + /* init out endpoint info structure */ + for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) + { + udev->ept_out[i_index].eptn = i_index; + udev->ept_out[i_index].ept_address = i_index; + udev->ept_out[i_index].inout = EPT_DIR_OUT; + udev->ept_out[i_index].maxpacket = 0; + udev->ept_out[i_index].trans_buf = 0; + udev->ept_out[i_index].total_len = 0; + } +} + +/** + * @brief endpoint send data + * @param udev: to the structure of usbd_core_type + * @param ept_addr: endpoint number + * @param buffer: send data buffer + * @param len: send data length + * @retval none + */ +void usbd_ept_send(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint16_t len) +{ + /* get endpoint info struct and register */ + usb_reg_type *usbx = udev->usb_reg; + usb_ept_info *ept_info = &udev->ept_in[ept_addr & 0x7F]; + otg_eptin_type *ept_in = USB_INEPT(usbx, ept_info->eptn); + otg_device_type *dev = OTG_DEVICE(usbx); + uint32_t pktcnt; + + /* set send data buffer and length */ + ept_info->trans_buf = buffer; + ept_info->total_len = len; + ept_info->trans_len = 0; + + /* transfer data len is zero */ + if(ept_info->total_len == 0) + { + ept_in->dieptsiz_bit.pktcnt = 1; + ept_in->dieptsiz_bit.xfersize = 0; + } + else + { + if((ept_addr & 0x7F) == 0) // endpoint 0 + { + /* endpoint 0 */ + if(ept_info->total_len > ept_info->maxpacket) + { + ept_info->total_len = ept_info->maxpacket; + } + + /* set transfer size */ + ept_in->dieptsiz_bit.xfersize = ept_info->total_len; + + /* set packet count */ + ept_in->dieptsiz_bit.pktcnt = 1; + + ept_info->last_len = ept_info->total_len; + } + else + { + /* other endpoint */ + + /* packet count */ + pktcnt = (ept_info->total_len + ept_info->maxpacket - 1) / ept_info->maxpacket; + + /* set transfer size */ + ept_in->dieptsiz_bit.xfersize = ept_info->total_len; + + /* set packet count */ + ept_in->dieptsiz_bit.pktcnt = pktcnt; + + if(ept_info->trans_type == EPT_ISO_TYPE) + { + ept_in->dieptsiz_bit.mc = 1; + } + } + } + + if(ept_info->trans_type != EPT_ISO_TYPE) + { + if(ept_info->total_len > 0) + { + /* set in endpoint tx fifo empty interrupt mask */ + dev->diepempmsk |= 1 << ept_info->eptn; + } + } + + if(ept_info->trans_type == EPT_ISO_TYPE) + { + if((dev->dsts_bit.soffn & 0x1) == 0) + { + ept_in->diepctl_bit.setd1pid = TRUE; + } + else + { + ept_in->diepctl_bit.setd0pid = TRUE; + } + } + + /* clear endpoint nak */ + ept_in->diepctl_bit.cnak = TRUE; + + /* endpoint enable */ + ept_in->diepctl_bit.eptena = TRUE; + + if(ept_info->trans_type == EPT_ISO_TYPE) + { + /* write data to fifo */ + usb_write_packet(usbx, ept_info->trans_buf, ept_info->eptn, ept_info->total_len); + } +} + +/** + * @brief endpoint receive data + * @param udev: to the structure of usbd_core_type + * @param ept_addr: endpoint number + * @param buffer: receive data buffer + * @param len: receive data length + * @retval none + */ +void usbd_ept_recv(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint16_t len) +{ + /* get endpoint info struct and register */ + usb_reg_type *usbx = udev->usb_reg; + usb_ept_info *ept_info = &udev->ept_out[ept_addr & 0x7F]; + otg_eptout_type *ept_out = USB_OUTEPT(usbx, ept_info->eptn); + otg_device_type *dev = OTG_DEVICE(usbx); + uint32_t pktcnt; + + /* set receive data buffer and length */ + ept_info->trans_buf = buffer; + ept_info->total_len = len; + ept_info->trans_len = 0; + + if((ept_addr & 0x7F) == 0) + { + /* endpoint 0 */ + ept_info->total_len = ept_info->maxpacket; + } + + if(ept_info->total_len == 0 || ((ept_addr & 0x7F) == 0)) + { + /* set transfer size */ + ept_out->doeptsiz_bit.xfersize = ept_info->maxpacket; + + /* set packet count */ + ept_out->doeptsiz_bit.pktcnt = 1; + } + else + { + pktcnt = (ept_info->total_len + ept_info->maxpacket - 1) / ept_info->maxpacket; + + /* set transfer size */ + ept_out->doeptsiz_bit.xfersize = ept_info->maxpacket * pktcnt; + + /* set packet count */ + ept_out->doeptsiz_bit.pktcnt = pktcnt; + } + + if(ept_info->trans_type == EPT_ISO_TYPE) + { + if((dev->dsts_bit.soffn & 0x01) == 0) + { + ept_out->doepctl_bit.setd1pid = TRUE; + } + else + { + ept_out->doepctl_bit.setd0pid = TRUE; + } + } + + /* clear endpoint nak */ + ept_out->doepctl_bit.cnak = TRUE; + + /* endpoint enable */ + ept_out->doepctl_bit.eptena = TRUE; +} + +/** + * @brief get usb connect state + * @param udev: to the structure of usbd_core_type + * @retval usb connect state + */ +usbd_conn_state usbd_connect_state_get(usbd_core_type *udev) +{ + return udev->conn_state; +} + +/** + * @brief usb device remote wakeup + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_remote_wakeup(usbd_core_type *udev) +{ + /* check device is in suspend mode */ + if(usb_suspend_status_get(udev->usb_reg) == 1) + { + /* set connect state */ + udev->conn_state = udev->old_conn_state; + + /* open phy clock */ + usb_open_phy_clk(udev->usb_reg); + + /* set remote wakeup */ + usb_remote_wkup_set(udev->usb_reg); + + /* delay 10 ms */ + usb_delay_ms(10); + + /* clear remote wakup */ + usb_remote_wkup_clear(udev->usb_reg); + } +} + +/** + * @brief usb device enter suspend mode + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_enter_suspend(usbd_core_type *udev) +{ + /* check device is in suspend mode */ + if(usb_suspend_status_get(udev->usb_reg) == 1) + { + /* stop phy clk */ + usb_stop_phy_clk(udev->usb_reg); + } +} + +/** + * @brief usb device flush in endpoint fifo + * @param udev: to the structure of usbd_core_type + * @param ept_num: endpoint number + * @retval none + */ +void usbd_flush_tx_fifo(usbd_core_type *udev, uint8_t ept_num) +{ + /* flush endpoint tx fifo */ + usb_flush_tx_fifo(udev->usb_reg, ept_num & 0x1F); +} + +/** + * @brief usb device endpoint fifo alloc + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_fifo_alloc(usbd_core_type *udev) +{ + usb_reg_type *usbx = udev->usb_reg; + + if(usbx == OTG1_GLOBAL) + { + /* set receive fifo size */ + usb_set_rx_fifo(usbx, USBD_RX_SIZE); + + /* set endpoint0 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT0, USBD_EP0_TX_SIZE); + + /* set endpoint1 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT1, USBD_EP1_TX_SIZE); + + /* set endpoint2 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT2, USBD_EP2_TX_SIZE); + + /* set endpoint3 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT3, USBD_EP3_TX_SIZE); + + if(USB_EPT_MAX_NUM == 8) + { + /* set endpoint4 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT4, USBD_EP4_TX_SIZE); + + /* set endpoint5 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT5, USBD_EP5_TX_SIZE); + + /* set endpoint6 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT6, USBD_EP6_TX_SIZE); + + /* set endpoint7 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT7, USBD_EP7_TX_SIZE); + } + } +#ifdef OTG2_GLOBAL + if(usbx == OTG2_GLOBAL) + { + /* set receive fifo size */ + usb_set_rx_fifo(usbx, USBD2_RX_SIZE); + + /* set endpoint0 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT0, USBD2_EP0_TX_SIZE); + + /* set endpoint1 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT1, USBD2_EP1_TX_SIZE); + + /* set endpoint2 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT2, USBD2_EP2_TX_SIZE); + + /* set endpoint3 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT3, USBD2_EP3_TX_SIZE); + + if(USB_EPT_MAX_NUM == 8) + { + /* set endpoint4 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT4, USBD2_EP4_TX_SIZE); + + /* set endpoint5 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT5, USBD2_EP5_TX_SIZE); + + /* set endpoint6 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT6, USBD2_EP6_TX_SIZE); + + /* set endpoint7 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT7, USBD2_EP7_TX_SIZE); + } + } +#endif +} + +/** + * @brief usb device core initialization + * @param udev: to the structure of usbd_core_type + * @param usb_reg: usb otgfs peripheral global register + * this parameter can be one of the following values: + * OTG1_GLOBAL , OTG2_GLOBAL + * @param class_handler: usb class handler + * @param desc_handler: device config handler + * @param core_id: usb core id number + * @retval usb_sts_type + */ +usb_sts_type usbd_core_init(usbd_core_type *udev, + usb_reg_type *usb_reg, + usbd_class_handler *class_handler, + usbd_desc_handler *desc_handler, + uint8_t core_id) +{ + usb_reg_type *usbx; + otg_device_type *dev; + otg_eptin_type *ept_in; + otg_eptout_type *ept_out; + uint32_t i_index; + + udev->usb_reg = usb_reg; + usbx = usb_reg; + dev = OTG_DEVICE(usbx); + + /* set connect state */ + udev->conn_state = USB_CONN_STATE_DEFAULT; + + /* device class config */ + udev->device_addr = 0; + udev->class_handler = class_handler; + udev->desc_handler = desc_handler; + /* set device disconnect */ + usbd_disconnect(udev); + + /* set endpoint to default status */ + usb_ept_default_init(udev); + + /* disable usb global interrupt */ + usb_interrupt_disable(usbx); + + /* init global register */ + usb_global_init(usbx); + + /* set device mode */ + usb_global_set_mode(usbx, OTG_DEVICE_MODE); + + /* open phy clock */ + usb_open_phy_clk(udev->usb_reg); + + /* set periodic frame interval */ + dev->dcfg_bit.perfrint = DCFG_PERFRINT_80; + + /* set device speed to full-speed */ + dev->dcfg_bit.devspd = USB_DCFG_FULL_SPEED; + + /* flush all tx fifo */ + usb_flush_tx_fifo(usbx, 16); + + /* flush share rx fifo */ + usb_flush_rx_fifo(usbx); + + /* clear all endpoint interrupt flag and mask */ + dev->daint = 0xFFFFFFFF; + dev->daintmsk = 0; + dev->diepmsk = 0; + dev->doepmsk = 0; + + for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) + { + usbx->dieptxfn[i_index] = 0; + } + + /* endpoint fifo alloc */ + usbd_fifo_alloc(udev); + + /* disable all in endpoint */ + for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) + { + ept_in = USB_INEPT(usbx, i_index); + if(ept_in->diepctl_bit.eptena) + { + ept_in->diepctl = 0; + ept_in->diepctl_bit.eptdis = TRUE; + ept_in->diepctl_bit.snak = TRUE; + } + else + { + ept_in->diepctl = 0; + } + ept_in->dieptsiz = 0; + ept_in->diepint = 0xFF; + } + + /* disable all out endpoint */ + for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) + { + ept_out = USB_OUTEPT(usbx, i_index); + if(ept_out->doepctl_bit.eptena) + { + ept_out->doepctl = 0; + ept_out->doepctl_bit.eptdis = TRUE; + ept_out->doepctl_bit.snak = TRUE; + } + else + { + ept_out->doepctl = 0; + } + ept_out->doeptsiz = 0; + ept_out->doepint = 0xFF; + } + dev->diepmsk_bit.txfifoudrmsk = TRUE; + + /* clear global interrupt and mask */ + usbx->gintmsk = 0; + usbx->gintsts = 0xBFFFFFFF; + + /* enable global interrupt mask */ + usbx->gintmsk = USB_OTG_SOF_INT | USB_OTG_RXFLVL_INT | + USB_OTG_USBSUSP_INT | USB_OTG_USBRST_INT | + USB_OTG_ENUMDONE_INT | USB_OTG_IEPT_INT | + USB_OTG_OEPT_INT | USB_OTG_INCOMISOIN_INT | + USB_OTG_INCOMPIP_INCOMPISOOUT_INT | USB_OTG_WKUP_INT | + USB_OTG_OTGINT_INT; + + /* usb connect */ + usbd_connect(udev); + + /* enable global interrupt */ + usb_interrupt_enable(usbx); + + return USB_OK; + +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/src/usbd_int.c b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/src/usbd_int.c new file mode 100644 index 0000000..0f73392 --- /dev/null +++ b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/src/usbd_int.c @@ -0,0 +1,538 @@ +/** + ************************************************************************** + * @file usbd_int.c + * @version v2.0.4 + * @date 2021-12-31 + * @brief usb interrupt request + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ +#include "usbd_int.h" + +/** @addtogroup AT32F435_437_middlewares_usbd_drivers + * @{ + */ + +/** @defgroup USBD_drivers_interrupt + * @brief usb device interrupt + * @{ + */ + +/** @defgroup USBD_int_private_functions + * @{ + */ + +/** + * @brief usb device interrput request handler. + * @param otgdev: to the structure of otg_core_type + * @retval none + */ +void usbd_irq_handler(otg_core_type *otgdev) +{ + otg_global_type *usbx = otgdev->usb_reg; + usbd_core_type *udev = &otgdev->dev; + uint32_t intsts = usb_global_get_all_interrupt(usbx); + + /* check current device mode */ + if(usbx->gintsts_bit.curmode == 0) + { + /* mode mismatch interrupt */ + if(intsts & USB_OTG_MODEMIS_FLAG) + { + usb_global_clear_interrupt(usbx, USB_OTG_MODEMIS_FLAG); + } + + /* in endpoint interrupt */ + if(intsts & USB_OTG_IEPT_FLAG) + { + usbd_inept_handler(udev); + } + + /* out endpoint interrupt */ + if(intsts & USB_OTG_OEPT_FLAG) + { + usbd_outept_handler(udev); + } + + /* usb reset interrupt */ + if(intsts & USB_OTG_USBRST_FLAG) + { + usbd_reset_handler(udev); + usb_global_clear_interrupt(usbx, USB_OTG_USBRST_FLAG); + } + + /* sof interrupt */ + if(intsts & USB_OTG_SOF_FLAG) + { + usbd_sof_handler(udev); + usb_global_clear_interrupt(usbx, USB_OTG_SOF_FLAG); + } + + /* enumeration done interrupt */ + if(intsts & USB_OTG_ENUMDONE_FLAG) + { + usbd_enumdone_handler(udev); + usb_global_clear_interrupt(usbx, USB_OTG_ENUMDONE_FLAG); + } + + /* rx non-empty interrupt, indicates that there is at least one + data packet pending to be read in rx fifo */ + if(intsts & USB_OTG_RXFLVL_FLAG) + { + usbd_rxflvl_handler(udev); + } + + /* incomplete isochronous in transfer interrupt */ + if(intsts & USB_OTG_INCOMISOIN_FLAG) + { + usbd_incomisioin_handler(udev); + usb_global_clear_interrupt(usbx, USB_OTG_INCOMISOIN_FLAG); + } + #ifndef USB_VBUS_IGNORE + /* disconnect detected interrupt */ + if(intsts & USB_OTG_OTGINT_FLAG) + { + uint32_t tmp = udev->usb_reg->gotgint; + if(udev->usb_reg->gotgint_bit.sesenddet) + usbd_discon_handler(udev); + udev->usb_reg->gotgint = tmp; + usb_global_clear_interrupt(usbx, USB_OTG_OTGINT_FLAG); + } +#endif + /* incomplete isochronous out transfer interrupt */ + if(intsts & USB_OTG_INCOMPIP_INCOMPISOOUT_FLAG) + { + usbd_incomisoout_handler(udev); + usb_global_clear_interrupt(usbx, USB_OTG_INCOMPIP_INCOMPISOOUT_FLAG); + } + + /* resume/remote wakeup interrupt */ + if(intsts & USB_OTG_WKUP_FLAG) + { + usbd_wakeup_handler(udev); + usb_global_clear_interrupt(usbx, USB_OTG_WKUP_FLAG); + } + + /* usb suspend interrupt */ + if(intsts & USB_OTG_USBSUSP_FLAG) + { + usbd_suspend_handler(udev); + usb_global_clear_interrupt(usbx, USB_OTG_USBSUSP_FLAG); + } + } +} + +/** + * @brief usb write tx fifo. + * @param udev: to the structure of usbd_core_type + * @param ept_num: endpoint number + * @retval none + */ +void usb_write_empty_txfifo(usbd_core_type *udev, uint32_t ept_num) +{ + otg_global_type *usbx = udev->usb_reg; + usb_ept_info *ept_info = &udev->ept_in[ept_num]; + uint32_t length = ept_info->total_len - ept_info->trans_len; + uint32_t wlen = 0; + + if(length > ept_info->maxpacket) + { + length = ept_info->maxpacket; + } + wlen = (length + 3) / 4; + + while((USB_INEPT(usbx, ept_num)->dtxfsts & USB_OTG_DTXFSTS_INEPTFSAV) > wlen && + (ept_info->trans_len < ept_info->total_len) && (ept_info->total_len != 0)) + { + length = ept_info->total_len - ept_info->trans_len; + if(length > ept_info->maxpacket) + { + length = ept_info->maxpacket; + } + wlen = (length + 3) / 4; + usb_write_packet(usbx, ept_info->trans_buf, ept_num, length); + + ept_info->trans_buf += length; + ept_info->trans_len += length; + + } + if(length <= 0) + { + OTG_DEVICE(usbx)->diepempmsk &= ~(0x1 << ept_num); + } +} + + +/** + * @brief usb in endpoint handler + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_inept_handler(usbd_core_type *udev) +{ + otg_global_type *usbx = udev->usb_reg; + uint32_t ept_num = 0, ept_int; + uint32_t intsts; + + /*get all endpoint interrut */ + intsts = usb_get_all_in_interrupt(usbx); + while(intsts) + { + if(intsts & 0x1) + { + /* get endpoint interrupt flag */ + ept_int = usb_ept_in_interrupt(usbx, ept_num); + + /* transfer completed interrupt */ + if(ept_int & USB_OTG_DIEPINT_XFERC_FLAG) + { + OTG_DEVICE(usbx)->diepempmsk &= ~(1 << ept_num); + usb_ept_in_clear(usbx, ept_num , USB_OTG_DIEPINT_XFERC_FLAG); + usbd_core_in_handler(udev, ept_num); + } + + /* timeout condition interrupt */ + if(ept_int & USB_OTG_DIEPINT_TIMEOUT_FLAG) + { + usb_ept_in_clear(usbx, ept_num , USB_OTG_DIEPINT_TIMEOUT_FLAG); + } + + /* in token received when tx fifo is empty */ + if(ept_int & USB_OTG_DIEPINT_INTKNTXFEMP_FLAG) + { + usb_ept_in_clear(usbx, ept_num , USB_OTG_DIEPINT_INTKNTXFEMP_FLAG); + } + + /* in endpoint nak effective */ + if(ept_int & USB_OTG_DIEPINT_INEPTNAK_FLAG) + { + usb_ept_in_clear(usbx, ept_num , USB_OTG_DIEPINT_INEPTNAK_FLAG); + } + + /* endpoint disable interrupt */ + if(ept_int & USB_OTG_DIEPINT_EPTDISD_FLAG) + { + usb_ept_in_clear(usbx, ept_num , USB_OTG_DIEPINT_EPTDISD_FLAG); + } + + /* transmit fifo empty interrupt */ + if(ept_int & USB_OTG_DIEPINT_TXFEMP_FLAG) + { + usb_write_empty_txfifo(udev, ept_num); + } + } + ept_num ++; + intsts >>= 1; + } +} + +/** + * @brief usb out endpoint handler + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_outept_handler(usbd_core_type *udev) +{ + otg_global_type *usbx = udev->usb_reg; + uint32_t ept_num = 0, ept_int; + uint32_t intsts; + + /* get all out endpoint interrupt */ + intsts = usb_get_all_out_interrupt(usbx); + + while(intsts) + { + if(intsts & 0x1) + { + /* get out endpoint interrupt */ + ept_int = usb_ept_out_interrupt(usbx, ept_num); + + /* transfer completed interrupt */ + if(ept_int & USB_OTG_DOEPINT_XFERC_FLAG) + { + usb_ept_out_clear(usbx, ept_num , USB_OTG_DOEPINT_XFERC_FLAG); + usbd_core_out_handler(udev, ept_num); + } + + /* setup phase done interrupt */ + if(ept_int & USB_OTG_DOEPINT_SETUP_FLAG) + { + usb_ept_out_clear(usbx, ept_num , USB_OTG_DOEPINT_SETUP_FLAG); + usbd_core_setup_handler(udev, ept_num); + if(udev->device_addr != 0) + { + OTG_DEVICE(udev->usb_reg)->dcfg_bit.devaddr = udev->device_addr; + udev->device_addr = 0; + } + } + + /* endpoint disable interrupt */ + if(ept_int & USB_OTG_DOEPINT_OUTTEPD_FLAG) + { + usb_ept_out_clear(usbx, ept_num , USB_OTG_DOEPINT_OUTTEPD_FLAG); + } + } + ept_num ++; + intsts >>= 1; + } +} + +/** + * @brief usb enumeration done handler + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_enumdone_handler(usbd_core_type *udev) +{ + otg_global_type *usbx = udev->usb_reg; + + usb_ept0_setup(usbx); + + usbx->gusbcfg_bit.usbtrdtim = USB_TRDTIM_16; + + /* open endpoint 0 out */ + usbd_ept_open(udev, 0x00, EPT_CONTROL_TYPE, 0x40); + + /* open endpoint 0 in */ + usbd_ept_open(udev, 0x80, EPT_CONTROL_TYPE, 0x40); + + /* usb connect state set to default */ + udev->conn_state = USB_CONN_STATE_DEFAULT; + + /* clear callback */ + if(udev->class_handler->clear_handler != 0) + udev->class_handler->clear_handler(udev); +} + +/** + * @brief usb rx non-empty handler + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_rxflvl_handler(usbd_core_type *udev) +{ + otg_global_type *usbx = udev->usb_reg; + uint32_t stsp; + uint32_t count; + uint32_t pktsts; + usb_ept_info *ept_info; + + /* disable rxflvl interrupt */ + usb_global_interrupt_enable(usbx, USB_OTG_RXFLVL_INT, FALSE); + + /* get rx status */ + stsp = usbx->grxstsp; + + /*get the byte count of receive */ + count = (stsp & USB_OTG_GRXSTSP_BCNT) >> 4; + + /* get packet status */ + pktsts = (stsp &USB_OTG_GRXSTSP_PKTSTS) >> 17; + + /* get endpoint infomation struct */ + ept_info = &udev->ept_out[stsp & USB_OTG_GRXSTSP_EPTNUM]; + + /* received out data packet */ + if(pktsts == USB_OUT_STS_DATA) + { + if(count != 0) + { + /* read packet to buffer */ + usb_read_packet(usbx, ept_info->trans_buf, (stsp & USB_OTG_GRXSTSP_EPTNUM), count); + ept_info->trans_buf += count; + ept_info->trans_len += count; + + } + } + /* setup data received */ + else if ( pktsts == USB_SETUP_STS_DATA) + { + /* read packet to buffer */ + usb_read_packet(usbx, udev->setup_buffer, (stsp & USB_OTG_GRXSTSP_EPTNUM), count); + ept_info->trans_len += count; + } + + /* enable rxflvl interrupt */ + usb_global_interrupt_enable(usbx, USB_OTG_RXFLVL_INT, TRUE); + +} + +/** + * @brief usb disconnect handler + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_discon_handler(usbd_core_type *udev) +{ + /* disconnect callback handler */ + if(udev->class_handler->event_handler != 0) + udev->class_handler->event_handler(udev, USBD_DISCONNECT_EVNET); +} + + +/** + * @brief usb incomplete out handler + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_incomisoout_handler(usbd_core_type *udev) +{ + if(udev->class_handler->event_handler != 0) + udev->class_handler->event_handler(udev, USBD_OUTISOINCOM_EVENT); +} + +/** + * @brief usb incomplete in handler + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_incomisioin_handler(usbd_core_type *udev) +{ + if(udev->class_handler->event_handler != 0) + udev->class_handler->event_handler(udev, USBD_INISOINCOM_EVENT); +} + +/** + * @brief usb device reset interrupt request handler. + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_reset_handler(usbd_core_type *udev) +{ + otg_global_type *usbx = udev->usb_reg; + otg_device_type *dev = OTG_DEVICE(usbx); + uint32_t i_index = 0; + + /* disable remote wakeup singal */ + dev->dctl_bit.rwkupsig = FALSE; + + /* endpoint fifo alloc */ + usbd_fifo_alloc(udev); + + /* flush all tx fifo */ + usb_flush_tx_fifo(usbx, 0x10); + + /* clear in and out endpoint interrupt flag */ + for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) + { + USB_INEPT(usbx, i_index)->diepint = 0xFF; + USB_OUTEPT(usbx, i_index)->doepint = 0xFF; + } + + /* clear endpoint flag */ + dev->daint = 0xFFFFFFFF; + + /*clear endpoint interrupt mask */ + dev->daintmsk = 0x10001; + + /* enable out endpoint xfer, eptdis, setup interrupt mask */ + dev->doepmsk_bit.xfercmsk = TRUE; + dev->doepmsk_bit.eptdismsk = TRUE; + dev->doepmsk_bit.setupmsk = TRUE; + + /* enable in endpoint xfer, eptdis, timeout interrupt mask */ + dev->diepmsk_bit.xfercmsk = TRUE; + dev->diepmsk_bit.eptdismsk = TRUE; + dev->diepmsk_bit.timeoutmsk = TRUE; + + /* set device address to 0 */ + usb_set_address(usbx, 0); + + /* enable endpoint 0 */ + usb_ept0_start(usbx); + + /* usb connect state set to default */ + udev->conn_state = USB_CONN_STATE_DEFAULT; + + /* user define reset event */ + if(udev->class_handler->event_handler) + udev->class_handler->event_handler(udev, USBD_RESET_EVENT); +} + +/** + * @brief usb device sof interrupt request handler. + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_sof_handler(usbd_core_type *udev) +{ + /* user sof handler in class define */ + if(udev->class_handler->sof_handler) + udev->class_handler->sof_handler(udev); +} + +/** + * @brief usb device suspend interrupt request handler. + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_suspend_handler(usbd_core_type *udev) +{ + otg_global_type *usbx = udev->usb_reg; + + if(OTG_DEVICE(usbx)->dsts_bit.suspsts) + { + /* save connect state */ + udev->old_conn_state = udev->conn_state; + + /* set current state to suspend */ + udev->conn_state = USB_CONN_STATE_SUSPENDED; + + /* enter suspend mode */ + usbd_enter_suspend(udev); + + /* user suspend handler */ + if(udev->class_handler->event_handler != 0) + udev->class_handler->event_handler(udev, USBD_SUSPEND_EVENT); + } +} + +/** + * @brief usb device wakup interrupt request handler. + * @param udev: to the structure of usbd_core_type + * @retval none + */ +void usbd_wakeup_handler(usbd_core_type *udev) +{ + otg_global_type *usbx = udev->usb_reg; + + /* clear remote wakeup bit */ + OTG_DEVICE(usbx)->dctl_bit.rwkupsig = FALSE; + + /* exit suspend mode */ + usb_open_phy_clk(udev->usb_reg); + + /* restore connect state */ + udev->conn_state = udev->old_conn_state; + + /* user suspend handler */ + if(udev->class_handler->event_handler != 0) + udev->class_handler->event_handler(udev, USBD_WAKEUP_EVENT); +} +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/src/usbd_sdr.c b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/src/usbd_sdr.c new file mode 100644 index 0000000..0d0edfd --- /dev/null +++ b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/src/usbd_sdr.c @@ -0,0 +1,534 @@ +/** + ************************************************************************** + * @file usbd_sdr.c + * @version v2.0.4 + * @date 2021-12-31 + * @brief usb standard device request + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ +#include "usbd_sdr.h" + +/** @addtogroup AT32F435_437_middlewares_usbd_drivers + * @{ + */ + +/** @defgroup USBD_drivers_standard_request + * @brief usb device standard_request + * @{ + */ + +/** @defgroup USBD_sdr_private_functions + * @{ + */ + +static usb_sts_type usbd_get_descriptor(usbd_core_type *udev); +static usb_sts_type usbd_set_address(usbd_core_type *udev); +static usb_sts_type usbd_get_status(usbd_core_type *udev); +static usb_sts_type usbd_clear_feature(usbd_core_type *udev); +static usb_sts_type usbd_set_feature(usbd_core_type *udev); +static usb_sts_type usbd_get_configuration(usbd_core_type *udev); +static usb_sts_type usbd_set_configuration(usbd_core_type *udev); + +/** + * @brief usb parse standard setup request + * @param setup: setup structure + * @param buf: setup buffer + * @retval none + */ +void usbd_setup_request_parse(usb_setup_type *setup, uint8_t *buf) +{ + setup->bmRequestType = *(uint8_t *) buf; + setup->bRequest = *(uint8_t *) (buf + 1); + setup->wValue = SWAPBYTE(buf + 2); + setup->wIndex = SWAPBYTE(buf + 4); + setup->wLength = SWAPBYTE(buf + 6); +} + +/** + * @brief get usb standard device description request + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +static usb_sts_type usbd_get_descriptor(usbd_core_type *udev) +{ + usb_sts_type ret = USB_OK; + uint16_t len = 0; + usbd_desc_t *desc = NULL; + uint8_t desc_type = udev->setup.wValue >> 8; + switch(desc_type) + { + case USB_DESCIPTOR_TYPE_DEVICE: + desc = udev->desc_handler->get_device_descriptor(); + break; + case USB_DESCIPTOR_TYPE_CONFIGURATION: + desc = udev->desc_handler->get_device_configuration(); + break; + case USB_DESCIPTOR_TYPE_STRING: + { + uint8_t str_desc = (uint8_t)udev->setup.wValue; + switch(str_desc) + { + case USB_LANGID_STRING: + desc = udev->desc_handler->get_device_lang_id(); + break; + case USB_MFC_STRING: + desc = udev->desc_handler->get_device_manufacturer_string(); + break; + case USB_PRODUCT_STRING: + desc = udev->desc_handler->get_device_product_string(); + break; + case USB_SERIAL_STRING: + desc = udev->desc_handler->get_device_serial_string(); + break; + case USB_CONFIG_STRING: + desc = udev->desc_handler->get_device_config_string(); + break; + case USB_INTERFACE_STRING: + desc = udev->desc_handler->get_device_interface_string(); + break; + default: + usbd_ctrl_unsupport(udev); + return ret; + } + break; + } + case USB_DESCIPTOR_TYPE_DEVICE_QUALIFIER: + usbd_ctrl_unsupport(udev); + break; + case USB_DESCIPTOR_TYPE_OTHER_SPEED: + usbd_ctrl_unsupport(udev); + return ret; + default: + usbd_ctrl_unsupport(udev); + return ret; + } + + if(desc != NULL) + { + if((desc->length != 0) && (udev->setup.wLength != 0)) + { + len = MIN(desc->length , udev->setup.wLength); + usbd_ctrl_send(udev, desc->descriptor, len); + } + } + return ret; +} + +/** + * @brief this request sets the device address + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +static usb_sts_type usbd_set_address(usbd_core_type *udev) +{ + usb_sts_type ret = USB_OK; + usb_setup_type *setup = &udev->setup; + uint8_t dev_addr; + + /* if wIndex or wLength are non-zero, then the behavior of + the device is not specified + */ + if(setup->wIndex == 0 && setup->wLength == 0) + { + dev_addr = (uint8_t)(setup->wValue) & 0x7f; + + /* device behavior when this request is received + while the device is in the configured state is not specified.*/ + if(udev->conn_state == USB_CONN_STATE_CONFIGURED ) + { + usbd_ctrl_unsupport(udev); + } + else + { + udev->device_addr = dev_addr; + + if(dev_addr != 0) + { + udev->conn_state = USB_CONN_STATE_ADDRESSED; + } + else + { + udev->conn_state = USB_CONN_STATE_DEFAULT; + } + usbd_ctrl_send_status(udev); + } + } + else + { + usbd_ctrl_unsupport(udev); + } + return ret; +} + +/** + * @brief get usb status request + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +static usb_sts_type usbd_get_status(usbd_core_type *udev) +{ + usb_sts_type ret = USB_OK; + switch(udev->conn_state) + { + case USB_CONN_STATE_ADDRESSED: + case USB_CONN_STATE_CONFIGURED: + if(udev->remote_wakup) + { + udev->config_status |= USB_CONF_REMOTE_WAKEUP; + } + usbd_ctrl_send(udev, (uint8_t *)(&udev->config_status), 2); + break; + default: + usbd_ctrl_unsupport(udev); + break; + } + return ret; +} + +/** + * @brief clear usb feature request + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +static usb_sts_type usbd_clear_feature(usbd_core_type *udev) +{ + usb_sts_type ret = USB_OK; + usb_setup_type *setup = &udev->setup; + switch(udev->conn_state) + { + case USB_CONN_STATE_ADDRESSED: + case USB_CONN_STATE_CONFIGURED: + if(setup->wValue == USB_FEATURE_REMOTE_WAKEUP) + { + udev->remote_wakup = 0; + udev->config_status &= ~USB_CONF_REMOTE_WAKEUP; + udev->class_handler->setup_handler(udev, &udev->setup); + usbd_ctrl_send_status(udev); + } + break; + default: + usbd_ctrl_unsupport(udev); + break; + } + return ret; +} + +/** + * @brief set usb feature request + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +static usb_sts_type usbd_set_feature(usbd_core_type *udev) +{ + usb_sts_type ret = USB_OK; + usb_setup_type *setup = &udev->setup; + if(setup->wValue == USB_FEATURE_REMOTE_WAKEUP) + { + udev->remote_wakup = 1; + udev->class_handler->setup_handler(udev, &udev->setup); + usbd_ctrl_send_status(udev); + } + return ret; +} + +/** + * @brief get usb configuration request + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +static usb_sts_type usbd_get_configuration(usbd_core_type *udev) +{ + usb_sts_type ret = USB_OK; + usb_setup_type *setup = &udev->setup; + if(setup->wLength != 1) + { + usbd_ctrl_unsupport(udev); + } + else + { + switch(udev->conn_state) + { + case USB_CONN_STATE_ADDRESSED: + udev->default_config = 0; + usbd_ctrl_send(udev, (uint8_t *)(&udev->default_config), 1); + break; + case USB_CONN_STATE_CONFIGURED: + usbd_ctrl_send(udev, (uint8_t *)(&udev->dev_config), 1); + break; + default: + usbd_ctrl_unsupport(udev); + break; + } + } + return ret; +} + +/** + * @brief sets the usb device configuration request + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +static usb_sts_type usbd_set_configuration(usbd_core_type *udev) +{ + usb_sts_type ret = USB_OK; + static uint8_t config_value; + usb_setup_type *setup = &udev->setup; + config_value = (uint8_t)setup->wValue; + + if(setup->wIndex == 0 && setup->wLength == 0) + { + switch(udev->conn_state) + { + case USB_CONN_STATE_ADDRESSED: + if(config_value) + { + udev->dev_config = config_value; + udev->conn_state = USB_CONN_STATE_CONFIGURED; + udev->class_handler->init_handler(udev); + usbd_ctrl_send_status(udev); + } + else + { + usbd_ctrl_send_status(udev); + } + + break; + case USB_CONN_STATE_CONFIGURED: + if(config_value == 0) + { + udev->conn_state = USB_CONN_STATE_ADDRESSED; + udev->dev_config = config_value; + udev->class_handler->clear_handler(udev); + usbd_ctrl_send_status(udev); + } + else if(config_value == udev->dev_config) + { + udev->class_handler->clear_handler(udev); + udev->dev_config = config_value; + udev->class_handler->init_handler(udev); + usbd_ctrl_send_status(udev); + } + else + { + usbd_ctrl_send_status(udev); + } + break; + default: + usbd_ctrl_unsupport(udev); + break; + } + } + else + { + usbd_ctrl_unsupport(udev); + } + return ret; +} + +/** + * @brief standard usb device requests + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +usb_sts_type usbd_device_request(usbd_core_type *udev) +{ + usb_sts_type ret = USB_OK; + usb_setup_type *setup = &udev->setup; + if((setup->bmRequestType & USB_REQ_TYPE_RESERVED) != USB_REQ_TYPE_STANDARD) + { + udev->class_handler->setup_handler(udev, &udev->setup); + return ret; + } + switch(udev->setup.bRequest) + { + case USB_STD_REQ_GET_STATUS: + usbd_get_status(udev); + break; + case USB_STD_REQ_CLEAR_FEATURE: + usbd_clear_feature(udev); + break; + case USB_STD_REQ_SET_FEATURE: + usbd_set_feature(udev); + break; + case USB_STD_REQ_SET_ADDRESS: + usbd_set_address(udev); + break; + case USB_STD_REQ_GET_DESCRIPTOR: + usbd_get_descriptor(udev); + break; + case USB_STD_REQ_GET_CONFIGURATION: + usbd_get_configuration(udev); + break; + case USB_STD_REQ_SET_CONFIGURATION: + usbd_set_configuration(udev); + break; + default: + usbd_ctrl_unsupport(udev); + break; + } + return ret; +} + +/** + * @brief standard usb interface requests + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +usb_sts_type usbd_interface_request(usbd_core_type *udev) +{ + usb_sts_type ret = USB_OK; + usb_setup_type *setup = &udev->setup; + switch(udev->conn_state) + { + case USB_CONN_STATE_CONFIGURED: + udev->class_handler->setup_handler(udev, &udev->setup); + if(setup->wLength == 0) + { + usbd_ctrl_send_status(udev); + } + break; + default: + usbd_ctrl_unsupport(udev); + break; + } + return ret; +} + +/** + * @brief standard usb endpoint requests + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +usb_sts_type usbd_endpoint_request(usbd_core_type *udev) +{ + usb_sts_type ret = USB_OK; + usb_setup_type *setup = &udev->setup; + uint8_t ept_addr = LBYTE(setup->wIndex); + usb_ept_info *ept_info; + + if((setup->bmRequestType & USB_REQ_TYPE_RESERVED) == USB_REQ_TYPE_CLASS) + { + udev->class_handler->setup_handler(udev, &udev->setup); + } + switch(setup->bRequest) + { + case USB_STD_REQ_GET_STATUS: + switch(udev->conn_state) + { + case USB_CONN_STATE_ADDRESSED: + if((ept_addr & 0x7F) != 0) + { + usbd_set_stall(udev, ept_addr); + } + break; + case USB_CONN_STATE_CONFIGURED: + { + if((ept_addr & 0x80) != 0) + { + ept_info = &udev->ept_in[ept_addr & 0x7F]; + } + else + { + ept_info = &udev->ept_out[ept_addr & 0x7F]; + } + if(ept_info->stall == 1) + { + ept_info->status = 0x0001; + } + else + { + ept_info->status = 0x0000; + } + usbd_ctrl_send(udev, (uint8_t *)(&ept_info->status), 2); + } + break; + default: + usbd_ctrl_unsupport(udev); + break; + } + break; + case USB_STD_REQ_CLEAR_FEATURE: + switch(udev->conn_state) + { + case USB_CONN_STATE_ADDRESSED: + if((ept_addr != 0x00) && (ept_addr != 0x80)) + { + usbd_set_stall(udev, ept_addr); + } + break; + case USB_CONN_STATE_CONFIGURED: + if(setup->wValue == USB_FEATURE_EPT_HALT) + { + if((ept_addr & 0x7F) != 0x00 ) + { + usbd_clear_stall(udev, ept_addr); + udev->class_handler->setup_handler(udev, &udev->setup); + } + usbd_ctrl_send_status(udev); + } + break; + default: + usbd_ctrl_unsupport(udev); + break; + } + break; + case USB_STD_REQ_SET_FEATURE: + switch(udev->conn_state) + { + case USB_CONN_STATE_ADDRESSED: + if((ept_addr != 0x00) && (ept_addr != 0x80)) + { + usbd_set_stall(udev, ept_addr); + } + break; + case USB_CONN_STATE_CONFIGURED: + if(setup->wValue == USB_FEATURE_EPT_HALT) + { + if((ept_addr != 0x00) && (ept_addr != 0x80)) + { + usbd_set_stall(udev, ept_addr); + } + } + udev->class_handler->setup_handler(udev, &udev->setup); + usbd_ctrl_send_status(udev); + break; + default: + usbd_ctrl_unsupport(udev); + break; + } + break; + default: + usbd_ctrl_unsupport(udev); + break; + } + return ret; +} +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_core.h b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_core.h deleted file mode 100644 index 630cf56..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_core.h +++ /dev/null @@ -1,241 +0,0 @@ -/** - ****************************************************************************** - * File : usb_core.h - * Version: V1.2.2 - * Date : 2020-07-01 - * Brief : Standard protocol processing functions prototypes - ****************************************************************************** - */ - - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_CORE_H -#define __USB_CORE_H - -/* Includes ------------------------------------------------------------------*/ -/* Exported types ------------------------------------------------------------*/ -typedef enum _CONTROL_STATE -{ - WAIT_SETUP, /* 0 */ - SETTING_UP, /* 1 */ - IN_DATA, /* 2 */ - OUT_DATA, /* 3 */ - LAST_IN_DATA, /* 4 */ - LAST_OUT_DATA, /* 5 */ - WAIT_STATUS_IN, /* 7 */ - WAIT_STATUS_OUT, /* 8 */ - STALLED, /* 9 */ - PAUSE /* 10 */ -} CONTROL_STATE; /* The state machine states of a control pipe */ - -typedef struct OneDescriptor -{ - uint8_t *Descriptor; - uint16_t Descriptor_Size; -} -ONE_DESCRIPTOR, *PONE_DESCRIPTOR; -/* All the request process routines return a value of this type - If the return value is not SUCCESS or NOT_READY, - the software will STALL the correspond endpoint */ -typedef enum _RESULT -{ - USB_SUCCESS = 0, /* Process successfully */ - USB_ERROR, - USB_UNSUPPORT, - USB_NOT_READY /* The process has not been finished, endpoint will be - NAK to further request */ -} RESULT; - - -/*-*-*-*-*-*-*-*-*-*-* Definitions for endpoint level -*-*-*-*-*-*-*-*-*-*-*-*/ -typedef struct _ENDPOINT_INFO -{ - /* When send data out of the device, - CopyData() is used to get data buffer 'Length' bytes data - if Length is 0, - CopyData() returns the total length of the data - if the request is not supported, returns 0 - (NEW Feature ) - if CopyData() returns -1, the calling routine should not proceed - further and will resume the SETUP process by the class device - if Length is not 0, - CopyData() returns a pointer to indicate the data location - Usb_wLength is the data remain to be sent, - Usb_wOffset is the Offset of original data - When receive data from the host, - CopyData() is used to get user data buffer which is capable - of Length bytes data to copy data from the endpoint buffer. - if Length is 0, - CopyData() returns the available data length, - if Length is not 0, - CopyData() returns user buffer address - Usb_rLength is the data remain to be received, - Usb_rPointer is the Offset of data buffer - */ - uint16_t Usb_wLength; - uint16_t Usb_wOffset; - uint16_t PacketSize; - uint8_t *(*CopyData)(uint16_t Length); -}ENDPOINT_INFO; - -/*-*-*-*-*-*-*-*-*-*-*-* Definitions for device level -*-*-*-*-*-*-*-*-*-*-*-*/ - -typedef struct _DEVICE -{ - uint8_t Total_Endpoint; /* Number of endpoints that are used */ - uint8_t Total_Configuration;/* Number of configuration available */ -} -DEVICE; - -typedef union -{ - uint16_t w; - struct BW - { - uint8_t bb1; - uint8_t bb0; - } - bw; -} uint16_t_uint8_t; - -typedef struct _DEVICE_INFO -{ - uint8_t USBbmRequestType; /* bmRequestType */ - uint8_t USBbRequest; /* bRequest */ - uint16_t_uint8_t USBwValues; /* wValue */ - uint16_t_uint8_t USBwIndexs; /* wIndex */ - uint16_t_uint8_t USBwLengths; /* wLength */ - - uint8_t ControlState; /* of type CONTROL_STATE */ - uint8_t Current_Feature; - uint8_t Current_Configuration; /* Selected configuration */ - uint8_t Current_Interface; /* Selected interface of current configuration */ - uint8_t Current_AlternateSetting;/* Selected Alternate Setting of current - interface*/ - - ENDPOINT_INFO Ctrl_Info; -}DEVICE_INFO; - -typedef struct _DEVICE_PROP -{ - void (*Init)(void); /* Initialize the device */ - void (*Reset)(void); /* Reset routine of this device */ - - /* Device dependent process after the status stage */ - void (*Process_Status_IN)(void); - void (*Process_Status_OUT)(void); - - /* Procedure of process on setup stage of a class specified request with data stage */ - /* All class specified requests with data stage are processed in Class_Data_Setup - Class_Data_Setup() - responses to check all special requests and fills ENDPOINT_INFO - according to the request - If IN tokens are expected, then wLength & wOffset will be filled - with the total transferring bytes and the starting position - If OUT tokens are expected, then rLength & rOffset will be filled - with the total expected bytes and the starting position in the buffer - - If the request is valid, Class_Data_Setup returns SUCCESS, else UNSUPPORT - - CAUTION: - Since GET_CONFIGURATION & GET_INTERFACE are highly related to - the individual classes, they will be checked and processed here. - */ - RESULT (*Class_Data_Setup)(uint8_t RequestNo); - - /* Procedure of process on setup stage of a class specified request without data stage */ - /* All class specified requests without data stage are processed in Class_NoData_Setup - Class_NoData_Setup - responses to check all special requests and perform the request - - CAUTION: - Since SET_CONFIGURATION & SET_INTERFACE are highly related to - the individual classes, they will be checked and processed here. - */ - RESULT (*Class_NoData_Setup)(uint8_t RequestNo); - - /*Class_Get_Interface_Setting - This function is used by the file usb_core.c to test if the selected Interface - and Alternate Setting (uint8_t Interface, uint8_t AlternateSetting) are supported by - the application. - This function is writing by user. It should return "SUCCESS" if the Interface - and Alternate Setting are supported by the application or "UNSUPPORT" if they - are not supported. */ - - RESULT (*Class_Get_Interface_Setting)(uint8_t Interface, uint8_t AlternateSetting); - - uint8_t* (*GetDeviceDescriptor)(uint16_t Length); - uint8_t* (*GetConfigDescriptor)(uint16_t Length); - uint8_t* (*GetStringDescriptor)(uint16_t Length); - - /* This field is not used in current library version. It is kept only for - compatibility with previous versions */ - void* RxEP_buffer; - - uint8_t MaxPacketSize; - -}DEVICE_PROP; - -typedef struct _USER_STANDARD_REQUESTS -{ - void (*User_GetConfiguration)(void); /* Get Configuration */ - void (*User_SetConfiguration)(void); /* Set Configuration */ - void (*User_GetInterface)(void); /* Get Interface */ - void (*User_SetInterface)(void); /* Set Interface */ - void (*User_GetStatus)(void); /* Get Status */ - void (*User_ClearFeature)(void); /* Clear Feature */ - void (*User_SetEndPointFeature)(void); /* Set Endpoint Feature */ - void (*User_SetDeviceFeature)(void); /* Set Device Feature */ - void (*User_SetDeviceAddress)(void); /* Set Device Address */ -} -USER_STANDARD_REQUESTS; - -/* Exported constants --------------------------------------------------------*/ -#define Type_Recipient (pInformation->USBbmRequestType & (REQUEST_TYPE | RECIPIENT)) - -#define Usb_rLength Usb_wLength -#define Usb_rOffset Usb_wOffset - -#define USBwValue USBwValues.w -#define USBwValue0 USBwValues.bw.bb0 -#define USBwValue1 USBwValues.bw.bb1 -#define USBwIndex USBwIndexs.w -#define USBwIndex0 USBwIndexs.bw.bb0 -#define USBwIndex1 USBwIndexs.bw.bb1 -#define USBwLength USBwLengths.w -#define USBwLength0 USBwLengths.bw.bb0 -#define USBwLength1 USBwLengths.bw.bb1 - -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ -uint8_t Setup0_Process(void); -uint8_t Post0_Process(void); -uint8_t Out0_Process(void); -uint8_t In0_Process(void); - -RESULT Standard_SetEndPointFeature(void); -RESULT Standard_SetDeviceFeature(void); - -uint8_t *Standard_GetConfiguration(uint16_t Length); -RESULT Standard_SetConfiguration(void); -uint8_t *Standard_GetInterface(uint16_t Length); -RESULT Standard_SetInterface(void); -uint8_t *Standard_GetDescriptorData(uint16_t Length, PONE_DESCRIPTOR pDesc); - -uint8_t *Standard_GetStatus(uint16_t Length); -RESULT Standard_ClearFeature(void); -void SetDeviceAddress(uint8_t); -void NOP_Process(void); - -extern DEVICE_PROP Device_Property; -extern USER_STANDARD_REQUESTS User_Standard_Requests; -extern DEVICE Device_Table; -extern DEVICE_INFO Device_Info; - -/* cells saving status during interrupt servicing */ -extern __IO uint16_t SaveRState; -extern __IO uint16_t SaveTState; - -#endif /* __USB_CORE_H */ - - diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_def.h b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_def.h deleted file mode 100644 index 045799d..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_def.h +++ /dev/null @@ -1,75 +0,0 @@ -/** - ****************************************************************************** - * File : usb_def.h - * Version: V1.2.2 - * Date : 2020-07-01 - * Brief : Definitions related to USB Core - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_DEF_H -#define __USB_DEF_H - -/* Includes ------------------------------------------------------------------*/ -/* Exported types ------------------------------------------------------------*/ -typedef enum _RECIPIENT_TYPE -{ - DEVICE_RECIPIENT, /* Recipient device */ - INTERFACE_RECIPIENT, /* Recipient interface */ - ENDPOINT_RECIPIENT, /* Recipient endpoint */ - OTHER_RECIPIENT -} RECIPIENT_TYPE; - - -typedef enum _STANDARD_REQUESTS -{ - GET_STATUS = 0, - CLEAR_FEATURE, - RESERVED1, - SET_FEATURE, - RESERVED2, - SET_ADDRESS, - GET_DESCRIPTOR, - SET_DESCRIPTOR, - GET_CONFIGURATION, - SET_CONFIGURATION, - GET_INTERFACE, - SET_INTERFACE, - TOTAL_sREQUEST, /* Total number of Standard request */ - SYNCH_FRAME = 12 -} STANDARD_REQUESTS; - -/* Definition of "USBwValue" */ -typedef enum _DESCRIPTOR_TYPE -{ - DEVICE_DESCRIPTOR = 1, - CONFIG_DESCRIPTOR, - STRING_DESCRIPTOR, - INTERFACE_DESCRIPTOR, - ENDPOINT_DESCRIPTOR -} DESCRIPTOR_TYPE; - -/* Feature selector of a SET_FEATURE or CLEAR_FEATURE */ -typedef enum _FEATURE_SELECTOR -{ - ENDPOINT_STALL, - DEVICE_REMOTE_WAKEUP -} FEATURE_SELECTOR; - -/* Exported constants --------------------------------------------------------*/ -/* Definition of "USBbmRequestType" */ -#define REQUEST_TYPE 0x60 /* Mask to get request type */ -#define STANDARD_REQUEST 0x00 /* Standard request */ -#define CLASS_REQUEST 0x20 /* Class request */ -#define VENDOR_REQUEST 0x40 /* Vendor request */ - -#define RECIPIENT 0x1F /* Mask to get recipient */ - -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ - -#endif /* __USB_DEF_H */ - - - diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_init.h b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_init.h deleted file mode 100644 index f1dc4d1..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_init.h +++ /dev/null @@ -1,51 +0,0 @@ -/** - ****************************************************************************** - * File : usb_init.h - * Version: V1.2.2 - * Date : 2020-07-01 - * Brief : Initialization routines & global variables - ****************************************************************************** - */ - - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_INIT_H -#define __USB_INIT_H - -#ifdef __cplusplus -extern "C" { -#endif -/* Includes ------------------------------------------------------------------*/ -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ -void USB_Init(void); - -/* External variables --------------------------------------------------------*/ -/* The number of current endpoint, it will be used to specify an endpoint */ -extern uint8_t EPindex; -/* The number of current device, it is an index to the Device_Table */ -/*extern uint8_t Device_no; */ -/* Points to the DEVICE_INFO structure of current device */ -/* The purpose of this register is to speed up the execution */ -extern DEVICE_INFO* pInformation; -/* Points to the DEVICE_PROP structure of current device */ -/* The purpose of this register is to speed up the execution */ -extern DEVICE_PROP* pProperty; -/* Temporary save the state of Rx & Tx status. */ -/* Whenever the Rx or Tx state is changed, its value is saved */ -/* in this variable first and will be set to the EPRB or EPRA */ -/* at the end of interrupt process */ -extern USER_STANDARD_REQUESTS *pUser_Standard_Requests; - -extern uint16_t SaveState ; -extern uint16_t wInterrupt_Mask; - -#ifdef __cplusplus -} -#endif - -#endif /* __USB_INIT_H */ - - diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_int.h b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_int.h deleted file mode 100644 index 290303f..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_int.h +++ /dev/null @@ -1,28 +0,0 @@ -/** - ****************************************************************************** - * File : usb_int.h - * Version: V1.2.2 - * Date : 2020-07-01 - * Brief : Endpoint CTRF (Low and High) interrupt's service routines prototypes - ****************************************************************************** - */ - - - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_INT_H -#define __USB_INT_H - -/* Includes ------------------------------------------------------------------*/ -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ -void CTR_LP(void); -void CTR_HP(void); - -/* External variables --------------------------------------------------------*/ - -#endif /* __USB_INT_H */ - - diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_lib.h b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_lib.h deleted file mode 100644 index e09d8e1..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_lib.h +++ /dev/null @@ -1,35 +0,0 @@ -/** - ****************************************************************************** - * File : usb_lib.h - * Version: V1.2.2 - * Date : 2020-07-01 - * Brief : USB library include files - ****************************************************************************** - */ - - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_LIB_H -#define __USB_LIB_H - -/* Includes ------------------------------------------------------------------*/ -#include "hw_config.h" -#include "usb_type.h" -#include "usb_regs.h" -#include "usb_def.h" -#include "usb_core.h" -#include "usb_init.h" -#include "usb_sil.h" -#include "usb_mem.h" -#include "usb_int.h" - - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ -/* External variables --------------------------------------------------------*/ - -#endif /* __USB_LIB_H */ - - diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_mem.h b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_mem.h deleted file mode 100644 index 08dbeb2..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_mem.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - ****************************************************************************** - * File : usb_mem.h - * Version: V1.2.2 - * Date : 2020-07-01 - * Brief : Utility prototypes functions for memory/PMA transfers - ****************************************************************************** - */ - - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_MEM_H -#define __USB_MEM_H - -#ifdef __cplusplus -extern "C" { -#endif -/* Includes ------------------------------------------------------------------*/ -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ -void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); -void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); - -/* External variables --------------------------------------------------------*/ - -#ifdef __cplusplus -} -#endif - -#endif /*__USB_MEM_H*/ - - diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_regs.h b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_regs.h deleted file mode 100644 index 8d7850f..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_regs.h +++ /dev/null @@ -1,672 +0,0 @@ -/** - ****************************************************************************** - * File : usb_reg.h - * Version: V1.2.2 - * Date : 2020-07-01 - * Brief : Interface prototype functions to USB cell registers - ****************************************************************************** - */ - - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_REGS_H -#define __USB_REGS_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -/* Exported types ------------------------------------------------------------*/ -typedef enum _EP_DBUF_DIR -{ - /* double buffered endpoint direction */ - EP_DBUF_ERR, - EP_DBUF_OUT, - EP_DBUF_IN -}EP_DBUF_DIR; - -/* endpoint buffer number */ -enum EP_BUF_NUM -{ - EP_NOBUF, - EP_BUF0, - EP_BUF1 -}; - -/* Exported constants --------------------------------------------------------*/ -#define RegBase (0x40005C00L) /* USB_IP Peripheral Registers base address */ -extern int PMAAddr; /* USB_IP Packet Memory Area base address, default is 0x40006000*/ - -/******************************************************************************/ -/* General registers */ -/******************************************************************************/ - -/* Control register */ -#define CTRL ((__IO unsigned *)(RegBase + 0x40)) -/* Interrupt status register */ -#define INTSTS ((__IO unsigned *)(RegBase + 0x44)) -/* Frame number register */ -#define FRNUM ((__IO unsigned *)(RegBase + 0x48)) -/* Device address register */ -#define DEVADR ((__IO unsigned *)(RegBase + 0x4C)) -/* Buffer Table address register */ -#define BUFTBL ((__IO unsigned *)(RegBase + 0x50)) -/******************************************************************************/ -/* Endpoint registers */ -/******************************************************************************/ -#define EP0REG ((__IO unsigned *)(RegBase)) /* endpoint 0 register address */ - -/* Endpoint Addresses (w/direction) */ -#define EP0_OUT ((uint8_t)0x00) -#define EP0_IN ((uint8_t)0x80) -#define EP1_OUT ((uint8_t)0x01) -#define EP1_IN ((uint8_t)0x81) -#define EP2_OUT ((uint8_t)0x02) -#define EP2_IN ((uint8_t)0x82) -#define EP3_OUT ((uint8_t)0x03) -#define EP3_IN ((uint8_t)0x83) -#define EP4_OUT ((uint8_t)0x04) -#define EP4_IN ((uint8_t)0x84) -#define EP5_OUT ((uint8_t)0x05) -#define EP5_IN ((uint8_t)0x85) -#define EP6_OUT ((uint8_t)0x06) -#define EP6_IN ((uint8_t)0x86) -#define EP7_OUT ((uint8_t)0x07) -#define EP7_IN ((uint8_t)0x87) - -/* endpoints enumeration */ -#define ENDP0 ((uint8_t)0) -#define ENDP1 ((uint8_t)1) -#define ENDP2 ((uint8_t)2) -#define ENDP3 ((uint8_t)3) -#define ENDP4 ((uint8_t)4) -#define ENDP5 ((uint8_t)5) -#define ENDP6 ((uint8_t)6) -#define ENDP7 ((uint8_t)7) - -/******************************************************************************/ -/* INTSTS interrupt events */ -/******************************************************************************/ -#define INTSTS_CTFR (0x8000) /* Correct TRansfer (clear-only bit) */ -#define INTSTS_DOVR (0x4000) /* DMA OVeR/underrun (clear-only bit) */ -#define INTSTS_ERRF (0x2000) /* ERRor (clear-only bit) */ -#define INTSTS_WKUPF (0x1000) /* WaKe UP (clear-only bit) */ -#define INTSTS_SUSPF (0x0800) /* SUSPend (clear-only bit) */ -#define INTSTS_RSTF (0x0400) /* RESET (clear-only bit) */ -#define INTSTS_SOFF (0x0200) /* Start Of Frame (clear-only bit) */ -#define INTSTS_ESOF (0x0100) /* Expected Start Of Frame (clear-only bit) */ - - -#define INTSTS_DIR (0x0010) /* DIRection of transaction (read-only bit) */ -#define INTSTS_EP_ID (0x000F) /* EndPoint IDentifier (read-only bit) */ - -#define CLR_CTFR (~INTSTS_CTFR) /* clear Correct TRansfer bit */ -#define CLR_DOVR (~INTSTS_DOVR) /* clear DMA OVeR/underrun bit*/ -#define CLR_ERRF (~INTSTS_ERRF) /* clear ERRor bit */ -#define CLR_WKUPF (~INTSTS_WKUPF) /* clear WaKe UP bit */ -#define CLR_SUSPF (~INTSTS_SUSPF) /* clear SUSPend bit */ -#define CLR_RSTF (~INTSTS_RSTF) /* clear RESET bit */ -#define CLR_SOFF (~INTSTS_SOFF) /* clear Start Of Frame bit */ -#define CLR_ESOF (~INTSTS_ESOF) /* clear Expected Start Of Frame bit */ - -/******************************************************************************/ -/* CTRL control register bits definitions */ -/******************************************************************************/ -#define CTRL_CTFR_IEN (0x8000) /* Correct TRansfer Mask */ -#define CTRL_DOVR_IEN (0x4000) /* DMA OVeR/underrun Mask */ -#define CTRL_ERR_IEN (0x2000) /* ERRor Mask */ -#define CTRL_WKUP_IEN (0x1000) /* WaKe UP Mask */ -#define CTRL_SUSP_IEN (0x0800) /* SUSPend Mask */ -#define CTRL_RST_IEN (0x0400) /* RESET Mask */ -#define CTRL_SOF_IEN (0x0200) /* Start Of Frame Mask */ -#define CTRL_ESOF_IEN (0x0100) /* Expected Start Of Frame Mask */ - - -#define CTRL_RESUME (0x0010) /* RESUME request */ -#define CTRL_FSUSP (0x0008) /* Force SUSPend */ -#define CTRL_LPWR (0x0004) /* Low-power MODE */ -#define CTRL_PDWN (0x0002) /* Power DoWN */ -#define CTRL_FRST (0x0001) /* Force USB RESet */ - -/******************************************************************************/ -/* FRNUM Frame Number Register bit definitions */ -/******************************************************************************/ -#define FRNUM_RXDP (0x8000) /* status of D+ data line */ -#define FRNUM_RXDM (0x4000) /* status of D- data line */ -#define FRNUM_LCK (0x2000) /* LoCKed */ -#define FRNUM_LSOF (0x1800) /* Lost SOF */ -#define FRNUM_FN (0x07FF) /* Frame Number */ -/******************************************************************************/ -/* DEVADR Device ADDRess bit definitions */ -/******************************************************************************/ -#define DEVADR_EN (0x80) -#define DEVADR_ADR (0x7F) -/******************************************************************************/ -/* Endpoint register */ -/******************************************************************************/ -/* bit positions */ -#define EP_CTFR_RX (0x8000) /* EndPoint Correct TRansfer RX */ -#define EP_DTOG_RX (0x4000) /* EndPoint Data TOGGLE RX */ -#define EP_STS_RX (0x3000) /* EndPoint RX STATus bit field */ -#define EP_SETUP (0x0800) /* EndPoint SETUP */ -#define EP_T_FIELD (0x0600) /* EndPoint TYPE */ -#define EP_SUBTYPE (0x0100) /* EndPoint KIND */ -#define EP_CTFR_TX (0x0080) /* EndPoint Correct TRansfer TX */ -#define EP_DTOG_TX (0x0040) /* EndPoint Data TOGGLE TX */ -#define EP_STS_TX (0x0030) /* EndPoint TX STATus bit field */ -#define EPADR_FIELD (0x000F) /* EndPoint ADDRess FIELD */ - -/* EndPoint REGister MASK (no toggle fields) */ -#define EPREG_MASK (EP_CTFR_RX|EP_SETUP|EP_T_FIELD|EP_SUBTYPE|EP_CTFR_TX|EPADR_FIELD) - -/* EP_TYPE[1:0] EndPoint TYPE */ -#define EP_TYPE_MASK (0x0600) /* EndPoint TYPE Mask */ -#define EP_BULK (0x0000) /* EndPoint BULK */ -#define EP_CONTROL (0x0200) /* EndPoint CONTROL */ -#define EP_ISOCHRONOUS (0x0400) /* EndPoint ISOCHRONOUS */ -#define EP_INTERRUPT (0x0600) /* EndPoint INTERRUPT */ -#define EP_T_MASK (~EP_T_FIELD & EPREG_MASK) - - -/* EP_SUBTYPE EndPoint KIND */ -#define EPKIND_MASK (~EP_SUBTYPE & EPREG_MASK) - -/* STAT_TX[1:0] STATus for TX transfer */ -#define EP_TX_DIS (0x0000) /* EndPoint TX DISabled */ -#define EP_TX_STALL (0x0010) /* EndPoint TX STALLed */ -#define EP_TX_NAK (0x0020) /* EndPoint TX NAKed */ -#define EP_TX_VALID (0x0030) /* EndPoint TX VALID */ -#define EPTX_DTOG1 (0x0010) /* EndPoint TX Data TOGgle bit1 */ -#define EPTX_DTOG2 (0x0020) /* EndPoint TX Data TOGgle bit2 */ -#define EPTX_DTOGMASK (EP_STS_TX|EPREG_MASK) - -/* STAT_RX[1:0] STATus for RX transfer */ -#define EP_RX_DIS (0x0000) /* EndPoint RX DISabled */ -#define EP_RX_STALL (0x1000) /* EndPoint RX STALLed */ -#define EP_RX_NAK (0x2000) /* EndPoint RX NAKed */ -#define EP_RX_VALID (0x3000) /* EndPoint RX VALID */ -#define EPRX_DTOG1 (0x1000) /* EndPoint RX Data TOGgle bit1 */ -#define EPRX_DTOG2 (0x2000) /* EndPoint RX Data TOGgle bit1 */ -#define EPRX_DTOGMASK (EP_STS_RX|EPREG_MASK) -/* Exported macro ------------------------------------------------------------*/ -/* SetCTRL */ -#define _SetCTRL(wRegValue) (*CTRL = (uint16_t)wRegValue) - -/* SetINTSTS */ -#define _SetINTSTS(wRegValue) (*INTSTS = (uint16_t)wRegValue) - -/* SetDEVADR */ -#define _SetDEVADR(wRegValue) (*DEVADR = (uint16_t)wRegValue) - -/* SetBUFTBL */ -#define _SetBUFTBL(wRegValue)(*BUFTBL = (uint16_t)(wRegValue & 0xFFF8)) - -/* GetCTRL */ -#define _GetCTRL() ((uint16_t) *CTRL) - -/* GetINTSTS */ -#define _GetINTSTS() ((uint16_t) *INTSTS) - -/* GetFRNUM */ -#define _GetFRNUM() ((uint16_t) *FRNUM) - -/* GetDEVADR */ -#define _GetDEVADR() ((uint16_t) *DEVADR) - -/* GetBUFTBL */ -#define _GetBUFTBL() ((uint16_t) *BUFTBL) - -/* SetENDPOINT */ -#define _SetENDPOINT(bEpNum,wRegValue) (*(EP0REG + bEpNum)= \ - (uint16_t)wRegValue) - -/* GetENDPOINT */ -#define _GetENDPOINT(bEpNum) ((uint16_t)(*(EP0REG + bEpNum))) - -/******************************************************************************* -* Macro Name : SetEPType -* Description : sets the type in the endpoint register(bits EP_TYPE[1:0]) -* Input : bEpNum: Endpoint Number. -* wType -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPType(bEpNum,wType) (_SetENDPOINT(bEpNum,\ - ((_GetENDPOINT(bEpNum) & EP_T_MASK) | wType ))) - -/******************************************************************************* -* Macro Name : GetEPType -* Description : gets the type in the endpoint register(bits EP_TYPE[1:0]) -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : Endpoint Type -*******************************************************************************/ -#define _GetEPType(bEpNum) (_GetENDPOINT(bEpNum) & EP_T_FIELD) - -/******************************************************************************* -* Macro Name : SetEPTxStatus -* Description : sets the status for tx transfer (bits STAT_TX[1:0]). -* Input : bEpNum: Endpoint Number. -* wState: new state -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPTxStatus(bEpNum,wState) {\ - register uint16_t _wRegVal; \ - _wRegVal = _GetENDPOINT(bEpNum) & EPTX_DTOGMASK;\ - /* toggle first bit ? */ \ - if((EPTX_DTOG1 & wState)!= 0) \ - _wRegVal ^= EPTX_DTOG1; \ - /* toggle second bit ? */ \ - if((EPTX_DTOG2 & wState)!= 0) \ - _wRegVal ^= EPTX_DTOG2; \ - _SetENDPOINT(bEpNum, (_wRegVal | EP_CTFR_RX|EP_CTFR_TX)); \ - } /* _SetEPTxStatus */ - -/******************************************************************************* -* Macro Name : SetEPRxStatus -* Description : sets the status for rx transfer (bits STAT_TX[1:0]) -* Input : bEpNum: Endpoint Number. -* wState: new state. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPRxStatus(bEpNum,wState) {\ - register uint16_t _wRegVal; \ - \ - _wRegVal = _GetENDPOINT(bEpNum) & EPRX_DTOGMASK;\ - /* toggle first bit ? */ \ - if((EPRX_DTOG1 & wState)!= 0) \ - _wRegVal ^= EPRX_DTOG1; \ - /* toggle second bit ? */ \ - if((EPRX_DTOG2 & wState)!= 0) \ - _wRegVal ^= EPRX_DTOG2; \ - _SetENDPOINT(bEpNum, (_wRegVal | EP_CTFR_RX|EP_CTFR_TX)); \ - } /* _SetEPRxStatus */ - -/******************************************************************************* -* Macro Name : SetEPRxTxStatus -* Description : sets the status for rx & tx (bits STAT_TX[1:0] & STAT_RX[1:0]) -* Input : bEpNum: Endpoint Number. -* wStaterx: new state. -* wStatetx: new state. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPRxTxStatus(bEpNum,wStaterx,wStatetx) {\ - register uint32_t _wRegVal; \ - \ - _wRegVal = _GetENDPOINT(bEpNum) & (EPRX_DTOGMASK |EP_STS_TX) ;\ - /* toggle first bit ? */ \ - if((EPRX_DTOG1 & wStaterx)!= 0) \ - _wRegVal ^= EPRX_DTOG1; \ - /* toggle second bit ? */ \ - if((EPRX_DTOG2 & wStaterx)!= 0) \ - _wRegVal ^= EPRX_DTOG2; \ - /* toggle first bit ? */ \ - if((EPTX_DTOG1 & wStatetx)!= 0) \ - _wRegVal ^= EPTX_DTOG1; \ - /* toggle second bit ? */ \ - if((EPTX_DTOG2 & wStatetx)!= 0) \ - _wRegVal ^= EPTX_DTOG2; \ - _SetENDPOINT(bEpNum, _wRegVal | EP_CTFR_RX|EP_CTFR_TX); \ - } /* _SetEPRxTxStatus */ -/******************************************************************************* -* Macro Name : GetEPTxStatus / GetEPRxStatus -* Description : gets the status for tx/rx transfer (bits STAT_TX[1:0] -* /STAT_RX[1:0]) -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : status . -*******************************************************************************/ -#define _GetEPTxStatus(bEpNum) ((uint16_t)_GetENDPOINT(bEpNum) & EP_STS_TX) - -#define _GetEPRxStatus(bEpNum) ((uint16_t)_GetENDPOINT(bEpNum) & EP_STS_RX) - -/******************************************************************************* -* Macro Name : SetEPTxValid / SetEPRxValid -* Description : sets directly the VALID tx/rx-status into the enpoint register -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPTxValid(bEpNum) (_SetEPTxStatus(bEpNum, EP_TX_VALID)) - -#define _SetEPRxValid(bEpNum) (_SetEPRxStatus(bEpNum, EP_RX_VALID)) - -/******************************************************************************* -* Macro Name : GetTxStallStatus / GetRxStallStatus. -* Description : checks stall condition in an endpoint. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : TRUE = endpoint in stall condition. -*******************************************************************************/ -#define _GetTxStallStatus(bEpNum) (_GetEPTxStatus(bEpNum) \ - == EP_TX_STALL) -#define _GetRxStallStatus(bEpNum) (_GetEPRxStatus(bEpNum) \ - == EP_RX_STALL) - -/******************************************************************************* -* Macro Name : SetEP_SUBTYPE / ClearEP_SUBTYPE. -* Description : set & clear EP_SUBTYPE bit. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEP_SUBTYPE(bEpNum) (_SetENDPOINT(bEpNum, \ - (EP_CTFR_RX|EP_CTFR_TX|((_GetENDPOINT(bEpNum) | EP_SUBTYPE) & EPREG_MASK)))) -#define _ClearEP_SUBTYPE(bEpNum) (_SetENDPOINT(bEpNum, \ - (EP_CTFR_RX|EP_CTFR_TX|(_GetENDPOINT(bEpNum) & EPKIND_MASK)))) - -/******************************************************************************* -* Macro Name : Set_Status_Out / Clear_Status_Out. -* Description : Sets/clears directly STATUS_OUT bit in the endpoint register. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _Set_Status_Out(bEpNum) _SetEP_SUBTYPE(bEpNum) -#define _Clear_Status_Out(bEpNum) _ClearEP_SUBTYPE(bEpNum) - -/******************************************************************************* -* Macro Name : SetEPDoubleBuff / ClearEPDoubleBuff. -* Description : Sets/clears directly EP_SUBTYPE bit in the endpoint register. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPDoubleBuff(bEpNum) _SetEP_SUBTYPE(bEpNum) -#define _ClearEPDoubleBuff(bEpNum) _ClearEP_SUBTYPE(bEpNum) - -/******************************************************************************* -* Macro Name : ClearEP_CTFR_RX / ClearEP_CTFR_TX. -* Description : Clears bit CTR_RX / CTR_TX in the endpoint register. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _ClearEP_CTFR_RX(bEpNum) (_SetENDPOINT(bEpNum,\ - _GetENDPOINT(bEpNum) & 0x7FFF & EPREG_MASK)) -#define _ClearEP_CTFR_TX(bEpNum) (_SetENDPOINT(bEpNum,\ - _GetENDPOINT(bEpNum) & 0xFF7F & EPREG_MASK)) - -/******************************************************************************* -* Macro Name : ToggleDTOG_RX / ToggleDTOG_TX . -* Description : Toggles DTOG_RX / DTOG_TX bit in the endpoint register. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _ToggleDTOG_RX(bEpNum) (_SetENDPOINT(bEpNum, \ - EP_CTFR_RX|EP_CTFR_TX|EP_DTOG_RX | (_GetENDPOINT(bEpNum) & EPREG_MASK))) -#define _ToggleDTOG_TX(bEpNum) (_SetENDPOINT(bEpNum, \ - EP_CTFR_RX|EP_CTFR_TX|EP_DTOG_TX | (_GetENDPOINT(bEpNum) & EPREG_MASK))) - -/******************************************************************************* -* Macro Name : ClearDTOG_RX / ClearDTOG_TX. -* Description : Clears DTOG_RX / DTOG_TX bit in the endpoint register. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _ClearDTOG_RX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_RX) != 0)\ - _ToggleDTOG_RX(bEpNum) -#define _ClearDTOG_TX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_TX) != 0)\ - _ToggleDTOG_TX(bEpNum) -/******************************************************************************* -* Macro Name : SetEPAddress. -* Description : Sets address in an endpoint register. -* Input : bEpNum: Endpoint Number. -* bAddr: Address. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPAddress(bEpNum,bAddr) _SetENDPOINT(bEpNum,\ - EP_CTFR_RX|EP_CTFR_TX|(_GetENDPOINT(bEpNum) & EPREG_MASK) | bAddr) - -/******************************************************************************* -* Macro Name : GetEPAddress. -* Description : Gets address in an endpoint register. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _GetEPAddress(bEpNum) ((uint8_t)(_GetENDPOINT(bEpNum) & EPADR_FIELD)) - -#define _pEPTxAddr(bEpNum) ((uint32_t *)((_GetBUFTBL()+bEpNum*8 )*2 + PMAAddr)) -#define _pEPTxCount(bEpNum) ((uint32_t *)((_GetBUFTBL()+bEpNum*8+2)*2 + PMAAddr)) -#define _pEPRxAddr(bEpNum) ((uint32_t *)((_GetBUFTBL()+bEpNum*8+4)*2 + PMAAddr)) -#define _pEPRxCount(bEpNum) ((uint32_t *)((_GetBUFTBL()+bEpNum*8+6)*2 + PMAAddr)) - -/******************************************************************************* -* Macro Name : SetEPTxAddr / SetEPRxAddr. -* Description : sets address of the tx/rx buffer. -* Input : bEpNum: Endpoint Number. -* wAddr: address to be set (must be word aligned). -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPTxAddr(bEpNum,wAddr) (*_pEPTxAddr(bEpNum) = ((wAddr >> 1) << 1)) -#define _SetEPRxAddr(bEpNum,wAddr) (*_pEPRxAddr(bEpNum) = ((wAddr >> 1) << 1)) - -/******************************************************************************* -* Macro Name : GetEPTxAddr / GetEPRxAddr. -* Description : Gets address of the tx/rx buffer. -* Input : bEpNum: Endpoint Number. -* Output : None. -* Return : address of the buffer. -*******************************************************************************/ -#define _GetEPTxAddr(bEpNum) ((uint16_t)*_pEPTxAddr(bEpNum)) -#define _GetEPRxAddr(bEpNum) ((uint16_t)*_pEPRxAddr(bEpNum)) - -/******************************************************************************* -* Macro Name : SetEPCountRxReg. -* Description : Sets counter of rx buffer with no. of blocks. -* Input : pdwReg: pointer to counter. -* wCount: Counter. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _BlocksOf32(dwReg,wCount,wNBlocks) {\ - wNBlocks = wCount >> 5;\ - if((wCount & 0x1f) == 0)\ - wNBlocks--;\ - *pdwReg = (uint32_t)((wNBlocks << 10) | 0x8000);\ - }/* _BlocksOf32 */ - -#define _BlocksOf2(dwReg,wCount,wNBlocks) {\ - wNBlocks = wCount >> 1;\ - if((wCount & 0x1) != 0)\ - wNBlocks++;\ - *pdwReg = (uint32_t)(wNBlocks << 10);\ - }/* _BlocksOf2 */ - -#define _SetEPCountRxReg(dwReg,wCount) {\ - uint16_t wNBlocks;\ - if(wCount > 62){_BlocksOf32(dwReg,wCount,wNBlocks);}\ - else {_BlocksOf2(dwReg,wCount,wNBlocks);}\ - }/* _SetEPCountRxReg */ - - - -#define _SetEPRxDblBuf0Count(bEpNum,wCount) {\ - uint32_t *pdwReg = _pEPTxCount(bEpNum); \ - _SetEPCountRxReg(pdwReg, wCount);\ - } -/******************************************************************************* -* Macro Name : SetEPTxCount / SetEPRxCount. -* Description : sets counter for the tx/rx buffer. -* Input : bEpNum: endpoint number. -* wCount: Counter value. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPTxCount(bEpNum,wCount) (*_pEPTxCount(bEpNum) = wCount) -#define _SetEPRxCount(bEpNum,wCount) {\ - uint32_t *pdwReg = _pEPRxCount(bEpNum); \ - _SetEPCountRxReg(pdwReg, wCount);\ - } -/******************************************************************************* -* Macro Name : GetEPTxCount / GetEPRxCount. -* Description : gets counter of the tx buffer. -* Input : bEpNum: endpoint number. -* Output : None. -* Return : Counter value. -*******************************************************************************/ -#define _GetEPTxCount(bEpNum)((uint16_t)(*_pEPTxCount(bEpNum)) & 0x3ff) -#define _GetEPRxCount(bEpNum)((uint16_t)(*_pEPRxCount(bEpNum)) & 0x3ff) - -/******************************************************************************* -* Macro Name : SetEPDblBuf0Addr / SetEPDblBuf1Addr. -* Description : Sets buffer 0/1 address in a double buffer endpoint. -* Input : bEpNum: endpoint number. -* : wBuf0Addr: buffer 0 address. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPDblBuf0Addr(bEpNum,wBuf0Addr) {_SetEPTxAddr(bEpNum, wBuf0Addr);} -#define _SetEPDblBuf1Addr(bEpNum,wBuf1Addr) {_SetEPRxAddr(bEpNum, wBuf1Addr);} - -/******************************************************************************* -* Macro Name : SetEPDblBuffAddr. -* Description : Sets addresses in a double buffer endpoint. -* Input : bEpNum: endpoint number. -* : wBuf0Addr: buffer 0 address. -* : wBuf1Addr = buffer 1 address. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPDblBuffAddr(bEpNum,wBuf0Addr,wBuf1Addr) { \ - _SetEPDblBuf0Addr(bEpNum, wBuf0Addr);\ - _SetEPDblBuf1Addr(bEpNum, wBuf1Addr);\ - } /* _SetEPDblBuffAddr */ - -/******************************************************************************* -* Macro Name : GetEPDblBuf0Addr / GetEPDblBuf1Addr. -* Description : Gets buffer 0/1 address of a double buffer endpoint. -* Input : bEpNum: endpoint number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _GetEPDblBuf0Addr(bEpNum) (_GetEPTxAddr(bEpNum)) -#define _GetEPDblBuf1Addr(bEpNum) (_GetEPRxAddr(bEpNum)) - -/******************************************************************************* -* Macro Name : SetEPDblBuffCount / SetEPDblBuf0Count / SetEPDblBuf1Count. -* Description : Gets buffer 0/1 address of a double buffer endpoint. -* Input : bEpNum: endpoint number. -* : bDir: endpoint dir EP_DBUF_OUT = OUT -* EP_DBUF_IN = IN -* : wCount: Counter value -* Output : None. -* Return : None. -*******************************************************************************/ -#define _SetEPDblBuf0Count(bEpNum, bDir, wCount) { \ - if(bDir == EP_DBUF_OUT)\ - /* OUT endpoint */ \ - {_SetEPRxDblBuf0Count(bEpNum,wCount);} \ - else if(bDir == EP_DBUF_IN)\ - /* IN endpoint */ \ - *_pEPTxCount(bEpNum) = (uint32_t)wCount; \ - } /* SetEPDblBuf0Count*/ - -#define _SetEPDblBuf1Count(bEpNum, bDir, wCount) { \ - if(bDir == EP_DBUF_OUT)\ - /* OUT endpoint */ \ - {_SetEPRxCount(bEpNum,wCount);}\ - else if(bDir == EP_DBUF_IN)\ - /* IN endpoint */\ - *_pEPRxCount(bEpNum) = (uint32_t)wCount; \ - } /* SetEPDblBuf1Count */ - -#define _SetEPDblBuffCount(bEpNum, bDir, wCount) {\ - _SetEPDblBuf0Count(bEpNum, bDir, wCount); \ - _SetEPDblBuf1Count(bEpNum, bDir, wCount); \ - } /* _SetEPDblBuffCount */ - -/******************************************************************************* -* Macro Name : GetEPDblBuf0Count / GetEPDblBuf1Count. -* Description : Gets buffer 0/1 rx/tx counter for double buffering. -* Input : bEpNum: endpoint number. -* Output : None. -* Return : None. -*******************************************************************************/ -#define _GetEPDblBuf0Count(bEpNum) (_GetEPTxCount(bEpNum)) -#define _GetEPDblBuf1Count(bEpNum) (_GetEPRxCount(bEpNum)) - - -/* External variables --------------------------------------------------------*/ -extern __IO uint16_t wIstr; /* INTSTS register last read value */ - -/* Exported functions ------------------------------------------------------- */ -void SetCTRL(uint16_t /*wRegValue*/); -void SetINTSTS(uint16_t /*wRegValue*/); -void SetDEVADR(uint16_t /*wRegValue*/); -void SetBUFTBL(uint16_t /*wRegValue*/); -void SetBUFTBL(uint16_t /*wRegValue*/); -uint16_t GetCTRL(void); -uint16_t GetINTSTS(void); -uint16_t GetFRNUM(void); -uint16_t GetDEVADR(void); -uint16_t GetBUFTBL(void); -void SetENDPOINT(uint8_t /*bEpNum*/, uint16_t /*wRegValue*/); -uint16_t GetENDPOINT(uint8_t /*bEpNum*/); -void SetEPType(uint8_t /*bEpNum*/, uint16_t /*wType*/); -uint16_t GetEPType(uint8_t /*bEpNum*/); -void SetEPTxStatus(uint8_t /*bEpNum*/, uint16_t /*wState*/); -void SetEPRxStatus(uint8_t /*bEpNum*/, uint16_t /*wState*/); -void SetDouBleBuffEPStall(uint8_t /*bEpNum*/, uint8_t bDir); -uint16_t GetEPTxStatus(uint8_t /*bEpNum*/); -uint16_t GetEPRxStatus(uint8_t /*bEpNum*/); -void SetEPTxValid(uint8_t /*bEpNum*/); -void SetEPRxValid(uint8_t /*bEpNum*/); -uint16_t GetTxStallStatus(uint8_t /*bEpNum*/); -uint16_t GetRxStallStatus(uint8_t /*bEpNum*/); -void SetEP_SUBTYPE(uint8_t /*bEpNum*/); -void ClearEP_SUBTYPE(uint8_t /*bEpNum*/); -void Set_Status_Out(uint8_t /*bEpNum*/); -void Clear_Status_Out(uint8_t /*bEpNum*/); -void SetEPDoubleBuff(uint8_t /*bEpNum*/); -void ClearEPDoubleBuff(uint8_t /*bEpNum*/); -void ClearEP_CTFR_RX(uint8_t /*bEpNum*/); -void ClearEP_CTFR_TX(uint8_t /*bEpNum*/); -void ToggleDTOG_RX(uint8_t /*bEpNum*/); -void ToggleDTOG_TX(uint8_t /*bEpNum*/); -void ClearDTOG_RX(uint8_t /*bEpNum*/); -void ClearDTOG_TX(uint8_t /*bEpNum*/); -void SetEPAddress(uint8_t /*bEpNum*/, uint8_t /*bAddr*/); -uint8_t GetEPAddress(uint8_t /*bEpNum*/); -void SetEPTxAddr(uint8_t /*bEpNum*/, uint16_t /*wAddr*/); -void SetEPRxAddr(uint8_t /*bEpNum*/, uint16_t /*wAddr*/); -uint16_t GetEPTxAddr(uint8_t /*bEpNum*/); -uint16_t GetEPRxAddr(uint8_t /*bEpNum*/); -void SetEPCountRxReg(uint32_t * /*pdwReg*/, uint16_t /*wCount*/); -void SetEPTxCount(uint8_t /*bEpNum*/, uint16_t /*wCount*/); -void SetEPRxCount(uint8_t /*bEpNum*/, uint16_t /*wCount*/); -uint16_t GetEPTxCount(uint8_t /*bEpNum*/); -uint16_t GetEPRxCount(uint8_t /*bEpNum*/); -void SetEPDblBuf0Addr(uint8_t /*bEpNum*/, uint16_t /*wBuf0Addr*/); -void SetEPDblBuf1Addr(uint8_t /*bEpNum*/, uint16_t /*wBuf1Addr*/); -void SetEPDblBuffAddr(uint8_t /*bEpNum*/, uint16_t /*wBuf0Addr*/, uint16_t /*wBuf1Addr*/); -uint16_t GetEPDblBuf0Addr(uint8_t /*bEpNum*/); -uint16_t GetEPDblBuf1Addr(uint8_t /*bEpNum*/); -void SetEPDblBuffCount(uint8_t /*bEpNum*/, uint8_t /*bDir*/, uint16_t /*wCount*/); -void SetEPDblBuf0Count(uint8_t /*bEpNum*/, uint8_t /*bDir*/, uint16_t /*wCount*/); -void SetEPDblBuf1Count(uint8_t /*bEpNum*/, uint8_t /*bDir*/, uint16_t /*wCount*/); -uint16_t GetEPDblBuf0Count(uint8_t /*bEpNum*/); -uint16_t GetEPDblBuf1Count(uint8_t /*bEpNum*/); -EP_DBUF_DIR GetEPDblBufDir(uint8_t /*bEpNum*/); -void FreeUserBuffer(uint8_t bEpNum/*bEpNum*/, uint8_t bDir); -uint16_t ToWord(uint8_t, uint8_t); -uint16_t ByteSwap(uint16_t); -void Set_USB768ByteMode(void); -void Clear_USB768ByteMode(void); - -#ifdef __cplusplus -} -#endif - -#endif /* __USB_REGS_H */ - - diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_type.h b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_type.h deleted file mode 100644 index 1529319..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/include/usb_type.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - ****************************************************************************** - * File : usb_type.h - * Version: V1.2.2 - * Date : 2020-07-01 - * Brief : Type definitions used by the USB Library - ****************************************************************************** - */ - - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_TYPE_H -#define __USB_TYPE_H - -/* Includes ------------------------------------------------------------------*/ -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -#ifndef NULL -#define NULL ((void *)0) -#endif - -#ifndef __cplusplus -typedef enum -{ - FALSE = 0, TRUE = !FALSE -} -bool; -#endif - - -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ -/* External variables --------------------------------------------------------*/ - -#endif /* __USB_TYPE_H */ - - diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/src/usb_core.c b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/src/usb_core.c deleted file mode 100644 index 6d683ce..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/src/usb_core.c +++ /dev/null @@ -1,973 +0,0 @@ -/** - ****************************************************************************** - * File : usb_core.c - * Version: V1.2.2 - * Date : 2020-07-01 - * Brief : Standard protocol processing (USB v2.0) - ****************************************************************************** - */ - - -/* Includes ------------------------------------------------------------------*/ -#include "usb_lib.h" -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -#define ValBit(VAR,Place) (VAR & (1 << Place)) -#define SetBit(VAR,Place) (VAR |= (1 << Place)) -#define ClrBit(VAR,Place) (VAR &= ((1 << Place) ^ 255)) -#define Send0LengthData() { _SetEPTxCount(ENDP0, 0); \ - vSetEPTxStatus(EP_TX_VALID); \ - } - -#define vSetEPRxStatus(st) (SaveRState = st) -#define vSetEPTxStatus(st) (SaveTState = st) - -#define USB_StatusIn() Send0LengthData() -#define USB_StatusOut() vSetEPRxStatus(EP_RX_VALID) - -#define StatusInfo0 StatusInfo.bw.bb1 /* Reverse bb0 & bb1 */ -#define StatusInfo1 StatusInfo.bw.bb0 - -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -uint16_t_uint8_t StatusInfo; - -bool Data_Mul_MaxPacketSize = FALSE; -/* Private function prototypes -----------------------------------------------*/ -static void DataStageOut(void); -static void DataStageIn(void); -static void NoData_Setup0(void); -static void Data_Setup0(void); -/* Private functions ---------------------------------------------------------*/ - -/** - * @brief Return the current configuration variable address. - * @param Length: How many bytes are needed. - * @retval 0 if the request is invalid when Length is 0. - * Buffer address if the Length is not 0. - */ -uint8_t *Standard_GetConfiguration(uint16_t Length) -{ - if (Length == 0) - { - pInformation->Ctrl_Info.Usb_wLength = - sizeof(pInformation->Current_Configuration); - return 0; - } - pUser_Standard_Requests->User_GetConfiguration(); - return (uint8_t *)&pInformation->Current_Configuration; -} - -/** - * @brief This routine is called to set the configuration value - * Then each class should configure device itself. - * @param None. - * @retval USB_SUCCESS if the request is performed. - * USB_UNSUPPORT if the request is invalid. - */ -RESULT Standard_SetConfiguration(void) -{ - - if ((pInformation->USBwValue0 <= - Device_Table.Total_Configuration) && (pInformation->USBwValue1 == 0) - && (pInformation->USBwIndex == 0)) /*call Back usb spec 2.0*/ - { - pInformation->Current_Configuration = pInformation->USBwValue0; - pUser_Standard_Requests->User_SetConfiguration(); - return USB_SUCCESS; - } - else - { - return USB_UNSUPPORT; - } -} - -/** - * @brief Return the Alternate Setting of the current interface. - * @param Length: How many bytes are needed. - * @retval 0 if the request is invalid when Length is 0. - * Buffer address if the Length is not 0. - */ -uint8_t *Standard_GetInterface(uint16_t Length) -{ - if (Length == 0) - { - pInformation->Ctrl_Info.Usb_wLength = - sizeof(pInformation->Current_AlternateSetting); - return 0; - } - pUser_Standard_Requests->User_GetInterface(); - return (uint8_t *)&pInformation->Current_AlternateSetting; -} - -/** - * @brief This routine is called to set the interface. - * Then each class should configure the interface them self. - * @param None. - * @retval USB_SUCCESS if the request is performed. - * USB_UNSUPPORT if the request is invalid. - */ -RESULT Standard_SetInterface(void) -{ - RESULT Re; - /*Test if the specified Interface and Alternate Setting are supported by - the application Firmware*/ - Re = (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, pInformation->USBwValue0); - - if (pInformation->Current_Configuration != 0) - { - if ((Re != USB_SUCCESS) || (pInformation->USBwIndex1 != 0) - || (pInformation->USBwValue1 != 0)) - { - return USB_UNSUPPORT; - } - else if (Re == USB_SUCCESS) - { - pUser_Standard_Requests->User_SetInterface(); - pInformation->Current_Interface = pInformation->USBwIndex0; - pInformation->Current_AlternateSetting = pInformation->USBwValue0; - return USB_SUCCESS; - } - - } - - return USB_UNSUPPORT; -} - -/** - * @brief Copy the device request data to "StatusInfo buffer". - * @param Length: How many bytes are needed. - * @retval 0 if the Length is 0. - * status address if Length is valid. - */ -uint8_t *Standard_GetStatus(uint16_t Length) -{ - if (Length == 0) - { - pInformation->Ctrl_Info.Usb_wLength = 2; - return 0; - } - - /* Reset Status Information */ - StatusInfo.w = 0; - - if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) - { - /*Get Device Status */ - uint8_t Feature = pInformation->Current_Feature; - - /* Remote Wakeup enabled */ - if (ValBit(Feature, 5)) - { - SetBit(StatusInfo0, 1); - } - else - { - ClrBit(StatusInfo0, 1); - } - - /* Bus-powered */ - if (ValBit(Feature, 6)) - { - SetBit(StatusInfo0, 0); - } - else /* Self-powered */ - { - ClrBit(StatusInfo0, 0); - } - } - /*Interface Status*/ - else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) - { - return (uint8_t *)&StatusInfo; - } - /*Get EndPoint Status*/ - else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) - { - uint8_t Related_Endpoint; - uint8_t wIndex0 = pInformation->USBwIndex0; - - Related_Endpoint = (wIndex0 & 0x0f); - if (ValBit(wIndex0, 7)) - { - /* IN endpoint */ - if (_GetTxStallStatus(Related_Endpoint)) - { - SetBit(StatusInfo0, 0); /* IN Endpoint stalled */ - } - } - else - { - /* OUT endpoint */ - if (_GetRxStallStatus(Related_Endpoint)) - { - SetBit(StatusInfo0, 0); /* OUT Endpoint stalled */ - } - } - - } - else - { - return NULL; - } - pUser_Standard_Requests->User_GetStatus(); - return (uint8_t *)&StatusInfo; -} - -/** - * @brief Clear or disable a specific feature. - * @param None. - * @retval USB_SUCCESS if the request is performed. - * USB_UNSUPPORT if the request is invalid. - */ -RESULT Standard_ClearFeature(void) -{ - uint32_t Type_Rec = Type_Recipient; - uint32_t Status; - - - if (Type_Rec == (STANDARD_REQUEST | DEVICE_RECIPIENT)) - {/*Device Clear Feature*/ - ClrBit(pInformation->Current_Feature, 5); - return USB_SUCCESS; - } - else if (Type_Rec == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) - {/*EndPoint Clear Feature*/ - DEVICE* pDev; - uint32_t Related_Endpoint; - uint32_t wIndex0; - uint32_t rEP; - - if ((pInformation->USBwValue != ENDPOINT_STALL) - || (pInformation->USBwIndex1 != 0)) - { - return USB_UNSUPPORT; - } - - pDev = &Device_Table; - wIndex0 = pInformation->USBwIndex0; - rEP = wIndex0 & ~0x80; - Related_Endpoint = ENDP0 + rEP; - - if (ValBit(pInformation->USBwIndex0, 7)) - { - /*Get Status of endpoint & stall the request if the related_ENdpoint - is Disabled*/ - Status = _GetEPTxStatus(Related_Endpoint); - } - else - { - Status = _GetEPRxStatus(Related_Endpoint); - } - - if ((rEP >= pDev->Total_Endpoint) || (Status == 0) - || (pInformation->Current_Configuration == 0)) - { - return USB_UNSUPPORT; - } - - - if (wIndex0 & 0x80) - { - /* IN endpoint */ - if (_GetTxStallStatus(Related_Endpoint )) - { - ClearDTOG_TX(Related_Endpoint); - SetEPTxStatus(Related_Endpoint, EP_TX_VALID); - } - } - else - { - /* OUT endpoint */ - if (_GetRxStallStatus(Related_Endpoint)) - { - if (Related_Endpoint == ENDP0) - { - /* After clear the STALL, enable the default endpoint receiver */ - SetEPRxCount(Related_Endpoint, Device_Property.MaxPacketSize); - _SetEPRxStatus(Related_Endpoint, EP_RX_VALID); - } - else - { - ClearDTOG_RX(Related_Endpoint); - _SetEPRxStatus(Related_Endpoint, EP_RX_VALID); - } - } - } - pUser_Standard_Requests->User_ClearFeature(); - return USB_SUCCESS; - } - - return USB_UNSUPPORT; -} - -/** - * @brief Set or enable a specific feature of EndPoint. - * @param None. - * @retval USB_SUCCESS if the request is performed. - * USB_UNSUPPORT if the request is invalid. - */ -RESULT Standard_SetEndPointFeature(void) -{ - uint32_t wIndex0; - uint32_t Related_Endpoint; - uint32_t rEP; - uint32_t Status; - - wIndex0 = pInformation->USBwIndex0; - rEP = wIndex0 & ~0x80; - Related_Endpoint = ENDP0 + rEP; - - if (ValBit(pInformation->USBwIndex0, 7)) - { - /* get Status of endpoint & stall the request if the related_ENdpoint - is Disabled*/ - Status = _GetEPTxStatus(Related_Endpoint); - } - else - { - Status = _GetEPRxStatus(Related_Endpoint); - } - - if (Related_Endpoint >= Device_Table.Total_Endpoint - || pInformation->USBwValue != 0 || Status == 0 - || pInformation->Current_Configuration == 0) - { - return USB_UNSUPPORT; - } - else - { - if (wIndex0 & 0x80) - { - /* IN endpoint */ - _SetEPTxStatus(Related_Endpoint, EP_TX_STALL); - } - - else - { - /* OUT endpoint */ - _SetEPRxStatus(Related_Endpoint, EP_RX_STALL); - } - } - pUser_Standard_Requests->User_SetEndPointFeature(); - return USB_SUCCESS; -} - -/** - * @brief Set or enable a specific feature of Device. - * @param None. - * @retval USB_SUCCESS if the request is performed. - * USB_UNSUPPORT if the request is invalid. - */ -RESULT Standard_SetDeviceFeature(void) -{ - SetBit(pInformation->Current_Feature, 5); - pUser_Standard_Requests->User_SetDeviceFeature(); - return USB_SUCCESS; -} - -/** - * @brief Standard_GetDescriptorData is used for descriptors transfer. - This routine is used for the descriptors resident in Flash - * or RAM - * pDesc can be in either Flash or RAM - * The purpose of this routine is to have a versatile way to - * response descriptors request. It allows user to generate - * certain descriptors with software or read descriptors from - * external storage part by part. - * @param Length: Length of the data in this transfer. - * @param pDesc: A pointer points to descriptor struct. - * The structure gives the initial address of the descriptor and its original size - * @retval Address of a part of the descriptor pointed by the Usb_wOffset the buffer pointed - * by this address contains at least Length bytes. - */ -uint8_t *Standard_GetDescriptorData(uint16_t Length, ONE_DESCRIPTOR *pDesc) -{ - uint32_t wOffset; - - wOffset = pInformation->Ctrl_Info.Usb_wOffset; - if (Length == 0) - { - pInformation->Ctrl_Info.Usb_wLength = pDesc->Descriptor_Size - wOffset; - return 0; - } - - return pDesc->Descriptor + wOffset; -} - -/** - * @brief Data stage of a Control Write Transfer. - * @param None. - * @retval None. - */ -void DataStageOut(void) -{ - ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info; - uint32_t save_rLength; - - save_rLength = pEPinfo->Usb_rLength; - - if (pEPinfo->CopyData && save_rLength) - { - uint8_t *Buffer; - uint32_t Length; - - Length = pEPinfo->PacketSize; - if (Length > save_rLength) - { - Length = save_rLength; - } - - Buffer = (*pEPinfo->CopyData)(Length); - pEPinfo->Usb_rLength -= Length; - pEPinfo->Usb_rOffset += Length; - PMAToUserBufferCopy(Buffer, GetEPRxAddr(ENDP0), Length); - } - - if (pEPinfo->Usb_rLength != 0) - { - vSetEPRxStatus(EP_RX_VALID);/* re-enable for next data reception */ -// SetEPTxCount(ENDP0, 0); -// vSetEPTxStatus(EP_TX_VALID);/* Expect the host to abort the data OUT stage */ - } - /* Set the next State*/ - if (pEPinfo->Usb_rLength >= pEPinfo->PacketSize) - { - pInformation->ControlState = OUT_DATA; - } - else - { - if (pEPinfo->Usb_rLength > 0) - { - pInformation->ControlState = LAST_OUT_DATA; - } - else if (pEPinfo->Usb_rLength == 0) - { - (*pEPinfo->CopyData)(0); //added to notify write to array finished - pInformation->ControlState = WAIT_STATUS_IN; - USB_StatusIn(); - } - } -} - -/** - * @brief Data stage of a Control Read Transfer. - * @param None. - * @retval None. - */ -void DataStageIn(void) -{ - ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info; - uint32_t save_wLength = pEPinfo->Usb_wLength; - uint32_t ControlState = pInformation->ControlState; - - uint8_t *DataBuffer; - uint32_t Length; - - if ((save_wLength == 0) && (ControlState == LAST_IN_DATA)) - { - if(Data_Mul_MaxPacketSize == TRUE) - { - /* No more data to send and empty packet */ - Send0LengthData(); - ControlState = LAST_IN_DATA; - Data_Mul_MaxPacketSize = FALSE; - } - else - { - /* No more data to send so STALL the TX Status*/ - ControlState = WAIT_STATUS_OUT; - vSetEPTxStatus(EP_TX_STALL); - } - goto Expect_Status_Out; - } - - Length = pEPinfo->PacketSize; - ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA; - - if (Length > save_wLength) - { - Length = save_wLength; - } - - DataBuffer = (*pEPinfo->CopyData)(Length); - - UserToPMABufferCopy(DataBuffer, GetEPTxAddr(ENDP0), Length); - - SetEPTxCount(ENDP0, Length); - - pEPinfo->Usb_wLength -= Length; - pEPinfo->Usb_wOffset += Length; - vSetEPTxStatus(EP_TX_VALID); - - USB_StatusOut();/* Expect the host to abort the data IN stage */ - -Expect_Status_Out: - pInformation->ControlState = ControlState; -} - -/** - * @brief Proceed the processing of setup request without data stage. - * @param None. - * @retval None. - */ -void NoData_Setup0(void) -{ - RESULT Result = USB_UNSUPPORT; - uint32_t RequestNo = pInformation->USBbRequest; - uint32_t ControlState; - - /* Device Request*/ - if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) - { - /* Device Request*/ - /* SET_CONFIGURATION*/ - if (RequestNo == SET_CONFIGURATION) - { - Result = Standard_SetConfiguration(); - } - - /*SET ADDRESS*/ - else if (RequestNo == SET_ADDRESS) - { - if ((pInformation->USBwValue0 > 127) || (pInformation->USBwValue1 != 0) - || (pInformation->USBwIndex != 0) - || (pInformation->Current_Configuration != 0)) - /* Device Address should be 127 or less*/ - { - ControlState = STALLED; - goto exit_NoData_Setup0; - } - else - { - Result = USB_SUCCESS; - } - } - /*SET FEATURE for Device*/ - else if (RequestNo == SET_FEATURE) - { - if ((pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP) \ - && (pInformation->USBwIndex == 0)) - { - Result = Standard_SetDeviceFeature(); - } - else - { - Result = USB_UNSUPPORT; - } - } - /*Clear FEATURE for Device */ - else if (RequestNo == CLEAR_FEATURE) - { - if (pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP - && pInformation->USBwIndex == 0 - && ValBit(pInformation->Current_Feature, 5)) - { - Result = Standard_ClearFeature(); - } - else - { - Result = USB_UNSUPPORT; - } - } - - } - - /* Interface Request*/ - else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) - { - /*SET INTERFACE*/ - if (RequestNo == SET_INTERFACE) - { - Result = Standard_SetInterface(); - } - } - - /* EndPoint Request*/ - else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) - { - /*CLEAR FEATURE for EndPoint*/ - if (RequestNo == CLEAR_FEATURE) - { - Result = Standard_ClearFeature(); - } - /* SET FEATURE for EndPoint*/ - else if (RequestNo == SET_FEATURE) - { - Result = Standard_SetEndPointFeature(); - } - } - else - { - Result = USB_UNSUPPORT; - } - - - if (Result != USB_SUCCESS) - { - Result = (*pProperty->Class_NoData_Setup)(RequestNo); - if (Result == USB_NOT_READY) - { - ControlState = PAUSE; - goto exit_NoData_Setup0; - } - } - - if (Result != USB_SUCCESS) - { - ControlState = STALLED; - goto exit_NoData_Setup0; - } - - ControlState = WAIT_STATUS_IN;/* After no data stage SETUP */ - - USB_StatusIn(); - -exit_NoData_Setup0: - pInformation->ControlState = ControlState; - return; -} - -/** - * @brief Proceed the processing of setup request with data stage. - * @param None. - * @retval None. - */ -void Data_Setup0(void) -{ - uint8_t *(*CopyRoutine)(uint16_t); - RESULT Result; - uint32_t Request_No = pInformation->USBbRequest; - - uint32_t Related_Endpoint, Reserved; - uint32_t wOffset, Status; - - - - CopyRoutine = NULL; - wOffset = 0; - - /*GET DESCRIPTOR*/ - if (Request_No == GET_DESCRIPTOR) - { - if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) - { - uint8_t wValue1 = pInformation->USBwValue1; - if (wValue1 == DEVICE_DESCRIPTOR) - { - CopyRoutine = pProperty->GetDeviceDescriptor; - } - else if (wValue1 == CONFIG_DESCRIPTOR) - { - CopyRoutine = pProperty->GetConfigDescriptor; - } - else if (wValue1 == STRING_DESCRIPTOR) - { - CopyRoutine = pProperty->GetStringDescriptor; - } /* End of GET_DESCRIPTOR */ - } - } - - /*GET STATUS*/ - else if ((Request_No == GET_STATUS) && (pInformation->USBwValue == 0) - && (pInformation->USBwLength == 0x0002) - && (pInformation->USBwIndex1 == 0)) - { - /* GET STATUS for Device*/ - if ((Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) - && (pInformation->USBwIndex == 0)) - { - CopyRoutine = Standard_GetStatus; - } - - /* GET STATUS for Interface*/ - else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) - { - if (((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, 0) == USB_SUCCESS) - && (pInformation->Current_Configuration != 0)) - { - CopyRoutine = Standard_GetStatus; - } - } - - /* GET STATUS for EndPoint*/ - else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) - { - Related_Endpoint = (pInformation->USBwIndex0 & 0x0f); - Reserved = pInformation->USBwIndex0 & 0x70; - - if (ValBit(pInformation->USBwIndex0, 7)) - { - /*Get Status of endpoint & stall the request if the related_ENdpoint - is Disabled*/ - Status = _GetEPTxStatus(Related_Endpoint); - } - else - { - Status = _GetEPRxStatus(Related_Endpoint); - } - - if ((Related_Endpoint < Device_Table.Total_Endpoint) && (Reserved == 0) - && (Status != 0)) - { - CopyRoutine = Standard_GetStatus; - } - } - - } - - /*GET CONFIGURATION*/ - else if (Request_No == GET_CONFIGURATION) - { - if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) - { - CopyRoutine = Standard_GetConfiguration; - } - } - /*GET INTERFACE*/ - else if (Request_No == GET_INTERFACE) - { - if ((Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) - && (pInformation->Current_Configuration != 0) && (pInformation->USBwValue == 0) - && (pInformation->USBwIndex1 == 0) && (pInformation->USBwLength == 0x0001) - && ((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, 0) == USB_SUCCESS)) - { - CopyRoutine = Standard_GetInterface; - } - - } - - if (CopyRoutine) - { - pInformation->Ctrl_Info.Usb_wOffset = wOffset; - pInformation->Ctrl_Info.CopyData = CopyRoutine; - /* sb in the original the cast to word was directly */ - /* now the cast is made step by step */ - (*CopyRoutine)(0); - Result = USB_SUCCESS; - } - else - { - Result = (*pProperty->Class_Data_Setup)(pInformation->USBbRequest); - if (Result == USB_NOT_READY) - { - pInformation->ControlState = PAUSE; - return; - } - } - - if (pInformation->Ctrl_Info.Usb_wLength == 0xFFFF) - { - /* Data is not ready, wait it */ - pInformation->ControlState = PAUSE; - return; - } - if ((Result == USB_UNSUPPORT) || (pInformation->Ctrl_Info.Usb_wLength == 0)) - { - /* Unsupported request */ - pInformation->ControlState = STALLED; - return; - } - - - if (ValBit(pInformation->USBbmRequestType, 7)) - { - /* Device ==> Host */ - __IO uint32_t wLength = pInformation->USBwLength; - - /* Restrict the data length to be the one host asks for */ - if (pInformation->Ctrl_Info.Usb_wLength > wLength) - { - pInformation->Ctrl_Info.Usb_wLength = wLength; - } - - else if (pInformation->Ctrl_Info.Usb_wLength < pInformation->USBwLength) - { - if (pInformation->Ctrl_Info.Usb_wLength < pProperty->MaxPacketSize) - { - Data_Mul_MaxPacketSize = FALSE; - } - else if ((pInformation->Ctrl_Info.Usb_wLength % pProperty->MaxPacketSize) == 0) - { - Data_Mul_MaxPacketSize = TRUE; - } - } - - pInformation->Ctrl_Info.PacketSize = pProperty->MaxPacketSize; - DataStageIn(); - } - else - { - pInformation->ControlState = OUT_DATA; - vSetEPRxStatus(EP_RX_VALID); /* enable for next data reception */ - } - - return; -} - -/** - * @brief Get the device request data and dispatch to individual process. - * @param None. - * @retval None. - */ -uint8_t Setup0_Process(void) -{ - - union - { - uint8_t* b; - uint16_t* w; - } pBuf; - uint16_t offset = 1; - - pBuf.b = PMAAddr + (uint8_t *)(_GetEPRxAddr(ENDP0) * 2); /* *2 for 32 bits addr */ - - if (pInformation->ControlState != PAUSE) - { - pInformation->USBbmRequestType = *pBuf.b++; /* bmRequestType */ - pInformation->USBbRequest = *pBuf.b++; /* bRequest */ - pBuf.w += offset; /* word not accessed because of 32 bits addressing */ - pInformation->USBwValue = ByteSwap(*pBuf.w++); /* wValue */ - pBuf.w += offset; /* word not accessed because of 32 bits addressing */ - pInformation->USBwIndex = ByteSwap(*pBuf.w++); /* wIndex */ - pBuf.w += offset; /* word not accessed because of 32 bits addressing */ - pInformation->USBwLength = *pBuf.w; /* wLength */ - } - - pInformation->ControlState = SETTING_UP; - if (pInformation->USBwLength == 0) - { - /* Setup with no data stage */ - NoData_Setup0(); - } - else - { - /* Setup with data stage */ - Data_Setup0(); - } - return Post0_Process(); -} - -/** - * @brief Process the IN token on all default endpoint. - * @param None. - * @retval None. - */ -uint8_t In0_Process(void) -{ - uint32_t ControlState = pInformation->ControlState; - - if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA)) - { - DataStageIn(); - /* ControlState may be changed outside the function */ - ControlState = pInformation->ControlState; - } - - else if (ControlState == WAIT_STATUS_IN) - { - if ((pInformation->USBbRequest == SET_ADDRESS) && - (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))) - { - SetDeviceAddress(pInformation->USBwValue0); - pUser_Standard_Requests->User_SetDeviceAddress(); - } - (*pProperty->Process_Status_IN)(); - ControlState = STALLED; - } - - else - { - ControlState = STALLED; - } - - pInformation->ControlState = ControlState; - - return Post0_Process(); -} - -/** - * @brief Process the OUT token on all default endpoint. - * @param None. - * @retval None. - */ -uint8_t Out0_Process(void) -{ - uint32_t ControlState = pInformation->ControlState; - - if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA)) - { - /* host aborts the transfer before finish */ - ControlState = STALLED; - } - else if ((ControlState == OUT_DATA) || (ControlState == LAST_OUT_DATA)) - { - DataStageOut(); - ControlState = pInformation->ControlState; /* may be changed outside the function */ - } - - else if (ControlState == WAIT_STATUS_OUT) - { - (*pProperty->Process_Status_OUT)(); - ControlState = STALLED; - } - - - /* Unexpect state, STALL the endpoint */ - else - { - ControlState = STALLED; - } - - pInformation->ControlState = ControlState; - - return Post0_Process(); -} - -/** - * @brief Stall the Endpoint 0 in case of error. - * @param None. - * @retval 0 if the control state is in PAUSE. - * 1 if not. - */ -uint8_t Post0_Process(void) -{ - - SetEPRxCount(ENDP0, Device_Property.MaxPacketSize); - /*no need set to STALL*/ - if (pInformation->ControlState == STALLED) - { - vSetEPRxStatus(EP_RX_STALL); - vSetEPTxStatus(EP_TX_STALL); - } - - return (pInformation->ControlState == PAUSE); -} - -/** - * @brief Set the device and all the used Endpoints addresses. - * @param Val: the device address - * @retval None. - */ -void SetDeviceAddress(uint8_t Val) -{ - uint32_t i; - uint32_t nEP = Device_Table.Total_Endpoint; - - /* set address in every used endpoint */ - for (i = 0; i < nEP; i++) - { - _SetEPAddress((uint8_t)i, (uint8_t)i); - } /* for */ - _SetDEVADR(Val | DEVADR_EN); /* set device address and enable function */ -} -/** - * @brief No operation function. - * @param None. - * @retval None. - */ -void NOP_Process(void) -{ -} - - diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/src/usb_init.c b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/src/usb_init.c deleted file mode 100644 index 673abe3..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/src/usb_init.c +++ /dev/null @@ -1,103 +0,0 @@ -/** - ****************************************************************************** - * File : usb_init.c - * Version: V1.2.2 - * Date : 2020-07-01 - * Brief : Initialization routines & global variables - ****************************************************************************** - */ - - -/* Includes ------------------------------------------------------------------*/ -#include "usb_lib.h" - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -/* The number of current endpoint, it will be used to specify an endpoint */ - uint8_t EPindex; -/* The number of current device, it is an index to the Device_Table */ -/* uint8_t Device_no; */ -/* Points to the DEVICE_INFO structure of current device */ -/* The purpose of this register is to speed up the execution */ -DEVICE_INFO *pInformation; -/* Points to the DEVICE_PROP structure of current device */ -/* The purpose of this register is to speed up the execution */ -DEVICE_PROP *pProperty; -/* Temporary save the state of Rx & Tx status. */ -/* Whenever the Rx or Tx state is changed, its value is saved */ -/* in this variable first and will be set to the EPRB or EPRA */ -/* at the end of interrupt process */ -uint16_t SaveState ; -uint16_t wInterrupt_Mask; -DEVICE_INFO Device_Info; -USER_STANDARD_REQUESTS *pUser_Standard_Requests; - -/* Extern variables ----------------------------------------------------------*/ -/* Private function prototypes -----------------------------------------------*/ -/* Private functions ---------------------------------------------------------*/ - -/******************************************************************************* -* Function Name : USB_Init -* Description : USB system initialization -* Input : None. -* Output : None. -* Return : None. -*******************************************************************************/ - -/* Re-enumerate the USB */ -void reenumerate() { - // pinMode(PA12, OUTPUT); - GPIO_InitType GPIO_InitStruct = {0}; - GPIO_InitStruct.GPIO_Pins = GPIO_Pins_12; - GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_PU; - GPIO_InitStruct.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_WriteBit(GPIOA, GPIO_Pins_12, Bit_RESET); //Blue Pill - for(int i=0;i<1512;i++){}; - - GPIO_InitStruct.GPIO_Pins = GPIO_Pins_12; - GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; - GPIO_InitStruct.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStruct); - - for(int i=0;i<512;i++){}; -} - -void USB_BluePill_Reenumerate() -{ - //__HAL_RCC_GPIOA_CLK_ENABLE(); - - GPIO_InitType GPIO_InitStruct = {0}; - - GPIO_InitStruct.GPIO_Pins = GPIO_Pins_12; - GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT_OD; - GPIO_InitStruct.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz; - GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_WriteBit(GPIOA, GPIO_Pins_12, Bit_RESET); - //HAL_Delay(1); -} - -/** - * @brief USB system initialization. - * @param None. - * @retval None. - */ -void USB_Init(void) -{ - //reenumerate(); - //USB_BluePill_Reenumerate(); - pInformation = &Device_Info; - pInformation->ControlState = 2; - pProperty = &Device_Property; - pUser_Standard_Requests = &User_Standard_Requests; - /* Initialize devices one by one */ - pProperty->Init(); - //reenumerate(); - //USB_BluePill_Reenumerate(); -} - - diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/src/usb_int.c b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/src/usb_int.c deleted file mode 100644 index 1358e90..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/src/usb_int.c +++ /dev/null @@ -1,176 +0,0 @@ -/** - ****************************************************************************** - * File : usb_int.c - * Version: V1.2.2 - * Date : 2020-07-01 - * Brief : Endpoint CTRF (Low and High) interrupt's service routines - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "usb_lib.h" - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -__IO uint16_t SaveRState; -__IO uint16_t SaveTState; - -/* Extern variables ----------------------------------------------------------*/ -extern void (*pEpInt_IN[7])(void); /* Handles IN interrupts */ -extern void (*pEpInt_OUT[7])(void); /* Handles OUT interrupts */ - -/* Private function prototypes -----------------------------------------------*/ -/* Private functions ---------------------------------------------------------*/ - -/** - * @brief Low priority Endpoint Correct Transfer interrupt's service. - * routine. - * @param None. - * @retval None. - */ -void CTR_LP(void) -{ - __IO uint16_t wEPVal = 0; - /* stay in loop while pending interrupts */ - while (((wIstr = _GetINTSTS()) & INTSTS_CTFR) != 0) - { - /* extract highest priority endpoint number */ - EPindex = (uint8_t)(wIstr & INTSTS_EP_ID); - if (EPindex != 0 ) - { - /* Decode and service non control endpoints interrupt */ - - /* process related endpoint register */ - wEPVal = _GetENDPOINT(EPindex); - if ((wEPVal & EP_CTFR_TX) != 0) - { - /* clear int flag */ - _ClearEP_CTFR_TX(EPindex); - - /* call IN service function */ - (*pEpInt_IN[EPindex-1])(); - continue; - } /* if((wEPVal & EP_CTFR_TX) != 0) */ - - if ((wEPVal & EP_CTFR_RX) != 0) - { - /* clear int flag */ - _ClearEP_CTFR_RX(EPindex); - - /* call OUT service function */ - (*pEpInt_OUT[EPindex-1])(); - - } /* if((wEPVal & EP_CTFR_RX) */ - - }/* if(EPindex != 0) */ - else - { - /* Decode and service control endpoint interrupt */ - /* calling related service routine */ - /* (Setup0_Process, In0_Process, Out0_Process) */ - - /* save RX & TX status */ - /* and set both to NAK */ - - SaveRState = _GetENDPOINT(ENDP0); - SaveTState = SaveRState & EP_STS_TX; - SaveRState &= EP_STS_RX; - - _SetEPRxTxStatus(ENDP0,EP_RX_NAK,EP_TX_NAK); - - /* DIR bit = origin of the interrupt */ - - if ((wIstr & INTSTS_DIR) == 0) - { - /* DIR = 0 */ - - /* DIR = 0 => IN int */ - /* DIR = 0 implies that (EP_CTFR_TX = 1) always */ - - _ClearEP_CTFR_TX(ENDP0); - In0_Process(); - - /* before terminate set Tx & Rx status */ - - _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState); - return; - } - else - { - /* DIR = 1 */ - - /* DIR = 1 & CTR_RX => SETUP or OUT int */ - /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */ - - wEPVal = _GetENDPOINT(ENDP0); - - if ((wEPVal &EP_SETUP) != 0) - { - _ClearEP_CTFR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */ - Setup0_Process(); - /* before terminate set Tx & Rx status */ - - _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState); - return; - } - - else if ((wEPVal & EP_CTFR_RX) != 0) - { - _ClearEP_CTFR_RX(ENDP0); - Out0_Process(); - /* before terminate set Tx & Rx status */ - - _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState); - return; - } - } - }/* if(EPindex != 0) else */ - - }/* while(...) */ -} - -/** - * @brief High Priority Endpoint Correct Transfer interrupt's service. - * routine. - * @param None. - * @retval None. - */ -void CTR_HP(void) -{ - uint32_t wEPVal = 0; - - while (((wIstr = _GetINTSTS()) & INTSTS_CTFR) != 0) - { - _SetINTSTS((uint16_t)CLR_CTFR); /* clear CTR flag */ - /* extract highest priority endpoint number */ - EPindex = (uint8_t)(wIstr & INTSTS_EP_ID); - if ( EPindex == 0 ) - return; - /* process related endpoint register */ - wEPVal = _GetENDPOINT(EPindex); - if ((wEPVal & EP_CTFR_RX) != 0) - { - /* clear int flag */ - _ClearEP_CTFR_RX(EPindex); - - /* call OUT service function */ - (*pEpInt_OUT[EPindex-1])(); - - } /* if((wEPVal & EP_CTFR_RX) */ - else if ((wEPVal & EP_CTFR_TX) != 0) - { - /* clear int flag */ - _ClearEP_CTFR_TX(EPindex); - - /* call IN service function */ - (*pEpInt_IN[EPindex-1])(); - - - } /* if((wEPVal & EP_CTFR_TX) != 0) */ - - }/* while(...) */ -} - - diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/src/usb_mem.c b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/src/usb_mem.c deleted file mode 100644 index 58724d8..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/src/usb_mem.c +++ /dev/null @@ -1,65 +0,0 @@ -/** - ****************************************************************************** - * File : usb_mem.c - * Version: V1.2.2 - * Date : 2020-07-01 - * Brief : Utility functions for memory transfers to/from PMA - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "usb_lib.h" - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -/* Extern variables ----------------------------------------------------------*/ -/* Private function prototypes -----------------------------------------------*/ -/* Private functions ---------------------------------------------------------*/ - -/** - * @brief Copy a buffer from user memory area to packet memory area (PMA). - * @param pbUsrBuf: pointer to user memory area. - * @param wPMABufAddr: address into PMA. - * @param wNBytes: number of bytes to be copied. - * @retval None. - */ -void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) -{ - uint32_t n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */ - uint32_t i, temp1, temp2; - uint16_t *pdwVal; - pdwVal = (uint16_t *)(wPMABufAddr * 2 + PMAAddr); - for (i = n; i != 0; i--) - { - temp1 = (uint16_t) * pbUsrBuf; - pbUsrBuf++; - temp2 = temp1 | (uint16_t) * pbUsrBuf << 8; - *pdwVal++ = temp2; - pdwVal++; - pbUsrBuf++; - } -} - -/** - * @brief Copy a buffer from packet memory area (PMA) to user memory area. - * @param pbUsrBuf: pointer to user memory area. - * @param wPMABufAddr: address into PMA. - * @param wNBytes: number of bytes to be copied. - * @retval None. - */ -void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) -{ - uint32_t n = (wNBytes + 1) >> 1;/* /2*/ - uint32_t i; - uint32_t *pdwVal; - pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr); - for (i = n; i != 0; i--) - { - *(uint16_t*)pbUsrBuf++ = *pdwVal++; - pbUsrBuf++; - } -} - - diff --git a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/src/usb_regs.c b/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/src/usb_regs.c deleted file mode 100644 index 05cd858..0000000 --- a/.platformio/packages/framework-cmsis-at32f43/libraries/AT32_USB-FS-Device_Driver/src/usb_regs.c +++ /dev/null @@ -1,692 +0,0 @@ -/** - ****************************************************************************** - * File : usb_reg.c - * Version: V1.2.2 - * Date : 2020-07-01 - * Brief : Interface functions to USB cell registers - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "usb_lib.h" - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -/* Extern variables ----------------------------------------------------------*/ -int PMAAddr = 0x40006000; -/* Private function prototypes -----------------------------------------------*/ -/* Private functions ---------------------------------------------------------*/ - -/** - * @brief Set the CTRL register value. - * @param wRegValue: new register value. - * @retval None. - */ -void SetCTRL(uint16_t wRegValue) -{ - _SetCTRL(wRegValue); -} - -/** - * @brief returns the CTRL register value. - * @param None. - * @retval CTRL register Value.. - */ -uint16_t GetCTRL(void) -{ - return(_GetCTRL()); -} - -/** - * @brief Set the INTSTS register value. - * @param wRegValue: new register value. - * @retval None. - */ -void SetINTSTS(uint16_t wRegValue) -{ - _SetINTSTS(wRegValue); -} - -/** - * @brief Returns the INTSTS register value. - * @param None. - * @retval INTSTS register Value. - */ -uint16_t GetINTSTS(void) -{ - return(_GetINTSTS()); -} - -/** - * @brief Returns the FRNUM register value. - * @param None. - * @retval FRNUM register Value. - */ -uint16_t GetFRNUM(void) -{ - return(_GetFRNUM()); -} - -/** - * @brief Set the DEVADR register value. - * @param wRegValue: new register value. - * @retval None. - */ -void SetDEVADR(uint16_t wRegValue) -{ - _SetDEVADR(wRegValue); -} - -/** - * @brief Returns the DEVADR register value. - * @param None. - * @retval DEVADR register Value. - */ -uint16_t GetDEVADR(void) -{ - return(_GetDEVADR()); -} - -/** - * @brief Set the BUFTBL. - * @param wRegValue: New register value. - * @retval None. - */ -void SetBUFTBL(uint16_t wRegValue) -{ - _SetBUFTBL(wRegValue); -} - -/** - * @brief Returns the BUFTBL register value. - * @param None - * @retval BUFTBL address. - */ -uint16_t GetBUFTBL(void) -{ - return(_GetBUFTBL()); -} - -/** - * @brief Set the Endpoint register value. - * @param bEpNum: Endpoint Number. - * @param wRegValue: New register value. - * @retval None. - */ -void SetENDPOINT(uint8_t bEpNum, uint16_t wRegValue) -{ - _SetENDPOINT(bEpNum, wRegValue); -} - -/** - * @brief Return the Endpoint register value. - * @param bEpNum: Endpoint Number. - * @retval Endpoint register value. - */ -uint16_t GetENDPOINT(uint8_t bEpNum) -{ - return(_GetENDPOINT(bEpNum)); -} - -/** - * @brief sets the type in the endpoint register. - * @param bEpNum: Endpoint Number. - * @param wType: type definition. - * @retval None. - */ -void SetEPType(uint8_t bEpNum, uint16_t wType) -{ - _SetEPType(bEpNum, wType); -} - -/** - * @brief Returns the endpoint type. - * @param bEpNum: Endpoint Number. - * @retval Endpoint Type. - */ -uint16_t GetEPType(uint8_t bEpNum) -{ - return(_GetEPType(bEpNum)); -} - -/** - * @brief Set the status of Tx endpoint. - * @param bEpNum: Endpoint Number. - * @param wState: new state. - * @retval None. - */ -void SetEPTxStatus(uint8_t bEpNum, uint16_t wState) -{ - _SetEPTxStatus(bEpNum, wState); -} - -/** - * @brief Set the status of Rx endpoint. - * @param bEpNum: Endpoint Number. - * @param wState: new state. - * @retval None. - */ -void SetEPRxStatus(uint8_t bEpNum, uint16_t wState) -{ - _SetEPRxStatus(bEpNum, wState); -} - -/** - * @brief sets the status for Double Buffer Endpoint to STALL - * @param bEpNum: Endpoint Number. - * @param bDir: Endpoint direction. - * @retval None. - */ -void SetDouBleBuffEPStall(uint8_t bEpNum, uint8_t bDir) -{ - uint16_t Endpoint_DTOG_Status; - Endpoint_DTOG_Status = GetENDPOINT(bEpNum); - if (bDir == EP_DBUF_OUT) - { /* OUT double buffered endpoint */ - _SetENDPOINT(bEpNum, Endpoint_DTOG_Status & ~EPRX_DTOG1); - } - else if (bDir == EP_DBUF_IN) - { /* IN double buffered endpoint */ - _SetENDPOINT(bEpNum, Endpoint_DTOG_Status & ~EPTX_DTOG1); - } -} - -/** - * @brief Returns the endpoint Tx status. - * @param bEpNum: Endpoint Number. - * @retval Endpoint TX Status. - */ -uint16_t GetEPTxStatus(uint8_t bEpNum) -{ - return(_GetEPTxStatus(bEpNum)); -} - -/** - * @brief Returns the endpoint Rx status. - * @param bEpNum: Endpoint Number. - * @retval Endpoint RX Status. - */ -uint16_t GetEPRxStatus(uint8_t bEpNum) -{ - return(_GetEPRxStatus(bEpNum)); -} - -/** - * @brief Valid the endpoint Tx Status. - * @param bEpNum: Endpoint Number. - * @retval None. - */ -void SetEPTxValid(uint8_t bEpNum) -{ - _SetEPTxStatus(bEpNum, EP_TX_VALID); -} - -/** - * @brief Valid the endpoint Rx Status. - * @param bEpNum: Endpoint Number. - * @retval None. - */ -void SetEPRxValid(uint8_t bEpNum) -{ - _SetEPRxStatus(bEpNum, EP_RX_VALID); -} - -/** - * @brief Clear the EP_SUBTYPE bit. - * @param bEpNum: Endpoint Number. - * @retval None. - */ -void SetEP_SUBTYPE(uint8_t bEpNum) -{ - _SetEP_SUBTYPE(bEpNum); -} - -/** - * @brief set the EP_SUBTYPE bit. - * @param bEpNum: Endpoint Number. - * @retval None. - */ -void ClearEP_SUBTYPE(uint8_t bEpNum) -{ - _ClearEP_SUBTYPE(bEpNum); -} - -/** - * @brief Clear the Status Out of the related Endpoint - * @param bEpNum: Endpoint Number. - * @retval None. - */ -void Clear_Status_Out(uint8_t bEpNum) -{ - _ClearEP_SUBTYPE(bEpNum); -} - -/** - * @brief Set the Status Out of the related Endpoint - * @param bEpNum: Endpoint Number. - * @retval None. - */ -void Set_Status_Out(uint8_t bEpNum) -{ - _SetEP_SUBTYPE(bEpNum); -} - -/** - * @brief Enable the double buffer feature for the endpoint. - * @param bEpNum: Endpoint Number. - * @retval None. - */ -void SetEPDoubleBuff(uint8_t bEpNum) -{ - _SetEP_SUBTYPE(bEpNum); -} - -/** - * @brief Disable the double buffer feature for the endpoint. - * @param bEpNum: Endpoint Number. - * @retval None. - */ -void ClearEPDoubleBuff(uint8_t bEpNum) -{ - _ClearEP_SUBTYPE(bEpNum); -} - -/** - * @brief Returns the Stall status of the Tx endpoint. - * @param bEpNum: Endpoint Number. - * @retval Tx Stall status. - */ -uint16_t GetTxStallStatus(uint8_t bEpNum) -{ - return(_GetTxStallStatus(bEpNum)); -} - -/** - * @brief Returns the Stall status of the Rx endpoint. - * @param bEpNum: Endpoint Number. - * @retval Rx Stall status. - */ -uint16_t GetRxStallStatus(uint8_t bEpNum) -{ - return(_GetRxStallStatus(bEpNum)); -} - -/** - * @brief Clear the CTRF_RX bit. - * @param bEpNum: Endpoint Number. - * @retval None. - */ -void ClearEP_CTFR_RX(uint8_t bEpNum) -{ - _ClearEP_CTFR_RX(bEpNum); -} - -/** - * @brief Clear the CTRF_TX bit. - * @param bEpNum: Endpoint Number. - * @retval None. - */ -void ClearEP_CTFR_TX(uint8_t bEpNum) -{ - _ClearEP_CTFR_TX(bEpNum); -} - -/** - * @brief Toggle the DTOG_RX bit. - * @param bEpNum: Endpoint Number. - * @retval None. - */ -void ToggleDTOG_RX(uint8_t bEpNum) -{ - _ToggleDTOG_RX(bEpNum); -} - -/** - * @brief Toggle the DTOG_TX bit. - * @param bEpNum: Endpoint Number. - * @retval None. - */ -void ToggleDTOG_TX(uint8_t bEpNum) -{ - _ToggleDTOG_TX(bEpNum); -} - -/** - * @brief Clear the DTOG_RX bit. - * @param bEpNum: Endpoint Number. - * @retval None. - */ -void ClearDTOG_RX(uint8_t bEpNum) -{ - _ClearDTOG_RX(bEpNum); -} - -/** - * @brief Clear the DTOG_TX bit. - * @param bEpNum: Endpoint Number. - * @retval None. - */ -void ClearDTOG_TX(uint8_t bEpNum) -{ - _ClearDTOG_TX(bEpNum); -} - -/** - * @brief Set the endpoint address. - * @param bEpNum: Endpoint Number. - * @param bAddr: New endpoint address. - * @retval None. - */ -void SetEPAddress(uint8_t bEpNum, uint8_t bAddr) -{ - _SetEPAddress(bEpNum, bAddr); -} - -/** - * @brief Get the endpoint address. - * @param bEpNum: Endpoint Number. - * @retval Endpoint address. - */ -uint8_t GetEPAddress(uint8_t bEpNum) -{ - return(_GetEPAddress(bEpNum)); -} - -/** - * @brief Set the endpoint Tx buffer address. - * @param bEpNum: Endpoint Number. - * @param wAddr: New address. - * @retval None. - */ -void SetEPTxAddr(uint8_t bEpNum, uint16_t wAddr) -{ - _SetEPTxAddr(bEpNum, wAddr); -} - -/** - * @brief Set the endpoint Rx buffer address. - * @param bEpNum: Endpoint Number. - * @param wAddr: New address. - * @retval None. - */ -void SetEPRxAddr(uint8_t bEpNum, uint16_t wAddr) -{ - _SetEPRxAddr(bEpNum, wAddr); -} - -/** - * @brief Returns the endpoint Tx buffer address. - * @param bEpNum: Endpoint Number. - * @retval Tx buffer address. - */ -uint16_t GetEPTxAddr(uint8_t bEpNum) -{ - return(_GetEPTxAddr(bEpNum)); -} - -/** - * @brief Returns the endpoint Rx buffer address. - * @param bEpNum: Endpoint Number. - * @retval Rx buffer address. - */ -uint16_t GetEPRxAddr(uint8_t bEpNum) -{ - return(_GetEPRxAddr(bEpNum)); -} - -/** - * @brief Set the Tx count. - * @param bEpNum: Endpoint Number. - * @param wCount: new count value. - * @retval None. - */ -void SetEPTxCount(uint8_t bEpNum, uint16_t wCount) -{ - _SetEPTxCount(bEpNum, wCount); -} - -/** - * @brief Set the Count Rx Register value. - * @param *pdwReg: point to the register. - * @param wCount: the new register value. - * @retval None. - */ -void SetEPCountRxReg(uint32_t *pdwReg, uint16_t wCount) -{ - _SetEPCountRxReg(dwReg, wCount); -} - -/** - * @brief Set the Rx count. - * @param bEpNum: Endpoint Number. - * @param wCount: the new count value. - * @retval None. - */ -void SetEPRxCount(uint8_t bEpNum, uint16_t wCount) -{ - _SetEPRxCount(bEpNum, wCount); -} - -/** - * @brief Get the Tx count. - * @param bEpNum: Endpoint Number. - * @retval Tx count value. - */ -uint16_t GetEPTxCount(uint8_t bEpNum) -{ - return(_GetEPTxCount(bEpNum)); -} - -/** - * @brief Get the Rx count. - * @param bEpNum: Endpoint Number. - * @retval Rx count value. - */ -uint16_t GetEPRxCount(uint8_t bEpNum) -{ - return(_GetEPRxCount(bEpNum)); -} - -/** - * @brief Set the addresses of the buffer 0 and 1. - * @param bEpNum: Endpoint Number. - * @param wBuf0Addr: new address of buffer 0. - * @param wBuf1Addr: new address of buffer 1. - * @retval None. - */ -void SetEPDblBuffAddr(uint8_t bEpNum, uint16_t wBuf0Addr, uint16_t wBuf1Addr) -{ - _SetEPDblBuffAddr(bEpNum, wBuf0Addr, wBuf1Addr); -} - -/** - * @brief Set the Buffer 0 address. - * @param bEpNum: Endpoint Number. - * @param wBuf0Addr: new address of buffer 0. - * @retval None. - */ -void SetEPDblBuf0Addr(uint8_t bEpNum, uint16_t wBuf0Addr) -{ - _SetEPDblBuf0Addr(bEpNum, wBuf0Addr); -} - -/** - * @brief Set the Buffer 1 address. - * @param bEpNum: Endpoint Number. - * @param wBuf1Addr: new address of buffer 1. - * @retval None. - */ -void SetEPDblBuf1Addr(uint8_t bEpNum, uint16_t wBuf1Addr) -{ - _SetEPDblBuf1Addr(bEpNum, wBuf1Addr); -} - -/** - * @brief Returns the address of the Buffer 0. - * @param bEpNum: Endpoint Number. - * @retval buffer 0 address. - */ -uint16_t GetEPDblBuf0Addr(uint8_t bEpNum) -{ - return(_GetEPDblBuf0Addr(bEpNum)); -} - -/** - * @brief Returns the address of the Buffer 1. - * @param bEpNum: Endpoint Number. - * @retval buffer 1 address. - */ -uint16_t GetEPDblBuf1Addr(uint8_t bEpNum) -{ - return(_GetEPDblBuf1Addr(bEpNum)); -} - -/** - * @brief Set the number of bytes for a double Buffer endpoint. - * @param bEpNum: Endpoint Number. - * @param bDin: Endpoint dir (IN/OUT). - * @param wCount: buffer count. - * @retval None. - */ -void SetEPDblBuffCount(uint8_t bEpNum, uint8_t bDir, uint16_t wCount) -{ - _SetEPDblBuffCount(bEpNum, bDir, wCount); -} - -/** - * @brief Set the number of bytes for a double Buffer0 endpoint. - * @param bEpNum: Endpoint Number. - * @param bDin: Endpoint dir (IN/OUT). - * @param wCount: buffer count. - * @retval None. - */ -void SetEPDblBuf0Count(uint8_t bEpNum, uint8_t bDir, uint16_t wCount) -{ - _SetEPDblBuf0Count(bEpNum, bDir, wCount); -} - -/** - * @brief Set the number of bytes for a double Buffer1 endpoint. - * @param bEpNum: Endpoint Number. - * @param bDin: Endpoint dir (IN/OUT). - * @param wCount: buffer count. - * @retval None. - */ -void SetEPDblBuf1Count(uint8_t bEpNum, uint8_t bDir, uint16_t wCount) -{ - _SetEPDblBuf1Count(bEpNum, bDir, wCount); -} - -/** - * @brief Returns the number of byte received in the buffer 0 - of a double Buffer endpoint. - * @param bEpNum: Endpoint Number. - * @retval Endpoint Buffer 0 count. - */ -uint16_t GetEPDblBuf0Count(uint8_t bEpNum) -{ - return(_GetEPDblBuf0Count(bEpNum)); -} - -/** - * @brief Returns the number of byte received in the buffer 1 - of a double Buffer endpoint. - * @param bEpNum: Endpoint Number. - * @retval Endpoint Buffer 1 count. - */ -uint16_t GetEPDblBuf1Count(uint8_t bEpNum) -{ - return(_GetEPDblBuf1Count(bEpNum)); -} - -/** - * @brief gets direction of the double buffered endpoint. - * @param bEpNum: Endpoint Number. - * @retval EP_DBUF_OUT, EP_DBUF_IN, - * EP_DBUF_ERR if the endpoint counter not yet programmed. - */ -EP_DBUF_DIR GetEPDblBufDir(uint8_t bEpNum) -{ - if ((uint16_t)(*_pEPRxCount(bEpNum) & 0xFC00) != 0) - return(EP_DBUF_OUT); - else if (((uint16_t)(*_pEPTxCount(bEpNum)) & 0x03FF) != 0) - return(EP_DBUF_IN); - else - return(EP_DBUF_ERR); -} - -/** - * @brief free buffer used from the application realizing it to the line - toggles bit SW_BUF in the double buffered endpoint register. - * @param bEpNum: Endpoint Number. - * @param bDir: Endpoint dir (IN/OUT). - * @retval None. - */ -void FreeUserBuffer(uint8_t bEpNum, uint8_t bDir) -{ - if (bDir == EP_DBUF_OUT) - { /* OUT double buffered endpoint */ - _ToggleDTOG_TX(bEpNum); - } - else if (bDir == EP_DBUF_IN) - { /* IN double buffered endpoint */ - _ToggleDTOG_RX(bEpNum); - } -} - -/** - * @brief merge two byte in a word. - * @param bh: byte high. - * @param bl: bytes low. - * @retval resulted word.. - */ -uint16_t ToWord(uint8_t bh, uint8_t bl) -{ - uint16_t wRet; - wRet = (uint16_t)bl | ((uint16_t)bh << 8); - return(wRet); -} - -/** - * @brief Swap two byte in a word. - * @param wSwW: word to Swap. - * @retval resulted word.. - */ -uint16_t ByteSwap(uint16_t wSwW) -{ - uint8_t bTemp; - uint16_t wRet; - bTemp = (uint8_t)(wSwW & 0xff); - wRet = (wSwW >> 8) | ((uint16_t)bTemp << 8); - return(wRet); -} - -/** - * @brief Set USB SRAM size to 768 byte. - * @param None. - * @retval None.. - */ -void Set_USB768ByteMode(void) -{ - /*Enable 768 Byte, Enable RCC->MISC*/ - RCC->MISC |= 0x1 << 24; - - /*USB SRAM Base address*/ - PMAAddr = 0x40007800; -} - -/** - * @brief Clear USB 768 byte mode, USB SRAM size is 512 byte. - * @param None. - * @retval None.. - */ -void Clear_USB768ByteMode(void) -{ - /*Clear 768 byte mode*/ - RCC->MISC &= ~(0x1 << 24); - - /*USB SRAM Base address*/ - PMAAddr = 0x40006000; -} diff --git a/.platformio/packages/framework-cmsis-at32f43/tools/platformio/platformio-build.py b/.platformio/packages/framework-cmsis-at32f43/tools/platformio/platformio-build.py index 0b9a9e6..da0effb 100644 --- a/.platformio/packages/framework-cmsis-at32f43/tools/platformio/platformio-build.py +++ b/.platformio/packages/framework-cmsis-at32f43/tools/platformio/platformio-build.py @@ -59,6 +59,9 @@ env.Append( "-fno-exceptions", ], CPPPATH=[ + join(FRAMEWORK_DIR, "libraries", "AT32F43x_StdPeriph_Driver", "include"), + join(FRAMEWORK_DIR, "libraries", "AT32F43x_USB-Device_Driver", "include"), + join(FRAMEWORK_DIR, "libraries", "AT32F435_437_board"), ], LIBS=[ "c", @@ -86,18 +89,20 @@ env.Append(ASFLAGS=env.get("CCFLAGS", [])[:]) # Target: Build Core Library # + libs = [] -libs.append( - env.BuildLibrary( +libs.append(env.BuildLibrary( join("$BUILD_DIR", "AT32F43x_StdPeriph"), join(FRAMEWORK_DIR, "libraries", "AT32F43x_StdPeriph_Driver") - ) -) + )) +libs.append(env.BuildLibrary( + join("$BUILD_DIR", "AT32F43x_USB-Device"), join(FRAMEWORK_DIR, "libraries", "AT32F43x_USB-Device_Driver") + )) +libs.append(env.BuildLibrary( + join("$BUILD_DIR", "AT32F435_437_board"), join(FRAMEWORK_DIR, "libraries", "AT32F435_437_board") + )) -#libs.append( - #env.BuildLibrary( - #join("$BUILD_DIR", "AT32_USB-FS-Device"), join(FRAMEWORK_DIR, "libraries", "AT32_USB-FS-Device_Driver") - #) -#) + +#print("BuildLibrary(): " + env.subst(join(FRAMEWORK_DIR, "libraries", "AT32F43x_USB-FS-Device_Driver")) ) env.Prepend(LIBS=libs) diff --git a/.platformio/platforms/at32/boards/generic_f435.json b/.platformio/platforms/at32/boards/generic_f435.json index 58eb2e2..d8bb88e 100644 --- a/.platformio/platforms/at32/boards/generic_f435.json +++ b/.platformio/platforms/at32/boards/generic_f435.json @@ -2,7 +2,7 @@ "build": { "core": "at32", "cpu": "cortex-m4", - "extra_flags": "-DAT32F435CGT7", + "extra_flags": "-DAT32F435CGT7 -DAT_START_F435_V1", "f_cpu": "288000000L", "hwids": [ [ diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/.gitignore b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/.gitignore similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/.gitignore rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/.gitignore diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/.travis.yml b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/.travis.yml similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/.travis.yml rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/.travis.yml diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/.vscode/c_cpp_properties.json b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/.vscode/c_cpp_properties.json similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/.vscode/c_cpp_properties.json rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/.vscode/c_cpp_properties.json diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/.vscode/extensions.json b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/.vscode/extensions.json similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/.vscode/extensions.json rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/.vscode/extensions.json diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/.vscode/launch.json b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/.vscode/launch.json similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/.vscode/launch.json rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/.vscode/launch.json diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/.vscode/settings.json b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/.vscode/settings.json similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/.vscode/settings.json rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/.vscode/settings.json diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/README.rst b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/README.rst similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/README.rst rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/README.rst diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/include/README b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/include/README similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/include/README rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/include/README diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/include/at32f435_437_clock.h b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/include/at32f435_437_clock.h similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/include/at32f435_437_clock.h rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/include/at32f435_437_clock.h diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/include/at32f435_437_conf.h b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/include/at32f435_437_conf.h similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/include/at32f435_437_conf.h rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/include/at32f435_437_conf.h diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/include/at32f435_437_int.h b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/include/at32f435_437_int.h similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/include/at32f435_437_int.h rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/include/at32f435_437_int.h diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/lib/Delay/delay.c b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/lib/Delay/delay.c similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/lib/Delay/delay.c rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/lib/Delay/delay.c diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/lib/Delay/delay.h b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/lib/Delay/delay.h similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/lib/Delay/delay.h rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/lib/Delay/delay.h diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/lib/README b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/lib/README similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/lib/README rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/lib/README diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/platformio.ini b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/platformio.ini similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/platformio.ini rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/platformio.ini diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/src/at32f435_437_clock.c b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/src/at32f435_437_clock.c similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/src/at32f435_437_clock.c rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/src/at32f435_437_clock.c diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/src/at32f435_437_int.c b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/src/at32f435_437_int.c similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/src/at32f435_437_int.c rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/src/at32f435_437_int.c diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/src/main.c b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/src/main.c similarity index 66% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/src/main.c rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/src/main.c index d1494c5..376a992 100644 --- a/.platformio/platforms/at32/examples/F435-cmsis-blink/src/main.c +++ b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/src/main.c @@ -2,10 +2,23 @@ #include "at32f435_437_clock.h" #include "delay.h" -#define LEDPERIPH CRM_GPIOB_PERIPH_CLOCK -#define LEDPORT (GPIOB) -#define LEDPIN (GPIO_PINS_12) +#define BLACKPILL // BLUEPILL BLACKPILL QFP48_FLASHER +#ifdef BLUEPILL + #define LEDPERIPH CRM_GPIOC_PERIPH_CLOCK + #define LEDPORT (GPIOC) + #define LEDPIN (GPIO_PINS_13) +#endif +#ifdef BLACKPILL + #define LEDPERIPH CRM_GPIOB_PERIPH_CLOCK + #define LEDPORT (GPIOB) + #define LEDPIN (GPIO_PINS_12) +#endif +#ifdef QFP48_FLASHER + #define LEDPERIPH CRM_GPIOB_PERIPH_CLOCK + #define LEDPORT (GPIOB) + #define LEDPIN (GPIO_PINS_14) +#endif /** * @brief gpio configuration. diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/src/main.h b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/src/main.h similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/src/main.h rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/src/main.h diff --git a/.platformio/platforms/at32/examples/F435-cmsis-blink/test/README b/.platformio/platforms/at32/examples/AT32F435/cmsis-blink/test/README similarity index 100% rename from .platformio/platforms/at32/examples/F435-cmsis-blink/test/README rename to .platformio/platforms/at32/examples/AT32F435/cmsis-blink/test/README diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.gitignore b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.gitignore new file mode 100644 index 0000000..03f4a3c --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.gitignore @@ -0,0 +1 @@ +.pio diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.travis.yml b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.travis.yml new file mode 100644 index 0000000..7c486f1 --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be used as a library with examples. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.vscode/c_cpp_properties.json b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..89ff1e2 --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.vscode/c_cpp_properties.json @@ -0,0 +1,55 @@ +// +// !!! WARNING !!! AUTO-GENERATED FILE! +// PLEASE DO NOT MODIFY IT AND USE "platformio.ini": +// https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags +// +{ + "configurations": [ + { + "name": "PlatformIO", + "includePath": [ + "c:/Users/Xliloz/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/include", + "c:/Users/Xliloz/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/src", + "c:/Users/Xliloz/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/cdc", + "C:/Users/Xliloz/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_StdPeriph_Driver/include", + "C:/Users/Xliloz/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include", + "C:/Users/Xliloz/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F435_437_board", + "C:/Users/Xliloz/.platformio/packages/framework-cmsis@2.50501.200527/CMSIS/Include", + "C:/Users/Xliloz/.platformio/packages/framework-cmsis-at32f43/Include", + "" + ], + "browse": { + "limitSymbolsToIncludedHeaders": true, + "path": [ + "c:/Users/Xliloz/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/include", + "c:/Users/Xliloz/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/src", + "c:/Users/Xliloz/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/cdc", + "C:/Users/Xliloz/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_StdPeriph_Driver/include", + "C:/Users/Xliloz/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F43x_USB-Device_Driver/include", + "C:/Users/Xliloz/.platformio/packages/framework-cmsis-at32f43/libraries/AT32F435_437_board", + "C:/Users/Xliloz/.platformio/packages/framework-cmsis@2.50501.200527/CMSIS/Include", + "C:/Users/Xliloz/.platformio/packages/framework-cmsis-at32f43/Include", + "" + ] + }, + "defines": [ + "PLATFORMIO=50205", + "AT32F435CGT7", + "AT_START_F435_V1", + "" + ], + "cStandard": "c11", + "compilerPath": "C:/Users/Xliloz/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin/arm-none-eabi-gcc.exe", + "compilerArgs": [ + "-mfpu=fpv4-sp-d16", + "-mfloat-abi=hard", + "-mcpu=cortex-m4", + "-mthumb", + "-mfpu=fpv4-sp-d16", + "-mfloat-abi=hard", + "" + ] + } + ], + "version": 4 +} diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.vscode/extensions.json b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.vscode/launch.json b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.vscode/launch.json new file mode 100644 index 0000000..9edd763 --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.vscode/launch.json @@ -0,0 +1,44 @@ +// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY +// +// PIO Unified Debugger +// +// Documentation: https://docs.platformio.org/page/plus/debugging.html +// Configuration: https://docs.platformio.org/page/projectconf/section_env_debug.html + +{ + "version": "0.2.0", + "configurations": [ + { + "type": "platformio-debug", + "request": "launch", + "name": "PIO Debug", + "executable": "c:/Users/Xliloz/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.pio/build/vcp_loopback/firmware.elf", + "projectEnvName": "vcp_loopback", + "toolchainBinDir": "C:/Users/Xliloz/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin", + "internalConsoleOptions": "openOnSessionStart", + "preLaunchTask": { + "type": "PlatformIO", + "task": "Pre-Debug" + } + }, + { + "type": "platformio-debug", + "request": "launch", + "name": "PIO Debug (skip Pre-Debug)", + "executable": "c:/Users/Xliloz/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.pio/build/vcp_loopback/firmware.elf", + "projectEnvName": "vcp_loopback", + "toolchainBinDir": "C:/Users/Xliloz/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin", + "internalConsoleOptions": "openOnSessionStart" + }, + { + "type": "platformio-debug", + "request": "launch", + "name": "PIO Debug (without uploading)", + "executable": "c:/Users/Xliloz/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.pio/build/vcp_loopback/firmware.elf", + "projectEnvName": "vcp_loopback", + "toolchainBinDir": "C:/Users/Xliloz/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin", + "internalConsoleOptions": "openOnSessionStart", + "loadMode": "manual" + } + ] +} diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.vscode/settings.json b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.vscode/settings.json new file mode 100644 index 0000000..9ae3c94 --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "at32f4xx.h": "c" + } +} \ No newline at end of file diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/include/at32f435_437_clock.h b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/include/at32f435_437_clock.h new file mode 100644 index 0000000..39da81e --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/include/at32f435_437_clock.h @@ -0,0 +1,46 @@ +/** + ************************************************************************** + * @file at32f435_437_clock.h + * @version v2.0.4 + * @date 2021-12-31 + * @brief header file of clock program + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ + +/* define to prevent recursive inclusion -------------------------------------*/ +#ifndef __AT32F435_437_CLOCK_H +#define __AT32F435_437_CLOCK_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* includes ------------------------------------------------------------------*/ +#include "at32f435_437.h" + +/* exported functions ------------------------------------------------------- */ +void system_clock_config(void); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_conf.h b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/include/at32f435_437_conf.h similarity index 99% rename from .platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_conf.h rename to .platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/include/at32f435_437_conf.h index 18e8615..4567d0d 100644 --- a/.platformio/packages/framework-cmsis-at32f43/Include/at32f435_437_conf.h +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/include/at32f435_437_conf.h @@ -32,12 +32,13 @@ extern "C" { #endif - /** * @brief in the following line adjust the value of high speed exernal crystal (hext) * used in your application + * * tip: to avoid modifying this file each time you need to use different hext, you * can define the hext value in your toolchain compiler preprocessor. + * */ #if !defined HEXT_VALUE #define HEXT_VALUE ((uint32_t)8000000) /*!< value of the high speed exernal crystal in hz */ @@ -165,11 +166,9 @@ extern "C" { #ifdef USB_MODULE_ENABLED #include "at32f435_437_usb.h" #endif - + #ifdef __cplusplus } #endif -#endif /* __AT32F435_437_CONF_H */ - - +#endif diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/include/at32f435_437_int.h b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/include/at32f435_437_int.h new file mode 100644 index 0000000..6671148 --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/include/at32f435_437_int.h @@ -0,0 +1,58 @@ +/** + ************************************************************************** + * @file at32f435_437_int.h + * @version v2.0.4 + * @date 2021-12-31 + * @brief header file of main interrupt service routines. + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ + +/* define to prevent recursive inclusion -------------------------------------*/ +#ifndef __AT32F435_437_INT_H +#define __AT32F435_437_INT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* includes ------------------------------------------------------------------*/ +#include "at32f435_437.h" + +/* exported types ------------------------------------------------------------*/ +/* exported constants --------------------------------------------------------*/ +/* exported macro ------------------------------------------------------------*/ +/* exported functions ------------------------------------------------------- */ + +void NMI_Handler(void); +void HardFault_Handler(void); +void MemManage_Handler(void); +void BusFault_Handler(void); +void UsageFault_Handler(void); +void SVC_Handler(void); +void DebugMon_Handler(void); +void PendSV_Handler(void); +void SysTick_Handler(void); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/include/usb_conf.h b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/include/usb_conf.h new file mode 100644 index 0000000..f8a27f8 --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/include/usb_conf.h @@ -0,0 +1,218 @@ +/** + ************************************************************************** + * @file usb_conf.h + * @version v2.0.4 + * @date 2021-12-31 + * @brief usb config header file + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ + +/* define to prevent recursive inclusion -------------------------------------*/ +#ifndef __USB_CONF_H +#define __USB_CONF_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "at32f435_437_usb.h" +#include "at32f435_437.h" +#include "stdio.h" + +/** @addtogroup AT32F435_periph_examples + * @{ + */ + +/** @addtogroup 435_USB_device_vcp_loopback + * @{ + */ + +/** + * @brief enable usb device mode + */ +#define USE_OTG_DEVICE_MODE + +/** + * @brief enable usb host mode + */ +/* #define USE_OTG_HOST_MODE */ + +/** + * @brief select otgfs1 or otgfs2 define + */ + +/* use otgfs1 */ +#define OTG_USB_ID 1 + +/* use otgfs2 */ +//#define OTG_USB_ID 2 + +#if (OTG_USB_ID == 1) +#define USB_ID 0 +#define OTG_CLOCK CRM_OTGFS1_PERIPH_CLOCK +#define OTG_IRQ OTGFS1_IRQn +#define OTG_IRQ_HANDLER OTGFS1_IRQHandler +#define OTG_WKUP_IRQ OTGFS1_WKUP_IRQn +#define OTG_WKUP_HANDLER OTGFS1_WKUP_IRQHandler +#define OTG_WKUP_EXINT_LINE EXINT_LINE_18 + +#define OTG_PIN_GPIO GPIOA +#define OTG_PIN_GPIO_CLOCK CRM_GPIOA_PERIPH_CLOCK + +#define OTG_PIN_DP GPIO_PINS_12 +#define OTG_PIN_DP_SOURCE GPIO_PINS_SOURCE12 + +#define OTG_PIN_DM GPIO_PINS_11 +#define OTG_PIN_DM_SOURCE GPIO_PINS_SOURCE11 + +#define OTG_PIN_VBUS GPIO_PINS_9 +#define OTG_PIN_VBUS_SOURCE GPIO_PINS_SOURCE9 + +#define OTG_PIN_ID GPIO_PINS_10 +#define OTG_PIN_ID_SOURCE GPIO_PINS_SOURCE10 + +#define OTG_PIN_SOF_GPIO GPIOA +#define OTG_PIN_SOF_GPIO_CLOCK CRM_GPIOA_PERIPH_CLOCK +#define OTG_PIN_SOF GPIO_PINS_8 +#define OTG_PIN_SOF_SOURCE GPIO_PINS_SOURCE8 + +#define OTG_PIN_MUX GPIO_MUX_10 +#endif + +#if (OTG_USB_ID == 2) +#define USB_ID 1 +#define OTG_CLOCK CRM_OTGFS2_PERIPH_CLOCK +#define OTG_IRQ OTGFS2_IRQn +#define OTG_IRQ_HANDLER OTGFS2_IRQHandler +#define OTG_WKUP_IRQ OTGFS2_WKUP_IRQn +#define OTG_WKUP_HANDLER OTGFS2_WKUP_IRQHandler +#define OTG_WKUP_EXINT_LINE EXINT_LINE_20 + +#define OTG_PIN_GPIO GPIOB +#define OTG_PIN_GPIO_CLOCK CRM_GPIOB_PERIPH_CLOCK + +#define OTG_PIN_DP GPIO_PINS_15 +#define OTG_PIN_DP_SOURCE GPIO_PINS_SOURCE15 + +#define OTG_PIN_DM GPIO_PINS_14 +#define OTG_PIN_DM_SOURCE GPIO_PINS_SOURCE14 + +#define OTG_PIN_VBUS GPIO_PINS_13 +#define OTG_PIN_VBUS_SOURCE GPIO_PINS_SOURCE13 + +#define OTG_PIN_ID GPIO_PINS_12 +#define OTG_PIN_ID_SOURCE GPIO_PINS_SOURCE10 + +#define OTG_PIN_SOF_GPIO GPIOA +#define OTG_PIN_SOF_GPIO_CLOCK CRM_GPIOA_PERIPH_CLOCK +#define OTG_PIN_SOF GPIO_PINS_4 +#define OTG_PIN_SOF_SOURCE GPIO_PINS_SOURCE4 + +#define OTG_PIN_MUX GPIO_MUX_12 +#endif + +/** + * @brief usb device mode config + */ +#ifdef USE_OTG_DEVICE_MODE +/** + * @brief usb device mode fifo + */ +/* otg1 device fifo */ +#define USBD_RX_SIZE 128 +#define USBD_EP0_TX_SIZE 24 +#define USBD_EP1_TX_SIZE 20 +#define USBD_EP2_TX_SIZE 20 +#define USBD_EP3_TX_SIZE 20 +#define USBD_EP4_TX_SIZE 20 +#define USBD_EP5_TX_SIZE 20 +#define USBD_EP6_TX_SIZE 20 +#define USBD_EP7_TX_SIZE 20 + +/* otg2 device fifo */ +#define USBD2_RX_SIZE 128 +#define USBD2_EP0_TX_SIZE 24 +#define USBD2_EP1_TX_SIZE 20 +#define USBD2_EP2_TX_SIZE 20 +#define USBD2_EP3_TX_SIZE 20 +#define USBD2_EP4_TX_SIZE 20 +#define USBD2_EP5_TX_SIZE 20 +#define USBD2_EP6_TX_SIZE 20 +#define USBD2_EP7_TX_SIZE 20 + +/** + * @brief usb endpoint max num define + */ +#ifndef USB_EPT_MAX_NUM +#define USB_EPT_MAX_NUM 8 +#endif +#endif + +/** + * @brief usb host mode config + */ +#ifdef USE_OTG_HOST_MODE +#ifndef USB_HOST_CHANNEL_NUM +#define USB_HOST_CHANNEL_NUM 16 +#endif + +/** + * @brief usb host mode fifo + */ +/* otg1 host fifo */ +#define USBH_RX_FIFO_SIZE 128 +#define USBH_NP_TX_FIFO_SIZE 96 +#define USBH_P_TX_FIFO_SIZE 96 + +/* otg2 host fifo */ +#define USBH2_RX_FIFO_SIZE 128 +#define USBH2_NP_TX_FIFO_SIZE 96 +#define USBH2_P_TX_FIFO_SIZE 96 +#endif + +/** + * @brief usb sof output enable + */ +/* #define USB_SOF_OUTPUT_ENABLE */ + +/** + * @brief usb vbus ignore, not use vbus pin + */ +#define USB_VBUS_IGNORE + +/** + * @brief usb low power wakeup handler enable + */ +/* #define USB_LOW_POWER_WAKUP */ + +void usb_delay_ms(uint32_t ms); +void usb_delay_us(uint32_t us); +/** + * @} + */ + +/** + * @} + */ +#ifdef __cplusplus +} +#endif + +#endif diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/README b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/cdc/cdc_class.c b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/cdc/cdc_class.c new file mode 100644 index 0000000..2de8567 --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/cdc/cdc_class.c @@ -0,0 +1,413 @@ +/** + ************************************************************************** + * @file cdc_class.c + * @version v2.0.4 + * @date 2021-12-31 + * @brief usb cdc class type + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ +#include "usbd_core.h" +#include "cdc_class.h" +#include "cdc_desc.h" + +/** @addtogroup AT32F435_437_middlewares_usbd_class + * @{ + */ + +/** @defgroup USB_cdc_class + * @brief usb device class cdc demo + * @{ + */ + +/** @defgroup USB_cdc_class_private_functions + * @{ + */ + +usb_sts_type class_init_handler(void *udev); +usb_sts_type class_clear_handler(void *udev); +usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup); +usb_sts_type class_ept0_tx_handler(void *udev); +usb_sts_type class_ept0_rx_handler(void *udev); +usb_sts_type class_in_handler(void *udev, uint8_t ept_num); +usb_sts_type class_out_handler(void *udev, uint8_t ept_num); +usb_sts_type class_sof_handler(void *udev); +usb_sts_type class_event_handler(void *udev, usbd_event_type event); + +void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len); +/* usb rx and tx buffer */ +static uint32_t alt_setting = 0; +static uint8_t g_rx_buff[USBD_OUT_MAXPACKET_SIZE]; +//static uint8_t g_tx_buff[USBD_IN_MAXPACKET_SIZE]; +static uint8_t g_cmd[USBD_CMD_MAXPACKET_SIZE]; +static uint8_t g_req; +static uint16_t g_len, g_rxlen; +__IO uint8_t g_tx_completed = 1, g_rx_completed = 0; + +linecoding_type linecoding = +{ + 115200, + 0x00, + 0x00, + 0x08 +}; + +/* static variable */ + + +/* usb device class handler */ +usbd_class_handler class_handler = +{ + class_init_handler, + class_clear_handler, + class_setup_handler, + class_ept0_tx_handler, + class_ept0_rx_handler, + class_in_handler, + class_out_handler, + class_sof_handler, + class_event_handler, +}; + +/** + * @brief initialize usb custom hid endpoint + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +usb_sts_type class_init_handler(void *udev) +{ + usb_sts_type status = USB_OK; + usbd_core_type *pudev = (usbd_core_type *)udev; + + /* open in endpoint */ + usbd_ept_open(pudev, USBD_CDC_INT_EPT, EPT_INT_TYPE, USBD_CMD_MAXPACKET_SIZE); + + /* open in endpoint */ + usbd_ept_open(pudev, USBD_CDC_BULK_IN_EPT, EPT_BULK_TYPE, USBD_IN_MAXPACKET_SIZE); + + /* open out endpoint */ + usbd_ept_open(pudev, USBD_CDC_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_OUT_MAXPACKET_SIZE); + + /* set out endpoint to receive status */ + usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, g_rx_buff, USBD_OUT_MAXPACKET_SIZE); + + g_tx_completed = 1; + + return status; +} + +/** + * @brief clear endpoint or other state + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +usb_sts_type class_clear_handler(void *udev) +{ + usb_sts_type status = USB_OK; + usbd_core_type *pudev = (usbd_core_type *)udev; + + /* close in endpoint */ + usbd_ept_close(pudev, USBD_CDC_INT_EPT); + + /* close in endpoint */ + usbd_ept_close(pudev, USBD_CDC_BULK_IN_EPT); + + /* close out endpoint */ + usbd_ept_close(pudev, USBD_CDC_BULK_OUT_EPT); + + return status; +} + +/** + * @brief usb device class setup request handler + * @param udev: to the structure of usbd_core_type + * @param setup: setup packet + * @retval status of usb_sts_type + */ +usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup) +{ + usb_sts_type status = USB_OK; + usbd_core_type *pudev = (usbd_core_type *)udev; + + switch(setup->bmRequestType & USB_REQ_TYPE_RESERVED) + { + /* class request */ + case USB_REQ_TYPE_CLASS: + if(setup->wLength) + { + if(setup->bmRequestType & USB_REQ_DIR_DTH) + { + usb_vcp_cmd_process(udev, setup->bRequest, g_cmd, setup->wLength); + usbd_ctrl_send(pudev, g_cmd, setup->wLength); + } + else + { + g_req = setup->bRequest; + g_len = setup->wLength; + usbd_ctrl_recv(pudev, g_cmd, g_len); + + } + } + break; + /* standard request */ + case USB_REQ_TYPE_STANDARD: + switch(setup->bRequest) + { + case USB_STD_REQ_GET_DESCRIPTOR: + usbd_ctrl_unsupport(pudev); + break; + case USB_STD_REQ_GET_INTERFACE: + usbd_ctrl_send(pudev, (uint8_t *)&alt_setting, 1); + break; + case USB_STD_REQ_SET_INTERFACE: + alt_setting = setup->wValue; + break; + default: + break; + } + break; + default: + usbd_ctrl_unsupport(pudev); + break; + } + return status; +} + +/** + * @brief usb device endpoint 0 in status stage complete + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +usb_sts_type class_ept0_tx_handler(void *udev) +{ + usb_sts_type status = USB_OK; + + /* ...user code... */ + + return status; +} + +/** + * @brief usb device endpoint 0 out status stage complete + * @param udev: usb device core handler type + * @retval status of usb_sts_type + */ +usb_sts_type class_ept0_rx_handler(void *udev) +{ + usb_sts_type status = USB_OK; + usbd_core_type *pudev = (usbd_core_type *)udev; + uint32_t recv_len = usbd_get_recv_len(pudev, 0); + /* ...user code... */ + if( g_req == SET_LINE_CODING) + { + /* class process */ + usb_vcp_cmd_process(udev, g_req, g_cmd, recv_len); + } + + return status; +} + +/** + * @brief usb device transmision complete handler + * @param udev: to the structure of usbd_core_type + * @param ept_num: endpoint number + * @retval status of usb_sts_type + */ +usb_sts_type class_in_handler(void *udev, uint8_t ept_num) +{ + usbd_core_type *pudev = (usbd_core_type *)udev; + usb_sts_type status = USB_OK; + + /* ...user code... + trans next packet data + */ + usbd_flush_tx_fifo(pudev, ept_num); + g_tx_completed = 1; + + return status; +} + +/** + * @brief usb device endpoint receive data + * @param udev: to the structure of usbd_core_type + * @param ept_num: endpoint number + * @retval status of usb_sts_type + */ +usb_sts_type class_out_handler(void *udev, uint8_t ept_num) +{ + usb_sts_type status = USB_OK; + usbd_core_type *pudev = (usbd_core_type *)udev; + + /* get endpoint receive data length */ + g_rxlen = usbd_get_recv_len(pudev, ept_num); + + /*set recv flag*/ + g_rx_completed = 1; + + return status; +} + +/** + * @brief usb device sof handler + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +usb_sts_type class_sof_handler(void *udev) +{ + usb_sts_type status = USB_OK; + + /* ...user code... */ + + return status; +} + +/** + * @brief usb device event handler + * @param udev: to the structure of usbd_core_type + * @param event: usb device event + * @retval status of usb_sts_type + */ +usb_sts_type class_event_handler(void *udev, usbd_event_type event) +{ + usb_sts_type status = USB_OK; + switch(event) + { + case USBD_RESET_EVENT: + + /* ...user code... */ + + break; + case USBD_SUSPEND_EVENT: + + /* ...user code... */ + + break; + case USBD_WAKEUP_EVENT: + /* ...user code... */ + + break; + case USBD_INISOINCOM_EVENT: + break; + case USBD_OUTISOINCOM_EVENT: + break; + + default: + break; + } + return status; +} + +/** + * @brief usb device class rx data process + * @param udev: to the structure of usbd_core_type + * @param recv_data: receive buffer + * @retval receive data len + */ +uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data) +{ + uint16_t i_index = 0; + uint16_t tmp_len = g_rxlen; + usbd_core_type *pudev = (usbd_core_type *)udev; + + if(g_rx_completed == 0) + { + return 0; + } + g_rx_completed = 0; + tmp_len = g_rxlen; + for(i_index = 0; i_index < g_rxlen; i_index ++) + { + recv_data[i_index] = g_rx_buff[i_index]; + } + + usbd_ept_recv(pudev, USBD_CDC_BULK_OUT_EPT, g_rx_buff, USBD_OUT_MAXPACKET_SIZE); + + return tmp_len; +} + +/** + * @brief usb device class send data + * @param udev: to the structure of usbd_core_type + * @param send_data: send data buffer + * @param len: send length + * @retval error status + */ +error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len) +{ + error_status status = SUCCESS; + usbd_core_type *pudev = (usbd_core_type *)udev; + if(g_tx_completed) + { + g_tx_completed = 0; + usbd_ept_send(pudev, USBD_CDC_BULK_IN_EPT, send_data, len); + } + else + { + status = ERROR; + } + return status; +} + + +/** + * @brief usb device function + * @param udev: to the structure of usbd_core_type + * @param cmd: request number + * @param buff: request buffer + * @param len: buffer length + * @retval none + */ +void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len) +{ + switch(cmd) + { + case SET_LINE_CODING: + linecoding.bitrate = (uint32_t)(buff[0] | (buff[1] << 8) | (buff[2] << 16) | (buff[3] <<24)); + linecoding.format = buff[4]; + linecoding.parity = buff[5]; + linecoding.data = buff[6]; + break; + + case GET_LINE_CODING: + buff[0] = (uint8_t)linecoding.bitrate; + buff[1] = (uint8_t)(linecoding.bitrate >> 8); + buff[2] = (uint8_t)(linecoding.bitrate >> 16); + buff[3] = (uint8_t)(linecoding.bitrate >> 24); + buff[4] = (uint8_t)(linecoding.format); + buff[5] = (uint8_t)(linecoding.parity); + buff[6] = (uint8_t)(linecoding.data); + break; + + default: + break; + } +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/cdc/cdc_class.h b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/cdc/cdc_class.h new file mode 100644 index 0000000..b8134cc --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/cdc/cdc_class.h @@ -0,0 +1,119 @@ +/** + ************************************************************************** + * @file cdc_class.h + * @version v2.0.4 + * @date 2021-12-31 + * @brief usb cdc class file + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ + + /* define to prevent recursive inclusion -------------------------------------*/ +#ifndef __CDC_CLASS_H +#define __CDC_CLASS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "usb_std.h" +#include "usbd_core.h" + +/** @addtogroup AT32F435_437_middlewares_usbd_class + * @{ + */ + +/** @addtogroup USB_cdc_class + * @{ + */ + +/** @defgroup USB_cdc_class_definition + * @{ + */ + +/** + * @brief usb cdc use endpoint define + */ +#define USBD_CDC_INT_EPT 0x82 +#define USBD_CDC_BULK_IN_EPT 0x81 +#define USBD_CDC_BULK_OUT_EPT 0x01 + +/** + * @brief usb cdc in and out max packet size define + */ +#define USBD_IN_MAXPACKET_SIZE 0x40 +#define USBD_OUT_MAXPACKET_SIZE 0x40 +#define USBD_CMD_MAXPACKET_SIZE 0x08 + +/** + * @brief usb cdc class request code define + */ +#define SET_LINE_CODING 0x20 +#define GET_LINE_CODING 0x21 + +/** + * @} + */ + +/** @defgroup USB_cdc_class_exported_types + * @{ + */ + +/** + * @brief usb cdc class set line coding struct + */ +typedef struct +{ + uint32_t bitrate; /* line coding baud rate */ + uint8_t format; /* line coding foramt */ + uint8_t parity; /* line coding parity */ + uint8_t data; /* line coding data bit */ +}linecoding_type; + +/** + * @} + */ + +/** @defgroup USB_cdc_class_exported_functions + * @{ + */ +extern usbd_class_handler class_handler; +uint16_t usb_vcp_get_rxdata(void *udev, uint8_t *recv_data); +error_status usb_vcp_send_data(void *udev, uint8_t *send_data, uint16_t len); + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ +#ifdef __cplusplus +} +#endif + +#endif + + + + diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/cdc/cdc_desc.c b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/cdc/cdc_desc.c new file mode 100644 index 0000000..5a73eec --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/cdc/cdc_desc.c @@ -0,0 +1,446 @@ +/** + ************************************************************************** + * @file cdc_desc.c + * @version v2.0.4 + * @date 2021-12-31 + * @brief usb cdc device descriptor + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ +#include "stdio.h" +#include "usb_std.h" +#include "usbd_sdr.h" +#include "usbd_core.h" +#include "cdc_desc.h" + +/** @addtogroup AT32F435_437_middlewares_usbd_class + * @{ + */ + +/** @defgroup USB_cdc_desc + * @brief usb device cdc descriptor + * @{ + */ + +/** @defgroup USB_cdc_desc_private_functions + * @{ + */ + +usbd_desc_t *get_device_descriptor(void); +usbd_desc_t *get_device_qualifier(void); +usbd_desc_t *get_device_configuration(void); +usbd_desc_t *get_device_other_speed(void); +usbd_desc_t *get_device_lang_id(void); +usbd_desc_t *get_device_manufacturer_string(void); +usbd_desc_t *get_device_product_string(void); +usbd_desc_t *get_device_serial_string(void); +usbd_desc_t *get_device_interface_string(void); +usbd_desc_t *get_device_config_string(void); + +uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf); +static void usbd_int_to_unicode (uint32_t value , uint8_t *pbuf , uint8_t len); +static void get_serial_num(void); +static uint8_t g_usbd_desc_buffer[256]; + +/** + * @brief device descriptor handler structure + */ +usbd_desc_handler desc_handler = +{ + get_device_descriptor, + get_device_qualifier, + get_device_configuration, + get_device_other_speed, + get_device_lang_id, + get_device_manufacturer_string, + get_device_product_string, + get_device_serial_string, + get_device_interface_string, + get_device_config_string, +}; + +/** + * @brief usb device standard descriptor + */ +#if defined ( __ICCARM__ ) /* iar compiler */ + #pragma data_alignment=4 +#endif +ALIGNED_HEAD uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN] ALIGNED_TAIL = +{ + USB_DEVICE_DESC_LEN, /* bLength */ + USB_DESCIPTOR_TYPE_DEVICE, /* bDescriptorType */ + 0x00, /* bcdUSB */ + 0x02, + 0x02, /* bDeviceClass */ + 0x00, /* bDeviceSubClass */ + 0x00, /* bDeviceProtocol */ + USB_MAX_EP0_SIZE, /* bMaxPacketSize */ + LBYTE(USBD_VENDOR_ID), /* idVendor */ + HBYTE(USBD_VENDOR_ID), /* idVendor */ + LBYTE(USBD_PRODUCT_ID), /* idProduct */ + HBYTE(USBD_PRODUCT_ID), /* idProduct */ + 0x00, /* bcdDevice rel. 2.00 */ + 0x02, + USB_MFC_STRING, /* Index of manufacturer string */ + USB_PRODUCT_STRING, /* Index of product string */ + USB_SERIAL_STRING, /* Index of serial number string */ + 1 /* bNumConfigurations */ +}; + +/** + * @brief usb configuration standard descriptor + */ +#if defined ( __ICCARM__ ) /* iar compiler */ + #pragma data_alignment=4 +#endif +ALIGNED_HEAD uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE] ALIGNED_TAIL = +{ + USB_DEVICE_CFG_DESC_LEN, /* bLength: configuration descriptor size */ + USB_DESCIPTOR_TYPE_CONFIGURATION, /* bDescriptorType: configuration */ + LBYTE(USBD_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */ + HBYTE(USBD_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */ + 0x02, /* bNumInterfaces: 2 interface */ + 0x01, /* bConfigurationValue: configuration value */ + 0x00, /* iConfiguration: index of string descriptor describing + the configuration */ + 0xC0, /* bmAttributes: self powered */ + 0x32, /* MaxPower 100 mA: this current is used for detecting vbus */ + + USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */ + USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */ + 0x00, /* bInterfaceNumber: number of interface */ + 0x00, /* bAlternateSetting: alternate set */ + 0x01, /* bNumEndpoints: number of endpoints */ + USB_CLASS_CODE_CDC, /* bInterfaceClass: CDC class code */ + 0x02, /* bInterfaceSubClass: subclass code, Abstract Control Model*/ + 0x01, /* bInterfaceProtocol: protocol code, AT Command */ + 0x00, /* iInterface: index of string descriptor */ + + 0x05, /* bFunctionLength: size of this descriptor in bytes */ + USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */ + USBD_CDC_SUBTYPE_HEADER, /* bDescriptorSubtype: Header function Descriptor 0x00*/ + LBYTE(BCD_NUM), + HBYTE(BCD_NUM), /* bcdCDC: USB class definitions for communications */ + + 0x05, /* bFunctionLength: size of this descriptor in bytes */ + USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */ + USBD_CDC_SUBTYPE_CMF, /* bDescriptorSubtype: Call Management function descriptor subtype 0x01 */ + 0x00, /* bmCapabilities: 0x00*/ + 0x01, /* bDataInterface: interface number of data class interface optionally used for call management */ + + 0x04, /* bFunctionLength: size of this descriptor in bytes */ + USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */ + USBD_CDC_SUBTYPE_ACM, /* bDescriptorSubtype: Abstract Control Management functional descriptor subtype 0x02 */ + 0x02, /* bmCapabilities: Support Set_Line_Coding and Get_Line_Coding 0x02 */ + + 0x05, /* bFunctionLength: size of this descriptor in bytes */ + USBD_CDC_CS_INTERFACE, /* bDescriptorType: CDC interface descriptor type */ + USBD_CDC_SUBTYPE_UFD, /* bDescriptorSubtype: Union Function Descriptor subtype 0x06 */ + 0x00, /* bControlInterface: The interface number of the communications or data class interface 0x00 */ + 0x01, /* bSubordinateInterface0: interface number of first subordinate interface in the union */ + + USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */ + USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */ + USBD_CDC_INT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */ + USB_EPT_DESC_INTERRUPT, /* bmAttributes: endpoint attributes */ + LBYTE(USBD_CMD_MAXPACKET_SIZE), + HBYTE(USBD_CMD_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */ + HID_BINTERVAL_TIME, /* bInterval: interval for polling endpoint for data transfers */ + + + USB_DEVICE_IF_DESC_LEN, /* bLength: interface descriptor size */ + USB_DESCIPTOR_TYPE_INTERFACE, /* bDescriptorType: interface descriptor type */ + 0x01, /* bInterfaceNumber: number of interface */ + 0x00, /* bAlternateSetting: alternate set */ + 0x02, /* bNumEndpoints: number of endpoints */ + USB_CLASS_CODE_CDCDATA, /* bInterfaceClass: CDC-data class code */ + 0x00, /* bInterfaceSubClass: Data interface subclass code 0x00*/ + 0x00, /* bInterfaceProtocol: data class protocol code 0x00 */ + 0x00, /* iInterface: index of string descriptor */ + + USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */ + USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */ + USBD_CDC_BULK_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */ + USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */ + LBYTE(USBD_IN_MAXPACKET_SIZE), + HBYTE(USBD_IN_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */ + 0x00, /* bInterval: interval for polling endpoint for data transfers */ + + USB_DEVICE_EPT_LEN, /* bLength: size of endpoint descriptor in bytes */ + USB_DESCIPTOR_TYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */ + USBD_CDC_BULK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */ + USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */ + LBYTE(USBD_OUT_MAXPACKET_SIZE), + HBYTE(USBD_OUT_MAXPACKET_SIZE), /* wMaxPacketSize: maximum packe size this endpoint */ + 0x00, /* bInterval: interval for polling endpoint for data transfers */ +}; + +/** + * @brief usb string lang id + */ +#if defined ( __ICCARM__ ) /* iar compiler */ + #pragma data_alignment=4 +#endif +ALIGNED_HEAD uint8_t g_string_lang_id[USBD_SIZ_STRING_LANGID] ALIGNED_TAIL = +{ + USBD_SIZ_STRING_LANGID, + USB_DESCIPTOR_TYPE_STRING, + 0x09, + 0x04, +}; + +/** + * @brief usb string serial + */ +#if defined ( __ICCARM__ ) /* iar compiler */ + #pragma data_alignment=4 +#endif +ALIGNED_HEAD uint8_t g_string_serial[USBD_SIZ_STRING_SERIAL] ALIGNED_TAIL = +{ + USBD_SIZ_STRING_SERIAL, + USB_DESCIPTOR_TYPE_STRING, +}; + + +/* device descriptor */ +usbd_desc_t device_descriptor = +{ + USB_DEVICE_DESC_LEN, + g_usbd_descriptor +}; + +/* config descriptor */ +usbd_desc_t config_descriptor = +{ + USBD_CONFIG_DESC_SIZE, + g_usbd_configuration +}; + +/* langid descriptor */ +usbd_desc_t langid_descriptor = +{ + USBD_SIZ_STRING_LANGID, + g_string_lang_id +}; + +/* serial descriptor */ +usbd_desc_t serial_descriptor = +{ + USBD_SIZ_STRING_SERIAL, + g_string_serial +}; + +usbd_desc_t vp_desc; + +/** + * @brief standard usb unicode convert + * @param string: source string + * @param unicode_buf: unicode buffer + * @retval length + */ +uint16_t usbd_unicode_convert(uint8_t *string, uint8_t *unicode_buf) +{ + uint16_t str_len = 0, id_pos = 2; + uint8_t *tmp_str = string; + + while(*tmp_str != '\0') + { + str_len ++; + unicode_buf[id_pos ++] = *tmp_str ++; + unicode_buf[id_pos ++] = 0x00; + } + + str_len = str_len * 2 + 2; + unicode_buf[0] = (uint8_t)str_len; + unicode_buf[1] = USB_DESCIPTOR_TYPE_STRING; + + return str_len; +} + +/** + * @brief usb int convert to unicode + * @param value: int value + * @param pbus: unicode buffer + * @param len: length + * @retval none + */ +static void usbd_int_to_unicode (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; + } +} + +/** + * @brief usb get serial number + * @param none + * @retval none + */ +static void get_serial_num(void) +{ + uint32_t serial0, serial1, serial2; + + serial0 = *(uint32_t*)MCU_ID1; + serial1 = *(uint32_t*)MCU_ID2; + serial2 = *(uint32_t*)MCU_ID3; + + serial0 += serial2; + + if (serial0 != 0) + { + usbd_int_to_unicode (serial0, &g_string_serial[2] ,8); + usbd_int_to_unicode (serial1, &g_string_serial[18] ,4); + } +} + +/** + * @brief get device descriptor + * @param none + * @retval usbd_desc + */ +usbd_desc_t *get_device_descriptor(void) +{ + return &device_descriptor; +} + +/** + * @brief get device qualifier + * @param none + * @retval usbd_desc + */ +usbd_desc_t * get_device_qualifier(void) +{ + return NULL; +} + +/** + * @brief get config descriptor + * @param none + * @retval usbd_desc + */ +usbd_desc_t *get_device_configuration(void) +{ + return &config_descriptor; +} + +/** + * @brief get other speed descriptor + * @param none + * @retval usbd_desc + */ +usbd_desc_t *get_device_other_speed(void) +{ + return NULL; +} + +/** + * @brief get lang id descriptor + * @param none + * @retval usbd_desc + */ +usbd_desc_t *get_device_lang_id(void) +{ + return &langid_descriptor; +} + + +/** + * @brief get manufacturer descriptor + * @param none + * @retval usbd_desc + */ +usbd_desc_t *get_device_manufacturer_string(void) +{ + vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_DESC_MANUFACTURER_STRING, g_usbd_desc_buffer); + vp_desc.descriptor = g_usbd_desc_buffer; + return &vp_desc; +} + +/** + * @brief get product descriptor + * @param none + * @retval usbd_desc + */ +usbd_desc_t *get_device_product_string(void) +{ + vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_DESC_PRODUCT_STRING, g_usbd_desc_buffer); + vp_desc.descriptor = g_usbd_desc_buffer; + return &vp_desc; +} + +/** + * @brief get serial descriptor + * @param none + * @retval usbd_desc + */ +usbd_desc_t *get_device_serial_string(void) +{ + get_serial_num(); + return &serial_descriptor; +} + +/** + * @brief get interface descriptor + * @param none + * @retval usbd_desc + */ +usbd_desc_t *get_device_interface_string(void) +{ + vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_DESC_INTERFACE_STRING, g_usbd_desc_buffer); + vp_desc.descriptor = g_usbd_desc_buffer; + return &vp_desc; +} + +/** + * @brief get device config descriptor + * @param none + * @retval usbd_desc + */ +usbd_desc_t *get_device_config_string(void) +{ + vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer); + vp_desc.descriptor = g_usbd_desc_buffer; + return &vp_desc; +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/cdc/cdc_desc.h b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/cdc/cdc_desc.h new file mode 100644 index 0000000..e8dff6e --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/lib/cdc/cdc_desc.h @@ -0,0 +1,122 @@ +/** + ************************************************************************** + * @file cdc_desc.h + * @version v2.0.4 + * @date 2021-12-31 + * @brief usb cdc descriptor header file + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ + +/* define to prevent recursive inclusion -------------------------------------*/ +#ifndef __CDC_DESC_H +#define __CDC_DESC_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "cdc_class.h" +#include "usbd_core.h" + +/** @addtogroup AT32F435_437_middlewares_usbd_class + * @{ + */ + +/** @addtogroup USB_cdc_desc + * @{ + */ + +/** @defgroup USB_cdc_desc_definition + * @{ + */ + +/** + * @brief usb bcd number define + */ +#define BCD_NUM 0x0110 + +/** + * @brief usb vendor id and product id define + */ +#define USBD_VENDOR_ID 0x2E3C +#define USBD_PRODUCT_ID 0x5740 + +/** + * @brief usb descriptor size define + */ +#define USBD_CONFIG_DESC_SIZE 67 +#define USBD_SIZ_STRING_LANGID 4 +#define USBD_SIZ_STRING_SERIAL 0x1A + +/** + * @brief usb string define(vendor, product configuration, interface) + */ +#define USBD_DESC_MANUFACTURER_STRING "Artery" +#define USBD_DESC_PRODUCT_STRING "AT32 Virtual Com Port " +#define USBD_DESC_CONFIGURATION_STRING "Virtual ComPort Config" +#define USBD_DESC_INTERFACE_STRING "Virtual ComPort Interface" + +/** + * @brief usb endpoint interval define + */ +#define HID_BINTERVAL_TIME 0xFF + +/** + * @brief usb hid class descriptor define + */ +#define USBD_CDC_CS_INTERFACE 0x24 +#define USBD_CDC_CS_ENDPOINT 0x25 + +/** + * @brief usb hid class sub-type define + */ +#define USBD_CDC_SUBTYPE_HEADER 0x00 +#define USBD_CDC_SUBTYPE_CMF 0x01 +#define USBD_CDC_SUBTYPE_ACM 0x02 +#define USBD_CDC_SUBTYPE_UFD 0x06 + +/** + * @brief usb mcu id address deine + */ +#define MCU_ID1 (0x1FFFF7E8) +#define MCU_ID2 (0x1FFFF7EC) +#define MCU_ID3 (0x1FFFF7F0) + +/** + * @} + */ + +extern uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN]; +extern uint8_t g_usbd_configuration[USBD_CONFIG_DESC_SIZE]; +extern usbd_desc_handler desc_handler; + + +/** + * @} + */ + +/** + * @} + */ +#ifdef __cplusplus +} +#endif + +#endif diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/platformio.ini b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/platformio.ini new file mode 100644 index 0000000..9e11fbf --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/platformio.ini @@ -0,0 +1,36 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[env:vcp_loopback] +platform = at32 +framework = cmsis +board = generic_f435 +build_flags = -I include +monitor_speed = 115200 ;serial monitor baudrate + +;Use the following for jlink upload +upload_protocol = jlink + +;Use the following for serial upload via bootloader (PA9, PA10) +;upload_protocol = serial +;upload_speed = 115200 ;default: 115200 + +;Use the following for DFU upload via USB port +;upload_protocol = dfu +;build_flags = +; -DDFU_MODE +; -UVECT_TAB_OFFSET +; -DUSER_VECT_TAB_ADDRESS +; -DVECT_TAB_OFFSET=0x2000 ; override default vector tale to support ISR table for DFU mode + +;Use the following for custom uploader +;upload_protocol = custom +;upload_port = COM16 +;upload_speed = 115200 +;upload_command = ${platformio.packages_dir}/framework-cmsis-at32f40/tools/stm32flash/stm32flash -b $UPLOAD_SPEED -w $SOURCE -g 0x8000000 $UPLOAD_PORT \ No newline at end of file diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/readme.txt b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/readme.txt new file mode 100644 index 0000000..c91c80b --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/readme.txt @@ -0,0 +1,11 @@ +/** + ************************************************************************** + * @file readme.txt + * @version v2.0.4 + * @date 2021-12-31 + * @brief readme + ************************************************************************** + */ + + this demo is based on the at-start board, in this demo, show how to build + a device of usb cdc class protocol. diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/src/at32f435_437_clock.c b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/src/at32f435_437_clock.c new file mode 100644 index 0000000..b9142ed --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/src/at32f435_437_clock.c @@ -0,0 +1,106 @@ +/** + ************************************************************************** + * @file at32f435_437_clock.c + * @version v2.0.4 + * @date 2021-12-31 + * @brief system clock config program + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ + +/* includes ------------------------------------------------------------------*/ +#include "at32f435_437_clock.h" + +/** + * @brief system clock config program + * @note the system clock is configured as follow: + * - system clock = (hext * pll_ns)/(pll_ms * pll_fr) + * - system clock source = pll (hext) + * - hext = 8000000 + * - sclk = 288000000 + * - ahbdiv = 1 + * - ahbclk = 288000000 + * - apb2div = 2 + * - apb2clk = 144000000 + * - apb1div = 2 + * - apb1clk = 144000000 + * - pll_ns = 72 + * - pll_ms = 1 + * - pll_fr = 2 + * @param none + * @retval none + */ +void system_clock_config(void) +{ + /* enable pwc periph clock */ + crm_periph_clock_enable(CRM_PWC_PERIPH_CLOCK, TRUE); + + /* config ldo voltage */ + pwc_ldo_output_voltage_set(PWC_LDO_OUTPUT_1V3); + + /* set the flash clock divider */ + flash_clock_divider_set(FLASH_CLOCK_DIV_3); + + /* reset crm */ + crm_reset(); + + crm_clock_source_enable(CRM_CLOCK_SOURCE_HEXT, TRUE); + + /* wait till hext is ready */ + while(crm_hext_stable_wait() == ERROR) + { + } + + /* config pll clock resource */ + crm_pll_config(CRM_PLL_SOURCE_HEXT, 72, 1, CRM_PLL_FR_2); + + /* enable pll */ + crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE); + + /* wait till pll is ready */ + while(crm_flag_get(CRM_PLL_STABLE_FLAG) != SET) + { + } + + /* config ahbclk */ + crm_ahb_div_set(CRM_AHB_DIV_1); + + /* config apb2clk */ + crm_apb2_div_set(CRM_APB2_DIV_2); + + /* config apb1clk */ + crm_apb1_div_set(CRM_APB1_DIV_2); + + /* enable auto step mode */ + crm_auto_step_mode_enable(TRUE); + + /* select pll as system clock source */ + crm_sysclk_switch(CRM_SCLK_PLL); + + /* wait till pll is used as system clock source */ + while(crm_sysclk_switch_status_get() != CRM_SCLK_PLL) + { + } + + /* disable auto step mode */ + crm_auto_step_mode_enable(FALSE); + + /* update system_core_clock global variable */ + system_core_clock_update(); +} diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/src/at32f435_437_int.c b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/src/at32f435_437_int.c new file mode 100644 index 0000000..33b6df6 --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/src/at32f435_437_int.c @@ -0,0 +1,142 @@ +/** + ************************************************************************** + * @file at32f435_437_int.c + * @version v2.0.4 + * @date 2021-12-31 + * @brief main interrupt service routines. + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ + +/* includes ------------------------------------------------------------------*/ +#include "at32f435_437_int.h" + +/** @addtogroup AT32F435_periph_examples + * @{ + */ + +/** @addtogroup 435_USB_device_vcp_loopback + * @{ + */ + +/** + * @brief this function handles nmi exception. + * @param none + * @retval none + */ +void NMI_Handler(void) +{ +} + +/** + * @brief this function handles hard fault exception. + * @param none + * @retval none + */ +void HardFault_Handler(void) +{ + /* go to infinite loop when hard fault exception occurs */ + while(1) + { + } +} + +/** + * @brief this function handles memory manage exception. + * @param none + * @retval none + */ +void MemManage_Handler(void) +{ + /* go to infinite loop when memory manage exception occurs */ + while(1) + { + } +} + +/** + * @brief this function handles bus fault exception. + * @param none + * @retval none + */ +void BusFault_Handler(void) +{ + /* go to infinite loop when bus fault exception occurs */ + while(1) + { + } +} + +/** + * @brief this function handles usage fault exception. + * @param none + * @retval none + */ +void UsageFault_Handler(void) +{ + /* go to infinite loop when usage fault exception occurs */ + while(1) + { + } +} + +/** + * @brief this function handles svcall exception. + * @param none + * @retval none + */ +void SVC_Handler(void) +{ +} + +/** + * @brief this function handles debug monitor exception. + * @param none + * @retval none + */ +void DebugMon_Handler(void) +{ +} + +/** + * @brief this function handles pendsv_handler exception. + * @param none + * @retval none + */ +void PendSV_Handler(void) +{ +} + +/** + * @brief this function handles systick handler. + * @param none + * @retval none + */ +void SysTick_Handler(void) +{ +} + +/** + * @} + */ + +/** + * @} + */ + diff --git a/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/src/main.c b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/src/main.c new file mode 100644 index 0000000..c9716ac --- /dev/null +++ b/.platformio/platforms/at32/examples/AT32F435/usb_device/vcp_loopback/src/main.c @@ -0,0 +1,326 @@ +/** + ************************************************************************** + * @file main.c + * @version v2.0.4 + * @date 2021-12-31 + * @brief main program + ************************************************************************** + * Copyright notice & Disclaimer + * + * The software Board Support Package (BSP) that is made available to + * download from Artery official website is the copyrighted work of Artery. + * Artery authorizes customers to use, copy, and distribute the BSP + * software and its related documentation for the purpose of design and + * development in conjunction with Artery microcontrollers. Use of the + * software is governed by this copyright notice and the following disclaimer. + * + * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, + * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, + * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR + * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, + * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * + ************************************************************************** + */ + +#include "at32f435_437_board.h" +#include "at32f435_437_clock.h" +#include "usb_conf.h" +#include "usb_core.h" +#include "usbd_int.h" +#include "cdc_class.h" +#include "cdc_desc.h" + +/** @addtogroup AT32F435_periph_examples + * @{ + */ + +/** @addtogroup 435_USB_device_vcp_loopback USB_device_vcp_loopback + * @{ + */ + +/* usb global struct define */ +otg_core_type otg_core_struct; +uint8_t usb_buffer[256]; +void usb_clock48m_select(usb_clk48_s clk_s); +void usb_gpio_config(void); +void usb_low_power_wakeup_config(void); + +/** + * @brief main function. + * @param none + * @retval none + */ +int main(void) +{ + uint16_t data_len; + + uint32_t timeout; + + uint8_t send_zero_packet = 0; + + nvic_priority_group_config(NVIC_PRIORITY_GROUP_4); + + system_clock_config(); + + at32_board_init(); + + /* usb gpio config */ + usb_gpio_config(); + +#ifdef USB_LOW_POWER_WAKUP + usb_low_power_wakeup_config(); +#endif + + /* enable otgfs clock */ + crm_periph_clock_enable(OTG_CLOCK, TRUE); + + /* select usb 48m clcok source */ + usb_clock48m_select(USB_CLK_HEXT); + + /* enable otgfs irq */ + nvic_irq_enable(OTG_IRQ, 0, 0); + + /* init usb */ + usbd_init(&otg_core_struct, + USB_FULL_SPEED_CORE_ID, + USB_ID, + &class_handler, + &desc_handler); + while(1) + { + /* get usb vcp receive data */ + data_len = usb_vcp_get_rxdata(&otg_core_struct.dev, usb_buffer); + + if(data_len > 0 || send_zero_packet == 1) + { + + /* bulk transfer is complete when the endpoint does one of the following + 1 has transferred exactly the amount of data expected + 2 transfers a packet with a payload size less than wMaxPacketSize or transfers a zero-length packet + */ + if(data_len > 0) + send_zero_packet = 1; + + if(data_len == 0) + send_zero_packet = 0; + + timeout = 50000; + do + { + /* send data to host */ + if(usb_vcp_send_data(&otg_core_struct.dev, usb_buffer, data_len) == SUCCESS) + { + break; + } + }while(timeout --); + } + } +} + +/** + * @brief usb 48M clock select + * @param clk_s:USB_CLK_HICK, USB_CLK_HEXT + * @retval none + */ +void usb_clock48m_select(usb_clk48_s clk_s) +{ + if(clk_s == USB_CLK_HICK) + { + crm_usb_clock_source_select(CRM_USB_CLOCK_SOURCE_HICK); + + /* enable the acc calibration ready interrupt */ + crm_periph_clock_enable(CRM_ACC_PERIPH_CLOCK, TRUE); + + /* update the c1\c2\c3 value */ + acc_write_c1(7980); + acc_write_c2(8000); + acc_write_c3(8020); +#if (USB_ID == 0) + acc_sof_select(ACC_SOF_OTG1); +#else + acc_sof_select(ACC_SOF_OTG2); +#endif + /* open acc calibration */ + acc_calibration_mode_enable(ACC_CAL_HICKTRIM, TRUE); + } + else + { + switch(system_core_clock) + { + /* 48MHz */ + case 48000000: + crm_usb_clock_div_set(CRM_USB_DIV_1); + break; + + /* 72MHz */ + case 72000000: + crm_usb_clock_div_set(CRM_USB_DIV_1_5); + break; + + /* 96MHz */ + case 96000000: + crm_usb_clock_div_set(CRM_USB_DIV_2); + break; + + /* 120MHz */ + case 120000000: + crm_usb_clock_div_set(CRM_USB_DIV_2_5); + break; + + /* 144MHz */ + case 144000000: + crm_usb_clock_div_set(CRM_USB_DIV_3); + break; + + /* 168MHz */ + case 168000000: + crm_usb_clock_div_set(CRM_USB_DIV_3_5); + break; + + /* 192MHz */ + case 192000000: + crm_usb_clock_div_set(CRM_USB_DIV_4); + break; + + /* 216MHz */ + case 216000000: + crm_usb_clock_div_set(CRM_USB_DIV_4_5); + break; + + /* 240MHz */ + case 240000000: + crm_usb_clock_div_set(CRM_USB_DIV_5); + break; + + /* 264MHz */ + case 264000000: + crm_usb_clock_div_set(CRM_USB_DIV_5_5); + break; + + /* 288MHz */ + case 288000000: + crm_usb_clock_div_set(CRM_USB_DIV_6); + break; + + default: + break; + + } + } +} + +/** + * @brief this function config gpio. + * @param none + * @retval none + */ +void usb_gpio_config(void) +{ + gpio_init_type gpio_init_struct; + + crm_periph_clock_enable(OTG_PIN_GPIO_CLOCK, TRUE); + gpio_default_para_init(&gpio_init_struct); + + gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + + /* dp and dm */ + gpio_init_struct.gpio_pins = OTG_PIN_DP | OTG_PIN_DM; + gpio_init(OTG_PIN_GPIO, &gpio_init_struct); + + gpio_pin_mux_config(OTG_PIN_GPIO, OTG_PIN_DP_SOURCE, OTG_PIN_MUX); + gpio_pin_mux_config(OTG_PIN_GPIO, OTG_PIN_DM_SOURCE, OTG_PIN_MUX); + +#ifdef USB_SOF_OUTPUT_ENABLE + crm_periph_clock_enable(OTG_PIN_SOF_GPIO_CLOCK, TRUE); + gpio_init_struct.gpio_pins = OTG_PIN_SOF; + gpio_init(OTG_PIN_SOF_GPIO, &gpio_init_struct); + gpio_pin_mux_config(OTG_PIN_GPIO, OTG_PIN_SOF_SOURCE, OTG_PIN_MUX); +#endif + + /* otgfs use vbus pin */ +#ifndef USB_VBUS_IGNORE + gpio_init_struct.gpio_pins = OTG_PIN_VBUS; + gpio_init_struct.gpio_pull = GPIO_PULL_DOWN; + gpio_pin_mux_config(OTG_PIN_GPIO, OTG_PIN_VBUS_SOURCE, OTG_PIN_MUX); + gpio_init(OTG_PIN_GPIO, &gpio_init_struct); +#endif + + +} +#ifdef USB_LOW_POWER_WAKUP +/** + * @brief usb low power wakeup interrupt config + * @param none + * @retval none + */ +void usb_low_power_wakeup_config(void) +{ + exint_init_type exint_init_struct; + + crm_periph_clock_enable(CRM_SCFG_PERIPH_CLOCK, TRUE); + exint_default_para_init(&exint_init_struct); + + exint_init_struct.line_enable = TRUE; + exint_init_struct.line_mode = EXINT_LINE_INTERRUPUT; + exint_init_struct.line_select = OTG_WKUP_EXINT_LINE; + exint_init_struct.line_polarity = EXINT_TRIGGER_RISING_EDGE; + exint_init(&exint_init_struct); + + nvic_irq_enable(OTG_WKUP_IRQ, 0, 0); +} + +/** + * @brief this function handles otgfs wakup interrupt. + * @param none + * @retval none + */ +void OTG_WKUP_HANDLER(void) +{ + exint_flag_clear(OTG_WKUP_EXINT_LINE); +} + +#endif + +/** + * @brief this function handles otgfs interrupt. + * @param none + * @retval none + */ +void OTG_IRQ_HANDLER(void) +{ + usbd_irq_handler(&otg_core_struct); +} + +/** + * @brief usb delay millisecond function. + * @param ms: number of millisecond delay + * @retval none + */ +void usb_delay_ms(uint32_t ms) +{ + /* user can define self delay function */ + delay_ms(ms); +} + +/** + * @brief usb delay microsecond function. + * @param us: number of microsecond delay + * @retval none + */ +void usb_delay_us(uint32_t us) +{ + delay_us(us); +} + +/** + * @} + */ + +/** + * @} + */ diff --git a/.platformio/platforms/at32/examples/cmsis-blink/lib/Delay/delay.c b/.platformio/platforms/at32/examples/cmsis-blink/lib/Delay/delay.c index d4f80b9..f7da62c 100644 --- a/.platformio/platforms/at32/examples/cmsis-blink/lib/Delay/delay.c +++ b/.platformio/platforms/at32/examples/cmsis-blink/lib/Delay/delay.c @@ -20,7 +20,7 @@ void Delay_init() { /*Config Systick*/ SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); - fac_us=(float)SystemCoreClock/(240 * 1000000); + fac_us=(float)SystemCoreClock/(8 * 1000000); fac_ms=fac_us*1000; } diff --git a/.platformio/platforms/at32/examples/cmsis-blink/src/main.c b/.platformio/platforms/at32/examples/cmsis-blink/src/main.c index 2c41212..5f6f00d 100644 --- a/.platformio/platforms/at32/examples/cmsis-blink/src/main.c +++ b/.platformio/platforms/at32/examples/cmsis-blink/src/main.c @@ -3,11 +3,33 @@ #include "at32f4xx.h" #include "delay.h" -#define LEDPORT (GPIOC) -#define LED1 (13) -#define ENABLE_GPIO_CLOCK (RCC->APB2EN |= RCC_APB2EN_GPIOCEN) //RCC_APB2ENR_IOPCEN) -#define _MODER CTRLH -#define GPIOMODER (GPIO_CTRLH_MDE13_0) + +#define BLUEPILL // BLUEPILL BLACKPILL QFP48_FLASHER + +#ifdef BLUEPILL + #define LEDPORT (GPIOC) + #define LED1 (13) + #define ENABLE_GPIO_CLOCK (RCC->APB2EN |= RCC_APB2EN_GPIOCEN) //RCC_APB2ENR_IOPCEN) + #define _MODER CTRLH + #define GPIOMODER (GPIO_CTRLH_MDE13_0) +#endif +#ifdef BLACKPILL + #define LEDPORT (GPIOB) + #define LED1 (12) + #define ENABLE_GPIO_CLOCK (RCC->APB2EN |= RCC_APB2EN_GPIOBEN) //RCC_APB2ENR_IOPCEN) + #define _MODER CTRLH + #define GPIOMODER (GPIO_CTRLH_MDE12_0) +#endif +#ifdef QFP48_FLASHER + #define LEDPORT (GPIOB) + #define LED1 (15) + #define ENABLE_GPIO_CLOCK (RCC->APB2EN |= RCC_APB2EN_GPIOBEN) //RCC_APB2ENR_IOPCEN) + #define _MODER CTRLH + #define GPIOMODER (GPIO_CTRLH_MDE15_0) +#endif + + + //Alternates blue and green LEDs quickly diff --git a/.platformio/platforms/at32/examples/cmsis-blink/src/system_at32f4xx.c b/.platformio/platforms/at32/examples/cmsis-blink/src/system_at32f4xx.c index d724fa6..99a8a54 100644 --- a/.platformio/platforms/at32/examples/cmsis-blink/src/system_at32f4xx.c +++ b/.platformio/platforms/at32/examples/cmsis-blink/src/system_at32f4xx.c @@ -118,8 +118,8 @@ #if defined (AT32F403Axx)|| defined (AT32F407xx) /* #define SYSCLK_FREQ_224MHz 224000000 */ -#define SYSCLK_FREQ_240MHz 240000000 -/* #define SYSCLK_FREQ_224MHz_HSI 224000000 */ +//#define SYSCLK_FREQ_240MHz 240000000 +#define SYSCLK_FREQ_224MHz_HSI 224000000 /* #define SYSCLK_FREQ_240MHz_HSI 240000000 */ #endif diff --git a/README.md b/README.md index 66c3af6..5b2435e 100644 --- a/README.md +++ b/README.md @@ -39,14 +39,20 @@ C/C++ 编译 224K 最大SRAM (AT32F403A) # TO-DO List 待办事项清单 -- Add more examples (USB)
-增加更多示例 (USB) -- Provide Bluepill board example? +- none # Screenshots 屏幕截图 ![VSCode Platform](Docs/VSCode_PlatformIO_2.jpg "VSCode Platform") ![VSCode Platform](Docs/VSCode_PlatformIO_1.jpg "VSCode Platform") +# Available Examples +**AT32F435** +- LED Blink +- USB vcp loopback + +**AT32F403A** +- LED BLink + # AT32F403A on Bluepill PCB - 在 Bluepill PCB 上使用 AT32F403A You can replace the MCU on the Bluepill board with the AT32F403A. It is pin fully compatible. Just need to replace BOOT0 resistor from the present value of 100K with the value of 10K. This will allow the MCU to enter in Bootloader mode and flash it via UART1.
@@ -56,5 +62,5 @@ Just need to replace BOOT0 resistor from the present value of 100K with the valu # AT32F435 on Blackpill PCB You can mount the AT32F435 on the [Blackpill PCB](https://item.taobao.com/item.htm?spm=a230r.1.14.44.458014682yTbFh&id=661526858750&ns=1&abbucket=11#detail) for STM32F103. It works without any other modification requied. -![AT32F435](Docs/AT32F435.jpg "AT32F435 on BLackpill board") +![AT32F435](Docs/AT32F435.jpg "AT32F435 on Blackpill board")