1717/*
1818 we have up to 512k of flash, but only use 64k for now
1919 */
20+ #ifndef BOARD_FLASH_SIZE
2021#define BOARD_FLASH_SIZE 64
22+ #endif
2123
2224#define GPIO_PIN (n ) (1U<<(n))
2325
2729
2830#define GPIO_OUTPUT_PUSH_PULL LL_GPIO_OUTPUT_PUSHPULL
2931
32+ #ifdef PORT_LETTER
3033static inline void gpio_mode_set_input (uint32_t pin , uint32_t pull_up_down )
3134{
3235 LL_GPIO_SetPinMode (input_port , pin , LL_GPIO_MODE_INPUT );
@@ -53,6 +56,7 @@ static inline bool gpio_read(uint32_t pin)
5356{
5457 return LL_GPIO_IsInputPinSet (input_port , pin );
5558}
59+ #endif // PORT_LETTER
5660
5761#define BL_TIMER TIM2
5862
@@ -102,28 +106,37 @@ static inline void bl_clock_config(void)
102106 while (LL_FLASH_GetLatency ()!= LL_FLASH_LATENCY_4 ) ;
103107 LL_PWR_SetRegulVoltageScaling (LL_PWR_REGU_VOLTAGE_SCALE1 );
104108 while (LL_PWR_IsActiveFlag_VOS () != 0 ) ;
105-
106109 LL_RCC_HSI_Enable ();
107-
108- /* Wait till HSI is ready */
109110 while (LL_RCC_HSI_IsReady () != 1 ) ;
110111
112+ LL_RCC_SetAHBPrescaler (LL_RCC_SYSCLK_DIV_1 );
113+ LL_RCC_SetAPB1Prescaler (LL_RCC_APB1_DIV_1 );
114+ LL_RCC_SetAPB2Prescaler (LL_RCC_APB2_DIV_1 );
115+
111116 LL_RCC_PLL_ConfigDomain_SYS (LL_RCC_PLLSOURCE_HSI , LL_RCC_PLLM_DIV_2 , 40 , LL_RCC_PLLR_DIV_2 );
112117 LL_RCC_PLL_EnableDomain_SYS ();
113- LL_RCC_PLL_Enable ();
114118
115- /* Wait till PLL is ready */
119+ #if DRONECAN_SUPPORT
120+ LL_RCC_SetFDCANClockSource (LL_RCC_FDCAN_CLKSOURCE_PLL );
121+ LL_RCC_PLL_EnableDomain_48M ();
122+ MODIFY_REG (RCC -> PLLCFGR , RCC_PLLCFGR_PLLQ , LL_RCC_PLLQ_DIV_4 );
123+
124+ // also enable the backup domain registers in TAMP for communication
125+ // between bootloader and main firmware
126+ LL_APB1_GRP1_EnableClock (LL_APB1_GRP1_PERIPH_PWR );
127+ PWR -> CR1 |= PWR_CR1_DBP ;
128+ LL_RCC_SetRTCClockSource (LL_RCC_RTC_CLKSOURCE_NONE );
129+ RCC -> BDCR |= RCC_BDCR_RTCEN ;
130+ #endif
131+
132+ LL_RCC_PLL_Enable ();
116133 while (LL_RCC_PLL_IsReady () != 1 ) ;
117- LL_RCC_SetSysClkSource (LL_RCC_SYS_CLKSOURCE_PLL );
118134
119- /* Wait till System clock is ready */
135+ LL_RCC_SetSysClkSource ( LL_RCC_SYS_CLKSOURCE_PLL );
120136 while (LL_RCC_GetSysClkSource () != LL_RCC_SYS_CLKSOURCE_STATUS_PLL ) ;
121-
122- LL_RCC_SetAHBPrescaler (LL_RCC_SYSCLK_DIV_1 );
123- LL_RCC_SetAPB1Prescaler (LL_RCC_APB1_DIV_1 );
124- LL_RCC_SetAPB2Prescaler (LL_RCC_APB2_DIV_1 );
125137}
126138
139+ #ifdef PORT_LETTER
127140static inline void bl_gpio_init (void )
128141{
129142 LL_GPIO_InitTypeDef GPIO_InitStruct = {0 };
@@ -180,3 +193,4 @@ static inline void jump_to_application(void)
180193void SystemInit ()
181194{
182195}
196+ #endif // PORT_LETTER
0 commit comments