Merge branch 'sdio-updates' of https://github.com/victorpv/Arduino_STM32 into victorpv-sdio-updates
This commit is contained in:
commit
314ce02bd0
|
@ -32,8 +32,8 @@
|
||||||
|
|
||||||
sdio_dev * SDIO = SDIO_BASE;
|
sdio_dev * SDIO = SDIO_BASE;
|
||||||
|
|
||||||
#define DELAY_LONG 10
|
#define DELAY_LONG 20
|
||||||
#define DELAY_SHORT 1
|
#define DELAY_SHORT 2
|
||||||
|
|
||||||
uint8_t dly = DELAY_LONG; // microseconds delay after accessing registers
|
uint8_t dly = DELAY_LONG; // microseconds delay after accessing registers
|
||||||
|
|
||||||
|
@ -43,9 +43,13 @@ uint8_t dly = DELAY_LONG; // microseconds delay after accessing registers
|
||||||
void sdio_gpios_init(void)
|
void sdio_gpios_init(void)
|
||||||
{
|
{
|
||||||
gpio_set_mode(PIN_MAP[BOARD_SDIO_D0].gpio_device, PIN_MAP[BOARD_SDIO_D0].gpio_bit, GPIO_AF_OUTPUT_PP);
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_D0].gpio_device, PIN_MAP[BOARD_SDIO_D0].gpio_bit, GPIO_AF_OUTPUT_PP);
|
||||||
gpio_set_mode(PIN_MAP[BOARD_SDIO_D1].gpio_device, PIN_MAP[BOARD_SDIO_D1].gpio_bit, GPIO_AF_OUTPUT_PP);
|
/* gpio_set_mode(PIN_MAP[BOARD_SDIO_D1].gpio_device, PIN_MAP[BOARD_SDIO_D1].gpio_bit, GPIO_AF_OUTPUT_PP);
|
||||||
gpio_set_mode(PIN_MAP[BOARD_SDIO_D2].gpio_device, PIN_MAP[BOARD_SDIO_D2].gpio_bit, GPIO_AF_OUTPUT_PP);
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_D2].gpio_device, PIN_MAP[BOARD_SDIO_D2].gpio_bit, GPIO_AF_OUTPUT_PP);
|
||||||
gpio_set_mode(PIN_MAP[BOARD_SDIO_D3].gpio_device, PIN_MAP[BOARD_SDIO_D3].gpio_bit, GPIO_AF_OUTPUT_PP);
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_D3].gpio_device, PIN_MAP[BOARD_SDIO_D3].gpio_bit, GPIO_AF_OUTPUT_PP);
|
||||||
|
*/
|
||||||
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_D1].gpio_device, PIN_MAP[BOARD_SDIO_D1].gpio_bit, GPIO_INPUT_PU);
|
||||||
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_D2].gpio_device, PIN_MAP[BOARD_SDIO_D2].gpio_bit, GPIO_INPUT_PU);
|
||||||
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_D3].gpio_device, PIN_MAP[BOARD_SDIO_D3].gpio_bit, GPIO_INPUT_PU);
|
||||||
gpio_set_mode(PIN_MAP[BOARD_SDIO_CLK].gpio_device, PIN_MAP[BOARD_SDIO_CLK].gpio_bit, GPIO_AF_OUTPUT_PP);
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_CLK].gpio_device, PIN_MAP[BOARD_SDIO_CLK].gpio_bit, GPIO_AF_OUTPUT_PP);
|
||||||
gpio_set_mode(PIN_MAP[BOARD_SDIO_CMD].gpio_device, PIN_MAP[BOARD_SDIO_CMD].gpio_bit, GPIO_AF_OUTPUT_PP);
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_CMD].gpio_device, PIN_MAP[BOARD_SDIO_CMD].gpio_bit, GPIO_AF_OUTPUT_PP);
|
||||||
/*
|
/*
|
||||||
|
@ -63,12 +67,12 @@ void sdio_gpios_init(void)
|
||||||
|
|
||||||
void sdio_gpios_deinit(void)
|
void sdio_gpios_deinit(void)
|
||||||
{
|
{
|
||||||
gpio_set_mode(PIN_MAP[BOARD_SDIO_D0].gpio_device, PIN_MAP[BOARD_SDIO_D0].gpio_bit, GPIO_INPUT_FLOATING);
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_D0].gpio_device, PIN_MAP[BOARD_SDIO_D0].gpio_bit, GPIO_INPUT_PU);
|
||||||
gpio_set_mode(PIN_MAP[BOARD_SDIO_D1].gpio_device, PIN_MAP[BOARD_SDIO_D1].gpio_bit, GPIO_INPUT_FLOATING);
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_D1].gpio_device, PIN_MAP[BOARD_SDIO_D1].gpio_bit, GPIO_INPUT_PU);
|
||||||
gpio_set_mode(PIN_MAP[BOARD_SDIO_D2].gpio_device, PIN_MAP[BOARD_SDIO_D2].gpio_bit, GPIO_INPUT_FLOATING);
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_D2].gpio_device, PIN_MAP[BOARD_SDIO_D2].gpio_bit, GPIO_INPUT_PU);
|
||||||
gpio_set_mode(PIN_MAP[BOARD_SDIO_D3].gpio_device, PIN_MAP[BOARD_SDIO_D3].gpio_bit, GPIO_INPUT_FLOATING);
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_D3].gpio_device, PIN_MAP[BOARD_SDIO_D3].gpio_bit, GPIO_INPUT_PU);
|
||||||
gpio_set_mode(PIN_MAP[BOARD_SDIO_CLK].gpio_device, PIN_MAP[BOARD_SDIO_CLK].gpio_bit, GPIO_INPUT_FLOATING);
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_CLK].gpio_device, PIN_MAP[BOARD_SDIO_CLK].gpio_bit, GPIO_INPUT_PU);
|
||||||
gpio_set_mode(PIN_MAP[BOARD_SDIO_CMD].gpio_device, PIN_MAP[BOARD_SDIO_CMD].gpio_bit, GPIO_INPUT_FLOATING);
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_CMD].gpio_device, PIN_MAP[BOARD_SDIO_CMD].gpio_bit, GPIO_INPUT_PU);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Todo just remove it, not needed for F1.
|
* Todo just remove it, not needed for F1.
|
||||||
|
@ -110,19 +114,35 @@ void sdio_power_off(void)
|
||||||
|
|
||||||
void sdio_set_clock(uint32_t clk)
|
void sdio_set_clock(uint32_t clk)
|
||||||
{
|
{
|
||||||
if (clk>24000000UL) clk = 24000000UL; // limit the SDIO master clock to 24MHz
|
/*
|
||||||
|
* limit the SDIO master clock to 8/3 of PCLK2.See RM 22.3
|
||||||
|
* Also limited to no more than 48Mhz
|
||||||
|
*/
|
||||||
|
clk = min(clk,(SDIOCLK/3)*8);
|
||||||
|
clk = min(clk,36000000);
|
||||||
|
|
||||||
if (clk<1000000) dly = DELAY_LONG;
|
if (clk<1000000) dly = DELAY_LONG;
|
||||||
else dly = DELAY_SHORT;
|
else dly = DELAY_SHORT;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* round up divider, so we don't run the card over the speed supported.
|
||||||
|
|
||||||
|
*/
|
||||||
|
uint32 div = SDIOCLK/clk + (SDIOCLK % clk != 0) - 2;
|
||||||
|
|
||||||
|
|
||||||
sdio_disable();
|
sdio_disable();
|
||||||
SDIO->CLKCR = (SDIO->CLKCR & (~(SDIO_CLKCR_CLKDIV|SDIO_CLKCR_BYPASS))) | SDIO_CLKCR_CLKEN | (((SDIOCLK/clk)-2)&SDIO_CLKCR_CLKDIV);
|
//Serial.println(div,DEC);
|
||||||
|
SDIO->CLKCR = (SDIO->CLKCR & (~(SDIO_CLKCR_CLKDIV|SDIO_CLKCR_BYPASS))) | SDIO_CLKCR_PWRSAV | SDIO_CLKCR_HWFC_EN | SDIO_CLKCR_CLKEN | (div & SDIO_CLKCR_CLKDIV);
|
||||||
delay_us(dly);
|
delay_us(dly);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sdio_set_dbus_width(uint16_t bus_w)
|
void sdio_set_dbus_width(uint16_t bus_w)
|
||||||
{
|
{
|
||||||
SDIO->CLKCR = (SDIO->CLKCR & (~SDIO_CLKCR_WIDBUS)) | bus_w;
|
SDIO->CLKCR = (SDIO->CLKCR & (~SDIO_CLKCR_WIDBUS)) | bus_w;
|
||||||
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_D1].gpio_device, PIN_MAP[BOARD_SDIO_D1].gpio_bit, GPIO_AF_OUTPUT_PP);
|
||||||
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_D2].gpio_device, PIN_MAP[BOARD_SDIO_D2].gpio_bit, GPIO_AF_OUTPUT_PP);
|
||||||
|
gpio_set_mode(PIN_MAP[BOARD_SDIO_D3].gpio_device, PIN_MAP[BOARD_SDIO_D3].gpio_bit, GPIO_AF_OUTPUT_PP);
|
||||||
delay_us(dly);
|
delay_us(dly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,9 +169,10 @@ void sdio_disable(void)
|
||||||
*/
|
*/
|
||||||
void sdio_begin(void)
|
void sdio_begin(void)
|
||||||
{
|
{
|
||||||
sdio_gpios_init();
|
|
||||||
sdio_init();
|
sdio_init();
|
||||||
sdio_power_on();
|
sdio_power_on();
|
||||||
|
sdio_gpios_init();
|
||||||
// Set initial SCK rate.
|
// Set initial SCK rate.
|
||||||
sdio_set_clock(400000);
|
sdio_set_clock(400000);
|
||||||
delay_us(200); // generate 80 pulses at 400kHz
|
delay_us(200); // generate 80 pulses at 400kHz
|
||||||
|
@ -162,11 +183,11 @@ void sdio_begin(void)
|
||||||
*/
|
*/
|
||||||
void sdio_end(void)
|
void sdio_end(void)
|
||||||
{
|
{
|
||||||
sdio_disable();
|
while ( sdio_cmd_xfer_ongoing() );
|
||||||
while ( sdio_cmd_xfer_ongoing() );
|
sdio_disable();
|
||||||
|
sdio_gpios_deinit();
|
||||||
sdio_power_off();
|
sdio_power_off();
|
||||||
rcc_clk_disable(RCC_SDIO);
|
rcc_clk_disable(RCC_SDIO);
|
||||||
sdio_gpios_deinit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
#ifndef _SDIOF4_H_
|
#ifndef _SDIOF1_H_
|
||||||
#define _SDIOF4_H_
|
#define _SDIOF1_H_
|
||||||
|
|
||||||
#include <SdFat.h>
|
#include <SdFat.h>
|
||||||
|
|
||||||
|
|
|
@ -52,19 +52,19 @@ extern "C" {
|
||||||
|
|
||||||
// SDIO register map type
|
// SDIO register map type
|
||||||
typedef struct sdio_reg_map {
|
typedef struct sdio_reg_map {
|
||||||
__io uint32 POWER; // 0x00
|
__IO uint32 POWER; // 0x00
|
||||||
__io uint32 CLKCR; // 0x04
|
__IO uint32 CLKCR; // 0x04
|
||||||
__io uint32 ARG; // 0x08
|
__IO uint32 ARG; // 0x08
|
||||||
__io uint32 CMD; // 0x0C
|
__IO uint32 CMD; // 0x0C
|
||||||
__io uint32 RESPCMD; // 0x10 (0x3F)
|
__IO uint32 RESPCMD; // 0x10 (0x3F)
|
||||||
__io const uint32 RESP[4]; // 0x14 - contain the card status, which is part of the received response.
|
__IO const uint32 RESP[4]; // 0x14 - contain the card status, which is part of the received response.
|
||||||
__io uint32 DTIMER; // 0x24 - contains the data timeout period, in card bus clock periods.
|
__IO uint32 DTIMER; // 0x24 - contains the data timeout period, in card bus clock periods.
|
||||||
__io uint32 DLEN; // 0x28 (0x01FF FFFF) - contains the number of data bytes to be transferred
|
__IO uint32 DLEN; // 0x28 (0x01FF FFFF) - contains the number of data bytes to be transferred
|
||||||
__io uint32 DCTRL; // 0x2C
|
__IO uint32 DCTRL; // 0x2C
|
||||||
__io uint32 DCOUNT; // 0x30 (0x01FF FFFF)
|
__IO uint32 DCOUNT; // 0x30 (0x01FF FFFF)
|
||||||
__io uint32 STA; // 0x34
|
__IO uint32 STA; // 0x34
|
||||||
__io uint32 ICR; // 0x38
|
__IO uint32 ICR; // 0x38
|
||||||
__io uint32 MASK; // 0x3C
|
__IO uint32 MASK; // 0x3C
|
||||||
const uint32 RESERVED1[2];
|
const uint32 RESERVED1[2];
|
||||||
__IO uint32 FIFOCNT; // 0x48 (0x01FF FFFF)
|
__IO uint32 FIFOCNT; // 0x48 (0x01FF FFFF)
|
||||||
const uint32 RESERVED2[13];
|
const uint32 RESERVED2[13];
|
||||||
|
|
Loading…
Reference in New Issue