py32f030xx_Start_Kit.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /**
  2. ******************************************************************************
  3. * @file py32f030xx_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 PY32F030_START_KIT_H
  33. #define PY32F030_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 py32f0xx_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 py32f0xx_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 StartKitVersion 2
  67. /* #define StartKitVersion 1 */
  68. #define LEDn 1
  69. #define LED3_PIN GPIO_PIN_11
  70. #define LED3_GPIO_PORT GPIOA
  71. #define LED3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  72. #define LED3_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  73. #define LEDx_GPIO_CLK_ENABLE(__INDEX__) do {LED3_GPIO_CLK_ENABLE(); } while(0U)
  74. #define LEDx_GPIO_CLK_DISABLE(__INDEX__) LED3_GPIO_CLK_DISABLE()
  75. #define BUTTONn 1
  76. /**
  77. * @brief User push-button
  78. */
  79. #define USER_BUTTON_PIN GPIO_PIN_12
  80. #define USER_BUTTON_GPIO_PORT GPIOA
  81. #define USER_BUTTON_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  82. #define USER_BUTTON_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
  83. #define USER_BUTTON_EXTI_IRQn EXTI4_15_IRQn
  84. /* Aliases */
  85. #define KEY_BUTTON_PIN USER_BUTTON_PIN
  86. #define KEY_BUTTON_GPIO_PORT USER_BUTTON_GPIO_PORT
  87. #define KEY_BUTTON_GPIO_CLK_ENABLE() USER_BUTTON_GPIO_CLK_ENABLE()
  88. #define KEY_BUTTON_GPIO_CLK_DISABLE() USER_BUTTON_GPIO_CLK_DISABLE()
  89. #define KEY_BUTTON_EXTI_IRQn USER_BUTTON_EXTI_IRQn
  90. #define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == 0) USER_BUTTON_GPIO_CLK_ENABLE();} while(0)
  91. #define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? USER_BUTTON_GPIO_CLK_DISABLE() : 0)
  92. #ifdef HAL_UART_MODULE_ENABLED
  93. //debug printf redirect config
  94. #define DEBUG_USART_BAUDRATE 115200
  95. #define DEBUG_USART USART2
  96. #define DEBUG_USART_CLK_ENABLE() do { \
  97. __IO uint32_t tmpreg = 0x00U; \
  98. SET_BIT(RCC->APBENR1, RCC_APBENR1_USART2EN);\
  99. /* Delay after an RCC peripheral clock enabling */ \
  100. tmpreg = READ_BIT(RCC->APBENR1, RCC_APBENR1_USART2EN);\
  101. UNUSED(tmpreg); \
  102. } while(0U)
  103. #define __GPIOA_CLK_ENABLE() do { \
  104. __IO uint32_t tmpreg = 0x00U; \
  105. SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
  106. /* Delay after an RCC peripheral clock enabling */ \
  107. tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
  108. UNUSED(tmpreg); \
  109. } while(0U)
  110. #define DEBUG_USART_RX_GPIO_PORT GPIOA
  111. #define DEBUG_USART_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  112. #define DEBUG_USART_RX_PIN GPIO_PIN_3
  113. #define DEBUG_USART_RX_AF GPIO_AF4_USART2
  114. #define DEBUG_USART_TX_GPIO_PORT GPIOA
  115. #define DEBUG_USART_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  116. #define DEBUG_USART_TX_PIN GPIO_PIN_2
  117. #define DEBUG_USART_TX_AF GPIO_AF4_USART2
  118. #define DEBUG_USART_IRQHandler USART2_IRQHandler
  119. #define DEBUG_USART_IRQ USART2_IRQn
  120. #else
  121. #define DEBUG_USART_TX_GPIO_PORT GPIOA
  122. #define DEBUG_USART_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
  123. #define DEBUG_USART_TX_PIN GPIO_PIN_2
  124. #endif
  125. /************************************************************/
  126. #ifdef HAL_UART_MODULE_ENABLED
  127. extern UART_HandleTypeDef DebugUartHandle;
  128. #endif
  129. /** @defgroup Functions
  130. * @{
  131. */
  132. uint32_t BSP_GetVersion(void);
  133. void BSP_LED_Init(Led_TypeDef Led);
  134. void BSP_LED_DeInit(Led_TypeDef Led);
  135. void BSP_LED_On(Led_TypeDef Led);
  136. void BSP_LED_Off(Led_TypeDef Led);
  137. void BSP_LED_Toggle(Led_TypeDef Led);
  138. void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
  139. void BSP_PB_DeInit(Button_TypeDef Button);
  140. uint32_t BSP_PB_GetState(Button_TypeDef Button);
  141. void BSP_USART_Config(void);
  142. #define DEBUG_USART_Config BSP_USART_Config
  143. /**
  144. * @}
  145. */
  146. /**
  147. * @}
  148. */
  149. #ifdef __cplusplus
  150. }
  151. #endif
  152. #endif /* PY32F030xx_START_KIT_H */
  153. /************************ (C) COPYRIGHT Puya *****END OF FILE****/