|
| 1 | +/* |
| 2 | + * The MIT License (MIT) |
| 3 | + * |
| 4 | + * Copyright (c) 2018 Ha Thach for Adafruit Industries |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | + * THE SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +#ifndef BOARD_H_ |
| 26 | +#define BOARD_H_ |
| 27 | + |
| 28 | +//--------------------------------------------------------------------+ |
| 29 | +// LED |
| 30 | +//--------------------------------------------------------------------+ |
| 31 | + |
| 32 | +#define LED_PORT GPIOC |
| 33 | +#define LED_PIN GPIO_PIN_13 |
| 34 | +#define LED_STATE_ON 1 |
| 35 | + |
| 36 | +//--------------------------------------------------------------------+ |
| 37 | +// Button |
| 38 | +//--------------------------------------------------------------------+ |
| 39 | +#define BUTTON_PORT GPIOA |
| 40 | +#define BUTTON_PIN GPIO_PIN_0 |
| 41 | +#define BUTTON_STATE_ACTIVE 0 |
| 42 | + |
| 43 | +//--------------------------------------------------------------------+ |
| 44 | +// UART Enable for STLink VCOM |
| 45 | +//--------------------------------------------------------------------+ |
| 46 | +#define UART_DEV USART3 |
| 47 | +#define UART_CLOCK_ENABLE __HAL_RCC_USART3_CLK_ENABLE |
| 48 | +#define UART_CLOCK_DISABLE __HAL_RCC_USART3_CLK_DISABLE |
| 49 | +#define UART_GPIO_PORT GPIOA |
| 50 | +#define UART_GPIO_AF GPIO_AF13_USART3 |
| 51 | + |
| 52 | +#define UART_TX_PIN GPIO_PIN_3 |
| 53 | +#define UART_RX_PIN GPIO_PIN_4 |
| 54 | + |
| 55 | +//--------------------------------------------------------------------+ |
| 56 | +// Neopixel |
| 57 | +//--------------------------------------------------------------------+ |
| 58 | + |
| 59 | +// Number of neopixels |
| 60 | +#define NEOPIXEL_NUMBER 0 |
| 61 | +// Brightness percentage from 1 to 255 |
| 62 | +#define NEOPIXEL_BRIGHTNESS 0x10 |
| 63 | + |
| 64 | +#define NEOPIXEL_PORT GPIOC |
| 65 | +#define NEOPIXEL_PIN GPIO_PIN_0 |
| 66 | +#define NEOPIXEL_PIN_MODE GPIO_MODE_OUTPUT_PP |
| 67 | + |
| 68 | +//--------------------------------------------------------------------+ |
| 69 | +// Flash |
| 70 | +//--------------------------------------------------------------------+ |
| 71 | + |
| 72 | +// Flash size of the board |
| 73 | +#define BOARD_FLASH_SIZE FLASH_SIZE |
| 74 | + |
| 75 | +//--------------------------------------------------------------------+ |
| 76 | +// USB UF2 |
| 77 | +//--------------------------------------------------------------------+ |
| 78 | + |
| 79 | +// 239A:0163 is a generic VID/PID for STM32H5, when using it USB_MANUFACTURER/USB_PRODUCT cannot be changed |
| 80 | +#define USB_VID 0x239A |
| 81 | +#define USB_PID 0x0163 |
| 82 | +#define USB_MANUFACTURER "ST" |
| 83 | +#define USB_PRODUCT "TinyUF2 for STM32H5" |
| 84 | + |
| 85 | +#define UF2_PRODUCT_NAME USB_MANUFACTURER " " USB_PRODUCT |
| 86 | +#define UF2_BOARD_ID "STM32H503-Coreboard" |
| 87 | +#define UF2_VOLUME_LABEL "STMH503BOOT" |
| 88 | +#define UF2_INDEX_URL "https://github.com/WeActStudio/WeActStudio.STM32H503CoreBoard" |
| 89 | + |
| 90 | +//--------------------------------------------------------------------+ |
| 91 | +// RCC Clock |
| 92 | +//--------------------------------------------------------------------+ |
| 93 | +static inline void SystemClock_Config(void) |
| 94 | +{ |
| 95 | + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
| 96 | + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
| 97 | + |
| 98 | + /** Configure the main internal regulator output voltage |
| 99 | + */ |
| 100 | + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0); |
| 101 | + |
| 102 | + while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {} |
| 103 | + |
| 104 | + /** Initializes the RCC Oscillators according to the specified parameters |
| 105 | + * in the RCC_OscInitTypeDef structure. |
| 106 | + */ |
| 107 | + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSE; |
| 108 | + RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
| 109 | + RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; |
| 110 | + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
| 111 | + RCC_OscInitStruct.PLL.PLLSource = RCC_PLL1_SOURCE_HSE; |
| 112 | + RCC_OscInitStruct.PLL.PLLM = 4; |
| 113 | + RCC_OscInitStruct.PLL.PLLN = 250; |
| 114 | + RCC_OscInitStruct.PLL.PLLP = 2; |
| 115 | + RCC_OscInitStruct.PLL.PLLQ = 2; |
| 116 | + RCC_OscInitStruct.PLL.PLLR = 2; |
| 117 | + RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1_VCIRANGE_1; |
| 118 | + RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1_VCORANGE_WIDE; |
| 119 | + RCC_OscInitStruct.PLL.PLLFRACN = 0; |
| 120 | + HAL_RCC_OscConfig(&RCC_OscInitStruct); |
| 121 | + |
| 122 | + /** Initializes the CPU, AHB and APB buses clocks |
| 123 | + */ |
| 124 | + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
| 125 | + |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2 |
| 126 | + |RCC_CLOCKTYPE_PCLK3; |
| 127 | + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
| 128 | + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
| 129 | + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
| 130 | + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
| 131 | + RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1; |
| 132 | + HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5); |
| 133 | + |
| 134 | + // Configure CRS clock source |
| 135 | + __HAL_RCC_CRS_CLK_ENABLE(); |
| 136 | + RCC_CRSInitTypeDef RCC_CRSInitStruct = {0}; |
| 137 | + RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1; |
| 138 | + RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB; |
| 139 | + RCC_CRSInitStruct.Polarity = RCC_CRS_SYNC_POLARITY_RISING; |
| 140 | + RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000, 1000); |
| 141 | + RCC_CRSInitStruct.ErrorLimitValue = 34; |
| 142 | + RCC_CRSInitStruct.HSI48CalibrationValue = 32; |
| 143 | + HAL_RCCEx_CRSConfig(&RCC_CRSInitStruct); |
| 144 | + |
| 145 | + /* Select HSI48 as USB clock source */ |
| 146 | + RCC_PeriphCLKInitTypeDef usb_clk = {0 }; |
| 147 | + usb_clk.PeriphClockSelection = RCC_PERIPHCLK_USB; |
| 148 | + usb_clk.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; |
| 149 | + HAL_RCCEx_PeriphCLKConfig(&usb_clk); |
| 150 | + |
| 151 | + /* Peripheral clock enable */ |
| 152 | + __HAL_RCC_USB_CLK_ENABLE(); |
| 153 | +} |
| 154 | + |
| 155 | +#endif |
0 commit comments