option to boot at 4MHz with no USB
This commit is contained in:
parent
121070822f
commit
20f8aac768
@ -108,7 +108,9 @@ void device_reboot()
|
||||
void device_init()
|
||||
{
|
||||
hw_init();
|
||||
#ifndef IS_BOOTLOADER
|
||||
nfc_init();
|
||||
#endif
|
||||
LL_GPIO_SetPinMode(SOLO_BUTTON_PORT,SOLO_BUTTON_PIN,LL_GPIO_MODE_INPUT);
|
||||
LL_GPIO_SetPinPull(SOLO_BUTTON_PORT,SOLO_BUTTON_PIN,LL_GPIO_PULL_UP);
|
||||
|
||||
@ -395,7 +397,9 @@ void device_manage()
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifndef IS_BOOTLOADER
|
||||
nfc_loop();
|
||||
#endif
|
||||
}
|
||||
|
||||
static int handle_packets()
|
||||
|
@ -122,13 +122,15 @@ static void LL_Init(void)
|
||||
NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
|
||||
|
||||
}
|
||||
|
||||
static int NFC = 0;
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
if (!NFC)
|
||||
{
|
||||
|
||||
LL_FLASH_SetLatency(LL_FLASH_LATENCY_2);
|
||||
|
||||
@ -208,10 +210,70 @@ void SystemClock_Config(void)
|
||||
|
||||
/* SysTick_IRQn interrupt configuration */
|
||||
NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
LL_FLASH_SetLatency(LL_FLASH_LATENCY_0);
|
||||
|
||||
if(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_0)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
|
||||
|
||||
LL_RCC_LSI_Enable();
|
||||
|
||||
/* Wait till LSI is ready */
|
||||
while(LL_RCC_LSI_IsReady() != 1)
|
||||
{
|
||||
|
||||
}
|
||||
LL_RCC_MSI_Enable();
|
||||
|
||||
/* Wait till MSI is ready */
|
||||
while(LL_RCC_MSI_IsReady() != 1)
|
||||
{
|
||||
|
||||
}
|
||||
LL_RCC_MSI_EnableRangeSelection();
|
||||
|
||||
LL_RCC_MSI_SetRange(LL_RCC_MSIRANGE_6);
|
||||
|
||||
LL_RCC_MSI_SetCalibTrimming(0);
|
||||
|
||||
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_MSI);
|
||||
|
||||
/* Wait till System clock is ready */
|
||||
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_MSI)
|
||||
{
|
||||
|
||||
}
|
||||
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
|
||||
|
||||
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
|
||||
|
||||
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
|
||||
|
||||
LL_Init1msTick(4000000);
|
||||
|
||||
LL_SYSTICK_SetClkSource(LL_SYSTICK_CLKSOURCE_HCLK);
|
||||
|
||||
LL_SetSystemCoreClock(4000000);
|
||||
|
||||
LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2);
|
||||
|
||||
LL_RCC_SetRNGClockSource(LL_RCC_RNG_CLKSOURCE_MSI);
|
||||
|
||||
/* SysTick_IRQn interrupt configuration */
|
||||
NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void usb_init()
|
||||
{
|
||||
if (!NFC)
|
||||
{
|
||||
// enable USB power
|
||||
SET_BIT(PWR->CR2, PWR_CR2_USV);
|
||||
|
||||
@ -234,12 +296,14 @@ void usb_init()
|
||||
USBD_CDC_RegisterInterface(&Solo_USBD_Device, &USBD_Interface_fops_FS);
|
||||
|
||||
USBD_Start(&Solo_USBD_Device);
|
||||
}
|
||||
}
|
||||
|
||||
/* TIM2 init function */
|
||||
static void MX_TIM2_Init(void)
|
||||
{
|
||||
|
||||
// if(!NFC)
|
||||
{
|
||||
LL_TIM_InitTypeDef TIM_InitStruct;
|
||||
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct;
|
||||
|
||||
@ -305,6 +369,7 @@ static void MX_TIM2_Init(void)
|
||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
LL_TIM_EnableCounter(TIM2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -369,7 +434,11 @@ static void MX_TIM6_Init(void)
|
||||
|
||||
// 48 MHz sys clock --> 6 MHz timer clock
|
||||
// 48 MHz / 48000 == 1000 Hz
|
||||
if (!NFC)
|
||||
TIM_InitStruct.Prescaler = 48000;
|
||||
else
|
||||
TIM_InitStruct.Prescaler = 4000;
|
||||
|
||||
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
|
||||
TIM_InitStruct.Autoreload = 90;
|
||||
LL_TIM_Init(TIM6, &TIM_InitStruct);
|
||||
@ -458,7 +527,10 @@ static void MX_SPI1_Init(void)
|
||||
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
|
||||
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE;
|
||||
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
|
||||
if (!NFC)
|
||||
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV64;
|
||||
else
|
||||
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV8;
|
||||
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
|
||||
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
|
||||
SPI_InitStruct.CRCPoly = 7;
|
||||
|
@ -37,15 +37,18 @@ void _putchar(char c)
|
||||
LL_USART_TransmitData8(DEBUG_UART,c);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int NFC = 0;
|
||||
|
||||
|
||||
int _write (int fd, const void *buf, long int len)
|
||||
{
|
||||
uint8_t * data = (uint8_t *) buf;
|
||||
|
||||
if (!NFC)
|
||||
{
|
||||
// Send out USB serial
|
||||
CDC_Transmit_FS(data, len);
|
||||
}
|
||||
|
||||
// Send out UART serial
|
||||
while(len--)
|
||||
|
Loading…
x
Reference in New Issue
Block a user