本文整理匯總了C++中GPIO_PinRemapConfig函數的典型用法代碼示例。如果您正苦於以下問題:C++ GPIO_PinRemapConfig函數的具體用法?C++ GPIO_PinRemapConfig怎麽用?C++ GPIO_PinRemapConfig使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GPIO_PinRemapConfig函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: PIOS_USART_Init
/**
* Initialise a single USART device
*/
int32_t PIOS_USART_Init(uint32_t * usart_id, const struct pios_usart_cfg * cfg)
{
PIOS_DEBUG_Assert(usart_id);
PIOS_DEBUG_Assert(cfg);
struct pios_usart_dev * usart_dev;
usart_dev = (struct pios_usart_dev *) PIOS_USART_alloc();
if (!usart_dev) goto out_fail;
/* Bind the configuration to the device instance */
usart_dev->cfg = cfg;
/* Clear buffer counters */
fifoBuf_init(&usart_dev->rx, usart_dev->rx_buffer, sizeof(usart_dev->rx_buffer));
fifoBuf_init(&usart_dev->tx, usart_dev->tx_buffer, sizeof(usart_dev->tx_buffer));
/* Enable the USART Pins Software Remapping */
if (usart_dev->cfg->remap) {
GPIO_PinRemapConfig(usart_dev->cfg->remap, ENABLE);
}
/* Initialize the USART Rx and Tx pins */
GPIO_Init(usart_dev->cfg->rx.gpio, &usart_dev->cfg->rx.init);
GPIO_Init(usart_dev->cfg->tx.gpio, &usart_dev->cfg->tx.init);
/* Enable USART clock */
switch ((uint32_t)usart_dev->cfg->regs) {
case (uint32_t)USART1:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
break;
case (uint32_t)USART2:
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
break;
case (uint32_t)USART3:
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
break;
}
/* Configure the USART */
USART_Init(usart_dev->cfg->regs, &usart_dev->cfg->init);
*usart_id = (uint32_t)usart_dev;
/* Configure USART Interrupts */
NVIC_Init(&usart_dev->cfg->irq.init);
USART_ITConfig(usart_dev->cfg->regs, USART_IT_RXNE, ENABLE);
USART_ITConfig(usart_dev->cfg->regs, USART_IT_TXE, ENABLE);
/* Enable USART */
USART_Cmd(usart_dev->cfg->regs, ENABLE);
return(0);
out_fail:
return(-1);
}
示例2: systemInit
void systemInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
uint8_t i;
gpio_config_t gpio_cfg[] = {
{ LED0_GPIO, LED0_PIN, GPIO_Mode_Out_PP }, // PB3 (LED)
{ LED1_GPIO, LED1_PIN, GPIO_Mode_Out_PP }, // PB4 (LED)
#ifndef FY90Q
{ BEEP_GPIO, BEEP_PIN, GPIO_Mode_Out_OD }, // PA12 (Buzzer)
#endif
};
uint8_t gpio_count = sizeof(gpio_cfg) / sizeof(gpio_cfg[0]);
// Turn on clocks for stuff we use
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4 | RCC_APB1Periph_I2C2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_TIM1 | RCC_APB2Periph_ADC1 | RCC_APB2Periph_USART1, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
RCC_ClearFlag();
// Make all GPIO in by default to save power and reduce noise
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_Init(GPIOC, &GPIO_InitStructure);
// Turn off JTAG port 'cause we're using the GPIO for leds
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
// Configure gpio
for (i = 0; i < gpio_count; i++) {
GPIO_InitStructure.GPIO_Pin = gpio_cfg[i].pin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = gpio_cfg[i].mode;
GPIO_Init(gpio_cfg[i].gpio, &GPIO_InitStructure);
}
LED0_OFF;
LED1_OFF;
BEEP_OFF;
// Init cycle counter
cycleCounterInit();
// SysTick
SysTick_Config(SystemCoreClock / 1000);
// Configure the rest of the stuff
adcInit();
#ifndef FY90Q
i2cInit(I2C2);
#endif
// sleep for 100ms
delay(100);
}
示例3: UsartRcc_Configuration
//rcc-rcc-rcc-rcc-rcc-rcc-rcc-rcc-rcc-rcc-rcc//
void UsartRcc_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
}
示例4: GPIO_Configuration
//========================================
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
GPIO_InitStructure.GPIO_Pin = LED_CLK_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(LED_CLK_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = LED_LAT_PIN;
GPIO_Init(LED_LAT_PORT, &GPIO_InitStructure);
/*
#if DISPLAY_LED_STATIC
GPIO_InitStructure.GPIO_Pin = LED_OE_PIN;
GPIO_Init(LED_OE_PORT, &GPIO_InitStructure);
#endif
*/
if(hwConfig.ledType == SCAN_STATIC)
{
GPIO_InitStructure.GPIO_Pin = LED_OE_PIN;
GPIO_Init(LED_OE_PORT, &GPIO_InitStructure);
}
// Config PORTA pins
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// Config PORTB pins
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// Config PORTB pins
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_Init(GPIOC, &GPIO_InitStructure);
// Config PORTB pins
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_Init(GPIOD, &GPIO_InitStructure);
// Config PORTB pins
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_Init(GPIOE, &GPIO_InitStructure);
// Set default value for control pins
GPIO_Write(GPIOA,0x0000);
GPIO_Write(GPIOB,0x0000);
GPIO_Write(GPIOC,0x0000);
GPIO_Write(GPIOD,0x0000);
GPIO_Write(GPIOE,0x0000);
// Configure USART1 Rx as input floating
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// Configure USART1 Tx as alternate function push-pull
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
示例5: I2C_Configuration
void I2C_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
I2C_InitTypeDef I2C_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_I2C1, ENABLE);
GPIO_InitStructure.GPIO_Pin = I2C_SCL_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_ResetBits(GPIOB, I2C_SCL_PIN);
I2CDelay(SystemCoreClock / 3 / 100000);
GPIO_InitStructure.GPIO_Pin = I2C_SDA_PIN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_ResetBits(GPIOB, I2C_SDA_PIN);
I2CDelay(SystemCoreClock / 3 / 100000);
GPIO_SetBits(GPIOB, I2C_SCL_PIN);
I2CDelay(SystemCoreClock / 3 / 100000);
GPIO_SetBits(GPIOB, I2C_SDA_PIN);
I2CDelay(SystemCoreClock / 3 / 100000);
GPIO_InitStructure.GPIO_Pin = I2C_SCL_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = I2C_SDA_PIN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
I2C_DeInit(I2C);
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = I2C_SLAVE_ADDR;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED;
I2C_Init(I2C, &I2C_InitStructure);
I2C_Cmd(I2C, ENABLE);
if (I2C->SR2 & 0x02) //檢測I2C
{
while (1) //DEBUG
{
}
}
}
示例6: SD_LowLevel_Init
/**
* @brief Initializes the SD_SPI and CS pins.
* @param None
* @retval None
*/
void SD_LowLevel_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
/*!< SD_SPI_CS_GPIO, SD_SPI_MOSI_GPIO, SD_SPI_MISO_GPIO, SD_SPI_DETECT_GPIO
and SD_SPI_SCK_GPIO Periph clock enable */
RCC_APB2PeriphClockCmd(SD_CS_GPIO_CLK | SD_SPI_MOSI_GPIO_CLK | SD_SPI_MISO_GPIO_CLK |
SD_SPI_SCK_GPIO_CLK | SD_DETECT_GPIO_CLK, ENABLE);
/*!< SD_SPI Periph clock enable */
RCC_APB1PeriphClockCmd(SD_SPI_CLK, ENABLE);
/*!< AFIO Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
/*!< Remap SPI3 Pins */
GPIO_PinRemapConfig(GPIO_Remap_SPI3,ENABLE);
/*!< Configure SD_SPI pins: SCK */
GPIO_InitStructure.GPIO_Pin = SD_SPI_SCK_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(SD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
/*!< Configure SD_SPI pins: MOSI */
GPIO_InitStructure.GPIO_Pin = SD_SPI_MOSI_PIN;
GPIO_Init(SD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
/*!< Configure SD_SPI pins: MISO */
GPIO_InitStructure.GPIO_Pin = SD_SPI_MISO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(SD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
/*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
GPIO_InitStructure.GPIO_Pin = SD_CS_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructure);
/*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
/*!< SD_SPI Config */
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SD_SPI, &SPI_InitStructure);
SPI_Cmd(SD_SPI, ENABLE); /*!< SD_SPI enable */
}
示例7: Tim1_Configuration
void Tim1_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
u16 CCR1_Val = 75; //前麵的電機
u16 CCR2_Val = 75; //後麵的電機
u16 CCR3_Val = 75; //左麵的電機
u16 CCR4_Val = 75; //右麵的電機
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
GPIO_PinRemapConfig(GPIO_FullRemap_TIM1, ENABLE);
TIM_DeInit(TIM1); //重設為缺省值
/*TIM1時鍾配置*/
TIM_TimeBaseStructure.TIM_Prescaler = 6; //預分頻(時鍾分頻)72M/4000=18K
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上計數
TIM_TimeBaseStructure.TIM_Period = 999; //裝載值 18k/144=125hz 就是說向上加的144便滿了
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //設置了時鍾分割 不懂得不管
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0; //周期計數器值 不懂得不管
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure); //初始化TIMx的時間基數單位
/* Channel 1 Configuration in PWM mode 通道一的PWM */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //PWM模式2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //正向通道有效 PA8
//TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; //反向通道也有效 PB13
TIM_OCInitStructure.TIM_Pulse = CCR1_Val; //占空時間 144 中有40的時間為高,互補的輸出正好相反
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //輸出極性
//TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low; //互補端的極性
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; //空閑狀態下的非工作狀態 不管
//TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; //先不管
TIM_OC1Init(TIM1,&TIM_OCInitStructure); //數初始化外設TIMx通道1這裏2.0庫為TIM_OCInit
/* PWM1 Mode configuration: Channel2 */
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR2_Val; //設置通道2的電平跳變值,輸出另外一個占空比的PWM
TIM_OC2Init(TIM1, &TIM_OCInitStructure); //使能通道2
TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable);
/* PWM1 Mode configuration: Channel3 */
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR3_Val; //設置通道3的電平跳變值,輸出另外一個占空比的PWM
TIM_OC3Init(TIM1, &TIM_OCInitStructure); //使能通道3
TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Enable);
/* PWM1 Mode configuration: Channel4 */
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR4_Val; //設置通道4的電平跳變值,輸出另外一個占空比的PWM
TIM_OC4Init(TIM1, &TIM_OCInitStructure); //使能通道4
TIM_OC4PreloadConfig(TIM1, TIM_OCPreload_Enable);
/* TIM1 counter enable開定時器 */
TIM_Cmd(TIM1,ENABLE);
/* TIM1 Main Output Enable 使能TIM1外設的主輸出*/
TIM_CtrlPWMOutputs(TIM1,ENABLE);
}
示例8: modCounter_init_GPIO
/*Init GPIOE (9,14,13) for PWM and GPIOC(6-8) for input*/
void modCounter_init_GPIO(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = 0;// очищаем после предыдущего
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//+5 TOLERANT?!!!!!!!!!!!!!!!!!!1
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
///////////////////// ///////////////////////////////////////////////////////
GPIO_InitStructure.GPIO_Pin = 0;// очищаем после предыдущего
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_14 | GPIO_Pin_13| GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_PinRemapConfig(GPIO_FullRemap_TIM1, ENABLE);
///////////////////////////////////////////////
GPIO_PinRemapConfig(GPIO_FullRemap_TIM3, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_TIM4, ENABLE);
}
示例9: ledInit
void ledInit(){
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
GPIO_InitTypeDef gpioInit;
gpioInit.GPIO_Pin = ledPins[0] | ledPins[1] | ledPins[2] | ledPins[3];
gpioInit.GPIO_Mode = GPIO_Mode_Out_PP;
gpioInit.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB, &gpioInit);
}
示例10: SPI_GPIO_Configuration
/**
* @brief 配置指定SPI的引腳
* @param SPIx 需要使用的SPI
* @retval None
*/
static void SPI_GPIO_Configuration(SPI_TypeDef* SPIx , u8 Remap )
{
GPIO_InitTypeDef GPIO_InitStruct;
if(Remap==0) //SPI沒有重映射
{
if(SPIx==SPI1){
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStruct);
//初始化片選輸出引腳
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_SetBits(GPIOA,GPIO_Pin_4);
}else{
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStruct);
//初始化片選輸出引腳
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_SetBits(GPIOB,GPIO_Pin_12);
}
}
if(Remap==1) //SPI有重映射
{
GPIO_PinRemapConfig(GPIO_Remap_SPI1, ENABLE); //SPI1重映射使能
if(SPIx==SPI1){
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4|GPIO_Pin_5;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStruct);
//初始化片選輸出引腳
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_SetBits(GPIOA,GPIO_Pin_15);
}else{
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStruct);
//初始化片選輸出引腳
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_SetBits(GPIOB,GPIO_Pin_12);
}
}
}
示例11: HAL_USART_Begin
void HAL_USART_Begin(HAL_USART_Serial serial, uint32_t baud)
{
// AFIO clock enable
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
// Enable USART Clock
*usartMap[serial]->usart_apbReg |= usartMap[serial]->usart_clock_en;
NVIC_InitTypeDef NVIC_InitStructure;
// Enable the USART Interrupt
NVIC_InitStructure.NVIC_IRQChannel = usartMap[serial]->usart_int_n;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 7;//USART2_IRQ_PRIORITY;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// Configure USART Rx as input floating
HAL_Pin_Mode(usartMap[serial]->usart_rx_pin, INPUT);
// Configure USART Tx as alternate function push-pull
HAL_Pin_Mode(usartMap[serial]->usart_tx_pin, AF_OUTPUT_PUSHPULL);
// Remap USARTn to alternate pins EG. USART1 to pins TX/PB6, RX/PB7
GPIO_PinRemapConfig(usartMap[serial]->usart_pin_remap, ENABLE);
// USART default configuration
// USART configured as follow:
// - BaudRate = (set baudRate as 9600 baud)
// - Word Length = 8 Bits
// - One Stop Bit
// - No parity
// - Hardware flow control disabled (RTS and CTS signals)
// - Receive and transmit enabled
USART_InitStructure.USART_BaudRate = baud;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
// Configure USART
USART_Init(usartMap[serial]->usart_peripheral, &USART_InitStructure);
// Enable USART Receive and Transmit interrupts
USART_ITConfig(usartMap[serial]->usart_peripheral, USART_IT_RXNE, ENABLE);
USART_ITConfig(usartMap[serial]->usart_peripheral, USART_IT_TXE, ENABLE);
// Enable the USART
USART_Cmd(usartMap[serial]->usart_peripheral, ENABLE);
usartMap[serial]->usart_enabled = true;
usartMap[serial]->usart_transmitting = false;
}
示例12: Bsp_Init
void Bsp_Init(void)
{
RCC_Configuration();
/*********************************************************************************************/
//
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);
//初始化LED燈
led_init_com();
led_init_io();
//初始化串口
UART1_NVIC_Configuration();
UART1_Configuration();
UART1_GPIO_Configuration();
UART2_NVIC_Configuration();
UART2_Configuration();
UART2_GPIO_Configuration();
//清除標誌位,否則第一位會丟失
USART_ClearFlag(USART1,USART_FLAG_TC);
USART_ClearFlag(USART2,USART_FLAG_TC);
//初始化輸入輸出接口
Io_Init();
//初始化E13_TLL模塊
/***
E13_Io_Init();
//配置E13_TLL模塊
if (E13_Configuration()==1) //E13模塊配置失效,閃爍發送和接受LED燈,進入死循環
{
while(1)
{
Delay_Ms(25);
led_on_com_r();
led_on_com_t();
Delay_Ms(25);
led_off_r();
led_off_t();
}
}
*///////////////
led_on_in_3(); //點亮IN3作為電源指示燈
//初始化flash
data_error =Read_Flash(0x0801fc00);
communication_over_time =Read_Flash(0x0801f800);
communication_miss =Read_Flash(0x0801f400);
power_up=Read_Flash(0x0801f000);
//Write_Flash(0x0801fc00,0);
//Write_Flash(0x0801f800,0);
}
示例13: RCC_Configuration
static void RCC_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
#ifdef RT_USING_UART1
/* Enable USART1 and GPIOA clocks */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
#endif
#ifdef RT_USING_UART2
#if (defined(STM32F10X_LD) || defined(STM32F10X_MD)) //|| defined(STM32F10X_CL))--2011del
/* Enable AFIO and GPIOD clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOD, ENABLE);
/* Enable the USART2 Pins Software Remapping */
GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
#else
/* Enable AFIO and GPIOA clock */
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOD, ENABLE);
#endif
/* Enable USART2 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
#endif
#ifdef RT_USING_UART3
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/* Enable USART3 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
/* DMA clock enable */
//RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
#endif
#ifdef RT_USING_UART4
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
#endif
}
示例14: GPIO_Configuration
/**
* @brief Configures the different GPIO ports.
* @param None
* @retval None
*/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
#ifdef USE_STM3210E_EVAL
/* Disable the JTAG interface and enable the SWJ interface
This operation is not necessary for Connectivity-Line devices since
SPI3 I/Os can be remapped on other GPIO pins */
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
#endif /* USE_STM3210E_EVAL */
/* Configure SPI2 pins: CK, WS and SD ---------------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
#ifdef USE_STM3210C_EVAL
/* Remap SPI3 on PC10-PC11-PC12-PA4 GPIO pins ------------------------*/
GPIO_PinRemapConfig(GPIO_Remap_SPI3, ENABLE);
/* Configure SPI3 pins: CK and SD ------------------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_12;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure SPI3 pins: WS -------------------------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_Init(GPIOA, &GPIO_InitStructure);
#elif defined (USE_STM3210E_EVAL)
/* Configure SPI3 pins: CK and SD ------------------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_5;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure SPI3 pins: WS -------------------------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_Init(GPIOA, &GPIO_InitStructure);
#endif /* USE_STM3210C_EVAL */
}
示例15: rccInit
static void rccInit(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
}