/*******************************************************************************
*
COPYRIGHT(c) 2020, China Mobile IOT
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
Neither the name of China Mobile IOT nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************//**
[url=home.php?mod=space&uid=1455510]@file[/url] main.c
[url=home.php?mod=space&uid=40524]@author[/url] CMIOT Firmware Team
[url=home.php?mod=space&uid=644434]@version[/url] v1.0.0
[url=home.php?mod=space&uid=855824]@copyright[/url] Copyright (c) 2020, CMIOT. All rights reserved.
*/#include "main.h"#include <stdio.h>/** @addtogroup CM32M4xxR_StdPeriph_Examples
@{
*//** @addtogroup USART_Printf
@{
*/
typedef enum{
FAILED = 0,
PASSED = !FAILED
} TestStatus;
#define countof(a) (sizeof(a) / sizeof(*(a)))
USART_InitType USART_InitStructure;
void RCC_Configuration(void);
void GPIO_Configuration(void);
TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength);
/**
[url=home.php?mod=space&uid=2666770]@Brief[/url] Main function
/
int main(void)
{
/ System Clocks Configuration */
RCC_Configuration();
/* Configure the GPIO ports */
GPIO_Configuration();
/* USARTy and USARTz configuration ------------------------------------------------------*/
USART_InitStructure.BaudRate = 115200;
USART_InitStructure.WordLength = USART_WL_8B;
USART_InitStructure.StopBits = USART_STPB_1;
USART_InitStructure.Parity = USART_PE_NO;
USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE;
USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX;
/* Configure USARTx */
USART_Init(USARTx, &USART_InitStructure);
/* Enable the USARTx */
USART_Enable(USARTx, ENABLE);
/* Output a message on Hyperterminal using printf function */
printf("\n\rhello world!\n\r");
while (1)
{
GPIO_SetBits(GPIOB,GPIO_PIN_5);//
delay_us(180);
GPIO_ResetBits(GPIOB,GPIO_PIN_5);//
delay_us(160);
//// GPIO_SetBits(GPIOB,GPIO_PIN_5);// delay_ms(50);// GPIO_ResetBits(GPIOB,GPIO_PIN_5);// delay_ms(50);//// GPIO_SetBits(GPIOB,GPIO_PIN_6);// delay_ms(50);// GPIO_ResetBits(GPIOB,GPIO_PIN_6);// delay_ms(50);//// GPIO_SetBits(GPIOB,GPIO_PIN_7);// delay_ms(50);// GPIO_ResetBits(GPIOB,GPIO_PIN_7);// delay_ms(50);//////////// GPIO_SetBits(GPIOB,GPIO_PIN_7);// delay_ms(50);// GPIO_ResetBits(GPIOB,GPIO_PIN_7);// delay_ms(50);//// GPIO_SetBits(GPIOB,GPIO_PIN_6);// delay_ms(50);// GPIO_ResetBits(GPIOB,GPIO_PIN_6);// delay_ms(50);//// GPIO_SetBits(GPIOB,GPIO_PIN_5);// delay_ms(50);// GPIO_ResetBits(GPIOB,GPIO_PIN_5);// delay_ms(50);//// GPIO_SetBits(GPIOA,GPIO_PIN_0);// delay_ms(50);// GPIO_ResetBits(GPIOA,GPIO_PIN_0);// delay_ms(50);
}
}
/**
@brief Configures the different system clocks.
/
void RCC_Configuration(void)
{
/ Enable GPIO clock */
GPIO_APBxClkCmd(RCC_APB2_PERIPH_GPIOA|RCC_APB2_PERIPH_GPIOB, ENABLE);
/* Enable USARTy and USARTz Clock */
USART_APBxClkCmd(USARTx_CLK, ENABLE);
}
/**
@brief Configures the different GPIO ports.
*/void GPIO_Configuration(void)
{
GPIO_InitType GPIO_InitStructure;
GPIO_ConfigPinRemap(GPIO_RMP_USART1,ENABLE);
/* Configure USARTx Tx as alternate function push-pull */
GPIO_InitStructure.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.Pin =GPIO_PIN_11| GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure USARTx Rx as input floating */
GPIO_InitStructure.Pin = USARTx_RxPin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(USARTx_GPIO, &GPIO_InitStructure);
GPIO_ConfigPinRemap(GPIO_RMP3_UART4, ENABLE);
}
/**
@brief Compares two buffers.
[url=home.php?mod=space&uid=3142012]@param[/url] pBuffer1, pBuffer2: buffers to be compared.
@param BufferLength buffer's length
[url=home.php?mod=space&uid=1141835]@Return[/url] PASSED: pBuffer1 identical to pBuffer2
FAILED: pBuffer1 differs from pBuffer2
/
TestStatus Buffercmp(uint8_t pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength)
{
while (BufferLength--)
{
if (*pBuffer1 != *pBuffer2)
{
return FAILED;
}
pBuffer1++;
pBuffer2++;
}
return PASSED;
}
/**
@brief Redefine printf function.
*/int _put_char(int ch)
{
USART_SendData(USARTx, (uint8_t)ch);
/* Loop until the end of transmission */while (USART_GetFlagStatus(USARTx, USART_FLAG_TXDE) == RESET)
{
}
return ch;
}
/**
@}
*//**
@}
/
/******************************************************************************/