|
| 1 | +/* |
| 2 | + ******************************************************************************* |
| 3 | + * Copyright (c) 2020, STMicroelectronics |
| 4 | + * All rights reserved. |
| 5 | + * |
| 6 | + * This software component is licensed by ST under BSD 3-Clause license, |
| 7 | + * the "License"; You may not use this file except in compliance with the |
| 8 | + * License. You may obtain a copy of the License at: |
| 9 | + * opensource.org/licenses/BSD-3-Clause |
| 10 | + * |
| 11 | + ******************************************************************************* |
| 12 | + */ |
| 13 | +#if defined(ARDUINO_PHOQUE2) |
| 14 | +#include "pins_arduino.h" |
| 15 | +#include "pinmap.h" |
| 16 | + |
| 17 | +// Digital PinName array |
| 18 | +extern "C" const PinName digitalPin[] = { |
| 19 | + PA_0, // D0/A0 |
| 20 | + PA_1, // D1/A1 |
| 21 | + PA_2, // D2/A2 |
| 22 | + PA_3, // D3/A3 |
| 23 | + PA_4, // D4/A4 |
| 24 | + PA_5, // D5/A5 |
| 25 | + PA_6, // D6/A6 |
| 26 | + PA_7, // D7/A7 |
| 27 | + PA_8, // D8 |
| 28 | + PA_9, // D9 |
| 29 | + PA_10, // D10 |
| 30 | + PA_11, // D11 |
| 31 | + PA_12, // D12 |
| 32 | + PA_13, // D13 |
| 33 | + PA_14, // D14 |
| 34 | + PA_15, // D15 |
| 35 | + PB_0, // D16/A8 |
| 36 | + PB_1, // D17/A9 |
| 37 | + PB_2, // D18/A10 |
| 38 | + PB_3, // D19 |
| 39 | + PB_4, // D20 |
| 40 | + PB_5, // D21 |
| 41 | + PB_6, // D22 |
| 42 | + PB_7, // D23 |
| 43 | + PB_8, // D24 |
| 44 | + PB_9, // D25 |
| 45 | + PB_10, // D26 |
| 46 | + PB_11, // D27/A11 |
| 47 | + PB_12, // D28/A12 |
| 48 | + PB_13, // D29 |
| 49 | + PB_14, // D30/A13 |
| 50 | + PB_15, // D31/A14 |
| 51 | + PC_4, // D32/A15 |
| 52 | + PC_6, // D33 |
| 53 | + PC_10, // D34 |
| 54 | + PC_11, // D35 |
| 55 | + PC_13, // D36 |
| 56 | + PC_14, // D37 |
| 57 | + PC_15, // D38 |
| 58 | + PF_0, // D39/A16 |
| 59 | + PF_1, // D40/A17 |
| 60 | + PG_10 // D41 |
| 61 | +}; |
| 62 | + |
| 63 | +// Analog (Ax) pin number array |
| 64 | +extern "C" const uint32_t analogInputPin[] = { |
| 65 | + 0, // A0, PA0 |
| 66 | + 1, // A1, PA1 |
| 67 | + 2, // A2, PA2 |
| 68 | + 3, // A3, PA3 |
| 69 | + 4, // A4, PA4 |
| 70 | + 5, // A5, PA5 |
| 71 | + 6, // A6, PA6 |
| 72 | + 7, // A7, PA7 |
| 73 | + 16, // A8, PB0 |
| 74 | + 17, // A9, PB1 |
| 75 | + 18, // A10, PB2 |
| 76 | + 27, // A11, PB11 |
| 77 | + 28, // A12, PB12 |
| 78 | + 30, // A13, PB14 |
| 79 | + 31, // A14, PB15 |
| 80 | + 32, // A15, PC4 |
| 81 | + 39, // A16, PF0 |
| 82 | + 40 // A17, PF1 |
| 83 | +}; |
| 84 | + |
| 85 | +__weak void SystemClock_Config(void) |
| 86 | +{ |
| 87 | + RCC_OscInitTypeDef RCC_OscInitStruct = {}; |
| 88 | + RCC_ClkInitTypeDef RCC_ClkInitStruct = {}; |
| 89 | + |
| 90 | + /** Configure the main internal regulator output voltage |
| 91 | + */ |
| 92 | + HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST); |
| 93 | + |
| 94 | + /** Initializes the RCC Oscillators according to the specified parameters |
| 95 | + * in the RCC_OscInitTypeDef structure. |
| 96 | + */ |
| 97 | + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSE; |
| 98 | + RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
| 99 | + RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
| 100 | + RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; |
| 101 | + RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; |
| 102 | + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
| 103 | + #if PHOQUE_PLL_HSI |
| 104 | + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
| 105 | + RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4; |
| 106 | + #else |
| 107 | + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
| 108 | + RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV2; |
| 109 | + #endif |
| 110 | + RCC_OscInitStruct.PLL.PLLN = 85; |
| 111 | + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; |
| 112 | + RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; |
| 113 | + RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; |
| 114 | + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
| 115 | + { |
| 116 | + Error_Handler(); |
| 117 | + } |
| 118 | + |
| 119 | + /** Initializes the CPU, AHB and APB buses clocks |
| 120 | + */ |
| 121 | + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
| 122 | + |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
| 123 | + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
| 124 | + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
| 125 | + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
| 126 | + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
| 127 | + |
| 128 | + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) |
| 129 | + { |
| 130 | + Error_Handler(); |
| 131 | + } |
| 132 | + |
| 133 | + RCC_PeriphCLKInitTypeDef PeriphClkInit; |
| 134 | + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_FDCAN | RCC_PERIPHCLK_USB | RCC_PERIPHCLK_RNG | RCC_PERIPHCLK_LPUART1 | RCC_PERIPHCLK_I2C1; |
| 135 | + PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1; |
| 136 | + PeriphClkInit.FdcanClockSelection = RCC_FDCANCLKSOURCE_PLL; //CAN will run at 170MHz (PLLQ) |
| 137 | + PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1; //I2C1 at 170MHz |
| 138 | + PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; |
| 139 | + PeriphClkInit.RngClockSelection = RCC_RNGCLKSOURCE_HSI48; |
| 140 | + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) |
| 141 | + { |
| 142 | + Error_Handler(); |
| 143 | + } |
| 144 | + |
| 145 | +} |
| 146 | + |
| 147 | +#endif /* ARDUINO_PHOQUE2* */ |
0 commit comments