HSMCI

Discussion around product based on ARM Cortex M3 core.

Moderators: nferre, ncollot

Freya
Posts: 58
Joined: Mon Jun 11, 2012 11:57 am

HSMCI

Fri Aug 01, 2014 11:39 am

Hi to all,
I need some help on HSMCI interface.
I tried to write my code using asf examples, SD simplified and spi interface, but it woudn't work

Here what I do:
- assign pins to peripheral C
- set registers
- enable PMC clock

and then:
- set speed to 250 KHz
- send 74 clock
- send CMD0
- send CMD8
- send CMD 58

here I stop because responses I got don't seems to be correct.
After every command, I read status register and response register for debug and here is what I got:

SEND CLOCK
SR with card = C00C0E5
SR without card = C00C0E5

CMD0
SR with card = C00C0E5
SR without card = C00C0E5
RESPONSE with card = FFFFFFFF
RESPONSE without card = FFFFFFFF

CMD8
SR with card = C05C0E5
SR without card = C10C0E5
RESPONSE with card = FFFFFFFF
RESPONSE without card = FFFFFFFF

CMD58
SR with card = C10C0E5
SR without card = C10C0E5
RESPONSE with card = FFFFFFFF
RESPONSE without card = FFFFFFFF


I think status register should be differente in case SD is inserted or not and also response shouldn't be FFFFFFFF everytime.
From examples it seems I only need to write argument and command registers to interface with SD card and than read response.
What's wrong?
What do I need to chek for debug?


That's my code

Code: Select all


#define MCCDA	0x01<<28	//PIO_PA28_IDX	A
#define MCCK	0x01<<29	//PIO_PA29_IDX	A
#define MCDA0	0x01<<30	//PIO_PA30_IDX	A
#define MCDA1	0x01<<31	//PIO_PA31_IDX	A
#define MCDA2	0x01<<26	//PIO_PA26_IDX	A
#define MCDA3	0x01<<27	//PIO_PA27_IDX	A


MYSD::MYSD()
{
	uint32_t pin, ul_sr;
	
	p_hsmci = HSMCI;
	pioa = (Pio *)((uint32_t)PIOA);
	
	pin = MCCDA | MCCK | MCDA0 | MCDA1 | MCDA2 | MCDA3;
	ul_sr = pioa->PIO_ABCDSR[0];
	pioa->PIO_ABCDSR[0] = ~pin & ul_sr;	// PIO_ABCDSR[0] = 0 C
	
	pioa->PIO_ABCDSR[1] |= pin;		// PIO_ABCDSR[1] = 1 C
	pioa->PIO_PDR = pin;	// Remove the pins from under the control of PIO
	
	p_hsmci->HSMCI_CR = 0x80;	// Software reset
	p_hsmci->HSMCI_MR =	0x200<<16 | 1<<12 | 1<<11 | 7;	// BLKLEN | WRPROOF | RDPROOF | CLKDIV (250KHz)
	p_hsmci->HSMCI_DTOR = 7<<4 | 2;	// DTOCYC x 1048576 | DTOCYC
	p_hsmci->HSMCI_CSTOR = 7<<4 | 2;	// CSTOMUL | CSTOCYC
	p_hsmci->HSMCI_SDCR = 0;
	p_hsmci->HSMCI_CFG = 1<<4 | 1;	// FERRCTRL | FIFOMODE
	p_hsmci->HSMCI_CR = 1<<3 | 1;	// PWSDIS | MCIEN
	
	if ((PMC->PMC_PCSR0 & (0x01u << ID_HSMCI)) != (0x01u << ID_HSMCI)) PMC->PMC_PCER0 = 0x01u << ID_HSMCI;	// Enable HSMCI clock
}




uint32_t MYSD::SDMount()
{
	uint32_t t, timeout = 100;
	
	SetSpeed(200);
	SendClock();
	SendCommand(CMD0, 0x00000000);	// 0 | SD_NORESP | SD_OPEN
	myio.PrintString((uint8_t *) "CMD0 response", ' ', 0);
	myio.PrintHex(p_hsmci->HSMCI_SR, ' ');
	myio.PrintHex(p_hsmci->HSMCI_RSPR[0], '\n');
	
	SendCommand(CMD8, 0x000001AA);	// 8 | SD_RESP48 | SD_OPEN | SD_LAT64
	myio.PrintString((uint8_t *) "CMD8 response", ' ', 0);
	myio.PrintHex(p_hsmci->HSMCI_SR, ' ');
	myio.PrintHex(p_hsmci->HSMCI_RSPR[0], '\n');
	
	SendCommand(CMD58, 0x00000000);	// 58 | SD_RESP48 | SD_LAT64
	myio.PrintString((uint8_t *) "CMD58 response", ' ', 0);
	myio.PrintHex(p_hsmci->HSMCI_SR, ' ');
	myio.PrintHex(p_hsmci->HSMCI_RSPR[0], '\n');
	return 0;
}


uint32_t MYSD::SendCommand(uint32_t cmd, uint32_t arg)
{
	uint32_t sr;
	
	p_hsmci->HSMCI_ARGR = arg;
	p_hsmci->HSMCI_CMDR = cmd;
	do 
	{
		sr = p_hsmci->HSMCI_SR;
		if(sr & (SR_CSTOE | SR_RTOE | SR_RENDE | SR_RDIRE | SR_RINDE | SR_RCRCE))
		{
			myio.PrintString((uint8_t *) "Command error", ' ', 0);
			myio.PrintHex(sr, '\n');
			return 1;
		}
	}
	while(!(sr & SR_CMDRDY));
	return 0;
}	



void MYSD::SendClock()
{
	uint32_t sr;
	
	p_hsmci->HSMCI_MR &= ~(1<<12 | 1<<11);
	p_hsmci->HSMCI_ARGR = 0;
	p_hsmci->HSMCI_CMDR = SD_NORESP | SD_INIT | SD_OPEN;
	while(!(p_hsmci->HSMCI_SR & SR_CMDRDY));
	return;
}


Thank you
Freya
Freya
Posts: 58
Joined: Mon Jun 11, 2012 11:57 am

Re: HSMCI

Tue Aug 12, 2014 2:30 pm

Hi there,
I try to change my question.
If I send a CMD0 (GO_IDLE_STATE) using HSMCI, where and how can I find that SD card is effectively in idel state and transition is ended?

Thank you
Freya
jharley
Posts: 238
Joined: Thu Dec 06, 2012 6:40 am

Re: HSMCI

Tue Aug 12, 2014 6:19 pm

Use CMD1 and check the response.

https://www.sdcard.org/downloads/pls/si ... t1_410.pdf
See section 7 SPI Mode.

Return to “SAM3 Cortex-M3 MCU”

Who is online

Users browsing this forum: No registered users and 2 guests