Can't see SD card via usbd_msc

I am trying to see onboard SD card via usbd_msc and I can not achieve that. I am sure SD card is connected properly and working as I can mount it and write files to it form on-chip code. But if I try to configure MSC device to use SD card as a backed, my Linux system does not mount it. In fact, I think it does not get partition table. I have tired using RAM blockdevice and I could mount it no problem. Can anyone suggest where should I look, how do I debug this?

The card I am using is Kingston 32G card, I have tried splitting 1MB partition and formatting the whole card to FAT32 from nrf52840 code using f_mkfs to no avail, however it's size is detected correctly:

Jan  3 20:03:59 veikia kernel: [ 6313.067048] usb 1-4: new full-speed USB device number 50 using xhci_hcd
Jan  3 20:03:59 veikia kernel: [ 6313.218460] usb 1-4: New USB device found, idVendor=0000, idProduct=0000
Jan  3 20:03:59 veikia kernel: [ 6313.218469] usb 1-4: New USB device strings: Mfr=1, Product=1, SerialNumber=1
Jan  3 20:03:59 veikia kernel: [ 6313.218476] usb 1-4: Product: 000000000000
Jan  3 20:03:59 veikia kernel: [ 6313.218482] usb 1-4: Manufacturer: 000000000000
Jan  3 20:03:59 veikia kernel: [ 6313.218488] usb 1-4: SerialNumber: 000000000000
Jan  3 20:03:59 veikia kernel: [ 6313.224824] usb-storage 1-4:1.0: USB Mass Storage device detected
Jan  3 20:03:59 veikia kernel: [ 6313.225148] scsi host2: usb-storage 1-4:1.0
Jan  3 20:03:59 veikia mtp-probe: checking bus 1, device 50: "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-4"
Jan  3 20:03:59 veikia mtp-probe: bus: 1, device: 50 was not an MTP device
Jan  3 20:04:00 veikia kernel: [ 6314.252097] scsi 2:0:0:0: Direct-Access     Zive     SDC              1.00 PQ: 0 ANSI: 6
Jan  3 20:04:00 veikia kernel: [ 6314.253129] sd 2:0:0:0: Attached scsi generic sg1 type 0
Jan  3 20:04:00 veikia kernel: [ 6314.253466] sd 2:0:0:0: [sdb] 60751872 512-byte logical blocks: (31.1 GB/29.0 GiB)
Jan  3 20:04:00 veikia kernel: [ 6314.331242] sd 2:0:0:0: [sdb] Write Protect is off
Jan  3 20:04:00 veikia kernel: [ 6314.331244] sd 2:0:0:0: [sdb] Mode Sense: 00 00 00 00
Jan  3 20:04:00 veikia kernel: [ 6314.411549] sd 2:0:0:0: [sdb] Asking for cache data failed
Jan  3 20:04:00 veikia kernel: [ 6314.411567] sd 2:0:0:0: [sdb] Assuming drive cache: write through

However, mounting process seems to stop here. I can not see SD card being accessed - no clock, no CS signal.

USB state machine in nrf82540 goes like this:

<info> app: USB CONNECTED
<info> app: Initializing disk 0 (RAM)...
<info> app: Mounting volume...
<info> app: USB power detected
<info> app: USB ready
<info> app: APP_USBD_EVT_STATE_CHANGED
<info> app: USB evt start
<info> app: USB suspend
<info> app: USB resume
<info> app: APP_USBD_EVT_STATE_CHANGED
<info> app: APP_USBD_EVT_STATE_CHANGED
<info> app: APP_USBD_EVT_STATE_CHANGED
<info> app: APP_USBD_EVT_STATE_CHANGED
<info> app: APP_USBD_EVT_STATE_CHANGED
<info> app: APP_USBD_EVT_STATE_CHANGED

However, when I disconnect the device from USB, Linux burps this:



Jan  3 20:18:37 veikia kernel: [ 7191.639773] usb 1-4: reset full-speed USB device number 51 using xhci_hcd


Jan  3 20:19:02 veikia kernel: [ 7216.463163] usb 1-4: USB disconnect, device number 51
Jan  3 20:19:02 veikia kernel: [ 7216.478990] sd 2:0:0:0: [sdb] tag#0 FAILED Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK
Jan  3 20:19:02 veikia kernel: [ 7216.479007] sd 2:0:0:0: [sdb] tag#0 CDB: Read(10) 28 00 00 00 00 00 00 00 08 00
Jan  3 20:19:02 veikia kernel: [ 7216.479016] print_req_error: I/O error, dev sdb, sector 0
Jan  3 20:19:02 veikia kernel: [ 7216.479036] Buffer I/O error on dev sdb, logical block 0, async page read
Jan  3 20:19:02 veikia kernel: [ 7216.479153] ldm_validate_partition_table(): Disk read failed.
Jan  3 20:19:02 veikia kernel: [ 7216.479223] Dev sdb: unable to read RDB block 0
Jan  3 20:19:02 veikia kernel: [ 7216.479328]  sdb: unable to read partition table
Jan  3 20:19:02 veikia kernel: [ 7216.480022] sd 2:0:0:0: [sdb] Read Capacity(10) failed: Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK
Jan  3 20:19:02 veikia kernel: [ 7216.480032] sd 2:0:0:0: [sdb] Sense not available.
Jan  3 20:19:02 veikia kernel: [ 7216.480051] sd 2:0:0:0: [sdb] 0 512-byte logical blocks: (0 B/0 B)
Jan  3 20:19:02 veikia kernel: [ 7216.480130] sd 2:0:0:0: [sdb] Attached SCSI removable disk
Jan  3 20:19:02 veikia systemd-udevd[11794]: inotify_add_watch(9, /dev/sdb, 10) failed: No such file or directory

If I don't configure, initialize and mount FAT in nrf52840 code, USB device initialization goes normally on Linux side, just disk contains "no media" - it seems scsi layer works fine.

My code is based on the usbd_msc example:

NRF_BLOCK_DEV_SDC_DEFINE(
        m_block_dev_sdc2,
        NRF_BLOCK_DEV_SDC_CONFIG(
                SDC_SECTOR_SIZE,
                APP_SDCARD_CONFIG(SDC_MOSI_PIN, SDC_MISO_PIN, SDC_SCK_PIN, SDC_CS_PIN)
         ),
         NFR_BLOCK_DEV_INFO_CONFIG("Zive", "SDC", "1.00")
);


diskio_blkdev_t drives2[] = {
        DISKIO_BLOCKDEV_CONFIG(NRF_BLOCKDEV_BASE_ADDR(m_block_dev_sdc2, block_dev), NULL)
};

#define BLOCKDEV_LIST() (                                   \
        NRF_BLOCKDEV_BASE_ADDR(m_block_dev_sdc2, block_dev)  \
)
//        NRF_BLOCKDEV_BASE_ADDR(m_block_dev_sdc2, block_dev)

#define ENDPOINT_LIST() APP_USBD_MSC_ENDPOINT_LIST(1, 1)

#define MSC_WORKBUFFER_SIZE (1024)

APP_USBD_MSC_GLOBAL_DEF(m_app_msc,
                        0,
                        msc_user_ev_handler,
                        ENDPOINT_LIST(),
                        BLOCKDEV_LIST(),
                        MSC_WORKBUFFER_SIZE);

void usb_device() {
    static const app_usbd_config_t usbd_config = {
            .ev_state_proc = usbd_user_ev_handler
        };

    nrfx_clock_init(clk_handler);

    fatfs_init();
    fatfs_mkfs();

    APP_ERROR_CHECK(app_usbd_init(&usbd_config));

    app_usbd_class_inst_t const * class_inst_msc = app_usbd_msc_class_inst_get(&m_app_msc);

    APP_ERROR_CHECK(app_usbd_class_append(class_inst_msc));

    APP_ERROR_CHECK(app_usbd_power_events_enable());

//    app_usbd_enable();
//    app_usbd_start();

    while (true) {
        while (app_usbd_event_queue_process()) {
            /* Nothing to do */
        }

        if(!is_usb_power_connected()) {
            NRF_LOG_INFO("USB power disconnected, resetting NOW!");
            delay(1);
            soft_reset();
        }
        nrf_pwr_mgmt_run();
    }
}

Please help!