Browse Source

Merge pull request #18 from mjs513/master

Updated fir T40=-Beta2 and Builtin SD Card define
main
Paul Stoffregen 5 years ago
parent
commit
e4b02fb1db
No account linked to committer's email address
2 changed files with 9 additions and 6 deletions
  1. +3
    -3
      utility/NXP_SDHC.cpp
  2. +6
    -3
      utility/Sd2Card.h

+ 3
- 3
utility/NXP_SDHC.cpp View File

//see also //see also
//https://community.nxp.com/thread/99202 //https://community.nxp.com/thread/99202


#if defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__IMXRT1052__)
#if defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__IMXRT1052__) || defined(__IMXRT1062__)


#include "core_pins.h" // include calls to kinetis.h or imxrt.h #include "core_pins.h" // include calls to kinetis.h or imxrt.h
#include "usb_serial.h" // for Serial #include "usb_serial.h" // for Serial
#define SDHC_FIFO_BUFFER_SIZE 16 #define SDHC_FIFO_BUFFER_SIZE 16
#define SDHC_BLOCK_SIZE 512 #define SDHC_BLOCK_SIZE 512


#if defined(__IMXRT1052__)
#if defined(__IMXRT1052__) || defined(__IMXRT1062__)
#define MAKE_REG_MASK(m,s) (((uint32_t)(((uint32_t)(m) << s)))) #define MAKE_REG_MASK(m,s) (((uint32_t)(((uint32_t)(m) << s))))
#define MAKE_REG_GET(x,m,s) (((uint32_t)(((uint32_t)(x)>>s) & m))) #define MAKE_REG_GET(x,m,s) (((uint32_t)(((uint32_t)(x)>>s) & m)))
#define MAKE_REG_SET(x,m,s) (((uint32_t)(((uint32_t)(x) & m) << s))) #define MAKE_REG_SET(x,m,s) (((uint32_t)(((uint32_t)(x) & m) << s)))
sigen |= SDHC_IRQSIGEN_DMA_MASK ; sigen |= SDHC_IRQSIGEN_DMA_MASK ;
SDHC_SYSCTL |= SDHC_SYSCTL_HCKEN; SDHC_SYSCTL |= SDHC_SYSCTL_HCKEN;
#if defined(__IMXRT1052__)
#if defined(__IMXRT1052__) || defined(__IMXRT1062__)
SDHC_MIX_CTRL |= SDHC_MIX_CTRL_DTDSEL ; // read SDHC_MIX_CTRL |= SDHC_MIX_CTRL_DTDSEL ; // read
SDHC_MIX_CTRL |= SDHC_MIX_CTRL_DMAEN ; // DMA SDHC_MIX_CTRL |= SDHC_MIX_CTRL_DMAEN ; // DMA
#endif #endif

+ 6
- 3
utility/Sd2Card.h View File

#if defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__IMXRT1052__) #if defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__IMXRT1052__)
#include "NXP_SDHC.h" #include "NXP_SDHC.h"
#define BUILTIN_SDCARD 254 #define BUILTIN_SDCARD 254
#elif defined(__IMXRT1062__)
#include "NXP_SDHC.h"
#define BUILTIN_SDCARD 36
#endif #endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** /**
/* Initialize an SD flash memory card with the selected SPI clock rate /* Initialize an SD flash memory card with the selected SPI clock rate
* and the SD chip select pin. */ * and the SD chip select pin. */
uint8_t init(uint8_t sckRateID, uint8_t chipSelectPin) { uint8_t init(uint8_t sckRateID, uint8_t chipSelectPin) {
#if defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__IMXRT1052__)
#if defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__IMXRT1052__) || defined(__IMXRT1062__)
if (chipSelectPin == BUILTIN_SDCARD) { if (chipSelectPin == BUILTIN_SDCARD) {
chipSelectPin_ = BUILTIN_SDCARD; chipSelectPin_ = BUILTIN_SDCARD;
uint8_t ret = SDHC_CardInit(); uint8_t ret = SDHC_CardInit();
uint8_t type(void) const {return type_;} uint8_t type(void) const {return type_;}
/** Returns the current value, true or false, for partial block read. */ /** Returns the current value, true or false, for partial block read. */
uint8_t readBlock(uint32_t block, uint8_t* dst) { uint8_t readBlock(uint32_t block, uint8_t* dst) {
#if defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__IMXRT1052__)
#if defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__IMXRT1052__) || defined(__IMXRT1062__)
if (chipSelectPin_ == BUILTIN_SDCARD) { if (chipSelectPin_ == BUILTIN_SDCARD) {
return (SDHC_CardReadBlock(dst, block) == 0) ? true : false; return (SDHC_CardReadBlock(dst, block) == 0) ? true : false;
} }
} }
/** Return the card type: SD V1, SD V2 or SDHC */ /** Return the card type: SD V1, SD V2 or SDHC */
uint8_t writeBlock(uint32_t block, const uint8_t* src) { uint8_t writeBlock(uint32_t block, const uint8_t* src) {
#if defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__IMXRT1052__)
#if defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__IMXRT1052__) || defined(__IMXRT1062__)
if (chipSelectPin_ == BUILTIN_SDCARD) { if (chipSelectPin_ == BUILTIN_SDCARD) {
return (SDHC_CardWriteBlock(src, block) == 0) ? true : false; return (SDHC_CardWriteBlock(src, block) == 0) ? true : false;
} }

Loading…
Cancel
Save