py32f002bxx_Start_Kit.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /**
  2. ******************************************************************************
  3. * @file py32f002bxx_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 PY32F002B_START_KIT_H
  33. #define PY32F002B_START_KIT_H
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /* Includes ------------------------------------------------------------------*/
  38. #include "py32f0xx_hal.h"
  39. /** @addtogroup BSP
  40. * @{
  41. */
  42. /** @defgroup py32f002b_Start_Kit
  43. * @brief This section contains the exported types, contants and functions
  44. * required to use the Nucleo 32 board.
  45. * @{
  46. */
  47. /** @defgroup py32f002b_Start_Kit_Exported_Types Exported Types
  48. * @{
  49. */
  50. typedef enum
  51. {
  52. LED3 = 0,
  53. LED_GREEN = LED3
  54. } Led_TypeDef;
  55. typedef enum
  56. {
  57. BUTTON_USER = 0,
  58. /* Alias */
  59. BUTTON_KEY = BUTTON_USER
  60. } Button_TypeDef;
  61. typedef enum
  62. {
  63. BUTTON_MODE_GPIO = 0,
  64. BUTTON_MODE_EXTI = 1
  65. } ButtonMode_TypeDef;
  66. #define LEDn 1
  67. #define LED3_PIN GPIO_PIN_1
  68. #define LED3_GPIO_PORT GPIOA
  69. #define LED3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  70. #define LED3_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  71. #define LEDx_GPIO_CLK_ENABLE(__INDEX__) do {LED3_GPIO_CLK_ENABLE(); } while(0U)
  72. #define LEDx_GPIO_CLK_DISABLE(__INDEX__) LED3_GPIO_CLK_DISABLE()
  73. #define BUTTONn 1
  74. /**
  75. * @brief User push-button
  76. */
  77. #define USER_BUTTON_PIN GPIO_PIN_0
  78. #define USER_BUTTON_GPIO_PORT GPIOA
  79. #define USER_BUTTON_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  80. #define USER_BUTTON_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  81. #define USER_BUTTON_EXTI_IRQn EXTI0_1_IRQn
  82. /* Aliases */
  83. #define KEY_BUTTON_PIN USER_BUTTON_PIN
  84. #define KEY_BUTTON_GPIO_PORT USER_BUTTON_GPIO_PORT
  85. #define KEY_BUTTON_GPIO_CLK_ENABLE() USER_BUTTON_GPIO_CLK_ENABLE()
  86. #define KEY_BUTTON_GPIO_CLK_DISABLE() USER_BUTTON_GPIO_CLK_DISABLE()
  87. #define KEY_BUTTON_EXTI_IRQn USER_BUTTON_EXTI_IRQn
  88. #define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == 0) USER_BUTTON_GPIO_CLK_ENABLE();} while(0)
  89. #define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? USER_BUTTON_GPIO_CLK_DISABLE() : 0)
  90. #ifdef HAL_UART_MODULE_ENABLED
  91. //debug printf redirect config
  92. #define DEBUG_USART_BAUDRATE 115200
  93. #define DEBUG_USART USART1
  94. #define DEBUG_USART_CLK_ENABLE() do { \
  95. __IO uint32_t tmpreg = 0x00U; \
  96. SET_BIT(RCC->APBENR2, RCC_APBENR2_USART1EN);\
  97. /* Delay after an RCC peripheral clock enabling */ \
  98. tmpreg = READ_BIT(RCC->APBENR2, RCC_APBENR2_USART1EN);\
  99. UNUSED(tmpreg); \
  100. } while(0U)
  101. #define __GPIOB_CLK_ENABLE() do { \
  102. __IO uint32_t tmpreg = 0x00U; \
  103. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN);\
  104. /* Delay after an RCC peripheral clock enabling */ \
  105. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOBEN);\
  106. UNUSED(tmpreg); \
  107. } while(0U)
  108. #define DEBUG_USART_RX_GPIO_PORT GPIOB
  109. #define DEBUG_USART_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  110. #define DEBUG_USART_RX_PIN GPIO_PIN_5
  111. #define DEBUG_USART_RX_AF GPIO_AF1_USART1
  112. #define DEBUG_USART_TX_GPIO_PORT GPIOB
  113. #define DEBUG_USART_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
  114. #define DEBUG_USART_TX_PIN GPIO_PIN_4
  115. #define DEBUG_USART_TX_AF GPIO_AF1_USART1
  116. #define DEBUG_USART_IRQHandler USART1_IRQHandler
  117. #define DEBUG_USART_IRQ USART1_IRQn
  118. #endif
  119. /************************************************************/
  120. #ifdef HAL_UART_MODULE_ENABLED
  121. extern UART_HandleTypeDef DebugUartHandle;
  122. #endif
  123. /** @defgroup Functions
  124. * @{
  125. */
  126. uint32_t BSP_GetVersion(void);
  127. void BSP_LED_Init(Led_TypeDef Led);
  128. void BSP_LED_DeInit(Led_TypeDef Led);
  129. void BSP_LED_On(Led_TypeDef Led);
  130. void BSP_LED_Off(Led_TypeDef Led);
  131. void BSP_LED_Toggle(Led_TypeDef Led);
  132. void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
  133. void BSP_PB_DeInit(Button_TypeDef Button);
  134. uint32_t BSP_PB_GetState(Button_TypeDef Button);
  135. void BSP_USART_Config(void);
  136. #define DEBUG_USART_Config BSP_USART_Config
  137. /**
  138. * @}
  139. */
  140. /**
  141. * @}
  142. */
  143. #ifdef __cplusplus
  144. }
  145. #endif
  146. #endif /* PY32F002B_START_KIT_H */
  147. /************************ (C) COPYRIGHT Puya *****END OF FILE****/