Skip to content

Commit

Permalink
fmuk66-v3:Fix hang on SDIO card removal/reinsertion
Browse files Browse the repository at this point in the history
   The interrupt driven card detect logic was enabled
   but the auto mounter was not. That interrupt was
   calling mmcsd_mediachange.

   There is a reentrancy issues in the kinetis callback logic.
   Toplevel calls mmcsd_mediachange calls SDIO_CALLBACKENABLE
   that calls kinetis_callbackenable that calls kinetis_callback
   that calls mmcsd_mediachange.
  • Loading branch information
davids5 authored and dagar committed Nov 15, 2019
1 parent cacf821 commit 1b313c6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
5 changes: 1 addition & 4 deletions boards/nxp/fmuk66-v3/nuttx-config/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# see misc/tools/kconfig-language.txt.
#

if ARCH_BOARD_NXP_FMUK66_V3
config FMUK66_SDHC_AUTOMOUNT
bool "SDHC automounter"
default n
Expand All @@ -21,7 +20,7 @@ config FMUK66_SDHC_AUTOMOUNT_BLKDEV

config FMUK66_SDHC_AUTOMOUNT_MOUNTPOINT
string "SDHC mount point"
default "/mnt/sdcard"
default "/fs/microsd"

config FMUK66_SDHC_AUTOMOUNT_DDELAY
int "SDHC debounce delay (milliseconds)"
Expand All @@ -46,5 +45,3 @@ config BOARD_USE_PROBES

---help---
Select to use GPIO FMU-CH1-6 to provide timing signals from selected drivers.

endif
8 changes: 7 additions & 1 deletion boards/nxp/fmuk66-v3/nuttx-config/nsh/defconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_DISABLE_OS_API is not set
# CONFIG_MMCSD_HAVE_WRITEPROTECT is not set
# CONFIG_MMCSD_SPI is not set
Expand Down Expand Up @@ -170,7 +177,6 @@ CONFIG_SDCLONE_DISABLE=y
CONFIG_SEM_NNESTPRIO=8
CONFIG_SEM_PREALLOCHOLDERS=0
CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS=y
CONFIG_SERIAL_TERMIOS=y
CONFIG_SIG_DEFAULT=y
CONFIG_SIG_SIGALRM_ACTION=y
CONFIG_SIG_SIGUSR1_ACTION=y
Expand Down
2 changes: 1 addition & 1 deletion boards/nxp/fmuk66-v3/src/board_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ __BEGIN_DECLS
*/
#define SD_CAED_P_EN (GPIO_LOWDRIVE | GPIO_OUTPUT_ONE | PIN_PORTD | PIN6)

#define GPIO_SD_CARDDETECT (GPIO_PULLUP | PIN_INT_BOTH | PIN_PORTD | PIN10)
//#define GPIO_SD_CARDDETECT (GPIO_PULLUP | PIN_INT_BOTH | PIN_PORTD | PIN10)

/* SPI
*
Expand Down
9 changes: 8 additions & 1 deletion boards/nxp/fmuk66-v3/src/sdhc.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ static struct fmuk66_sdhc_state_s g_sdhc;
* Private Functions
****************************************************************************/

#if defined(GPIO_SD_CARDDETECT)
/****************************************************************************
* Name: fmuk66_mediachange
****************************************************************************/
Expand Down Expand Up @@ -143,6 +144,7 @@ static int fmuk66_cdinterrupt(int irq, FAR void *context, FAR void *args)
fmuk66_mediachange((struct fmuk66_sdhc_state_s *) args);
return OK;
}
#endif

/****************************************************************************
* Public Functions
Expand All @@ -164,12 +166,13 @@ int fmuk66_sdhc_initialize(void)

VDD_3V3_SD_CARD_EN(true);

#if defined(GPIO_SD_CARDDETECT)
kinetis_pinconfig(GPIO_SD_CARDDETECT);

/* Attached the card detect interrupt (but don't enable it yet) */

kinetis_pinirqattach(GPIO_SD_CARDDETECT, fmuk66_cdinterrupt, sdhc);

#endif
/* Configure the write protect GPIO -- None */

/* Mount the SDHC-based MMC/SD block driver */
Expand Down Expand Up @@ -210,13 +213,17 @@ int fmuk66_sdhc_initialize(void)

syslog(LOG_ERR, "Successfully bound SDHC to the MMC/SD driver\n");

#if defined(GPIO_SD_CARDDETECT)
/* Handle the initial card state */

fmuk66_mediachange(sdhc);

/* Enable CD interrupts to handle subsequent media changes */

kinetis_pinirqenable(GPIO_SD_CARDDETECT);
#else
sdhc_mediachange(sdhc->sdhc, true);
#endif
return OK;
}

Expand Down

0 comments on commit 1b313c6

Please sign in to comment.