@@ -853,8 +853,8 @@ static rt_err_t bsp_spiSd_contex_init(struct bsp_sd_contex *ctx,
853853 ctx->dev .write = bsp_spiSd_write;
854854 ctx->dev .control = bsp_spiSd_control;
855855 ctx->dev .user_data = (void *)ctx;
856- ret = rt_device_register (&ctx->dev , name, RT_DEVICE_FLAG_RDWR | \
857- RT_DEVICE_FLAG_REMOVABLE);
856+ ret = rt_device_register (&ctx->dev , name,
857+ RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE);
858858 } while (0 );
859859
860860 return ret;
@@ -899,8 +899,7 @@ rt_err_t bsp_hw_spiSd_init(void) {
899899/* ******************************************************************************
900900 * Export to FINSH
901901 ******************************************************************************/
902- #if 0 //#ifdef RT_USING_FINSH
903- #include "components/finsh/finsh.h"
902+ #ifdef RT_USING_FINSH
904903
905904rt_err_t list_sd (void ) {
906905 struct bsp_sd_contex *ctx = SD_CTX ();
@@ -914,16 +913,23 @@ rt_err_t list_sd(void) {
914913 rt_kprintf (" Error: open failed!\n " );
915914 return ret;
916915 }
916+ if (RT_EOK != (ret = rt_device_open (ctx->ldev , RT_DEVICE_OFLAG_RDWR))) {
917+ rt_kprintf (" Error: open ldev failed!\n " );
918+ rt_device_close (&ctx->dev );
919+ return ret;
920+ }
917921 SD_CS (1 );
918922
919923 /* Receive CID as a data block (16 bytes) */
920924 if (sd_send_cmd (ctx, CMD10, 0x00000000 , buf_res)) {
921925 SD_CS (0 );
926+ rt_device_close (ctx->ldev );
922927 rt_device_close (&ctx->dev );
923928 rt_kprintf (" Error: Get CID failed!\n " );
924929 return -RT_ERROR;
925930 }
926931 SD_CS (0 );
932+ rt_device_close (ctx->ldev );
927933
928934 rt_kprintf (" SD Card on %s\n " , ctx->ldev ->parent .name );
929935 rt_kprintf (" ------------------------------\n " );
@@ -964,7 +970,7 @@ rt_err_t list_sd(void) {
964970
965971 return RT_EOK;
966972}
967- FINSH_FUNCTION_EXPORT(list_sd, list the SD card .)
973+ FINSH_FUNCTION_EXPORT (list_sd, show SD information .)
968974#endif /* RT_USING_FINSH */
969975
970976/* **************************************************************************/ /* *
0 commit comments