diff --git a/boards/arm/gd32f4/gd32f450zk-eval/src/gd32f4xx_sdio.c b/boards/arm/gd32f4/gd32f450zk-eval/src/gd32f4xx_sdio.c index c23e7d69a47..f3ec5fff554 100644 --- a/boards/arm/gd32f4/gd32f450zk-eval/src/gd32f4xx_sdio.c +++ b/boards/arm/gd32f4/gd32f450zk-eval/src/gd32f4xx_sdio.c @@ -57,7 +57,7 @@ static struct sdio_dev_s *g_sdio_dev; #ifdef HAVE_NCD -static bool g_sd_inserted = 0xff; /* Impossible value */ +static bool g_sd_inserted; #endif /**************************************************************************** @@ -104,13 +104,6 @@ int gd32_sdio_initialize(void) { int ret; -#ifdef HAVE_NCD - /* Card detect */ - - bool cd_status; - -#endif - /* Mount the SDIO-based MMC/SD block driver * First, get an instance of the SDIO interface */ @@ -140,10 +133,10 @@ int gd32_sdio_initialize(void) #ifdef HAVE_NCD /* Use SD card detect pin to check if a card is g_sd_inserted */ - cd_status = !gd32_gpio_read(GPIO_SDMMC1_NCD); - finfo("Card detect : %d\n", cd_status); + g_sd_inserted = !gd32_gpio_read(GPIO_SDMMC1_NCD); + finfo("Card detect : %d\n", g_sd_inserted); - sdio_mediachange(g_sdio_dev, cd_status); + sdio_mediachange(g_sdio_dev, g_sd_inserted); #else /* Assume that the SD card is inserted. What choice do we have? */ diff --git a/boards/arm/lpc17xx_40xx/lpc4088-quickstart/src/lpc17_40_bringup.c b/boards/arm/lpc17xx_40xx/lpc4088-quickstart/src/lpc17_40_bringup.c index b8f95cc9238..f7e8c0e9ae9 100644 --- a/boards/arm/lpc17xx_40xx/lpc4088-quickstart/src/lpc17_40_bringup.c +++ b/boards/arm/lpc17xx_40xx/lpc4088-quickstart/src/lpc17_40_bringup.c @@ -151,6 +151,9 @@ static struct usbhost_connection_s *g_usbconn; #ifdef NSH_HAVE_MMCSD static struct sdio_dev_s *g_sdiodev; #endif +#ifdef NSH_HAVE_MMCSD_CD +static bool g_sd_inserted; +#endif /**************************************************************************** * Private Functions @@ -205,14 +208,13 @@ static int nsh_waiter(int argc, char *argv[]) #ifdef NSH_HAVE_MMCSD_CDINT static int nsh_cdinterrupt(int irq, void *context, void *arg) { - static bool inserted = 0xff; /* Impossible value */ bool present; present = !lpc17_40_gpioread(GPIO_SD_CD); - if (present != inserted) + if (present != g_sd_inserted) { sdio_mediachange(g_sdiodev, present); - inserted = present; + g_sd_inserted = present; } return OK; @@ -275,7 +277,8 @@ static int nsh_sdinitialize(void) */ #ifdef NSH_HAVE_MMCSD_CD - sdio_mediachange(g_sdiodev, !lpc17_40_gpioread(GPIO_SD_CD)); + g_sd_inserted = !lpc17_40_gpioread(GPIO_SD_CD); + sdio_mediachange(g_sdiodev, g_sd_inserted); #else sdio_mediachange(g_sdiodev, true); #endif diff --git a/boards/arm/lpc17xx_40xx/lx_cpu/src/lpc17_40_bringup.c b/boards/arm/lpc17xx_40xx/lx_cpu/src/lpc17_40_bringup.c index 076f2f1141e..53936d59180 100644 --- a/boards/arm/lpc17xx_40xx/lx_cpu/src/lpc17_40_bringup.c +++ b/boards/arm/lpc17xx_40xx/lx_cpu/src/lpc17_40_bringup.c @@ -150,6 +150,9 @@ static struct usbhost_connection_s *g_usbconn; #ifdef NSH_HAVE_MMCSD static struct sdio_dev_s *g_sdiodev; #endif +#ifdef NSH_HAVE_MMCSD_CD +static bool g_sd_inserted; +#endif /**************************************************************************** * Private Functions @@ -204,14 +207,13 @@ static int nsh_waiter(int argc, char *argv[]) #ifdef NSH_HAVE_MMCSD_CDINT static int nsh_cdinterrupt(int irq, void *context, void *arg) { - static bool inserted = 0xff; /* Impossible value */ bool present; present = !lpc17_40_gpioread(GPIO_SD_CD); - if (present != inserted) + if (present != g_sd_inserted) { sdio_mediachange(g_sdiodev, present); - inserted = present; + g_sd_inserted = present; } return OK; @@ -273,7 +275,8 @@ static int nsh_sdinitialize(void) */ #ifdef NSH_HAVE_MMCSD_CD - sdio_mediachange(g_sdiodev, !lpc17_40_gpioread(GPIO_SD_CD)); + g_sd_inserted = !lpc17_40_gpioread(GPIO_SD_CD); + sdio_mediachange(g_sdiodev, g_sd_inserted); #else sdio_mediachange(g_sdiodev, true); #endif diff --git a/boards/arm/lpc17xx_40xx/lx_cpu/src/lpc17_40_nsh.c b/boards/arm/lpc17xx_40xx/lx_cpu/src/lpc17_40_nsh.c index f0840073fb5..235923e8cd4 100644 --- a/boards/arm/lpc17xx_40xx/lx_cpu/src/lpc17_40_nsh.c +++ b/boards/arm/lpc17xx_40xx/lx_cpu/src/lpc17_40_nsh.c @@ -147,6 +147,9 @@ static struct usbhost_connection_s *g_usbconn; #ifdef NSH_HAVE_MMCSD static struct sdio_dev_s *g_sdiodev; #endif +#ifdef NSH_HAVE_MMCSD_CD +static bool g_sd_inserted; +#endif /**************************************************************************** * Private Functions @@ -201,14 +204,13 @@ static int nsh_waiter(int argc, char *argv[]) #ifdef NSH_HAVE_MMCSD_CDINT static int nsh_cdinterrupt(int irq, void *context) { - static bool inserted = 0xff; /* Impossible value */ bool present; present = !lpc17_40_gpioread(GPIO_SD_CD); - if (present != inserted) + if (present != g_sd_inserted) { sdio_mediachange(g_sdiodev, present); - inserted = present; + g_sd_inserted = present; } return OK; @@ -270,7 +272,8 @@ static int nsh_sdinitialize(void) */ #ifdef NSH_HAVE_MMCSD_CD - sdio_mediachange(g_sdiodev, !lpc17_40_gpioread(GPIO_SD_CD)); + g_sd_inserted = !lpc17_40_gpioread(GPIO_SD_CD); + sdio_mediachange(g_sdiodev, g_sd_inserted); #else sdio_mediachange(g_sdiodev, true); #endif diff --git a/boards/arm/lpc17xx_40xx/open1788/src/lpc17_40_bringup.c b/boards/arm/lpc17xx_40xx/open1788/src/lpc17_40_bringup.c index 63688f8aa03..4f76aad9b6a 100644 --- a/boards/arm/lpc17xx_40xx/open1788/src/lpc17_40_bringup.c +++ b/boards/arm/lpc17xx_40xx/open1788/src/lpc17_40_bringup.c @@ -150,6 +150,9 @@ static struct usbhost_connection_s *g_usbconn; #ifdef NSH_HAVE_MMCSD static struct sdio_dev_s *g_sdiodev; #endif +#ifdef NSH_HAVE_MMCSD_CD +static bool g_sd_inserted; +#endif /**************************************************************************** * Private Functions @@ -204,14 +207,13 @@ static int nsh_waiter(int argc, char *argv[]) #ifdef NSH_HAVE_MMCSD_CDINT static int nsh_cdinterrupt(int irq, void *context, void *arg) { - static bool inserted = 0xff; /* Impossible value */ bool present; present = !lpc17_40_gpioread(GPIO_SD_CD); - if (present != inserted) + if (present != g_sd_inserted) { sdio_mediachange(g_sdiodev, present); - inserted = present; + g_sd_inserted = present; } return OK; @@ -274,7 +276,8 @@ static int nsh_sdinitialize(void) */ #ifdef NSH_HAVE_MMCSD_CD - sdio_mediachange(g_sdiodev, !lpc17_40_gpioread(GPIO_SD_CD)); + g_sd_inserted = !lpc17_40_gpioread(GPIO_SD_CD); + sdio_mediachange(g_sdiodev, g_sd_inserted); #else sdio_mediachange(g_sdiodev, true); #endif diff --git a/boards/arm/stm32/axoloti/src/stm32_sdio.c b/boards/arm/stm32/axoloti/src/stm32_sdio.c index 6d51212fc14..5b6ed6b407f 100644 --- a/boards/arm/stm32/axoloti/src/stm32_sdio.c +++ b/boards/arm/stm32/axoloti/src/stm32_sdio.c @@ -54,7 +54,7 @@ static struct sdio_dev_s *g_sdio_dev; #ifdef HAVE_NCD -static bool g_sd_inserted = 0xff; /* Impossible value */ +static bool g_sd_inserted; #endif /**************************************************************************** @@ -102,8 +102,6 @@ int stm32_sdio_initialize(void) int ret; #ifdef HAVE_NCD - bool cd_status; - /* Configure the card detect GPIO */ stm32_configgpio(GPIO_SDIO_NCD); @@ -112,7 +110,6 @@ int stm32_sdio_initialize(void) stm32_gpiosetevent(GPIO_SDIO_NCD, true, true, true, stm32_ncd_interrupt, NULL); - #endif /* Mount the SDIO-based MMC/SD block driver. @@ -142,9 +139,9 @@ int stm32_sdio_initialize(void) #ifdef HAVE_NCD /* Use SD card detect pin to check if a card is g_sd_inserted */ - cd_status = !stm32_gpioread(GPIO_SDIO_NCD); - finfo("Card detect : %d\n", cd_status); - sdio_mediachange(g_sdio_dev, cd_status); + g_sd_inserted = !stm32_gpioread(GPIO_SDIO_NCD); + finfo("Card detect : %d\n", g_sd_inserted); + sdio_mediachange(g_sdio_dev, g_sd_inserted); #else /* Assume that the SD card is inserted. What choice do we have? */ diff --git a/boards/arm/stm32/hymini-stm32v/src/stm32_appinit.c b/boards/arm/stm32/hymini-stm32v/src/stm32_appinit.c index 444bac8cddd..97dd73b5b9e 100644 --- a/boards/arm/stm32/hymini-stm32v/src/stm32_appinit.c +++ b/boards/arm/stm32/hymini-stm32v/src/stm32_appinit.c @@ -95,6 +95,7 @@ #ifdef CONFIG_MMCSD static struct sdio_dev_s *g_sdiodev; +static bool g_sd_inserted; #endif /**************************************************************************** @@ -112,14 +113,13 @@ static struct sdio_dev_s *g_sdiodev; #ifdef NSH_HAVEMMCSD static int nsh_cdinterrupt(int irq, void *context, void *arg) { - static bool inserted = 0xff; /* Impossible value */ bool present; present = !stm32_gpioread(GPIO_SD_CD); - if (present != inserted) + if (present != g_sd_inserted) { sdio_mediachange(g_sdiodev, present); - inserted = present; + g_sd_inserted = present; } return OK; @@ -158,10 +158,6 @@ int board_app_initialize(uintptr_t arg) int ret; #ifdef NSH_HAVEMMCSD - /* Card detect */ - - bool cd_status; - /* Configure the card detect GPIO */ stm32_configgpio(GPIO_SD_CD); @@ -203,10 +199,10 @@ int board_app_initialize(uintptr_t arg) /* Use SD card detect pin to check if a card is inserted */ - cd_status = !stm32_gpioread(GPIO_SD_CD); - _info("Card detect : %hhu\n", cd_status); + g_sd_inserted = !stm32_gpioread(GPIO_SD_CD); + _info("Card detect : %hhu\n", g_sd_inserted); - sdio_mediachange(g_sdiodev, cd_status); + sdio_mediachange(g_sdiodev, g_sd_inserted); #endif #ifdef CONFIG_INPUT diff --git a/boards/arm/stm32/nucleo-f429zi/src/stm32_sdio.c b/boards/arm/stm32/nucleo-f429zi/src/stm32_sdio.c index 8d078898ac3..bb9ccb98f3a 100644 --- a/boards/arm/stm32/nucleo-f429zi/src/stm32_sdio.c +++ b/boards/arm/stm32/nucleo-f429zi/src/stm32_sdio.c @@ -58,7 +58,7 @@ static struct sdio_dev_s *g_sdio_dev; #ifdef HAVE_NCD -static bool g_sd_inserted = 0xff; /* Impossible value */ +static bool g_sd_inserted; #endif /**************************************************************************** @@ -106,10 +106,6 @@ int stm32_sdio_initialize(void) int ret; #ifdef HAVE_NCD - /* Card detect */ - - bool cd_status; - /* Configure the card detect GPIO */ stm32_configgpio(GPIO_SDMMC1_NCD); @@ -149,10 +145,10 @@ int stm32_sdio_initialize(void) #ifdef HAVE_NCD /* Use SD card detect pin to check if a card is g_sd_inserted */ - cd_status = !stm32_gpioread(GPIO_SDMMC1_NCD); - finfo("Card detect : %d\n", cd_status); + g_sd_inserted = !stm32_gpioread(GPIO_SDMMC1_NCD); + finfo("Card detect : %d\n", g_sd_inserted); - sdio_mediachange(g_sdio_dev, cd_status); + sdio_mediachange(g_sdio_dev, g_sd_inserted); #else /* Assume that the SD card is inserted. What choice do we have? */ diff --git a/boards/arm/stm32/olimex-stm32-h407/src/stm32_sdio.c b/boards/arm/stm32/olimex-stm32-h407/src/stm32_sdio.c index dba5a0f3f38..5a22fff6a9b 100644 --- a/boards/arm/stm32/olimex-stm32-h407/src/stm32_sdio.c +++ b/boards/arm/stm32/olimex-stm32-h407/src/stm32_sdio.c @@ -56,7 +56,7 @@ static struct sdio_dev_s *g_sdio_dev; #ifdef HAVE_NCD -static bool g_sd_inserted = 0xff; /* Impossible value */ +static bool g_sd_inserted; #endif /**************************************************************************** @@ -104,10 +104,6 @@ int stm32_sdio_initialize(void) int ret; #ifdef HAVE_NCD - /* Card detect */ - - bool cd_status; - /* Configure the card detect GPIO */ stm32_configgpio(GPIO_SDIO_NCD); @@ -147,10 +143,10 @@ int stm32_sdio_initialize(void) #ifdef HAVE_NCD /* Use SD card detect pin to check if a card is g_sd_inserted */ - cd_status = !stm32_gpioread(GPIO_SDIO_NCD); - finfo("Card detect : %d\n", cd_status); + g_sd_inserted = !stm32_gpioread(GPIO_SDIO_NCD); + finfo("Card detect : %d\n", g_sd_inserted); - sdio_mediachange(g_sdio_dev, cd_status); + sdio_mediachange(g_sdio_dev, g_sd_inserted); #else /* Assume that the SD card is inserted. What choice do we have? */ diff --git a/boards/arm/stm32/stm32f4discovery/src/stm32_sdio.c b/boards/arm/stm32/stm32f4discovery/src/stm32_sdio.c index 81f55ecdb51..e98d493668f 100644 --- a/boards/arm/stm32/stm32f4discovery/src/stm32_sdio.c +++ b/boards/arm/stm32/stm32f4discovery/src/stm32_sdio.c @@ -56,7 +56,7 @@ static struct sdio_dev_s *g_sdio_dev; #ifdef HAVE_NCD -static bool g_sd_inserted = 0xff; /* Impossible value */ +static bool g_sd_inserted; #endif /**************************************************************************** @@ -104,10 +104,6 @@ int stm32_sdio_initialize(void) int ret; #ifdef HAVE_NCD - /* Card detect */ - - bool cd_status; - /* Configure the card detect GPIO */ stm32_configgpio(GPIO_SDIO_NCD); @@ -147,10 +143,10 @@ int stm32_sdio_initialize(void) #ifdef HAVE_NCD /* Use SD card detect pin to check if a card is g_sd_inserted */ - cd_status = !stm32_gpioread(GPIO_SDIO_NCD); - finfo("Card detect : %d\n", cd_status); + g_sd_inserted = !stm32_gpioread(GPIO_SDIO_NCD); + finfo("Card detect : %d\n", g_sd_inserted); - sdio_mediachange(g_sdio_dev, cd_status); + sdio_mediachange(g_sdio_dev, g_sd_inserted); #else /* Assume that the SD card is inserted. What choice do we have? */ diff --git a/boards/arm/stm32f7/nucleo-144/src/stm32_sdio.c b/boards/arm/stm32f7/nucleo-144/src/stm32_sdio.c index f8c7ff43f34..f385dc66578 100644 --- a/boards/arm/stm32f7/nucleo-144/src/stm32_sdio.c +++ b/boards/arm/stm32f7/nucleo-144/src/stm32_sdio.c @@ -58,7 +58,7 @@ static struct sdio_dev_s *g_sdio_dev; #ifdef HAVE_NCD -static bool g_sd_inserted = 0xff; /* Impossible value */ +static bool g_sd_inserted; #endif /**************************************************************************** @@ -106,10 +106,6 @@ int stm32_sdio_initialize(void) int ret; #ifdef HAVE_NCD - /* Card detect */ - - bool cd_status; - /* Configure the card detect GPIO */ stm32_configgpio(GPIO_SDMMC1_NCD); @@ -149,10 +145,10 @@ int stm32_sdio_initialize(void) #ifdef HAVE_NCD /* Use SD card detect pin to check if a card is g_sd_inserted */ - cd_status = !stm32_gpioread(GPIO_SDMMC1_NCD); - finfo("Card detect : %d\n", cd_status); + g_sd_inserted = !stm32_gpioread(GPIO_SDMMC1_NCD); + finfo("Card detect : %d\n", g_sd_inserted); - sdio_mediachange(g_sdio_dev, cd_status); + sdio_mediachange(g_sdio_dev, g_sd_inserted); #else /* Assume that the SD card is inserted. What choice do we have? */ diff --git a/boards/arm/stm32f7/stm32f746-ws/src/stm32_sdmmc.c b/boards/arm/stm32f7/stm32f746-ws/src/stm32_sdmmc.c index 8e0ef272559..67a6405c3e0 100644 --- a/boards/arm/stm32f7/stm32f746-ws/src/stm32_sdmmc.c +++ b/boards/arm/stm32f7/stm32f746-ws/src/stm32_sdmmc.c @@ -54,7 +54,7 @@ static struct sdio_dev_s *g_sdio_dev; #ifdef HAVE_NCD -static bool g_sd_inserted = 0xff; /* Impossible value */ +static bool g_sd_inserted; #endif /**************************************************************************** @@ -102,10 +102,6 @@ int stm32_sdio_initialize(void) int ret; #ifdef HAVE_NCD - /* Card detect */ - - bool cd_status; - /* Configure the card detect GPIO */ stm32_configgpio(GPIO_SDIO_NCD); @@ -145,10 +141,10 @@ int stm32_sdio_initialize(void) #ifdef HAVE_NCD /* Use SD card detect pin to check if a card is g_sd_inserted */ - cd_status = !stm32_gpioread(GPIO_SDIO_NCD); - finfo("Card detect : %d\n", cd_status); + g_sd_inserted = !stm32_gpioread(GPIO_SDIO_NCD); + finfo("Card detect : %d\n", g_sd_inserted); - sdio_mediachange(g_sdio_dev, cd_status); + sdio_mediachange(g_sdio_dev, g_sd_inserted); #else /* Assume that the SD card is inserted. What choice do we have? */ diff --git a/boards/arm/stm32f7/stm32f746g-disco/src/stm32_sdmmc.c b/boards/arm/stm32f7/stm32f746g-disco/src/stm32_sdmmc.c index f042b37ed40..ca0d57d2fd0 100644 --- a/boards/arm/stm32f7/stm32f746g-disco/src/stm32_sdmmc.c +++ b/boards/arm/stm32f7/stm32f746g-disco/src/stm32_sdmmc.c @@ -55,7 +55,7 @@ static struct sdio_dev_s *g_sdio_dev; #ifdef HAVE_NCD -static bool g_sd_inserted = 0xff; /* Impossible value */ +static bool g_sd_inserted; #endif /**************************************************************************** @@ -103,10 +103,6 @@ int stm32_sdio_initialize(void) int ret; #ifdef HAVE_NCD - /* Card detect */ - - bool cd_status; - /* Configure the card detect GPIO */ stm32_configgpio(GPIO_SDIO_NCD); @@ -146,10 +142,10 @@ int stm32_sdio_initialize(void) #ifdef HAVE_NCD /* Use SD card detect pin to check if a card is g_sd_inserted */ - cd_status = !stm32_gpioread(GPIO_SDIO_NCD); - finfo("Card detect : %d\n", cd_status); + g_sd_inserted = !stm32_gpioread(GPIO_SDIO_NCD); + finfo("Card detect : %d\n", g_sd_inserted); - sdio_mediachange(g_sdio_dev, cd_status); + sdio_mediachange(g_sdio_dev, g_sd_inserted); #else /* Assume that the SD card is inserted. What choice do we have? */ diff --git a/boards/arm/stm32h7/stm32h747i-disco/src/stm32_sdmmc.c b/boards/arm/stm32h7/stm32h747i-disco/src/stm32_sdmmc.c index f897baf3843..3a044a5a035 100644 --- a/boards/arm/stm32h7/stm32h747i-disco/src/stm32_sdmmc.c +++ b/boards/arm/stm32h7/stm32h747i-disco/src/stm32_sdmmc.c @@ -55,7 +55,7 @@ static struct sdio_dev_s *g_sdio_dev; #ifdef HAVE_NCD -static bool g_sd_inserted = 0xff; /* Impossible value */ +static bool g_sd_inserted; #endif /**************************************************************************** @@ -103,10 +103,6 @@ int stm32_sdio_initialize(void) int ret; #ifdef HAVE_NCD - /* Card detect */ - - bool cd_status; - /* Configure the card detect GPIO */ stm32_configgpio(GPIO_SDIO_NCD); @@ -146,10 +142,10 @@ int stm32_sdio_initialize(void) #ifdef HAVE_NCD /* Use SD card detect pin to check if a card is g_sd_inserted */ - cd_status = !stm32_gpioread(GPIO_SDIO_NCD); - finfo("Card detect : %d\n", cd_status); + g_sd_inserted = !stm32_gpioread(GPIO_SDIO_NCD); + finfo("Card detect : %d\n", g_sd_inserted); - sdio_mediachange(g_sdio_dev, cd_status); + sdio_mediachange(g_sdio_dev, g_sd_inserted); #else /* Assume that the SD card is inserted. What choice do we have? */ diff --git a/boards/arm/stm32l4/nucleo-l496zg/src/stm32_sdio.c b/boards/arm/stm32l4/nucleo-l496zg/src/stm32_sdio.c index 6c160f1649a..8b19da0e306 100644 --- a/boards/arm/stm32l4/nucleo-l496zg/src/stm32_sdio.c +++ b/boards/arm/stm32l4/nucleo-l496zg/src/stm32_sdio.c @@ -58,7 +58,7 @@ static struct sdio_dev_s *g_sdio_dev; #ifdef HAVE_NCD -static bool g_sd_inserted = 0xff; /* Impossible value */ +static bool g_sd_inserted; #endif /**************************************************************************** @@ -106,10 +106,6 @@ int stm32l4_sdio_initialize(void) int ret; #ifdef HAVE_NCD - /* Card detect */ - - bool cd_status; - /* Configure the card detect GPIO */ stm32l4_configgpio(GPIO_SDMMC1_NCD); @@ -149,10 +145,10 @@ int stm32l4_sdio_initialize(void) #ifdef HAVE_NCD /* Use SD card detect pin to check if a card is g_sd_inserted */ - cd_status = !stm32l4_gpioread(GPIO_SDMMC1_NCD); - finfo("Card detect : %d\n", cd_status); + g_sd_inserted = !stm32l4_gpioread(GPIO_SDMMC1_NCD); + finfo("Card detect : %d\n", g_sd_inserted); - sdio_mediachange(g_sdio_dev, cd_status); + sdio_mediachange(g_sdio_dev, g_sd_inserted); #else /* Assume that the SD card is inserted. What choice do we have? */