refactor: SD card SPI HAL (#3957)
* refactor: SD card SPI driver * Removed SPI and DMA StdPeriph drivers * Allow for disabling SPI DMA support * Disable SPI sdcard CRC support * Fix 2MHz timer on NV14 * Shared VS1053b driver * Fix: SPI2 uses PCLK1 * feat: new generic diskio API * More generic SD_CARD_PRESENT() * Fixes * Flush incoming block on token mismatch * Scratch buffer test * Incredible hack to re-sync sd card * fix: SDIO driver
This commit is contained in:
@@ -94,8 +94,8 @@ uint32_t eepromWritten = 0;
|
||||
FlashCheckRes valid;
|
||||
MemoryType memoryType;
|
||||
uint32_t unlocked = 0;
|
||||
uint32_t timer10MsCount;
|
||||
|
||||
volatile uint32_t timer10MsCount;
|
||||
|
||||
void interrupt10ms()
|
||||
{
|
||||
@@ -117,30 +117,52 @@ void interrupt10ms()
|
||||
#endif
|
||||
}
|
||||
|
||||
void init10msTimer()
|
||||
extern "C" uint32_t HAL_GetTick(void)
|
||||
{
|
||||
return timer10MsCount * 10;
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
static volatile uint32_t _us_overflow_cnt;
|
||||
|
||||
void initTimers()
|
||||
{
|
||||
timer10MsCount = 0;
|
||||
INTERRUPT_xMS_TIMER->ARR = 9999; // 10mS in uS
|
||||
INTERRUPT_xMS_TIMER->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 1000000 - 1; // 1uS
|
||||
INTERRUPT_xMS_TIMER->CCER = 0;
|
||||
INTERRUPT_xMS_TIMER->CCMR1 = 0;
|
||||
INTERRUPT_xMS_TIMER->EGR = 0;
|
||||
INTERRUPT_xMS_TIMER->CR1 = 5;
|
||||
INTERRUPT_xMS_TIMER->DIER |= 1;
|
||||
INTERRUPT_xMS_TIMER->CR1 = TIM_CR1_CEN;
|
||||
INTERRUPT_xMS_TIMER->DIER = TIM_DIER_UIE;
|
||||
NVIC_EnableIRQ(INTERRUPT_xMS_IRQn);
|
||||
|
||||
_us_overflow_cnt = 0;
|
||||
TIMER_2MHz_TIMER->ARR = 65535;
|
||||
TIMER_2MHz_TIMER->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 2000000 - 1; // 0.5 uS, 2 MHz
|
||||
TIMER_2MHz_TIMER->CR1 = TIM_CR1_CEN;
|
||||
TIMER_2MHz_TIMER->DIER = TIM_DIER_UIE;
|
||||
NVIC_EnableIRQ(TIMER_2MHz_IRQn);
|
||||
|
||||
while(timer10MsCount < 10);
|
||||
}
|
||||
|
||||
extern "C" uint32_t HAL_GetTick(void)
|
||||
uint32_t timersGetUsTick()
|
||||
{
|
||||
return timer10MsCount*10;
|
||||
uint32_t us;
|
||||
us = TIMER_2MHz_TIMER->CNT >> 1;
|
||||
us += _us_overflow_cnt << 15;
|
||||
return us;
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
extern "C" void INTERRUPT_xMS_IRQHandler()
|
||||
{
|
||||
INTERRUPT_xMS_TIMER->SR &= ~TIM_SR_UIF;
|
||||
interrupt10ms();
|
||||
}
|
||||
|
||||
extern "C" void TIMER_2MHz_IRQHandler()
|
||||
{
|
||||
TIMER_2MHz_TIMER->SR &= ~TIM_SR_UIF;
|
||||
_us_overflow_cnt += 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t isValidBufferStart(const uint8_t * buffer)
|
||||
@@ -226,14 +248,15 @@ void writeEepromBlock()
|
||||
#if !defined(SIMU)
|
||||
void bootloaderInitApp()
|
||||
{
|
||||
RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph |
|
||||
LCD_RCC_AHB1Periph | BACKLIGHT_RCC_AHB1Periph |
|
||||
KEYS_BACKLIGHT_RCC_AHB1Periph | SD_RCC_AHB1Periph,
|
||||
RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | LCD_RCC_AHB1Periph |
|
||||
BACKLIGHT_RCC_AHB1Periph |
|
||||
KEYS_BACKLIGHT_RCC_AHB1Periph,
|
||||
ENABLE);
|
||||
|
||||
RCC_APB1PeriphClockCmd(ROTARY_ENCODER_RCC_APB1Periph | LCD_RCC_APB1Periph |
|
||||
BACKLIGHT_RCC_APB1Periph |
|
||||
INTERRUPT_xMS_RCC_APB1Periph | SD_RCC_APB1Periph,
|
||||
INTERRUPT_xMS_RCC_APB1Periph |
|
||||
TIMER_2MHz_RCC_APB1Periph,
|
||||
ENABLE);
|
||||
|
||||
RCC_APB2PeriphClockCmd(
|
||||
@@ -251,18 +274,6 @@ void bootloaderInitApp()
|
||||
pwrInit();
|
||||
keysInit();
|
||||
|
||||
#if defined(SWSERIALPOWER)
|
||||
// TODO: replace with proper serial port query...
|
||||
// #if defined(AUX_SERIAL)
|
||||
// void set_aux_pwr(uint8_t on);
|
||||
// set_aux_pwr(0);
|
||||
// #endif
|
||||
// #if defined(AUX2_SERIAL)
|
||||
// void set_aux2_pwr(uint8_t on);
|
||||
// set_aux2_pwr(0);
|
||||
// #endif
|
||||
#endif
|
||||
|
||||
// wait a bit for the inputs to stabilize...
|
||||
if (!WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {
|
||||
for (uint32_t i = 0; i < 150000; i++) {
|
||||
@@ -311,7 +322,7 @@ void bootloaderInitApp()
|
||||
eepromInit();
|
||||
#endif
|
||||
|
||||
init10msTimer();
|
||||
initTimers();
|
||||
|
||||
// SD card detect pin
|
||||
sdInit();
|
||||
@@ -578,16 +589,6 @@ int bootloaderMain()
|
||||
|
||||
lcdRefresh();
|
||||
|
||||
#if defined(SDCARD) && defined(PCBTARANIS)
|
||||
static uint32_t PowerUpDelay = 0;
|
||||
|
||||
if (PowerUpDelay < 20) { // 200 mS
|
||||
PowerUpDelay += 1;
|
||||
}
|
||||
else {
|
||||
sdPoll10ms();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (state != ST_FLASHING && state != ST_USB) {
|
||||
|
||||
Reference in New Issue
Block a user