py32f002bxx_ll_Start_Kit.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /**
  2. ******************************************************************************
  3. * @file py32f002bxx_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 __PY32F002Bxx_LL_START_KIT_H
  33. #define __PY32F002Bxx_LL_START_KIT_H
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /* Includes ------------------------------------------------------------------*/
  38. #include <stdio.h>
  39. #include "py32f002b_ll_rcc.h"
  40. #include "py32f002b_ll_bus.h"
  41. #include "py32f002b_ll_system.h"
  42. #include "py32f002b_ll_exti.h"
  43. #include "py32f002b_ll_cortex.h"
  44. #include "py32f002b_ll_utils.h"
  45. #include "py32f002b_ll_pwr.h"
  46. #include "py32f002b_ll_gpio.h"
  47. #include "py32f002b_ll_usart.h"
  48. /** @addtogroup BSP
  49. * @{
  50. */
  51. /** @defgroup py32f002bxx_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 py32f002bxx_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 LEDn 1
  76. #define LED3_PIN LL_GPIO_PIN_1
  77. #define LED3_GPIO_PORT GPIOA
  78. #define LED3_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA)
  79. #define LED3_GPIO_CLK_DISABLE() LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOA)
  80. #define LEDx_GPIO_CLK_ENABLE(__INDEX__) do {LED3_GPIO_CLK_ENABLE(); } while(0U)
  81. #define LEDx_GPIO_CLK_DISABLE(__INDEX__) LED3_GPIO_CLK_DISABLE()
  82. #define BUTTONn 1
  83. /**
  84. * @brief User push-button
  85. */
  86. #define USER_BUTTON_PIN LL_GPIO_PIN_0
  87. #define USER_BUTTON_GPIO_PORT GPIOA
  88. #define USER_BUTTON_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA)
  89. #define USER_BUTTON_GPIO_CLK_DISABLE() LL_IOP_GRP1_DisableClock(LL_IOP_GRP1_PERIPH_GPIOA)
  90. #define USER_BUTTON_EXTI_IRQn EXTI0_1_IRQn
  91. #define USER_BUTTON_EXTI_LINE LL_EXTI_LINE_0
  92. #define USER_BUTTON_EXTI_LINE_ENABLE() LL_EXTI_EnableIT(USER_BUTTON_EXTI_LINE)
  93. #define USER_BUTTON_EXTI_FALLING_TRIG_ENABLE() LL_EXTI_EnableFallingTrig(USER_BUTTON_EXTI_LINE)
  94. #define USER_BUTTON_IRQHANDLER EXTI0_1_IRQHandler
  95. /* Aliases */
  96. #define KEY_BUTTON_PIN USER_BUTTON_PIN
  97. #define KEY_BUTTON_GPIO_PORT USER_BUTTON_GPIO_PORT
  98. #define KEY_BUTTON_GPIO_CLK_ENABLE() USER_BUTTON_GPIO_CLK_ENABLE()
  99. #define KEY_BUTTON_GPIO_CLK_DISABLE() USER_BUTTON_GPIO_CLK_DISABLE()
  100. #define KEY_BUTTON_EXTI_IRQn USER_BUTTON_EXTI_IRQn
  101. #define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == 0) USER_BUTTON_GPIO_CLK_ENABLE();} while(0)
  102. #define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? USER_BUTTON_GPIO_CLK_DISABLE() : 0)
  103. //debug printf redirect config
  104. #define DEBUG_USART_BAUDRATE 115200
  105. #define DEBUG_USART USART1
  106. #define DEBUG_USART_CLK_ENABLE() LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_USART1)
  107. #define __GPIOA_CLK_ENABLE() do { \
  108. __IO uint32_t tmpreg = 0x00U; \
  109. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
  110. /* Delay after an RCC peripheral clock enabling */ \
  111. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
  112. UNUSED(tmpreg); \
  113. } while(0U)
  114. #define DEBUG_USART_RX_GPIO_PORT GPIOB
  115. #define DEBUG_USART_RX_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB)
  116. #define DEBUG_USART_RX_PIN LL_GPIO_PIN_5
  117. #define DEBUG_USART_RX_AF LL_GPIO_AF_1
  118. #define DEBUG_USART_TX_GPIO_PORT GPIOB
  119. #define DEBUG_USART_TX_GPIO_CLK_ENABLE() LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB)
  120. #define DEBUG_USART_TX_PIN LL_GPIO_PIN_4
  121. #define DEBUG_USART_TX_AF LL_GPIO_AF_1
  122. #define DEBUG_USART_IRQHandler USART1_IRQHandler
  123. #define DEBUG_USART_IRQ USART1_IRQn
  124. /************************************************************/
  125. /** @defgroup Functions
  126. * @{
  127. */
  128. uint32_t BSP_GetVersion(void);
  129. void BSP_LED_Init(Led_TypeDef Led);
  130. void BSP_LED_DeInit(Led_TypeDef Led);
  131. void BSP_LED_On(Led_TypeDef Led);
  132. void BSP_LED_Off(Led_TypeDef Led);
  133. void BSP_LED_Toggle(Led_TypeDef Led);
  134. void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
  135. void BSP_PB_DeInit(Button_TypeDef Button);
  136. uint32_t BSP_PB_GetState(Button_TypeDef Button);
  137. void BSP_USART_Config(void);
  138. /**
  139. * @}
  140. */
  141. /**
  142. * @}
  143. */
  144. #ifdef __cplusplus
  145. }
  146. #endif
  147. #endif /* PY32F002Bxx_LL_START_KIT_H */
  148. /************************ (C) COPYRIGHT Puya *****END OF FILE****/