Skip to content

Handle 8 and 12 MHz HSE values #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1117,14 +1117,20 @@ Genericflight.build.cmsis_lib_gcc=arm_cortexM3l_math
Genericflight.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.xSerial} {build.bootloader_flags}

# AfroFlight Rev5
Genericflight.menu.pnum.AFROFLIGHT_F103CB=Afro Flight Rev5
Genericflight.menu.pnum.AFROFLIGHT_F103CB=Afro Flight Rev5 (8MHz)
Genericflight.menu.pnum.AFROFLIGHT_F103CB.upload.maximum_size=131072
Genericflight.menu.pnum.AFROFLIGHT_F103CB.upload.maximum_data_size=20480
Genericflight.menu.pnum.AFROFLIGHT_F103CB.build.board=AFROFLIGHT_F103CB
Genericflight.menu.pnum.AFROFLIGHT_F103CB.build.series=STM32F1xx
Genericflight.menu.pnum.AFROFLIGHT_F103CB.build.product_line=STM32F103xB
Genericflight.menu.pnum.AFROFLIGHT_F103CB.build.variant=AFROFLIGHT_F103CB

Genericflight.menu.pnum.AFROFLIGHT_F103CB_12M=Afro Flight Rev5 (12MHz)
Genericflight.menu.pnum.AFROFLIGHT_F103CB_12M.upload.maximum_size=131072
Genericflight.menu.pnum.AFROFLIGHT_F103CB_12M.upload.maximum_data_size=20480
Genericflight.menu.pnum.AFROFLIGHT_F103CB_12M.build.board=AFROFLIGHT_F103CB_12M
Genericflight.menu.pnum.AFROFLIGHT_F103CB_12M.build.product_line=STM32F103xB
Genericflight.menu.pnum.AFROFLIGHT_F103CB_12M.build.variant=AFROFLIGHT_F103CB

# Upload menu
Genericflight.menu.upload_method.swdMethod=STM32CubeProgrammer (SWD)
Genericflight.menu.upload_method.swdMethod.upload.protocol=0
Expand Down
30 changes: 16 additions & 14 deletions variants/AFROFLIGHT_F103CB/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,28 @@ extern "C" {
*/
WEAK void SystemClock_Config(void)
{
// Board has external 12MHz Xtal, currenlty using HSI internal Xtal
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;
RCC_OscInitTypeDef RCC_OscInitStruct = {};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {};

/* Initializes the CPU, AHB and APB busses clocks */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
#ifdef ARDUINO_AFROFLIGHT_F103CB_12M
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
#else /* 8 MHz */
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
#endif
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
Error_Handler();
}

/* Initializes the CPU, AHB and APB busses clocks */
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
Expand All @@ -116,9 +119,8 @@ WEAK void SystemClock_Config(void)
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
Error_Handler();
}

PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
Error_Handler();
}
Expand Down
4 changes: 4 additions & 0 deletions variants/AFROFLIGHT_F103CB/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ extern "C" {
*
*/

#ifdef ARDUINO_AFROFLIGHT_F103CB_12M
#define HSE_VALUE 12000000U /*!< Value of the External oscillator in Hz */
#endif

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down