py32f003xx_ll_Start_Kit.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /**
  2. ******************************************************************************
  3. * @file py32f003xx_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_dma.h"
  47. #include "py32f0xx_ll_gpio.h"
  48. #include "py32f0xx_ll_usart.h"
  49. /** @addtogroup BSP
  50. * @{
  51. */
  52. /** @defgroup py32f0xx_Start_Kit
  53. * @brief This section contains the exported types, contants and functions
  54. * required to use the Nucleo 32 board.
  55. * @{
  56. */
  57. /** @defgroup py32f0xx_Start_Kit_Exported_Types Exported Types
  58. * @{
  59. */
  60. typedef enum
  61. {
  62. LED3 = 0,
  63. LED_GREEN = LED3
  64. } Led_TypeDef;
  65. typedef enum
  66. {
  67. BUTTON_USER = 0,
  68. /* Alias */
  69. BUTTON_KEY = BUTTON_USER
  70. } Button_TypeDef;
  71. typedef enum
  72. {
  73. BUTTON_MODE_GPIO = 0,
  74. BUTTON_MODE_EXTI = 1
  75. } ButtonMode_TypeDef;
  76. #define StartKitVersion 2
  77. /* #define StartKitVersion 1 */
  78. #define LEDn 1
  79. #define LED3_PIN LL_GPIO_PIN_5
  80. #define LED3_GPIO_PORT GPIOB
  81. #define LED3_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB)
  82. #define LED3_GPIO_CLK_DISABLE() LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOB)
  83. #define LEDx_GPIO_CLK_ENABLE(__INDEX__) do {LED3_GPIO_CLK_ENABLE(); } while(0U)
  84. #define LEDx_GPIO_CLK_DISABLE(__INDEX__) LED3_GPIO_CLK_DISABLE()
  85. #define BUTTONn 1
  86. /**
  87. * @brief User push-button
  88. */
  89. #define USER_BUTTON_PIN LL_GPIO_PIN_12
  90. #define USER_BUTTON_GPIO_PORT GPIOA
  91. #define USER_BUTTON_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA)
  92. #define USER_BUTTON_GPIO_CLK_DISABLE() LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOA)
  93. #define USER_BUTTON_EXTI_IRQn EXTI4_15_IRQn
  94. #define USER_BUTTON_EXTI_LINE LL_EXTI_LINE_12
  95. #define USER_BUTTON_EXTI_LINE_ENABLE() LL_EXTI_EnableIT(USER_BUTTON_EXTI_LINE)
  96. #define USER_BUTTON_EXTI_FALLING_TRIG_ENABLE() LL_EXTI_EnableFallingTrig(USER_BUTTON_EXTI_LINE)
  97. #define USER_BUTTON_IRQHANDLER EXTI4_15_IRQHandler
  98. /* Aliases */
  99. #define KEY_BUTTON_PIN USER_BUTTON_PIN
  100. #define KEY_BUTTON_GPIO_PORT USER_BUTTON_GPIO_PORT
  101. #define KEY_BUTTON_GPIO_CLK_ENABLE() USER_BUTTON_GPIO_CLK_ENABLE()
  102. #define KEY_BUTTON_GPIO_CLK_DISABLE() USER_BUTTON_GPIO_CLK_DISABLE()
  103. #define KEY_BUTTON_EXTI_IRQn USER_BUTTON_EXTI_IRQn
  104. #define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == 0) USER_BUTTON_GPIO_CLK_ENABLE();} while(0)
  105. #define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? USER_BUTTON_GPIO_CLK_DISABLE() : 0)
  106. #ifdef USART2
  107. //debug printf redirect config
  108. #define DEBUG_USART_BAUDRATE 115200
  109. #define DEBUG_USART USART2
  110. #define DEBUG_USART_CLK_ENABLE() LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2)
  111. #define __GPIOA_CLK_ENABLE() do { \
  112. __IO uint32_t tmpreg = 0x00U; \
  113. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
  114. /* Delay after an RCC peripheral clock enabling */ \
  115. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
  116. UNUSED(tmpreg); \
  117. } while(0U)
  118. #define DEBUG_USART_RX_GPIO_PORT GPIOA
  119. #define DEBUG_USART_RX_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA)
  120. #define DEBUG_USART_RX_PIN LL_GPIO_PIN_3
  121. #define DEBUG_USART_RX_AF LL_GPIO_AF_4
  122. #define DEBUG_USART_TX_GPIO_PORT GPIOA
  123. #define DEBUG_USART_TX_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA)
  124. #define DEBUG_USART_TX_PIN LL_GPIO_PIN_2
  125. #define DEBUG_USART_TX_AF LL_GPIO_AF_4
  126. #define DEBUG_USART_IRQHandler USART2_IRQHandler
  127. #define DEBUG_USART_IRQ USART2_IRQn
  128. #else
  129. #define DEBUG_USART_TX_GPIO_PORT GPIOA
  130. #define DEBUG_USART_TX_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA)
  131. #define DEBUG_USART_TX_PIN LL_GPIO_PIN_2
  132. #endif
  133. /************************************************************/
  134. /** @defgroup Functions
  135. * @{
  136. */
  137. uint32_t BSP_GetVersion(void);
  138. void BSP_LED_Init(Led_TypeDef Led);
  139. void BSP_LED_DeInit(Led_TypeDef Led);
  140. void BSP_LED_On(Led_TypeDef Led);
  141. void BSP_LED_Off(Led_TypeDef Led);
  142. void BSP_LED_Toggle(Led_TypeDef Led);
  143. void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
  144. void BSP_PB_DeInit(Button_TypeDef Button);
  145. uint32_t BSP_PB_GetState(Button_TypeDef Button);
  146. void BSP_USART_Config(void);
  147. /**
  148. * @}
  149. */
  150. /**
  151. * @}
  152. */
  153. #ifdef __cplusplus
  154. }
  155. #endif
  156. #endif /* PY32F003XX_LL_START_KIT_H */
  157. /************************ (C) COPYRIGHT Puya *****END OF FILE****/