Browse Source

Fix sd init after file transfer

Signed-off-by: Sergey Terentiev <sergey@terentiev.me>
FB4S_WIFI
Sergey Terentiev 3 years ago
parent
commit
3eca98fa3b
No known key found for this signature in database GPG Key ID: AFAA57ACD15D1EB0
  1. 14
      Marlin/src/libs/fatfs/sdio_driver_f1.cpp
  2. 1
      Marlin/src/libs/fatfs/sdio_driver_f1.h
  3. 19
      Marlin/src/libs/fatfs/sdio_driver_f4.cpp
  4. 1
      Marlin/src/libs/fatfs/sdio_driver_f4.h
  5. 18
      Marlin/src/module/mks_wifi/mks_wifi_hal_f1.cpp
  6. 1
      Marlin/src/module/mks_wifi/mks_wifi_hal_f1.h
  7. 5
      Marlin/src/module/mks_wifi/mks_wifi_hal_f4.cpp
  8. 1
      Marlin/src/module/mks_wifi/mks_wifi_hal_f4.h
  9. 5
      Marlin/src/module/mks_wifi/mks_wifi_sd.cpp
  10. 2
      Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_common.h

14
Marlin/src/libs/fatfs/sdio_driver_f1.cpp

@ -163,6 +163,20 @@ uint32_t SD_transfer(uint8_t *buf, uint32_t blk, uint32_t cnt, uint32_t dir){
return 0;
};
void sd_reset(void){
(void)SD_Cmd(SD_CMD0,0x00,SDIO_RESP_NONE,(uint32_t*)response); //NORESP
DMA2_Channel4->CCR = 0;
DMA2_Channel4->CMAR = 0;
DMA2_Channel4->CPAR = 0;
DMA2_Channel4->CNDTR = 0;
DMA2->IFCR = DMA_S4_CLEAR;
SDIO->CLKCR = 0;
SDIO->POWER = 0;
RCC->AHBENR &= ~RCC_AHBENR_SDIOEN;
}
uint8_t SD_Init(void) {
volatile uint32_t trials = 0x0000FFFF;
uint32_t tempreg; //Для временного хранения регистров

1
Marlin/src/libs/fatfs/sdio_driver_f1.h

@ -156,6 +156,7 @@ uint32_t SD_get_block_count(void);
uint8_t SD_Cmd(uint8_t cmd, uint32_t arg, uint16_t response_type, uint32_t *response);
uint32_t SD_transfer(uint8_t *buf, uint32_t blk, uint32_t cnt, uint32_t dir);
uint8_t SD_Init(void);
void sd_reset(void);
//void SDIO_Config(void);
#endif

19
Marlin/src/libs/fatfs/sdio_driver_f4.cpp

@ -53,6 +53,25 @@ uint8_t SD_Cmd(uint8_t cmd, uint32_t arg, uint16_t response_type, uint32_t *resp
return 0;
}
void sd_reset(void){
(void)SD_Cmd(SD_CMD0,0x00,SDIO_RESP_NONE,(uint32_t*)response); //NORESP
DMA2_Stream3->CR = 0;
DMA2_Stream3->M0AR=0;
DMA2_Stream3->PAR=0;
DMA2_Stream3->NDTR=0;
DMA2->LIFCR=DMA_S3_CLEAR;
SDIO->CLKCR = 0;
SDIO->POWER = 0;
RCC->APB2RSTR |= RCC_APB2RSTR_SDIORST;
__NOP();
RCC->APB2RSTR &= ~RCC_APB2RSTR_SDIORST;
RCC->APB2ENR &= ~RCC_APB2ENR_SDIOEN;
}
uint32_t __attribute__((optimize("O0"))) SD_transfer(uint8_t *buf, uint32_t blk, uint32_t cnt, uint32_t dir){
uint32_t trials;
uint8_t cmd=0;

1
Marlin/src/libs/fatfs/sdio_driver_f4.h

@ -199,6 +199,7 @@ uint32_t SD_get_block_count(void);
uint8_t SD_Cmd(uint8_t cmd, uint32_t arg, uint16_t response_type, uint32_t *response);
uint32_t SD_transfer(uint8_t *buf, uint32_t blk, uint32_t cnt, uint32_t dir);
uint8_t SD_Init(void);
void sd_reset(void);
//void SDIO_Config(void);
#endif

18
Marlin/src/module/mks_wifi/mks_wifi_hal_f1.cpp

@ -1,8 +1,8 @@
#include "mks_wifi_hal_f1.h"
#include "../../libs/Segger/log.h"
#ifdef STM32F1
#include "../../libs/fatfs/sdio_driver_f1.h"
#ifdef MAPLE_STM32F1
#include "stm32f103xe.h"
@ -50,18 +50,6 @@ void mks_wifi_hw_prepare(unsigned int buf, unsigned int count){
DMA1_Channel5->CCR = DMA_CONF|DMA_CCR_EN;
NVIC_EnableIRQ(DMA1_Channel5_IRQn);
// DEBUG("Start DMA %0X / %d",buf, count);
// DEBUG("CCRR %0X",DMA1_Channel5->CCR);
// DEBUG("CMAR %0X",DMA1_Channel5->CMAR);
// DEBUG("CPAR %0X",DMA1_Channel5->CPAR);
// DEBUG("NDTR %0X",DMA1_Channel5->CNDTR);
// DEBUG("IFC %0X",DMA1->IFCR);
// DEBUG("USART CR1 %0X",USART1->CR1);
// DEBUG("CR2 %0X",USART1->CR2);
// DEBUG("CR3 %0X",USART1->CR3);
// DEBUG("BRR %0X",USART1->BRR);
// DEBUG("SR %0X",USART1->SR);
}
@ -95,6 +83,10 @@ void wd_reset(void){
#endif
}
void mks_wifi_hw_deinit_sd(void){
sd_reset();
};
#ifdef MAPLE_STM32F1
extern "C" void __irq_dma1_channel5(void) {
#else

1
Marlin/src/module/mks_wifi/mks_wifi_hal_f1.h

@ -13,6 +13,7 @@ void mks_wifi_hw_restore(void);
void mks_wifi_disable_dma(void);
void mks_wifi_sys_rst(void);
void wd_reset(void);
void mks_wifi_hw_deinit_sd(void);
#ifdef MAPLE_STM32F1
void NVIC_SetPriority(int IRQn, unsigned int priority);

5
Marlin/src/module/mks_wifi/mks_wifi_hal_f4.cpp

@ -1,6 +1,7 @@
#include "mks_wifi_hal_f4.h"
#ifdef STM32F4
#include "../../libs/fatfs/sdio_driver_f4.h"
volatile unsigned char *buff;
volatile unsigned char buffer_ready;
volatile unsigned char dma_stopped;
@ -50,6 +51,10 @@ void mks_wifi_empty_uart(void){
};
}
void mks_wifi_hw_deinit_sd(void){
sd_reset();
};
void wd_reset(void){
hal.watchdog_refresh();
}

1
Marlin/src/module/mks_wifi/mks_wifi_hal_f4.h

@ -30,5 +30,6 @@ void mks_wifi_sys_rst(void);
void wd_reset(void);
void mks_wifi_empty_uart(void);
void mks_wifi_disable_dma(void);
void mks_wifi_hw_deinit_sd(void);
#endif

5
Marlin/src/module/mks_wifi/mks_wifi_sd.cpp

@ -65,6 +65,11 @@ uint8_t mks_wifi_sd_init(void){
void mks_wifi_sd_deinit(void){
DEBUG("Unmount SD");
f_mount(0, "", 1);
mks_wifi_hw_deinit_sd();
wd_reset();
card.release();
DEBUG("Marlin mount");
card.mount();
};

2
Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_common.h

@ -157,7 +157,7 @@
#endif
#define SDIO_SUPPORT
#define SDIO_CLOCK 4500000 // 4.5 MHz
#define SDIO_CLOCK 18000000 // 4.5 MHz
#define SD_DETECT_PIN PD12
#define ONBOARD_SD_CS_PIN PC11

Loading…
Cancel
Save