diff --git a/AT32F403A_407_periph_lib_V2.1.6.chm b/AT32F403A_407_periph_lib_V2.1.7.chm similarity index 71% rename from AT32F403A_407_periph_lib_V2.1.6.chm rename to AT32F403A_407_periph_lib_V2.1.7.chm index e2f93cb5..4ccecd6d 100644 Binary files a/AT32F403A_407_periph_lib_V2.1.6.chm and b/AT32F403A_407_periph_lib_V2.1.7.chm differ diff --git a/document/ReleaseNotes_AT32F403A_407_Firmware_Library.pdf b/document/ReleaseNotes_AT32F403A_407_Firmware_Library.pdf index 7f0b0241..a576034b 100644 Binary files a/document/ReleaseNotes_AT32F403A_407_Firmware_Library.pdf and b/document/ReleaseNotes_AT32F403A_407_Firmware_Library.pdf differ diff --git a/libraries/cmsis/cm4/device_support/at32f403a_407.h b/libraries/cmsis/cm4/device_support/at32f403a_407.h index 243db641..e7ef125f 100644 --- a/libraries/cmsis/cm4/device_support/at32f403a_407.h +++ b/libraries/cmsis/cm4/device_support/at32f403a_407.h @@ -161,7 +161,7 @@ extern "C" { */ #define __AT32F403A_407_LIBRARY_VERSION_MAJOR (0x02) /*!< [31:24] major version */ #define __AT32F403A_407_LIBRARY_VERSION_MIDDLE (0x01) /*!< [23:16] middle version */ -#define __AT32F403A_407_LIBRARY_VERSION_MINOR (0x06) /*!< [15:8] minor version */ +#define __AT32F403A_407_LIBRARY_VERSION_MINOR (0x07) /*!< [15:8] minor version */ #define __AT32F403A_407_LIBRARY_VERSION_RC (0x00) /*!< [7:0] release candidate */ #define __AT32F403A_407_LIBRARY_VERSION ((__AT32F403A_407_LIBRARY_VERSION_MAJOR << 24) | \ (__AT32F403A_407_LIBRARY_VERSION_MIDDLE << 16) | \ @@ -280,7 +280,7 @@ typedef enum IRQn DMA2_Channel6_7_IRQn = 75, /*!< dma2 channel 6 and channel 7 global interrupt */ USART6_IRQn = 76, /*!< usart6 interrupt */ UART7_IRQn = 77, /*!< uart7 interrupt */ - UART8_IRQn = 78, /*!< uart8 interrupt */ + UART8_IRQn = 78 /*!< uart8 interrupt */ #endif #if defined (AT32F407xx) @@ -342,7 +342,7 @@ typedef enum IRQn UART7_IRQn = 77, /*!< uart7 interrupt */ UART8_IRQn = 78, /*!< uart8 interrupt */ EMAC_IRQn = 79, /*!< emac interrupt */ - EMAC_WKUP_IRQn = 80, /*!< emac wakeup interrupt */ + EMAC_WKUP_IRQn = 80 /*!< emac wakeup interrupt */ #endif } IRQn_Type; diff --git a/libraries/drivers/ReleaseNotes_AT32F403A_407_Firmware_Library_Drivers.pdf b/libraries/drivers/ReleaseNotes_AT32F403A_407_Firmware_Library_Drivers.pdf index 84c13ffc..11513df1 100644 Binary files a/libraries/drivers/ReleaseNotes_AT32F403A_407_Firmware_Library_Drivers.pdf and b/libraries/drivers/ReleaseNotes_AT32F403A_407_Firmware_Library_Drivers.pdf differ diff --git a/libraries/drivers/inc/at32f403a_407_dma.h b/libraries/drivers/inc/at32f403a_407_dma.h index 0bcb19ff..016b2d30 100644 --- a/libraries/drivers/inc/at32f403a_407_dma.h +++ b/libraries/drivers/inc/at32f403a_407_dma.h @@ -525,6 +525,7 @@ void dma_interrupt_enable(dma_channel_type* dmax_channely, uint32_t dma_int, con void dma_channel_enable(dma_channel_type* dmax_channely, confirm_state new_state); void dma_flexible_config(dma_type* dma_x, uint8_t flex_channelx, dma_flexible_request_type flexible_request); flag_status dma_flag_get(uint32_t dmax_flag); +flag_status dma_interrupt_flag_get(uint32_t dmax_flag); void dma_flag_clear(uint32_t dmax_flag); void dma_default_para_init(dma_init_type* dma_init_struct); void dma_init(dma_channel_type* dmax_channely, dma_init_type* dma_init_struct); diff --git a/libraries/drivers/inc/at32f403a_407_emac.h b/libraries/drivers/inc/at32f403a_407_emac.h index 9efd332f..88f80fbc 100644 --- a/libraries/drivers/inc/at32f403a_407_emac.h +++ b/libraries/drivers/inc/at32f403a_407_emac.h @@ -44,6 +44,7 @@ extern "C" { */ #define PHY_TIMEOUT (0x000FFFFF) /*!< timeout for phy response */ +#define EMAC_USE_ENHANCED_DMA_DESCRIPTOR /** @defgroup EMAC_smi_clock_border_definition * @brief emac smi clock border @@ -269,6 +270,15 @@ extern "C" { #define EMAC_DMA_AIS_FLAG ((uint32_t)0x00008000) /*!< emac dma abnormal interrupt summary */ #define EMAC_DMA_NIS_FLAG ((uint32_t)0x00010000) /*!< emac dma normal interrupt summary */ +/** + * @brief emac ptp time sign + */ +#define EMAC_PTP_POSITIVETIME ((uint32_t)0x00000000) /*!< Positive time value */ +#define EMAC_PTP_NEGATIVETIME ((uint32_t)0x80000000) /*!< Negative time value */ + +#define EMAC_PTP_TI_FLAG ((uint32_t)0x00000004) /*!< Time Stamp Initialized */ +#define EMAC_PTP_TU_FLAG ((uint32_t)0x00000008) /*!< Time Stamp Updated */ +#define EMAC_PTP_ARU_FLAG ((uint32_t)0x00000020) /*!< Addend Register Updated */ /** @defgroup EMAC_exported_types * @{ */ @@ -343,9 +353,10 @@ typedef enum */ typedef enum { - EMAC_CONTROL_FRAME_PASSING_NO = 0x00, /*!< don't pass any control frame to application */ - EMAC_CONTROL_FRAME_PASSING_ALL = 0x02, /*!< pass all control frames to application */ - EMAC_CONTROL_FRAME_PASSING_MATCH = 0x03 /*!< only pass filtered control frames to application */ + EMAC_CONTROL_FRAME_PASSING_NO = 0x00, /*!< don't pass any control frame to application */ + EMAC_CONTROL_FRAME_PASSING_ALL_EXCEPT_PAUSE = 0x01, /*!< pass all control frames to application except pause frame */ + EMAC_CONTROL_FRAME_PASSING_ALL = 0x02, /*!< pass all control frames to application */ + EMAC_CONTROL_FRAME_PASSING_MATCH = 0x03 /*!< only pass filtered control frames to application */ } emac_control_frames_filter_type; /** @@ -631,6 +642,10 @@ typedef struct { uint32_t controlsize; /*!< control and buffer1, buffer2 lengths */ uint32_t buf1addr; /*!< buffer1 address pointer */ uint32_t buf2nextdescaddr; /*!< buffer2 or next descriptor address pointer */ + uint32_t extendedstatus; + uint32_t reserved1; + uint32_t timestamp_l; + uint32_t timestamp_h; } emac_dma_desc_type; /** @@ -889,7 +904,7 @@ typedef struct __IO uint32_t reserved1 : 8; /* [16:23] */ __IO uint32_t mbc : 6; /* [24:29] */ __IO uint32_t sa : 1; /* [30] */ - __IO uint32_t ae : 1; /* [31] */ + __IO uint32_t ae : 1; /* [31] */ } a1h_bit; }; @@ -1326,7 +1341,7 @@ typedef struct __IO uint32_t swr : 1; /* [0] */ __IO uint32_t da : 1; /* [1] */ __IO uint32_t dsl : 5; /* [2:6] */ - __IO uint32_t reserved1 : 1; /* [7] */ + __IO uint32_t atds : 1; /* [7] */ __IO uint32_t pbl : 6; /* [8:13] */ __IO uint32_t pr : 2; /* [14:15] */ __IO uint32_t fb : 1; /* [16] */ @@ -1334,7 +1349,7 @@ typedef struct __IO uint32_t usp : 1; /* [23] */ __IO uint32_t pblx8 : 1; /* [24] */ __IO uint32_t aab : 1; /* [25] */ - __IO uint32_t reserved2 : 6; /* [26:31] */ + __IO uint32_t reserved : 6; /* [26:31] */ } bm_bit; }; @@ -1626,6 +1641,7 @@ void emac_address_filter_set(emac_address_type mac, emac_address_filter_type fil uint32_t emac_received_packet_size_get(void); uint32_t emac_dmarxdesc_frame_length_get(emac_dma_desc_type *dma_rx_desc); void emac_dma_descriptor_list_address_set(emac_dma_tx_rx_type transfer_type, emac_dma_desc_type *dma_desc_tab, uint8_t *buff, uint32_t buffer_count); +void emac_ptp_dma_descriptor_list_address_set(emac_dma_tx_rx_type transfer_type, emac_dma_desc_type *dma_desc_tab, emac_dma_desc_type *ptp_dma_desc_tab, uint8_t *buff, uint32_t buffer_count); uint32_t emac_dma_descriptor_list_address_get(emac_dma_tx_rx_type transfer_type); void emac_dma_rx_desc_interrupt_config(emac_dma_desc_type *dma_rx_desc, confirm_state new_state); void emac_dma_para_init(emac_dma_config_type *control_para); @@ -1648,6 +1664,7 @@ uint8_t emac_dma_missing_overflow_bit_get(void); uint16_t emac_dma_application_missing_frame_get(void); uint8_t emac_dma_fifo_overflow_bit_get(void); uint32_t emac_dma_tansfer_address_get(emac_dma_transfer_address_type transfer_type); +void emac_dma_alternate_desc_size(confirm_state new_state); void emac_mmc_counter_reset(void); void emac_mmc_rollover_stop(confirm_state new_state); void emac_mmc_reset_on_read_enable(confirm_state new_state); @@ -1674,13 +1691,12 @@ void emac_ptp_snapshot_event_message_enable(confirm_state new_state); void emac_ptp_snapshot_master_event_enable(confirm_state new_state); void emac_ptp_clock_node_set(emac_ptp_clock_node_type node); void emac_ptp_mac_address_filter_enable(confirm_state new_state); +flag_status emac_ptp_flag_get(uint32_t flag); void emac_ptp_subsecond_increment_set(uint8_t value); uint32_t emac_ptp_system_second_get(void); uint32_t emac_ptp_system_subsecond_get(void); confirm_state emac_ptp_system_time_sign_get(void); -void emac_ptp_system_second_set(uint32_t second); -void emac_ptp_system_subsecond_set(uint32_t subsecond); -void emac_ptp_system_time_sign_set(confirm_state sign); +void emac_ptp_system_time_set(uint32_t sign, uint32_t second, uint32_t subsecond); void emac_ptp_timestamp_addend_set(uint32_t value); void emac_ptp_target_second_set(uint32_t value); void emac_ptp_target_nanosecond_set(uint32_t value); diff --git a/libraries/drivers/inc/at32f403a_407_flash.h b/libraries/drivers/inc/at32f403a_407_flash.h index bbde24e7..9b65ce5d 100644 --- a/libraries/drivers/inc/at32f403a_407_flash.h +++ b/libraries/drivers/inc/at32f403a_407_flash.h @@ -188,7 +188,7 @@ typedef enum typedef enum { FLASH_SPIM_MODEL1 = 0x01, /*!< spim model 1 */ - FLASH_SPIM_MODEL2 = 0x02, /*!< spim model 2 */ + FLASH_SPIM_MODEL2 = 0x02 /*!< spim model 2 */ } flash_spim_model_type; /** diff --git a/libraries/drivers/src/at32f403a_407_dma.c b/libraries/drivers/src/at32f403a_407_dma.c index 8c83fa07..77ce26dd 100644 --- a/libraries/drivers/src/at32f403a_407_dma.c +++ b/libraries/drivers/src/at32f403a_407_dma.c @@ -278,6 +278,52 @@ void dma_flexible_config(dma_type* dma_x, uint8_t flex_channelx, dma_flexible_re } } +/** + * @brief get dma interrupt flag + * @param dmax_flag + * this parameter can be one of the following values: + * - DMA1_FDT1_FLAG - DMA1_HDT1_FLAG - DMA1_DTERR1_FLAG + * - DMA1_FDT2_FLAG - DMA1_HDT2_FLAG - DMA1_DTERR2_FLAG + * - DMA1_FDT3_FLAG - DMA1_HDT3_FLAG - DMA1_DTERR3_FLAG + * - DMA1_FDT4_FLAG - DMA1_HDT4_FLAG - DMA1_DTERR4_FLAG + * - DMA1_FDT5_FLAG - DMA1_HDT5_FLAG - DMA1_DTERR5_FLAG + * - DMA1_FDT6_FLAG - DMA1_HDT6_FLAG - DMA1_DTERR6_FLAG + * - DMA1_FDT7_FLAG - DMA1_HDT7_FLAG - DMA1_DTERR7_FLAG + * - DMA2_FDT1_FLAG - DMA2_HDT1_FLAG - DMA2_DTERR1_FLAG + * - DMA2_FDT2_FLAG - DMA2_HDT2_FLAG - DMA2_DTERR2_FLAG + * - DMA2_FDT3_FLAG - DMA2_HDT3_FLAG - DMA2_DTERR3_FLAG + * - DMA2_FDT4_FLAG - DMA2_HDT4_FLAG - DMA2_DTERR4_FLAG + * - DMA2_FDT5_FLAG - DMA2_HDT5_FLAG - DMA2_DTERR5_FLAG + * - DMA2_FDT6_FLAG - DMA2_HDT6_FLAG - DMA2_DTERR6_FLAG + * - DMA2_FDT7_FLAG - DMA2_HDT7_FLAG - DMA2_DTERR7_FLAG + * @retval state of dma flag + */ +flag_status dma_interrupt_flag_get(uint32_t dmax_flag) +{ + flag_status status = RESET; + uint32_t temp = 0; + + if(dmax_flag > 0x10000000) + { + temp = DMA2->sts; + } + else + { + temp = DMA1->sts; + } + + if ((temp & dmax_flag) != (uint16_t)RESET) + { + status = SET; + } + else + { + status = RESET; + } + + return status; +} + /** * @brief get dma flag * @param dmax_flag diff --git a/libraries/drivers/src/at32f403a_407_emac.c b/libraries/drivers/src/at32f403a_407_emac.c index 4ed337af..fefd9056 100644 --- a/libraries/drivers/src/at32f403a_407_emac.c +++ b/libraries/drivers/src/at32f403a_407_emac.c @@ -43,8 +43,10 @@ /** * @brief global pointers on tx and rx descriptor used to track transmit and receive descriptors */ -emac_dma_desc_type *dma_tx_desc_to_set; -emac_dma_desc_type *dma_rx_desc_to_get; +__IO emac_dma_desc_type *dma_tx_desc_to_set; +__IO emac_dma_desc_type *dma_rx_desc_to_get; +__IO emac_dma_desc_type *ptp_dma_tx_desc_to_set; +__IO emac_dma_desc_type *ptp_dma_rx_desc_to_get; /* emac private function */ static void emac_delay(uint32_t delay); @@ -523,6 +525,7 @@ void emac_broadcast_frames_disable(confirm_state new_state) * @param condition: set what control frame can pass filter. * this parameter can be one of the following values: * - EMAC_CONTROL_FRAME_PASSING_NO + * - EMAC_CONTROL_FRAME_PASSING_ALL_EXCEPT_PAUSE * - EMAC_CONTROL_FRAME_PASSING_ALL * - EMAC_CONTROL_FRAME_PASSING_MATCH * @retval none @@ -982,6 +985,90 @@ void emac_dma_descriptor_list_address_set(emac_dma_tx_rx_type transfer_type, ema } } +/** + * @brief set transmit/receive descriptor list address + * @param transfer_type: it will be transmit or receive + * this parameter can be one of the following values: + * - EMAC_DMA_TRANSMIT + * - EMAC_DMA_RECEIVE + * @param dma_desc_tab: pointer on the first tx desc list + * @param buff: pointer on the first tx/rx buffer list + * @param buffer_count: number of the used Tx desc in the list + * @retval none + */ +void emac_ptp_dma_descriptor_list_address_set(emac_dma_tx_rx_type transfer_type, emac_dma_desc_type *dma_desc_tab, emac_dma_desc_type *ptp_dma_desc_tab, uint8_t *buff, uint32_t buffer_count) +{ + uint32_t i = 0; + emac_dma_desc_type *dma_descriptor; + + switch(transfer_type) + { + case EMAC_DMA_TRANSMIT: + { + dma_tx_desc_to_set = dma_desc_tab; + ptp_dma_tx_desc_to_set = ptp_dma_desc_tab; + + for(i = 0; i < buffer_count; i++) + { + dma_descriptor = dma_desc_tab + i; + + dma_descriptor->status = EMAC_DMATXDESC_TCH | EMAC_DMATXDESC_TTSE; + + dma_descriptor->buf1addr = (uint32_t)(&buff[i * EMAC_MAX_PACKET_LENGTH]); + + if(i < (buffer_count - 1)) + { + dma_descriptor->buf2nextdescaddr = (uint32_t)(dma_desc_tab + i + 1); + } + else + { + dma_descriptor->buf2nextdescaddr = (uint32_t) dma_desc_tab; + } + + (&ptp_dma_desc_tab[i])->buf1addr = dma_descriptor->buf1addr; + (&ptp_dma_desc_tab[i])->buf2nextdescaddr = dma_descriptor->buf2nextdescaddr; + } + + (&ptp_dma_desc_tab[i-1])->status = (uint32_t) ptp_dma_desc_tab; + + EMAC_DMA->tdladdr_bit.stl = (uint32_t) dma_desc_tab; + break; + } + case EMAC_DMA_RECEIVE: + { + dma_rx_desc_to_get = dma_desc_tab; + ptp_dma_rx_desc_to_get = ptp_dma_desc_tab; + + for(i = 0; i < buffer_count; i++) + { + dma_descriptor = dma_desc_tab + i; + + dma_descriptor->status = EMAC_DMARXDESC_OWN; + + dma_descriptor->controlsize = EMAC_DMARXDESC_RCH | (uint32_t)EMAC_MAX_PACKET_LENGTH; + + dma_descriptor->buf1addr = (uint32_t)(&buff[i * EMAC_MAX_PACKET_LENGTH]); + + if(i < (buffer_count - 1)) + { + dma_descriptor->buf2nextdescaddr = (uint32_t)(dma_desc_tab + i + 1); + } + else + { + dma_descriptor->buf2nextdescaddr = (uint32_t) dma_desc_tab; + } + + (&ptp_dma_desc_tab[i])->buf1addr = dma_descriptor->buf1addr; + (&ptp_dma_desc_tab[i])->buf2nextdescaddr = dma_descriptor->buf2nextdescaddr; + } + + (&ptp_dma_desc_tab[i-1])->status = (uint32_t) ptp_dma_desc_tab; + + EMAC_DMA->rdladdr_bit.srl = (uint32_t) dma_desc_tab; + break; + } + } +} /** * @brief enable or disable the specified dma rx descriptor receive interrupt * @param dma_rx_desc: pointer on a rx desc. @@ -1042,7 +1129,7 @@ uint32_t emac_received_packet_size_get(void) ((dma_rx_desc_to_get->status & EMAC_DMARXDESC_LS) != (uint32_t)RESET) && ((dma_rx_desc_to_get->status & EMAC_DMARXDESC_FS) != (uint32_t)RESET)) { - frame_length = emac_dmarxdesc_frame_length_get(dma_rx_desc_to_get); + frame_length = emac_dmarxdesc_frame_length_get((emac_dma_desc_type*) dma_rx_desc_to_get); } return frame_length; @@ -1653,6 +1740,16 @@ uint32_t emac_dma_tansfer_address_get(emac_dma_transfer_address_type transfer_ty return address; } +/** + * @brief alternate dma descriptor size + * @param new_state: TRUE or FALSE + * @retval none + */ +void emac_dma_alternate_desc_size(confirm_state new_state) +{ + EMAC_DMA->bm_bit.atds = new_state; +} + /** * @brief reset all counter * @param none @@ -2032,6 +2129,27 @@ void emac_ptp_mac_address_filter_enable(confirm_state new_state) EMAC_PTP->tsctrl_bit.emafpff = new_state; } +/** + * @brief check whether the specified emac ptp flag is set or not. + * @param flag: specifies the flag to check. + * this parameter can be one of the following values: + * - EMAC_PTP_TI_FLAG: time stamp initialized flag + * - EMAC_PTP_TU_FLAG: time stamp updtated flag + * - EMAC_PTP_ARU_FLAG: transmit data buffer empty flag + * @retval the new state of usart_flag (SET or RESET). + */ +flag_status emac_ptp_flag_get(uint32_t flag) +{ + if(EMAC_PTP->tsctrl & flag) + { + return SET; + } + else + { + return RESET; + } +} + /** * @brief set subsecond increment value * @param value: add to subsecond value for every update @@ -2082,42 +2200,19 @@ confirm_state emac_ptp_system_time_sign_get(void) } /** - * @brief set system time second + * @brief set system time + * @param sign: plus or minus * @param second: system time second - * @retval none - */ -void emac_ptp_system_second_set(uint32_t second) -{ - EMAC_PTP->tshud_bit.ts = second; -} - -/** - * @brief set system time subsecond * @param subsecond: system time subsecond * @retval none */ -void emac_ptp_system_subsecond_set(uint32_t subsecond) +void emac_ptp_system_time_set(uint32_t sign, uint32_t second, uint32_t subsecond) { + EMAC_PTP->tslud_bit.ast = sign ? 1 : 0; + EMAC_PTP->tshud_bit.ts = second; EMAC_PTP->tslud_bit.tss = subsecond; } -/** - * @brief set system time sign - * @param sign: TRUE or FALSE. - * @retval none - */ -void emac_ptp_system_time_sign_set(confirm_state sign) -{ - if(sign) - { - EMAC_PTP->tslud_bit.ast = 1; - } - else - { - EMAC_PTP->tslud_bit.ast = 0; - } -} - /** * @brief set time stamp addend * @param value: to achieve time synchronization diff --git a/libraries/drivers/src/at32f403a_407_exint.c b/libraries/drivers/src/at32f403a_407_exint.c index 9cea28ba..eb1934a0 100644 --- a/libraries/drivers/src/at32f403a_407_exint.c +++ b/libraries/drivers/src/at32f403a_407_exint.c @@ -175,8 +175,10 @@ flag_status exint_flag_get(uint32_t exint_line) flag_status exint_interrupt_flag_get(uint32_t exint_line) { flag_status status = RESET; - uint32_t exint_flag =0; - exint_flag = EXINT->intsts & exint_line & EXINT->inten; + uint32_t exint_flag = 0; + exint_flag = EXINT->intsts & exint_line; + exint_flag = exint_flag & EXINT->inten; + if((exint_flag != (uint16_t)RESET)) { status = SET; diff --git a/libraries/drivers/src/at32f403a_407_i2c.c b/libraries/drivers/src/at32f403a_407_i2c.c index 10192bf4..48d1ea88 100644 --- a/libraries/drivers/src/at32f403a_407_i2c.c +++ b/libraries/drivers/src/at32f403a_407_i2c.c @@ -641,7 +641,7 @@ flag_status i2c_interrupt_flag_get(i2c_type *i2c_x, uint32_t flag) break; case I2C_RDBF_FLAG: case I2C_TDBE_FLAG: - iten = i2c_x->ctrl2_bit.dataien & i2c_x->ctrl2_bit.evtien; + iten = i2c_x->ctrl2_bit.dataien && i2c_x->ctrl2_bit.evtien; break; case I2C_BUSERR_FLAG: case I2C_ARLOST_FLAG: diff --git a/libraries/drivers/src/at32f403a_407_xmc.c b/libraries/drivers/src/at32f403a_407_xmc.c index 7f3a4294..b9158d7d 100644 --- a/libraries/drivers/src/at32f403a_407_xmc.c +++ b/libraries/drivers/src/at32f403a_407_xmc.c @@ -487,17 +487,17 @@ flag_status xmc_interrupt_flag_status_get(xmc_class_bank_type xmc_bank, xmc_inte switch(xmc_flag) { case XMC_RISINGEDGE_FLAG: - if(XMC_BANK2->bk2is_bit.reien & XMC_BANK2->bk2is_bit.res) + if(XMC_BANK2->bk2is_bit.reien && XMC_BANK2->bk2is_bit.res) status = SET; break; case XMC_LEVEL_FLAG: - if(XMC_BANK2->bk2is_bit.feien & XMC_BANK2->bk2is_bit.fes) + if(XMC_BANK2->bk2is_bit.feien && XMC_BANK2->bk2is_bit.fes) status = SET; break; case XMC_FALLINGEDGE_FLAG: - if(XMC_BANK2->bk2is_bit.hlien & XMC_BANK2->bk2is_bit.hls) + if(XMC_BANK2->bk2is_bit.hlien && XMC_BANK2->bk2is_bit.hls) status = SET; break; diff --git a/middlewares/usbd_class/audio_hid/audio_hid_class.c b/middlewares/usbd_class/audio_hid/audio_hid_class.c index 90d9753a..c3d6595c 100644 --- a/middlewares/usbd_class/audio_hid/audio_hid_class.c +++ b/middlewares/usbd_class/audio_hid/audio_hid_class.c @@ -284,13 +284,18 @@ usb_sts_type class_hid_setup_handler(void *udev, usb_setup_type *setup) { len = MIN(USBD_AUHID_HID_SIZ_REPORT_DESC, setup->wLength); buf = (uint8_t *)g_usbd_audio_hid_report; + usbd_ctrl_send(pudev, (uint8_t *)buf, len); } else if(setup->wValue >> 8 == HID_DESCRIPTOR_TYPE) { len = MIN(9, setup->wLength); buf = (uint8_t *)g_audio_hid_usb_desc; + usbd_ctrl_send(pudev, (uint8_t *)buf, len); + } + else + { + usbd_ctrl_unsupport(pudev); } - usbd_ctrl_send(pudev, (uint8_t *)buf, len); break; case USB_STD_REQ_GET_INTERFACE: usbd_ctrl_send(pudev, (uint8_t *)&paudio_hid->alt_setting, 1); diff --git a/middlewares/usbd_class/composite_cdc_keyboard/cdc_keyboard_class.c b/middlewares/usbd_class/composite_cdc_keyboard/cdc_keyboard_class.c index ab7a4062..f423be99 100644 --- a/middlewares/usbd_class/composite_cdc_keyboard/cdc_keyboard_class.c +++ b/middlewares/usbd_class/composite_cdc_keyboard/cdc_keyboard_class.c @@ -422,13 +422,18 @@ static usb_sts_type keyboard_class_setup_handler(void *udev, usb_setup_type *set { len = MIN(USBD_VCPKYBRD_HID_SIZ_REPORT_DESC, setup->wLength); buf = (uint8_t *)g_usbd_vcpkybrd_hid_report; + usbd_ctrl_send(pudev, (uint8_t *)buf, len); } else if(setup->wValue >> 8 == HID_DESCRIPTOR_TYPE) { len = MIN(9, setup->wLength); buf = (uint8_t *)g_vcpkybrd_hid_usb_desc; + usbd_ctrl_send(pudev, (uint8_t *)buf, len); + } + else + { + usbd_ctrl_unsupport(pudev); } - usbd_ctrl_send(pudev, (uint8_t *)buf, len); break; case USB_STD_REQ_GET_INTERFACE: usbd_ctrl_send(pudev, (uint8_t *)&vcpkybrd->alt_setting, 1); diff --git a/middlewares/usbd_class/custom_hid/custom_hid_class.c b/middlewares/usbd_class/custom_hid/custom_hid_class.c index 4d0bdc05..2af440c6 100644 --- a/middlewares/usbd_class/custom_hid/custom_hid_class.c +++ b/middlewares/usbd_class/custom_hid/custom_hid_class.c @@ -166,13 +166,18 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup) { len = MIN(USBD_CUSHID_SIZ_REPORT_DESC, setup->wLength); buf = (uint8_t *)g_usbd_custom_hid_report; + usbd_ctrl_send(pudev, (uint8_t *)buf, len); } else if(setup->wValue >> 8 == HID_DESCRIPTOR_TYPE) { len = MIN(9, setup->wLength); buf = (uint8_t *)g_custom_hid_usb_desc; + usbd_ctrl_send(pudev, (uint8_t *)buf, len); + } + else + { + usbd_ctrl_unsupport(pudev); } - usbd_ctrl_send(pudev, (uint8_t *)buf, len); break; case USB_STD_REQ_GET_INTERFACE: usbd_ctrl_send(pudev, (uint8_t *)&pcshid->alt_setting, 1); diff --git a/middlewares/usbd_class/hid_iap/hid_iap_class.c b/middlewares/usbd_class/hid_iap/hid_iap_class.c index b5c3dbef..c7c287b1 100644 --- a/middlewares/usbd_class/hid_iap/hid_iap_class.c +++ b/middlewares/usbd_class/hid_iap/hid_iap_class.c @@ -157,13 +157,18 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup) { len = MIN(USBD_HIDIAP_SIZ_REPORT_DESC, setup->wLength); buf = (uint8_t *)g_usbd_hidiap_report; + usbd_ctrl_send(pudev, (uint8_t *)buf, len); } else if(setup->wValue >> 8 == HID_DESCRIPTOR_TYPE) { len = MIN(9, setup->wLength); buf = (uint8_t *)g_hidiap_usb_desc; + usbd_ctrl_send(pudev, (uint8_t *)buf, len); + } + else + { + usbd_ctrl_unsupport(pudev); } - usbd_ctrl_send(pudev, (uint8_t *)buf, len); break; case USB_STD_REQ_GET_INTERFACE: usbd_ctrl_send(pudev, (uint8_t *)&piap->alt_setting, 1); diff --git a/middlewares/usbd_class/keyboard/keyboard_class.c b/middlewares/usbd_class/keyboard/keyboard_class.c index d1a9a5c2..3493fe9c 100644 --- a/middlewares/usbd_class/keyboard/keyboard_class.c +++ b/middlewares/usbd_class/keyboard/keyboard_class.c @@ -287,13 +287,18 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup) { len = MIN(USBD_KEYBOARD_SIZ_REPORT_DESC, setup->wLength); buf = (uint8_t *)g_usbd_keyboard_report; + usbd_ctrl_send(pudev, (uint8_t *)buf, len); } else if(setup->wValue >> 8 == HID_DESCRIPTOR_TYPE) { len = MIN(9, setup->wLength); buf = (uint8_t *)g_keyboard_usb_desc; + usbd_ctrl_send(pudev, (uint8_t *)buf, len); + } + else + { + usbd_ctrl_unsupport(pudev); } - usbd_ctrl_send(pudev, (uint8_t *)buf, len); break; case USB_STD_REQ_GET_INTERFACE: usbd_ctrl_send(pudev, (uint8_t *)&pkeyboard->alt_setting, 1); diff --git a/middlewares/usbd_class/mouse/mouse_class.c b/middlewares/usbd_class/mouse/mouse_class.c index 45fc59a7..e519bd33 100644 --- a/middlewares/usbd_class/mouse/mouse_class.c +++ b/middlewares/usbd_class/mouse/mouse_class.c @@ -152,13 +152,18 @@ static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup) { len = MIN(USBD_MOUSE_SIZ_REPORT_DESC, setup->wLength); buf = (uint8_t *)g_usbd_mouse_report; + usbd_ctrl_send(pudev, (uint8_t *)buf, len); } else if(setup->wValue >> 8 == HID_DESCRIPTOR_TYPE) { len = MIN(9, setup->wLength); buf = (uint8_t *)g_mouse_usb_desc; + usbd_ctrl_send(pudev, (uint8_t *)buf, len); + } + else + { + usbd_ctrl_unsupport(pudev); } - usbd_ctrl_send(pudev, (uint8_t *)buf, len); break; case USB_STD_REQ_GET_INTERFACE: usbd_ctrl_send(pudev, (uint8_t *)&pmouse->alt_setting, 1); diff --git a/middlewares/usbd_class/winusb/winusb_class.c b/middlewares/usbd_class/winusb/winusb_class.c new file mode 100644 index 00000000..191d67fa --- /dev/null +++ b/middlewares/usbd_class/winusb/winusb_class.c @@ -0,0 +1,413 @@ +/** + ************************************************************************** + * @file winusb_class.c + * @brief usb winusb 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 "winusb_class.h" +#include "winusb_desc.h" +#include "string.h" +#include "stdio.h" +#include "stdlib.h" + +/** @addtogroup AT32F403A_407_middlewares_usbd_class + * @{ + */ + +/** @defgroup USB_winusb_class + * @brief usb device class win usb + * @{ + */ + +/** @defgroup USB_winusb_class_private_functions + * @{ + */ + +static usb_sts_type class_init_handler(void *udev); +static usb_sts_type class_clear_handler(void *udev); +static usb_sts_type class_setup_handler(void *udev, usb_setup_type *setup); +static usb_sts_type class_ept0_tx_handler(void *udev); +static usb_sts_type class_ept0_rx_handler(void *udev); +static usb_sts_type class_in_handler(void *udev, uint8_t ept_num); +static usb_sts_type class_out_handler(void *udev, uint8_t ept_num); +static usb_sts_type class_sof_handler(void *udev); +static usb_sts_type class_event_handler(void *udev, usbd_event_type event); +#if (USBD_SUPPORT_WINUSB == 1) +static usb_sts_type usbd_get_winusb_descriptor(usbd_core_type *udev); +#endif +static usb_sts_type winusb_struct_init(winusb_struct_type *p_winusb); + +/* winusb data struct */ +winusb_struct_type winusb_struct; + +/*winusb receive buffer define*/ +static uint32_t g_winusb_rx_buffer[16]; + +/* usb device class handler */ +usbd_class_handler winusb_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, + &winusb_struct +}; +/** + * @brief initialize usb endpoint + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +static usb_sts_type class_init_handler(void *udev) +{ + usb_sts_type status = USB_OK; + usbd_core_type *pudev = (usbd_core_type *)udev; + winusb_struct_type *p_winusb = (winusb_struct_type *)pudev->class_handler->pdata; + + /* init winusb struct */ + winusb_struct_init(p_winusb); + + p_winusb->maxpacket = USBD_FS_WINUSB_MAXPACKET_SIZE; + +#ifndef USB_EPT_AUTO_MALLOC_BUFFER + /* use user define buffer address */ + usbd_ept_buf_custom_define(pudev, USBD_WINUSB_BULK_IN_EPT, EPT1_TX_ADDR); + usbd_ept_buf_custom_define(pudev, USBD_WINUSB_BULK_OUT_EPT, EPT1_RX_ADDR); +#endif + + /* open out endpoint */ + usbd_ept_open(pudev, USBD_WINUSB_BULK_OUT_EPT, EPT_BULK_TYPE, USBD_WINUSB_OUT_MAXPACKET_SIZE); + + /* open in endpoint */ + usbd_ept_open(pudev, USBD_WINUSB_BULK_IN_EPT, EPT_BULK_TYPE, USBD_WINUSB_IN_MAXPACKET_SIZE); + + /* set out endpoint to receive status */ + usbd_ept_recv(pudev, USBD_WINUSB_BULK_OUT_EPT, p_winusb->g_rx_buff, USBD_WINUSB_OUT_MAXPACKET_SIZE); + + return status; +} + +/** + * @brief clear endpoint or other state + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +static 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_WINUSB_BULK_IN_EPT); + + /* close out endpoint */ + usbd_ept_close(pudev, USBD_WINUSB_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 + */ +static 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; + winusb_struct_type *p_winusb = (winusb_struct_type *)pudev->class_handler->pdata; + + switch(setup->bmRequestType & USB_REQ_TYPE_RESERVED) + { + /* class request */ + case USB_REQ_TYPE_CLASS: + usbd_ctrl_unsupport(pudev); + 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 *)&p_winusb->alt_setting, 1); + break; + case USB_STD_REQ_SET_INTERFACE: + p_winusb->alt_setting = setup->wValue; + break; + case USB_STD_REQ_CLEAR_FEATURE: + break; + case USB_STD_REQ_SET_FEATURE: + break; + default: + usbd_ctrl_unsupport(pudev); + break; + } + break; +#if (USBD_SUPPORT_WINUSB == 1) + case USB_REQ_TYPE_VENDOR: + if(setup->bRequest == WINUSB_BMS_VENDOR_CODE) + { + usbd_get_winusb_descriptor(pudev); + } + else + { + usbd_ctrl_unsupport(pudev); + } + break; +#endif + default: + usbd_ctrl_unsupport(pudev); + break; + } + return status; +} + +#if (USBD_SUPPORT_WINUSB == 1) +static usb_sts_type usbd_get_winusb_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.wIndex; + + switch(desc_type) + { + case USB_WINUSB_COMPAT_ID: + desc = udev->desc_handler->get_device_winusb_os_feature(); + break; + case USB_WINUSB_PROPERTIES_ID: + desc = udev->desc_handler->get_device_winusb_os_property(); + break; + 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; +} +#endif + +/** + * @brief usb device endpoint 0 in status stage complete + * @param udev: to the structure of usbd_core_type + * @retval status of usb_sts_type + */ +static 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 + */ +static usb_sts_type class_ept0_rx_handler(void *udev) +{ + usb_sts_type status = USB_OK; + 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 + */ +static usb_sts_type class_in_handler(void *udev, uint8_t ept_num) +{ + usbd_core_type *pudev = (usbd_core_type *)udev; + winusb_struct_type *p_winusb = (winusb_struct_type *)pudev->class_handler->pdata; + usb_sts_type status = USB_OK; + + /* ...user code... + trans next packet data + */ + p_winusb->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 + */ +static 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; + winusb_struct_type *p_winusb = (winusb_struct_type *)pudev->class_handler->pdata; + + /* get endpoint receive data length */ + p_winusb->g_rxlen = usbd_get_recv_len(pudev, ept_num); + + /*set recv flag*/ + p_winusb->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 + */ +static 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 + */ +static 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; + + default: + break; + } + return status; +} + +/** + * @brief usb device winusb init + * @param p_winusb: to the structure of winusb_struct + * @retval status of usb_sts_type + */ +static usb_sts_type winusb_struct_init(winusb_struct_type *p_winusb) +{ + p_winusb->g_tx_completed = 1; + p_winusb->g_rx_completed = 0; + p_winusb->alt_setting = 0; + p_winusb->g_rx_buff = (uint8_t *)g_winusb_rx_buffer; + return USB_OK; +} + +/** + * @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_winusb_get_rxdata(void *udev, uint8_t *recv_data) +{ + uint16_t i_index = 0; + uint16_t tmp_len = 0; + usbd_core_type *pudev = (usbd_core_type *)udev; + winusb_struct_type *p_winusb = (winusb_struct_type *)pudev->class_handler->pdata; + + if(p_winusb->g_rx_completed == 0) + { + return 0; + } + p_winusb->g_rx_completed = 0; + tmp_len = p_winusb->g_rxlen; + for(i_index = 0; i_index < p_winusb->g_rxlen; i_index ++) + { + recv_data[i_index] = p_winusb->g_rx_buff[i_index]; + } + + usbd_ept_recv(pudev, USBD_WINUSB_BULK_OUT_EPT, p_winusb->g_rx_buff, p_winusb->maxpacket); + + 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_winusb_send_data(void *udev, uint8_t *send_data, uint16_t len) +{ + error_status status = SUCCESS; + usbd_core_type *pudev = (usbd_core_type *)udev; + winusb_struct_type *p_winusb = (winusb_struct_type *)pudev->class_handler->pdata; + if(p_winusb->g_tx_completed) + { + p_winusb->g_tx_completed = 0; + usbd_ept_send(pudev, USBD_WINUSB_BULK_IN_EPT, send_data, len); + } + else + { + status = ERROR; + } + return status; +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + diff --git a/middlewares/usbd_class/winusb/winusb_class.h b/middlewares/usbd_class/winusb/winusb_class.h new file mode 100644 index 00000000..4631e7bf --- /dev/null +++ b/middlewares/usbd_class/winusb/winusb_class.h @@ -0,0 +1,115 @@ +/** + ************************************************************************** + * @file winusb_class.h + * @brief usb winusb 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 __WINUSB_CLASS_H +#define __WINUSB_CLASS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "usb_std.h" +#include "usbd_core.h" + +/** @addtogroup AT32F403A_407_middlewares_usbd_class + * @{ + */ + +/** @addtogroup USB_winusb_class + * @{ + */ + +/** @defgroup USB_winusb_class_definition + * @{ + */ + +/** + * @brief usb use endpoint define + */ +#define USBD_WINUSB_BULK_IN_EPT 0x81 +#define USBD_WINUSB_BULK_OUT_EPT 0x01 + +/** + * @brief usb in and out max packet size define + */ + +#define USBD_FS_WINUSB_MAXPACKET_SIZE 0x40 +#define USBD_WINUSB_IN_MAXPACKET_SIZE USBD_FS_WINUSB_MAXPACKET_SIZE +#define USBD_WINUSB_OUT_MAXPACKET_SIZE USBD_FS_WINUSB_MAXPACKET_SIZE + +#define WINUSB_BMS_VENDOR_CODE 0xA0 + +/** + * @} + */ + +/** @defgroup USB_winusb_class_exported_types + * @{ + */ + +/** + * @brief usb winusb class struct + */ +typedef struct +{ + uint32_t alt_setting; + uint8_t *g_rx_buff; + uint16_t g_len, g_rxlen; + __IO uint8_t g_tx_completed, g_rx_completed; + uint32_t maxpacket; +}winusb_struct_type; + + +/** + * @} + */ + +/** @defgroup USB_cdc_class_exported_functions + * @{ + */ +extern usbd_class_handler winusb_class_handler; +uint16_t usb_winusb_get_rxdata(void *udev, uint8_t *recv_data); +error_status usb_winusb_send_data(void *udev, uint8_t *send_data, uint16_t len); + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ +#ifdef __cplusplus +} +#endif + +#endif + + + + diff --git a/middlewares/usbd_class/winusb/winusb_desc.c b/middlewares/usbd_class/winusb/winusb_desc.c new file mode 100644 index 00000000..5bfc7801 --- /dev/null +++ b/middlewares/usbd_class/winusb/winusb_desc.c @@ -0,0 +1,527 @@ +/** + ************************************************************************** + * @file winusb_desc.c + * @brief usb winusb 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 "winusb_desc.h" + +/** @addtogroup AT32F403A_407_middlewares_usbd_class + * @{ + */ + +/** @defgroup USB_winusb_desc + * @brief usb device winusb descriptor + * @{ + */ + +/** @defgroup USB_winusb_desc_private_functions + * @{ + */ + +static usbd_desc_t *get_device_descriptor(void); +static usbd_desc_t *get_device_qualifier(void); +static usbd_desc_t *get_device_configuration(void); +static usbd_desc_t *get_device_other_speed(void); +static usbd_desc_t *get_device_lang_id(void); +static usbd_desc_t *get_device_manufacturer_string(void); +static usbd_desc_t *get_device_product_string(void); +static usbd_desc_t *get_device_serial_string(void); +static usbd_desc_t *get_device_interface_string(void); +static usbd_desc_t *get_device_config_string(void); + +static 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); + +#if (USBD_SUPPORT_WINUSB == 1) +static usbd_desc_t *get_device_winusb_os_string(void); +static usbd_desc_t *get_device_winusb_os_feature(void); +static usbd_desc_t *get_device_winusb_os_property(void); +#endif + +#if defined ( __ICCARM__ ) /* iar compiler */ + #pragma data_alignment=4 +#endif +ALIGNED_HEAD static uint8_t g_usbd_desc_buffer[256] ALIGNED_TAIL; + +/** + * @brief device descriptor handler structure + */ +usbd_desc_handler winusb_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, +#if (USBD_SUPPORT_WINUSB == 1) + get_device_winusb_os_string, + get_device_winusb_os_feature, + get_device_winusb_os_property +#endif +}; + +/** + * @brief usb device standard descriptor + */ +#if defined ( __ICCARM__ ) /* iar compiler */ + #pragma data_alignment=4 +#endif +ALIGNED_HEAD static uint8_t g_usbd_descriptor[USB_DEVICE_DESC_LEN] ALIGNED_TAIL = +{ + USB_DEVICE_DESC_LEN, /* bLength */ + USB_DESCIPTOR_TYPE_DEVICE, /* bDescriptorType */ + 0x00, /* bcdUSB */ + 0x02, + 0x00, /* bDeviceClass */ + 0x00, /* bDeviceSubClass */ + 0x00, /* bDeviceProtocol */ + USB_MAX_EP0_SIZE, /* bMaxPacketSize */ + LBYTE(USBD_WINUSB_VENDOR_ID), /* idVendor */ + HBYTE(USBD_WINUSB_VENDOR_ID), /* idVendor */ + LBYTE(USBD_WINUSB_PRODUCT_ID), /* idProduct */ + HBYTE(USBD_WINUSB_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 static uint8_t g_usbd_configuration[USBD_WINUSB_CONFIG_DESC_SIZE] ALIGNED_TAIL = +{ + USB_DEVICE_CFG_DESC_LEN, /* bLength: configuration descriptor size */ + USB_DESCIPTOR_TYPE_CONFIGURATION, /* bDescriptorType: configuration */ + LBYTE(USBD_WINUSB_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */ + HBYTE(USBD_WINUSB_CONFIG_DESC_SIZE), /* wTotalLength: bytes returned */ + 0x01, /* bNumInterfaces: 1 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 */ + 0x02, /* bNumEndpoints: number of endpoints */ + 0xff, /* bInterfaceClass: Vendor specific*/ + 0x00, /* bInterfaceSubClass: subclass code */ + 0x00, /* bInterfaceProtocol: protocol code */ + 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_WINUSB_BULK_OUT_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */ + USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */ + LBYTE(USBD_WINUSB_OUT_MAXPACKET_SIZE), + HBYTE(USBD_WINUSB_OUT_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_WINUSB_BULK_IN_EPT, /* bEndpointAddress: the address of endpoint on usb device described by this descriptor */ + USB_EPT_DESC_BULK, /* bmAttributes: endpoint attributes */ + LBYTE(USBD_WINUSB_IN_MAXPACKET_SIZE), + HBYTE(USBD_WINUSB_IN_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 static uint8_t g_string_lang_id[USBD_WINUSB_SIZ_STRING_LANGID] ALIGNED_TAIL = +{ + USBD_WINUSB_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 static uint8_t g_string_serial[USBD_WINUSB_SIZ_STRING_SERIAL] ALIGNED_TAIL = +{ + USBD_WINUSB_SIZ_STRING_SERIAL, + USB_DESCIPTOR_TYPE_STRING, +}; + + +/* device descriptor */ +static usbd_desc_t device_descriptor = +{ + USB_DEVICE_DESC_LEN, + g_usbd_descriptor +}; + +/* config descriptor */ +static usbd_desc_t config_descriptor = +{ + USBD_WINUSB_CONFIG_DESC_SIZE, + g_usbd_configuration +}; + +/* langid descriptor */ +static usbd_desc_t langid_descriptor = +{ + USBD_WINUSB_SIZ_STRING_LANGID, + g_string_lang_id +}; + +/* serial descriptor */ +static usbd_desc_t serial_descriptor = +{ + USBD_WINUSB_SIZ_STRING_SERIAL, + g_string_serial +}; + +static usbd_desc_t vp_desc; + +/** + * @brief standard usb unicode convert + * @param string: source string + * @param unicode_buf: unicode buffer + * @retval length + */ +static 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 + */ +static usbd_desc_t *get_device_descriptor(void) +{ + return &device_descriptor; +} + +/** + * @brief get device qualifier + * @param none + * @retval usbd_desc + */ +static usbd_desc_t * get_device_qualifier(void) +{ + return NULL; +} + +/** + * @brief get config descriptor + * @param none + * @retval usbd_desc + */ +static usbd_desc_t *get_device_configuration(void) +{ + return &config_descriptor; +} + + +/** + * @brief get other speed descriptor + * @param none + * @retval usbd_desc + */ +static usbd_desc_t *get_device_other_speed(void) +{ + return NULL; +} + +/** + * @brief get lang id descriptor + * @param none + * @retval usbd_desc + */ +static usbd_desc_t *get_device_lang_id(void) +{ + return &langid_descriptor; +} + + +/** + * @brief get manufacturer descriptor + * @param none + * @retval usbd_desc + */ +static usbd_desc_t *get_device_manufacturer_string(void) +{ + vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_WINUSB_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 + */ +static usbd_desc_t *get_device_product_string(void) +{ + vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_WINUSB_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 + */ +static usbd_desc_t *get_device_serial_string(void) +{ + get_serial_num(); + return &serial_descriptor; +} + +/** + * @brief get interface descriptor + * @param none + * @retval usbd_desc + */ +static usbd_desc_t *get_device_interface_string(void) +{ + vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_WINUSB_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 + */ +static usbd_desc_t *get_device_config_string(void) +{ + vp_desc.length = usbd_unicode_convert((uint8_t *)USBD_WINUSB_DESC_CONFIGURATION_STRING, g_usbd_desc_buffer); + vp_desc.descriptor = g_usbd_desc_buffer; + return &vp_desc; +} + +#if (USBD_SUPPORT_WINUSB == 1) + +#define USB_LEN_OS_FEATURE_DESC 0x28 +#define USB_LEN_OS_PROPERTY_DESC 0x8E + +/* os string descriptor fields */ +const uint8_t winusb_os_string[8] = { + 'M','S','F','T','1','0','0', + WINUSB_BMS_VENDOR_CODE, +}; + +#define U32TO8C(v) ((v & 0xFF), ((v >> 8) & 0xFF), ((v >> 16) & 0xFF), ((v >> 24) & 0xFF)) + +#if defined ( __ICCARM__ ) /* iar compiler */ + #pragma data_alignment=4 +#endif +ALIGNED_HEAD static uint8_t g_usbd_winusb_os_feature[USB_LEN_OS_FEATURE_DESC] ALIGNED_TAIL = +{ + USB_LEN_OS_FEATURE_DESC, 0x00, 0x00, 0x00, /*dwlength: 4 byte*/ + 0x00, 0x01, /* bcd version 1.0 */ + 0x04, 0x00, /* windex: extended compat ID descritor*/ + 0x01, /* bcount the number of custom property sections */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* reserved */ + /* function section */ + 0x00, /* first interface number */ + 0x00, /* reserved */ + 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, /* 8 byte: the function compatible id */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* 8 byte: the function subcompatible id */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* reserved 6 bytes */ +}; + +#if defined ( __ICCARM__ ) /* iar compiler */ + #pragma data_alignment=4 +#endif +ALIGNED_HEAD static uint8_t g_usbd_winusb_os_property[USB_LEN_OS_PROPERTY_DESC] ALIGNED_TAIL = +{ + USB_LEN_OS_PROPERTY_DESC, 0x00, 0x00, 0x00,/* dwlength: 4 byte*/ + 0x00, 0x01, /* bcd version 1.0 */ + 0x05, 0x00, /* property descriptor index(5) */ + 0x01, 0x00, /* wcount: number of section (1) */ + + /* custom property section */ + 0x84, 0x00, 0x00, 0x00, /* dwsize: size of property section */ + 0x01, 0x00, 0x00, 0x00, /* property data type */ + 0x28, 0x00, /* property name length */ + /* property name: DeviceinterfaceGUID */ + 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, + 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, 'r', 0x00, 'f', 0x00, + 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, + 'D', 0x00, 0x00, 0x00, + + 0x4E, 0x00, 0x00, 0x00, /* property data length */ + /*property data: {13eb360b-bc1e-46cb-ac8b-ef3da47b4062} */ + '{', 0x00, '1', 0x00, '3', 0x00, 'E', 0x00, 'B', 0x00, '3', 0x00, + '6', 0x00, '0', 0x00, 'B', 0x00, '-', 0x00, 'B', 0x00, 'C', 0x00, + '1', 0x00, 'E', 0x00, '-', 0x00, '4', 0x00, '6', 0x00, 'C', 0x00, + 'B', 0x00, '-', 0x00, 'A', 0x00, 'C', 0x00, '8', 0x00, 'B', 0x00, + '-', 0x00, 'E', 0x00, 'F', 0x00, '3', 0x00, 'D', 0x00, 'A', 0x00, + '4', 0x00, '7', 0x00, 'B', 0x00, '4', 0x00, '0', 0x00, '6', 0x00, + '2', 0x00, '}', 0x00, 0x00, 0x00 +}; + +static usbd_desc_t winusb_os_feature_descriptor = +{ + USB_LEN_OS_FEATURE_DESC, + g_usbd_winusb_os_feature +}; + +static usbd_desc_t winusb_os_property_descriptor = +{ + USB_LEN_OS_PROPERTY_DESC, + g_usbd_winusb_os_property +}; + +/** + * @brief get winusb os sring + * @param none + * @retval usbd_desc + */ +static usbd_desc_t *get_device_winusb_os_string(void) +{ + vp_desc.length = usbd_unicode_convert((uint8_t *)winusb_os_string, g_usbd_desc_buffer); + vp_desc.descriptor = g_usbd_desc_buffer; + return &vp_desc; +} + +/** + * @brief get winusb os feature + * @param none + * @retval usbd_desc + */ +static usbd_desc_t *get_device_winusb_os_feature(void) +{ + return &winusb_os_feature_descriptor; +} + +/** + * @brief get winusb os property + * @param none + * @retval usbd_desc + */ +static usbd_desc_t *get_device_winusb_os_property(void) +{ + return &winusb_os_property_descriptor; +} + + +#endif + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/middlewares/usbd_class/winusb/winusb_desc.h b/middlewares/usbd_class/winusb/winusb_desc.h new file mode 100644 index 00000000..39ad0e8c --- /dev/null +++ b/middlewares/usbd_class/winusb/winusb_desc.h @@ -0,0 +1,92 @@ +/** + ************************************************************************** + * @file winusb_desc.h + * @brief usb winusb 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 __WINUSB_DESC_H +#define __WINUSB_DESC_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "winusb_class.h" +#include "usbd_core.h" + +/** @addtogroup AT32F403A_407_middlewares_usbd_class + * @{ + */ + +/** @addtogroup USB_winusb_desc + * @{ + */ + +/** @defgroup USB_winusb_desc_definition + * @{ + */ +/** + * @brief usb vendor id and product id define + */ +#define USBD_WINUSB_VENDOR_ID 0x2E3C +#define USBD_WINUSB_PRODUCT_ID 0x5780 + +/** + * @brief usb descriptor size define + */ +#define USBD_WINUSB_CONFIG_DESC_SIZE 32 +#define USBD_WINUSB_SIZ_STRING_LANGID 4 +#define USBD_WINUSB_SIZ_STRING_SERIAL 0x1A + +/** + * @brief usb string define(vendor, product configuration, interface) + */ +#define USBD_WINUSB_DESC_MANUFACTURER_STRING "Artery" +#define USBD_WINUSB_DESC_PRODUCT_STRING "AT32 WinUSB" +#define USBD_WINUSB_DESC_CONFIGURATION_STRING "WinUSB Config" +#define USBD_WINUSB_DESC_INTERFACE_STRING "WinUSB Interface" + +/** + * @brief usb mcu id address deine + */ +#define MCU_ID1 (0x1FFFF7E8) +#define MCU_ID2 (0x1FFFF7EC) +#define MCU_ID3 (0x1FFFF7F0) +/** + * @} + */ + +extern usbd_desc_handler winusb_desc_handler; + + +/** + * @} + */ + +/** + * @} + */ +#ifdef __cplusplus +} +#endif + +#endif diff --git a/middlewares/usbd_drivers/inc/usb_std.h b/middlewares/usbd_drivers/inc/usb_std.h index dafb0d46..1d50f444 100644 --- a/middlewares/usbd_drivers/inc/usb_std.h +++ b/middlewares/usbd_drivers/inc/usb_std.h @@ -105,6 +105,7 @@ extern "C" { #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 */ +#define USB_WINUSB_OS_STRING 0xEE /*!< usb microsoft os string */ /** * @brief usb configuration attributes @@ -119,6 +120,12 @@ extern "C" { #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 winusb feature id + */ +#define USB_WINUSB_COMPAT_ID 0x04 /*!< usb winusb compat id os descriptor */ +#define USB_WINUSB_PROPERTIES_ID 0x05 /*!< usb winusb properties id os descriptor */ + /** * @brief usb device connect state */ diff --git a/middlewares/usbd_drivers/inc/usbd_core.h b/middlewares/usbd_drivers/inc/usbd_core.h index e1ea6b43..5fb66685 100644 --- a/middlewares/usbd_drivers/inc/usbd_core.h +++ b/middlewares/usbd_drivers/inc/usbd_core.h @@ -82,6 +82,11 @@ typedef struct 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 */ +#if (USBD_SUPPORT_WINUSB == 1) + usbd_desc_t *(*get_device_winusb_os_string)(void); /*!< get winusb os string */ + usbd_desc_t *(*get_device_winusb_os_feature)(void); /*!< get winusb os feature */ + usbd_desc_t *(*get_device_winusb_os_property)(void); /*!< get winusb os property */ +#endif }usbd_desc_handler; /** diff --git a/middlewares/usbd_drivers/src/usbd_sdr.c b/middlewares/usbd_drivers/src/usbd_sdr.c index b3ceacb9..3e9b7cd3 100644 --- a/middlewares/usbd_drivers/src/usbd_sdr.c +++ b/middlewares/usbd_drivers/src/usbd_sdr.c @@ -101,6 +101,20 @@ static usb_sts_type usbd_get_descriptor(usbd_core_type *udev) case USB_INTERFACE_STRING: desc = udev->desc_handler->get_device_interface_string(); break; + case USB_WINUSB_OS_STRING: +#if (USBD_SUPPORT_WINUSB == 1) + if(udev->desc_handler->get_device_winusb_os_string != NULL) + { + desc = udev->desc_handler->get_device_winusb_os_string(); + } + else + { + usbd_ctrl_unsupport(udev); + } +#else + usbd_ctrl_unsupport(udev); +#endif + break; default: udev->class_handler->setup_handler(udev, &udev->setup); return ret; @@ -243,6 +257,10 @@ static usb_sts_type usbd_set_feature(usbd_core_type *udev) udev->class_handler->setup_handler(udev, &udev->setup); usbd_ctrl_send_status(udev); } + else + { + usbd_ctrl_unsupport(udev); + } return ret; } diff --git a/project/at_start_f403a/examples/acc/calibration/src/main.c b/project/at_start_f403a/examples/acc/calibration/src/main.c index 3f7c2a57..74ce3e63 100644 --- a/project/at_start_f403a/examples/acc/calibration/src/main.c +++ b/project/at_start_f403a/examples/acc/calibration/src/main.c @@ -132,14 +132,14 @@ void USBFS_L_CAN1_RX0_IRQHandler(void) */ void ACC_IRQHandler(void) { - if(acc_flag_get(ACC_CALRDY_FLAG) != RESET) + if(acc_interrupt_flag_get(ACC_CALRDY_FLAG) != RESET) { at32_led_toggle(LED2); /* clear acc calibration ready flag */ acc_flag_clear(ACC_CALRDY_FLAG); } - if(acc_flag_get(ACC_RSLOST_FLAG) != RESET) + if(acc_interrupt_flag_get(ACC_RSLOST_FLAG) != RESET) { at32_led_toggle(LED3); diff --git a/project/at_start_f403a/examples/adc/combine_mode_ordinary_simult/mdk_v5/combine_mode_ordinary_simult.uvprojx b/project/at_start_f403a/examples/adc/combine_mode_ordinary_simult/mdk_v5/combine_mode_ordinary_simult.uvprojx index 58c8ff10..3234ea25 100644 --- a/project/at_start_f403a/examples/adc/combine_mode_ordinary_simult/mdk_v5/combine_mode_ordinary_simult.uvprojx +++ b/project/at_start_f403a/examples/adc/combine_mode_ordinary_simult/mdk_v5/combine_mode_ordinary_simult.uvprojx @@ -10,7 +10,7 @@ combine_mode_ordinary_simult 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f403a/examples/adc/combine_mode_ordinary_simult/src/at32f403a_407_int.c b/project/at_start_f403a/examples/adc/combine_mode_ordinary_simult/src/at32f403a_407_int.c index ba7452b9..5f41dd17 100644 --- a/project/at_start_f403a/examples/adc/combine_mode_ordinary_simult/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/adc/combine_mode_ordinary_simult/src/at32f403a_407_int.c @@ -141,7 +141,7 @@ void SysTick_Handler(void) */ void DMA1_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT1_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA1_FDT1_FLAG) != RESET) { dma_flag_clear(DMA1_FDT1_FLAG); dma1_trans_complete_flag = 1; diff --git a/project/at_start_f403a/examples/adc/current_vref_value_check/mdk_v5/current_vref_value_check.uvprojx b/project/at_start_f403a/examples/adc/current_vref_value_check/mdk_v5/current_vref_value_check.uvprojx index 0d4e7ac8..c837b6f8 100644 --- a/project/at_start_f403a/examples/adc/current_vref_value_check/mdk_v5/current_vref_value_check.uvprojx +++ b/project/at_start_f403a/examples/adc/current_vref_value_check/mdk_v5/current_vref_value_check.uvprojx @@ -10,7 +10,7 @@ current_vref_value_check 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f403a/examples/adc/exint_trigger_partitioned/mdk_v5/exint_trigger_partitioned.uvprojx b/project/at_start_f403a/examples/adc/exint_trigger_partitioned/mdk_v5/exint_trigger_partitioned.uvprojx index fa3ea7ca..b52215b8 100644 --- a/project/at_start_f403a/examples/adc/exint_trigger_partitioned/mdk_v5/exint_trigger_partitioned.uvprojx +++ b/project/at_start_f403a/examples/adc/exint_trigger_partitioned/mdk_v5/exint_trigger_partitioned.uvprojx @@ -10,7 +10,7 @@ exint_trigger_partitioned 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f403a/examples/adc/exint_trigger_partitioned/src/at32f403a_407_int.c b/project/at_start_f403a/examples/adc/exint_trigger_partitioned/src/at32f403a_407_int.c index de8169bf..1953388e 100644 --- a/project/at_start_f403a/examples/adc/exint_trigger_partitioned/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/adc/exint_trigger_partitioned/src/at32f403a_407_int.c @@ -142,7 +142,7 @@ void SysTick_Handler(void) */ void DMA1_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT1_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA1_FDT1_FLAG) != RESET) { dma_flag_clear(DMA1_FDT1_FLAG); dma_trans_complete_flag = 1; @@ -156,7 +156,7 @@ void DMA1_Channel1_IRQHandler(void) */ void ADC1_2_IRQHandler(void) { - if(adc_flag_get(ADC1, ADC_PCCE_FLAG) != RESET) + if(adc_interrupt_flag_get(ADC1, ADC_PCCE_FLAG) != RESET) { adc_flag_clear(ADC1, ADC_PCCE_FLAG); if(preempt_trigger_count < 3) diff --git a/project/at_start_f403a/examples/adc/internal_temperature_sensor/mdk_v5/internal_temperature_sensor.uvprojx b/project/at_start_f403a/examples/adc/internal_temperature_sensor/mdk_v5/internal_temperature_sensor.uvprojx index adf75ec2..18c97108 100644 --- a/project/at_start_f403a/examples/adc/internal_temperature_sensor/mdk_v5/internal_temperature_sensor.uvprojx +++ b/project/at_start_f403a/examples/adc/internal_temperature_sensor/mdk_v5/internal_temperature_sensor.uvprojx @@ -10,7 +10,7 @@ internal_temperature_sensor 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f403a/examples/adc/repeat_conversion_loop_transfer/src/at32f403a_407_int.c b/project/at_start_f403a/examples/adc/repeat_conversion_loop_transfer/src/at32f403a_407_int.c index 12919811..cb43edf3 100644 --- a/project/at_start_f403a/examples/adc/repeat_conversion_loop_transfer/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/adc/repeat_conversion_loop_transfer/src/at32f403a_407_int.c @@ -140,7 +140,7 @@ void SysTick_Handler(void) */ void DMA1_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT1_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA1_FDT1_FLAG) != RESET) { dma_flag_clear(DMA1_FDT1_FLAG); dma_trans_complete_flag++; diff --git a/project/at_start_f403a/examples/adc/software_trigger_repeat/src/at32f403a_407_int.c b/project/at_start_f403a/examples/adc/software_trigger_repeat/src/at32f403a_407_int.c index 85caae0a..8bbc6bcf 100644 --- a/project/at_start_f403a/examples/adc/software_trigger_repeat/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/adc/software_trigger_repeat/src/at32f403a_407_int.c @@ -140,7 +140,7 @@ void SysTick_Handler(void) */ void DMA1_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT1_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA1_FDT1_FLAG) != RESET) { dma_flag_clear(DMA1_FDT1_FLAG); dma_trans_complete_flag++; diff --git a/project/at_start_f403a/examples/adc/tmr_trigger_automatic_preempted/mdk_v5/tmr_trigger_automatic_preempted.uvprojx b/project/at_start_f403a/examples/adc/tmr_trigger_automatic_preempted/mdk_v5/tmr_trigger_automatic_preempted.uvprojx index 62f6051b..d42f855d 100644 --- a/project/at_start_f403a/examples/adc/tmr_trigger_automatic_preempted/mdk_v5/tmr_trigger_automatic_preempted.uvprojx +++ b/project/at_start_f403a/examples/adc/tmr_trigger_automatic_preempted/mdk_v5/tmr_trigger_automatic_preempted.uvprojx @@ -10,7 +10,7 @@ tmr_trigger_automatic_preempted 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f403a/examples/adc/tmr_trigger_automatic_preempted/src/at32f403a_407_int.c b/project/at_start_f403a/examples/adc/tmr_trigger_automatic_preempted/src/at32f403a_407_int.c index e1011850..0f4b1d97 100644 --- a/project/at_start_f403a/examples/adc/tmr_trigger_automatic_preempted/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/adc/tmr_trigger_automatic_preempted/src/at32f403a_407_int.c @@ -143,7 +143,7 @@ void SysTick_Handler(void) */ void DMA1_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT1_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA1_FDT1_FLAG) != RESET) { dma_flag_clear(DMA1_FDT1_FLAG); dma_trans_complete_flag = 1; @@ -157,7 +157,7 @@ void DMA1_Channel1_IRQHandler(void) */ void ADC1_2_IRQHandler(void) { - if(adc_flag_get(ADC1, ADC_PCCE_FLAG) != RESET) + if(adc_interrupt_flag_get(ADC1, ADC_PCCE_FLAG) != RESET) { adc_flag_clear(ADC1, ADC_PCCE_FLAG); if(preempt_conversion_count < 5) diff --git a/project/at_start_f403a/examples/adc/triple_adc_synchro_trigger/mdk_v5/triple_adc_synchro_trigger.uvprojx b/project/at_start_f403a/examples/adc/triple_adc_synchro_trigger/mdk_v5/triple_adc_synchro_trigger.uvprojx index e8df05c2..ee15645d 100644 --- a/project/at_start_f403a/examples/adc/triple_adc_synchro_trigger/mdk_v5/triple_adc_synchro_trigger.uvprojx +++ b/project/at_start_f403a/examples/adc/triple_adc_synchro_trigger/mdk_v5/triple_adc_synchro_trigger.uvprojx @@ -10,7 +10,7 @@ triple_adc_synchro_trigger 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f403a/examples/adc/triple_adc_synchro_trigger/src/at32f403a_407_int.c b/project/at_start_f403a/examples/adc/triple_adc_synchro_trigger/src/at32f403a_407_int.c index 1361563f..a81035d5 100644 --- a/project/at_start_f403a/examples/adc/triple_adc_synchro_trigger/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/adc/triple_adc_synchro_trigger/src/at32f403a_407_int.c @@ -143,7 +143,7 @@ void SysTick_Handler(void) */ void DMA1_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT1_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA1_FDT1_FLAG) != RESET) { dma_flag_clear(DMA1_FDT1_FLAG); dma1_trans_complete_flag = 1; @@ -157,7 +157,7 @@ void DMA1_Channel1_IRQHandler(void) */ void DMA2_Channel4_5_IRQHandler(void) { - if(dma_flag_get(DMA2_FDT5_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA2_FDT5_FLAG) != RESET) { dma_flag_clear(DMA2_FDT5_FLAG); dma2_trans_complete_flag = 1; diff --git a/project/at_start_f403a/examples/adc/voltage_monitoring/mdk_v5/voltage_monitoring.uvprojx b/project/at_start_f403a/examples/adc/voltage_monitoring/mdk_v5/voltage_monitoring.uvprojx index 69f632e1..4bd5801e 100644 --- a/project/at_start_f403a/examples/adc/voltage_monitoring/mdk_v5/voltage_monitoring.uvprojx +++ b/project/at_start_f403a/examples/adc/voltage_monitoring/mdk_v5/voltage_monitoring.uvprojx @@ -10,7 +10,7 @@ voltage_monitoring 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f403a/examples/adc/voltage_monitoring/src/at32f403a_407_int.c b/project/at_start_f403a/examples/adc/voltage_monitoring/src/at32f403a_407_int.c index 40d2bf24..c8fbbd0d 100644 --- a/project/at_start_f403a/examples/adc/voltage_monitoring/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/adc/voltage_monitoring/src/at32f403a_407_int.c @@ -142,7 +142,7 @@ void SysTick_Handler(void) */ void ADC1_2_IRQHandler(void) { - if(adc_flag_get(ADC1, ADC_VMOR_FLAG) != RESET) + if(adc_interrupt_flag_get(ADC1, ADC_VMOR_FLAG) != RESET) { at32_led_toggle(LED3); adc_flag_clear(ADC1, ADC_VMOR_FLAG); diff --git a/project/at_start_f403a/examples/bpr/tamper/src/at32f403a_407_int.c b/project/at_start_f403a/examples/bpr/tamper/src/at32f403a_407_int.c index 9e4cd902..3618c967 100644 --- a/project/at_start_f403a/examples/bpr/tamper/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/bpr/tamper/src/at32f403a_407_int.c @@ -140,7 +140,7 @@ void SysTick_Handler(void) */ void TAMPER_IRQHandler(void) { - if(bpr_flag_get(BPR_TAMPER_INTERRUPT_FLAG) != RESET) + if(bpr_interrupt_flag_get(BPR_TAMPER_INTERRUPT_FLAG) != RESET) { /* check if bpr registers are cleared */ if(bpr_reg_judge() == 0) diff --git a/project/at_start_f403a/examples/can/communication_mode/src/main.c b/project/at_start_f403a/examples/can/communication_mode/src/main.c index a1b6a59a..a0f0e621 100644 --- a/project/at_start_f403a/examples/can/communication_mode/src/main.c +++ b/project/at_start_f403a/examples/can/communication_mode/src/main.c @@ -108,7 +108,7 @@ static void can_configuration(void) nvic_irq_enable(CAN1_SE_IRQn, 0x00, 0x00); nvic_irq_enable(USBFS_L_CAN1_RX0_IRQn, 0x00, 0x00); can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE); - + /* error interrupt enable */ can_interrupt_enable(CAN1, CAN_ETRIEN_INT, TRUE); can_interrupt_enable(CAN1, CAN_EOIEN_INT, TRUE); @@ -148,7 +148,7 @@ static void can_transmit_data(void) void USBFS_L_CAN1_RX0_IRQHandler (void) { can_rx_message_type rx_message_struct; - if(can_flag_get(CAN1,CAN_RF0MN_FLAG) != RESET) + if(can_interrupt_flag_get(CAN1,CAN_RF0MN_FLAG) != RESET) { can_message_receive(CAN1, CAN_RX_FIFO0, &rx_message_struct); if(rx_message_struct.standard_id == 0x400) @@ -166,7 +166,7 @@ void USBFS_L_CAN1_RX0_IRQHandler (void) void CAN1_SE_IRQHandler(void) { __IO uint32_t err_index = 0; - if(can_flag_get(CAN1,CAN_ETR_FLAG) != RESET) + if(can_interrupt_flag_get(CAN1,CAN_ETR_FLAG) != RESET) { err_index = CAN1->ests & 0x70; can_flag_clear(CAN1, CAN_ETR_FLAG); diff --git a/project/at_start_f403a/examples/can/filter/src/main.c b/project/at_start_f403a/examples/can/filter/src/main.c index c268a74a..9236b6ca 100644 --- a/project/at_start_f403a/examples/can/filter/src/main.c +++ b/project/at_start_f403a/examples/can/filter/src/main.c @@ -133,7 +133,7 @@ static void can_configuration(void) nvic_irq_enable(CAN1_SE_IRQn, 0x00, 0x00); nvic_irq_enable(USBFS_L_CAN1_RX0_IRQn, 0x00, 0x00); can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE); - + /* error interrupt enable */ can_interrupt_enable(CAN1, CAN_ETRIEN_INT, TRUE); can_interrupt_enable(CAN1, CAN_EOIEN_INT, TRUE); @@ -260,7 +260,7 @@ static void can_transmit_data(void) void USBFS_L_CAN1_RX0_IRQHandler (void) { can_rx_message_type rx_message_struct; - if(can_flag_get(CAN1,CAN_RF0MN_FLAG) != RESET) + if(can_interrupt_flag_get(CAN1,CAN_RF0MN_FLAG) != RESET) { if(test_result == 4) { @@ -288,7 +288,7 @@ void USBFS_L_CAN1_RX0_IRQHandler (void) void CAN1_SE_IRQHandler(void) { __IO uint32_t err_index = 0; - if(can_flag_get(CAN1,CAN_ETR_FLAG) != RESET) + if(can_interrupt_flag_get(CAN1,CAN_ETR_FLAG) != RESET) { err_index = CAN1->ests & 0x70; can_flag_clear(CAN1, CAN_ETR_FLAG); diff --git a/project/at_start_f403a/examples/can/loopback_mode/src/main.c b/project/at_start_f403a/examples/can/loopback_mode/src/main.c index 4bf183b0..f706c627 100644 --- a/project/at_start_f403a/examples/can/loopback_mode/src/main.c +++ b/project/at_start_f403a/examples/can/loopback_mode/src/main.c @@ -108,7 +108,7 @@ static void can_configuration(void) nvic_irq_enable(CAN1_SE_IRQn, 0x00, 0x00); nvic_irq_enable(USBFS_L_CAN1_RX0_IRQn, 0x00, 0x00); can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE); - + /* error interrupt enable */ can_interrupt_enable(CAN1, CAN_ETRIEN_INT, TRUE); can_interrupt_enable(CAN1, CAN_EOIEN_INT, TRUE); @@ -148,7 +148,7 @@ static void can_transmit_data(void) void USBFS_L_CAN1_RX0_IRQHandler (void) { can_rx_message_type rx_message_struct; - if(can_flag_get(CAN1,CAN_RF0MN_FLAG) != RESET) + if(can_interrupt_flag_get(CAN1,CAN_RF0MN_FLAG) != RESET) { can_message_receive(CAN1, CAN_RX_FIFO0, &rx_message_struct); if(rx_message_struct.standard_id == 0x400) @@ -164,7 +164,7 @@ void USBFS_L_CAN1_RX0_IRQHandler (void) void CAN1_SE_IRQHandler(void) { __IO uint32_t err_index = 0; - if(can_flag_get(CAN1,CAN_ETR_FLAG) != RESET) + if(can_interrupt_flag_get(CAN1,CAN_ETR_FLAG) != RESET) { err_index = CAN1->ests & 0x70; can_flag_clear(CAN1, CAN_ETR_FLAG); diff --git a/project/at_start_f403a/examples/cortex_m4/systick_interrupt/src/main.c b/project/at_start_f403a/examples/cortex_m4/systick_interrupt/src/main.c index b17a0ff4..2cb20935 100644 --- a/project/at_start_f403a/examples/cortex_m4/systick_interrupt/src/main.c +++ b/project/at_start_f403a/examples/cortex_m4/systick_interrupt/src/main.c @@ -55,6 +55,26 @@ void systick_handler(void) } } +/** + * @brief config systick and enable interrupt. + * @param none + * @retval none + */ +static uint32_t systick_interrupt_config(uint32_t ticks) +{ + if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) + { + return (1UL); + } + + SysTick->LOAD = (uint32_t)(ticks - 1UL); + NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); + SysTick->VAL = 0UL; + SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk | + SysTick_CTRL_ENABLE_Msk; + return (0UL); +} + /** * @brief main function. * @param none @@ -68,7 +88,7 @@ int main(void) systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV); /* config systick reload value and enable interrupt */ - SysTick_Config(MS_TICK); + systick_interrupt_config(MS_TICK); /* configure led */ at32_led_init(LED2); diff --git a/project/at_start_f403a/examples/debug/tmr1/src/main.c b/project/at_start_f403a/examples/debug/tmr1/src/main.c index 631f5147..9a74033d 100644 --- a/project/at_start_f403a/examples/debug/tmr1/src/main.c +++ b/project/at_start_f403a/examples/debug/tmr1/src/main.c @@ -44,7 +44,7 @@ uint16_t counter = 0; */ void TMR1_OVF_TMR10_IRQHandler(void) { - if(tmr_flag_get(TMR1, TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR1, TMR_OVF_FLAG) != RESET) { /* add user code... */ at32_led_toggle(LED3); diff --git a/project/at_start_f403a/examples/dma/data_to_gpio_flexible/src/main.c b/project/at_start_f403a/examples/dma/data_to_gpio_flexible/src/main.c index 3b2696d9..1d333d3a 100644 --- a/project/at_start_f403a/examples/dma/data_to_gpio_flexible/src/main.c +++ b/project/at_start_f403a/examples/dma/data_to_gpio_flexible/src/main.c @@ -47,7 +47,7 @@ uint16_t src_buffer[BUFFER_SIZE] = {0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x00 */ void DMA2_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA2_FDT1_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA2_FDT1_FLAG) != RESET) { /* turn led2/led3/led4 on */ at32_led_on(LED2); diff --git a/project/at_start_f403a/examples/dma/flash_to_sram/src/main.c b/project/at_start_f403a/examples/dma/flash_to_sram/src/main.c index 10e61bd0..c05f5736 100644 --- a/project/at_start_f403a/examples/dma/flash_to_sram/src/main.c +++ b/project/at_start_f403a/examples/dma/flash_to_sram/src/main.c @@ -59,7 +59,7 @@ error_status buffer_compare(const uint32_t* pbuffer, uint32_t* pbuffer1, uint16_ */ void DMA1_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT1_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA1_FDT1_FLAG) != RESET) { data_counter_end = 0; dma_flag_clear(DMA1_FDT1_FLAG); @@ -157,4 +157,3 @@ int main(void) /** * @} */ - diff --git a/project/at_start_f403a/examples/exint/exint_config/src/main.c b/project/at_start_f403a/examples/exint/exint_config/src/main.c index 335e53d8..b57aefda 100644 --- a/project/at_start_f403a/examples/exint/exint_config/src/main.c +++ b/project/at_start_f403a/examples/exint/exint_config/src/main.c @@ -93,7 +93,7 @@ void exint_line0_config(void) */ void EXINT0_IRQHandler(void) { - if(exint_flag_get(EXINT_LINE_0) != RESET) + if(exint_interrupt_flag_get(EXINT_LINE_0) != RESET) { at32_led_toggle(LED2); at32_led_toggle(LED3); diff --git a/project/at_start_f403a/examples/exint/exint_software_trigger/src/main.c b/project/at_start_f403a/examples/exint/exint_software_trigger/src/main.c index b17d2c63..c2411930 100644 --- a/project/at_start_f403a/examples/exint/exint_software_trigger/src/main.c +++ b/project/at_start_f403a/examples/exint/exint_software_trigger/src/main.c @@ -88,7 +88,7 @@ static void tmr1_config(void) */ void TMR1_OVF_TMR10_IRQHandler(void) { - if(tmr_flag_get(TMR1,TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR1,TMR_OVF_FLAG) != RESET) { at32_led_toggle(LED2); exint_software_interrupt_event_generate(EXINT_LINE_4); @@ -103,7 +103,7 @@ void TMR1_OVF_TMR10_IRQHandler(void) */ void EXINT4_IRQHandler(void) { - if(exint_flag_get(EXINT_LINE_4) != RESET) + if(exint_interrupt_flag_get(EXINT_LINE_4) != RESET) { at32_led_toggle(LED3); at32_led_toggle(LED4); diff --git a/project/at_start_f403a/examples/i2s/halfduplex_interrupt/src/at32f403a_407_int.c b/project/at_start_f403a/examples/i2s/halfduplex_interrupt/src/at32f403a_407_int.c index c61076c3..c2c48a3c 100644 --- a/project/at_start_f403a/examples/i2s/halfduplex_interrupt/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/i2s/halfduplex_interrupt/src/at32f403a_407_int.c @@ -143,7 +143,7 @@ void SysTick_Handler(void) */ void SPI2_I2S2EXT_IRQHandler(void) { - if(spi_i2s_flag_get(SPI2, SPI_I2S_RDBF_FLAG) != RESET) + if(spi_i2s_interrupt_flag_get(SPI2, SPI_I2S_RDBF_FLAG) != RESET) { i2s2_buffer_rx[rx_index++] = spi_i2s_data_receive(SPI2); } @@ -156,7 +156,7 @@ void SysTick_Handler(void) */ void SPI3_I2S3EXT_IRQHandler(void) { - if(spi_i2s_flag_get(SPI3, SPI_I2S_TDBE_FLAG) != RESET) + if(spi_i2s_interrupt_flag_get(SPI3, SPI_I2S_TDBE_FLAG) != RESET) { spi_i2s_data_transmit(SPI3, i2s3_buffer_tx[tx_index++]); if(tx_index == 32) diff --git a/project/at_start_f403a/examples/pwc/deepsleep_rtc/src/at32f403a_407_int.c b/project/at_start_f403a/examples/pwc/deepsleep_rtc/src/at32f403a_407_int.c index 24a161eb..22a32f06 100644 --- a/project/at_start_f403a/examples/pwc/deepsleep_rtc/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/pwc/deepsleep_rtc/src/at32f403a_407_int.c @@ -140,7 +140,7 @@ void SysTick_Handler(void) */ void RTCAlarm_IRQHandler(void) { - if(rtc_flag_get(RTC_TA_FLAG) != RESET) + if(rtc_interrupt_flag_get(RTC_TA_FLAG) != RESET) { /* clear exint line flag */ exint_flag_clear(EXINT_LINE_17); diff --git a/project/at_start_f403a/examples/pwc/power_voltage_monitor/mdk_v5/power_voltage_monitor.uvprojx b/project/at_start_f403a/examples/pwc/power_voltage_monitor/mdk_v5/power_voltage_monitor.uvprojx index ae671c24..e7b690ad 100644 --- a/project/at_start_f403a/examples/pwc/power_voltage_monitor/mdk_v5/power_voltage_monitor.uvprojx +++ b/project/at_start_f403a/examples/pwc/power_voltage_monitor/mdk_v5/power_voltage_monitor.uvprojx @@ -10,7 +10,7 @@ power_voltage_monitor 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f403a/examples/pwc/power_voltage_monitor/src/at32f403a_407_int.c b/project/at_start_f403a/examples/pwc/power_voltage_monitor/src/at32f403a_407_int.c index 4637c4f4..c14ac27e 100644 --- a/project/at_start_f403a/examples/pwc/power_voltage_monitor/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/pwc/power_voltage_monitor/src/at32f403a_407_int.c @@ -140,7 +140,7 @@ void SysTick_Handler(void) */ void PVM_IRQHandler(void) { - if(exint_flag_get(EXINT_LINE_16) != RESET) + if(exint_interrupt_flag_get(EXINT_LINE_16) != RESET) { /* clear exint line flag */ exint_flag_clear(EXINT_LINE_16); diff --git a/project/at_start_f403a/examples/pwc/sleep_tmr2/mdk_v5/sleep_tmr2.uvprojx b/project/at_start_f403a/examples/pwc/sleep_tmr2/mdk_v5/sleep_tmr2.uvprojx index 4e50a870..51402335 100644 --- a/project/at_start_f403a/examples/pwc/sleep_tmr2/mdk_v5/sleep_tmr2.uvprojx +++ b/project/at_start_f403a/examples/pwc/sleep_tmr2/mdk_v5/sleep_tmr2.uvprojx @@ -10,7 +10,7 @@ sleep_tmr2 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f403a/examples/pwc/sleep_tmr2/src/at32f403a_407_int.c b/project/at_start_f403a/examples/pwc/sleep_tmr2/src/at32f403a_407_int.c index 8ff6c87e..50ef5036 100644 --- a/project/at_start_f403a/examples/pwc/sleep_tmr2/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/pwc/sleep_tmr2/src/at32f403a_407_int.c @@ -139,7 +139,7 @@ void SysTick_Handler(void) */ void TMR2_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR2, TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR2, TMR_OVF_FLAG) != RESET) { /* clear timer 2 ovf flag */ tmr_flag_clear(TMR2, TMR_OVF_FLAG); diff --git a/project/at_start_f403a/examples/pwc/sleep_usart1/mdk_v5/sleep_usart1.uvprojx b/project/at_start_f403a/examples/pwc/sleep_usart1/mdk_v5/sleep_usart1.uvprojx index 73dbc04a..4e0237a8 100644 --- a/project/at_start_f403a/examples/pwc/sleep_usart1/mdk_v5/sleep_usart1.uvprojx +++ b/project/at_start_f403a/examples/pwc/sleep_usart1/mdk_v5/sleep_usart1.uvprojx @@ -10,7 +10,7 @@ sleep_usart1 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f403a/examples/pwc/sleep_usart1/src/at32f403a_407_int.c b/project/at_start_f403a/examples/pwc/sleep_usart1/src/at32f403a_407_int.c index 52b23fd8..7feb8fec 100644 --- a/project/at_start_f403a/examples/pwc/sleep_usart1/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/pwc/sleep_usart1/src/at32f403a_407_int.c @@ -141,7 +141,7 @@ void SysTick_Handler(void) */ void USART1_IRQHandler(void) { - if(usart_flag_get(USART1, USART_RDBF_FLAG) != RESET) + if(usart_interrupt_flag_get(USART1, USART_RDBF_FLAG) != RESET) { /* clear rdbf flag */ usart1_index = usart_data_receive(USART1); diff --git a/project/at_start_f403a/examples/pwc/standby_rtc/mdk_v5/standby_rtc.uvprojx b/project/at_start_f403a/examples/pwc/standby_rtc/mdk_v5/standby_rtc.uvprojx index 78ca86d7..157cb97f 100644 --- a/project/at_start_f403a/examples/pwc/standby_rtc/mdk_v5/standby_rtc.uvprojx +++ b/project/at_start_f403a/examples/pwc/standby_rtc/mdk_v5/standby_rtc.uvprojx @@ -10,7 +10,7 @@ standby_rtc 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f403a/examples/rtc/calendar/src/at32f403a_407_int.c b/project/at_start_f403a/examples/rtc/calendar/src/at32f403a_407_int.c index 3628bbe0..ea4ddb98 100644 --- a/project/at_start_f403a/examples/rtc/calendar/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/rtc/calendar/src/at32f403a_407_int.c @@ -139,7 +139,7 @@ void SysTick_Handler(void) */ void RTC_IRQHandler(void) { - if(rtc_flag_get(RTC_TA_FLAG) != RESET) + if(rtc_interrupt_flag_get(RTC_TA_FLAG) != RESET) { at32_led_toggle(LED4); diff --git a/project/at_start_f403a/examples/rtc/lick_calibration/src/at32f403a_407_int.c b/project/at_start_f403a/examples/rtc/lick_calibration/src/at32f403a_407_int.c index 29215a02..3c08cc10 100644 --- a/project/at_start_f403a/examples/rtc/lick_calibration/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/rtc/lick_calibration/src/at32f403a_407_int.c @@ -148,7 +148,7 @@ void SysTick_Handler(void) */ void RTC_IRQHandler(void) { - if(rtc_flag_get(RTC_TS_FLAG) != RESET) + if(rtc_interrupt_flag_get(RTC_TS_FLAG) != RESET) { /* toggle led3 */ at32_led_toggle(LED3); @@ -169,11 +169,11 @@ void TMR5_GLOBAL_IRQHandler(void) { uint32_t tmp = 0; - if(tmr_flag_get(TMR5, TMR_C4_FLAG) == SET) + if(tmr_interrupt_flag_get(TMR5, TMR_C4_FLAG) == SET) { tmpCC4[incrementvar_operationcomplete()] = (uint16_t)(TMR5->c4dt); - tmr_flag_get(TMR5, TMR_C4_FLAG); + tmr_interrupt_flag_get(TMR5, TMR_C4_FLAG); if(getvar_operationcomplete() >= 2) { diff --git a/project/at_start_f403a/examples/sdio/sd_mmc_card/src/at32_sdio.c b/project/at_start_f403a/examples/sdio/sd_mmc_card/src/at32_sdio.c index dd4505d3..cbbd9ef5 100644 --- a/project/at_start_f403a/examples/sdio/sd_mmc_card/src/at32_sdio.c +++ b/project/at_start_f403a/examples/sdio/sd_mmc_card/src/at32_sdio.c @@ -99,11 +99,11 @@ sd_error_status_type sd_init(void) sdio_reset(SDIOx); /* power on */ status = sd_power_on(); - + if(status == SD_OK) break; } - + if(status == SD_OK) { /* sdio card initialize */ @@ -281,7 +281,7 @@ sd_error_status_type sd_power_on(void) while((!valid_voltage) && (count < SD_MAX_VOLT_TRIAL)) { delay_ms(10); - + /* send cmd55 before acmd41 */ sdio_command_init_struct.argument = 0x00; sdio_command_init_struct.cmd_index = SD_CMD_APP_CMD; @@ -348,7 +348,7 @@ sd_error_status_type sd_power_on(void) while((!valid_voltage) && (count < SD_MAX_VOLT_TRIAL)) { delay_ms(10); - + sdio_command_init_struct.argument = SD_VOLTAGE_WINDOW_MMC; sdio_command_init_struct.cmd_index = SD_CMD_SEND_OP_COND; sdio_command_init_struct.rsp_type = SDIO_RESPONSE_SHORT; @@ -1779,7 +1779,7 @@ void SDIO2_IRQHandler(void) */ sd_error_status_type sd_irq_service(void) { - if(sdio_flag_get(SDIOx, SDIO_DTCMPL_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_DTCMPL_FLAG) != RESET) { if(stop_flag == 1) { @@ -1804,7 +1804,7 @@ sd_error_status_type sd_irq_service(void) return transfer_error; } - if(sdio_flag_get(SDIOx, SDIO_DTFAIL_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_DTFAIL_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_DTFAIL_FLAG); @@ -1813,7 +1813,7 @@ sd_error_status_type sd_irq_service(void) return transfer_error; } - if(sdio_flag_get(SDIOx, SDIO_DTTIMEOUT_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_DTTIMEOUT_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_DTTIMEOUT_FLAG); @@ -1822,7 +1822,7 @@ sd_error_status_type sd_irq_service(void) return transfer_error; } - if(sdio_flag_get(SDIOx, SDIO_RXERRO_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_RXERRO_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_RXERRO_FLAG); @@ -1831,7 +1831,7 @@ sd_error_status_type sd_irq_service(void) return(SD_RX_OVERRUN); } - if(sdio_flag_get(SDIOx, SDIO_TXERRU_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_TXERRU_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_TXERRU_FLAG); @@ -1840,7 +1840,7 @@ sd_error_status_type sd_irq_service(void) return(SD_TX_UNDERRUN); } - if(sdio_flag_get(SDIOx, SDIO_SBITERR_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_SBITERR_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_SBITERR_FLAG); diff --git a/project/at_start_f403a/examples/sdio/sdio_fatfs/src/at32_sdio.c b/project/at_start_f403a/examples/sdio/sdio_fatfs/src/at32_sdio.c index 8172f2d0..d9cc51b9 100644 --- a/project/at_start_f403a/examples/sdio/sdio_fatfs/src/at32_sdio.c +++ b/project/at_start_f403a/examples/sdio/sdio_fatfs/src/at32_sdio.c @@ -100,11 +100,11 @@ sd_error_status_type sd_init(void) sdio_reset(SDIOx); /* power on */ status = sd_power_on(); - + if(status == SD_OK) break; } - + if(status == SD_OK) { /* sdio card initialize */ @@ -288,7 +288,7 @@ sd_error_status_type sd_power_on(void) while((!valid_voltage) && (count < SD_MAX_VOLT_TRIAL)) { delay_ms(10); - + /* send cmd55 before acmd41 */ sdio_command_init_struct.argument = 0x00; sdio_command_init_struct.cmd_index = SD_CMD_APP_CMD; @@ -355,7 +355,7 @@ sd_error_status_type sd_power_on(void) while((!valid_voltage) && (count < SD_MAX_VOLT_TRIAL)) { delay_ms(10); - + sdio_command_init_struct.argument = SD_VOLTAGE_WINDOW_MMC; sdio_command_init_struct.cmd_index = SD_CMD_SEND_OP_COND; sdio_command_init_struct.rsp_type = SDIO_RESPONSE_SHORT; @@ -1786,7 +1786,7 @@ void SDIO2_IRQHandler(void) */ sd_error_status_type sd_irq_service(void) { - if(sdio_flag_get(SDIOx, SDIO_DTCMPL_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_DTCMPL_FLAG) != RESET) { if(stop_flag == 1) { @@ -1811,7 +1811,7 @@ sd_error_status_type sd_irq_service(void) return transfer_error; } - if(sdio_flag_get(SDIOx, SDIO_DTFAIL_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_DTFAIL_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_DTFAIL_FLAG); @@ -1820,7 +1820,7 @@ sd_error_status_type sd_irq_service(void) return transfer_error; } - if(sdio_flag_get(SDIOx, SDIO_DTTIMEOUT_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_DTTIMEOUT_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_DTTIMEOUT_FLAG); @@ -1829,7 +1829,7 @@ sd_error_status_type sd_irq_service(void) return transfer_error; } - if(sdio_flag_get(SDIOx, SDIO_RXERRO_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_RXERRO_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_RXERRO_FLAG); @@ -1838,7 +1838,7 @@ sd_error_status_type sd_irq_service(void) return(SD_RX_OVERRUN); } - if(sdio_flag_get(SDIOx, SDIO_TXERRU_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_TXERRU_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_TXERRU_FLAG); @@ -1847,7 +1847,7 @@ sd_error_status_type sd_irq_service(void) return(SD_TX_UNDERRUN); } - if(sdio_flag_get(SDIOx, SDIO_SBITERR_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_SBITERR_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_SBITERR_FLAG); diff --git a/project/at_start_f403a/examples/spi/halfduplex_interrupt/src/at32f403a_407_int.c b/project/at_start_f403a/examples/spi/halfduplex_interrupt/src/at32f403a_407_int.c index dd1f1afa..96b85c19 100644 --- a/project/at_start_f403a/examples/spi/halfduplex_interrupt/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/spi/halfduplex_interrupt/src/at32f403a_407_int.c @@ -145,7 +145,7 @@ void SysTick_Handler(void) */ void SPI1_IRQHandler(void) { - if(spi_i2s_flag_get(SPI1, SPI_I2S_TDBE_FLAG) != RESET) + if(spi_i2s_interrupt_flag_get(SPI1, SPI_I2S_TDBE_FLAG) != RESET) { spi_i2s_data_transmit(SPI1, spi1_tx_buffer[tx_index++]); if(tx_index == BUFFERSIZE) @@ -162,7 +162,7 @@ void SysTick_Handler(void) */ void SPI2_I2S2EXT_IRQHandler(void) { - if(spi_i2s_flag_get(SPI2, SPI_I2S_RDBF_FLAG) != RESET) + if(spi_i2s_interrupt_flag_get(SPI2, SPI_I2S_RDBF_FLAG) != RESET) { spi2_rx_buffer[rx_index++] = spi_i2s_data_receive(SPI2); } diff --git a/project/at_start_f403a/examples/spi/halfduplex_transceiver_switch/mdk_v5/halfduplex_transceiver_switch.uvprojx b/project/at_start_f403a/examples/spi/halfduplex_transceiver_switch/mdk_v5/halfduplex_transceiver_switch.uvprojx index 1c64f3a7..5a09f445 100644 --- a/project/at_start_f403a/examples/spi/halfduplex_transceiver_switch/mdk_v5/halfduplex_transceiver_switch.uvprojx +++ b/project/at_start_f403a/examples/spi/halfduplex_transceiver_switch/mdk_v5/halfduplex_transceiver_switch.uvprojx @@ -10,7 +10,7 @@ halfduplex_transceiver_switch 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f403a/examples/spi/halfduplex_transceiver_switch/src/at32f403a_407_int.c b/project/at_start_f403a/examples/spi/halfduplex_transceiver_switch/src/at32f403a_407_int.c index 5623e006..0a759f31 100644 --- a/project/at_start_f403a/examples/spi/halfduplex_transceiver_switch/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/spi/halfduplex_transceiver_switch/src/at32f403a_407_int.c @@ -147,28 +147,22 @@ void SysTick_Handler(void) */ void SPI1_IRQHandler(void) { - if(SPI1->ctrl2_bit.tdbeie != RESET) + if(spi_i2s_interrupt_flag_get(SPI1, SPI_I2S_TDBE_FLAG) != RESET) { - if(spi_i2s_flag_get(SPI1, SPI_I2S_TDBE_FLAG) != RESET) + spi_i2s_data_transmit(SPI1, spi1_tx_buffer[tx_index++]); + if(tx_index == BUFFERSIZE) { - spi_i2s_data_transmit(SPI1, spi1_tx_buffer[tx_index++]); - if(tx_index == BUFFERSIZE) - { - spi_i2s_interrupt_enable(SPI1, SPI_I2S_TDBE_INT, FALSE); - } + spi_i2s_interrupt_enable(SPI1, SPI_I2S_TDBE_INT, FALSE); } } - if(SPI1->ctrl2_bit.rdbfie != RESET) + if(spi_i2s_interrupt_flag_get(SPI1, SPI_I2S_RDBF_FLAG) != RESET) { - if(spi_i2s_flag_get(SPI1, SPI_I2S_RDBF_FLAG) != RESET) + spi_enable(SPI1, FALSE); + spi1_rx_buffer[rx_index++] = spi_i2s_data_receive(SPI1); + spi_enable(SPI1, TRUE); + if(rx_index == BUFFERSIZE) { - spi_enable(SPI1, FALSE); - spi1_rx_buffer[rx_index++] = spi_i2s_data_receive(SPI1); - spi_enable(SPI1, TRUE); - if(rx_index == BUFFERSIZE) - { - spi_i2s_interrupt_enable(SPI1, SPI_I2S_RDBF_INT, FALSE); - } + spi_i2s_interrupt_enable(SPI1, SPI_I2S_RDBF_INT, FALSE); } } } @@ -180,23 +174,17 @@ void SysTick_Handler(void) */ void SPI2_I2S2EXT_IRQHandler(void) { - if(SPI2->ctrl2_bit.tdbeie != RESET) + if(spi_i2s_interrupt_flag_get(SPI2, SPI_I2S_TDBE_FLAG) != RESET) { - if(spi_i2s_flag_get(SPI2, SPI_I2S_TDBE_FLAG) != RESET) + spi_i2s_data_transmit(SPI2, spi2_tx_buffer[tx_index++]); + if(tx_index == BUFFERSIZE) { - spi_i2s_data_transmit(SPI2, spi2_tx_buffer[tx_index++]); - if(tx_index == BUFFERSIZE) - { - spi_i2s_interrupt_enable(SPI2, SPI_I2S_TDBE_INT, FALSE); - } + spi_i2s_interrupt_enable(SPI2, SPI_I2S_TDBE_INT, FALSE); } } - if(SPI2->ctrl2_bit.rdbfie != RESET) + if(spi_i2s_interrupt_flag_get(SPI2, SPI_I2S_RDBF_FLAG) != RESET) { - if(spi_i2s_flag_get(SPI2, SPI_I2S_RDBF_FLAG) != RESET) - { - spi2_rx_buffer[rx_index++] = spi_i2s_data_receive(SPI2); - } + spi2_rx_buffer[rx_index++] = spi_i2s_data_receive(SPI2); } } diff --git a/project/at_start_f403a/examples/tmr/dma/src/main.c b/project/at_start_f403a/examples/tmr/dma/src/main.c index b6e8d3f4..32faad1f 100644 --- a/project/at_start_f403a/examples/tmr/dma/src/main.c +++ b/project/at_start_f403a/examples/tmr/dma/src/main.c @@ -130,7 +130,7 @@ int main(void) dma_init_struct.memory_base_addr = (uint32_t)src_buffer; dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_HALFWORD; dma_init_struct.memory_inc_enable = TRUE; - dma_init_struct.peripheral_base_addr = (uint32_t)0x40012C3C; + dma_init_struct.peripheral_base_addr = (uint32_t)&TMR1->c3dt; dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_HALFWORD; dma_init_struct.peripheral_inc_enable = FALSE; dma_init_struct.priority = DMA_PRIORITY_MEDIUM; diff --git a/project/at_start_f403a/examples/tmr/dma_burst/src/main.c b/project/at_start_f403a/examples/tmr/dma_burst/src/main.c index b771399f..883014d4 100644 --- a/project/at_start_f403a/examples/tmr/dma_burst/src/main.c +++ b/project/at_start_f403a/examples/tmr/dma_burst/src/main.c @@ -111,7 +111,7 @@ int main(void) dma_init_struct.memory_base_addr = (uint32_t)src_buffer; dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_HALFWORD; dma_init_struct.memory_inc_enable = TRUE; - dma_init_struct.peripheral_base_addr = (uint32_t)0x40012C4C; + dma_init_struct.peripheral_base_addr = (uint32_t)&TMR1->dmadt; dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_HALFWORD; dma_init_struct.peripheral_inc_enable = FALSE; dma_init_struct.priority = DMA_PRIORITY_MEDIUM; diff --git a/project/at_start_f403a/examples/tmr/hall_xor_tmr2/src/main.c b/project/at_start_f403a/examples/tmr/hall_xor_tmr2/src/main.c index b6330a16..031d081f 100644 --- a/project/at_start_f403a/examples/tmr/hall_xor_tmr2/src/main.c +++ b/project/at_start_f403a/examples/tmr/hall_xor_tmr2/src/main.c @@ -136,7 +136,7 @@ int main(void) */ void TMR2_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR2, TMR_TRIGGER_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR2, TMR_TRIGGER_FLAG) != RESET) { GPIOA->odt ^= GPIO_PINS_8; tmr_flag_clear(TMR2, TMR_TRIGGER_FLAG); diff --git a/project/at_start_f403a/examples/tmr/input_capture/src/main.c b/project/at_start_f403a/examples/tmr/input_capture/src/main.c index c70f09ba..c42c7d74 100644 --- a/project/at_start_f403a/examples/tmr/input_capture/src/main.c +++ b/project/at_start_f403a/examples/tmr/input_capture/src/main.c @@ -63,7 +63,7 @@ void delay(uint32_t time) */ void TMR3_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR3, TMR_C2_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR3, TMR_C2_FLAG) != RESET) { tmr_flag_clear(TMR3, TMR_C2_FLAG); if(capturenumber == 0) @@ -84,7 +84,7 @@ void TMR3_GLOBAL_IRQHandler(void) } else { - capture = ((0xFFFF - ic3readvalue1) + ic3readvalue2); + capture = ((0x10000 - ic3readvalue1) + ic3readvalue2); } /* frequency computation */ diff --git a/project/at_start_f403a/examples/tmr/oc_high/src/at32f403a_407_int.c b/project/at_start_f403a/examples/tmr/oc_high/src/at32f403a_407_int.c index 7501cbdc..41dbd3a9 100644 --- a/project/at_start_f403a/examples/tmr/oc_high/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/tmr/oc_high/src/at32f403a_407_int.c @@ -137,7 +137,7 @@ void SysTick_Handler(void) */ void TMR2_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR2, TMR_C1_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR2, TMR_C1_FLAG) != RESET) { /* clear tmr2 channel1 interrupt pending bit */ tmr_flag_clear(TMR2, TMR_C1_FLAG); @@ -145,7 +145,7 @@ void TMR2_GLOBAL_IRQHandler(void) /* pc.06 turnoff after 1000 ms */ gpio_bits_reset(GPIOC, GPIO_PINS_6); } - else if(tmr_flag_get(TMR2, TMR_C2_FLAG) != RESET) + else if(tmr_interrupt_flag_get(TMR2, TMR_C2_FLAG) != RESET) { /* clear tmr2 channel2 interrupt pending bit */ tmr_flag_clear(TMR2, TMR_C2_FLAG); @@ -153,7 +153,7 @@ void TMR2_GLOBAL_IRQHandler(void) /* pc.07 turnoff after 500 ms */ gpio_bits_reset(GPIOC, GPIO_PINS_7); } - else if(tmr_flag_get(TMR2, TMR_C3_FLAG) != RESET) + else if(tmr_interrupt_flag_get(TMR2, TMR_C3_FLAG) != RESET) { /* clear tmr2 channel3 interrupt pending bit */ tmr_flag_clear(TMR2, TMR_C3_FLAG); diff --git a/project/at_start_f403a/examples/tmr/oc_low/src/at32f403a_407_int.c b/project/at_start_f403a/examples/tmr/oc_low/src/at32f403a_407_int.c index 576502d2..67296e39 100644 --- a/project/at_start_f403a/examples/tmr/oc_low/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/tmr/oc_low/src/at32f403a_407_int.c @@ -137,7 +137,7 @@ void SysTick_Handler(void) */ void TMR2_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR2, TMR_C1_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR2, TMR_C1_FLAG) != RESET) { /* clear tmr2 channel1 interrupt pending bit */ tmr_flag_clear(TMR2, TMR_C1_FLAG); @@ -145,7 +145,7 @@ void TMR2_GLOBAL_IRQHandler(void) /* pc.06 turnoff after 1000 ms */ gpio_bits_reset(GPIOC, GPIO_PINS_6); } - else if(tmr_flag_get(TMR2, TMR_C2_FLAG) != RESET) + else if(tmr_interrupt_flag_get(TMR2, TMR_C2_FLAG) != RESET) { /* clear tmr2 channel2 interrupt pending bit */ tmr_flag_clear(TMR2, TMR_C2_FLAG); @@ -153,7 +153,7 @@ void TMR2_GLOBAL_IRQHandler(void) /* pc.07 turnoff after 500 ms */ gpio_bits_reset(GPIOC, GPIO_PINS_7); } - else if(tmr_flag_get(TMR2, TMR_C3_FLAG) != RESET) + else if(tmr_interrupt_flag_get(TMR2, TMR_C3_FLAG) != RESET) { /* clear tmr2 channel3 interrupt pending bit */ tmr_flag_clear(TMR2, TMR_C3_FLAG); diff --git a/project/at_start_f403a/examples/tmr/oc_toggle_tmr3/src/at32f403a_407_int.c b/project/at_start_f403a/examples/tmr/oc_toggle_tmr3/src/at32f403a_407_int.c index 06296cef..f59db46a 100644 --- a/project/at_start_f403a/examples/tmr/oc_toggle_tmr3/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/tmr/oc_toggle_tmr3/src/at32f403a_407_int.c @@ -145,7 +145,7 @@ void SysTick_Handler(void) void TMR3_GLOBAL_IRQHandler(void) { /* TMR3_CH1 toggling with frequency = 183.1 Hz */ - if(tmr_flag_get(TMR3, TMR_C1_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR3, TMR_C1_FLAG) != RESET) { tmr_flag_clear(TMR3, TMR_C1_FLAG ); capture = tmr_channel_value_get(TMR3, TMR_SELECT_CHANNEL_1); @@ -153,7 +153,7 @@ void TMR3_GLOBAL_IRQHandler(void) } /* TMR3_CH2 toggling with frequency = 366.2 Hz */ - if(tmr_flag_get(TMR3, TMR_C2_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR3, TMR_C2_FLAG) != RESET) { tmr_flag_clear(TMR3, TMR_C2_FLAG); capture = tmr_channel_value_get(TMR3, TMR_SELECT_CHANNEL_2); @@ -161,7 +161,7 @@ void TMR3_GLOBAL_IRQHandler(void) } /* TMR3_CH3 toggling with frequency = 732.4 Hz */ - if(tmr_flag_get(TMR3, TMR_C3_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR3, TMR_C3_FLAG) != RESET) { tmr_flag_clear(TMR3, TMR_C3_FLAG); capture = tmr_channel_value_get(TMR3, TMR_SELECT_CHANNEL_3); @@ -169,7 +169,7 @@ void TMR3_GLOBAL_IRQHandler(void) } /* TMR3_CH4 toggling with frequency = 1464.8 Hz */ - if(tmr_flag_get(TMR3, TMR_C4_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR3, TMR_C4_FLAG) != RESET) { tmr_flag_clear(TMR3, TMR_C4_FLAG); capture = tmr_channel_value_get(TMR3, TMR_SELECT_CHANNEL_4); diff --git a/project/at_start_f403a/examples/tmr/oc_toggle_tmr9/src/at32f403a_407_int.c b/project/at_start_f403a/examples/tmr/oc_toggle_tmr9/src/at32f403a_407_int.c index cd6b5cdf..1f305a15 100644 --- a/project/at_start_f403a/examples/tmr/oc_toggle_tmr9/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/tmr/oc_toggle_tmr9/src/at32f403a_407_int.c @@ -143,7 +143,7 @@ void SysTick_Handler(void) void TMR1_BRK_TMR9_IRQHandler(void) { /* TMR9_CH1 toggling with frequency = 366.2 Hz */ - if(tmr_flag_get(TMR9, TMR_C1_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR9, TMR_C1_FLAG) != RESET) { tmr_flag_clear(TMR9, TMR_C1_FLAG ); capture = tmr_channel_value_get(TMR9, TMR_SELECT_CHANNEL_1); @@ -151,7 +151,7 @@ void TMR1_BRK_TMR9_IRQHandler(void) } /* TMR9_CH2 toggling with frequency = 732.4 Hz */ - if(tmr_flag_get(TMR9, TMR_C2_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR9, TMR_C2_FLAG) != RESET) { tmr_flag_clear(TMR9, TMR_C2_FLAG); capture = tmr_channel_value_get(TMR9, TMR_SELECT_CHANNEL_2); diff --git a/project/at_start_f403a/examples/tmr/pwm_input_dma/src/main.c b/project/at_start_f403a/examples/tmr/pwm_input_dma/src/main.c index f686a34b..af7e570c 100644 --- a/project/at_start_f403a/examples/tmr/pwm_input_dma/src/main.c +++ b/project/at_start_f403a/examples/tmr/pwm_input_dma/src/main.c @@ -33,9 +33,6 @@ * @{ */ -#define TMR1_C1DT_ADDRESS 0x40012C34 -#define TMR1_C2DT_ADDRESS 0x40012C38 - #define SAMPLING_NUM 1000 tmr_input_config_type tmr_ic_init_structure; @@ -131,7 +128,7 @@ int main(void) dma_reset(DMA1_CHANNEL2); dma_default_para_init(&dma_init_structure); - dma_init_structure.peripheral_base_addr = (uint32_t)TMR1_C1DT_ADDRESS; + dma_init_structure.peripheral_base_addr = (uint32_t)&TMR1->c1dt; dma_init_structure.memory_base_addr = (uint32_t)buffer_cc1; dma_init_structure.direction = DMA_DIR_PERIPHERAL_TO_MEMORY; dma_init_structure.buffer_size = SAMPLING_NUM; @@ -144,7 +141,7 @@ int main(void) dma_init(DMA1_CHANNEL2, &dma_init_structure); dma_reset(DMA1_CHANNEL3); - dma_init_structure.peripheral_base_addr = (uint32_t)TMR1_C2DT_ADDRESS; + dma_init_structure.peripheral_base_addr = (uint32_t)&TMR1->c2dt; dma_init_structure.memory_base_addr = (uint32_t)buffer_cc2; dma_init(DMA1_CHANNEL3, &dma_init_structure); diff --git a/project/at_start_f403a/examples/tmr/pwm_output_simulate/src/at32f403a_407_int.c b/project/at_start_f403a/examples/tmr/pwm_output_simulate/src/at32f403a_407_int.c index c37476bd..ebf8b57b 100644 --- a/project/at_start_f403a/examples/tmr/pwm_output_simulate/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/tmr/pwm_output_simulate/src/at32f403a_407_int.c @@ -139,7 +139,7 @@ void SysTick_Handler(void) void TMR2_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR2, TMR_C1_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR2, TMR_C1_FLAG) != RESET) { tmr_flag_clear(TMR2, TMR_C1_FLAG ); @@ -148,7 +148,7 @@ void TMR2_GLOBAL_IRQHandler(void) capture = tmr_channel_value_get(TMR2, TMR_SELECT_CHANNEL_1); tmr_channel_value_set(TMR2, TMR_SELECT_CHANNEL_1, capture + ccr1_val); } - else if(tmr_flag_get(TMR2, TMR_C2_FLAG) != RESET) + else if(tmr_interrupt_flag_get(TMR2, TMR_C2_FLAG) != RESET) { tmr_flag_clear(TMR2, TMR_C2_FLAG); @@ -157,7 +157,7 @@ void TMR2_GLOBAL_IRQHandler(void) capture = tmr_channel_value_get(TMR2, TMR_SELECT_CHANNEL_2); tmr_channel_value_set(TMR2, TMR_SELECT_CHANNEL_2, capture + ccr2_val); } - else if(tmr_flag_get(TMR2, TMR_C3_FLAG) != RESET) + else if(tmr_interrupt_flag_get(TMR2, TMR_C3_FLAG) != RESET) { tmr_flag_clear(TMR2, TMR_C3_FLAG); diff --git a/project/at_start_f403a/examples/tmr/timer_base/src/main.c b/project/at_start_f403a/examples/tmr/timer_base/src/main.c index 42f0d62a..5a9f4c80 100644 --- a/project/at_start_f403a/examples/tmr/timer_base/src/main.c +++ b/project/at_start_f403a/examples/tmr/timer_base/src/main.c @@ -67,7 +67,7 @@ void clkout_config(void) */ void TMR1_OVF_TMR10_IRQHandler(void) { - if(tmr_flag_get(TMR1, TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR1, TMR_OVF_FLAG) != RESET) { /* add user code... */ at32_led_toggle(LED3); diff --git a/project/at_start_f403a/examples/usart/idle_detection/src/at32f403a_407_int.c b/project/at_start_f403a/examples/usart/idle_detection/src/at32f403a_407_int.c index 6cbc99ca..00444396 100644 --- a/project/at_start_f403a/examples/usart/idle_detection/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/usart/idle_detection/src/at32f403a_407_int.c @@ -138,7 +138,7 @@ void SysTick_Handler(void) */ void USART2_IRQHandler(void) { - if(usart_flag_get(USART2, USART_IDLEF_FLAG)) + if(usart_interrupt_flag_get(USART2, USART_IDLEF_FLAG)) { usart_data_receive(USART2); at32_led_on(LED2); diff --git a/project/at_start_f403a/examples/usart/interrupt/src/at32f403a_407_int.c b/project/at_start_f403a/examples/usart/interrupt/src/at32f403a_407_int.c index a9544a45..8083f3da 100644 --- a/project/at_start_f403a/examples/usart/interrupt/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/usart/interrupt/src/at32f403a_407_int.c @@ -148,33 +148,27 @@ void SysTick_Handler(void) */ void USART2_IRQHandler(void) { - if(USART2->ctrl1_bit.rdbfien != RESET) + if(usart_interrupt_flag_get(USART2, USART_RDBF_FLAG) != RESET) { - if(usart_flag_get(USART2, USART_RDBF_FLAG) != RESET) - { - /* read one byte from the receive data register */ - usart2_rx_buffer[usart2_rx_counter++] = usart_data_receive(USART2); + /* read one byte from the receive data register */ + usart2_rx_buffer[usart2_rx_counter++] = usart_data_receive(USART2); - if(usart2_rx_counter == usart3_tx_buffer_size) - { - /* disable the usart2 receive interrupt */ - usart_interrupt_enable(USART2, USART_RDBF_INT, FALSE); - } + if(usart2_rx_counter == usart3_tx_buffer_size) + { + /* disable the usart2 receive interrupt */ + usart_interrupt_enable(USART2, USART_RDBF_INT, FALSE); } } - - if(USART2->ctrl1_bit.tdbeien != RESET) - { - if(usart_flag_get(USART2, USART_TDBE_FLAG) != RESET) - { - /* write one byte to the transmit data register */ - usart_data_transmit(USART2, usart2_tx_buffer[usart2_tx_counter++]); - if(usart2_tx_counter == usart2_tx_buffer_size) - { - /* disable the usart2 transmit interrupt */ - usart_interrupt_enable(USART2, USART_TDBE_INT, FALSE); - } + if(usart_interrupt_flag_get(USART2, USART_TDBE_FLAG) != RESET) + { + /* write one byte to the transmit data register */ + usart_data_transmit(USART2, usart2_tx_buffer[usart2_tx_counter++]); + + if(usart2_tx_counter == usart2_tx_buffer_size) + { + /* disable the usart2 transmit interrupt */ + usart_interrupt_enable(USART2, USART_TDBE_INT, FALSE); } } } @@ -186,33 +180,27 @@ void USART2_IRQHandler(void) */ void USART3_IRQHandler(void) { - if(USART3->ctrl1_bit.rdbfien != RESET) + if(usart_interrupt_flag_get(USART3, USART_RDBF_FLAG) != RESET) { - if(usart_flag_get(USART3, USART_RDBF_FLAG) != RESET) - { - /* read one byte from the receive data register */ - usart3_rx_buffer[usart3_rx_counter++] = usart_data_receive(USART3); + /* read one byte from the receive data register */ + usart3_rx_buffer[usart3_rx_counter++] = usart_data_receive(USART3); - if(usart3_rx_counter == usart2_tx_buffer_size) - { - /* disable the usart3 receive interrupt */ - usart_interrupt_enable(USART3, USART_RDBF_INT, FALSE); - } + if(usart3_rx_counter == usart2_tx_buffer_size) + { + /* disable the usart3 receive interrupt */ + usart_interrupt_enable(USART3, USART_RDBF_INT, FALSE); } } - - if(USART3->ctrl1_bit.tdbeien != RESET) - { - if(usart_flag_get(USART3, USART_TDBE_FLAG) != RESET) - { - /* write one byte to the transmit data register */ - usart_data_transmit(USART3, usart3_tx_buffer[usart3_tx_counter++]); - if(usart3_tx_counter == usart3_tx_buffer_size) - { - /* disable the usart3 transmit interrupt */ - usart_interrupt_enable(USART3, USART_TDBE_INT, FALSE); - } + if(usart_interrupt_flag_get(USART3, USART_TDBE_FLAG) != RESET) + { + /* write one byte to the transmit data register */ + usart_data_transmit(USART3, usart3_tx_buffer[usart3_tx_counter++]); + + if(usart3_tx_counter == usart3_tx_buffer_size) + { + /* disable the usart3 transmit interrupt */ + usart_interrupt_enable(USART3, USART_TDBE_INT, FALSE); } } } diff --git a/project/at_start_f403a/examples/usart/receiver_mute/src/at32f403a_407_int.c b/project/at_start_f403a/examples/usart/receiver_mute/src/at32f403a_407_int.c index 0d46104e..57474f7c 100644 --- a/project/at_start_f403a/examples/usart/receiver_mute/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/usart/receiver_mute/src/at32f403a_407_int.c @@ -140,7 +140,7 @@ void SysTick_Handler(void) */ void USART3_IRQHandler(void) { - if(usart_flag_get(USART3, USART_RDBF_FLAG) != RESET) + if(usart_interrupt_flag_get(USART3, USART_RDBF_FLAG) != RESET) { usart3_rx_buffer[rx_counter++] = usart_data_receive(USART3); } diff --git a/project/at_start_f403a/examples/usart/rs485/src/main.c b/project/at_start_f403a/examples/usart/rs485/src/main.c index 07946c3b..4acdc126 100644 --- a/project/at_start_f403a/examples/usart/rs485/src/main.c +++ b/project/at_start_f403a/examples/usart/rs485/src/main.c @@ -5,11 +5,11 @@ ************************************************************************** * 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 + * 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, @@ -37,7 +37,7 @@ #define RS485_BUFFER_SIZE 128 uint8_t rs485_buffer_rx[RS485_BUFFER_SIZE]; -uint8_t rs485_buffer_rx_cnt = 0; +uint8_t rs485_buffer_rx_cnt = 0; /** * @brief rs485 configiguration. @@ -61,29 +61,29 @@ static void rs485_config(void) gpio_init_struct.gpio_pins = GPIO_PINS_2; gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init(GPIOA, &gpio_init_struct); - + gpio_init_struct.gpio_pins = GPIO_PINS_3; gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; gpio_init_struct.gpio_pull = GPIO_PULL_UP; gpio_init(GPIOA, &gpio_init_struct); - + gpio_init_struct.gpio_pins = GPIO_PINS_1; gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init(GPIOA, &gpio_init_struct); - + gpio_bits_reset(GPIOA, GPIO_PINS_1); - + /* configure uart2 param */ usart_init(USART2, RS485_BAUDRATE, USART_DATA_8BITS, USART_STOP_1_BIT); - + usart_flag_clear(USART2, USART_RDBF_FLAG); usart_interrupt_enable(USART2, USART_RDBF_INT, TRUE); - + usart_receiver_enable(USART2, TRUE); usart_transmitter_enable(USART2, TRUE); usart_enable(USART2, TRUE); - + nvic_irq_enable(USART2_IRQn, 1, 0); } @@ -113,13 +113,13 @@ int main(void) { char str[]="start test..\r\n"; u8 len = 0; - + system_clock_config(); at32_board_init(); nvic_priority_group_config(NVIC_PRIORITY_GROUP_4); - + rs485_config(); - + len = sizeof(str); rs485_send_data((u8*)str, len); while(1) @@ -131,7 +131,7 @@ int main(void) rs485_send_data(rs485_buffer_rx, rs485_buffer_rx_cnt); rs485_buffer_rx_cnt = 0; usart_interrupt_enable(USART2, USART_RDBF_INT, TRUE); - } + } } } @@ -143,8 +143,8 @@ int main(void) void USART2_IRQHandler(void) { uint16_t tmp; - - if(usart_flag_get(USART2, USART_RDBF_FLAG) != RESET) + + if(usart_interrupt_flag_get(USART2, USART_RDBF_FLAG) != RESET) { tmp = usart_data_receive(USART2); if(rs485_buffer_rx_cnt < RS485_BUFFER_SIZE) @@ -156,8 +156,8 @@ void USART2_IRQHandler(void) /** * @} - */ + */ /** * @} - */ + */ diff --git a/project/at_start_f403a/examples/usart/smartcard/src/at32f403a_407_int.c b/project/at_start_f403a/examples/usart/smartcard/src/at32f403a_407_int.c index 3ff180d0..63b1c218 100644 --- a/project/at_start_f403a/examples/usart/smartcard/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/usart/smartcard/src/at32f403a_407_int.c @@ -164,7 +164,7 @@ void EXINT9_5_IRQHandler(void) void SC_USART_IRQHandler(void) { /* if the sc_usart detects a parity error */ - if(usart_flag_get(SC_USART, USART_PERR_FLAG) != RESET) + if(usart_interrupt_flag_get(SC_USART, USART_PERR_FLAG) != RESET) { /* enable sc_usart rdbf interrupt (until receiving the corrupted byte) */ usart_interrupt_enable(SC_USART, USART_RDBF_INT, TRUE); @@ -172,7 +172,7 @@ void SC_USART_IRQHandler(void) usart_data_receive(SC_USART); } - if(usart_flag_get(SC_USART, USART_RDBF_FLAG) != RESET) + if(usart_interrupt_flag_get(SC_USART, USART_RDBF_FLAG) != RESET) { /* disable sc_usart rdbf interrupt */ usart_interrupt_enable(SC_USART, USART_RDBF_INT, FALSE); diff --git a/project/at_start_f403a/examples/usart/transfer_by_dma_interrupt/src/at32f403a_407_int.c b/project/at_start_f403a/examples/usart/transfer_by_dma_interrupt/src/at32f403a_407_int.c index 8e14c9fc..7a645452 100644 --- a/project/at_start_f403a/examples/usart/transfer_by_dma_interrupt/src/at32f403a_407_int.c +++ b/project/at_start_f403a/examples/usart/transfer_by_dma_interrupt/src/at32f403a_407_int.c @@ -142,7 +142,7 @@ void SysTick_Handler(void) */ void DMA1_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT1_FLAG)) + if(dma_interrupt_flag_get(DMA1_FDT1_FLAG)) { usart2_tx_dma_status = 1; dma_flag_clear(DMA1_FDT1_FLAG); @@ -157,7 +157,7 @@ void DMA1_Channel1_IRQHandler(void) */ void DMA1_Channel2_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT2_FLAG)) + if(dma_interrupt_flag_get(DMA1_FDT2_FLAG)) { usart2_rx_dma_status = 1; dma_flag_clear(DMA1_FDT2_FLAG); @@ -172,7 +172,7 @@ void DMA1_Channel2_IRQHandler(void) */ void DMA1_Channel3_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT3_FLAG)) + if(dma_interrupt_flag_get(DMA1_FDT3_FLAG)) { usart3_tx_dma_status = 1; dma_flag_clear(DMA1_FDT3_FLAG); @@ -187,7 +187,7 @@ void DMA1_Channel3_IRQHandler(void) */ void DMA1_Channel4_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT4_FLAG)) + if(dma_interrupt_flag_get(DMA1_FDT4_FLAG)) { usart3_rx_dma_status = 1; dma_flag_clear(DMA1_FDT4_FLAG); diff --git a/project/at_start_f403a/examples/usb_device/audio/src/audio_codec.c b/project/at_start_f403a/examples/usb_device/audio/src/audio_codec.c index c5a9590d..6601e257 100644 --- a/project/at_start_f403a/examples/usb_device/audio/src/audio_codec.c +++ b/project/at_start_f403a/examples/usb_device/audio/src/audio_codec.c @@ -205,6 +205,10 @@ void audio_codec_set_mic_volume(uint16_t volume) { /* wm8988 adc have 256 steps */ audio_codec.mic_volume = volume; + if(audio_codec.mic_volume > 0xFF) + { + audio_codec.mic_volume = 0xFF; + } } /** @@ -649,13 +653,13 @@ void DMA1_Channel3_IRQHandler(void) uint16_t half_size = audio_codec.spk_tx_size; uint16_t *pdst; - if(dma_flag_get(DMA1_HDT3_FLAG) == SET) + if(dma_interrupt_flag_get(DMA1_HDT3_FLAG) == SET) { //copy_buff(audio_codec.spk_buffer, audio_codec.spk_tx_fifo + audio_codec.r_pos, half_size); pdst = spk_dma_buffer; dma_flag_clear(DMA1_HDT3_FLAG); } - else if(dma_flag_get(DMA1_FDT3_FLAG) == SET) + else if(dma_interrupt_flag_get(DMA1_FDT3_FLAG) == SET) { //copy_buff(&audio_codec.spk_buffer[half_size], audio_codec.spk_tx_fifo + audio_codec.r_pos, half_size); pdst = spk_dma_buffer + half_size; @@ -724,12 +728,12 @@ void DMA1_Channel4_IRQHandler(void) uint16_t *psrc; uint16_t len = audio_codec.mic_rx_size << 1; - if(dma_flag_get(DMA1_HDT4_FLAG) == SET) + if(dma_interrupt_flag_get(DMA1_HDT4_FLAG) == SET) { dma_flag_clear(DMA1_HDT4_FLAG); psrc = mic_dma_buffer; } - else if(dma_flag_get(DMA1_FDT4_FLAG) == SET) + else if(dma_interrupt_flag_get(DMA1_FDT4_FLAG) == SET) { psrc = mic_dma_buffer + audio_codec.mic_rx_size; dma_flag_clear(DMA1_FDT4_FLAG); @@ -947,7 +951,3 @@ error_status audio_codec_loop(void) /** * @} */ - - - - diff --git a/project/at_start_f403a/examples/usb_device/composite_audio_hid/src/audio_codec.c b/project/at_start_f403a/examples/usb_device/composite_audio_hid/src/audio_codec.c index 833a78ae..28d26dbe 100644 --- a/project/at_start_f403a/examples/usb_device/composite_audio_hid/src/audio_codec.c +++ b/project/at_start_f403a/examples/usb_device/composite_audio_hid/src/audio_codec.c @@ -205,6 +205,10 @@ void audio_codec_set_mic_volume(uint16_t volume) { /* wm8988 adc have 256 steps */ audio_codec.mic_volume = volume; + if(audio_codec.mic_volume > 0xFF) + { + audio_codec.mic_volume = 0xFF; + } } /** @@ -651,13 +655,13 @@ void DMA1_Channel3_IRQHandler(void) uint16_t half_size = audio_codec.spk_tx_size; uint16_t *pdst; - if(dma_flag_get(DMA1_HDT3_FLAG) == SET) + if(dma_interrupt_flag_get(DMA1_HDT3_FLAG) == SET) { //copy_buff(audio_codec.spk_buffer, audio_codec.spk_tx_fifo + audio_codec.r_pos, half_size); pdst = spk_dma_buffer; dma_flag_clear(DMA1_HDT3_FLAG); } - else if(dma_flag_get(DMA1_FDT3_FLAG) == SET) + else if(dma_interrupt_flag_get(DMA1_FDT3_FLAG) == SET) { //copy_buff(&audio_codec.spk_buffer[half_size], audio_codec.spk_tx_fifo + audio_codec.r_pos, half_size); pdst = spk_dma_buffer + half_size; @@ -726,12 +730,12 @@ void DMA1_Channel4_IRQHandler(void) uint16_t *psrc; uint16_t len = audio_codec.mic_rx_size << 1; - if(dma_flag_get(DMA1_HDT4_FLAG) == SET) + if(dma_interrupt_flag_get(DMA1_HDT4_FLAG) == SET) { dma_flag_clear(DMA1_HDT4_FLAG); psrc = mic_dma_buffer; } - else if(dma_flag_get(DMA1_FDT4_FLAG) == SET) + else if(dma_interrupt_flag_get(DMA1_FDT4_FLAG) == SET) { psrc = mic_dma_buffer + audio_codec.mic_rx_size; dma_flag_clear(DMA1_FDT4_FLAG); @@ -949,7 +953,3 @@ error_status audio_codec_loop(void) /** * @} */ - - - - diff --git a/project/at_start_f403a/examples/usb_device/virtual_comport/src/main.c b/project/at_start_f403a/examples/usb_device/virtual_comport/src/main.c index 74ea9795..ea200279 100644 --- a/project/at_start_f403a/examples/usb_device/virtual_comport/src/main.c +++ b/project/at_start_f403a/examples/usb_device/virtual_comport/src/main.c @@ -281,7 +281,7 @@ uint16_t usart_receive_data(void) */ void USART2_IRQHandler(void) { - if(usart_flag_get(USART2, USART_RDBF_FLAG) != RESET) + if(usart_interrupt_flag_get(USART2, USART_RDBF_FLAG) != RESET) { /* read one byte from the receive data register */ usart_rx_buffer[hw_usart_rx_index] = usart_data_receive(USART2); @@ -320,7 +320,7 @@ void usb_usart_config( linecoding_type linecoding) default : break; } - + /* parity */ switch(linecoding.parity) { @@ -340,7 +340,7 @@ void usb_usart_config( linecoding_type linecoding) default : break; } - + if(USART_PARITY_NONE == usart_parity_select) { /* data bits */ @@ -359,7 +359,7 @@ void usb_usart_config( linecoding_type linecoding) break; default : break; - } + } } else { @@ -381,7 +381,7 @@ void usb_usart_config( linecoding_type linecoding) break; default : break; - } + } } nvic_irq_enable(USART2_IRQn, 0, 0); diff --git a/project/at_start_f403a/examples/usb_device/winusb/inc/at32f403a_407_clock.h b/project/at_start_f403a/examples/usb_device/winusb/inc/at32f403a_407_clock.h new file mode 100644 index 00000000..20f803ab --- /dev/null +++ b/project/at_start_f403a/examples/usb_device/winusb/inc/at32f403a_407_clock.h @@ -0,0 +1,44 @@ +/** + ************************************************************************** + * @file at32f403a_407_clock.h + * @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 __AT32F403A_407_CLOCK_H +#define __AT32F403A_407_CLOCK_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* includes ------------------------------------------------------------------*/ +#include "at32f403a_407.h" + +/* exported functions ------------------------------------------------------- */ +void system_clock_config(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __AT32F403A_407_CLOCK_H */ + diff --git a/project/at_start_f403a/examples/usb_device/winusb/inc/at32f403a_407_conf.h b/project/at_start_f403a/examples/usb_device/winusb/inc/at32f403a_407_conf.h new file mode 100644 index 00000000..4608566d --- /dev/null +++ b/project/at_start_f403a/examples/usb_device/winusb/inc/at32f403a_407_conf.h @@ -0,0 +1,162 @@ +/** + ************************************************************************** + * @file at32f403a_407_conf.h + * @brief at32f403a_407 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 __AT32F403A_407_CONF_H +#define __AT32F403A_407_CONF_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @brief in the following line adjust the value of high speed external 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 external crystal in hz */ +#endif + +/** + * @brief in the following line adjust the high speed external crystal (hext) startup + * timeout value + */ +#define HEXT_STARTUP_TIMEOUT ((uint16_t)0x3000) /*!< time out for hext start up */ +#define HICK_VALUE ((uint32_t)8000000) /*!< value of the high speed internal clock in hz */ +#define LEXT_VALUE ((uint32_t)32768) /*!< value of the low speed external clock in hz */ + +/* module define -------------------------------------------------------------*/ +#define CRM_MODULE_ENABLED +#define TMR_MODULE_ENABLED +#define RTC_MODULE_ENABLED +#define BPR_MODULE_ENABLED +#define GPIO_MODULE_ENABLED +#define I2C_MODULE_ENABLED +#define USART_MODULE_ENABLED +#define PWC_MODULE_ENABLED +#define CAN_MODULE_ENABLED +#define ADC_MODULE_ENABLED +#define DAC_MODULE_ENABLED +#define SPI_MODULE_ENABLED +#define DMA_MODULE_ENABLED +#define DEBUG_MODULE_ENABLED +#define FLASH_MODULE_ENABLED +#define CRC_MODULE_ENABLED +#define WWDT_MODULE_ENABLED +#define WDT_MODULE_ENABLED +#define EXINT_MODULE_ENABLED +#define SDIO_MODULE_ENABLED +#define XMC_MODULE_ENABLED +#define USB_MODULE_ENABLED +#define ACC_MODULE_ENABLED +#define MISC_MODULE_ENABLED +#define EMAC_MODULE_ENABLED + +/* includes ------------------------------------------------------------------*/ +#ifdef CRM_MODULE_ENABLED +#include "at32f403a_407_crm.h" +#endif +#ifdef TMR_MODULE_ENABLED +#include "at32f403a_407_tmr.h" +#endif +#ifdef RTC_MODULE_ENABLED +#include "at32f403a_407_rtc.h" +#endif +#ifdef BPR_MODULE_ENABLED +#include "at32f403a_407_bpr.h" +#endif +#ifdef GPIO_MODULE_ENABLED +#include "at32f403a_407_gpio.h" +#endif +#ifdef I2C_MODULE_ENABLED +#include "at32f403a_407_i2c.h" +#endif +#ifdef USART_MODULE_ENABLED +#include "at32f403a_407_usart.h" +#endif +#ifdef PWC_MODULE_ENABLED +#include "at32f403a_407_pwc.h" +#endif +#ifdef CAN_MODULE_ENABLED +#include "at32f403a_407_can.h" +#endif +#ifdef ADC_MODULE_ENABLED +#include "at32f403a_407_adc.h" +#endif +#ifdef DAC_MODULE_ENABLED +#include "at32f403a_407_dac.h" +#endif +#ifdef SPI_MODULE_ENABLED +#include "at32f403a_407_spi.h" +#endif +#ifdef DMA_MODULE_ENABLED +#include "at32f403a_407_dma.h" +#endif +#ifdef DEBUG_MODULE_ENABLED +#include "at32f403a_407_debug.h" +#endif +#ifdef FLASH_MODULE_ENABLED +#include "at32f403a_407_flash.h" +#endif +#ifdef CRC_MODULE_ENABLED +#include "at32f403a_407_crc.h" +#endif +#ifdef WWDT_MODULE_ENABLED +#include "at32f403a_407_wwdt.h" +#endif +#ifdef WDT_MODULE_ENABLED +#include "at32f403a_407_wdt.h" +#endif +#ifdef EXINT_MODULE_ENABLED +#include "at32f403a_407_exint.h" +#endif +#ifdef SDIO_MODULE_ENABLED +#include "at32f403a_407_sdio.h" +#endif +#ifdef XMC_MODULE_ENABLED +#include "at32f403a_407_xmc.h" +#endif +#ifdef ACC_MODULE_ENABLED +#include "at32f403a_407_acc.h" +#endif +#ifdef MISC_MODULE_ENABLED +#include "at32f403a_407_misc.h" +#endif +#ifdef USB_MODULE_ENABLED +#include "at32f403a_407_usb.h" +#endif +#ifdef EMAC_MODULE_ENABLED +#include "at32f403a_407_emac.h" +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/project/at_start_f403a/examples/usb_device/winusb/inc/at32f403a_407_int.h b/project/at_start_f403a/examples/usb_device/winusb/inc/at32f403a_407_int.h new file mode 100644 index 00000000..0685ab3c --- /dev/null +++ b/project/at_start_f403a/examples/usb_device/winusb/inc/at32f403a_407_int.h @@ -0,0 +1,56 @@ +/** + ************************************************************************** + * @file at32f403a_407_int.h + * @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 __AT32F403A_407_INT_H +#define __AT32F403A_407_INT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* includes ------------------------------------------------------------------*/ +#include "at32f403a_407.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/project/at_start_f403a/examples/usb_device/winusb/inc/usb_conf.h b/project/at_start_f403a/examples/usb_device/winusb/inc/usb_conf.h new file mode 100644 index 00000000..f20fefae --- /dev/null +++ b/project/at_start_f403a/examples/usb_device/winusb/inc/usb_conf.h @@ -0,0 +1,119 @@ +/** + ************************************************************************** + * @file usb_conf.h + * @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 "at32f403a_407.h" +#include "at32f403a_407_board.h" +#include "stdio.h" + +/** @addtogroup AT32F403A_periph_examples + * @{ + */ + +/** @addtogroup 403A_USB_device_winusb + * @{ + */ + +/** + * @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 buffer extend to 768-1280 bytes + */ +//#define USB_BUFFER_SIZE_EX /*!< usb enable extend buffer */ + + +/** + * @brief auto malloc usb endpoint buffer + */ +//#define USB_EPT_AUTO_MALLOC_BUFFER /*!< usb auto malloc endpoint tx and rx buffer */ + + +#ifndef USB_EPT_AUTO_MALLOC_BUFFER +/** + * @brief user custom endpoint buffer + * EPTn_TX_ADDR, EPTn_RX_ADDR must less than usb buffer size + */ + +/* ept0 tx start address 0x40, size 0x40, + so rx start address is 0x40 + 0x40 = 0x80 */ +#define EPT0_TX_ADDR 0x40 /*!< usb endpoint 0 tx buffer address offset */ +#define EPT0_RX_ADDR 0x80 /*!< usb endpoint 0 rx buffer address offset */ + +#define EPT1_TX_ADDR 0xC0 /*!< usb endpoint 1 tx buffer address offset */ +#define EPT1_RX_ADDR 0x100 /*!< usb endpoint 1 rx buffer address offset */ + +#define EPT2_TX_ADDR 0x140 /*!< usb endpoint 2 tx buffer address offset */ +#define EPT2_RX_ADDR 0x180 /*!< usb endpoint 2 rx buffer address offset */ + +#define EPT3_TX_ADDR 0x00 /*!< usb endpoint 3 tx buffer address offset */ +#define EPT3_RX_ADDR 0x00 /*!< usb endpoint 3 rx buffer address offset */ + +#define EPT4_TX_ADDR 0x00 /*!< usb endpoint 4 tx buffer address offset */ +#define EPT4_RX_ADDR 0x00 /*!< usb endpoint 4 rx buffer address offset */ + +#define EPT5_TX_ADDR 0x00 /*!< usb endpoint 5 tx buffer address offset */ +#define EPT5_RX_ADDR 0x00 /*!< usb endpoint 5 rx buffer address offset */ + +#define EPT6_TX_ADDR 0x00 /*!< usb endpoint 6 tx buffer address offset */ +#define EPT6_RX_ADDR 0x00 /*!< usb endpoint 6 rx buffer address offset */ + +#define EPT7_TX_ADDR 0x00 /*!< usb endpoint 7 tx buffer address offset */ +#define EPT7_RX_ADDR 0x00 /*!< usb endpoint 7 rx buffer address offset */ + +#endif + +/** + * @brief support winusb + */ +#define USBD_SUPPORT_WINUSB 1 + +void usb_delay_ms(uint32_t ms); +void usb_delay_us(uint32_t us); + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/project/at_start_f403a/examples/usb_device/winusb/mdk_v5/winusb.uvoptx b/project/at_start_f403a/examples/usb_device/winusb/mdk_v5/winusb.uvoptx new file mode 100644 index 00000000..5a588954 --- /dev/null +++ b/project/at_start_f403a/examples/usb_device/winusb/mdk_v5/winusb.uvoptx @@ -0,0 +1,672 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + winusb + 0x4 + ARM-ADS + + 12000000 + + 0 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0AT32F403A_1024 -FS08000000 -FL0100000 -FP0($$Device:-AT32F403AVGT7$Flash\AT32F403A_1024.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + user + 0 + 0 + 0 + 0 + + 1 + 1 + 1 + 0 + 0 + 0 + ..\src\at32f403a_407_clock.c + at32f403a_407_clock.c + 0 + 0 + + + 1 + 2 + 1 + 0 + 0 + 0 + ..\src\at32f403a_407_int.c + at32f403a_407_int.c + 0 + 0 + + + 1 + 3 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + + + bsp + 0 + 0 + 0 + 0 + + 2 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\at32f403a_407_board\at32f403a_407_board.c + at32f403a_407_board.c + 0 + 0 + + + + + firmware + 0 + 0 + 0 + 0 + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_acc.c + at32f403a_407_acc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_adc.c + at32f403a_407_adc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_bpr.c + at32f403a_407_bpr.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_can.c + at32f403a_407_can.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_crc.c + at32f403a_407_crc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_crm.c + at32f403a_407_crm.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_dac.c + at32f403a_407_dac.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_debug.c + at32f403a_407_debug.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_dma.c + at32f403a_407_dma.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_emac.c + at32f403a_407_emac.c + 0 + 0 + + + 3 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_exint.c + at32f403a_407_exint.c + 0 + 0 + + + 3 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_flash.c + at32f403a_407_flash.c + 0 + 0 + + + 3 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_gpio.c + at32f403a_407_gpio.c + 0 + 0 + + + 3 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_i2c.c + at32f403a_407_i2c.c + 0 + 0 + + + 3 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_misc.c + at32f403a_407_misc.c + 0 + 0 + + + 3 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_pwc.c + at32f403a_407_pwc.c + 0 + 0 + + + 3 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_rtc.c + at32f403a_407_rtc.c + 0 + 0 + + + 3 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_sdio.c + at32f403a_407_sdio.c + 0 + 0 + + + 3 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_spi.c + at32f403a_407_spi.c + 0 + 0 + + + 3 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_tmr.c + at32f403a_407_tmr.c + 0 + 0 + + + 3 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_usart.c + at32f403a_407_usart.c + 0 + 0 + + + 3 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_usb.c + at32f403a_407_usb.c + 0 + 0 + + + 3 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_wdt.c + at32f403a_407_wdt.c + 0 + 0 + + + 3 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_wwdt.c + at32f403a_407_wwdt.c + 0 + 0 + + + 3 + 29 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_xmc.c + at32f403a_407_xmc.c + 0 + 0 + + + + + cmsis + 0 + 0 + 0 + 0 + + 4 + 30 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\cmsis\cm4\device_support\system_at32f403a_407.c + system_at32f403a_407.c + 0 + 0 + + + 4 + 31 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\cmsis\cm4\device_support\startup\mdk\startup_at32f403a_407.s + startup_at32f403a_407.s + 0 + 0 + + + + + usbd_drivers + 0 + 0 + 0 + 0 + + 5 + 32 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\usbd_drivers\src\usbd_core.c + usbd_core.c + 0 + 0 + + + 5 + 33 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\usbd_drivers\src\usbd_int.c + usbd_int.c + 0 + 0 + + + 5 + 34 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\usbd_drivers\src\usbd_sdr.c + usbd_sdr.c + 0 + 0 + + + + + usbd_class + 0 + 0 + 0 + 0 + + 6 + 35 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\usbd_class\winusb\winusb_class.c + winusb_class.c + 0 + 0 + + + 6 + 36 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\usbd_class\winusb\winusb_desc.c + winusb_desc.c + 0 + 0 + + + + + readme + 0 + 0 + 0 + 0 + + 7 + 37 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/project/at_start_f403a/examples/usb_device/winusb/mdk_v5/winusb.uvprojx b/project/at_start_f403a/examples/usb_device/winusb/mdk_v5/winusb.uvprojx new file mode 100644 index 00000000..a6d42a2e --- /dev/null +++ b/project/at_start_f403a/examples/usb_device/winusb/mdk_v5/winusb.uvprojx @@ -0,0 +1,627 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + winusb + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + -AT32F403AVGT7 + ArteryTek + ArteryTek.AT32F403A_407_DFP.2.0.2 + IRAM(0x20000000,0x38000) IROM(0x08000000,0x100000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0AT32F403A_1024 -FS08000000 -FL0100000 -FP0($$Device:-AT32F403AVGT7$Flash\AT32F403A_1024.FLM)) + 0 + $$Device:-AT32F403AVGT7$Device\Include\at32f40x.h + + + + + + + + + + $$Device:-AT32F403AVGT7$SVD\AT32F403Axx_v2.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\objects\ + winusb + 1 + 0 + 1 + 1 + 1 + .\listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 0 + + + SARMCM3.DLL + -REMAP -MPU + DCM.DLL + -pCM4 + SARMCM3.DLL + -MPU + TCM.DLL + -pCM4 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M4" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 8 + 0 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x38000 + + + 1 + 0x8000000 + 0x100000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x8000000 + 0x100000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x38000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + AT32F403AVGT7,USE_STDPERIPH_DRIVER,AT_START_F403A_V1 + + ..\inc;..\..\..\..\..\at32f403a_407_board;..\..\..\..\..\..\libraries\drivers\inc;..\..\..\..\..\..\libraries\cmsis\cm4\core_support;..\..\..\..\..\..\libraries\cmsis\cm4\device_support;..\..\..\..\..\..\middlewares\usbd_drivers\inc;..\..\..\..\..\..\middlewares\usbd_class\winusb + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x08000000 + 0x20000000 + + + + + + + + + + + + + user + + + at32f403a_407_clock.c + 1 + ..\src\at32f403a_407_clock.c + + + at32f403a_407_int.c + 1 + ..\src\at32f403a_407_int.c + + + main.c + 1 + ..\src\main.c + + + + + bsp + + + at32f403a_407_board.c + 1 + ..\..\..\..\..\at32f403a_407_board\at32f403a_407_board.c + + + + + firmware + + + at32f403a_407_acc.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_acc.c + + + at32f403a_407_adc.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_adc.c + + + at32f403a_407_bpr.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_bpr.c + + + at32f403a_407_can.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_can.c + + + at32f403a_407_crc.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_crc.c + + + at32f403a_407_crm.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_crm.c + + + at32f403a_407_dac.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_dac.c + + + at32f403a_407_debug.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_debug.c + + + at32f403a_407_dma.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_dma.c + + + at32f403a_407_emac.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_emac.c + + + at32f403a_407_exint.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_exint.c + + + at32f403a_407_flash.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_flash.c + + + at32f403a_407_gpio.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_gpio.c + + + at32f403a_407_i2c.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_i2c.c + + + at32f403a_407_misc.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_misc.c + + + at32f403a_407_pwc.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_pwc.c + + + at32f403a_407_rtc.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_rtc.c + + + at32f403a_407_sdio.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_sdio.c + + + at32f403a_407_spi.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_spi.c + + + at32f403a_407_tmr.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_tmr.c + + + at32f403a_407_usart.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_usart.c + + + at32f403a_407_usb.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_usb.c + + + at32f403a_407_wdt.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_wdt.c + + + at32f403a_407_wwdt.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_wwdt.c + + + at32f403a_407_xmc.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_xmc.c + + + + + cmsis + + + system_at32f403a_407.c + 1 + ..\..\..\..\..\..\libraries\cmsis\cm4\device_support\system_at32f403a_407.c + + + startup_at32f403a_407.s + 2 + ..\..\..\..\..\..\libraries\cmsis\cm4\device_support\startup\mdk\startup_at32f403a_407.s + + + + + usbd_drivers + + + usbd_core.c + 1 + ..\..\..\..\..\..\middlewares\usbd_drivers\src\usbd_core.c + + + usbd_int.c + 1 + ..\..\..\..\..\..\middlewares\usbd_drivers\src\usbd_int.c + + + usbd_sdr.c + 1 + ..\..\..\..\..\..\middlewares\usbd_drivers\src\usbd_sdr.c + + + + + usbd_class + + + winusb_class.c + 1 + ..\..\..\..\..\..\middlewares\usbd_class\winusb\winusb_class.c + + + winusb_desc.c + 1 + ..\..\..\..\..\..\middlewares\usbd_class\winusb\winusb_desc.c + + + + + readme + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + + + + + <Project Info> + + + + + + 0 + 1 + + + + +
diff --git a/project/at_start_f403a/examples/usb_device/winusb/readme.txt b/project/at_start_f403a/examples/usb_device/winusb/readme.txt new file mode 100644 index 00000000..32a4ffd6 --- /dev/null +++ b/project/at_start_f403a/examples/usb_device/winusb/readme.txt @@ -0,0 +1,10 @@ +/** + ************************************************************************** + * @file readme.txt + * @brief readme + ************************************************************************** + */ + + this demo is based on the at-start board, in this demo, show how to build + a device of winusb. + for more detailed information, please refer to the application note document AN0097. diff --git a/project/at_start_f403a/examples/usb_device/winusb/src/at32f403a_407_clock.c b/project/at_start_f403a/examples/usb_device/winusb/src/at32f403a_407_clock.c new file mode 100644 index 00000000..3310724f --- /dev/null +++ b/project/at_start_f403a/examples/usb_device/winusb/src/at32f403a_407_clock.c @@ -0,0 +1,98 @@ +/** + ************************************************************************** + * @file at32f403a_407_clock.c + * @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 "at32f403a_407_clock.h" + +/** + * @brief system clock config program + * @note the system clock is configured as follow: + * system clock (sclk) = hext / 2 * pll_mult + * system clock source = pll (hext) + * - hext = HEXT_VALUE + * - sclk = 192000000 + * - ahbdiv = 1 + * - ahbclk = 192000000 + * - apb2div = 2 + * - apb2clk = 96000000 + * - apb1div = 2 + * - apb1clk = 96000000 + * - pll_mult = 48 + * - pll_range = GT72MHZ (greater than 72 mhz) + * @param none + * @retval none + */ +void system_clock_config(void) +{ + /* 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_DIV, CRM_PLL_MULT_48, CRM_PLL_OUTPUT_RANGE_GT72MHZ); + + /* config hext division */ + crm_hext_clock_div_set(CRM_HEXT_DIV_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, the maximum frequency of APB1/APB2 clock is 120 MHz */ + crm_apb2_div_set(CRM_APB2_DIV_2); + + /* config apb1clk, the maximum frequency of APB1/APB2 clock is 120 MHz */ + 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/project/at_start_f403a/examples/usb_device/winusb/src/at32f403a_407_int.c b/project/at_start_f403a/examples/usb_device/winusb/src/at32f403a_407_int.c new file mode 100644 index 00000000..b2b92dcc --- /dev/null +++ b/project/at_start_f403a/examples/usb_device/winusb/src/at32f403a_407_int.c @@ -0,0 +1,141 @@ +/** + ************************************************************************** + * @file at32f403a_407_int.c + * @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 "at32f403a_407_int.h" + +/** @addtogroup AT32F403A_periph_examples + * @{ + */ + +/** @addtogroup 403A_USB_device_winusb + * @{ + */ + +/** + * @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/project/at_start_f403a/examples/usb_device/winusb/src/main.c b/project/at_start_f403a/examples/usb_device/winusb/src/main.c new file mode 100644 index 00000000..9f893f4e --- /dev/null +++ b/project/at_start_f403a/examples/usb_device/winusb/src/main.c @@ -0,0 +1,207 @@ +/** + ************************************************************************** + * @file main.c + * @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 "at32f403a_407_board.h" +#include "at32f403a_407_clock.h" +#include "usbd_core.h" +#include "winusb_class.h" +#include "winusb_desc.h" +#include "usbd_int.h" + +/** @addtogroup AT32F403A_periph_examples + * @{ + */ + +/** @addtogroup 403A_USB_device_winusb USB_device_winusb + * @{ + */ + +usbd_core_type usb_core_dev; +uint8_t usb_buffer[256]; + +/** + * @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); + + /* 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; + + default: + break; + + } + } +} + +/** + * @brief main function. + * @param none + * @retval none + */ +int main(void) +{ + uint16_t data_len; + + uint32_t timeout; + + /* config nvic priority group */ + nvic_priority_group_config(NVIC_PRIORITY_GROUP_4); + + system_clock_config(); + + at32_board_init(); + + /* select usb 48m clcok source */ + usb_clock48m_select(USB_CLK_HEXT); + + /* enable usb clock */ + crm_periph_clock_enable(CRM_USB_PERIPH_CLOCK, TRUE); + + /* enable usb interrupt */ + nvic_irq_enable(USBFS_L_CAN1_RX0_IRQn, 0, 0); + + /* usb core init */ + usbd_core_init(&usb_core_dev, USB, &winusb_class_handler, &winusb_desc_handler, 0); + + /* enable usb pull-up */ + usbd_connect(&usb_core_dev); + + while(1) + { + /* get usb winusb receive data */ + data_len = usb_winusb_get_rxdata(&usb_core_dev, usb_buffer); + + if(data_len > 0) + { + + /* 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 + */ + timeout = 5000000; + do + { + /* send data to host */ + if(usb_winusb_send_data(&usb_core_dev, usb_buffer, data_len) == SUCCESS) + { + break; + } + }while(timeout --); + } + } +} + + +/** + * @brief this function handles usb interrupt. + * @param none + * @retval none + */ +void USBFS_L_CAN1_RX0_IRQHandler(void) +{ + usbd_irq_handler(&usb_core_dev); +} + +/** + * @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/project/at_start_f407/examples/acc/calibration/src/main.c b/project/at_start_f407/examples/acc/calibration/src/main.c index ab8cb7a1..7614134d 100644 --- a/project/at_start_f407/examples/acc/calibration/src/main.c +++ b/project/at_start_f407/examples/acc/calibration/src/main.c @@ -132,14 +132,14 @@ void USBFS_L_CAN1_RX0_IRQHandler(void) */ void ACC_IRQHandler(void) { - if(acc_flag_get(ACC_CALRDY_FLAG) != RESET) + if(acc_interrupt_flag_get(ACC_CALRDY_FLAG) != RESET) { at32_led_toggle(LED2); /* clear acc calibration ready flag */ acc_flag_clear(ACC_CALRDY_FLAG); } - if(acc_flag_get(ACC_RSLOST_FLAG) != RESET) + if(acc_interrupt_flag_get(ACC_RSLOST_FLAG) != RESET) { at32_led_toggle(LED3); diff --git a/project/at_start_f407/examples/adc/combine_mode_ordinary_simult/mdk_v5/combine_mode_ordinary_simult.uvprojx b/project/at_start_f407/examples/adc/combine_mode_ordinary_simult/mdk_v5/combine_mode_ordinary_simult.uvprojx index 8bdc24b1..95e3fae9 100644 --- a/project/at_start_f407/examples/adc/combine_mode_ordinary_simult/mdk_v5/combine_mode_ordinary_simult.uvprojx +++ b/project/at_start_f407/examples/adc/combine_mode_ordinary_simult/mdk_v5/combine_mode_ordinary_simult.uvprojx @@ -10,7 +10,7 @@ combine_mode_ordinary_simult 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f407/examples/adc/combine_mode_ordinary_simult/src/at32f403a_407_int.c b/project/at_start_f407/examples/adc/combine_mode_ordinary_simult/src/at32f403a_407_int.c index a0b79dc0..8d203cb6 100644 --- a/project/at_start_f407/examples/adc/combine_mode_ordinary_simult/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/adc/combine_mode_ordinary_simult/src/at32f403a_407_int.c @@ -141,7 +141,7 @@ void SysTick_Handler(void) */ void DMA1_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT1_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA1_FDT1_FLAG) != RESET) { dma_flag_clear(DMA1_FDT1_FLAG); dma1_trans_complete_flag = 1; diff --git a/project/at_start_f407/examples/adc/current_vref_value_check/mdk_v5/current_vref_value_check.uvprojx b/project/at_start_f407/examples/adc/current_vref_value_check/mdk_v5/current_vref_value_check.uvprojx index 588a3bcc..f1a70b2b 100644 --- a/project/at_start_f407/examples/adc/current_vref_value_check/mdk_v5/current_vref_value_check.uvprojx +++ b/project/at_start_f407/examples/adc/current_vref_value_check/mdk_v5/current_vref_value_check.uvprojx @@ -10,7 +10,7 @@ current_vref_value_check 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f407/examples/adc/exint_trigger_partitioned/mdk_v5/exint_trigger_partitioned.uvprojx b/project/at_start_f407/examples/adc/exint_trigger_partitioned/mdk_v5/exint_trigger_partitioned.uvprojx index cc5d5a1d..3bcac073 100644 --- a/project/at_start_f407/examples/adc/exint_trigger_partitioned/mdk_v5/exint_trigger_partitioned.uvprojx +++ b/project/at_start_f407/examples/adc/exint_trigger_partitioned/mdk_v5/exint_trigger_partitioned.uvprojx @@ -10,7 +10,7 @@ exint_trigger_partitioned 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f407/examples/adc/exint_trigger_partitioned/src/at32f403a_407_int.c b/project/at_start_f407/examples/adc/exint_trigger_partitioned/src/at32f403a_407_int.c index fa42d184..cae63dee 100644 --- a/project/at_start_f407/examples/adc/exint_trigger_partitioned/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/adc/exint_trigger_partitioned/src/at32f403a_407_int.c @@ -142,7 +142,7 @@ void SysTick_Handler(void) */ void DMA1_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT1_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA1_FDT1_FLAG) != RESET) { dma_flag_clear(DMA1_FDT1_FLAG); dma_trans_complete_flag = 1; @@ -156,7 +156,7 @@ void DMA1_Channel1_IRQHandler(void) */ void ADC1_2_IRQHandler(void) { - if(adc_flag_get(ADC1, ADC_PCCE_FLAG) != RESET) + if(adc_interrupt_flag_get(ADC1, ADC_PCCE_FLAG) != RESET) { adc_flag_clear(ADC1, ADC_PCCE_FLAG); if(preempt_trigger_count < 3) diff --git a/project/at_start_f407/examples/adc/internal_temperature_sensor/mdk_v5/internal_temperature_sensor.uvprojx b/project/at_start_f407/examples/adc/internal_temperature_sensor/mdk_v5/internal_temperature_sensor.uvprojx index 846071b0..b38f5d78 100644 --- a/project/at_start_f407/examples/adc/internal_temperature_sensor/mdk_v5/internal_temperature_sensor.uvprojx +++ b/project/at_start_f407/examples/adc/internal_temperature_sensor/mdk_v5/internal_temperature_sensor.uvprojx @@ -10,7 +10,7 @@ internal_temperature_sensor 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f407/examples/adc/repeat_conversion_loop_transfer/src/at32f403a_407_int.c b/project/at_start_f407/examples/adc/repeat_conversion_loop_transfer/src/at32f403a_407_int.c index bb3d849a..5d565c44 100644 --- a/project/at_start_f407/examples/adc/repeat_conversion_loop_transfer/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/adc/repeat_conversion_loop_transfer/src/at32f403a_407_int.c @@ -140,7 +140,7 @@ void SysTick_Handler(void) */ void DMA1_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT1_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA1_FDT1_FLAG) != RESET) { dma_flag_clear(DMA1_FDT1_FLAG); dma_trans_complete_flag++; diff --git a/project/at_start_f407/examples/adc/software_trigger_repeat/src/at32f403a_407_int.c b/project/at_start_f407/examples/adc/software_trigger_repeat/src/at32f403a_407_int.c index a53b32a3..c1e0c8cd 100644 --- a/project/at_start_f407/examples/adc/software_trigger_repeat/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/adc/software_trigger_repeat/src/at32f403a_407_int.c @@ -140,7 +140,7 @@ void SysTick_Handler(void) */ void DMA1_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT1_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA1_FDT1_FLAG) != RESET) { dma_flag_clear(DMA1_FDT1_FLAG); dma_trans_complete_flag++; diff --git a/project/at_start_f407/examples/adc/tmr_trigger_automatic_preempted/mdk_v5/tmr_trigger_automatic_preempted.uvprojx b/project/at_start_f407/examples/adc/tmr_trigger_automatic_preempted/mdk_v5/tmr_trigger_automatic_preempted.uvprojx index 90a11c69..ce42d451 100644 --- a/project/at_start_f407/examples/adc/tmr_trigger_automatic_preempted/mdk_v5/tmr_trigger_automatic_preempted.uvprojx +++ b/project/at_start_f407/examples/adc/tmr_trigger_automatic_preempted/mdk_v5/tmr_trigger_automatic_preempted.uvprojx @@ -10,7 +10,7 @@ tmr_trigger_automatic_preempted 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f407/examples/adc/tmr_trigger_automatic_preempted/src/at32f403a_407_int.c b/project/at_start_f407/examples/adc/tmr_trigger_automatic_preempted/src/at32f403a_407_int.c index d5485982..b786bfc3 100644 --- a/project/at_start_f407/examples/adc/tmr_trigger_automatic_preempted/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/adc/tmr_trigger_automatic_preempted/src/at32f403a_407_int.c @@ -143,7 +143,7 @@ void SysTick_Handler(void) */ void DMA1_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT1_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA1_FDT1_FLAG) != RESET) { dma_flag_clear(DMA1_FDT1_FLAG); dma_trans_complete_flag = 1; @@ -157,7 +157,7 @@ void DMA1_Channel1_IRQHandler(void) */ void ADC1_2_IRQHandler(void) { - if(adc_flag_get(ADC1, ADC_PCCE_FLAG) != RESET) + if(adc_interrupt_flag_get(ADC1, ADC_PCCE_FLAG) != RESET) { adc_flag_clear(ADC1, ADC_PCCE_FLAG); if(preempt_conversion_count < 5) diff --git a/project/at_start_f407/examples/adc/triple_adc_synchro_trigger/mdk_v5/triple_adc_synchro_trigger.uvprojx b/project/at_start_f407/examples/adc/triple_adc_synchro_trigger/mdk_v5/triple_adc_synchro_trigger.uvprojx index 390e3c12..ef9dc052 100644 --- a/project/at_start_f407/examples/adc/triple_adc_synchro_trigger/mdk_v5/triple_adc_synchro_trigger.uvprojx +++ b/project/at_start_f407/examples/adc/triple_adc_synchro_trigger/mdk_v5/triple_adc_synchro_trigger.uvprojx @@ -10,7 +10,7 @@ triple_adc_synchro_trigger 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f407/examples/adc/triple_adc_synchro_trigger/src/at32f403a_407_int.c b/project/at_start_f407/examples/adc/triple_adc_synchro_trigger/src/at32f403a_407_int.c index 05bb1fcb..c7adbb12 100644 --- a/project/at_start_f407/examples/adc/triple_adc_synchro_trigger/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/adc/triple_adc_synchro_trigger/src/at32f403a_407_int.c @@ -143,7 +143,7 @@ void SysTick_Handler(void) */ void DMA1_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT1_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA1_FDT1_FLAG) != RESET) { dma_flag_clear(DMA1_FDT1_FLAG); dma1_trans_complete_flag = 1; @@ -157,7 +157,7 @@ void DMA1_Channel1_IRQHandler(void) */ void DMA2_Channel4_5_IRQHandler(void) { - if(dma_flag_get(DMA2_FDT5_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA2_FDT5_FLAG) != RESET) { dma_flag_clear(DMA2_FDT5_FLAG); dma2_trans_complete_flag = 1; diff --git a/project/at_start_f407/examples/adc/voltage_monitoring/mdk_v5/voltage_monitoring.uvprojx b/project/at_start_f407/examples/adc/voltage_monitoring/mdk_v5/voltage_monitoring.uvprojx index 36613880..e73e0c86 100644 --- a/project/at_start_f407/examples/adc/voltage_monitoring/mdk_v5/voltage_monitoring.uvprojx +++ b/project/at_start_f407/examples/adc/voltage_monitoring/mdk_v5/voltage_monitoring.uvprojx @@ -10,7 +10,7 @@ voltage_monitoring 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f407/examples/adc/voltage_monitoring/src/at32f403a_407_int.c b/project/at_start_f407/examples/adc/voltage_monitoring/src/at32f403a_407_int.c index 04da3520..9f6448f4 100644 --- a/project/at_start_f407/examples/adc/voltage_monitoring/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/adc/voltage_monitoring/src/at32f403a_407_int.c @@ -142,7 +142,7 @@ void SysTick_Handler(void) */ void ADC1_2_IRQHandler(void) { - if(adc_flag_get(ADC1, ADC_VMOR_FLAG) != RESET) + if(adc_interrupt_flag_get(ADC1, ADC_VMOR_FLAG) != RESET) { at32_led_toggle(LED3); adc_flag_clear(ADC1, ADC_VMOR_FLAG); diff --git a/project/at_start_f407/examples/bpr/tamper/src/at32f403a_407_int.c b/project/at_start_f407/examples/bpr/tamper/src/at32f403a_407_int.c index 25807fb1..87e83752 100644 --- a/project/at_start_f407/examples/bpr/tamper/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/bpr/tamper/src/at32f403a_407_int.c @@ -140,7 +140,7 @@ void SysTick_Handler(void) */ void TAMPER_IRQHandler(void) { - if(bpr_flag_get(BPR_TAMPER_INTERRUPT_FLAG) != RESET) + if(bpr_interrupt_flag_get(BPR_TAMPER_INTERRUPT_FLAG) != RESET) { /* check if bpr registers are cleared */ if(bpr_reg_judge() == 0) diff --git a/project/at_start_f407/examples/can/communication_mode/src/main.c b/project/at_start_f407/examples/can/communication_mode/src/main.c index 997170ce..1d25c7f5 100644 --- a/project/at_start_f407/examples/can/communication_mode/src/main.c +++ b/project/at_start_f407/examples/can/communication_mode/src/main.c @@ -108,7 +108,7 @@ static void can_configuration(void) nvic_irq_enable(CAN1_SE_IRQn, 0x00, 0x00); nvic_irq_enable(USBFS_L_CAN1_RX0_IRQn, 0x00, 0x00); can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE); - + /* error interrupt enable */ can_interrupt_enable(CAN1, CAN_ETRIEN_INT, TRUE); can_interrupt_enable(CAN1, CAN_EOIEN_INT, TRUE); @@ -148,7 +148,7 @@ static void can_transmit_data(void) void USBFS_L_CAN1_RX0_IRQHandler (void) { can_rx_message_type rx_message_struct; - if(can_flag_get(CAN1,CAN_RF0MN_FLAG) != RESET) + if(can_interrupt_flag_get(CAN1,CAN_RF0MN_FLAG) != RESET) { can_message_receive(CAN1, CAN_RX_FIFO0, &rx_message_struct); if(rx_message_struct.standard_id == 0x400) @@ -166,7 +166,7 @@ void USBFS_L_CAN1_RX0_IRQHandler (void) void CAN1_SE_IRQHandler(void) { __IO uint32_t err_index = 0; - if(can_flag_get(CAN1,CAN_ETR_FLAG) != RESET) + if(can_interrupt_flag_get(CAN1,CAN_ETR_FLAG) != RESET) { err_index = CAN1->ests & 0x70; can_flag_clear(CAN1, CAN_ETR_FLAG); diff --git a/project/at_start_f407/examples/can/filter/src/main.c b/project/at_start_f407/examples/can/filter/src/main.c index 4da9c25e..b21a36f0 100644 --- a/project/at_start_f407/examples/can/filter/src/main.c +++ b/project/at_start_f407/examples/can/filter/src/main.c @@ -133,7 +133,7 @@ static void can_configuration(void) nvic_irq_enable(CAN1_SE_IRQn, 0x00, 0x00); nvic_irq_enable(USBFS_L_CAN1_RX0_IRQn, 0x00, 0x00); can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE); - + /* error interrupt enable */ can_interrupt_enable(CAN1, CAN_ETRIEN_INT, TRUE); can_interrupt_enable(CAN1, CAN_EOIEN_INT, TRUE); @@ -260,7 +260,7 @@ static void can_transmit_data(void) void USBFS_L_CAN1_RX0_IRQHandler (void) { can_rx_message_type rx_message_struct; - if(can_flag_get(CAN1,CAN_RF0MN_FLAG) != RESET) + if(can_interrupt_flag_get(CAN1,CAN_RF0MN_FLAG) != RESET) { if(test_result == 4) { @@ -288,7 +288,7 @@ void USBFS_L_CAN1_RX0_IRQHandler (void) void CAN1_SE_IRQHandler(void) { __IO uint32_t err_index = 0; - if(can_flag_get(CAN1,CAN_ETR_FLAG) != RESET) + if(can_interrupt_flag_get(CAN1,CAN_ETR_FLAG) != RESET) { err_index = CAN1->ests & 0x70; can_flag_clear(CAN1, CAN_ETR_FLAG); diff --git a/project/at_start_f407/examples/can/loopback_mode/src/main.c b/project/at_start_f407/examples/can/loopback_mode/src/main.c index 9ed075f8..9607b9a8 100644 --- a/project/at_start_f407/examples/can/loopback_mode/src/main.c +++ b/project/at_start_f407/examples/can/loopback_mode/src/main.c @@ -108,7 +108,7 @@ static void can_configuration(void) nvic_irq_enable(CAN1_SE_IRQn, 0x00, 0x00); nvic_irq_enable(USBFS_L_CAN1_RX0_IRQn, 0x00, 0x00); can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE); - + /* error interrupt enable */ can_interrupt_enable(CAN1, CAN_ETRIEN_INT, TRUE); can_interrupt_enable(CAN1, CAN_EOIEN_INT, TRUE); @@ -148,7 +148,7 @@ static void can_transmit_data(void) void USBFS_L_CAN1_RX0_IRQHandler (void) { can_rx_message_type rx_message_struct; - if(can_flag_get(CAN1,CAN_RF0MN_FLAG) != RESET) + if(can_interrupt_flag_get(CAN1,CAN_RF0MN_FLAG) != RESET) { can_message_receive(CAN1, CAN_RX_FIFO0, &rx_message_struct); if(rx_message_struct.standard_id == 0x400) @@ -164,7 +164,7 @@ void USBFS_L_CAN1_RX0_IRQHandler (void) void CAN1_SE_IRQHandler(void) { __IO uint32_t err_index = 0; - if(can_flag_get(CAN1,CAN_ETR_FLAG) != RESET) + if(can_interrupt_flag_get(CAN1,CAN_ETR_FLAG) != RESET) { err_index = CAN1->ests & 0x70; can_flag_clear(CAN1, CAN_ETR_FLAG); diff --git a/project/at_start_f407/examples/cortex_m4/systick_interrupt/src/main.c b/project/at_start_f407/examples/cortex_m4/systick_interrupt/src/main.c index db781f71..a158f192 100644 --- a/project/at_start_f407/examples/cortex_m4/systick_interrupt/src/main.c +++ b/project/at_start_f407/examples/cortex_m4/systick_interrupt/src/main.c @@ -55,6 +55,26 @@ void systick_handler(void) } } +/** + * @brief config systick and enable interrupt. + * @param none + * @retval none + */ +static uint32_t systick_interrupt_config(uint32_t ticks) +{ + if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) + { + return (1UL); + } + + SysTick->LOAD = (uint32_t)(ticks - 1UL); + NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); + SysTick->VAL = 0UL; + SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk | + SysTick_CTRL_ENABLE_Msk; + return (0UL); +} + /** * @brief main function. * @param none @@ -68,7 +88,7 @@ int main(void) systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV); /* config systick reload value and enable interrupt */ - SysTick_Config(MS_TICK); + systick_interrupt_config(MS_TICK); /* configure led */ at32_led_init(LED2); diff --git a/project/at_start_f407/examples/debug/tmr1/src/main.c b/project/at_start_f407/examples/debug/tmr1/src/main.c index 533b6db4..e7a4d152 100644 --- a/project/at_start_f407/examples/debug/tmr1/src/main.c +++ b/project/at_start_f407/examples/debug/tmr1/src/main.c @@ -44,7 +44,7 @@ uint16_t counter = 0; */ void TMR1_OVF_TMR10_IRQHandler(void) { - if(tmr_flag_get(TMR1, TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR1, TMR_OVF_FLAG) != RESET) { /* add user code... */ at32_led_toggle(LED3); diff --git a/project/at_start_f407/examples/dma/data_to_gpio_flexible/src/main.c b/project/at_start_f407/examples/dma/data_to_gpio_flexible/src/main.c index 49008212..bd5bebb0 100644 --- a/project/at_start_f407/examples/dma/data_to_gpio_flexible/src/main.c +++ b/project/at_start_f407/examples/dma/data_to_gpio_flexible/src/main.c @@ -47,7 +47,7 @@ uint16_t src_buffer[BUFFER_SIZE] = {0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x00 */ void DMA2_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA2_FDT1_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA2_FDT1_FLAG) != RESET) { /* turn led2/led3/led4 on */ at32_led_on(LED2); diff --git a/project/at_start_f407/examples/dma/flash_to_sram/src/main.c b/project/at_start_f407/examples/dma/flash_to_sram/src/main.c index a7f97e75..2e0eeb71 100644 --- a/project/at_start_f407/examples/dma/flash_to_sram/src/main.c +++ b/project/at_start_f407/examples/dma/flash_to_sram/src/main.c @@ -59,7 +59,7 @@ error_status buffer_compare(const uint32_t* pbuffer, uint32_t* pbuffer1, uint16_ */ void DMA1_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT1_FLAG) != RESET) + if(dma_interrupt_flag_get(DMA1_FDT1_FLAG) != RESET) { data_counter_end = 0; dma_flag_clear(DMA1_FDT1_FLAG); @@ -157,4 +157,3 @@ int main(void) /** * @} */ - diff --git a/project/at_start_f407/examples/emac/dns_client/src/at32f403a_407_int.c b/project/at_start_f407/examples/emac/dns_client/src/at32f403a_407_int.c index 57ddb66e..269201ed 100644 --- a/project/at_start_f407/examples/emac/dns_client/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/emac/dns_client/src/at32f403a_407_int.c @@ -138,7 +138,7 @@ void SysTick_Handler(void) */ void TMR6_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR6, TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR6, TMR_OVF_FLAG) != RESET) { /* Update the local_time by adding SYSTEMTICK_PERIOD_MS each SysTick interrupt */ time_update(); diff --git a/project/at_start_f407/examples/emac/http_server/src/at32f403a_407_int.c b/project/at_start_f407/examples/emac/http_server/src/at32f403a_407_int.c index 2429e7d1..7ab3e5d8 100644 --- a/project/at_start_f407/examples/emac/http_server/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/emac/http_server/src/at32f403a_407_int.c @@ -138,7 +138,7 @@ void SysTick_Handler(void) */ void TMR6_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR6, TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR6, TMR_OVF_FLAG) != RESET) { /* Update the local_time by adding SYSTEMTICK_PERIOD_MS each SysTick interrupt */ time_update(); diff --git a/project/at_start_f407/examples/emac/iperf/src/at32f403a_407_int.c b/project/at_start_f407/examples/emac/iperf/src/at32f403a_407_int.c index cab63110..206c13ad 100644 --- a/project/at_start_f407/examples/emac/iperf/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/emac/iperf/src/at32f403a_407_int.c @@ -138,7 +138,7 @@ void SysTick_Handler(void) */ void TMR6_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR6, TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR6, TMR_OVF_FLAG) != RESET) { /* Update the local_time by adding SYSTEMTICK_PERIOD_MS each SysTick interrupt */ time_update(); diff --git a/project/at_start_f407/examples/emac/mqtt_client/src/at32f403a_407_int.c b/project/at_start_f407/examples/emac/mqtt_client/src/at32f403a_407_int.c index 4a4d1569..ffcf9afc 100644 --- a/project/at_start_f407/examples/emac/mqtt_client/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/emac/mqtt_client/src/at32f403a_407_int.c @@ -138,7 +138,7 @@ void SysTick_Handler(void) */ void TMR6_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR6, TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR6, TMR_OVF_FLAG) != RESET) { /* Update the local_time by adding SYSTEMTICK_PERIOD_MS each SysTick interrupt */ time_update(); diff --git a/project/at_start_f407/examples/emac/tcp_client/src/at32f403a_407_int.c b/project/at_start_f407/examples/emac/tcp_client/src/at32f403a_407_int.c index ff661f96..83e7e5f1 100644 --- a/project/at_start_f407/examples/emac/tcp_client/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/emac/tcp_client/src/at32f403a_407_int.c @@ -138,7 +138,7 @@ void SysTick_Handler(void) */ void TMR6_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR6, TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR6, TMR_OVF_FLAG) != RESET) { /* Update the local_time by adding SYSTEMTICK_PERIOD_MS each SysTick interrupt */ time_update(); diff --git a/project/at_start_f407/examples/emac/tcp_server/src/at32f403a_407_int.c b/project/at_start_f407/examples/emac/tcp_server/src/at32f403a_407_int.c index 6bfd7ecc..220e41a9 100644 --- a/project/at_start_f407/examples/emac/tcp_server/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/emac/tcp_server/src/at32f403a_407_int.c @@ -138,7 +138,7 @@ void SysTick_Handler(void) */ void TMR6_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR6, TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR6, TMR_OVF_FLAG) != RESET) { /* Update the local_time by adding SYSTEMTICK_PERIOD_MS each SysTick interrupt */ time_update(); diff --git a/project/at_start_f407/examples/emac/telnet/src/at32f403a_407_int.c b/project/at_start_f407/examples/emac/telnet/src/at32f403a_407_int.c index f11f8893..ea206b10 100644 --- a/project/at_start_f407/examples/emac/telnet/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/emac/telnet/src/at32f403a_407_int.c @@ -138,7 +138,7 @@ void SysTick_Handler(void) */ void TMR6_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR6, TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR6, TMR_OVF_FLAG) != RESET) { /* Update the local_time by adding SYSTEMTICK_PERIOD_MS each SysTick interrupt */ time_update(); diff --git a/project/at_start_f407/examples/emac/wake_on_lan/src/at32f403a_407_int.c b/project/at_start_f407/examples/emac/wake_on_lan/src/at32f403a_407_int.c index c6fb6dd3..378d418c 100644 --- a/project/at_start_f407/examples/emac/wake_on_lan/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/emac/wake_on_lan/src/at32f403a_407_int.c @@ -139,7 +139,7 @@ void SysTick_Handler(void) */ void TMR6_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR6, TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR6, TMR_OVF_FLAG) != RESET) { /* Update the local_time by adding SYSTEMTICK_PERIOD_MS each SysTick interrupt */ time_update(); diff --git a/project/at_start_f407/examples/exint/exint_config/src/main.c b/project/at_start_f407/examples/exint/exint_config/src/main.c index 800dacda..5e4ed48e 100644 --- a/project/at_start_f407/examples/exint/exint_config/src/main.c +++ b/project/at_start_f407/examples/exint/exint_config/src/main.c @@ -93,7 +93,7 @@ void exint_line0_config(void) */ void EXINT0_IRQHandler(void) { - if(exint_flag_get(EXINT_LINE_0) != RESET) + if(exint_interrupt_flag_get(EXINT_LINE_0) != RESET) { at32_led_toggle(LED2); at32_led_toggle(LED3); diff --git a/project/at_start_f407/examples/exint/exint_software_trigger/src/main.c b/project/at_start_f407/examples/exint/exint_software_trigger/src/main.c index 8ad11bfc..4033c5f4 100644 --- a/project/at_start_f407/examples/exint/exint_software_trigger/src/main.c +++ b/project/at_start_f407/examples/exint/exint_software_trigger/src/main.c @@ -88,7 +88,7 @@ static void tmr1_config(void) */ void TMR1_OVF_TMR10_IRQHandler(void) { - if(tmr_flag_get(TMR1,TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR1,TMR_OVF_FLAG) != RESET) { at32_led_toggle(LED2); exint_software_interrupt_event_generate(EXINT_LINE_4); @@ -103,7 +103,7 @@ void TMR1_OVF_TMR10_IRQHandler(void) */ void EXINT4_IRQHandler(void) { - if(exint_flag_get(EXINT_LINE_4) != RESET) + if(exint_interrupt_flag_get(EXINT_LINE_4) != RESET) { at32_led_toggle(LED3); at32_led_toggle(LED4); diff --git a/project/at_start_f407/examples/i2s/halfduplex_interrupt/src/at32f403a_407_int.c b/project/at_start_f407/examples/i2s/halfduplex_interrupt/src/at32f403a_407_int.c index 2146025a..f10cb163 100644 --- a/project/at_start_f407/examples/i2s/halfduplex_interrupt/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/i2s/halfduplex_interrupt/src/at32f403a_407_int.c @@ -143,7 +143,7 @@ void SysTick_Handler(void) */ void SPI2_I2S2EXT_IRQHandler(void) { - if(spi_i2s_flag_get(SPI2, SPI_I2S_RDBF_FLAG) != RESET) + if(spi_i2s_interrupt_flag_get(SPI2, SPI_I2S_RDBF_FLAG) != RESET) { i2s2_buffer_rx[rx_index++] = spi_i2s_data_receive(SPI2); } @@ -156,7 +156,7 @@ void SysTick_Handler(void) */ void SPI3_I2S3EXT_IRQHandler(void) { - if(spi_i2s_flag_get(SPI3, SPI_I2S_TDBE_FLAG) != RESET) + if(spi_i2s_interrupt_flag_get(SPI3, SPI_I2S_TDBE_FLAG) != RESET) { spi_i2s_data_transmit(SPI3, i2s3_buffer_tx[tx_index++]); if(tx_index == 32) diff --git a/project/at_start_f407/examples/pwc/deepsleep_rtc/src/at32f403a_407_int.c b/project/at_start_f407/examples/pwc/deepsleep_rtc/src/at32f403a_407_int.c index 9601e9c6..67cf4ecd 100644 --- a/project/at_start_f407/examples/pwc/deepsleep_rtc/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/pwc/deepsleep_rtc/src/at32f403a_407_int.c @@ -140,7 +140,7 @@ void SysTick_Handler(void) */ void RTCAlarm_IRQHandler(void) { - if(rtc_flag_get(RTC_TA_FLAG) != RESET) + if(rtc_interrupt_flag_get(RTC_TA_FLAG) != RESET) { /* clear exint line flag */ exint_flag_clear(EXINT_LINE_17); diff --git a/project/at_start_f407/examples/pwc/power_voltage_monitor/mdk_v5/power_voltage_monitor.uvprojx b/project/at_start_f407/examples/pwc/power_voltage_monitor/mdk_v5/power_voltage_monitor.uvprojx index 656e98be..d2fa6018 100644 --- a/project/at_start_f407/examples/pwc/power_voltage_monitor/mdk_v5/power_voltage_monitor.uvprojx +++ b/project/at_start_f407/examples/pwc/power_voltage_monitor/mdk_v5/power_voltage_monitor.uvprojx @@ -10,7 +10,7 @@ power_voltage_monitor 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f407/examples/pwc/power_voltage_monitor/src/at32f403a_407_int.c b/project/at_start_f407/examples/pwc/power_voltage_monitor/src/at32f403a_407_int.c index a27e194b..e36693e3 100644 --- a/project/at_start_f407/examples/pwc/power_voltage_monitor/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/pwc/power_voltage_monitor/src/at32f403a_407_int.c @@ -140,7 +140,7 @@ void SysTick_Handler(void) */ void PVM_IRQHandler(void) { - if(exint_flag_get(EXINT_LINE_16) != RESET) + if(exint_interrupt_flag_get(EXINT_LINE_16) != RESET) { /* clear exint line flag */ exint_flag_clear(EXINT_LINE_16); diff --git a/project/at_start_f407/examples/pwc/sleep_tmr2/mdk_v5/sleep_tmr2.uvprojx b/project/at_start_f407/examples/pwc/sleep_tmr2/mdk_v5/sleep_tmr2.uvprojx index 41abea69..29901556 100644 --- a/project/at_start_f407/examples/pwc/sleep_tmr2/mdk_v5/sleep_tmr2.uvprojx +++ b/project/at_start_f407/examples/pwc/sleep_tmr2/mdk_v5/sleep_tmr2.uvprojx @@ -10,7 +10,7 @@ sleep_tmr2 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f407/examples/pwc/sleep_tmr2/src/at32f403a_407_int.c b/project/at_start_f407/examples/pwc/sleep_tmr2/src/at32f403a_407_int.c index ba4d62b9..6187f2d9 100644 --- a/project/at_start_f407/examples/pwc/sleep_tmr2/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/pwc/sleep_tmr2/src/at32f403a_407_int.c @@ -139,7 +139,7 @@ void SysTick_Handler(void) */ void TMR2_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR2, TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR2, TMR_OVF_FLAG) != RESET) { /* clear timer 2 ovf flag */ tmr_flag_clear(TMR2, TMR_OVF_FLAG); diff --git a/project/at_start_f407/examples/pwc/sleep_usart1/mdk_v5/sleep_usart1.uvprojx b/project/at_start_f407/examples/pwc/sleep_usart1/mdk_v5/sleep_usart1.uvprojx index 97399d9b..e5175817 100644 --- a/project/at_start_f407/examples/pwc/sleep_usart1/mdk_v5/sleep_usart1.uvprojx +++ b/project/at_start_f407/examples/pwc/sleep_usart1/mdk_v5/sleep_usart1.uvprojx @@ -10,7 +10,7 @@ sleep_usart1 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f407/examples/pwc/sleep_usart1/src/at32f403a_407_int.c b/project/at_start_f407/examples/pwc/sleep_usart1/src/at32f403a_407_int.c index 38df23f6..f6ccc7f4 100644 --- a/project/at_start_f407/examples/pwc/sleep_usart1/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/pwc/sleep_usart1/src/at32f403a_407_int.c @@ -141,7 +141,7 @@ void SysTick_Handler(void) */ void USART1_IRQHandler(void) { - if(usart_flag_get(USART1, USART_RDBF_FLAG) != RESET) + if(usart_interrupt_flag_get(USART1, USART_RDBF_FLAG) != RESET) { /* clear rdbf flag */ usart1_index = usart_data_receive(USART1); diff --git a/project/at_start_f407/examples/pwc/standby_rtc/mdk_v5/standby_rtc.uvprojx b/project/at_start_f407/examples/pwc/standby_rtc/mdk_v5/standby_rtc.uvprojx index bf7cb26c..67468adf 100644 --- a/project/at_start_f407/examples/pwc/standby_rtc/mdk_v5/standby_rtc.uvprojx +++ b/project/at_start_f407/examples/pwc/standby_rtc/mdk_v5/standby_rtc.uvprojx @@ -10,7 +10,7 @@ standby_rtc 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f407/examples/rtc/calendar/src/at32f403a_407_int.c b/project/at_start_f407/examples/rtc/calendar/src/at32f403a_407_int.c index 4f249519..c0660e61 100644 --- a/project/at_start_f407/examples/rtc/calendar/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/rtc/calendar/src/at32f403a_407_int.c @@ -139,7 +139,7 @@ void SysTick_Handler(void) */ void RTC_IRQHandler(void) { - if(rtc_flag_get(RTC_TA_FLAG) != RESET) + if(rtc_interrupt_flag_get(RTC_TA_FLAG) != RESET) { at32_led_toggle(LED4); diff --git a/project/at_start_f407/examples/rtc/lick_calibration/src/at32f403a_407_int.c b/project/at_start_f407/examples/rtc/lick_calibration/src/at32f403a_407_int.c index c4586c14..ccad2c4d 100644 --- a/project/at_start_f407/examples/rtc/lick_calibration/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/rtc/lick_calibration/src/at32f403a_407_int.c @@ -148,7 +148,7 @@ void SysTick_Handler(void) */ void RTC_IRQHandler(void) { - if(rtc_flag_get(RTC_TS_FLAG) != RESET) + if(rtc_interrupt_flag_get(RTC_TS_FLAG) != RESET) { /* toggle led3 */ at32_led_toggle(LED3); @@ -169,11 +169,11 @@ void TMR5_GLOBAL_IRQHandler(void) { uint32_t tmp = 0; - if(tmr_flag_get(TMR5, TMR_C4_FLAG) == SET) + if(tmr_interrupt_flag_get(TMR5, TMR_C4_FLAG) == SET) { tmpCC4[incrementvar_operationcomplete()] = (uint16_t)(TMR5->c4dt); - tmr_flag_get(TMR5, TMR_C4_FLAG); + tmr_interrupt_flag_get(TMR5, TMR_C4_FLAG); if(getvar_operationcomplete() >= 2) { diff --git a/project/at_start_f407/examples/sdio/sd_mmc_card/src/at32_sdio.c b/project/at_start_f407/examples/sdio/sd_mmc_card/src/at32_sdio.c index cfcdb21e..d3f6ccf7 100644 --- a/project/at_start_f407/examples/sdio/sd_mmc_card/src/at32_sdio.c +++ b/project/at_start_f407/examples/sdio/sd_mmc_card/src/at32_sdio.c @@ -99,11 +99,11 @@ sd_error_status_type sd_init(void) sdio_reset(SDIOx); /* power on */ status = sd_power_on(); - + if(status == SD_OK) break; } - + if(status == SD_OK) { /* sdio card initialize */ @@ -281,7 +281,7 @@ sd_error_status_type sd_power_on(void) while((!valid_voltage) && (count < SD_MAX_VOLT_TRIAL)) { delay_ms(10); - + /* send cmd55 before acmd41 */ sdio_command_init_struct.argument = 0x00; sdio_command_init_struct.cmd_index = SD_CMD_APP_CMD; @@ -348,7 +348,7 @@ sd_error_status_type sd_power_on(void) while((!valid_voltage) && (count < SD_MAX_VOLT_TRIAL)) { delay_ms(10); - + sdio_command_init_struct.argument = SD_VOLTAGE_WINDOW_MMC; sdio_command_init_struct.cmd_index = SD_CMD_SEND_OP_COND; sdio_command_init_struct.rsp_type = SDIO_RESPONSE_SHORT; @@ -1779,7 +1779,7 @@ void SDIO2_IRQHandler(void) */ sd_error_status_type sd_irq_service(void) { - if(sdio_flag_get(SDIOx, SDIO_DTCMPL_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_DTCMPL_FLAG) != RESET) { if(stop_flag == 1) { @@ -1804,7 +1804,7 @@ sd_error_status_type sd_irq_service(void) return transfer_error; } - if(sdio_flag_get(SDIOx, SDIO_DTFAIL_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_DTFAIL_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_DTFAIL_FLAG); @@ -1813,7 +1813,7 @@ sd_error_status_type sd_irq_service(void) return transfer_error; } - if(sdio_flag_get(SDIOx, SDIO_DTTIMEOUT_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_DTTIMEOUT_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_DTTIMEOUT_FLAG); @@ -1822,7 +1822,7 @@ sd_error_status_type sd_irq_service(void) return transfer_error; } - if(sdio_flag_get(SDIOx, SDIO_RXERRO_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_RXERRO_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_RXERRO_FLAG); @@ -1831,7 +1831,7 @@ sd_error_status_type sd_irq_service(void) return(SD_RX_OVERRUN); } - if(sdio_flag_get(SDIOx, SDIO_TXERRU_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_TXERRU_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_TXERRU_FLAG); @@ -1840,7 +1840,7 @@ sd_error_status_type sd_irq_service(void) return(SD_TX_UNDERRUN); } - if(sdio_flag_get(SDIOx, SDIO_SBITERR_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_SBITERR_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_SBITERR_FLAG); diff --git a/project/at_start_f407/examples/sdio/sdio_fatfs/src/at32_sdio.c b/project/at_start_f407/examples/sdio/sdio_fatfs/src/at32_sdio.c index 408c916f..27bbf6a5 100644 --- a/project/at_start_f407/examples/sdio/sdio_fatfs/src/at32_sdio.c +++ b/project/at_start_f407/examples/sdio/sdio_fatfs/src/at32_sdio.c @@ -100,11 +100,11 @@ sd_error_status_type sd_init(void) sdio_reset(SDIOx); /* power on */ status = sd_power_on(); - + if(status == SD_OK) break; } - + if(status == SD_OK) { /* sdio card initialize */ @@ -288,7 +288,7 @@ sd_error_status_type sd_power_on(void) while((!valid_voltage) && (count < SD_MAX_VOLT_TRIAL)) { delay_ms(10); - + /* send cmd55 before acmd41 */ sdio_command_init_struct.argument = 0x00; sdio_command_init_struct.cmd_index = SD_CMD_APP_CMD; @@ -355,7 +355,7 @@ sd_error_status_type sd_power_on(void) while((!valid_voltage) && (count < SD_MAX_VOLT_TRIAL)) { delay_ms(10); - + sdio_command_init_struct.argument = SD_VOLTAGE_WINDOW_MMC; sdio_command_init_struct.cmd_index = SD_CMD_SEND_OP_COND; sdio_command_init_struct.rsp_type = SDIO_RESPONSE_SHORT; @@ -1786,7 +1786,7 @@ void SDIO2_IRQHandler(void) */ sd_error_status_type sd_irq_service(void) { - if(sdio_flag_get(SDIOx, SDIO_DTCMPL_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_DTCMPL_FLAG) != RESET) { if(stop_flag == 1) { @@ -1811,7 +1811,7 @@ sd_error_status_type sd_irq_service(void) return transfer_error; } - if(sdio_flag_get(SDIOx, SDIO_DTFAIL_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_DTFAIL_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_DTFAIL_FLAG); @@ -1820,7 +1820,7 @@ sd_error_status_type sd_irq_service(void) return transfer_error; } - if(sdio_flag_get(SDIOx, SDIO_DTTIMEOUT_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_DTTIMEOUT_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_DTTIMEOUT_FLAG); @@ -1829,7 +1829,7 @@ sd_error_status_type sd_irq_service(void) return transfer_error; } - if(sdio_flag_get(SDIOx, SDIO_RXERRO_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_RXERRO_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_RXERRO_FLAG); @@ -1838,7 +1838,7 @@ sd_error_status_type sd_irq_service(void) return(SD_RX_OVERRUN); } - if(sdio_flag_get(SDIOx, SDIO_TXERRU_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_TXERRU_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_TXERRU_FLAG); @@ -1847,7 +1847,7 @@ sd_error_status_type sd_irq_service(void) return(SD_TX_UNDERRUN); } - if(sdio_flag_get(SDIOx, SDIO_SBITERR_FLAG) != RESET) + if(sdio_interrupt_flag_get(SDIOx, SDIO_SBITERR_FLAG) != RESET) { /* clear flag */ sdio_flag_clear(SDIOx, SDIO_SBITERR_FLAG); diff --git a/project/at_start_f407/examples/spi/halfduplex_interrupt/src/at32f403a_407_int.c b/project/at_start_f407/examples/spi/halfduplex_interrupt/src/at32f403a_407_int.c index 65d5b063..03889796 100644 --- a/project/at_start_f407/examples/spi/halfduplex_interrupt/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/spi/halfduplex_interrupt/src/at32f403a_407_int.c @@ -145,7 +145,7 @@ void SysTick_Handler(void) */ void SPI1_IRQHandler(void) { - if(spi_i2s_flag_get(SPI1, SPI_I2S_TDBE_FLAG) != RESET) + if(spi_i2s_interrupt_flag_get(SPI1, SPI_I2S_TDBE_FLAG) != RESET) { spi_i2s_data_transmit(SPI1, spi1_tx_buffer[tx_index++]); if(tx_index == BUFFERSIZE) @@ -162,7 +162,7 @@ void SysTick_Handler(void) */ void SPI2_I2S2EXT_IRQHandler(void) { - if(spi_i2s_flag_get(SPI2, SPI_I2S_RDBF_FLAG) != RESET) + if(spi_i2s_interrupt_flag_get(SPI2, SPI_I2S_RDBF_FLAG) != RESET) { spi2_rx_buffer[rx_index++] = spi_i2s_data_receive(SPI2); } diff --git a/project/at_start_f407/examples/spi/halfduplex_transceiver_switch/mdk_v5/halfduplex_transceiver_switch.uvprojx b/project/at_start_f407/examples/spi/halfduplex_transceiver_switch/mdk_v5/halfduplex_transceiver_switch.uvprojx index 037e59ed..e73b9bac 100644 --- a/project/at_start_f407/examples/spi/halfduplex_transceiver_switch/mdk_v5/halfduplex_transceiver_switch.uvprojx +++ b/project/at_start_f407/examples/spi/halfduplex_transceiver_switch/mdk_v5/halfduplex_transceiver_switch.uvprojx @@ -10,7 +10,7 @@ halfduplex_transceiver_switch 0x4 ARM-ADS - 5060750::V5.06 update 6 (build 750)::ARMCC + 5060750::V5.06 update 6 (build 750)::.\ARMCC 0 diff --git a/project/at_start_f407/examples/spi/halfduplex_transceiver_switch/src/at32f403a_407_int.c b/project/at_start_f407/examples/spi/halfduplex_transceiver_switch/src/at32f403a_407_int.c index 3cc6e71c..c91bc2cb 100644 --- a/project/at_start_f407/examples/spi/halfduplex_transceiver_switch/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/spi/halfduplex_transceiver_switch/src/at32f403a_407_int.c @@ -147,28 +147,22 @@ void SysTick_Handler(void) */ void SPI1_IRQHandler(void) { - if(SPI1->ctrl2_bit.tdbeie != RESET) + if(spi_i2s_interrupt_flag_get(SPI1, SPI_I2S_TDBE_FLAG) != RESET) { - if(spi_i2s_flag_get(SPI1, SPI_I2S_TDBE_FLAG) != RESET) + spi_i2s_data_transmit(SPI1, spi1_tx_buffer[tx_index++]); + if(tx_index == BUFFERSIZE) { - spi_i2s_data_transmit(SPI1, spi1_tx_buffer[tx_index++]); - if(tx_index == BUFFERSIZE) - { - spi_i2s_interrupt_enable(SPI1, SPI_I2S_TDBE_INT, FALSE); - } + spi_i2s_interrupt_enable(SPI1, SPI_I2S_TDBE_INT, FALSE); } } - if(SPI1->ctrl2_bit.rdbfie != RESET) + if(spi_i2s_interrupt_flag_get(SPI1, SPI_I2S_RDBF_FLAG) != RESET) { - if(spi_i2s_flag_get(SPI1, SPI_I2S_RDBF_FLAG) != RESET) + spi_enable(SPI1, FALSE); + spi1_rx_buffer[rx_index++] = spi_i2s_data_receive(SPI1); + spi_enable(SPI1, TRUE); + if(rx_index == BUFFERSIZE) { - spi_enable(SPI1, FALSE); - spi1_rx_buffer[rx_index++] = spi_i2s_data_receive(SPI1); - spi_enable(SPI1, TRUE); - if(rx_index == BUFFERSIZE) - { - spi_i2s_interrupt_enable(SPI1, SPI_I2S_RDBF_INT, FALSE); - } + spi_i2s_interrupt_enable(SPI1, SPI_I2S_RDBF_INT, FALSE); } } } @@ -180,23 +174,17 @@ void SysTick_Handler(void) */ void SPI2_I2S2EXT_IRQHandler(void) { - if(SPI2->ctrl2_bit.tdbeie != RESET) + if(spi_i2s_interrupt_flag_get(SPI2, SPI_I2S_TDBE_FLAG) != RESET) { - if(spi_i2s_flag_get(SPI2, SPI_I2S_TDBE_FLAG) != RESET) + spi_i2s_data_transmit(SPI2, spi2_tx_buffer[tx_index++]); + if(tx_index == BUFFERSIZE) { - spi_i2s_data_transmit(SPI2, spi2_tx_buffer[tx_index++]); - if(tx_index == BUFFERSIZE) - { - spi_i2s_interrupt_enable(SPI2, SPI_I2S_TDBE_INT, FALSE); - } + spi_i2s_interrupt_enable(SPI2, SPI_I2S_TDBE_INT, FALSE); } } - if(SPI2->ctrl2_bit.rdbfie != RESET) + if(spi_i2s_interrupt_flag_get(SPI2, SPI_I2S_RDBF_FLAG) != RESET) { - if(spi_i2s_flag_get(SPI2, SPI_I2S_RDBF_FLAG) != RESET) - { - spi2_rx_buffer[rx_index++] = spi_i2s_data_receive(SPI2); - } + spi2_rx_buffer[rx_index++] = spi_i2s_data_receive(SPI2); } } diff --git a/project/at_start_f407/examples/tmr/dma/src/main.c b/project/at_start_f407/examples/tmr/dma/src/main.c index c2de0cca..de4895aa 100644 --- a/project/at_start_f407/examples/tmr/dma/src/main.c +++ b/project/at_start_f407/examples/tmr/dma/src/main.c @@ -130,7 +130,7 @@ int main(void) dma_init_struct.memory_base_addr = (uint32_t)src_buffer; dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_HALFWORD; dma_init_struct.memory_inc_enable = TRUE; - dma_init_struct.peripheral_base_addr = (uint32_t)0x40012C3C; + dma_init_struct.peripheral_base_addr = (uint32_t)&TMR1->c3dt; dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_HALFWORD; dma_init_struct.peripheral_inc_enable = FALSE; dma_init_struct.priority = DMA_PRIORITY_MEDIUM; diff --git a/project/at_start_f407/examples/tmr/dma_burst/src/main.c b/project/at_start_f407/examples/tmr/dma_burst/src/main.c index f05a2ef1..8e609e93 100644 --- a/project/at_start_f407/examples/tmr/dma_burst/src/main.c +++ b/project/at_start_f407/examples/tmr/dma_burst/src/main.c @@ -111,7 +111,7 @@ int main(void) dma_init_struct.memory_base_addr = (uint32_t)src_buffer; dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_HALFWORD; dma_init_struct.memory_inc_enable = TRUE; - dma_init_struct.peripheral_base_addr = (uint32_t)0x40012C4C; + dma_init_struct.peripheral_base_addr = (uint32_t)&TMR1->dmadt; dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_HALFWORD; dma_init_struct.peripheral_inc_enable = FALSE; dma_init_struct.priority = DMA_PRIORITY_MEDIUM; diff --git a/project/at_start_f407/examples/tmr/hall_xor_tmr2/src/main.c b/project/at_start_f407/examples/tmr/hall_xor_tmr2/src/main.c index b4be5b36..1fe4766d 100644 --- a/project/at_start_f407/examples/tmr/hall_xor_tmr2/src/main.c +++ b/project/at_start_f407/examples/tmr/hall_xor_tmr2/src/main.c @@ -136,7 +136,7 @@ int main(void) */ void TMR2_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR2, TMR_TRIGGER_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR2, TMR_TRIGGER_FLAG) != RESET) { GPIOA->odt ^= GPIO_PINS_8; tmr_flag_clear(TMR2, TMR_TRIGGER_FLAG); diff --git a/project/at_start_f407/examples/tmr/input_capture/src/main.c b/project/at_start_f407/examples/tmr/input_capture/src/main.c index 86648db2..901d8de4 100644 --- a/project/at_start_f407/examples/tmr/input_capture/src/main.c +++ b/project/at_start_f407/examples/tmr/input_capture/src/main.c @@ -63,7 +63,7 @@ void delay(uint32_t time) */ void TMR3_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR3, TMR_C2_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR3, TMR_C2_FLAG) != RESET) { tmr_flag_clear(TMR3, TMR_C2_FLAG); if(capturenumber == 0) @@ -84,7 +84,7 @@ void TMR3_GLOBAL_IRQHandler(void) } else { - capture = ((0xFFFF - ic3readvalue1) + ic3readvalue2); + capture = ((0x10000 - ic3readvalue1) + ic3readvalue2); } /* frequency computation */ diff --git a/project/at_start_f407/examples/tmr/oc_high/src/at32f403a_407_int.c b/project/at_start_f407/examples/tmr/oc_high/src/at32f403a_407_int.c index 9d543fa5..14f42625 100644 --- a/project/at_start_f407/examples/tmr/oc_high/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/tmr/oc_high/src/at32f403a_407_int.c @@ -137,7 +137,7 @@ void SysTick_Handler(void) */ void TMR2_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR2, TMR_C1_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR2, TMR_C1_FLAG) != RESET) { /* clear tmr2 channel1 interrupt pending bit */ tmr_flag_clear(TMR2, TMR_C1_FLAG); @@ -145,7 +145,7 @@ void TMR2_GLOBAL_IRQHandler(void) /* pc.06 turnoff after 1000 ms */ gpio_bits_reset(GPIOC, GPIO_PINS_6); } - else if(tmr_flag_get(TMR2, TMR_C2_FLAG) != RESET) + else if(tmr_interrupt_flag_get(TMR2, TMR_C2_FLAG) != RESET) { /* clear tmr2 channel2 interrupt pending bit */ tmr_flag_clear(TMR2, TMR_C2_FLAG); @@ -153,7 +153,7 @@ void TMR2_GLOBAL_IRQHandler(void) /* pc.07 turnoff after 500 ms */ gpio_bits_reset(GPIOC, GPIO_PINS_7); } - else if(tmr_flag_get(TMR2, TMR_C3_FLAG) != RESET) + else if(tmr_interrupt_flag_get(TMR2, TMR_C3_FLAG) != RESET) { /* clear tmr2 channel3 interrupt pending bit */ tmr_flag_clear(TMR2, TMR_C3_FLAG); diff --git a/project/at_start_f407/examples/tmr/oc_low/src/at32f403a_407_int.c b/project/at_start_f407/examples/tmr/oc_low/src/at32f403a_407_int.c index a8ce7462..fefce812 100644 --- a/project/at_start_f407/examples/tmr/oc_low/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/tmr/oc_low/src/at32f403a_407_int.c @@ -137,7 +137,7 @@ void SysTick_Handler(void) */ void TMR2_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR2, TMR_C1_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR2, TMR_C1_FLAG) != RESET) { /* clear tmr2 channel1 interrupt pending bit */ tmr_flag_clear(TMR2, TMR_C1_FLAG); @@ -145,7 +145,7 @@ void TMR2_GLOBAL_IRQHandler(void) /* pc.06 turnoff after 1000 ms */ gpio_bits_reset(GPIOC, GPIO_PINS_6); } - else if(tmr_flag_get(TMR2, TMR_C2_FLAG) != RESET) + else if(tmr_interrupt_flag_get(TMR2, TMR_C2_FLAG) != RESET) { /* clear tmr2 channel2 interrupt pending bit */ tmr_flag_clear(TMR2, TMR_C2_FLAG); @@ -153,7 +153,7 @@ void TMR2_GLOBAL_IRQHandler(void) /* pc.07 turnoff after 500 ms */ gpio_bits_reset(GPIOC, GPIO_PINS_7); } - else if(tmr_flag_get(TMR2, TMR_C3_FLAG) != RESET) + else if(tmr_interrupt_flag_get(TMR2, TMR_C3_FLAG) != RESET) { /* clear tmr2 channel3 interrupt pending bit */ tmr_flag_clear(TMR2, TMR_C3_FLAG); diff --git a/project/at_start_f407/examples/tmr/oc_toggle_tmr3/src/at32f403a_407_int.c b/project/at_start_f407/examples/tmr/oc_toggle_tmr3/src/at32f403a_407_int.c index 6f028216..3d3a5aa8 100644 --- a/project/at_start_f407/examples/tmr/oc_toggle_tmr3/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/tmr/oc_toggle_tmr3/src/at32f403a_407_int.c @@ -145,7 +145,7 @@ void SysTick_Handler(void) void TMR3_GLOBAL_IRQHandler(void) { /* TMR3_CH1 toggling with frequency = 183.1 Hz */ - if(tmr_flag_get(TMR3, TMR_C1_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR3, TMR_C1_FLAG) != RESET) { tmr_flag_clear(TMR3, TMR_C1_FLAG ); capture = tmr_channel_value_get(TMR3, TMR_SELECT_CHANNEL_1); @@ -153,7 +153,7 @@ void TMR3_GLOBAL_IRQHandler(void) } /* TMR3_CH2 toggling with frequency = 366.2 Hz */ - if(tmr_flag_get(TMR3, TMR_C2_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR3, TMR_C2_FLAG) != RESET) { tmr_flag_clear(TMR3, TMR_C2_FLAG); capture = tmr_channel_value_get(TMR3, TMR_SELECT_CHANNEL_2); @@ -161,7 +161,7 @@ void TMR3_GLOBAL_IRQHandler(void) } /* TMR3_CH3 toggling with frequency = 732.4 Hz */ - if(tmr_flag_get(TMR3, TMR_C3_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR3, TMR_C3_FLAG) != RESET) { tmr_flag_clear(TMR3, TMR_C3_FLAG); capture = tmr_channel_value_get(TMR3, TMR_SELECT_CHANNEL_3); @@ -169,7 +169,7 @@ void TMR3_GLOBAL_IRQHandler(void) } /* TMR3_CH4 toggling with frequency = 1464.8 Hz */ - if(tmr_flag_get(TMR3, TMR_C4_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR3, TMR_C4_FLAG) != RESET) { tmr_flag_clear(TMR3, TMR_C4_FLAG); capture = tmr_channel_value_get(TMR3, TMR_SELECT_CHANNEL_4); diff --git a/project/at_start_f407/examples/tmr/oc_toggle_tmr9/src/at32f403a_407_int.c b/project/at_start_f407/examples/tmr/oc_toggle_tmr9/src/at32f403a_407_int.c index 2536421e..e00aba0a 100644 --- a/project/at_start_f407/examples/tmr/oc_toggle_tmr9/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/tmr/oc_toggle_tmr9/src/at32f403a_407_int.c @@ -143,7 +143,7 @@ void SysTick_Handler(void) void TMR1_BRK_TMR9_IRQHandler(void) { /* TMR9_CH1 toggling with frequency = 366.2 Hz */ - if(tmr_flag_get(TMR9, TMR_C1_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR9, TMR_C1_FLAG) != RESET) { tmr_flag_clear(TMR9, TMR_C1_FLAG ); capture = tmr_channel_value_get(TMR9, TMR_SELECT_CHANNEL_1); @@ -151,7 +151,7 @@ void TMR1_BRK_TMR9_IRQHandler(void) } /* TMR9_CH2 toggling with frequency = 732.4 Hz */ - if(tmr_flag_get(TMR9, TMR_C2_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR9, TMR_C2_FLAG) != RESET) { tmr_flag_clear(TMR9, TMR_C2_FLAG); capture = tmr_channel_value_get(TMR9, TMR_SELECT_CHANNEL_2); diff --git a/project/at_start_f407/examples/tmr/pwm_input_dma/src/main.c b/project/at_start_f407/examples/tmr/pwm_input_dma/src/main.c index 0f0fa461..16182b65 100644 --- a/project/at_start_f407/examples/tmr/pwm_input_dma/src/main.c +++ b/project/at_start_f407/examples/tmr/pwm_input_dma/src/main.c @@ -33,9 +33,6 @@ * @{ */ -#define TMR1_C1DT_ADDRESS 0x40012C34 -#define TMR1_C2DT_ADDRESS 0x40012C38 - #define SAMPLING_NUM 1000 tmr_input_config_type tmr_ic_init_structure; @@ -131,7 +128,7 @@ int main(void) dma_reset(DMA1_CHANNEL2); dma_default_para_init(&dma_init_structure); - dma_init_structure.peripheral_base_addr = (uint32_t)TMR1_C1DT_ADDRESS; + dma_init_structure.peripheral_base_addr = (uint32_t)&TMR1->c1dt; dma_init_structure.memory_base_addr = (uint32_t)buffer_cc1; dma_init_structure.direction = DMA_DIR_PERIPHERAL_TO_MEMORY; dma_init_structure.buffer_size = SAMPLING_NUM; @@ -144,7 +141,7 @@ int main(void) dma_init(DMA1_CHANNEL2, &dma_init_structure); dma_reset(DMA1_CHANNEL3); - dma_init_structure.peripheral_base_addr = (uint32_t)TMR1_C2DT_ADDRESS; + dma_init_structure.peripheral_base_addr = (uint32_t)&TMR1->c2dt; dma_init_structure.memory_base_addr = (uint32_t)buffer_cc2; dma_init(DMA1_CHANNEL3, &dma_init_structure); diff --git a/project/at_start_f407/examples/tmr/pwm_output_simulate/src/at32f403a_407_int.c b/project/at_start_f407/examples/tmr/pwm_output_simulate/src/at32f403a_407_int.c index 983ffa6a..54e72bc1 100644 --- a/project/at_start_f407/examples/tmr/pwm_output_simulate/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/tmr/pwm_output_simulate/src/at32f403a_407_int.c @@ -139,7 +139,7 @@ void SysTick_Handler(void) void TMR2_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR2, TMR_C1_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR2, TMR_C1_FLAG) != RESET) { tmr_flag_clear(TMR2, TMR_C1_FLAG ); @@ -148,7 +148,7 @@ void TMR2_GLOBAL_IRQHandler(void) capture = tmr_channel_value_get(TMR2, TMR_SELECT_CHANNEL_1); tmr_channel_value_set(TMR2, TMR_SELECT_CHANNEL_1, capture + ccr1_val); } - else if(tmr_flag_get(TMR2, TMR_C2_FLAG) != RESET) + else if(tmr_interrupt_flag_get(TMR2, TMR_C2_FLAG) != RESET) { tmr_flag_clear(TMR2, TMR_C2_FLAG); @@ -157,7 +157,7 @@ void TMR2_GLOBAL_IRQHandler(void) capture = tmr_channel_value_get(TMR2, TMR_SELECT_CHANNEL_2); tmr_channel_value_set(TMR2, TMR_SELECT_CHANNEL_2, capture + ccr2_val); } - else if(tmr_flag_get(TMR2, TMR_C3_FLAG) != RESET) + else if(tmr_interrupt_flag_get(TMR2, TMR_C3_FLAG) != RESET) { tmr_flag_clear(TMR2, TMR_C3_FLAG); diff --git a/project/at_start_f407/examples/tmr/timer_base/src/main.c b/project/at_start_f407/examples/tmr/timer_base/src/main.c index f9c8939f..6a4d03ba 100644 --- a/project/at_start_f407/examples/tmr/timer_base/src/main.c +++ b/project/at_start_f407/examples/tmr/timer_base/src/main.c @@ -67,7 +67,7 @@ void clkout_config(void) */ void TMR1_OVF_TMR10_IRQHandler(void) { - if(tmr_flag_get(TMR1, TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR1, TMR_OVF_FLAG) != RESET) { /* add user code... */ at32_led_toggle(LED3); diff --git a/project/at_start_f407/examples/usart/idle_detection/src/at32f403a_407_int.c b/project/at_start_f407/examples/usart/idle_detection/src/at32f403a_407_int.c index 79dc9e43..d08b712e 100644 --- a/project/at_start_f407/examples/usart/idle_detection/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/usart/idle_detection/src/at32f403a_407_int.c @@ -138,7 +138,7 @@ void SysTick_Handler(void) */ void USART2_IRQHandler(void) { - if(usart_flag_get(USART2, USART_IDLEF_FLAG)) + if(usart_interrupt_flag_get(USART2, USART_IDLEF_FLAG)) { usart_data_receive(USART2); at32_led_on(LED2); diff --git a/project/at_start_f407/examples/usart/interrupt/src/at32f403a_407_int.c b/project/at_start_f407/examples/usart/interrupt/src/at32f403a_407_int.c index 909f7e7f..623caef7 100644 --- a/project/at_start_f407/examples/usart/interrupt/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/usart/interrupt/src/at32f403a_407_int.c @@ -148,33 +148,27 @@ void SysTick_Handler(void) */ void USART2_IRQHandler(void) { - if(USART2->ctrl1_bit.rdbfien != RESET) + if(usart_interrupt_flag_get(USART2, USART_RDBF_FLAG) != RESET) { - if(usart_flag_get(USART2, USART_RDBF_FLAG) != RESET) - { - /* read one byte from the receive data register */ - usart2_rx_buffer[usart2_rx_counter++] = usart_data_receive(USART2); + /* read one byte from the receive data register */ + usart2_rx_buffer[usart2_rx_counter++] = usart_data_receive(USART2); - if(usart2_rx_counter == usart3_tx_buffer_size) - { - /* disable the usart2 receive interrupt */ - usart_interrupt_enable(USART2, USART_RDBF_INT, FALSE); - } + if(usart2_rx_counter == usart3_tx_buffer_size) + { + /* disable the usart2 receive interrupt */ + usart_interrupt_enable(USART2, USART_RDBF_INT, FALSE); } } - - if(USART2->ctrl1_bit.tdbeien != RESET) - { - if(usart_flag_get(USART2, USART_TDBE_FLAG) != RESET) - { - /* write one byte to the transmit data register */ - usart_data_transmit(USART2, usart2_tx_buffer[usart2_tx_counter++]); - if(usart2_tx_counter == usart2_tx_buffer_size) - { - /* disable the usart2 transmit interrupt */ - usart_interrupt_enable(USART2, USART_TDBE_INT, FALSE); - } + if(usart_interrupt_flag_get(USART2, USART_TDBE_FLAG) != RESET) + { + /* write one byte to the transmit data register */ + usart_data_transmit(USART2, usart2_tx_buffer[usart2_tx_counter++]); + + if(usart2_tx_counter == usart2_tx_buffer_size) + { + /* disable the usart2 transmit interrupt */ + usart_interrupt_enable(USART2, USART_TDBE_INT, FALSE); } } } @@ -186,33 +180,27 @@ void USART2_IRQHandler(void) */ void USART3_IRQHandler(void) { - if(USART3->ctrl1_bit.rdbfien != RESET) + if(usart_interrupt_flag_get(USART3, USART_RDBF_FLAG) != RESET) { - if(usart_flag_get(USART3, USART_RDBF_FLAG) != RESET) - { - /* read one byte from the receive data register */ - usart3_rx_buffer[usart3_rx_counter++] = usart_data_receive(USART3); + /* read one byte from the receive data register */ + usart3_rx_buffer[usart3_rx_counter++] = usart_data_receive(USART3); - if(usart3_rx_counter == usart2_tx_buffer_size) - { - /* disable the usart3 receive interrupt */ - usart_interrupt_enable(USART3, USART_RDBF_INT, FALSE); - } + if(usart3_rx_counter == usart2_tx_buffer_size) + { + /* disable the usart3 receive interrupt */ + usart_interrupt_enable(USART3, USART_RDBF_INT, FALSE); } } - - if(USART3->ctrl1_bit.tdbeien != RESET) - { - if(usart_flag_get(USART3, USART_TDBE_FLAG) != RESET) - { - /* write one byte to the transmit data register */ - usart_data_transmit(USART3, usart3_tx_buffer[usart3_tx_counter++]); - if(usart3_tx_counter == usart3_tx_buffer_size) - { - /* disable the usart3 transmit interrupt */ - usart_interrupt_enable(USART3, USART_TDBE_INT, FALSE); - } + if(usart_interrupt_flag_get(USART3, USART_TDBE_FLAG) != RESET) + { + /* write one byte to the transmit data register */ + usart_data_transmit(USART3, usart3_tx_buffer[usart3_tx_counter++]); + + if(usart3_tx_counter == usart3_tx_buffer_size) + { + /* disable the usart3 transmit interrupt */ + usart_interrupt_enable(USART3, USART_TDBE_INT, FALSE); } } } diff --git a/project/at_start_f407/examples/usart/receiver_mute/src/at32f403a_407_int.c b/project/at_start_f407/examples/usart/receiver_mute/src/at32f403a_407_int.c index 8648ea6e..c5778d6b 100644 --- a/project/at_start_f407/examples/usart/receiver_mute/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/usart/receiver_mute/src/at32f403a_407_int.c @@ -140,7 +140,7 @@ void SysTick_Handler(void) */ void USART3_IRQHandler(void) { - if(usart_flag_get(USART3, USART_RDBF_FLAG) != RESET) + if(usart_interrupt_flag_get(USART3, USART_RDBF_FLAG) != RESET) { usart3_rx_buffer[rx_counter++] = usart_data_receive(USART3); } diff --git a/project/at_start_f407/examples/usart/rs485/src/main.c b/project/at_start_f407/examples/usart/rs485/src/main.c index f0485439..0855c453 100644 --- a/project/at_start_f407/examples/usart/rs485/src/main.c +++ b/project/at_start_f407/examples/usart/rs485/src/main.c @@ -5,11 +5,11 @@ ************************************************************************** * 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 + * 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, @@ -37,7 +37,7 @@ #define RS485_BUFFER_SIZE 128 uint8_t rs485_buffer_rx[RS485_BUFFER_SIZE]; -uint8_t rs485_buffer_rx_cnt = 0; +uint8_t rs485_buffer_rx_cnt = 0; /** * @brief rs485 configiguration. @@ -61,29 +61,29 @@ static void rs485_config(void) gpio_init_struct.gpio_pins = GPIO_PINS_2; gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init(GPIOA, &gpio_init_struct); - + gpio_init_struct.gpio_pins = GPIO_PINS_3; gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; gpio_init_struct.gpio_pull = GPIO_PULL_UP; gpio_init(GPIOA, &gpio_init_struct); - + gpio_init_struct.gpio_pins = GPIO_PINS_1; gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init(GPIOA, &gpio_init_struct); - + gpio_bits_reset(GPIOA, GPIO_PINS_1); - + /* configure uart2 param */ usart_init(USART2, RS485_BAUDRATE, USART_DATA_8BITS, USART_STOP_1_BIT); - + usart_flag_clear(USART2, USART_RDBF_FLAG); usart_interrupt_enable(USART2, USART_RDBF_INT, TRUE); - + usart_receiver_enable(USART2, TRUE); usart_transmitter_enable(USART2, TRUE); usart_enable(USART2, TRUE); - + nvic_irq_enable(USART2_IRQn, 1, 0); } @@ -113,13 +113,13 @@ int main(void) { char str[]="start test..\r\n"; u8 len = 0; - + system_clock_config(); at32_board_init(); nvic_priority_group_config(NVIC_PRIORITY_GROUP_4); - + rs485_config(); - + len = sizeof(str); rs485_send_data((u8*)str, len); while(1) @@ -131,7 +131,7 @@ int main(void) rs485_send_data(rs485_buffer_rx, rs485_buffer_rx_cnt); rs485_buffer_rx_cnt = 0; usart_interrupt_enable(USART2, USART_RDBF_INT, TRUE); - } + } } } @@ -143,8 +143,8 @@ int main(void) void USART2_IRQHandler(void) { uint16_t tmp; - - if(usart_flag_get(USART2, USART_RDBF_FLAG) != RESET) + + if(usart_interrupt_flag_get(USART2, USART_RDBF_FLAG) != RESET) { tmp = usart_data_receive(USART2); if(rs485_buffer_rx_cnt < RS485_BUFFER_SIZE) @@ -156,8 +156,8 @@ void USART2_IRQHandler(void) /** * @} - */ + */ /** * @} - */ + */ diff --git a/project/at_start_f407/examples/usart/smartcard/src/at32f403a_407_int.c b/project/at_start_f407/examples/usart/smartcard/src/at32f403a_407_int.c index 2abe6bfb..f74c4dbc 100644 --- a/project/at_start_f407/examples/usart/smartcard/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/usart/smartcard/src/at32f403a_407_int.c @@ -164,7 +164,7 @@ void EXINT9_5_IRQHandler(void) void SC_USART_IRQHandler(void) { /* if the sc_usart detects a parity error */ - if(usart_flag_get(SC_USART, USART_PERR_FLAG) != RESET) + if(usart_interrupt_flag_get(SC_USART, USART_PERR_FLAG) != RESET) { /* enable sc_usart rdbf interrupt (until receiving the corrupted byte) */ usart_interrupt_enable(SC_USART, USART_RDBF_INT, TRUE); @@ -172,7 +172,7 @@ void SC_USART_IRQHandler(void) usart_data_receive(SC_USART); } - if(usart_flag_get(SC_USART, USART_RDBF_FLAG) != RESET) + if(usart_interrupt_flag_get(SC_USART, USART_RDBF_FLAG) != RESET) { /* disable sc_usart rdbf interrupt */ usart_interrupt_enable(SC_USART, USART_RDBF_INT, FALSE); diff --git a/project/at_start_f407/examples/usart/transfer_by_dma_interrupt/src/at32f403a_407_int.c b/project/at_start_f407/examples/usart/transfer_by_dma_interrupt/src/at32f403a_407_int.c index 98cbb6f7..871f7778 100644 --- a/project/at_start_f407/examples/usart/transfer_by_dma_interrupt/src/at32f403a_407_int.c +++ b/project/at_start_f407/examples/usart/transfer_by_dma_interrupt/src/at32f403a_407_int.c @@ -142,7 +142,7 @@ void SysTick_Handler(void) */ void DMA1_Channel1_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT1_FLAG)) + if(dma_interrupt_flag_get(DMA1_FDT1_FLAG)) { usart2_tx_dma_status = 1; dma_flag_clear(DMA1_FDT1_FLAG); @@ -157,7 +157,7 @@ void DMA1_Channel1_IRQHandler(void) */ void DMA1_Channel2_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT2_FLAG)) + if(dma_interrupt_flag_get(DMA1_FDT2_FLAG)) { usart2_rx_dma_status = 1; dma_flag_clear(DMA1_FDT2_FLAG); @@ -172,7 +172,7 @@ void DMA1_Channel2_IRQHandler(void) */ void DMA1_Channel3_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT3_FLAG)) + if(dma_interrupt_flag_get(DMA1_FDT3_FLAG)) { usart3_tx_dma_status = 1; dma_flag_clear(DMA1_FDT3_FLAG); @@ -187,7 +187,7 @@ void DMA1_Channel3_IRQHandler(void) */ void DMA1_Channel4_IRQHandler(void) { - if(dma_flag_get(DMA1_FDT4_FLAG)) + if(dma_interrupt_flag_get(DMA1_FDT4_FLAG)) { usart3_rx_dma_status = 1; dma_flag_clear(DMA1_FDT4_FLAG); diff --git a/project/at_start_f407/examples/usb_device/audio/src/audio_codec.c b/project/at_start_f407/examples/usb_device/audio/src/audio_codec.c index 02391e8d..d3b9295b 100644 --- a/project/at_start_f407/examples/usb_device/audio/src/audio_codec.c +++ b/project/at_start_f407/examples/usb_device/audio/src/audio_codec.c @@ -205,6 +205,10 @@ void audio_codec_set_mic_volume(uint16_t volume) { /* wm8988 adc have 256 steps */ audio_codec.mic_volume = volume; + if(audio_codec.mic_volume > 0xFF) + { + audio_codec.mic_volume = 0xFF; + } } /** @@ -649,13 +653,13 @@ void DMA1_Channel3_IRQHandler(void) uint16_t half_size = audio_codec.spk_tx_size; uint16_t *pdst; - if(dma_flag_get(DMA1_HDT3_FLAG) == SET) + if(dma_interrupt_flag_get(DMA1_HDT3_FLAG) == SET) { //copy_buff(audio_codec.spk_buffer, audio_codec.spk_tx_fifo + audio_codec.r_pos, half_size); pdst = spk_dma_buffer; dma_flag_clear(DMA1_HDT3_FLAG); } - else if(dma_flag_get(DMA1_FDT3_FLAG) == SET) + else if(dma_interrupt_flag_get(DMA1_FDT3_FLAG) == SET) { //copy_buff(&audio_codec.spk_buffer[half_size], audio_codec.spk_tx_fifo + audio_codec.r_pos, half_size); pdst = spk_dma_buffer + half_size; @@ -724,12 +728,12 @@ void DMA1_Channel4_IRQHandler(void) uint16_t *psrc; uint16_t len = audio_codec.mic_rx_size << 1; - if(dma_flag_get(DMA1_HDT4_FLAG) == SET) + if(dma_interrupt_flag_get(DMA1_HDT4_FLAG) == SET) { dma_flag_clear(DMA1_HDT4_FLAG); psrc = mic_dma_buffer; } - else if(dma_flag_get(DMA1_FDT4_FLAG) == SET) + else if(dma_interrupt_flag_get(DMA1_FDT4_FLAG) == SET) { psrc = mic_dma_buffer + audio_codec.mic_rx_size; dma_flag_clear(DMA1_FDT4_FLAG); @@ -947,7 +951,3 @@ error_status audio_codec_loop(void) /** * @} */ - - - - diff --git a/project/at_start_f407/examples/usb_device/composite_audio_hid/src/audio_codec.c b/project/at_start_f407/examples/usb_device/composite_audio_hid/src/audio_codec.c index 5d75c4a7..6555493f 100644 --- a/project/at_start_f407/examples/usb_device/composite_audio_hid/src/audio_codec.c +++ b/project/at_start_f407/examples/usb_device/composite_audio_hid/src/audio_codec.c @@ -205,6 +205,10 @@ void audio_codec_set_mic_volume(uint16_t volume) { /* wm8988 adc have 256 steps */ audio_codec.mic_volume = volume; + if(audio_codec.mic_volume > 0xFF) + { + audio_codec.mic_volume = 0xFF; + } } /** @@ -651,13 +655,13 @@ void DMA1_Channel3_IRQHandler(void) uint16_t half_size = audio_codec.spk_tx_size; uint16_t *pdst; - if(dma_flag_get(DMA1_HDT3_FLAG) == SET) + if(dma_interrupt_flag_get(DMA1_HDT3_FLAG) == SET) { //copy_buff(audio_codec.spk_buffer, audio_codec.spk_tx_fifo + audio_codec.r_pos, half_size); pdst = spk_dma_buffer; dma_flag_clear(DMA1_HDT3_FLAG); } - else if(dma_flag_get(DMA1_FDT3_FLAG) == SET) + else if(dma_interrupt_flag_get(DMA1_FDT3_FLAG) == SET) { //copy_buff(&audio_codec.spk_buffer[half_size], audio_codec.spk_tx_fifo + audio_codec.r_pos, half_size); pdst = spk_dma_buffer + half_size; @@ -726,12 +730,12 @@ void DMA1_Channel4_IRQHandler(void) uint16_t *psrc; uint16_t len = audio_codec.mic_rx_size << 1; - if(dma_flag_get(DMA1_HDT4_FLAG) == SET) + if(dma_interrupt_flag_get(DMA1_HDT4_FLAG) == SET) { dma_flag_clear(DMA1_HDT4_FLAG); psrc = mic_dma_buffer; } - else if(dma_flag_get(DMA1_FDT4_FLAG) == SET) + else if(dma_interrupt_flag_get(DMA1_FDT4_FLAG) == SET) { psrc = mic_dma_buffer + audio_codec.mic_rx_size; dma_flag_clear(DMA1_FDT4_FLAG); @@ -949,7 +953,3 @@ error_status audio_codec_loop(void) /** * @} */ - - - - diff --git a/project/at_start_f407/examples/usb_device/virtual_comport/src/main.c b/project/at_start_f407/examples/usb_device/virtual_comport/src/main.c index cb1ff234..c370e683 100644 --- a/project/at_start_f407/examples/usb_device/virtual_comport/src/main.c +++ b/project/at_start_f407/examples/usb_device/virtual_comport/src/main.c @@ -281,7 +281,7 @@ uint16_t usart_receive_data(void) */ void USART2_IRQHandler(void) { - if(usart_flag_get(USART2, USART_RDBF_FLAG) != RESET) + if(usart_interrupt_flag_get(USART2, USART_RDBF_FLAG) != RESET) { /* read one byte from the receive data register */ usart_rx_buffer[hw_usart_rx_index] = usart_data_receive(USART2); @@ -320,7 +320,7 @@ void usb_usart_config( linecoding_type linecoding) default : break; } - + /* parity */ switch(linecoding.parity) { @@ -340,7 +340,7 @@ void usb_usart_config( linecoding_type linecoding) default : break; } - + if(USART_PARITY_NONE == usart_parity_select) { /* data bits */ @@ -359,7 +359,7 @@ void usb_usart_config( linecoding_type linecoding) break; default : break; - } + } } else { @@ -381,7 +381,7 @@ void usb_usart_config( linecoding_type linecoding) break; default : break; - } + } } nvic_irq_enable(USART2_IRQn, 0, 0); diff --git a/project/at_start_f407/examples/usb_device/winusb/inc/at32f403a_407_clock.h b/project/at_start_f407/examples/usb_device/winusb/inc/at32f403a_407_clock.h new file mode 100644 index 00000000..20f803ab --- /dev/null +++ b/project/at_start_f407/examples/usb_device/winusb/inc/at32f403a_407_clock.h @@ -0,0 +1,44 @@ +/** + ************************************************************************** + * @file at32f403a_407_clock.h + * @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 __AT32F403A_407_CLOCK_H +#define __AT32F403A_407_CLOCK_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* includes ------------------------------------------------------------------*/ +#include "at32f403a_407.h" + +/* exported functions ------------------------------------------------------- */ +void system_clock_config(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __AT32F403A_407_CLOCK_H */ + diff --git a/project/at_start_f407/examples/usb_device/winusb/inc/at32f403a_407_conf.h b/project/at_start_f407/examples/usb_device/winusb/inc/at32f403a_407_conf.h new file mode 100644 index 00000000..4608566d --- /dev/null +++ b/project/at_start_f407/examples/usb_device/winusb/inc/at32f403a_407_conf.h @@ -0,0 +1,162 @@ +/** + ************************************************************************** + * @file at32f403a_407_conf.h + * @brief at32f403a_407 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 __AT32F403A_407_CONF_H +#define __AT32F403A_407_CONF_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @brief in the following line adjust the value of high speed external 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 external crystal in hz */ +#endif + +/** + * @brief in the following line adjust the high speed external crystal (hext) startup + * timeout value + */ +#define HEXT_STARTUP_TIMEOUT ((uint16_t)0x3000) /*!< time out for hext start up */ +#define HICK_VALUE ((uint32_t)8000000) /*!< value of the high speed internal clock in hz */ +#define LEXT_VALUE ((uint32_t)32768) /*!< value of the low speed external clock in hz */ + +/* module define -------------------------------------------------------------*/ +#define CRM_MODULE_ENABLED +#define TMR_MODULE_ENABLED +#define RTC_MODULE_ENABLED +#define BPR_MODULE_ENABLED +#define GPIO_MODULE_ENABLED +#define I2C_MODULE_ENABLED +#define USART_MODULE_ENABLED +#define PWC_MODULE_ENABLED +#define CAN_MODULE_ENABLED +#define ADC_MODULE_ENABLED +#define DAC_MODULE_ENABLED +#define SPI_MODULE_ENABLED +#define DMA_MODULE_ENABLED +#define DEBUG_MODULE_ENABLED +#define FLASH_MODULE_ENABLED +#define CRC_MODULE_ENABLED +#define WWDT_MODULE_ENABLED +#define WDT_MODULE_ENABLED +#define EXINT_MODULE_ENABLED +#define SDIO_MODULE_ENABLED +#define XMC_MODULE_ENABLED +#define USB_MODULE_ENABLED +#define ACC_MODULE_ENABLED +#define MISC_MODULE_ENABLED +#define EMAC_MODULE_ENABLED + +/* includes ------------------------------------------------------------------*/ +#ifdef CRM_MODULE_ENABLED +#include "at32f403a_407_crm.h" +#endif +#ifdef TMR_MODULE_ENABLED +#include "at32f403a_407_tmr.h" +#endif +#ifdef RTC_MODULE_ENABLED +#include "at32f403a_407_rtc.h" +#endif +#ifdef BPR_MODULE_ENABLED +#include "at32f403a_407_bpr.h" +#endif +#ifdef GPIO_MODULE_ENABLED +#include "at32f403a_407_gpio.h" +#endif +#ifdef I2C_MODULE_ENABLED +#include "at32f403a_407_i2c.h" +#endif +#ifdef USART_MODULE_ENABLED +#include "at32f403a_407_usart.h" +#endif +#ifdef PWC_MODULE_ENABLED +#include "at32f403a_407_pwc.h" +#endif +#ifdef CAN_MODULE_ENABLED +#include "at32f403a_407_can.h" +#endif +#ifdef ADC_MODULE_ENABLED +#include "at32f403a_407_adc.h" +#endif +#ifdef DAC_MODULE_ENABLED +#include "at32f403a_407_dac.h" +#endif +#ifdef SPI_MODULE_ENABLED +#include "at32f403a_407_spi.h" +#endif +#ifdef DMA_MODULE_ENABLED +#include "at32f403a_407_dma.h" +#endif +#ifdef DEBUG_MODULE_ENABLED +#include "at32f403a_407_debug.h" +#endif +#ifdef FLASH_MODULE_ENABLED +#include "at32f403a_407_flash.h" +#endif +#ifdef CRC_MODULE_ENABLED +#include "at32f403a_407_crc.h" +#endif +#ifdef WWDT_MODULE_ENABLED +#include "at32f403a_407_wwdt.h" +#endif +#ifdef WDT_MODULE_ENABLED +#include "at32f403a_407_wdt.h" +#endif +#ifdef EXINT_MODULE_ENABLED +#include "at32f403a_407_exint.h" +#endif +#ifdef SDIO_MODULE_ENABLED +#include "at32f403a_407_sdio.h" +#endif +#ifdef XMC_MODULE_ENABLED +#include "at32f403a_407_xmc.h" +#endif +#ifdef ACC_MODULE_ENABLED +#include "at32f403a_407_acc.h" +#endif +#ifdef MISC_MODULE_ENABLED +#include "at32f403a_407_misc.h" +#endif +#ifdef USB_MODULE_ENABLED +#include "at32f403a_407_usb.h" +#endif +#ifdef EMAC_MODULE_ENABLED +#include "at32f403a_407_emac.h" +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/project/at_start_f407/examples/usb_device/winusb/inc/at32f403a_407_int.h b/project/at_start_f407/examples/usb_device/winusb/inc/at32f403a_407_int.h new file mode 100644 index 00000000..0685ab3c --- /dev/null +++ b/project/at_start_f407/examples/usb_device/winusb/inc/at32f403a_407_int.h @@ -0,0 +1,56 @@ +/** + ************************************************************************** + * @file at32f403a_407_int.h + * @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 __AT32F403A_407_INT_H +#define __AT32F403A_407_INT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* includes ------------------------------------------------------------------*/ +#include "at32f403a_407.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/project/at_start_f407/examples/usb_device/winusb/inc/usb_conf.h b/project/at_start_f407/examples/usb_device/winusb/inc/usb_conf.h new file mode 100644 index 00000000..ab76505b --- /dev/null +++ b/project/at_start_f407/examples/usb_device/winusb/inc/usb_conf.h @@ -0,0 +1,119 @@ +/** + ************************************************************************** + * @file usb_conf.h + * @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 "at32f403a_407.h" +#include "at32f403a_407_board.h" +#include "stdio.h" + +/** @addtogroup AT32F407_periph_examples + * @{ + */ + +/** @addtogroup 407_USB_device_winusb + * @{ + */ + +/** + * @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 buffer extend to 768-1280 bytes + */ +//#define USB_BUFFER_SIZE_EX /*!< usb enable extend buffer */ + + +/** + * @brief auto malloc usb endpoint buffer + */ +//#define USB_EPT_AUTO_MALLOC_BUFFER /*!< usb auto malloc endpoint tx and rx buffer */ + + +#ifndef USB_EPT_AUTO_MALLOC_BUFFER +/** + * @brief user custom endpoint buffer + * EPTn_TX_ADDR, EPTn_RX_ADDR must less than usb buffer size + */ + +/* ept0 tx start address 0x40, size 0x40, + so rx start address is 0x40 + 0x40 = 0x80 */ +#define EPT0_TX_ADDR 0x40 /*!< usb endpoint 0 tx buffer address offset */ +#define EPT0_RX_ADDR 0x80 /*!< usb endpoint 0 rx buffer address offset */ + +#define EPT1_TX_ADDR 0xC0 /*!< usb endpoint 1 tx buffer address offset */ +#define EPT1_RX_ADDR 0x100 /*!< usb endpoint 1 rx buffer address offset */ + +#define EPT2_TX_ADDR 0x140 /*!< usb endpoint 2 tx buffer address offset */ +#define EPT2_RX_ADDR 0x180 /*!< usb endpoint 2 rx buffer address offset */ + +#define EPT3_TX_ADDR 0x00 /*!< usb endpoint 3 tx buffer address offset */ +#define EPT3_RX_ADDR 0x00 /*!< usb endpoint 3 rx buffer address offset */ + +#define EPT4_TX_ADDR 0x00 /*!< usb endpoint 4 tx buffer address offset */ +#define EPT4_RX_ADDR 0x00 /*!< usb endpoint 4 rx buffer address offset */ + +#define EPT5_TX_ADDR 0x00 /*!< usb endpoint 5 tx buffer address offset */ +#define EPT5_RX_ADDR 0x00 /*!< usb endpoint 5 rx buffer address offset */ + +#define EPT6_TX_ADDR 0x00 /*!< usb endpoint 6 tx buffer address offset */ +#define EPT6_RX_ADDR 0x00 /*!< usb endpoint 6 rx buffer address offset */ + +#define EPT7_TX_ADDR 0x00 /*!< usb endpoint 7 tx buffer address offset */ +#define EPT7_RX_ADDR 0x00 /*!< usb endpoint 7 rx buffer address offset */ + +#endif + +/** + * @brief support winusb + */ +#define USBD_SUPPORT_WINUSB 1 + +void usb_delay_ms(uint32_t ms); +void usb_delay_us(uint32_t us); + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/project/at_start_f407/examples/usb_device/winusb/mdk_v5/winusb.uvoptx b/project/at_start_f407/examples/usb_device/winusb/mdk_v5/winusb.uvoptx new file mode 100644 index 00000000..0681b453 --- /dev/null +++ b/project/at_start_f407/examples/usb_device/winusb/mdk_v5/winusb.uvoptx @@ -0,0 +1,672 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj; *.o + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + 0 + + + + 0 + 0 + + + + winusb + 0x4 + ARM-ADS + + 12000000 + + 0 + 1 + 0 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\listings\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + + + + + + + + + + + BIN\CMSIS_AGDI.dll + + + + 0 + UL2CM3 + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0AT32F407_1024 -FS08000000 -FL0100000 -FP0($$Device:-AT32F407VGT7$Flash\AT32F407_1024.FLM)) + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + 0 + 0 + 0 + + + + + + + + + + + + + user + 0 + 0 + 0 + 0 + + 1 + 1 + 1 + 0 + 0 + 0 + ..\src\at32f403a_407_clock.c + at32f403a_407_clock.c + 0 + 0 + + + 1 + 2 + 1 + 0 + 0 + 0 + ..\src\at32f403a_407_int.c + at32f403a_407_int.c + 0 + 0 + + + 1 + 3 + 1 + 0 + 0 + 0 + ..\src\main.c + main.c + 0 + 0 + + + + + bsp + 0 + 0 + 0 + 0 + + 2 + 4 + 1 + 0 + 0 + 0 + ..\..\..\..\..\at32f403a_407_board\at32f403a_407_board.c + at32f403a_407_board.c + 0 + 0 + + + + + firmware + 0 + 0 + 0 + 0 + + 3 + 5 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_acc.c + at32f403a_407_acc.c + 0 + 0 + + + 3 + 6 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_adc.c + at32f403a_407_adc.c + 0 + 0 + + + 3 + 7 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_bpr.c + at32f403a_407_bpr.c + 0 + 0 + + + 3 + 8 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_can.c + at32f403a_407_can.c + 0 + 0 + + + 3 + 9 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_crc.c + at32f403a_407_crc.c + 0 + 0 + + + 3 + 10 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_crm.c + at32f403a_407_crm.c + 0 + 0 + + + 3 + 11 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_dac.c + at32f403a_407_dac.c + 0 + 0 + + + 3 + 12 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_debug.c + at32f403a_407_debug.c + 0 + 0 + + + 3 + 13 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_dma.c + at32f403a_407_dma.c + 0 + 0 + + + 3 + 14 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_emac.c + at32f403a_407_emac.c + 0 + 0 + + + 3 + 15 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_exint.c + at32f403a_407_exint.c + 0 + 0 + + + 3 + 16 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_flash.c + at32f403a_407_flash.c + 0 + 0 + + + 3 + 17 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_gpio.c + at32f403a_407_gpio.c + 0 + 0 + + + 3 + 18 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_i2c.c + at32f403a_407_i2c.c + 0 + 0 + + + 3 + 19 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_misc.c + at32f403a_407_misc.c + 0 + 0 + + + 3 + 20 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_pwc.c + at32f403a_407_pwc.c + 0 + 0 + + + 3 + 21 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_rtc.c + at32f403a_407_rtc.c + 0 + 0 + + + 3 + 22 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_sdio.c + at32f403a_407_sdio.c + 0 + 0 + + + 3 + 23 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_spi.c + at32f403a_407_spi.c + 0 + 0 + + + 3 + 24 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_tmr.c + at32f403a_407_tmr.c + 0 + 0 + + + 3 + 25 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_usart.c + at32f403a_407_usart.c + 0 + 0 + + + 3 + 26 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_usb.c + at32f403a_407_usb.c + 0 + 0 + + + 3 + 27 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_wdt.c + at32f403a_407_wdt.c + 0 + 0 + + + 3 + 28 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_wwdt.c + at32f403a_407_wwdt.c + 0 + 0 + + + 3 + 29 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_xmc.c + at32f403a_407_xmc.c + 0 + 0 + + + + + cmsis + 0 + 0 + 0 + 0 + + 4 + 30 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\cmsis\cm4\device_support\system_at32f403a_407.c + system_at32f403a_407.c + 0 + 0 + + + 4 + 31 + 2 + 0 + 0 + 0 + ..\..\..\..\..\..\libraries\cmsis\cm4\device_support\startup\mdk\startup_at32f403a_407.s + startup_at32f403a_407.s + 0 + 0 + + + + + usbd_drivers + 0 + 0 + 0 + 0 + + 5 + 32 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\usbd_drivers\src\usbd_core.c + usbd_core.c + 0 + 0 + + + 5 + 33 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\usbd_drivers\src\usbd_int.c + usbd_int.c + 0 + 0 + + + 5 + 34 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\usbd_drivers\src\usbd_sdr.c + usbd_sdr.c + 0 + 0 + + + + + usbd_class + 0 + 0 + 0 + 0 + + 6 + 35 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\usbd_class\winusb\winusb_class.c + winusb_class.c + 0 + 0 + + + 6 + 36 + 1 + 0 + 0 + 0 + ..\..\..\..\..\..\middlewares\usbd_class\winusb\winusb_desc.c + winusb_desc.c + 0 + 0 + + + + + readme + 0 + 0 + 0 + 0 + + 7 + 37 + 5 + 0 + 0 + 0 + ..\readme.txt + readme.txt + 0 + 0 + + + +
diff --git a/project/at_start_f407/examples/usb_device/winusb/mdk_v5/winusb.uvprojx b/project/at_start_f407/examples/usb_device/winusb/mdk_v5/winusb.uvprojx new file mode 100644 index 00000000..0ddb90c7 --- /dev/null +++ b/project/at_start_f407/examples/usb_device/winusb/mdk_v5/winusb.uvprojx @@ -0,0 +1,627 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + winusb + 0x4 + ARM-ADS + 5060960::V5.06 update 7 (build 960)::.\ARMCC + 0 + + + -AT32F407VGT7 + ArteryTek + ArteryTek.AT32F403A_407_DFP.2.0.2 + IRAM(0x20000000,0x38000) IROM(0x08000000,0x100000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0AT32F407_1024 -FS08000000 -FL0100000 -FP0($$Device:-AT32F407VGT7$Flash\AT32F407_1024.FLM)) + 0 + $$Device:-AT32F407VGT7$Device\Include\at32f40x.h + + + + + + + + + + $$Device:-AT32F407VGT7$SVD\AT32F407xx_v2.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\objects\ + winusb + 1 + 0 + 1 + 1 + 1 + .\listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 0 + + + SARMCM3.DLL + -REMAP -MPU + DCM.DLL + -pCM4 + SARMCM3.DLL + -MPU + TCM.DLL + -pCM4 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4096 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M4" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 8 + 0 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x38000 + + + 1 + 0x8000000 + 0x100000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x8000000 + 0x100000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x38000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + AT32F407VGT7,USE_STDPERIPH_DRIVER,AT_START_F407_V1 + + ..\inc;..\..\..\..\..\at32f403a_407_board;..\..\..\..\..\..\libraries\drivers\inc;..\..\..\..\..\..\libraries\cmsis\cm4\core_support;..\..\..\..\..\..\libraries\cmsis\cm4\device_support;..\..\..\..\..\..\middlewares\usbd_drivers\inc;..\..\..\..\..\..\middlewares\usbd_class\winusb + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4 + + + + + + + + + 1 + 0 + 0 + 0 + 1 + 0 + 0x08000000 + 0x20000000 + + + + + + + + + + + + + user + + + at32f403a_407_clock.c + 1 + ..\src\at32f403a_407_clock.c + + + at32f403a_407_int.c + 1 + ..\src\at32f403a_407_int.c + + + main.c + 1 + ..\src\main.c + + + + + bsp + + + at32f403a_407_board.c + 1 + ..\..\..\..\..\at32f403a_407_board\at32f403a_407_board.c + + + + + firmware + + + at32f403a_407_acc.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_acc.c + + + at32f403a_407_adc.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_adc.c + + + at32f403a_407_bpr.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_bpr.c + + + at32f403a_407_can.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_can.c + + + at32f403a_407_crc.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_crc.c + + + at32f403a_407_crm.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_crm.c + + + at32f403a_407_dac.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_dac.c + + + at32f403a_407_debug.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_debug.c + + + at32f403a_407_dma.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_dma.c + + + at32f403a_407_emac.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_emac.c + + + at32f403a_407_exint.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_exint.c + + + at32f403a_407_flash.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_flash.c + + + at32f403a_407_gpio.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_gpio.c + + + at32f403a_407_i2c.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_i2c.c + + + at32f403a_407_misc.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_misc.c + + + at32f403a_407_pwc.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_pwc.c + + + at32f403a_407_rtc.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_rtc.c + + + at32f403a_407_sdio.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_sdio.c + + + at32f403a_407_spi.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_spi.c + + + at32f403a_407_tmr.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_tmr.c + + + at32f403a_407_usart.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_usart.c + + + at32f403a_407_usb.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_usb.c + + + at32f403a_407_wdt.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_wdt.c + + + at32f403a_407_wwdt.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_wwdt.c + + + at32f403a_407_xmc.c + 1 + ..\..\..\..\..\..\libraries\drivers\src\at32f403a_407_xmc.c + + + + + cmsis + + + system_at32f403a_407.c + 1 + ..\..\..\..\..\..\libraries\cmsis\cm4\device_support\system_at32f403a_407.c + + + startup_at32f403a_407.s + 2 + ..\..\..\..\..\..\libraries\cmsis\cm4\device_support\startup\mdk\startup_at32f403a_407.s + + + + + usbd_drivers + + + usbd_core.c + 1 + ..\..\..\..\..\..\middlewares\usbd_drivers\src\usbd_core.c + + + usbd_int.c + 1 + ..\..\..\..\..\..\middlewares\usbd_drivers\src\usbd_int.c + + + usbd_sdr.c + 1 + ..\..\..\..\..\..\middlewares\usbd_drivers\src\usbd_sdr.c + + + + + usbd_class + + + winusb_class.c + 1 + ..\..\..\..\..\..\middlewares\usbd_class\winusb\winusb_class.c + + + winusb_desc.c + 1 + ..\..\..\..\..\..\middlewares\usbd_class\winusb\winusb_desc.c + + + + + readme + + + readme.txt + 5 + ..\readme.txt + + + + + + + + + + + + + + + + + <Project Info> + + + + + + 0 + 1 + + + + +
diff --git a/project/at_start_f407/examples/usb_device/winusb/readme.txt b/project/at_start_f407/examples/usb_device/winusb/readme.txt new file mode 100644 index 00000000..32a4ffd6 --- /dev/null +++ b/project/at_start_f407/examples/usb_device/winusb/readme.txt @@ -0,0 +1,10 @@ +/** + ************************************************************************** + * @file readme.txt + * @brief readme + ************************************************************************** + */ + + this demo is based on the at-start board, in this demo, show how to build + a device of winusb. + for more detailed information, please refer to the application note document AN0097. diff --git a/project/at_start_f407/examples/usb_device/winusb/src/at32f403a_407_clock.c b/project/at_start_f407/examples/usb_device/winusb/src/at32f403a_407_clock.c new file mode 100644 index 00000000..3310724f --- /dev/null +++ b/project/at_start_f407/examples/usb_device/winusb/src/at32f403a_407_clock.c @@ -0,0 +1,98 @@ +/** + ************************************************************************** + * @file at32f403a_407_clock.c + * @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 "at32f403a_407_clock.h" + +/** + * @brief system clock config program + * @note the system clock is configured as follow: + * system clock (sclk) = hext / 2 * pll_mult + * system clock source = pll (hext) + * - hext = HEXT_VALUE + * - sclk = 192000000 + * - ahbdiv = 1 + * - ahbclk = 192000000 + * - apb2div = 2 + * - apb2clk = 96000000 + * - apb1div = 2 + * - apb1clk = 96000000 + * - pll_mult = 48 + * - pll_range = GT72MHZ (greater than 72 mhz) + * @param none + * @retval none + */ +void system_clock_config(void) +{ + /* 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_DIV, CRM_PLL_MULT_48, CRM_PLL_OUTPUT_RANGE_GT72MHZ); + + /* config hext division */ + crm_hext_clock_div_set(CRM_HEXT_DIV_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, the maximum frequency of APB1/APB2 clock is 120 MHz */ + crm_apb2_div_set(CRM_APB2_DIV_2); + + /* config apb1clk, the maximum frequency of APB1/APB2 clock is 120 MHz */ + 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/project/at_start_f407/examples/usb_device/winusb/src/at32f403a_407_int.c b/project/at_start_f407/examples/usb_device/winusb/src/at32f403a_407_int.c new file mode 100644 index 00000000..fbdcaa8b --- /dev/null +++ b/project/at_start_f407/examples/usb_device/winusb/src/at32f403a_407_int.c @@ -0,0 +1,141 @@ +/** + ************************************************************************** + * @file at32f403a_407_int.c + * @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 "at32f403a_407_int.h" + +/** @addtogroup AT32F407_periph_examples + * @{ + */ + +/** @addtogroup 407_USB_device_winusb + * @{ + */ + +/** + * @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/project/at_start_f407/examples/usb_device/winusb/src/main.c b/project/at_start_f407/examples/usb_device/winusb/src/main.c new file mode 100644 index 00000000..ba5a28e1 --- /dev/null +++ b/project/at_start_f407/examples/usb_device/winusb/src/main.c @@ -0,0 +1,207 @@ +/** + ************************************************************************** + * @file main.c + * @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 "at32f403a_407_board.h" +#include "at32f403a_407_clock.h" +#include "usbd_core.h" +#include "winusb_class.h" +#include "winusb_desc.h" +#include "usbd_int.h" + +/** @addtogroup AT32F407_periph_examples + * @{ + */ + +/** @addtogroup 407_USB_device_winusb USB_device_winusb + * @{ + */ + +usbd_core_type usb_core_dev; +uint8_t usb_buffer[256]; + +/** + * @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); + + /* 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; + + default: + break; + + } + } +} + +/** + * @brief main function. + * @param none + * @retval none + */ +int main(void) +{ + uint16_t data_len; + + uint32_t timeout; + + /* config nvic priority group */ + nvic_priority_group_config(NVIC_PRIORITY_GROUP_4); + + system_clock_config(); + + at32_board_init(); + + /* select usb 48m clcok source */ + usb_clock48m_select(USB_CLK_HEXT); + + /* enable usb clock */ + crm_periph_clock_enable(CRM_USB_PERIPH_CLOCK, TRUE); + + /* enable usb interrupt */ + nvic_irq_enable(USBFS_L_CAN1_RX0_IRQn, 0, 0); + + /* usb core init */ + usbd_core_init(&usb_core_dev, USB, &winusb_class_handler, &winusb_desc_handler, 0); + + /* enable usb pull-up */ + usbd_connect(&usb_core_dev); + + while(1) + { + /* get usb winusb receive data */ + data_len = usb_winusb_get_rxdata(&usb_core_dev, usb_buffer); + + if(data_len > 0) + { + + /* 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 + */ + timeout = 5000000; + do + { + /* send data to host */ + if(usb_winusb_send_data(&usb_core_dev, usb_buffer, data_len) == SUCCESS) + { + break; + } + }while(timeout --); + } + } +} + + +/** + * @brief this function handles usb interrupt. + * @param none + * @retval none + */ +void USBFS_L_CAN1_RX0_IRQHandler(void) +{ + usbd_irq_handler(&usb_core_dev); +} + +/** + * @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/utilities/at32f403a_407_usart_iap_demo/source_code/app_led3_toggle/src/tmr.c b/utilities/at32f403a_407_usart_iap_demo/source_code/app_led3_toggle/src/tmr.c index 45868b06..60f2e97a 100644 --- a/utilities/at32f403a_407_usart_iap_demo/source_code/app_led3_toggle/src/tmr.c +++ b/utilities/at32f403a_407_usart_iap_demo/source_code/app_led3_toggle/src/tmr.c @@ -69,7 +69,7 @@ void tmr_init(void) */ void TMR3_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR3, TMR_OVF_FLAG) == SET) + if(tmr_interrupt_flag_get(TMR3, TMR_OVF_FLAG) == SET) { tmr_flag_clear(TMR3, TMR_OVF_FLAG); at32_led_toggle(LED3); diff --git a/utilities/at32f403a_407_usart_iap_demo/source_code/app_led3_toggle/src/usart.c b/utilities/at32f403a_407_usart_iap_demo/source_code/app_led3_toggle/src/usart.c index 5a00b7be..ab68e8a6 100644 --- a/utilities/at32f403a_407_usart_iap_demo/source_code/app_led3_toggle/src/usart.c +++ b/utilities/at32f403a_407_usart_iap_demo/source_code/app_led3_toggle/src/usart.c @@ -85,7 +85,7 @@ void uart_init(uint32_t baudrate) void USART1_IRQHandler(void) { uint16_t reval; - if(usart_flag_get(USART1, USART_RDBF_FLAG) != RESET) + if(usart_interrupt_flag_get(USART1, USART_RDBF_FLAG) != RESET) { reval = usart_data_receive(USART1); if((reval == 0x5A) && (iap_flag == IAP_REV_FLAG_NO)) diff --git a/utilities/at32f403a_407_usart_iap_demo/source_code/app_led4_toggle/src/tmr.c b/utilities/at32f403a_407_usart_iap_demo/source_code/app_led4_toggle/src/tmr.c index 0122ccc2..896ff19d 100644 --- a/utilities/at32f403a_407_usart_iap_demo/source_code/app_led4_toggle/src/tmr.c +++ b/utilities/at32f403a_407_usart_iap_demo/source_code/app_led4_toggle/src/tmr.c @@ -69,7 +69,7 @@ void tmr_init(void) */ void TMR3_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR3, TMR_OVF_FLAG) == SET) + if(tmr_interrupt_flag_get(TMR3, TMR_OVF_FLAG) == SET) { tmr_flag_clear(TMR3, TMR_OVF_FLAG); at32_led_toggle(LED4); diff --git a/utilities/at32f403a_407_usart_iap_demo/source_code/app_led4_toggle/src/usart.c b/utilities/at32f403a_407_usart_iap_demo/source_code/app_led4_toggle/src/usart.c index da113ec7..28a14767 100644 --- a/utilities/at32f403a_407_usart_iap_demo/source_code/app_led4_toggle/src/usart.c +++ b/utilities/at32f403a_407_usart_iap_demo/source_code/app_led4_toggle/src/usart.c @@ -85,7 +85,7 @@ void uart_init(uint32_t baudrate) void USART1_IRQHandler(void) { uint16_t reval; - if(usart_flag_get(USART1, USART_RDBF_FLAG) != RESET) + if(usart_interrupt_flag_get(USART1, USART_RDBF_FLAG) != RESET) { reval = usart_data_receive(USART1); if((reval == 0x5A) && (iap_flag == IAP_REV_FLAG_NO)) diff --git a/utilities/at32f403a_407_usart_iap_demo/source_code/bootloader/src/iap.c b/utilities/at32f403a_407_usart_iap_demo/source_code/bootloader/src/iap.c index eb6a8877..0802f4a5 100644 --- a/utilities/at32f403a_407_usart_iap_demo/source_code/bootloader/src/iap.c +++ b/utilities/at32f403a_407_usart_iap_demo/source_code/bootloader/src/iap.c @@ -48,7 +48,10 @@ iapfun jump_to_app; #pragma O0 #elif defined (__ICCARM__) #pragma optimize=s none +#elif defined (__GNUC__) +__attribute__((optimize("O0"))) #endif + /** * @brief app load. * @param app_addr diff --git a/utilities/at32f403a_407_usart_iap_demo/source_code/bootloader/src/tmr.c b/utilities/at32f403a_407_usart_iap_demo/source_code/bootloader/src/tmr.c index 2c75561d..a1dec080 100644 --- a/utilities/at32f403a_407_usart_iap_demo/source_code/bootloader/src/tmr.c +++ b/utilities/at32f403a_407_usart_iap_demo/source_code/bootloader/src/tmr.c @@ -72,7 +72,7 @@ void tmr_init(void) */ void TMR3_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR3, TMR_OVF_FLAG) == SET) + if(tmr_interrupt_flag_get(TMR3, TMR_OVF_FLAG) == SET) { tmr_flag_clear(TMR3, TMR_OVF_FLAG); at32_led_toggle(LED2); diff --git a/utilities/at32f403a_407_usart_iap_demo/source_code/bootloader/src/usart.c b/utilities/at32f403a_407_usart_iap_demo/source_code/bootloader/src/usart.c index a2fd6da6..d780b259 100644 --- a/utilities/at32f403a_407_usart_iap_demo/source_code/bootloader/src/usart.c +++ b/utilities/at32f403a_407_usart_iap_demo/source_code/bootloader/src/usart.c @@ -86,7 +86,7 @@ void USART1_IRQHandler(void) { uint16_t reval; time_ira_cnt = 0; /* clear upgrade time out flag */ - if(usart_flag_get(USART1, USART_RDBF_FLAG) != RESET) + if(usart_interrupt_flag_get(USART1, USART_RDBF_FLAG) != RESET) { reval = usart_data_receive(USART1); if(usart_group_struct.count > (USART_REC_LEN - 1)) diff --git a/utilities/at32f403a_407_usb_iap_demo/source_code/bootloader/src/hid_iap_user.c b/utilities/at32f403a_407_usb_iap_demo/source_code/bootloader/src/hid_iap_user.c index f19b4afe..c538cee7 100644 --- a/utilities/at32f403a_407_usb_iap_demo/source_code/bootloader/src/hid_iap_user.c +++ b/utilities/at32f403a_407_usb_iap_demo/source_code/bootloader/src/hid_iap_user.c @@ -47,6 +47,15 @@ iap_result_type iap_data_write(uint8_t *pdata, uint32_t len); void iap_jump(void); void iap_respond(uint8_t *res_buf, uint16_t iap_cmd, uint16_t result); +/* app_load don't optimize */ +#if defined (__CC_ARM) + #pragma O0 +#elif defined (__ICCARM__) + #pragma optimize=s none +#elif defined (__GNUC__) +__attribute__((optimize("O0"))) +#endif + /** * @brief jump to app * @param none diff --git a/utilities/at32f407_emac_iap_demo/source_code/app_led3_toggle/src/at32f403a_407_int.c b/utilities/at32f407_emac_iap_demo/source_code/app_led3_toggle/src/at32f403a_407_int.c index 73763601..f3a84e0c 100644 --- a/utilities/at32f407_emac_iap_demo/source_code/app_led3_toggle/src/at32f403a_407_int.c +++ b/utilities/at32f407_emac_iap_demo/source_code/app_led3_toggle/src/at32f403a_407_int.c @@ -138,7 +138,7 @@ void SysTick_Handler(void) */ void TMR6_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR6, TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR6, TMR_OVF_FLAG) != RESET) { /* Update the local_time by adding SYSTEMTICK_PERIOD_MS each SysTick interrupt */ time_update(); diff --git a/utilities/at32f407_emac_iap_demo/source_code/app_led3_toggle/src/tmr.c b/utilities/at32f407_emac_iap_demo/source_code/app_led3_toggle/src/tmr.c index 100c44e2..65316c1c 100644 --- a/utilities/at32f407_emac_iap_demo/source_code/app_led3_toggle/src/tmr.c +++ b/utilities/at32f407_emac_iap_demo/source_code/app_led3_toggle/src/tmr.c @@ -70,7 +70,7 @@ void tmr_init(void) */ void TMR3_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR3, TMR_OVF_FLAG) == SET) + if(tmr_interrupt_flag_get(TMR3, TMR_OVF_FLAG) == SET) { tmr_flag_clear(TMR3, TMR_OVF_FLAG); at32_led_toggle(LED3); diff --git a/utilities/at32f407_emac_iap_demo/source_code/bootloader/src/at32f403a_407_int.c b/utilities/at32f407_emac_iap_demo/source_code/bootloader/src/at32f403a_407_int.c index 6d6d8b6e..786f96d1 100644 --- a/utilities/at32f407_emac_iap_demo/source_code/bootloader/src/at32f403a_407_int.c +++ b/utilities/at32f407_emac_iap_demo/source_code/bootloader/src/at32f403a_407_int.c @@ -138,7 +138,7 @@ void SysTick_Handler(void) */ void TMR6_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR6, TMR_OVF_FLAG) != RESET) + if(tmr_interrupt_flag_get(TMR6, TMR_OVF_FLAG) != RESET) { /* Update the local_time by adding SYSTEMTICK_PERIOD_MS each SysTick interrupt */ time_update(); diff --git a/utilities/at32f407_emac_iap_demo/source_code/bootloader/src/iap.c b/utilities/at32f407_emac_iap_demo/source_code/bootloader/src/iap.c index 5a5586e1..e08d988a 100644 --- a/utilities/at32f407_emac_iap_demo/source_code/bootloader/src/iap.c +++ b/utilities/at32f407_emac_iap_demo/source_code/bootloader/src/iap.c @@ -43,7 +43,10 @@ iapfun jump_to_app; #pragma O0 #elif defined (__ICCARM__) #pragma optimize=s none +#elif defined (__GNUC__) +__attribute__((optimize("O0"))) #endif + /** * @brief app load. * @param app_addr diff --git a/utilities/at32f407_emac_iap_demo/source_code/bootloader/src/tmr.c b/utilities/at32f407_emac_iap_demo/source_code/bootloader/src/tmr.c index c1a5f549..dbbc6fc4 100644 --- a/utilities/at32f407_emac_iap_demo/source_code/bootloader/src/tmr.c +++ b/utilities/at32f407_emac_iap_demo/source_code/bootloader/src/tmr.c @@ -70,7 +70,7 @@ void tmr_init(void) */ void TMR3_GLOBAL_IRQHandler(void) { - if(tmr_flag_get(TMR3, TMR_OVF_FLAG) == SET) + if(tmr_interrupt_flag_get(TMR3, TMR_OVF_FLAG) == SET) { tmr_flag_clear(TMR3, TMR_OVF_FLAG); at32_led_toggle(LED2);