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()
|
void device_init()
|
||||||
{
|
{
|
||||||
hw_init();
|
hw_init();
|
||||||
nfc_init();
|
#ifndef IS_BOOTLOADER
|
||||||
|
nfc_init();
|
||||||
|
#endif
|
||||||
LL_GPIO_SetPinMode(SOLO_BUTTON_PORT,SOLO_BUTTON_PIN,LL_GPIO_MODE_INPUT);
|
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);
|
LL_GPIO_SetPinPull(SOLO_BUTTON_PORT,SOLO_BUTTON_PIN,LL_GPIO_PULL_UP);
|
||||||
|
|
||||||
@ -395,7 +397,9 @@ void device_manage()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef IS_BOOTLOADER
|
||||||
nfc_loop();
|
nfc_loop();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_packets()
|
static int handle_packets()
|
||||||
|
@ -122,189 +122,254 @@ static void LL_Init(void)
|
|||||||
NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
|
NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
static int NFC = 0;
|
||||||
/**
|
/**
|
||||||
* @brief System Clock Configuration
|
* @brief System Clock Configuration
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void SystemClock_Config(void)
|
void SystemClock_Config(void)
|
||||||
{
|
{
|
||||||
|
if (!NFC)
|
||||||
|
{
|
||||||
|
|
||||||
LL_FLASH_SetLatency(LL_FLASH_LATENCY_2);
|
LL_FLASH_SetLatency(LL_FLASH_LATENCY_2);
|
||||||
|
|
||||||
if(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_2)
|
if(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_2)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
|
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
|
||||||
|
|
||||||
LL_RCC_HSI48_Enable();
|
LL_RCC_HSI48_Enable();
|
||||||
|
|
||||||
/* Wait till HSI48 is ready */
|
/* Wait till HSI48 is ready */
|
||||||
while(LL_RCC_HSI48_IsReady() != 1)
|
while(LL_RCC_HSI48_IsReady() != 1)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LL_RCC_LSI_Enable();
|
LL_RCC_LSI_Enable();
|
||||||
|
|
||||||
/* Wait till LSI is ready */
|
/* Wait till LSI is ready */
|
||||||
while(LL_RCC_LSI_IsReady() != 1)
|
while(LL_RCC_LSI_IsReady() != 1)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
LL_RCC_MSI_Enable();
|
LL_RCC_MSI_Enable();
|
||||||
/* Wait till MSI is ready */
|
/* Wait till MSI is ready */
|
||||||
while(LL_RCC_MSI_IsReady() != 1)
|
while(LL_RCC_MSI_IsReady() != 1)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
LL_RCC_MSI_EnableRangeSelection();
|
LL_RCC_MSI_EnableRangeSelection();
|
||||||
|
|
||||||
LL_RCC_MSI_SetRange(LL_RCC_MSIRANGE_11);
|
LL_RCC_MSI_SetRange(LL_RCC_MSIRANGE_11);
|
||||||
|
|
||||||
LL_RCC_MSI_SetCalibTrimming(0);
|
LL_RCC_MSI_SetCalibTrimming(0);
|
||||||
|
|
||||||
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_MSI);
|
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_MSI);
|
||||||
|
|
||||||
/* Wait till System clock is ready */
|
/* Wait till System clock is ready */
|
||||||
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_MSI)
|
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_MSI)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
|
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
|
||||||
|
|
||||||
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
|
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
|
||||||
|
|
||||||
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_16);
|
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_16);
|
||||||
|
|
||||||
LL_Init1msTick(48000000);
|
LL_Init1msTick(48000000);
|
||||||
|
|
||||||
LL_SYSTICK_SetClkSource(LL_SYSTICK_CLKSOURCE_HCLK);
|
LL_SYSTICK_SetClkSource(LL_SYSTICK_CLKSOURCE_HCLK);
|
||||||
|
|
||||||
LL_SetSystemCoreClock(48000000);
|
LL_SetSystemCoreClock(48000000);
|
||||||
|
|
||||||
LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2);
|
LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2);
|
||||||
|
|
||||||
LL_RCC_SetUSBClockSource(LL_RCC_USB_CLKSOURCE_HSI48);
|
LL_RCC_SetUSBClockSource(LL_RCC_USB_CLKSOURCE_HSI48);
|
||||||
|
|
||||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_CRS);
|
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_CRS);
|
||||||
|
|
||||||
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_CRS);
|
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_CRS);
|
||||||
|
|
||||||
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_CRS);
|
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_CRS);
|
||||||
|
|
||||||
LL_CRS_SetSyncDivider(LL_CRS_SYNC_DIV_1);
|
LL_CRS_SetSyncDivider(LL_CRS_SYNC_DIV_1);
|
||||||
|
|
||||||
LL_CRS_SetSyncPolarity(LL_CRS_SYNC_POLARITY_RISING);
|
LL_CRS_SetSyncPolarity(LL_CRS_SYNC_POLARITY_RISING);
|
||||||
|
|
||||||
LL_CRS_SetSyncSignalSource(LL_CRS_SYNC_SOURCE_USB);
|
LL_CRS_SetSyncSignalSource(LL_CRS_SYNC_SOURCE_USB);
|
||||||
|
|
||||||
LL_CRS_SetReloadCounter(__LL_CRS_CALC_CALCULATE_RELOADVALUE(48000000,1000));
|
LL_CRS_SetReloadCounter(__LL_CRS_CALC_CALCULATE_RELOADVALUE(48000000,1000));
|
||||||
|
|
||||||
LL_CRS_SetFreqErrorLimit(34);
|
LL_CRS_SetFreqErrorLimit(34);
|
||||||
|
|
||||||
LL_CRS_SetHSI48SmoothTrimming(32);
|
LL_CRS_SetHSI48SmoothTrimming(32);
|
||||||
|
|
||||||
|
/* 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));
|
||||||
|
}
|
||||||
|
|
||||||
/* SysTick_IRQn interrupt configuration */
|
|
||||||
NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_init()
|
void usb_init()
|
||||||
{
|
{
|
||||||
// enable USB power
|
if (!NFC)
|
||||||
SET_BIT(PWR->CR2, PWR_CR2_USV);
|
{
|
||||||
|
// enable USB power
|
||||||
|
SET_BIT(PWR->CR2, PWR_CR2_USV);
|
||||||
|
|
||||||
// Enable USB Clock
|
// Enable USB Clock
|
||||||
SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_USBFSEN);
|
SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_USBFSEN);
|
||||||
|
|
||||||
|
|
||||||
USBD_Composite_Set_Classes(&USBD_HID, &USBD_CDC);
|
USBD_Composite_Set_Classes(&USBD_HID, &USBD_CDC);
|
||||||
in_endpoint_to_class[HID_EPIN_ADDR & 0x7F] = 0;
|
in_endpoint_to_class[HID_EPIN_ADDR & 0x7F] = 0;
|
||||||
out_endpoint_to_class[HID_EPOUT_ADDR & 0x7F] = 0;
|
out_endpoint_to_class[HID_EPOUT_ADDR & 0x7F] = 0;
|
||||||
|
|
||||||
in_endpoint_to_class[CDC_IN_EP & 0x7F] = 1;
|
in_endpoint_to_class[CDC_IN_EP & 0x7F] = 1;
|
||||||
out_endpoint_to_class[CDC_OUT_EP & 0x7F] = 1;
|
out_endpoint_to_class[CDC_OUT_EP & 0x7F] = 1;
|
||||||
|
|
||||||
USBD_Init(&Solo_USBD_Device, &Solo_Desc, 0);
|
USBD_Init(&Solo_USBD_Device, &Solo_Desc, 0);
|
||||||
USBD_RegisterClass(&Solo_USBD_Device, &USBD_Composite);
|
USBD_RegisterClass(&Solo_USBD_Device, &USBD_Composite);
|
||||||
// USBD_RegisterClass(&Solo_USBD_Device, &USBD_HID);
|
// USBD_RegisterClass(&Solo_USBD_Device, &USBD_HID);
|
||||||
//
|
//
|
||||||
// USBD_RegisterClass(&Solo_USBD_Device, &USBD_CDC);
|
// USBD_RegisterClass(&Solo_USBD_Device, &USBD_CDC);
|
||||||
USBD_CDC_RegisterInterface(&Solo_USBD_Device, &USBD_Interface_fops_FS);
|
USBD_CDC_RegisterInterface(&Solo_USBD_Device, &USBD_Interface_fops_FS);
|
||||||
|
|
||||||
USBD_Start(&Solo_USBD_Device);
|
USBD_Start(&Solo_USBD_Device);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TIM2 init function */
|
/* TIM2 init function */
|
||||||
static void MX_TIM2_Init(void)
|
static void MX_TIM2_Init(void)
|
||||||
{
|
{
|
||||||
|
// if(!NFC)
|
||||||
|
{
|
||||||
|
LL_TIM_InitTypeDef TIM_InitStruct;
|
||||||
|
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct;
|
||||||
|
|
||||||
LL_TIM_InitTypeDef TIM_InitStruct;
|
LL_GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct;
|
|
||||||
|
|
||||||
LL_GPIO_InitTypeDef GPIO_InitStruct;
|
/* Peripheral clock enable */
|
||||||
|
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
||||||
|
|
||||||
/* Peripheral clock enable */
|
TIM2->SR = 0 ;
|
||||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
|
||||||
|
|
||||||
TIM2->SR = 0 ;
|
TIM_InitStruct.Prescaler = 0;
|
||||||
|
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
|
||||||
|
TIM_InitStruct.Autoreload = 1000;
|
||||||
|
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
|
||||||
|
LL_TIM_Init(TIM2, &TIM_InitStruct);
|
||||||
|
|
||||||
TIM_InitStruct.Prescaler = 0;
|
LL_TIM_EnableARRPreload(TIM2);
|
||||||
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
|
|
||||||
TIM_InitStruct.Autoreload = 1000;
|
|
||||||
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
|
|
||||||
LL_TIM_Init(TIM2, &TIM_InitStruct);
|
|
||||||
|
|
||||||
LL_TIM_EnableARRPreload(TIM2);
|
LL_TIM_SetClockSource(TIM2, LL_TIM_CLOCKSOURCE_INTERNAL);
|
||||||
|
|
||||||
LL_TIM_SetClockSource(TIM2, LL_TIM_CLOCKSOURCE_INTERNAL);
|
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
|
||||||
|
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_ENABLE;
|
||||||
|
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_ENABLE;
|
||||||
|
TIM_OC_InitStruct.CompareValue = 1000;
|
||||||
|
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
|
||||||
|
LL_TIM_OC_Init(TIM2, LL_TIM_CHANNEL_CH2, &TIM_OC_InitStruct);
|
||||||
|
|
||||||
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
|
LL_TIM_OC_DisableFast(TIM2, LL_TIM_CHANNEL_CH2);
|
||||||
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_ENABLE;
|
|
||||||
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_ENABLE;
|
|
||||||
TIM_OC_InitStruct.CompareValue = 1000;
|
|
||||||
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
|
|
||||||
LL_TIM_OC_Init(TIM2, LL_TIM_CHANNEL_CH2, &TIM_OC_InitStruct);
|
|
||||||
|
|
||||||
LL_TIM_OC_DisableFast(TIM2, LL_TIM_CHANNEL_CH2);
|
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_ENABLE;
|
||||||
|
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_ENABLE;
|
||||||
|
LL_TIM_OC_Init(TIM2, LL_TIM_CHANNEL_CH3, &TIM_OC_InitStruct);
|
||||||
|
|
||||||
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_ENABLE;
|
LL_TIM_OC_DisableFast(TIM2, LL_TIM_CHANNEL_CH3);
|
||||||
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_ENABLE;
|
|
||||||
LL_TIM_OC_Init(TIM2, LL_TIM_CHANNEL_CH3, &TIM_OC_InitStruct);
|
|
||||||
|
|
||||||
LL_TIM_OC_DisableFast(TIM2, LL_TIM_CHANNEL_CH3);
|
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_ENABLE;
|
||||||
|
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_ENABLE;
|
||||||
|
LL_TIM_OC_Init(TIM2, LL_TIM_CHANNEL_CH4, &TIM_OC_InitStruct);
|
||||||
|
|
||||||
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_ENABLE;
|
LL_TIM_OC_DisableFast(TIM2, LL_TIM_CHANNEL_CH4);
|
||||||
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_ENABLE;
|
|
||||||
LL_TIM_OC_Init(TIM2, LL_TIM_CHANNEL_CH4, &TIM_OC_InitStruct);
|
|
||||||
|
|
||||||
LL_TIM_OC_DisableFast(TIM2, LL_TIM_CHANNEL_CH4);
|
LL_TIM_SetOCRefClearInputSource(TIM2, LL_TIM_OCREF_CLR_INT_NC);
|
||||||
|
|
||||||
LL_TIM_SetOCRefClearInputSource(TIM2, LL_TIM_OCREF_CLR_INT_NC);
|
LL_TIM_DisableExternalClock(TIM2);
|
||||||
|
|
||||||
LL_TIM_DisableExternalClock(TIM2);
|
LL_TIM_ConfigETR(TIM2, LL_TIM_ETR_POLARITY_NONINVERTED, LL_TIM_ETR_PRESCALER_DIV1, LL_TIM_ETR_FILTER_FDIV1);
|
||||||
|
|
||||||
LL_TIM_ConfigETR(TIM2, LL_TIM_ETR_POLARITY_NONINVERTED, LL_TIM_ETR_PRESCALER_DIV1, LL_TIM_ETR_FILTER_FDIV1);
|
LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_RESET);
|
||||||
|
|
||||||
LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_RESET);
|
LL_TIM_DisableMasterSlaveMode(TIM2);
|
||||||
|
|
||||||
LL_TIM_DisableMasterSlaveMode(TIM2);
|
/**TIM2 GPIO Configuration
|
||||||
|
PA1 ------> TIM2_CH2
|
||||||
|
PA2 ------> TIM2_CH3
|
||||||
|
PA3 ------> TIM2_CH4
|
||||||
|
*/
|
||||||
|
GPIO_InitStruct.Pin = LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_3;
|
||||||
|
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||||
|
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||||
|
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||||
|
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||||
|
GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
|
||||||
|
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
/**TIM2 GPIO Configuration
|
LL_TIM_EnableCounter(TIM2);
|
||||||
PA1 ------> TIM2_CH2
|
}
|
||||||
PA2 ------> TIM2_CH3
|
|
||||||
PA3 ------> TIM2_CH4
|
|
||||||
*/
|
|
||||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_3;
|
|
||||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
|
||||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
|
||||||
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
||||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
||||||
GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
|
|
||||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
LL_TIM_EnableCounter(TIM2);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,29 +427,33 @@ static void MX_GPIO_Init(void)
|
|||||||
static void MX_TIM6_Init(void)
|
static void MX_TIM6_Init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
LL_TIM_InitTypeDef TIM_InitStruct;
|
LL_TIM_InitTypeDef TIM_InitStruct;
|
||||||
|
|
||||||
/* Peripheral clock enable */
|
/* Peripheral clock enable */
|
||||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM6);
|
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM6);
|
||||||
|
|
||||||
// 48 MHz sys clock --> 6 MHz timer clock
|
// 48 MHz sys clock --> 6 MHz timer clock
|
||||||
// 48 MHz / 48000 == 1000 Hz
|
// 48 MHz / 48000 == 1000 Hz
|
||||||
TIM_InitStruct.Prescaler = 48000;
|
if (!NFC)
|
||||||
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
|
TIM_InitStruct.Prescaler = 48000;
|
||||||
TIM_InitStruct.Autoreload = 90;
|
else
|
||||||
LL_TIM_Init(TIM6, &TIM_InitStruct);
|
TIM_InitStruct.Prescaler = 4000;
|
||||||
|
|
||||||
LL_TIM_DisableARRPreload(TIM6);
|
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
|
||||||
|
TIM_InitStruct.Autoreload = 90;
|
||||||
|
LL_TIM_Init(TIM6, &TIM_InitStruct);
|
||||||
|
|
||||||
LL_TIM_SetTriggerOutput(TIM6, LL_TIM_TRGO_RESET);
|
LL_TIM_DisableARRPreload(TIM6);
|
||||||
|
|
||||||
LL_TIM_DisableMasterSlaveMode(TIM6);
|
LL_TIM_SetTriggerOutput(TIM6, LL_TIM_TRGO_RESET);
|
||||||
|
|
||||||
// enable interrupt
|
LL_TIM_DisableMasterSlaveMode(TIM6);
|
||||||
TIM6->DIER |= 1;
|
|
||||||
|
|
||||||
// Start immediately
|
// enable interrupt
|
||||||
LL_TIM_EnableCounter(TIM6);
|
TIM6->DIER |= 1;
|
||||||
|
|
||||||
|
// Start immediately
|
||||||
|
LL_TIM_EnableCounter(TIM6);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TIM7 init function */
|
/* TIM7 init function */
|
||||||
@ -458,7 +527,10 @@ static void MX_SPI1_Init(void)
|
|||||||
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
|
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
|
||||||
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE;
|
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE;
|
||||||
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
|
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
|
||||||
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV64;
|
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.BitOrder = LL_SPI_MSB_FIRST;
|
||||||
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
|
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
|
||||||
SPI_InitStruct.CRCPoly = 7;
|
SPI_InitStruct.CRCPoly = 7;
|
||||||
|
@ -37,15 +37,18 @@ void _putchar(char c)
|
|||||||
LL_USART_TransmitData8(DEBUG_UART,c);
|
LL_USART_TransmitData8(DEBUG_UART,c);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
static int NFC = 0;
|
||||||
|
|
||||||
|
|
||||||
int _write (int fd, const void *buf, long int len)
|
int _write (int fd, const void *buf, long int len)
|
||||||
{
|
{
|
||||||
uint8_t * data = (uint8_t *) buf;
|
uint8_t * data = (uint8_t *) buf;
|
||||||
|
|
||||||
// Send out USB serial
|
if (!NFC)
|
||||||
CDC_Transmit_FS(data, len);
|
{
|
||||||
|
// Send out USB serial
|
||||||
|
CDC_Transmit_FS(data, len);
|
||||||
|
}
|
||||||
|
|
||||||
// Send out UART serial
|
// Send out UART serial
|
||||||
while(len--)
|
while(len--)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user