Sony's Developer World forum

    • Home
    • Forum guidelines

    Upcoming maintenance 

     

    Dear Customers and Partners.

    This website will be undergoing scheduled maintenance on June 14, 2023. Please be aware there may be disruption to the developer portal website and associated services during the scheduled maintenance period.

    This upgrade is essential to ensure the continued performance, reliability, and security of Developer World.

    We apologize for any inconvenience.

     

     

    Camera app cannot detect SD card

    Spresense
    2
    8
    5185
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    This topic has been deleted. Only users with topic management privileges can see it.
    • vivekbhadra
      vivekbhadra last edited by vivekbhadra

      Good morning everyone. Need a bit of help.
      I am trying to bring up my SPRESENSE with the SPRESENSE IDE. I have been able to compile and flash the camera example on to the SPRESENSE at my desk. I can run the camera app from within the IDE. However, I can see the app fails to detect there is a SDK card attached to the extension board and falls back to the SPI flash for saving the video. I have added some extra logging to bring out bit more logging from the app and here is what it looks like when I run the app:

      Configure the camra app
      ~/spresense/sdk$ tools/config.py examples/camera

      Compile the Kernel
      From the IDE:
      SPRESENSE : Kernel Clean
      SPRESENSE : Kernel Build
      make[2]: Leaving directory '/home/vbhadra/spresense/nuttx/libnx'
      make[1]: Leaving directory '/home/vbhadra/spresense/nuttx'

      Added extra debug log in the camera main
      --- a/examples/camera/camera_main.c
      +++ b/examples/camera/camera_main.c
      @@ -491,10 +491,12 @@ int camera_main(int argc, char *argv[])
      ret = stat("/mnt/sd0", &stat_buf);
      if (ret < 0)
      {

      •  printf("%s: Failed to get SD card handle: %d, setting save directory to spi flashcard\n", __FUNCTION__, errno);
         save_dir = "/mnt/spif";
        
        }
        else
        {
      •  printf("%s: Setting save directory to SD card: %d\n", __FUNCTION__);
         save_dir = "/mnt/sd0";
        
        }

      Build and Flash the application
      SPRESENSE : Application Clean
      SPRESENSE : Build and Flash
      Install sdk/nuttx.spk
      |0%-----------------------------50%------------------------------100%|
      ######################################################################

      180112 bytes loaded.
      Package validation is OK.
      Saving package to "nuttx"
      updater# sync
      updater# Restarting the board ...
      reboot

      Run the camera application
      NuttShell (NSH) NuttX-7.22
      nsh> camera
      camera_main: Failed to get SD card handle: 2, setting save directory to spi flashcard
      FILENAME:/mnt/spif/VIDEO001.YUV
      FILENAME:/mnt/spif/VIDEO002.YUV
      FILENAME:/mnt/spif/VIDEO003.YUV
      FILENAME:/mnt/spif/VIDEO004.YUV
      FILENAME:/mnt/spif/VIDEO005.YUV
      FILENAME:/mnt/spif/VIDEO006.YUV
      FILENAME:/mnt/spif/VIDEO007.YUV
      FILENAME:/mnt/spif/VIDEO008.YUV
      FILENAME:/mnt/spif/VIDEO009.YUV
      FILENAME:/mnt/spif/VIDEO010.YUV
      nsh>

      Debugging
      Check the mmc card dev node
      nsh> ls -l /dev/mmcsd0
      brw-rw-rw- 0 /dev/mmcsd0
      Try mounting the sd card
      nsh> mkdir /mnt/sd0
      nsh> mount -t vfat /dev/mmcsd0 /mnt/sd0
      nsh: mount: mount failed: 5

      Enable emmc in the kernel config
      ~/spresense/sdk$ make menuconfig
      General
      CXD56xx Configuration --->
      [*] eMMC
      Save the config and exit.

      SPRESENSE : Kernel Clean and Build
      SPRESENSE : Build and Flash

      Run the camera app again, the same error occurs, i.e. it cannot detect the sd card and hence the captured images going into the spi flash.

      Has anyone faced this issue before? I am trying to understand why the manual mounting of the SD card fails as below:
      nsh> mount -t vfat /dev/mmcsd0/ /mnt/sd0
      nsh: mount: mount failed: 5

      SD card not auto-mounted
      With mount command I cannot see the SD card is mounted at the moment.
      nsh> mount
      /mnt/spif type smartfs
      /proc type procfs

      Is it part of the bsp code/script which auto mounts the sd card?

      Any help or lead would be highly appreciated.

      Thanks and regards,
      Vivek

      vivekbhadra 1 Reply Last reply Reply Quote
      • vivekbhadra
        vivekbhadra @vivekbhadra last edited by

        Hi

        With subsequent debugging I can see the sd card mounting happens at the below file:

        vbhadra@jupiter:~/spresense/sdk$ find . | xargs grep -i "mmcsd0" 2>/dev/null
        ./bsp/board/common/src/cxd56_spisd.c: ret = mount("/dev/mmcsd0", "/mnt/sd0", "vfat", 0, NULL);

        cxd56_spisd.c is not being compiled and a part of the binary I believe as the below kernel config controls the compilation of it:

        ifeq ($(CONFIG_CXD56_SPISD),y)
        CSRCS += cxd56_spisd.c
        endif

        I can see CONFIG_CXD56_SPISD is not enabled at the moment in my kernel .config file:
        vbhadra@jupiter:~/spresense/sdk$ find . -iname "config" | xargs grep -w "CONFIG_CXD56_SPISD" 2>/dev/null
        ./configs/device/sdcard_spi-defconfig:CONFIG_CXD56_SPISD=y
        ./.config:# CONFIG_CXD56_SPISD is not set

        I have now enabled the kernel config CONFIG_CXD56_SPISD from the menuconfig:

        General ---> CXD56xx Configuration ---> [*] SPI SD Card --->
        After the above I can see it is now enabled as below:
        vbhadra@jupiter:~/spresense/sdk$ find . -iname "config" | xargs grep -w "CONFIG_CXD56_SPISD" 2>/dev/null
        ./configs/device/sdcard_spi-defconfig:CONFIG_CXD56_SPISD=y
        ./.config.old:# CONFIG_CXD56_SPISD is not set
        ./.config:CONFIG_CXD56_SPISD=y

        The kernel compiles fine:
        make[2]: Leaving directory '/home/vbhadra/spresense/nuttx/libnx'
        make[1]: Leaving directory '/home/vbhadra/spresense/nuttx'

        Terminal will be reused by tasks, press any key to close it.

        Then I try to do a clean application build and it fails as below:
        SPRESENSE : Application Clean
        SPRESENSE : Build and Flash

        But I can see the problem is still there:
        nsh> camera
        camera_main: Failed to get SD card handle: 2, setting save directory to spi flashcard

        Questions:

        1. When I try to do "dmesg" it appears that the syslog is not enabled, so that is another thing to enable. Is there any kernel config whcih I can quickly turn on for the dmesg to work?
        2. Where can I see the logs coming out of the cxd56_spisd.c file?
        3. cxd56_spisd.c is a bsp file, hence does it gets flashed as the bootloader?
        TE-KarlKomierowski 1 Reply Last reply Reply Quote
        • TE-KarlKomierowski
          TE-KarlKomierowski DeveloperWorld @vivekbhadra last edited by TE-KarlKomierowski

          Hi @vivekbhadra ,

          I did the following:

          tools/config.py -k release
          tools/config.py examples/camera
          make buildkernel
          make 
          

          I flashed it and then ran the camera example and this is the output.

          NuttShell (NSH) NuttX-7.22
          nsh> 
          nsh> help
          help usage:  help [-v] [<cmd>]
          
            [           date        help        mksmartfs   rm          uname       
            ?           dd          hexdump     mh          rmdir       umount      
            basename    df          kill        mount       set         unset       
            break       echo        ls          mv          sh          usleep      
            cat         printf      mb          mw          shutdown    xd          
            cd          exec        mkdir       poweroff    sleep       
            cp          exit        mkfatfs     ps          test        
            cmp         false       mkfifo      pwd         time        
            dirname     free        mkrd        reboot      true        
          
          Builtin Apps:
            camera
          nsh> camera
          FILENAME:/mnt/sd0/VIDEO001.YUV
          FILENAME:/mnt/sd0/VIDEO002.YUV
          FILENAME:/mnt/sd0/VIDEO003.YUV
          FILENAME:/mnt/sd0/VIDEO004.YUV
          FILENAME:/mnt/sd0/VIDEO005.YUV
          FILENAME:/mnt/sd0/VIDEO006.YUV
          FILENAME:/mnt/sd0/VIDEO007.YUV
          FILENAME:/mnt/sd0/VIDEO008.YUV
          FILENAME:/mnt/sd0/VIDEO009.YUV
          FILENAME:/mnt/sd0/VIDEO010.YUV
          

          I think either your SD card is not working or the main board is not correctly mounted to the extension board.
          What filesystem do you have on your SD card and how big is the card? Can you verify that it is working as it should in your PC?

          nsh> mount
            /mnt/sd0 type vfat
            /mnt/spif type smartfs
            /proc type procfs
          
          1 Reply Last reply Reply Quote
          • vivekbhadra
            vivekbhadra last edited by vivekbhadra

            Hi @TE-KarlKomierowski the SD card fs is of type vfat. I have tested it on the PC and seems detected fine and I can write on the card as well. I doubt there could be a difference in the kernel config (for the sd card). Yesterday

            When I "mount" I see this:

            nsh> mount
            /mnt/spif type smartfs
            /proc type procfs

            The reason seems to me that the bsp packages are not selected with my kernel config.

            vbhadra@jupiter:~/spresense/sdk$ find . | xargs grep -i "mmcsd0" 2>/dev/null
            ./bsp/board/common/src/cxd56_spisd.c: ret = mount("/dev/mmcsd0", "/mnt/sd0", "vfat", 0, NULL);

            cxd56_spisd.c is not being compiled and a part of the binary I believe as the below kernel config controls the compilation of it:

            ifeq ($(CONFIG_CXD56_SPISD),y)
            CSRCS += cxd56_spisd.c
            endif

            I can see CONFIG_CXD56_SPISD is not enabled at the moment in my kernel .config file:
            vbhadra@jupiter:~/spresense/sdk$ find . -iname "config" | xargs grep -w "CONFIG_CXD56_SPISD" 2>/dev/null
            ./configs/device/sdcard_spi-defconfig:CONFIG_CXD56_SPISD=y
            ./.config:# CONFIG_CXD56_SPISD is not set

            I have now enabled the kernel config CONFIG_CXD56_SPISD from the menuconfig:

            General ---> CXD56xx Configuration ---> [*] SPI SD Card --->
            After the above I can see it is now enabled as below:
            vbhadra@jupiter:~/spresense/sdk$ find . -iname "config" | xargs grep -w "CONFIG_CXD56_SPISD" 2>/dev/null
            ./configs/device/sdcard_spi-defconfig:CONFIG_CXD56_SPISD=y
            ./.config.old:# CONFIG_CXD56_SPISD is not set
            ./.config:CONFIG_CXD56_SPISD=y

            The kernel compiles fine:
            make[2]: Leaving directory '/home/vbhadra/spresense/nuttx/libnx'
            make[1]: Leaving directory '/home/vbhadra/spresense/nuttx'

            Terminal will be reused by tasks, press any key to close it.

            Then I try to do a clean application build and it fails as below:
            SPRESENSE : Application Clean
            SPRESENSE : Build and Flash

            But I can see the problem is still there:
            nsh> camera
            camera_main: Failed to get SD card handle: 2, setting save directory to spi flashcard

            Could you please share your kernel .config file please just to be sure there is no difference in there. Also, I cannot see my dmesg is working either. I think that too because of the kernel configuration? Maybe a good idea to compare my kernel .config with yours.

            Thanks and regards,
            Vivek

            1 Reply Last reply Reply Quote
            • vivekbhadra
              vivekbhadra last edited by vivekbhadra

              Hi @TE-KarlKomierowski couple of questions regarding the extension board:

              1. Power: Does both the SPRESENSE and the extension board has to be separately powered?
              2. Is there any pin/jumper configuration which I need to check?
              3. Which GIT branch are you using for the SPRESENSE SDK? I am using master. Is that the correct one?

              Thanks again,

              Regards,
              Vivek

              TE-KarlKomierowski 1 Reply Last reply Reply Quote
              • TE-KarlKomierowski
                TE-KarlKomierowski DeveloperWorld @vivekbhadra last edited by TE-KarlKomierowski

                Hi @vivekbhadra ,

                1. No, USB connected to the Main board is fine.
                2. No, but if the SD card is fine, and works in a computer, has FAT filesystem and still doesn't work with Spresense, try with a different Spresense if you have a different one.
                3. I am using master too.

                You will get the same config as I if you just:

                tools/config.py -k release
                tools/config.py examples/camera
                

                I don't think that the CONFIG_CXD56_SPISD has to be set since the SD card is not running on a regular SPI bus but the SDIO bus.

                https://github.com/sonydevworld/spresense-hw-design-files/blob/master/CXD5602PWBEXT1/schematics/CXD5602PWBEXT1_schematics.pdf

                Press the main board to the extension board again if you can, maybe the connection is not proper in the B2B connector.

                I can also email you my nuttx.spk file I used when I tested this. You can just flash that one down and see. Then you will have the exact same binary as I did and that has been proven to work.

                1 Reply Last reply Reply Quote
                • vivekbhadra
                  vivekbhadra last edited by

                  Hi @TE-KarlKomierowski thanks a lot for confirming that and sorry for asking some of the obvious question perhaps as being pretty new to this, jus wanted to check if I am missing anything very obvious.

                  As you said, please send me your nuttx.spk binary and I will give it a try just to be sure that it is nothing to do with my build.

                  Thanks again.

                  Regards,
                  Vivek

                  1 Reply Last reply Reply Quote
                  • vivekbhadra
                    vivekbhadra last edited by

                    Hi @TE-KarlKomierowski as you said I pressed the SPRESENSE a bit on the extension board and seems the SD card is now working. So the issue was the SPRESENSE was not connected properly on the extension board.

                    Thanks you very much for the help.

                    Regards,
                    Vivek

                    1 Reply Last reply Reply Quote
                    • First post
                      Last post
                    Developer World
                    Copyright © 2021 Sony Group Corporation. All rights reserved.
                    • Contact us
                    • Legal