123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- /**
- ******************************************************************************
- * @file at32_msp.c
- * @author Artery Technology
- * @version V1.0.1
- * @date 2021-02-09
- * @brief Msp source file
- ******************************************************************************
- * @attention
- *
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
- * TIME. AS A RESULT, ARTERYTEK SHALL NOT BE HELD LIABLE FOR ANY
- * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
- * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
- * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *
- * <h2><center>© COPYRIGHT 2018 ArteryTek</center></h2>
- ******************************************************************************
- */
- #include <at32f4xx.h>
- #include <rtthread.h>
- #include "at32_msp.h"
- #ifdef BSP_USING_UART
- void at32_msp_usart_init(void *Instance)
- {
- GPIO_InitType GPIO_InitStruct;
- USART_Type *USARTx = (USART_Type *)Instance;
- GPIO_StructInit(&GPIO_InitStruct);
- GPIO_InitStruct.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
- #ifdef BSP_USING_UART1
- if(USART1 == USARTx)
- {
- RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_USART1, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOA, ENABLE);
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_9;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_10;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
- }
- #endif
- #ifdef BSP_USING_UART2
- if(USART2 == USARTx)
- {
- RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_USART2, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOA, ENABLE);
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_2;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_3;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
- }
- #endif
- #ifdef BSP_USING_UART3
- if(USART3 == USARTx)
- {
- RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_USART3, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOB, ENABLE);
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_10;
- GPIO_Init(GPIOB, &GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_11;
- GPIO_Init(GPIOB, &GPIO_InitStruct);
- }
- #endif
- /* Add others */
- }
- #endif /* BSP_USING_SERIAL */
- #ifdef BSP_USING_SPI
- void at32_msp_spi_init(void *Instance)
- {
- GPIO_InitType GPIO_InitStruct;
- SPI_Type *SPIx = (SPI_Type *)Instance;
- GPIO_StructInit(&GPIO_InitStruct);
- GPIO_InitStruct.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
- #ifdef BSP_USING_SPI1
- if(SPI1 == SPIx)
- {
- RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_SPI1, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOA, ENABLE);
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT_PP;
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_4;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_5 | GPIO_Pins_7;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_6;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
- }
- #endif
- #ifdef BSP_USING_SPI2
- if(SPI2 == SPIx)
- {
- RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_SPI2, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOB, ENABLE);
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT_PP;
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_12;
- GPIO_Init(GPIOB, &GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_13 | GPIO_Pins_15;
- GPIO_Init(GPIOB, &GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_14;
- GPIO_Init(GPIOB, &GPIO_InitStruct);
- }
- #endif
- /* Add others */
- }
- #endif /* BSP_USING_SPI */
- #ifdef BSP_USING_SDIO
- void at32_msp_sdio_init(void *Instance)
- {
- GPIO_InitType GPIO_InitStructure;
- SDIO_Type *SDIOx = (SDIO_Type *)Instance;
- GPIO_StructInit(&GPIO_InitStructure);
- GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
- if(SDIO1 == SDIOx)
- {
- /* if used dma ... */
- RCC_AHBPeriphClockCmd(RCC_AHBPERIPH_DMA2, ENABLE);
- RCC_AHBPeriphClockCmd(RCC_AHBPERIPH_SDIO1, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOC | RCC_APB2PERIPH_GPIOD, ENABLE);
- GPIO_InitStructure.GPIO_Pins = GPIO_Pins_8 | GPIO_Pins_9 | GPIO_Pins_10 | GPIO_Pins_11 | GPIO_Pins_12;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pins = GPIO_Pins_2;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- }
- }
- #endif /* BSP_USING_SDIO */
- #ifdef BSP_USING_PWM
- void at32_msp_tmr_init(void *Instance)
- {
- GPIO_InitType GPIO_InitStructure;
- TMR_Type *TMRx = (TMR_Type *)Instance;
- if(TMRx == TMR1)
- {
- /* TMR1 clock enable */
- RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_TMR1, ENABLE);
- /* GPIOA clock enable */
- RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOA, ENABLE);
- /* GPIOA Configuration:TMR1 Channel1 and Channel4 as alternate function push-pull */
- GPIO_InitStructure.GPIO_Pins = GPIO_Pins_8 | GPIO_Pins_11;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- }
- if(TMRx == TMR2)
- {
- /* TMR2 clock enable */
- RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_TMR2, ENABLE);
- /* GPIOA clock enable */
- RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOA, ENABLE);
- /* GPIOA Configuration:TMR2 Channel1 and Channel2 as alternate function push-pull */
- GPIO_InitStructure.GPIO_Pins = GPIO_Pins_0 | GPIO_Pins_1;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- }
- /* Add others */
- }
- #endif /* BSP_USING_PWM */
- #ifdef BSP_USING_ADC
- void at32_msp_adc_init(void *Instance)
- {
- GPIO_InitType GPIO_InitStruct;
- ADC_Type *ADCx = (ADC_Type *)Instance;
- #ifdef BSP_USING_ADC1
- if(ADCx == ADC1)
- {
- /* ADC1 & GPIO clock enable */
- RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_ADC1 | RCC_APB2PERIPH_GPIOA | RCC_APB2PERIPH_GPIOB | RCC_APB2PERIPH_GPIOC,ENABLE);
-
- /* Configure ADC Channel as analog input */
- GPIO_StructInit(&GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_0 | GPIO_Pins_1 | GPIO_Pins_2 | GPIO_Pins_3 | GPIO_Pins_4 | GPIO_Pins_5;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_ANALOG;
- GPIO_Init(GPIOC, &GPIO_InitStruct);
-
- }
- #endif
- #ifdef BSP_USING_ADC2
- if(ADCx == ADC2)
- {
- /* ADC2 & GPIO clock enable */
- RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_ADC2 | RCC_APB2PERIPH_GPIOA | RCC_APB2PERIPH_GPIOB | RCC_APB2PERIPH_GPIOC,ENABLE);
-
- /* Configure ADC Channel as analog input */
- GPIO_StructInit(&GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_0 | GPIO_Pins_1 | GPIO_Pins_2 | GPIO_Pins_3 | GPIO_Pins_4 | GPIO_Pins_5;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_ANALOG;
- GPIO_Init(GPIOC, &GPIO_InitStruct);
- }
- #endif
- }
- #endif /* BSP_USING_ADC */
- #ifdef BSP_USING_HWTIMER
- void at32_msp_hwtmr_init(void *Instance)
- {
- TMR_Type *TMRx = (TMR_Type *)Instance;
- #ifdef BSP_USING_HWTMR3
- if(TMRx == TMR3)
- {
- /* TMR3 clock enable */
- RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_TMR3, ENABLE);
- }
- #endif
- #ifdef BSP_USING_HWTMR4
- if(TMRx == TMR4)
- {
- /* TMR4 clock enable */
- RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_TMR4, ENABLE);
- }
- #endif
- #ifdef BSP_USING_HWTMR5
- if(TMRx == TMR5)
- {
- /* TMR5 clock enable */
- RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_TMR5, ENABLE);
- }
- #endif
- }
- #endif
- #ifdef BSP_USING_CAN
- void at32_msp_can_init(void *Instance)
- {
- GPIO_InitType GPIO_InitStruct;
- CAN_Type *CANx = (CAN_Type *)Instance;
- GPIO_StructInit(&GPIO_InitStruct);
- GPIO_InitStruct.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
- #ifdef BSP_USING_CAN1
- if(CAN1 == CANx)
- {
- RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_CAN1, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOA, ENABLE);
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_12;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_11;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
- }
- #endif
- #ifdef BSP_USING_CAN2
- if(CAN2 == CANx)
- {
- RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_CAN2, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_AFIO, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOB, ENABLE);
- GPIO_PinsRemapConfig(AFIO_MAP6_CAN2_0001, ENABLE);
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_6;
- GPIO_Init(GPIOB, &GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStruct.GPIO_Pins = GPIO_Pins_5;
- GPIO_Init(GPIOB, &GPIO_InitStruct);
- }
- #endif
- }
- #endif /* BSP_USING_CAN */
|