SD-Card corrections on ersky9x board
Status line FatFs on simu
This commit is contained in:
+2
-8
@@ -47,11 +47,6 @@
|
||||
#include "core_cm3.h"
|
||||
#endif
|
||||
|
||||
#define BOARD_MCK 64000000
|
||||
|
||||
#define CardIsConnected() ( (PIOB->PIO_PDSR & PIO_PB7) == 0 )
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -91,7 +86,6 @@
|
||||
#define BOARD_MAINOSC 12000000
|
||||
|
||||
/// Master clock frequency (when using board_lowlevel.c).
|
||||
//#define BOARD_MCK 48000000
|
||||
#define BOARD_MCK 64000000
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -353,8 +347,6 @@
|
||||
#define PIN_USART1_RTS {0x1 << 24, PIOA, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT}
|
||||
#define PIN_USART1_EN {0x1 << 23, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_DEFAULT}
|
||||
|
||||
|
||||
|
||||
/// USB VBus monitoring pin definition.
|
||||
#ifdef BOARD_REV_A
|
||||
#define PIN_USB_VBUS {1 << 23, PIOC, ID_PIOC, PIO_INPUT, PIO_DEFAULT}
|
||||
@@ -500,6 +492,8 @@
|
||||
///// MCI Card Detect pin.
|
||||
#define BOARD_SD_PIN_CD PIN_MCI_CD
|
||||
|
||||
#define CardIsConnected() ( (PIOB->PIO_PDSR & PIO_PB7) == 0 )
|
||||
|
||||
/*
|
||||
#define BOARD_PSRAM_PINS PIN_EBI_DATA_BUS, PIN_EBI_NCS0, PIN_EBI_NRD, PIN_EBI_NWE, \
|
||||
PIN_EBI_PSRAM_ADDR_BUS, PIN_EBI_PSRAM_NBS, PIN_EBI_A1
|
||||
|
||||
+5
-5
@@ -86,7 +86,7 @@ extern uint32_t Master_frequency ;
|
||||
/***************************************************************************/
|
||||
void ResetHandler (void)
|
||||
{
|
||||
{
|
||||
{
|
||||
register uint32_t *pSrc;
|
||||
register uint32_t *pDest;
|
||||
register uint32_t m_freq ;
|
||||
@@ -125,10 +125,10 @@ void ResetHandler (void)
|
||||
pDest = &_sbss;
|
||||
while(pDest < &_ebss)
|
||||
{
|
||||
*pDest++ = 0;
|
||||
}
|
||||
Master_frequency = m_freq ;
|
||||
}
|
||||
*pDest++ = 0;
|
||||
}
|
||||
Master_frequency = m_freq ;
|
||||
}
|
||||
|
||||
/*
|
||||
* And now the main function can be called.
|
||||
|
||||
+20
-10
@@ -589,6 +589,7 @@ uint32_t sd_card_ready( void )
|
||||
|
||||
uint32_t sd_cmd16()
|
||||
{
|
||||
#if 0
|
||||
Hsmci *phsmci = HSMCI;
|
||||
|
||||
if (CardIsConnected()) {
|
||||
@@ -606,20 +607,24 @@ uint32_t sd_cmd16()
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t sd_read_block(uint32_t block_no, uint32_t *data)
|
||||
{
|
||||
uint32_t result = 0;
|
||||
Hsmci *phsmci = HSMCI;
|
||||
|
||||
if (Card_state == SD_ST_DATA) {
|
||||
Hsmci *phsmci = HSMCI;
|
||||
if (CardIsConnected()) {
|
||||
//sd_cmd16();
|
||||
sd_cmd16();
|
||||
// Block size = 512, nblocks = 1
|
||||
phsmci->HSMCI_BLKR = ((512) << 16) | 1;
|
||||
phsmci->HSMCI_MR = (phsmci->HSMCI_MR & (~(HSMCI_MR_BLKLEN_Msk|HSMCI_MR_FBYTE))) | (HSMCI_MR_PDCMODE|HSMCI_MR_WRPROOF|HSMCI_MR_RDPROOF) | (512 << 16);
|
||||
phsmci->HSMCI_RPR = (uint32_t)data;
|
||||
phsmci->HSMCI_RCR = 512 / 4;
|
||||
phsmci->HSMCI_RNCR = 0;
|
||||
phsmci->HSMCI_PTCR = HSMCI_PTCR_RXTEN;
|
||||
phsmci->HSMCI_ARGR = block_no << 9;
|
||||
phsmci->HSMCI_CMDR = SD_READ_SINGLE_BLOCK;
|
||||
@@ -628,28 +633,31 @@ uint32_t sd_read_block(uint32_t block_no, uint32_t *data)
|
||||
while (retry-- > 0) {
|
||||
CoTickDelay(1); // 2ms
|
||||
if (phsmci->HSMCI_SR & HSMCI_SR_ENDRX) {
|
||||
return 1;
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
phsmci->HSMCI_MR &= ~HSMCI_MR_PDCMODE;
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t sd_write_block( uint32_t block_no, uint32_t *data )
|
||||
{
|
||||
uint32_t result = 0;
|
||||
Hsmci *phsmci = HSMCI;
|
||||
|
||||
if (Card_state == SD_ST_DATA) {
|
||||
Hsmci *phsmci = HSMCI;
|
||||
if (CardIsConnected()) {
|
||||
//sd_cmd16();
|
||||
sd_cmd16();
|
||||
// Block size = 512, nblocks = 1
|
||||
phsmci->HSMCI_BLKR = ((512) << 16) | 1;
|
||||
phsmci->HSMCI_MR = (phsmci->HSMCI_MR & (~(HSMCI_MR_BLKLEN_Msk|HSMCI_MR_FBYTE))) | (HSMCI_MR_PDCMODE|HSMCI_MR_WRPROOF|HSMCI_MR_RDPROOF) | (512 << 16);
|
||||
phsmci->HSMCI_TPR = (uint32_t)data;
|
||||
phsmci->HSMCI_TCR = 512 / 4;
|
||||
phsmci->HSMCI_TNCR = 0;
|
||||
phsmci->HSMCI_ARGR = block_no << 9;
|
||||
phsmci->HSMCI_CMDR = SD_WRITE_SINGLE_BLOCK;
|
||||
phsmci->HSMCI_PTCR = HSMCI_PTCR_TXTEN;
|
||||
@@ -658,14 +666,16 @@ uint32_t sd_write_block( uint32_t block_no, uint32_t *data )
|
||||
while (retry-- > 0) {
|
||||
CoTickDelay(1); // 2ms
|
||||
if (phsmci->HSMCI_SR & HSMCI_SR_NOTBUSY) {
|
||||
return 1;
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
phsmci->HSMCI_MR &= ~HSMCI_MR_PDCMODE;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user