removed WAITPEND from CMD init, Module is able to send commands. Ready to test SD Card
This commit is contained in:
parent
00bcf66457
commit
b935f93ae1
@ -179,6 +179,8 @@ void SDIO_init_hw(){
|
|||||||
CLKPORT->MODER |= (2<<CLKPIN*2);
|
CLKPORT->MODER |= (2<<CLKPIN*2);
|
||||||
D0PORT->MODER |= (2<<D0PIN*2);
|
D0PORT->MODER |= (2<<D0PIN*2);
|
||||||
D0PORT->PUPDR |= (1<<D0PIN*2);
|
D0PORT->PUPDR |= (1<<D0PIN*2);
|
||||||
|
CMDPORT->MODER |= (2<<CMDPIN*2);
|
||||||
|
CMDPORT->PUPDR |= (1<<CMDPIN*2);
|
||||||
#if BUSWIDTH==4
|
#if BUSWIDTH==4
|
||||||
D1PORT->MODER |= (2<<D1PIN*2);
|
D1PORT->MODER |= (2<<D1PIN*2);
|
||||||
D1PORT->PUPDR |= (1<<D1PIN*2);
|
D1PORT->PUPDR |= (1<<D1PIN*2);
|
||||||
@ -189,6 +191,7 @@ void SDIO_init_hw(){
|
|||||||
#endif
|
#endif
|
||||||
//CLKPORT->AFR[(CLKPIN < 8 ? 0 : 1)] |= ALTFUNC << ((CLKPIN < 8 ? CLKPIN : (CLKPIN - 8)) * 4);
|
//CLKPORT->AFR[(CLKPIN < 8 ? 0 : 1)] |= ALTFUNC << ((CLKPIN < 8 ? CLKPIN : (CLKPIN - 8)) * 4);
|
||||||
SETAF(CLKPORT, CLKPIN, ALTFUNC);
|
SETAF(CLKPORT, CLKPIN, ALTFUNC);
|
||||||
|
SETAF(CMDPORT, CMDPIN, ALTFUNC);
|
||||||
SETAF(D0PORT, D0PIN, ALTFUNC);
|
SETAF(D0PORT, D0PIN, ALTFUNC);
|
||||||
#if BUSWIDTH==4
|
#if BUSWIDTH==4
|
||||||
SETAF(D1PORT, D1PIN, ALTFUNC);
|
SETAF(D1PORT, D1PIN, ALTFUNC);
|
||||||
@ -245,12 +248,15 @@ int SDIO_send_cmd(uint8_t CMD, uint32_t arg, uint8_t expectedAns){
|
|||||||
SDIO->ICR = SDIO_ICR_CCRCFAILC | SDIO_ICR_CMDRENDC | SDIO_ICR_CTIMEOUTC | SDIO_ICR_CMDSENTC;
|
SDIO->ICR = SDIO_ICR_CCRCFAILC | SDIO_ICR_CMDRENDC | SDIO_ICR_CTIMEOUTC | SDIO_ICR_CMDSENTC;
|
||||||
//Send command
|
//Send command
|
||||||
SDIO->ARG = arg;
|
SDIO->ARG = arg;
|
||||||
SDIO->CMD = (CMD & SDIO_CMD_CMDINDEX) | SDIO_CMD_CPSMEN | SDIO_CMD_WAITPEND | ((expectedAns << 6) & SDIO_CMD_WAITRESP);
|
SDIO->CMD = (CMD & SDIO_CMD_CMDINDEX) | SDIO_CMD_CPSMEN | /*SDIO_CMD_WAITPEND |*/ ((expectedAns << 6) & SDIO_CMD_WAITRESP);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
unsigned int debug;
|
||||||
void SDIO_wait_cmd_sent() {
|
void SDIO_wait_cmd_sent() {
|
||||||
while (!(SDIO->STA & SDIO_STA_CMDSENT));
|
while (!(SDIO->STA & SDIO_STA_CMDSENT))
|
||||||
|
{
|
||||||
|
debug = SDIO->STA;
|
||||||
|
}
|
||||||
SDIO->ICR |= SDIO_ICR_CMDSENTC;
|
SDIO->ICR |= SDIO_ICR_CMDSENTC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,7 +367,7 @@ int SDIO_send_relative_address_CMD3(uint16_t* rca) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int SDIO_send_go_idle_CMD0() {
|
int SDIO_send_go_idle_CMD0() {
|
||||||
SDIO_send_cmd(0, 0, NO_ANS);
|
SDIO_send_cmd(0, 0x0, NO_ANS);
|
||||||
SDIO_wait_cmd_sent();
|
SDIO_wait_cmd_sent();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
24
main.c
24
main.c
@ -12,28 +12,30 @@
|
|||||||
|
|
||||||
FATFS SDfs;
|
FATFS SDfs;
|
||||||
FIL file;
|
FIL file;
|
||||||
|
volatile int w;
|
||||||
|
|
||||||
|
void SDIO_wait_cmd_sent();
|
||||||
|
int SDIO_switch_appmode_CMD55();
|
||||||
|
int SDIO_send_all_send_cid_CMD2();
|
||||||
|
int SDIO_send_relative_address_CMD3(uint16_t* rca);
|
||||||
|
int SDIO_send_go_idle_CMD0();
|
||||||
|
|
||||||
|
int SDIO_send_block_length_CMD16(uint32_t blocklen);
|
||||||
|
int SDIO_send_bus_width_ACMD6(uint8_t bus_width);
|
||||||
|
|
||||||
void test(char a, char b, char c, char d, char e,char f, char g, char h, char i, char j);
|
|
||||||
void gna();
|
|
||||||
int main() {
|
int main() {
|
||||||
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
|
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
|
||||||
__DSB();
|
__DSB();
|
||||||
GPIOD->MODER = OUTPUT(12);
|
GPIOD->MODER |= OUTPUT(12);
|
||||||
SysTick_Config(8*1680000);
|
SysTick_Config(8*1680000);
|
||||||
f_mount(&SDfs, "0:/", 1);
|
// f_mount(&SDfs, "0:/", 1);
|
||||||
while(1);
|
while(1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void test(char a, char b, char c, char d, char e,char f, char g, char h, char i, char j) {
|
|
||||||
gna();
|
|
||||||
//GPIOD->ODR ^= a+b+c+d+e+f+g+h+i+j;
|
|
||||||
}
|
|
||||||
void gna() {
|
|
||||||
GPIOD->ODR = 0;
|
|
||||||
}
|
|
||||||
void SysTick_Handler()
|
void SysTick_Handler()
|
||||||
{
|
{
|
||||||
GPIOD->ODR ^= (1<<12);
|
GPIOD->ODR ^= (1<<12);
|
||||||
|
w++;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user