mirror of
https://github.com/IcedRooibos/py32f0-template.git
synced 2025-10-29 00:42:06 -07:00
refactor: bsp functions
This commit is contained in:
parent
688ba2b4f2
commit
8b7da6d0c6
68
Libraries/BSP/Inc/py32f0xx_bsp_button.h
Normal file
68
Libraries/BSP/Inc/py32f0xx_bsp_button.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file py32f0xx_bsp_button.h
|
||||||
|
* @author MCU Application Team
|
||||||
|
* @brief
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef PY32F003_BSP_BUTTON_H
|
||||||
|
#define PY32F003_BSP_BUTTON_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "py32f0xx_hal.h"
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
BUTTON_USER = 0,
|
||||||
|
/* Alias */
|
||||||
|
BUTTON_KEY = BUTTON_USER
|
||||||
|
} Button_TypeDef;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
BUTTON_MODE_GPIO = 0,
|
||||||
|
BUTTON_MODE_EXTI = 1
|
||||||
|
} ButtonMode_TypeDef;
|
||||||
|
|
||||||
|
#define BUTTONn 1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief User push-button
|
||||||
|
*/
|
||||||
|
#define USER_BUTTON_PIN GPIO_PIN_12
|
||||||
|
#define USER_BUTTON_GPIO_PORT GPIOA
|
||||||
|
#define USER_BUTTON_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||||
|
#define USER_BUTTON_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
||||||
|
#define USER_BUTTON_EXTI_IRQn EXTI4_15_IRQn
|
||||||
|
|
||||||
|
/* Aliases */
|
||||||
|
#define KEY_BUTTON_PIN USER_BUTTON_PIN
|
||||||
|
#define KEY_BUTTON_GPIO_PORT USER_BUTTON_GPIO_PORT
|
||||||
|
#define KEY_BUTTON_GPIO_CLK_ENABLE() USER_BUTTON_GPIO_CLK_ENABLE()
|
||||||
|
#define KEY_BUTTON_GPIO_CLK_DISABLE() USER_BUTTON_GPIO_CLK_DISABLE()
|
||||||
|
#define KEY_BUTTON_EXTI_IRQn USER_BUTTON_EXTI_IRQn
|
||||||
|
|
||||||
|
#define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == 0) USER_BUTTON_GPIO_CLK_ENABLE();} while(0)
|
||||||
|
#define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? USER_BUTTON_GPIO_CLK_DISABLE() : 0)
|
||||||
|
|
||||||
|
/** @defgroup Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
uint32_t BSP_GetVersion(void);
|
||||||
|
|
||||||
|
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
|
||||||
|
void BSP_PB_DeInit(Button_TypeDef Button);
|
||||||
|
uint32_t BSP_PB_GetState(Button_TypeDef Button);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* PY32F003_BSP_BUTTON_H */
|
||||||
50
Libraries/BSP/Inc/py32f0xx_bsp_led.h
Normal file
50
Libraries/BSP/Inc/py32f0xx_bsp_led.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file py32f0xx_bsp_led.h
|
||||||
|
* @author MCU Application Team
|
||||||
|
* @brief
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef PY32F003_BSP_LED_H
|
||||||
|
#define PY32F003_BSP_LED_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "py32f0xx_hal.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
LED3 = 0,
|
||||||
|
LED_GREEN = LED3
|
||||||
|
} Led_TypeDef;
|
||||||
|
|
||||||
|
#define LEDn 1
|
||||||
|
|
||||||
|
#define LED3_PIN GPIO_PIN_5
|
||||||
|
#define LED3_GPIO_PORT GPIOB
|
||||||
|
#define LED3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||||
|
#define LED3_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
||||||
|
|
||||||
|
#define LEDx_GPIO_CLK_ENABLE(__INDEX__) do {LED3_GPIO_CLK_ENABLE(); } while(0U)
|
||||||
|
#define LEDx_GPIO_CLK_DISABLE(__INDEX__) LED3_GPIO_CLK_DISABLE()
|
||||||
|
|
||||||
|
|
||||||
|
void BSP_LED_Init(Led_TypeDef Led);
|
||||||
|
void BSP_LED_DeInit(Led_TypeDef Led);
|
||||||
|
void BSP_LED_On(Led_TypeDef Led);
|
||||||
|
void BSP_LED_Off(Led_TypeDef Led);
|
||||||
|
void BSP_LED_Toggle(Led_TypeDef Led);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* PY32F003_BSP_LED_H */
|
||||||
70
Libraries/BSP/Inc/py32f0xx_bsp_printf.h
Normal file
70
Libraries/BSP/Inc/py32f0xx_bsp_printf.h
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file py32f0xx_bsp_printf.h
|
||||||
|
* @author MCU Application Team
|
||||||
|
* @brief
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef PY32F003_BSP_PRINTF_H
|
||||||
|
#define PY32F003_BSP_PRINTF_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "py32f0xx_hal.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAL_UART_MODULE_ENABLED
|
||||||
|
//debug printf redirect config
|
||||||
|
#define DEBUG_USART_BAUDRATE 115200
|
||||||
|
|
||||||
|
#define DEBUG_USART USART2
|
||||||
|
#define DEBUG_USART_CLK_ENABLE() do { \
|
||||||
|
__IO uint32_t tmpreg = 0x00U; \
|
||||||
|
SET_BIT(RCC->APBENR1, RCC_APBENR1_USART2EN);\
|
||||||
|
/* Delay after an RCC peripheral clock enabling */ \
|
||||||
|
tmpreg = READ_BIT(RCC->APBENR1, RCC_APBENR1_USART2EN);\
|
||||||
|
UNUSED(tmpreg); \
|
||||||
|
} while(0U)
|
||||||
|
|
||||||
|
#define __GPIOA_CLK_ENABLE() do { \
|
||||||
|
__IO uint32_t tmpreg = 0x00U; \
|
||||||
|
SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
|
||||||
|
/* Delay after an RCC peripheral clock enabling */ \
|
||||||
|
tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
|
||||||
|
UNUSED(tmpreg); \
|
||||||
|
} while(0U)
|
||||||
|
|
||||||
|
#define DEBUG_USART_RX_GPIO_PORT GPIOA
|
||||||
|
#define DEBUG_USART_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||||
|
#define DEBUG_USART_RX_PIN GPIO_PIN_3
|
||||||
|
#define DEBUG_USART_RX_AF GPIO_AF4_USART2
|
||||||
|
|
||||||
|
#define DEBUG_USART_TX_GPIO_PORT GPIOA
|
||||||
|
#define DEBUG_USART_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||||
|
#define DEBUG_USART_TX_PIN GPIO_PIN_2
|
||||||
|
#define DEBUG_USART_TX_AF GPIO_AF4_USART2
|
||||||
|
|
||||||
|
#define DEBUG_USART_IRQHandler USART2_IRQHandler
|
||||||
|
#define DEBUG_USART_IRQ USART2_IRQn
|
||||||
|
#endif
|
||||||
|
/************************************************************/
|
||||||
|
|
||||||
|
#ifdef HAL_UART_MODULE_ENABLED
|
||||||
|
extern UART_HandleTypeDef DebugUartHandle;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void BSP_USART_Config(void);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* PY32F003_BSP_PRINTF_H */
|
||||||
@ -1,317 +0,0 @@
|
|||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file py32f003xx_Start_Kit.c
|
|
||||||
* @author MCU Application Team
|
|
||||||
* @brief This file provides set of firmware functions to manage Leds,
|
|
||||||
* push-button available on Start Kit.
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* <h2><center>© Copyright (c) Puya Semiconductor Co.
|
|
||||||
* All rights reserved.</center></h2>
|
|
||||||
*
|
|
||||||
* <h2><center>© Copyright (c) 2016 STMicroelectronics.
|
|
||||||
* All rights reserved.</center></h2>
|
|
||||||
*
|
|
||||||
* This software component is licensed by ST under BSD 3-Clause license,
|
|
||||||
* the "License"; You may not use this file except in compliance with the
|
|
||||||
* License. You may obtain a copy of the License at:
|
|
||||||
* opensource.org/licenses/BSD-3-Clause
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "py32f003xx_Start_Kit.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief PY32F003xx STK BSP Driver version number
|
|
||||||
*/
|
|
||||||
#define __PY32F003xx_STK_BSP_VERSION_MAIN (0x01U) /*!< [31:24] main version */
|
|
||||||
#define __PY32F003xx_STK_BSP_VERSION_SUB1 (0x00U) /*!< [23:16] sub1 version */
|
|
||||||
#define __PY32F003xx_STK_BSP_VERSION_SUB2 (0x00U) /*!< [15:8] sub2 version */
|
|
||||||
#define __PY32F003xx_STK_BSP_VERSION_RC (0x00U) /*!< [7:0] release candidate */
|
|
||||||
#define __PY32F003xx_STK_BSP_VERSION ((__PY32F003xx_STK_BSP_VERSION_MAIN << 24) \
|
|
||||||
|(__PY32F003xx_STK_BSP_VERSION_SUB1 << 16) \
|
|
||||||
|(__PY32F003xx_STK_BSP_VERSION_SUB2 << 8 ) \
|
|
||||||
|(__PY32F003xx_STK_BSP_VERSION_RC))
|
|
||||||
|
|
||||||
#ifdef HAL_UART_MODULE_ENABLED
|
|
||||||
UART_HandleTypeDef DebugUartHandle;
|
|
||||||
#endif
|
|
||||||
GPIO_TypeDef* LED_PORT[LEDn] = {LED3_GPIO_PORT};
|
|
||||||
const uint16_t LED_PIN[LEDn] = {LED3_PIN};
|
|
||||||
|
|
||||||
GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {USER_BUTTON_GPIO_PORT };
|
|
||||||
const uint16_t BUTTON_PIN[BUTTONn] = {USER_BUTTON_PIN };
|
|
||||||
const uint8_t BUTTON_IRQn[BUTTONn] = {USER_BUTTON_EXTI_IRQn };
|
|
||||||
|
|
||||||
/** @addtogroup PY32F003xx_STK_Exported_Functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This method returns the PY32F030 STK BSP Driver revision.
|
|
||||||
* @retval version : 0xXYZR (8bits for each decimal, R for RC)
|
|
||||||
*/
|
|
||||||
uint32_t BSP_GetVersion(void)
|
|
||||||
{
|
|
||||||
return __PY32F003xx_STK_BSP_VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @addtogroup LED_Functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configures LED GPIO.
|
|
||||||
* @param Led Specifies the Led to be configured.
|
|
||||||
* This parameter can be one of following parameters:
|
|
||||||
* @arg LED3
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void BSP_LED_Init(Led_TypeDef Led)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
|
||||||
|
|
||||||
/* Enable the GPIO_LED Clock */
|
|
||||||
LEDx_GPIO_CLK_ENABLE(Led);
|
|
||||||
|
|
||||||
/* Configure the GPIO_LED pin */
|
|
||||||
GPIO_InitStruct.Pin = LED_PIN[Led];
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
||||||
|
|
||||||
HAL_GPIO_Init(LED_PORT[Led], &GPIO_InitStruct);
|
|
||||||
HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_SET);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DeInitialize LED GPIO.
|
|
||||||
* @param Led Specifies the Led to be deconfigured.
|
|
||||||
* This parameter can be one of the following values:
|
|
||||||
* @arg LED3
|
|
||||||
* @note BSP_LED_DeInit() does not disable the GPIO clock
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void BSP_LED_DeInit(Led_TypeDef Led)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
|
||||||
|
|
||||||
/* Turn off LED */
|
|
||||||
HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET);
|
|
||||||
/* DeInit the GPIO_LED pin */
|
|
||||||
GPIO_InitStruct.Pin = LED_PIN[Led];
|
|
||||||
HAL_GPIO_DeInit(LED_PORT[Led], GPIO_InitStruct.Pin);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Turns selected LED On.
|
|
||||||
* @param Led Specifies the Led to be set on.
|
|
||||||
* This parameter can be one of following parameters:
|
|
||||||
* @arg LED3
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void BSP_LED_On(Led_TypeDef Led)
|
|
||||||
{
|
|
||||||
HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Turns selected LED Off.
|
|
||||||
* @param Led Specifies the Led to be set off.
|
|
||||||
* This parameter can be one of following parameters:
|
|
||||||
* @arg LED3
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void BSP_LED_Off(Led_TypeDef Led)
|
|
||||||
{
|
|
||||||
HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_SET);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Toggles the selected LED.
|
|
||||||
* @param Led Specifies the Led to be toggled.
|
|
||||||
* This parameter can be one of following parameters:
|
|
||||||
* @arg LED3
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void BSP_LED_Toggle(Led_TypeDef Led)
|
|
||||||
{
|
|
||||||
HAL_GPIO_TogglePin(LED_PORT[Led], LED_PIN[Led]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configures Button GPIO and EXTI Line.
|
|
||||||
* @param Button: Specifies the Button to be configured.
|
|
||||||
* This parameter should be: BUTTON_USER
|
|
||||||
* @param ButtonMode: Specifies Button mode.
|
|
||||||
* This parameter can be one of following parameters:
|
|
||||||
* @arg BUTTON_MODE_GPIO: Button will be used as simple IO
|
|
||||||
* @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
|
|
||||||
* generation capability
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef gpioinitstruct;
|
|
||||||
|
|
||||||
/* Enable the BUTTON Clock */
|
|
||||||
BUTTONx_GPIO_CLK_ENABLE(Button);
|
|
||||||
|
|
||||||
gpioinitstruct.Pin = BUTTON_PIN[Button];
|
|
||||||
gpioinitstruct.Pull = GPIO_NOPULL;
|
|
||||||
gpioinitstruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
|
||||||
|
|
||||||
if(ButtonMode == BUTTON_MODE_GPIO)
|
|
||||||
{
|
|
||||||
/* Configure Button pin as input */
|
|
||||||
gpioinitstruct.Mode = GPIO_MODE_INPUT;
|
|
||||||
|
|
||||||
HAL_GPIO_Init(BUTTON_PORT[Button], &gpioinitstruct);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ButtonMode == BUTTON_MODE_EXTI)
|
|
||||||
{
|
|
||||||
/* Configure Button pin as input with External interrupt */
|
|
||||||
gpioinitstruct.Mode = GPIO_MODE_IT_FALLING;
|
|
||||||
HAL_GPIO_Init(BUTTON_PORT[Button], &gpioinitstruct);
|
|
||||||
|
|
||||||
/* Enable and set Button EXTI Interrupt to the lowest priority */
|
|
||||||
HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0);
|
|
||||||
HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Push Button DeInit.
|
|
||||||
* @param Button: Button to be configured
|
|
||||||
* This parameter should be: BUTTON_USER
|
|
||||||
* @note PB DeInit does not disable the GPIO clock
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void BSP_PB_DeInit(Button_TypeDef Button)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef gpio_init_structure;
|
|
||||||
|
|
||||||
gpio_init_structure.Pin = BUTTON_PIN[Button];
|
|
||||||
HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
|
|
||||||
HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns the selected Button state.
|
|
||||||
* @param Button: Specifies the Button to be checked.
|
|
||||||
* This parameter should be: BUTTON_USER
|
|
||||||
* @retval Button state.
|
|
||||||
*/
|
|
||||||
uint32_t BSP_PB_GetState(Button_TypeDef Button)
|
|
||||||
{
|
|
||||||
return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAL_UART_MODULE_ENABLED
|
|
||||||
/**
|
|
||||||
* @brief DEBUG_USART GPIO Config,Mode Config,115200 8-N-1
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void BSP_USART_Config(void)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
|
||||||
|
|
||||||
DEBUG_USART_CLK_ENABLE();
|
|
||||||
|
|
||||||
DebugUartHandle.Instance = DEBUG_USART;
|
|
||||||
|
|
||||||
DebugUartHandle.Init.BaudRate = DEBUG_USART_BAUDRATE;
|
|
||||||
DebugUartHandle.Init.WordLength = UART_WORDLENGTH_8B;
|
|
||||||
DebugUartHandle.Init.StopBits = UART_STOPBITS_1;
|
|
||||||
DebugUartHandle.Init.Parity = UART_PARITY_NONE;
|
|
||||||
DebugUartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
||||||
DebugUartHandle.Init.Mode = UART_MODE_TX_RX;
|
|
||||||
|
|
||||||
HAL_UART_Init(&DebugUartHandle);
|
|
||||||
|
|
||||||
DEBUG_USART_RX_GPIO_CLK_ENABLE();
|
|
||||||
DEBUG_USART_TX_GPIO_CLK_ENABLE();
|
|
||||||
|
|
||||||
/**USART1 GPIO Configuration
|
|
||||||
PA2 ------> USART2_TX
|
|
||||||
PA3 ------> USART2_RX
|
|
||||||
*/
|
|
||||||
GPIO_InitStruct.Pin = DEBUG_USART_TX_PIN;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
||||||
GPIO_InitStruct.Alternate = DEBUG_USART_TX_AF;
|
|
||||||
HAL_GPIO_Init(DEBUG_USART_TX_GPIO_PORT, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
GPIO_InitStruct.Pin = DEBUG_USART_RX_PIN;
|
|
||||||
GPIO_InitStruct.Alternate = DEBUG_USART_RX_AF;
|
|
||||||
|
|
||||||
HAL_GPIO_Init(DEBUG_USART_RX_GPIO_PORT, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* ENABLE NVIC */
|
|
||||||
HAL_NVIC_SetPriority(DEBUG_USART_IRQ,0,1);
|
|
||||||
HAL_NVIC_EnableIRQ(DEBUG_USART_IRQ );
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (defined (__CC_ARM)) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
|
|
||||||
/**
|
|
||||||
* @brief writes a character to the usart
|
|
||||||
* @param ch
|
|
||||||
* *f
|
|
||||||
* @retval the character
|
|
||||||
*/
|
|
||||||
int fputc(int ch, FILE *f)
|
|
||||||
{
|
|
||||||
/* Send a byte to USART */
|
|
||||||
HAL_UART_Transmit(&DebugUartHandle, (uint8_t *)&ch, 1, 1000);
|
|
||||||
|
|
||||||
return (ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief get a character from the usart
|
|
||||||
* @param *f
|
|
||||||
* @retval a character
|
|
||||||
*/
|
|
||||||
int fgetc(FILE *f)
|
|
||||||
{
|
|
||||||
int ch;
|
|
||||||
HAL_UART_Receive(&DebugUartHandle, (uint8_t *)&ch, 1, 1000);
|
|
||||||
return (ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(__ICCARM__)
|
|
||||||
/**
|
|
||||||
* @brief writes a character to the usart
|
|
||||||
* @param ch
|
|
||||||
* *f
|
|
||||||
* @retval the character
|
|
||||||
*/
|
|
||||||
int putchar(int ch)
|
|
||||||
{
|
|
||||||
/* Send a byte to USART */
|
|
||||||
HAL_UART_Transmit(&DebugUartHandle, (uint8_t *)&ch, 1, 1000);
|
|
||||||
|
|
||||||
return (ch);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT Puya *****END OF FILE****/
|
|
||||||
@ -1,171 +0,0 @@
|
|||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file py32f003xx_Start_Kit.h
|
|
||||||
* @author MCU Application Team
|
|
||||||
* @brief This file provides set of firmware functions to manage Leds,
|
|
||||||
* push-button available on Start Kit.
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* <h2><center>© Copyright (c) Puya Semiconductor Co.
|
|
||||||
* All rights reserved.</center></h2>
|
|
||||||
*
|
|
||||||
* <h2><center>© Copyright (c) 2016 STMicroelectronics.
|
|
||||||
* All rights reserved.</center></h2>
|
|
||||||
*
|
|
||||||
* This software component is licensed by ST under BSD 3-Clause license,
|
|
||||||
* the "License"; You may not use this file except in compliance with the
|
|
||||||
* License. You may obtain a copy of the License at:
|
|
||||||
* opensource.org/licenses/BSD-3-Clause
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
|
||||||
#ifndef PY32F003_START_KIT_H
|
|
||||||
#define PY32F003_START_KIT_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "py32f0xx_hal.h"
|
|
||||||
|
|
||||||
/** @addtogroup BSP
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup py32f0xx_Start_Kit
|
|
||||||
* @brief This section contains the exported types, contants and functions
|
|
||||||
* required to use the Nucleo 32 board.
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup py32f0xx_Start_Kit_Exported_Types Exported Types
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
LED3 = 0,
|
|
||||||
LED_GREEN = LED3
|
|
||||||
} Led_TypeDef;
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
BUTTON_USER = 0,
|
|
||||||
/* Alias */
|
|
||||||
BUTTON_KEY = BUTTON_USER
|
|
||||||
} Button_TypeDef;
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
BUTTON_MODE_GPIO = 0,
|
|
||||||
BUTTON_MODE_EXTI = 1
|
|
||||||
} ButtonMode_TypeDef;
|
|
||||||
|
|
||||||
#define LEDn 1
|
|
||||||
|
|
||||||
#define LED3_PIN GPIO_PIN_5
|
|
||||||
#define LED3_GPIO_PORT GPIOB
|
|
||||||
#define LED3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
|
||||||
#define LED3_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
|
||||||
|
|
||||||
#define LEDx_GPIO_CLK_ENABLE(__INDEX__) do {LED3_GPIO_CLK_ENABLE(); } while(0U)
|
|
||||||
#define LEDx_GPIO_CLK_DISABLE(__INDEX__) LED3_GPIO_CLK_DISABLE())
|
|
||||||
|
|
||||||
#define BUTTONn 1
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief User push-button
|
|
||||||
*/
|
|
||||||
#define USER_BUTTON_PIN GPIO_PIN_12
|
|
||||||
#define USER_BUTTON_GPIO_PORT GPIOA
|
|
||||||
#define USER_BUTTON_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
|
||||||
#define USER_BUTTON_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
|
||||||
#define USER_BUTTON_EXTI_IRQn EXTI4_15_IRQn
|
|
||||||
|
|
||||||
/* Aliases */
|
|
||||||
#define KEY_BUTTON_PIN USER_BUTTON_PIN
|
|
||||||
#define KEY_BUTTON_GPIO_PORT USER_BUTTON_GPIO_PORT
|
|
||||||
#define KEY_BUTTON_GPIO_CLK_ENABLE() USER_BUTTON_GPIO_CLK_ENABLE()
|
|
||||||
#define KEY_BUTTON_GPIO_CLK_DISABLE() USER_BUTTON_GPIO_CLK_DISABLE()
|
|
||||||
#define KEY_BUTTON_EXTI_IRQn USER_BUTTON_EXTI_IRQn
|
|
||||||
|
|
||||||
#define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == 0) USER_BUTTON_GPIO_CLK_ENABLE();} while(0)
|
|
||||||
#define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? USER_BUTTON_GPIO_CLK_DISABLE() : 0)
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAL_UART_MODULE_ENABLED
|
|
||||||
//debug printf redirect config
|
|
||||||
#define DEBUG_USART_BAUDRATE 115200
|
|
||||||
|
|
||||||
#define DEBUG_USART USART2
|
|
||||||
#define DEBUG_USART_CLK_ENABLE() do { \
|
|
||||||
__IO uint32_t tmpreg = 0x00U; \
|
|
||||||
SET_BIT(RCC->APBENR1, RCC_APBENR1_USART2EN);\
|
|
||||||
/* Delay after an RCC peripheral clock enabling */ \
|
|
||||||
tmpreg = READ_BIT(RCC->APBENR1, RCC_APBENR1_USART2EN);\
|
|
||||||
UNUSED(tmpreg); \
|
|
||||||
} while(0U)
|
|
||||||
|
|
||||||
#define __GPIOA_CLK_ENABLE() do { \
|
|
||||||
__IO uint32_t tmpreg = 0x00U; \
|
|
||||||
SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
|
|
||||||
/* Delay after an RCC peripheral clock enabling */ \
|
|
||||||
tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
|
|
||||||
UNUSED(tmpreg); \
|
|
||||||
} while(0U)
|
|
||||||
|
|
||||||
#define DEBUG_USART_RX_GPIO_PORT GPIOA
|
|
||||||
#define DEBUG_USART_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
|
||||||
#define DEBUG_USART_RX_PIN GPIO_PIN_3
|
|
||||||
#define DEBUG_USART_RX_AF GPIO_AF4_USART2
|
|
||||||
|
|
||||||
#define DEBUG_USART_TX_GPIO_PORT GPIOA
|
|
||||||
#define DEBUG_USART_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
|
||||||
#define DEBUG_USART_TX_PIN GPIO_PIN_2
|
|
||||||
#define DEBUG_USART_TX_AF GPIO_AF4_USART2
|
|
||||||
|
|
||||||
#define DEBUG_USART_IRQHandler USART2_IRQHandler
|
|
||||||
#define DEBUG_USART_IRQ USART2_IRQn
|
|
||||||
#endif
|
|
||||||
/************************************************************/
|
|
||||||
|
|
||||||
#ifdef HAL_UART_MODULE_ENABLED
|
|
||||||
extern UART_HandleTypeDef DebugUartHandle;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** @defgroup Functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
uint32_t BSP_GetVersion(void);
|
|
||||||
|
|
||||||
void BSP_LED_Init(Led_TypeDef Led);
|
|
||||||
void BSP_LED_DeInit(Led_TypeDef Led);
|
|
||||||
void BSP_LED_On(Led_TypeDef Led);
|
|
||||||
void BSP_LED_Off(Led_TypeDef Led);
|
|
||||||
void BSP_LED_Toggle(Led_TypeDef Led);
|
|
||||||
|
|
||||||
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
|
|
||||||
void BSP_PB_DeInit(Button_TypeDef Button);
|
|
||||||
uint32_t BSP_PB_GetState(Button_TypeDef Button);
|
|
||||||
|
|
||||||
void BSP_USART_Config(void);
|
|
||||||
#define DEBUG_USART_Config BSP_USART_Config
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* PY32F003_START_KIT_H */
|
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT Puya *****END OF FILE****/
|
|
||||||
80
Libraries/BSP/Src/py32f0xx_bsp_button.c
Normal file
80
Libraries/BSP/Src/py32f0xx_bsp_button.c
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#include "py32f0xx_bsp_button.h"
|
||||||
|
|
||||||
|
|
||||||
|
GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {USER_BUTTON_GPIO_PORT };
|
||||||
|
const uint16_t BUTTON_PIN[BUTTONn] = {USER_BUTTON_PIN };
|
||||||
|
const uint8_t BUTTON_IRQn[BUTTONn] = {USER_BUTTON_EXTI_IRQn };
|
||||||
|
|
||||||
|
|
||||||
|
/** @addtogroup LED_Functions
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Configures Button GPIO and EXTI Line.
|
||||||
|
* @param Button: Specifies the Button to be configured.
|
||||||
|
* This parameter should be: BUTTON_USER
|
||||||
|
* @param ButtonMode: Specifies Button mode.
|
||||||
|
* This parameter can be one of following parameters:
|
||||||
|
* @arg BUTTON_MODE_GPIO: Button will be used as simple IO
|
||||||
|
* @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
|
||||||
|
* generation capability
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef gpioinitstruct;
|
||||||
|
|
||||||
|
/* Enable the BUTTON Clock */
|
||||||
|
BUTTONx_GPIO_CLK_ENABLE(Button);
|
||||||
|
|
||||||
|
gpioinitstruct.Pin = BUTTON_PIN[Button];
|
||||||
|
gpioinitstruct.Pull = GPIO_NOPULL;
|
||||||
|
gpioinitstruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||||
|
|
||||||
|
if(ButtonMode == BUTTON_MODE_GPIO)
|
||||||
|
{
|
||||||
|
/* Configure Button pin as input */
|
||||||
|
gpioinitstruct.Mode = GPIO_MODE_INPUT;
|
||||||
|
|
||||||
|
HAL_GPIO_Init(BUTTON_PORT[Button], &gpioinitstruct);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ButtonMode == BUTTON_MODE_EXTI)
|
||||||
|
{
|
||||||
|
/* Configure Button pin as input with External interrupt */
|
||||||
|
gpioinitstruct.Mode = GPIO_MODE_IT_FALLING;
|
||||||
|
HAL_GPIO_Init(BUTTON_PORT[Button], &gpioinitstruct);
|
||||||
|
|
||||||
|
/* Enable and set Button EXTI Interrupt to the lowest priority */
|
||||||
|
HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0);
|
||||||
|
HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Push Button DeInit.
|
||||||
|
* @param Button: Button to be configured
|
||||||
|
* This parameter should be: BUTTON_USER
|
||||||
|
* @note PB DeInit does not disable the GPIO clock
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void BSP_PB_DeInit(Button_TypeDef Button)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef gpio_init_structure;
|
||||||
|
|
||||||
|
gpio_init_structure.Pin = BUTTON_PIN[Button];
|
||||||
|
HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
|
||||||
|
HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the selected Button state.
|
||||||
|
* @param Button: Specifies the Button to be checked.
|
||||||
|
* This parameter should be: BUTTON_USER
|
||||||
|
* @retval Button state.
|
||||||
|
*/
|
||||||
|
uint32_t BSP_PB_GetState(Button_TypeDef Button)
|
||||||
|
{
|
||||||
|
return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
|
||||||
|
}
|
||||||
85
Libraries/BSP/Src/py32f0xx_bsp_led.c
Normal file
85
Libraries/BSP/Src/py32f0xx_bsp_led.c
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#include "py32f0xx_bsp_led.h"
|
||||||
|
|
||||||
|
|
||||||
|
GPIO_TypeDef* LED_PORT[LEDn] = {LED3_GPIO_PORT};
|
||||||
|
const uint16_t LED_PIN[LEDn] = {LED3_PIN};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Configures LED GPIO.
|
||||||
|
* @param Led Specifies the Led to be configured.
|
||||||
|
* This parameter can be one of following parameters:
|
||||||
|
* @arg LED3
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void BSP_LED_Init(Led_TypeDef Led)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
|
|
||||||
|
/* Enable the GPIO_LED Clock */
|
||||||
|
LEDx_GPIO_CLK_ENABLE(Led);
|
||||||
|
|
||||||
|
/* Configure the GPIO_LED pin */
|
||||||
|
GPIO_InitStruct.Pin = LED_PIN[Led];
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
|
|
||||||
|
HAL_GPIO_Init(LED_PORT[Led], &GPIO_InitStruct);
|
||||||
|
HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_SET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DeInitialize LED GPIO.
|
||||||
|
* @param Led Specifies the Led to be deconfigured.
|
||||||
|
* This parameter can be one of the following values:
|
||||||
|
* @arg LED3
|
||||||
|
* @note BSP_LED_DeInit() does not disable the GPIO clock
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void BSP_LED_DeInit(Led_TypeDef Led)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
|
|
||||||
|
/* Turn off LED */
|
||||||
|
HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET);
|
||||||
|
/* DeInit the GPIO_LED pin */
|
||||||
|
GPIO_InitStruct.Pin = LED_PIN[Led];
|
||||||
|
HAL_GPIO_DeInit(LED_PORT[Led], GPIO_InitStruct.Pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Turns selected LED On.
|
||||||
|
* @param Led Specifies the Led to be set on.
|
||||||
|
* This parameter can be one of following parameters:
|
||||||
|
* @arg LED3
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void BSP_LED_On(Led_TypeDef Led)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Turns selected LED Off.
|
||||||
|
* @param Led Specifies the Led to be set off.
|
||||||
|
* This parameter can be one of following parameters:
|
||||||
|
* @arg LED3
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void BSP_LED_Off(Led_TypeDef Led)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_SET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Toggles the selected LED.
|
||||||
|
* @param Led Specifies the Led to be toggled.
|
||||||
|
* This parameter can be one of following parameters:
|
||||||
|
* @arg LED3
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void BSP_LED_Toggle(Led_TypeDef Led)
|
||||||
|
{
|
||||||
|
HAL_GPIO_TogglePin(LED_PORT[Led], LED_PIN[Led]);
|
||||||
|
}
|
||||||
@ -1,24 +1,97 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include "py32f0xx_bsp_printf.h"
|
||||||
|
|
||||||
#define UART_PRINTF_BAUDRATE 115200
|
#ifdef HAL_UART_MODULE_ENABLED
|
||||||
|
/**
|
||||||
const uint8_t HEX_TABLE[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
|
* @brief DEBUG_USART GPIO Config,Mode Config,115200 8-N-1
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
int __io_getchar(void)
|
*/
|
||||||
|
void BSP_USART_Config(void)
|
||||||
{
|
{
|
||||||
//return USART_ReceiveData(USART1);
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
return 0;
|
|
||||||
|
DEBUG_USART_CLK_ENABLE();
|
||||||
|
|
||||||
|
DebugUartHandle.Instance = DEBUG_USART;
|
||||||
|
|
||||||
|
DebugUartHandle.Init.BaudRate = DEBUG_USART_BAUDRATE;
|
||||||
|
DebugUartHandle.Init.WordLength = UART_WORDLENGTH_8B;
|
||||||
|
DebugUartHandle.Init.StopBits = UART_STOPBITS_1;
|
||||||
|
DebugUartHandle.Init.Parity = UART_PARITY_NONE;
|
||||||
|
DebugUartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||||
|
DebugUartHandle.Init.Mode = UART_MODE_TX_RX;
|
||||||
|
|
||||||
|
HAL_UART_Init(&DebugUartHandle);
|
||||||
|
|
||||||
|
DEBUG_USART_RX_GPIO_CLK_ENABLE();
|
||||||
|
DEBUG_USART_TX_GPIO_CLK_ENABLE();
|
||||||
|
|
||||||
|
/**USART GPIO Configuration
|
||||||
|
PA2 ------> USART2_TX
|
||||||
|
PA3 ------> USART2_RX
|
||||||
|
*/
|
||||||
|
GPIO_InitStruct.Pin = DEBUG_USART_TX_PIN;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||||
|
GPIO_InitStruct.Alternate = DEBUG_USART_TX_AF;
|
||||||
|
HAL_GPIO_Init(DEBUG_USART_TX_GPIO_PORT, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
GPIO_InitStruct.Pin = DEBUG_USART_RX_PIN;
|
||||||
|
GPIO_InitStruct.Alternate = DEBUG_USART_RX_AF;
|
||||||
|
|
||||||
|
HAL_GPIO_Init(DEBUG_USART_RX_GPIO_PORT, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* ENABLE NVIC */
|
||||||
|
HAL_NVIC_SetPriority(DEBUG_USART_IRQ,0,1);
|
||||||
|
HAL_NVIC_EnableIRQ(DEBUG_USART_IRQ );
|
||||||
}
|
}
|
||||||
|
|
||||||
int __io_putchar(int ch)
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined (__GNUC__) && !defined (__clang__)
|
||||||
|
#define GETCHAR_PROTOTYPE int __io_getchar (void)
|
||||||
|
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
|
||||||
|
#else
|
||||||
|
#define GETCHAR_PROTOTYPE int fgetc(FILE * f)
|
||||||
|
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief retargets the c library printf function to the usart.
|
||||||
|
* @param none
|
||||||
|
* @retval none
|
||||||
|
*/
|
||||||
|
PUTCHAR_PROTOTYPE
|
||||||
{
|
{
|
||||||
// UART_SendByte((uint8_t)ch);
|
HAL_UART_Transmit(&DebugUartHandle, (uint8_t *)&ch, 1, 1000);
|
||||||
return ch;
|
return (ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GETCHAR_PROTOTYPE
|
||||||
|
{
|
||||||
|
int ch;
|
||||||
|
HAL_UART_Receive(&DebugUartHandle, (uint8_t *)&ch, 1, 1000);
|
||||||
|
return (ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined (__GNUC__) && !defined (__clang__)
|
||||||
|
__attribute__((weak)) int _write(int file, char *ptr, int len)
|
||||||
|
{
|
||||||
|
(void)file;
|
||||||
|
int DataIdx;
|
||||||
|
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
||||||
|
{
|
||||||
|
__io_putchar(*ptr++);
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
__attribute__((weak)) int _read(int file, char *ptr, int len)
|
__attribute__((weak)) int _read(int file, char *ptr, int len)
|
||||||
{
|
{
|
||||||
(void)file;
|
(void)file;
|
||||||
@ -30,18 +103,6 @@ __attribute__((weak)) int _read(int file, char *ptr, int len)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((weak)) int _write(int file, char *ptr, int len)
|
|
||||||
{
|
|
||||||
(void)file;
|
|
||||||
int DataIdx;
|
|
||||||
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
|
||||||
{
|
|
||||||
__io_putchar(*ptr++);
|
|
||||||
}
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
__attribute__((weak)) int _isatty(int fd)
|
__attribute__((weak)) int _isatty(int fd)
|
||||||
{
|
{
|
||||||
if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
|
if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
|
||||||
@ -81,3 +142,17 @@ __attribute__((weak)) int _fstat(int fd, struct stat *st)
|
|||||||
errno = EBADF;
|
errno = EBADF;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__((weak)) int _getpid(void)
|
||||||
|
{
|
||||||
|
errno = ENOSYS;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((weak)) int _kill(pid_t pid, int sig)
|
||||||
|
{
|
||||||
|
(void)pid;
|
||||||
|
(void)sig;
|
||||||
|
errno = ENOSYS;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|||||||
@ -21,7 +21,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main.h"
|
#include "py32f0xx_bsp_button.h"
|
||||||
|
#include "py32f0xx_bsp_led.h"
|
||||||
|
#include "py32f0xx_bsp_printf.h"
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
/* Private define ------------------------------------------------------------*/
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
@ -44,11 +46,14 @@ int main(void)
|
|||||||
/* 初始化LED */
|
/* 初始化LED */
|
||||||
APP_LedConfig();
|
APP_LedConfig();
|
||||||
|
|
||||||
|
BSP_USART_Config();
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
/* 延时250ms */
|
/* 延时250ms */
|
||||||
HAL_Delay(250);
|
HAL_Delay(1000);
|
||||||
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_5);
|
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_5);
|
||||||
|
printf("echo\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
52
User/main.h
52
User/main.h
@ -1,52 +0,0 @@
|
|||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file py32f0xx_hal_conf.h
|
|
||||||
* @author MCU Application Team
|
|
||||||
* @brief HAL configuration file.
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* <h2><center>© Copyright (c) Puya Semiconductor Co.
|
|
||||||
* All rights reserved.</center></h2>
|
|
||||||
*
|
|
||||||
* <h2><center>© Copyright (c) 2016 STMicroelectronics.
|
|
||||||
* All rights reserved.</center></h2>
|
|
||||||
*
|
|
||||||
* This software component is licensed by ST under BSD 3-Clause license,
|
|
||||||
* the "License"; You may not use this file except in compliance with the
|
|
||||||
* License. You may obtain a copy of the License at:
|
|
||||||
* opensource.org/licenses/BSD-3-Clause
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
|
||||||
#ifndef __MAIN_H
|
|
||||||
#define __MAIN_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "py32f0xx_hal.h"
|
|
||||||
#include "py32f003xx_Start_Kit.h"
|
|
||||||
|
|
||||||
/* Exported types ------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Exported constants --------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Exported macro ------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Exported functions prototypes ---------------------------------------------*/
|
|
||||||
void APP_ErrorHandler(void);
|
|
||||||
|
|
||||||
/* Private defines -----------------------------------------------------------*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __MAIN_H */
|
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT Puya *****END OF FILE******************/
|
|
||||||
@ -22,7 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main.h"
|
#include "py32f0xx_hal.h"
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
/* Private define ------------------------------------------------------------*/
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main.h"
|
#include "py32f0xx_hal.h"
|
||||||
#include "py32f0xx_it.h"
|
#include "py32f0xx_it.h"
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user