MM32G0001测评回复

分享作者:user202412045861
评测品牌:灵动微电子
评测型号:MM32G0001A6T
发布时间:2025-02-10 09:34:51
0
概要
ICeasy加油!测试内容:对MM32G0001的串口1,GPIO进行简单测试
开源口碑分享内容
#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为主
*/



全部评论
暂无评论
0/144