From cdbc333cf231b599a6f428ec5c42d7ae265c4176 Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 13 Jul 2021 16:14:37 +0300 Subject: [PATCH] SD remount --- Marlin/src/module/mks_wifi/mks_wifi_sd.cpp | 21 +++++++++++++++++++-- Marlin/src/sd/SdVolume.h | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Marlin/src/module/mks_wifi/mks_wifi_sd.cpp b/Marlin/src/module/mks_wifi/mks_wifi_sd.cpp index 2bd8bcfc46..21b4958377 100644 --- a/Marlin/src/module/mks_wifi/mks_wifi_sd.cpp +++ b/Marlin/src/module/mks_wifi/mks_wifi_sd.cpp @@ -51,8 +51,17 @@ uint8_t mks_wifi_sd_init(void){ void mks_wifi_sd_deinit(void){ DEBUG("Unmount SD"); f_mount(0, "", 1); + + SDIO->POWER &= ~SDIO_POWER_PWRCTRL; + SDIO->CLKCR = SDIO_CLKCR_CLKEN | (58 << SDIO_CLKCR_CLKDIV_Pos); + SDIO->MASK = 0; + RCC->AHBENR &= ~RCC_AHBENR_SDIOEN; + RCC->AHBENR |= RCC_AHBENR_SDIOEN; + DMA2->IFCR = (DMA_IFCR_CTCIF4 | DMA_IFCR_CTEIF4 | DMA_IFCR_CGIF4 | DMA_IFCR_CHTIF4); + DMA2_Channel4->CCR = 0; + DEBUG("Marlin mount"); - card.mount(); + card.manage_media(); card.mount(); }; @@ -166,7 +175,14 @@ void mks_wifi_start_file_upload(ESP_PROTOC_FRAME *packet){ dma_timeout = DMA_TIMEOUT; //Тайм-аут, на случай если передача зависла. last_sector = 0; + MYSERIAL2.end(); + __HAL_RCC_USART1_FORCE_RESET(); + __HAL_RCC_USART1_RELEASE_RESET(); + __HAL_RCC_USART1_CLK_ENABLE(); + + __HAL_RCC_DMA1_CLK_ENABLE(); + DMA1_Channel5->CCR = DMA_CCR_PL|DMA_CCR_MINC; DMA1_Channel5->CPAR = (uint32_t)&USART1->DR; DMA1_Channel5->CMAR = (uint32_t)dma_buff[dma_buff_index]; @@ -178,9 +194,10 @@ void mks_wifi_start_file_upload(ESP_PROTOC_FRAME *packet){ USART1->BRR = 0x25; USART1->CR2 = 0; USART1->CR3 = USART_CR3_DMAR; + (void)USART1->DR; USART1->SR = 0; - safe_delay(200); + //safe_delay(200); USART1->CR1 = USART_CR1_RE | USART_CR1_UE; TERN_(USE_WATCHDOG, HAL_watchdog_refresh()); diff --git a/Marlin/src/sd/SdVolume.h b/Marlin/src/sd/SdVolume.h index b8e70ca9d7..1c6e402a2a 100644 --- a/Marlin/src/sd/SdVolume.h +++ b/Marlin/src/sd/SdVolume.h @@ -93,7 +93,7 @@ class SdVolume { * Reasons for failure include not finding a valid partition, not finding * a valid FAT file system or an I/O error. */ - bool init(DiskIODriver *dev) { return init(dev, 1) || init(dev, 0); } + bool init(DiskIODriver *dev) { return init(dev, 1) ? true : init(dev, 0); } bool init(DiskIODriver *dev, uint8_t part); // inline functions that return volume info