#define _GPIO_LED_TOGGLE_C_
/* Files include */
#include <stdio.h>
#include "platform.h"
#include "gpio_led_toggle.h"
void GPIO_Configure(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOA, ENABLE);
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_High;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_WriteBit(GPIOA, GPIO_Pin_11, Bit_SET);
}
void GPIO_IO_Toggle(GPIO_TypeDef *GPIOn, uint16_t PINn)
{
if (Bit_RESET == GPIO_ReadOutputDataBit(GPIOn, PINn))
{
GPIO_SetBits(GPIOn, PINn);
}
else
{
GPIO_ResetBits(GPIOn, PINn);
}
}
void GPIO_LED_Toggle_Sample(void)
{
printf("\r\nTest %s", __FUNCTION__);
GPIO_Configure();
while (1)
{
GPIO_IO_Toggle(GPIOA, GPIO_Pin_11);
printf("PinState:%d",(uint8_t)GPIO_ReadOutputDataBit(GPIOA,GPIO_Pin_11));
PLATFORM_DelayMS(200);
}
}
void PLATFORM_InitConsole(uint32_t Baudrate)
{
GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef USART_InitStruct;
RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_USART1, ENABLE);
USART_StructInit(&USART_InitStruct);
USART_InitStruct.USART_BaudRate = Baudrate;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStruct);
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOA, ENABLE);
//GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_4);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_1); //alternative PA12 as USART1-TX
GPIO_PinAFConfig(GPIOA,GPIO_PinSource3,GPIO_AF_1); //alternative PA3 as USART1-RX
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_3;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_High;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStruct);
USART_Cmd(USART1, ENABLE);
}
int fputc(int ch, FILE *f)
{
USART_SendData(USART1, (uint8_t)ch);
while (RESET == USART_GetFlagStatus(USART1, USART_FLAG_TC))
{
}
return (ch);
}
int main(void)
{
PLATFORM_Init();
GPIO_LED_Toggle_Sample();
while (1)
{
}
}
/*
主要代码在上面,其余文件均以官方所提供HAL为主
*/
