[FL-1009, FL-1118] Better initialization sequence and V8 hardware support (#406)
* Interrupt manager: add memory barriers. * ISRs: remove TIM17 dead code. * API HAL Delay: rename initialization routine and move to API-HAL * Main: move FURI initialization to the start. * API HAL GPIO: drop CC1101 shenanigans, COMP inversion for new boards. * IButton: migrate Cyfral and Metakom to RFID comp routine, make it compatible with new boards. * RFID: Better keyboard handling and shutdown routines
This commit is contained in:
@@ -5,6 +5,9 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Init DWT */
|
||||
void api_hal_delay_init(void);
|
||||
|
||||
/**
|
||||
* Delay in milliseconds
|
||||
* @warning Cannot be used from ISR
|
||||
@@ -14,9 +17,6 @@ void delay(float milliseconds);
|
||||
/** Delay in microseconds */
|
||||
void delay_us(float microseconds);
|
||||
|
||||
/** Init DWT */
|
||||
void delay_us_init_DWT(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -23,11 +23,13 @@
|
||||
void SystemClock_Config(void);
|
||||
void MX_FREERTOS_Init(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int main(void) {
|
||||
// Initialize FURI layer
|
||||
furi_init();
|
||||
|
||||
// Initialize ST HAL hardware
|
||||
HAL_Init();
|
||||
SystemClock_Config();
|
||||
|
||||
MX_GPIO_Init();
|
||||
MX_ADC1_Init();
|
||||
MX_RTC_Init();
|
||||
@@ -46,11 +48,12 @@ int main(void)
|
||||
MX_AES2_Init();
|
||||
MX_CRC_Init();
|
||||
|
||||
delay_us_init_DWT();
|
||||
// Flipper API HAL
|
||||
api_hal_init();
|
||||
|
||||
// 3rd party
|
||||
MX_FATFS_Init();
|
||||
|
||||
furi_init();
|
||||
// CMSIS initialization
|
||||
osKernelInitialize();
|
||||
// Init flipper
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
static uint32_t clk_per_microsecond;
|
||||
|
||||
void delay_us_init_DWT(void) {
|
||||
void api_hal_delay_init(void) {
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||
DWT->CYCCNT = 0U;
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include <api-hal-gpio.h>
|
||||
#include <api-hal-version.h>
|
||||
|
||||
// init GPIO
|
||||
void hal_gpio_init(
|
||||
@@ -17,17 +18,12 @@ void hal_gpio_init(
|
||||
HAL_GPIO_Init(gpio->port, &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
void enable_cc1101_irq() {
|
||||
HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI4_IRQn);
|
||||
}
|
||||
|
||||
extern COMP_HandleTypeDef hcomp1;
|
||||
|
||||
bool get_rfid_in_level() {
|
||||
#ifdef INVERT_RFID_IN
|
||||
return (HAL_COMP_GetOutputLevel(&hcomp1) == COMP_OUTPUT_LEVEL_LOW);
|
||||
#else
|
||||
return (HAL_COMP_GetOutputLevel(&hcomp1) == COMP_OUTPUT_LEVEL_HIGH);
|
||||
#endif
|
||||
#ifdef INVERT_RFID_IN
|
||||
return (HAL_COMP_GetOutputLevel(&hcomp1) == COMP_OUTPUT_LEVEL_LOW);
|
||||
#else
|
||||
return (HAL_COMP_GetOutputLevel(&hcomp1) == COMP_OUTPUT_LEVEL_HIGH);
|
||||
#endif
|
||||
}
|
||||
|
@@ -68,8 +68,6 @@ static inline bool hal_gpio_read(const GpioPin* gpio) {
|
||||
}
|
||||
}
|
||||
|
||||
void enable_cc1101_irq();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include <api-hal.h>
|
||||
|
||||
void api_hal_init() {
|
||||
api_hal_delay_init();
|
||||
api_hal_os_init();
|
||||
api_hal_vcp_init();
|
||||
api_hal_spi_init();
|
||||
|
@@ -23,11 +23,6 @@ void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef* htim) {
|
||||
/* Timer update event */
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim) {
|
||||
api_interrupt_call(InterruptTypeTimerUpdate, htim);
|
||||
|
||||
// handle HAL ticks
|
||||
if(htim->Instance == TIM17) {
|
||||
HAL_IncTick();
|
||||
}
|
||||
}
|
||||
|
||||
/* External interrupt event */
|
||||
|
@@ -23,11 +23,13 @@
|
||||
void SystemClock_Config(void);
|
||||
void MX_FREERTOS_Init(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int main(void) {
|
||||
// Initialize FURI layer
|
||||
furi_init();
|
||||
|
||||
// Initialize ST HAL hardware
|
||||
HAL_Init();
|
||||
SystemClock_Config();
|
||||
|
||||
MX_GPIO_Init();
|
||||
MX_ADC1_Init();
|
||||
MX_RTC_Init();
|
||||
@@ -46,11 +48,12 @@ int main(void)
|
||||
MX_AES2_Init();
|
||||
MX_CRC_Init();
|
||||
|
||||
delay_us_init_DWT();
|
||||
// Flipper API HAL
|
||||
api_hal_init();
|
||||
|
||||
// 3rd party
|
||||
MX_FATFS_Init();
|
||||
|
||||
furi_init();
|
||||
// CMSIS initialization
|
||||
osKernelInitialize();
|
||||
// Init flipper
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
static uint32_t clk_per_microsecond;
|
||||
|
||||
void delay_us_init_DWT(void) {
|
||||
void api_hal_delay_init(void) {
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||
DWT->CYCCNT = 0U;
|
||||
|
@@ -1,7 +1,5 @@
|
||||
#include <api-hal-gpio.h>
|
||||
#include <api-hal-spi.h>
|
||||
#include <api-hal-resources.h>
|
||||
#include <api-hal-delay.h>
|
||||
#include <api-hal-version.h>
|
||||
|
||||
// init GPIO
|
||||
void hal_gpio_init(
|
||||
@@ -23,9 +21,16 @@ void hal_gpio_init(
|
||||
extern COMP_HandleTypeDef hcomp1;
|
||||
|
||||
bool get_rfid_in_level() {
|
||||
#ifdef INVERT_RFID_IN
|
||||
return (HAL_COMP_GetOutputLevel(&hcomp1) == COMP_OUTPUT_LEVEL_LOW);
|
||||
#else
|
||||
return (HAL_COMP_GetOutputLevel(&hcomp1) == COMP_OUTPUT_LEVEL_HIGH);
|
||||
#endif
|
||||
bool value = false;
|
||||
if (api_hal_version_get_hw_version() > 7) {
|
||||
value = (HAL_COMP_GetOutputLevel(&hcomp1) == COMP_OUTPUT_LEVEL_LOW);
|
||||
} else {
|
||||
value = (HAL_COMP_GetOutputLevel(&hcomp1) == COMP_OUTPUT_LEVEL_HIGH);
|
||||
}
|
||||
|
||||
#ifdef INVERT_RFID_IN
|
||||
return !value;
|
||||
#else
|
||||
return value;
|
||||
#endif
|
||||
}
|
||||
|
@@ -68,8 +68,6 @@ static inline bool hal_gpio_read(const GpioPin* gpio) {
|
||||
}
|
||||
}
|
||||
|
||||
void enable_cc1101_irq();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include <api-hal.h>
|
||||
|
||||
void api_hal_init() {
|
||||
api_hal_delay_init();
|
||||
api_hal_os_init();
|
||||
api_hal_vcp_init();
|
||||
api_hal_spi_init();
|
||||
|
@@ -23,11 +23,6 @@ void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef* htim) {
|
||||
/* Timer update event */
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim) {
|
||||
api_interrupt_call(InterruptTypeTimerUpdate, htim);
|
||||
|
||||
// handle HAL ticks
|
||||
if(htim->Instance == TIM17) {
|
||||
HAL_IncTick();
|
||||
}
|
||||
}
|
||||
|
||||
/* External interrupt event */
|
||||
|
Reference in New Issue
Block a user