sdcard recovery

This commit is contained in:
Peter D. Gray 2024-01-10 13:19:11 -05:00
parent 34e9006702
commit 010156f690
No known key found for this signature in database
GPG Key ID: A2DCD558C2BE5D7C
2 changed files with 27 additions and 6 deletions

View File

@ -171,10 +171,12 @@ system_startup(void)
// .. will reboot if it works; only helps w/ reset pulses, not power downs.
psram_recover_firmware();
#ifdef RELEASE
if(!flash_is_security_level2()) {
// in factory, DFU is prefered; can't work if flash locked tho
enter_dfu();
}
#endif
// use SDCard to recover
while(1) sdcard_recovery();

View File

@ -53,6 +53,24 @@ sdcard_setup(void)
HAL_GPIO_Init(GPIOC, &setup);
}
#ifdef FOR_Q1_ONLY
// Force mux to A slot only (we don't support B here at all)
{
GPIO_InitTypeDef setup = {
.Pin = GPIO_PIN_13,
.Mode = GPIO_MODE_OUTPUT_PP,
.Pull = GPIO_NOPULL,
.Speed = GPIO_SPEED_FREQ_LOW,
};
HAL_GPIO_Init(GPIOC, &setup);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 0); // select A
}
// PD3 = DETECT1 .. already configed in q1-bootrom/gpio.c
// Ignore DETECT2, and ACTIVE_LED2 (port D pins) because
// not using and default state (hiz input) will be fine.
#endif
// PD2 = CMD
{ GPIO_InitTypeDef setup = {
.Pin = GPIO_PIN_2,
@ -76,7 +94,7 @@ sdcard_probe(uint32_t *num_blocks)
{
memset(&hsd, 0, sizeof(SD_HandleTypeDef));
puts2("SDCard: ");
puts2("sdcard_probe: ");
hsd.Instance = SDMMC1;
hsd.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
@ -124,10 +142,9 @@ sdcard_probe(uint32_t *num_blocks)
sdcard_is_inserted(void)
{
#ifdef FOR_Q1_ONLY
// XXX check pin; also force mux to A
return !!HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_3); // PD3
return !HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_3); // PD3 - inserted when low (Q)
#else
return !!HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13); // PC13
return !!HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13); // PC13 - inserted when high (Mk4)
#endif
}
@ -197,7 +214,8 @@ sdcard_try_file(uint32_t blk_pos)
// read full possible file into PSRAM, assume continguous, and big enough
uint8_t *ps = (uint8_t *)PSRAM_BASE;
uint8_t buf[512*8]; // half of all our SRAM 0x00002000
//uint8_t buf[512*8]; // half of all our SRAM 0x00002000
uint8_t buf[512]; // slower, but works.
for(uint32_t off = 0; off < FW_MAX_LENGTH_MK4; off += sizeof(buf)) {
int rv = HAL_SD_ReadBlocks(&hsd, buf, blk_pos+(off/512), sizeof(buf)/512, 60000);
@ -253,8 +271,9 @@ sdcard_search(void)
uint32_t num_blocks;
// open card (power it) and get details, do setup
puts2("SDCard: ");
puts2("sdcard_search: ");
sdcard_setup();
delay_ms(100);
if(!sdcard_probe(&num_blocks)) return;
uint8_t blk[512];