mirror of
https://github.com/IcedRooibos/py32f0-template.git
synced 2025-10-29 08:52:04 -07:00
feat: ll lib option
This commit is contained in:
parent
061ec26799
commit
dafe61f45e
130
Examples/Raw_LL/GPIO/LED_Toggle/main.c
Normal file
130
Examples/Raw_LL/GPIO/LED_Toggle/main.c
Normal file
@ -0,0 +1,130 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file main.c
|
||||
* @author MCU Application Team
|
||||
* @brief Main program body
|
||||
******************************************************************************
|
||||
* @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 "main.h"
|
||||
#include "py32f003xx_ll_Start_Kit.h"
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static void APP_SystemClockConfig(void);
|
||||
static void APP_GpioConfig(void);
|
||||
|
||||
/**
|
||||
* @brief 应用程序入口函数.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
/* 配置系统时钟 */
|
||||
APP_SystemClockConfig();
|
||||
|
||||
/* 初始化GPIO */
|
||||
APP_GpioConfig();
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* LED灯闪烁 */
|
||||
LL_mDelay(500);
|
||||
LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_5);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 系统时钟配置函数
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void APP_SystemClockConfig(void)
|
||||
{
|
||||
/* 使能HSI */
|
||||
LL_RCC_HSI_Enable();
|
||||
while(LL_RCC_HSI_IsReady() != 1)
|
||||
{
|
||||
}
|
||||
|
||||
/* 设置 AHB 分频*/
|
||||
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
|
||||
|
||||
/* 配置HSISYS作为系统时钟源 */
|
||||
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSISYS);
|
||||
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSISYS)
|
||||
{
|
||||
}
|
||||
|
||||
/* 设置 APB1 分频*/
|
||||
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
|
||||
LL_Init1msTick(8000000);
|
||||
|
||||
/* 更新系统时钟全局变量SystemCoreClock(也可以通过调用SystemCoreClockUpdate函数更新) */
|
||||
LL_SetSystemCoreClock(8000000);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 配置GPIO
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void APP_GpioConfig(void)
|
||||
{
|
||||
/* 使能时钟 */
|
||||
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
|
||||
|
||||
/* 将PA5引脚配置为输出 */
|
||||
LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_5, LL_GPIO_MODE_OUTPUT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 错误执行函数
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
void APP_ErrorHandler(void)
|
||||
{
|
||||
/* 无限循环 */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief 输出产生断言错误的源文件名及行号
|
||||
* @param file:源文件名指针
|
||||
* @param line:发生断言错误的行号
|
||||
* @retval 无
|
||||
*/
|
||||
void assert_failed(uint8_t *file, uint32_t line)
|
||||
{
|
||||
/* 用户可以根据需要添加自己的打印信息,
|
||||
例如: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
/* 无限循环 */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
/************************ (C) COPYRIGHT Puya *****END OF FILE******************/
|
||||
59
Examples/Raw_LL/GPIO/LED_Toggle/main.h
Normal file
59
Examples/Raw_LL/GPIO/LED_Toggle/main.h
Normal file
@ -0,0 +1,59 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file main.h
|
||||
* @author MCU Application Team
|
||||
* @brief Header for main.c file.
|
||||
* This file contains the common defines of the application.
|
||||
******************************************************************************
|
||||
* @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_ll_rcc.h"
|
||||
#include "py32f0xx_ll_bus.h"
|
||||
#include "py32f0xx_ll_system.h"
|
||||
#include "py32f0xx_ll_exti.h"
|
||||
#include "py32f0xx_ll_cortex.h"
|
||||
#include "py32f0xx_ll_utils.h"
|
||||
#include "py32f0xx_ll_pwr.h"
|
||||
#include "py32f0xx_ll_dma.h"
|
||||
#include "py32f0xx_ll_gpio.h"
|
||||
|
||||
#if defined(USE_FULL_ASSERT)
|
||||
#include "py32_assert.h"
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
/* Exported variables prototypes ---------------------------------------------*/
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
void APP_ErrorHandler(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MAIN_H */
|
||||
|
||||
/************************ (C) COPYRIGHT Puya *****END OF FILE******************/
|
||||
59
Examples/Raw_LL/GPIO/LED_Toggle/py32_assert.h
Normal file
59
Examples/Raw_LL/GPIO/LED_Toggle/py32_assert.h
Normal file
@ -0,0 +1,59 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file py32_assert.h
|
||||
* @brief PY32 assert 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 __PY32_ASSERT_H
|
||||
#define __PY32_ASSERT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stdint.h"
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief The assert_param macro is used for function's parameters check.
|
||||
* @param expr: If expr is false, it calls assert_failed function
|
||||
* which reports the name of the source file and the source
|
||||
* line number of the call that failed.
|
||||
* If expr is true, it returns no value.
|
||||
* @retval None
|
||||
*/
|
||||
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void assert_failed(uint8_t* file, uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PY32_ASSERT_H */
|
||||
|
||||
/************************ (C) COPYRIGHT Puya *****END OF FILE******************/
|
||||
84
Examples/Raw_LL/GPIO/LED_Toggle/py32f0xx_it.c
Normal file
84
Examples/Raw_LL/GPIO/LED_Toggle/py32f0xx_it.c
Normal file
@ -0,0 +1,84 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file py32f0xx_it.c
|
||||
* @author MCU Application Team
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
* @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 "main.h"
|
||||
#include "py32f0xx_it.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* External variables --------------------------------------------------------*/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Cortex-M0+ Processor Interruption and Exception Handlers */
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @brief This function handles Non maskable interrupt.
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System service call via SWI instruction.
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Pendable request for system service.
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System tick timer.
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* PY32F0xx Peripheral Interrupt Handlers */
|
||||
/* Add here the Interrupt Handlers for the used peripherals. */
|
||||
/* For the available peripheral interrupt handler names, */
|
||||
/* please refer to the startup file. */
|
||||
/******************************************************************************/
|
||||
|
||||
/************************ (C) COPYRIGHT Puya *****END OF FILE******************/
|
||||
49
Examples/Raw_LL/GPIO/LED_Toggle/py32f0xx_it.h
Normal file
49
Examples/Raw_LL/GPIO/LED_Toggle/py32f0xx_it.h
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file py32f0xx_it.h
|
||||
* @author MCU Application Team
|
||||
* @brief This file contains the headers of the interrupt handlers.
|
||||
******************************************************************************
|
||||
* @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 __PY32F0XX_IT_H
|
||||
#define __PY32F0XX_IT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
void NMI_Handler(void);
|
||||
void HardFault_Handler(void);
|
||||
void SVC_Handler(void);
|
||||
void PendSV_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PY32F0XX_IT_H */
|
||||
|
||||
/************************ (C) COPYRIGHT Puya *****END OF FILE******************/
|
||||
@ -110,32 +110,6 @@ typedef enum
|
||||
#define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? USER_BUTTON_GPIO_CLK_DISABLE() : 0)
|
||||
|
||||
|
||||
//debug printf redirect config
|
||||
#define DEBUG_USART_BAUDRATE 115200
|
||||
|
||||
#define DEBUG_USART USART2
|
||||
#define DEBUG_USART_CLK_ENABLE() LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2)
|
||||
|
||||
#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() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA)
|
||||
#define DEBUG_USART_RX_PIN LL_GPIO_PIN_3
|
||||
#define DEBUG_USART_RX_AF LL_GPIO_AF_4
|
||||
|
||||
#define DEBUG_USART_TX_GPIO_PORT GPIOA
|
||||
#define DEBUG_USART_TX_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA)
|
||||
#define DEBUG_USART_TX_PIN LL_GPIO_PIN_2
|
||||
#define DEBUG_USART_TX_AF LL_GPIO_AF_4
|
||||
|
||||
#define DEBUG_USART_IRQHandler USART2_IRQHandler
|
||||
#define DEBUG_USART_IRQ USART2_IRQn
|
||||
/************************************************************/
|
||||
|
||||
/** @defgroup Functions
|
||||
@ -153,7 +127,6 @@ void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMod
|
||||
void BSP_PB_DeInit(Button_TypeDef Button);
|
||||
uint32_t BSP_PB_GetState(Button_TypeDef Button);
|
||||
|
||||
void BSP_USART_Config(void);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
69
Libraries/BSP_LL/Inc/py32f0xx_bsp_printf.h
Normal file
69
Libraries/BSP_LL/Inc/py32f0xx_bsp_printf.h
Normal file
@ -0,0 +1,69 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @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_ll_rcc.h"
|
||||
#include "py32f0xx_ll_bus.h"
|
||||
#include "py32f0xx_ll_system.h"
|
||||
#include "py32f0xx_ll_exti.h"
|
||||
#include "py32f0xx_ll_cortex.h"
|
||||
#include "py32f0xx_ll_utils.h"
|
||||
#include "py32f0xx_ll_pwr.h"
|
||||
#include "py32f0xx_ll_dma.h"
|
||||
#include "py32f0xx_ll_gpio.h"
|
||||
#include "py32f0xx_ll_usart.h"
|
||||
|
||||
|
||||
|
||||
|
||||
//debug printf redirect config
|
||||
#define DEBUG_USART_BAUDRATE 115200
|
||||
|
||||
#define DEBUG_USART USART2
|
||||
#define DEBUG_USART_CLK_ENABLE() LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2)
|
||||
|
||||
#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() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA)
|
||||
#define DEBUG_USART_RX_PIN LL_GPIO_PIN_3
|
||||
#define DEBUG_USART_RX_AF LL_GPIO_AF_4
|
||||
|
||||
#define DEBUG_USART_TX_GPIO_PORT GPIOA
|
||||
#define DEBUG_USART_TX_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA)
|
||||
#define DEBUG_USART_TX_PIN LL_GPIO_PIN_2
|
||||
#define DEBUG_USART_TX_AF LL_GPIO_AF_4
|
||||
|
||||
#define DEBUG_USART_IRQHandler USART2_IRQHandler
|
||||
#define DEBUG_USART_IRQ USART2_IRQn
|
||||
|
||||
/************************************************************/
|
||||
|
||||
void BSP_USART_Config(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* PY32F003_BSP_PRINTF_H */
|
||||
@ -197,90 +197,6 @@ uint32_t BSP_PB_GetState(Button_TypeDef Button)
|
||||
return LL_GPIO_IsInputPinSet(BUTTON_PORT[Button], BUTTON_PIN[Button]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DEBUG_USART GPIO Config,Mode Config,115200 8-N-1
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void BSP_USART_Config(void)
|
||||
{
|
||||
DEBUG_USART_CLK_ENABLE();
|
||||
|
||||
/* USART Init */
|
||||
LL_USART_SetBaudRate(DEBUG_USART, SystemCoreClock, LL_USART_OVERSAMPLING_16, DEBUG_USART_BAUDRATE);
|
||||
LL_USART_SetDataWidth(DEBUG_USART, LL_USART_DATAWIDTH_8B);
|
||||
LL_USART_SetStopBitsLength(DEBUG_USART, LL_USART_STOPBITS_1);
|
||||
LL_USART_SetParity(DEBUG_USART, LL_USART_PARITY_NONE);
|
||||
LL_USART_SetHWFlowCtrl(DEBUG_USART, LL_USART_HWCONTROL_NONE);
|
||||
LL_USART_SetTransferDirection(DEBUG_USART, LL_USART_DIRECTION_TX_RX);
|
||||
LL_USART_Enable(DEBUG_USART);
|
||||
LL_USART_ClearFlag_TC(DEBUG_USART);
|
||||
|
||||
/**USART GPIO Configuration
|
||||
PA2 ------> USART1_TX
|
||||
PA3 ------> USART1_RX
|
||||
*/
|
||||
DEBUG_USART_RX_GPIO_CLK_ENABLE();
|
||||
DEBUG_USART_TX_GPIO_CLK_ENABLE();
|
||||
|
||||
LL_GPIO_SetPinMode(DEBUG_USART_TX_GPIO_PORT, DEBUG_USART_TX_PIN, LL_GPIO_MODE_ALTERNATE);
|
||||
LL_GPIO_SetPinSpeed(DEBUG_USART_TX_GPIO_PORT, DEBUG_USART_TX_PIN, LL_GPIO_SPEED_FREQ_VERY_HIGH);
|
||||
LL_GPIO_SetPinPull(DEBUG_USART_TX_GPIO_PORT, DEBUG_USART_TX_PIN, LL_GPIO_PULL_UP);
|
||||
LL_GPIO_SetAFPin_0_7(DEBUG_USART_TX_GPIO_PORT, DEBUG_USART_TX_PIN, DEBUG_USART_TX_AF);
|
||||
|
||||
LL_GPIO_SetPinMode(DEBUG_USART_RX_GPIO_PORT, DEBUG_USART_RX_PIN, LL_GPIO_MODE_ALTERNATE);
|
||||
LL_GPIO_SetPinSpeed(DEBUG_USART_RX_GPIO_PORT, DEBUG_USART_RX_PIN, LL_GPIO_SPEED_FREQ_VERY_HIGH);
|
||||
LL_GPIO_SetPinPull(DEBUG_USART_RX_GPIO_PORT, DEBUG_USART_RX_PIN, LL_GPIO_PULL_UP);
|
||||
LL_GPIO_SetAFPin_0_7(DEBUG_USART_RX_GPIO_PORT, DEBUG_USART_RX_PIN, DEBUG_USART_RX_AF);
|
||||
}
|
||||
|
||||
#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 */
|
||||
LL_USART_TransmitData8(DEBUG_USART, ch);
|
||||
while (!LL_USART_IsActiveFlag_TC(DEBUG_USART));
|
||||
LL_USART_ClearFlag_TC(DEBUG_USART);
|
||||
|
||||
return (ch);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get a character from the usart
|
||||
* @param *f
|
||||
* @retval a character
|
||||
*/
|
||||
int fgetc(FILE *f)
|
||||
{
|
||||
int ch;
|
||||
while (!LL_USART_IsActiveFlag_RXNE(DEBUG_USART));
|
||||
ch = LL_USART_ReceiveData8(DEBUG_USART);
|
||||
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 */
|
||||
LL_USART_TransmitData8(DEBUG_USART, ch);
|
||||
while (!LL_USART_IsActiveFlag_TC(DEBUG_USART));
|
||||
LL_USART_ClearFlag_TC(DEBUG_USART);
|
||||
|
||||
return (ch);
|
||||
}
|
||||
#endif
|
||||
|
||||
//#endif
|
||||
/**
|
||||
151
Libraries/BSP_LL/Src/py32f0xx_bsp_printf.c
Normal file
151
Libraries/BSP_LL/Src/py32f0xx_bsp_printf.c
Normal file
@ -0,0 +1,151 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include "py32f0xx_bsp_printf.h"
|
||||
|
||||
/**
|
||||
* @brief DEBUG_USART GPIO Config,Mode Config,115200 8-N-1
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void BSP_USART_Config(void)
|
||||
{
|
||||
DEBUG_USART_CLK_ENABLE();
|
||||
|
||||
/* USART Init */
|
||||
LL_USART_SetBaudRate(DEBUG_USART, SystemCoreClock, LL_USART_OVERSAMPLING_16, DEBUG_USART_BAUDRATE);
|
||||
LL_USART_SetDataWidth(DEBUG_USART, LL_USART_DATAWIDTH_8B);
|
||||
LL_USART_SetStopBitsLength(DEBUG_USART, LL_USART_STOPBITS_1);
|
||||
LL_USART_SetParity(DEBUG_USART, LL_USART_PARITY_NONE);
|
||||
LL_USART_SetHWFlowCtrl(DEBUG_USART, LL_USART_HWCONTROL_NONE);
|
||||
LL_USART_SetTransferDirection(DEBUG_USART, LL_USART_DIRECTION_TX_RX);
|
||||
LL_USART_Enable(DEBUG_USART);
|
||||
LL_USART_ClearFlag_TC(DEBUG_USART);
|
||||
|
||||
/**USART GPIO Configuration
|
||||
PA2 ------> USART1_TX
|
||||
PA3 ------> USART1_RX
|
||||
*/
|
||||
DEBUG_USART_RX_GPIO_CLK_ENABLE();
|
||||
DEBUG_USART_TX_GPIO_CLK_ENABLE();
|
||||
|
||||
LL_GPIO_SetPinMode(DEBUG_USART_TX_GPIO_PORT, DEBUG_USART_TX_PIN, LL_GPIO_MODE_ALTERNATE);
|
||||
LL_GPIO_SetPinSpeed(DEBUG_USART_TX_GPIO_PORT, DEBUG_USART_TX_PIN, LL_GPIO_SPEED_FREQ_VERY_HIGH);
|
||||
LL_GPIO_SetPinPull(DEBUG_USART_TX_GPIO_PORT, DEBUG_USART_TX_PIN, LL_GPIO_PULL_UP);
|
||||
LL_GPIO_SetAFPin_0_7(DEBUG_USART_TX_GPIO_PORT, DEBUG_USART_TX_PIN, DEBUG_USART_TX_AF);
|
||||
|
||||
LL_GPIO_SetPinMode(DEBUG_USART_RX_GPIO_PORT, DEBUG_USART_RX_PIN, LL_GPIO_MODE_ALTERNATE);
|
||||
LL_GPIO_SetPinSpeed(DEBUG_USART_RX_GPIO_PORT, DEBUG_USART_RX_PIN, LL_GPIO_SPEED_FREQ_VERY_HIGH);
|
||||
LL_GPIO_SetPinPull(DEBUG_USART_RX_GPIO_PORT, DEBUG_USART_RX_PIN, LL_GPIO_PULL_UP);
|
||||
LL_GPIO_SetAFPin_0_7(DEBUG_USART_RX_GPIO_PORT, DEBUG_USART_RX_PIN, DEBUG_USART_RX_AF);
|
||||
}
|
||||
|
||||
|
||||
#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
|
||||
{
|
||||
/* Send a byte to USART */
|
||||
LL_USART_TransmitData8(DEBUG_USART, ch);
|
||||
while (!LL_USART_IsActiveFlag_TC(DEBUG_USART));
|
||||
LL_USART_ClearFlag_TC(DEBUG_USART);
|
||||
|
||||
return (ch);
|
||||
}
|
||||
|
||||
GETCHAR_PROTOTYPE
|
||||
{
|
||||
int ch;
|
||||
while (!LL_USART_IsActiveFlag_RXNE(DEBUG_USART));
|
||||
ch = LL_USART_ReceiveData8(DEBUG_USART);
|
||||
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)
|
||||
{
|
||||
(void)file;
|
||||
int DataIdx;
|
||||
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
||||
{
|
||||
*ptr++ = __io_getchar();
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
__attribute__((weak)) int _isatty(int fd)
|
||||
{
|
||||
if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
|
||||
return 1;
|
||||
|
||||
errno = EBADF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((weak)) int _close(int fd)
|
||||
{
|
||||
if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
|
||||
return 0;
|
||||
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
__attribute__((weak)) int _lseek(int fd, int ptr, int dir)
|
||||
{
|
||||
(void)fd;
|
||||
(void)ptr;
|
||||
(void)dir;
|
||||
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
__attribute__((weak)) int _fstat(int fd, struct stat *st)
|
||||
{
|
||||
if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
|
||||
{
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
errno = EBADF;
|
||||
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;
|
||||
}
|
||||
20
Makefile
20
Makefile
@ -7,6 +7,8 @@ BUILD_DIR = Build
|
||||
|
||||
##### Options #####
|
||||
|
||||
# Use LL library instead of HAL
|
||||
USE_LL_LIB ?= y
|
||||
# Enable printf float %f support, y:yes, n:no
|
||||
ENABLE_PRINTF_FLOAT ?= n
|
||||
# Build with CMSIS DSP functions, y:yes, n:no
|
||||
@ -39,9 +41,7 @@ LIB_FLAGS = PY32F003x8
|
||||
|
||||
# C source folders
|
||||
CDIRS := User \
|
||||
Libraries/CMSIS/Device/PY32F0xx/Source \
|
||||
Libraries/PY32F0xx_HAL_Driver/Src \
|
||||
Libraries/BSP/Src
|
||||
Libraries/CMSIS/Device/PY32F0xx/Source
|
||||
# C source files (if there are any single ones)
|
||||
CFILES :=
|
||||
|
||||
@ -53,10 +53,20 @@ AFILES := Libraries/CMSIS/Device/PY32F0xx/Source/gcc/startup_py32f003.s
|
||||
# Include paths
|
||||
INCLUDES := Libraries/CMSIS/Include \
|
||||
Libraries/CMSIS/Device/PY32F0xx/Include \
|
||||
Libraries/PY32F0xx_HAL_Driver/Inc \
|
||||
Libraries/BSP/Inc \
|
||||
User
|
||||
|
||||
ifeq ($(USE_LL_LIB),y)
|
||||
CDIRS += Libraries/PY32F0xx_LL_Driver/Src \
|
||||
Libraries/BSP_LL/Src
|
||||
INCLUDES += Libraries/PY32F0xx_LL_Driver/Inc \
|
||||
Libraries/BSP_LL/Inc
|
||||
else
|
||||
CDIRS += Libraries/PY32F0xx_HAL_Driver/Src \
|
||||
Libraries/BSP/Src
|
||||
INCLUDES += Libraries/PY32F0xx_HAL_Driver/Inc \
|
||||
Libraries/BSP/Inc
|
||||
endif
|
||||
|
||||
ifeq ($(USE_DSP),y)
|
||||
LIB_FLAGS += ARM_MATH_CM0PLUS
|
||||
CDIRS += Libraries/CMSIS/DSP_Lib/Source/BasicMathFunctions \
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user