py32f002xx_ll_Start_Kit.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**
  2. ******************************************************************************
  3. * @file py32f002xx_ll_Start_Kit.h
  4. * @author MCU Application Team
  5. * @brief This file provides set of firmware functions to manage Leds,
  6. * push-button available on Start Kit.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software component is licensed by Puya under BSD 3-Clause license,
  14. * the "License"; You may not use this file except in compliance with the
  15. * License. You may obtain a copy of the License at:
  16. * opensource.org/licenses/BSD-3-Clause
  17. *
  18. ******************************************************************************
  19. * @attention
  20. *
  21. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  22. * All rights reserved.</center></h2>
  23. *
  24. * This software component is licensed by ST under BSD 3-Clause license,
  25. * the "License"; You may not use this file except in compliance with the
  26. * License. You may obtain a copy of the License at:
  27. * opensource.org/licenses/BSD-3-Clause
  28. *
  29. ******************************************************************************
  30. */
  31. /* Define to prevent recursive inclusion -------------------------------------*/
  32. #ifndef PY32F0XX_LL_START_KIT_H
  33. #define PY32F0XX_LL_START_KIT_H
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /* Includes ------------------------------------------------------------------*/
  38. #include <stdio.h>
  39. #include "py32f0xx_ll_rcc.h"
  40. #include "py32f0xx_ll_bus.h"
  41. #include "py32f0xx_ll_system.h"
  42. #include "py32f0xx_ll_exti.h"
  43. #include "py32f0xx_ll_cortex.h"
  44. #include "py32f0xx_ll_utils.h"
  45. #include "py32f0xx_ll_pwr.h"
  46. #include "py32f0xx_ll_gpio.h"
  47. #include "py32f0xx_ll_usart.h"
  48. /** @addtogroup BSP
  49. * @{
  50. */
  51. /** @defgroup py32f0xx_Start_Kit
  52. * @brief This section contains the exported types, contants and functions
  53. * required to use the Nucleo 32 board.
  54. * @{
  55. */
  56. /** @defgroup py32f0xx_Start_Kit_Exported_Types Exported Types
  57. * @{
  58. */
  59. typedef enum
  60. {
  61. LED3 = 0,
  62. LED_GREEN = LED3
  63. } Led_TypeDef;
  64. typedef enum
  65. {
  66. BUTTON_USER = 0,
  67. /* Alias */
  68. BUTTON_KEY = BUTTON_USER
  69. } Button_TypeDef;
  70. typedef enum
  71. {
  72. BUTTON_MODE_GPIO = 0,
  73. BUTTON_MODE_EXTI = 1
  74. } ButtonMode_TypeDef;
  75. #define StartKitVersion 2
  76. /* #define StartKitVersion 1 */
  77. #define LEDn 1
  78. #define LED3_PIN LL_GPIO_PIN_5
  79. #define LED3_GPIO_PORT GPIOA
  80. #define LED3_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA)
  81. #define LED3_GPIO_CLK_DISABLE() LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOA)
  82. #define LEDx_GPIO_CLK_ENABLE(__INDEX__) do {LED3_GPIO_CLK_ENABLE(); } while(0U)
  83. #define LEDx_GPIO_CLK_DISABLE(__INDEX__) LED3_GPIO_CLK_DISABLE()
  84. #define BUTTONn 1
  85. /**
  86. * @brief User push-button
  87. */
  88. #define USER_BUTTON_PIN LL_GPIO_PIN_2
  89. #define USER_BUTTON_GPIO_PORT GPIOB
  90. #define USER_BUTTON_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB)
  91. #define USER_BUTTON_GPIO_CLK_DISABLE() LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOB)
  92. #define USER_BUTTON_EXTI_IRQn EXTI2_3_IRQn
  93. #define USER_BUTTON_EXTI_LINE LL_EXTI_LINE_2
  94. #define USER_BUTTON_EXTI_LINE_ENABLE() LL_EXTI_EnableIT(USER_BUTTON_EXTI_LINE)
  95. #define USER_BUTTON_EXTI_FALLING_TRIG_ENABLE() LL_EXTI_EnableFallingTrig(USER_BUTTON_EXTI_LINE)
  96. #define USER_BUTTON_IRQHANDLER EXTI2_3_IRQHandler
  97. /* Aliases */
  98. #define KEY_BUTTON_PIN USER_BUTTON_PIN
  99. #define KEY_BUTTON_GPIO_PORT USER_BUTTON_GPIO_PORT
  100. #define KEY_BUTTON_GPIO_CLK_ENABLE() USER_BUTTON_GPIO_CLK_ENABLE()
  101. #define KEY_BUTTON_GPIO_CLK_DISABLE() USER_BUTTON_GPIO_CLK_DISABLE()
  102. #define KEY_BUTTON_EXTI_IRQn USER_BUTTON_EXTI_IRQn
  103. #define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == 0) USER_BUTTON_GPIO_CLK_ENABLE();} while(0)
  104. #define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? USER_BUTTON_GPIO_CLK_DISABLE() : 0)
  105. #ifdef USART1
  106. //debug printf redirect config
  107. #define DEBUG_USART_BAUDRATE 115200
  108. #define DEBUG_USART USART1
  109. #define DEBUG_USART_CLK_ENABLE() LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_USART1)
  110. #define __GPIOA_CLK_ENABLE() do { \
  111. __IO uint32_t tmpreg = 0x00U; \
  112. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
  113. /* Delay after an RCC peripheral clock enabling */ \
  114. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
  115. UNUSED(tmpreg); \
  116. } while(0U)
  117. #define DEBUG_USART_RX_GPIO_PORT GPIOA
  118. #define DEBUG_USART_RX_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA)
  119. #define DEBUG_USART_RX_PIN LL_GPIO_PIN_3
  120. #define DEBUG_USART_RX_AF LL_GPIO_AF_1
  121. #define DEBUG_USART_TX_GPIO_PORT GPIOA
  122. #define DEBUG_USART_TX_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA)
  123. #define DEBUG_USART_TX_PIN LL_GPIO_PIN_2
  124. #define DEBUG_USART_TX_AF LL_GPIO_AF_1
  125. #define DEBUG_USART_IRQHandler USART1_IRQHandler
  126. #define DEBUG_USART_IRQ USART1_IRQn
  127. #else
  128. #define DEBUG_USART_TX_GPIO_PORT GPIOA
  129. #define DEBUG_USART_TX_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA)
  130. #define DEBUG_USART_TX_PIN LL_GPIO_PIN_2
  131. #endif
  132. /************************************************************/
  133. /** @defgroup Functions
  134. * @{
  135. */
  136. uint32_t BSP_GetVersion(void);
  137. void BSP_LED_Init(Led_TypeDef Led);
  138. void BSP_LED_DeInit(Led_TypeDef Led);
  139. void BSP_LED_On(Led_TypeDef Led);
  140. void BSP_LED_Off(Led_TypeDef Led);
  141. void BSP_LED_Toggle(Led_TypeDef Led);
  142. void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
  143. void BSP_PB_DeInit(Button_TypeDef Button);
  144. uint32_t BSP_PB_GetState(Button_TypeDef Button);
  145. void BSP_USART_Config(void);
  146. /**
  147. * @}
  148. */
  149. /**
  150. * @}
  151. */
  152. #ifdef __cplusplus
  153. }
  154. #endif
  155. #endif /* PY32F002XX_LL_START_KIT_H */
  156. /************************ (C) COPYRIGHT Puya *****END OF FILE****/