[bsp][stm32][f469-disco]Add SD card hot plug detection

Signed-off-by: Willian Chan <chentingwei@rt-thread.com>
This commit is contained in:
Willian Chan 2019-06-12 09:51:12 +08:00
parent 91c858ead2
commit 33febada5c
6 changed files with 114 additions and 15 deletions

View File

@ -7,6 +7,7 @@
* Date Author Notes * Date Author Notes
* 2018-06-22 tyx first * 2018-06-22 tyx first
* 2018-12-12 balanceTWK first version * 2018-12-12 balanceTWK first version
* 2019-06-11 WillianChan Add SD card hot plug detection
*/ */
#include "board.h" #include "board.h"
@ -878,4 +879,9 @@ int rt_hw_sdio_init(void)
} }
INIT_DEVICE_EXPORT(rt_hw_sdio_init); INIT_DEVICE_EXPORT(rt_hw_sdio_init);
void stm32_mmcsd_change(void)
{
mmcsd_change(host);
}
#endif #endif

View File

@ -6,6 +6,7 @@
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2018-12-13 BalanceTWK first version * 2018-12-13 BalanceTWK first version
* 2019-06-11 WillianChan Add SD card hot plug detection
*/ */
#ifndef _DRV_SDIO_H #ifndef _DRV_SDIO_H
@ -187,4 +188,6 @@ struct stm32_sdio_class
} dma; } dma;
}; };
extern void stm32_mmcsd_change(void);
#endif #endif

View File

@ -66,8 +66,9 @@ CONFIG_RT_USING_DEVICE=y
CONFIG_RT_USING_CONSOLE=y CONFIG_RT_USING_CONSOLE=y
CONFIG_RT_CONSOLEBUF_SIZE=128 CONFIG_RT_CONSOLEBUF_SIZE=128
CONFIG_RT_CONSOLE_DEVICE_NAME="uart3" CONFIG_RT_CONSOLE_DEVICE_NAME="uart3"
CONFIG_RT_VER_NUM=0x40001 CONFIG_RT_VER_NUM=0x40002
CONFIG_ARCH_ARM=y CONFIG_ARCH_ARM=y
CONFIG_RT_USING_CPU_FFS=y
CONFIG_ARCH_ARM_CORTEX_M=y CONFIG_ARCH_ARM_CORTEX_M=y
CONFIG_ARCH_ARM_CORTEX_M4=y CONFIG_ARCH_ARM_CORTEX_M4=y
# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set # CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set
@ -169,6 +170,11 @@ CONFIG_RT_MMCSD_MAX_PARTITION=16
# CONFIG_RT_USING_AUDIO is not set # CONFIG_RT_USING_AUDIO is not set
# CONFIG_RT_USING_SENSOR is not set # CONFIG_RT_USING_SENSOR is not set
#
# Using Hardware Crypto drivers
#
# CONFIG_RT_USING_HWCRYPTO is not set
# #
# Using WiFi # Using WiFi
# #
@ -385,6 +391,35 @@ CONFIG_RT_USING_POSIX=y
# CONFIG_PKG_USING_PERIPHERAL_SAMPLES is not set # CONFIG_PKG_USING_PERIPHERAL_SAMPLES is not set
# CONFIG_PKG_USING_HELLO is not set # CONFIG_PKG_USING_HELLO is not set
# CONFIG_PKG_USING_VI is not set # CONFIG_PKG_USING_VI is not set
#
# Privated Packages of RealThread
#
# CONFIG_PKG_USING_CODEC is not set
# CONFIG_PKG_USING_PLAYER is not set
# CONFIG_PKG_USING_MPLAYER is not set
# CONFIG_PKG_USING_PERSIMMON_SRC is not set
# CONFIG_PKG_USING_JS_PERSIMMON is not set
# CONFIG_PKG_USING_JERRYSCRIPT_WIN32 is not set
# CONFIG_PKG_USING_LIBRWS is not set
#
# Network Utilities
#
# CONFIG_PKG_USING_WICED is not set
# CONFIG_PKG_USING_CLOUDSDK is not set
# CONFIG_PKG_USING_COREMARK is not set
# CONFIG_PKG_USING_POWER_MANAGER is not set
# CONFIG_PKG_USING_RT_OTA is not set
# CONFIG_PKG_USING_RDBD_SRC is not set
# CONFIG_PKG_USING_RTINSIGHT is not set
# CONFIG_PKG_USING_SMARTCONFIG is not set
# CONFIG_PKG_USING_RTX is not set
# CONFIG_RT_USING_TESTCASE is not set
# CONFIG_PKG_USING_NGHTTP2 is not set
# CONFIG_PKG_USING_AVS is not set
# CONFIG_PKG_USING_STS is not set
# CONFIG_PKG_USING_DLMS is not set
CONFIG_SOC_FAMILY_STM32=y CONFIG_SOC_FAMILY_STM32=y
CONFIG_SOC_SERIES_STM32F4=y CONFIG_SOC_SERIES_STM32F4=y
@ -397,6 +432,7 @@ CONFIG_SOC_STM32F469NI=y
# Onboard Peripheral Drivers # Onboard Peripheral Drivers
# #
# CONFIG_BSP_USING_SDRAM is not set # CONFIG_BSP_USING_SDRAM is not set
# CONFIG_BSP_USING_LCD_MIPI is not set
# CONFIG_BSP_USING_LCD_OTM8009A is not set # CONFIG_BSP_USING_LCD_OTM8009A is not set
# CONFIG_BSP_USING_QSPI_FLASH is not set # CONFIG_BSP_USING_QSPI_FLASH is not set
# CONFIG_BSP_USING_SDCARD is not set # CONFIG_BSP_USING_SDCARD is not set

View File

@ -43,7 +43,7 @@ STM32F469-ST-DISCO 是 ST 推出的一款基于 ARM Cortex-M4 内核的开发板
| :-----: | :-----: | :-----: | | :-----: | :-----: | :-----: |
| SDRAM | 支持 | 16MB | | SDRAM | 支持 | 16MB |
| LCD | 支持 | MIPI屏otm8009a | | LCD | 支持 | MIPI屏otm8009a |
| SDCARD | 支持 | | | SDCARD | 支持 | 支持热插拔插拔检测间隔为200ms |
| TOUCH | 支持 | ft6206 | | TOUCH | 支持 | ft6206 |
| **片上外设** | **支持情况** | **备注** | | **片上外设** | **支持情况** | **备注** |
| GPIO | 支持 | | | GPIO | 支持 | |

View File

@ -6,6 +6,7 @@
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2018-12-13 balanceTWK add sdcard port file * 2018-12-13 balanceTWK add sdcard port file
* 2019-06-11 WillianChan Add SD card hot plug detection
*/ */
#include <rtthread.h> #include <rtthread.h>
@ -16,28 +17,69 @@
#include <dfs_fs.h> #include <dfs_fs.h>
#include <dfs_posix.h> #include <dfs_posix.h>
#include "drv_gpio.h" #include "drv_gpio.h"
#include "drv_sdio.h"
#define DBG_TAG "app.card" #define DBG_TAG "app.card"
#define DBG_LVL DBG_INFO #define DBG_LVL DBG_INFO
#include <rtdbg.h> #include <rtdbg.h>
void sd_mount(void *parameter) /* SD Card hot plug detection pin */
#define SD_CHECK_PIN GET_PIN(G, 2)
void __mount(void)
{ {
while (1) rt_device_t device;
device = rt_device_find("sd0");
if (device == NULL)
{ {
rt_thread_mdelay(500); mmcsd_wait_cd_changed(0);
if(rt_device_find("sd0") != RT_NULL) stm32_mmcsd_change();
mmcsd_wait_cd_changed(RT_WAITING_FOREVER);
device = rt_device_find("sd0");
}
if (device != RT_NULL)
{ {
if (dfs_mount("sd0", "/", "elm", 0, 0) == RT_EOK) if (dfs_mount("sd0", "/", "elm", 0, 0) == RT_EOK)
{ {
LOG_I("sd card mount to '/'"); LOG_I("sd card mount to '/'");
break;
} }
else else
{ {
LOG_W("sd card mount to '/' failed!"); LOG_W("sd card mount to '/' failed!");
} }
} }
}
void __unmount(void)
{
rt_thread_mdelay(200);
dfs_unmount("/");
LOG_I("Unmount \"/\"");
mmcsd_wait_cd_changed(0);
stm32_mmcsd_change();
mmcsd_wait_cd_changed(RT_WAITING_FOREVER);
}
void sd_mount(void *parameter)
{
rt_uint8_t re_sd_check = 1;
while (1)
{
rt_thread_mdelay(200);
if(re_sd_check && !rt_pin_read(SD_CHECK_PIN))
{
__mount();
}
if (!re_sd_check && rt_pin_read(SD_CHECK_PIN))
{
__unmount();
}
re_sd_check = rt_pin_read(SD_CHECK_PIN);
} }
} }
@ -45,8 +87,10 @@ int stm32_sdcard_mount(void)
{ {
rt_thread_t tid; rt_thread_t tid;
rt_pin_mode(SD_CHECK_PIN, PIN_MODE_INPUT_PULLUP);
tid = rt_thread_create("sd_mount", sd_mount, RT_NULL, tid = rt_thread_create("sd_mount", sd_mount, RT_NULL,
1024, RT_THREAD_PRIORITY_MAX - 2, 20); 1024, RT_THREAD_PRIORITY_MAX - 1, 20);
if (tid != RT_NULL) if (tid != RT_NULL)
{ {
rt_thread_startup(tid); rt_thread_startup(tid);

View File

@ -42,8 +42,9 @@
#define RT_USING_CONSOLE #define RT_USING_CONSOLE
#define RT_CONSOLEBUF_SIZE 128 #define RT_CONSOLEBUF_SIZE 128
#define RT_CONSOLE_DEVICE_NAME "uart3" #define RT_CONSOLE_DEVICE_NAME "uart3"
#define RT_VER_NUM 0x40001 #define RT_VER_NUM 0x40002
#define ARCH_ARM #define ARCH_ARM
#define RT_USING_CPU_FFS
#define ARCH_ARM_CORTEX_M #define ARCH_ARM_CORTEX_M
#define ARCH_ARM_CORTEX_M4 #define ARCH_ARM_CORTEX_M4
@ -109,6 +110,9 @@
#define RT_MMCSD_THREAD_PREORITY 22 #define RT_MMCSD_THREAD_PREORITY 22
#define RT_MMCSD_MAX_PARTITION 16 #define RT_MMCSD_MAX_PARTITION 16
/* Using Hardware Crypto drivers */
/* Using WiFi */ /* Using WiFi */
@ -184,6 +188,12 @@
/* samples: kernel and components samples */ /* samples: kernel and components samples */
/* Privated Packages of RealThread */
/* Network Utilities */
#define SOC_FAMILY_STM32 #define SOC_FAMILY_STM32
#define SOC_SERIES_STM32F4 #define SOC_SERIES_STM32F4