implemented clock switch
This commit is contained in:
		@@ -28,7 +28,7 @@ typedef enum {ACMD41_RESP_INIT, ACMD41_RESP_ERR, ACMD41_RESP_SDSC, ACMD41_RESP_S
 | 
			
		||||
typedef enum {CMD8_RESP_TIMEOUT, CMD8_RESP_ACK, CMD8_RESP_ERR} CMD8_RESP_t;
 | 
			
		||||
typedef uint8_t CID_t;
 | 
			
		||||
 | 
			
		||||
void SDIO_InitModule();
 | 
			
		||||
void initModuleHw();
 | 
			
		||||
 | 
			
		||||
int SDIO_sendCmd(uint8_t CMD, uint32_t arg, uint8_t expectedAns);
 | 
			
		||||
int SDIO_getResp(uint8_t expectedCMD, uint8_t typeOfAns, uint32_t* responseBuffer);
 | 
			
		||||
@@ -45,7 +45,7 @@ CMD8_RESP_t SDIO_send_CMD8();
 | 
			
		||||
void initDetectandProtectionPins();
 | 
			
		||||
int checkNotInserted(); // Returns 0 if inserted!
 | 
			
		||||
int checkWriteProtection(); // returns 0 if write protected
 | 
			
		||||
 | 
			
		||||
void switchPrescaler(uint8_t clkdiv);
 | 
			
		||||
 | 
			
		||||
//BYTE rxtxbuffer[1<<BLOCKSIZE]; //Data RX and TX Buffer not needed anymore. thanks to DMA
 | 
			
		||||
SDInfo_t cardInfo; // = {.type = CARD_NONE};
 | 
			
		||||
@@ -72,7 +72,7 @@ DSTATUS SDIO_initialize(){
 | 
			
		||||
    cardInfo.rca = 0;
 | 
			
		||||
    cardInfo.type = CARD_NONE;
 | 
			
		||||
 | 
			
		||||
    SDIO_InitModule();
 | 
			
		||||
    initModuleHw();
 | 
			
		||||
 | 
			
		||||
    initDetectandProtectionPins();
 | 
			
		||||
 | 
			
		||||
@@ -126,6 +126,10 @@ DSTATUS SDIO_initialize(){
 | 
			
		||||
    //TODO: Set 4 bit mode
 | 
			
		||||
    //TODO:
 | 
			
		||||
 | 
			
		||||
    switchPrescaler(WORKCLK);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    if (checkWriteProtection()) {
 | 
			
		||||
        return STA_PROTECT;
 | 
			
		||||
    } else
 | 
			
		||||
@@ -168,7 +172,7 @@ DWORD __attribute__((weak)) get_fattime(){
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void SDIO_InitModule(){
 | 
			
		||||
void initModuleHw(){
 | 
			
		||||
    //Init Clocks
 | 
			
		||||
    RCC->AHB1ENR    |= PORTCLKMASK;
 | 
			
		||||
    RCC->APB2ENR    |= RCC_APB2ENR_SDIOEN;
 | 
			
		||||
@@ -209,6 +213,15 @@ void SDIO_InitModule(){
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void switchPrescaler(uint8_t clkdiv) {
 | 
			
		||||
    SDIO->POWER = 0;
 | 
			
		||||
    __DSB();
 | 
			
		||||
    SDIO->CLKCR &= ~SDIO_CLKCR_CLKDIV; // Clear prescaler
 | 
			
		||||
    SDIO->CLKCR |= (SDIO_CLKCR_CLKDIV & clkdiv); // Set bits
 | 
			
		||||
    __DSB();
 | 
			
		||||
    SDIO->POWER = SDIO_POWER_PWRCTRL_0 | SDIO_POWER_PWRCTRL_1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//Send Command
 | 
			
		||||
//Clear respone Flags
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user