Anyone got esp_msc_ota example to work

mikemoy
Posts: 622
Joined: Fri Jan 12, 2018 9:10 pm

Anyone got esp_msc_ota example to work

Postby mikemoy » Sat Sep 07, 2024 6:40 pm

ESP v5.3.1

I am trying to get the esp_msc_ota example to work.
https://components.espressif.com/compon ... sp_msc_ota

It detects when I insert the USB stick. But ends up with (msc_host_task):Failed to register VFS

main.c

Code: Select all

/*
 * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdio.h>
#include "esp_err.h"
#include "esp_log.h"
#include "esp_check.h"
#include "esp_msc_host.h"
#include "esp_msc_ota.h"
#include "usb/usb_host.h"

static const char *TAG = "usb_msc_ota";

#define OTA_FILE_NAME "/usb/" CONFIG_MSC_OTA_BIN_NAME

void print_progressbar(float progress, float total)
{
    const int bar_width = 50;
    int filled_width = progress * bar_width / total;

    printf("%s[", LOG_COLOR_I);
    for (int i = 0; i < bar_width; ++i) {
        if (i < filled_width) {
            printf(">");
        } else {
            printf(" ");
        }
    }
    printf(" ]%s%d%%\r", LOG_RESET_COLOR, filled_width * 100 / bar_width);
}

static void msc_ota_event_handler(void *arg, esp_event_base_t event_base,
                                  int32_t event_id, void *event_data)
{
    switch (event_id) {
    case ESP_MSC_OTA_START:
        ESP_LOGI(TAG, "ESP_MSC_OTA_START");
        break;
    case ESP_MSC_OTA_READY_UPDATE:
        ESP_LOGI(TAG, "ESP_MSC_OTA_READY_UPDATE");
        break;
    case ESP_MSC_OTA_WRITE_FLASH:
        float progress = *(float *)event_data;
        print_progressbar(progress, 1.0);
        break;
    case ESP_MSC_OTA_FAILED:
        ESP_LOGI(TAG, "ESP_MSC_OTA_FAILED");
        break;
    case ESP_MSC_OTA_GET_IMG_DESC:
        ESP_LOGI(TAG, "ESP_MSC_OTA_GET_IMG_DESC");
        break;
    case ESP_MSC_OTA_VERIFY_CHIP_ID:
        esp_chip_id_t chip_id = *(esp_chip_id_t *)event_data;
        ESP_LOGI(TAG, "ESP_MSC_OTA_VERIFY_CHIP_ID, chip_id: %08x", chip_id);
        break;
    case ESP_MSC_OTA_UPDATE_BOOT_PARTITION:
        esp_partition_subtype_t subtype = *(esp_partition_subtype_t *)event_data;
        ESP_LOGI(TAG, "ESP_MSC_OTA_UPDATE_BOOT_PARTITION, subtype: %d", subtype);
        break;
    case ESP_MSC_OTA_FINISH:
        ESP_LOGI(TAG, "ESP_MSC_OTA_FINISH");
        break;
    case ESP_MSC_OTA_ABORT:
        ESP_LOGI(TAG, "ESP_MSC_OTA_ABORT");
        break;
    }
}

void app_main(void)
{
    esp_event_loop_create_default();
    ESP_ERROR_CHECK(esp_event_handler_register(ESP_MSC_OTA_EVENT, ESP_EVENT_ANY_ID, &msc_ota_event_handler, NULL));
    esp_msc_host_config_t msc_host_config = {
        .base_path = "/usb",
        .host_driver_config = DEFAULT_MSC_HOST_DRIVER_CONFIG(),
        .vfs_fat_mount_config = DEFAULT_ESP_VFS_FAT_MOUNT_CONFIG(),
        .host_config = DEFAULT_USB_HOST_CONFIG()
    };
    esp_msc_host_handle_t host_handle = NULL;
    esp_msc_host_install(&msc_host_config, &host_handle);

    esp_msc_ota_config_t config = {
        .ota_bin_path = OTA_FILE_NAME,
        .wait_msc_connect = portMAX_DELAY,
    };
#if CONFIG_SIMPLE_MSC_OTA
    esp_err_t ret = esp_msc_ota(&config);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "esp_msc_ota failed, ret: %d", ret);
    }
#else
    esp_msc_ota_handle_t msc_ota_handle = NULL;

    esp_err_t ret = esp_msc_ota_begin(&config, &msc_ota_handle);
    ESP_GOTO_ON_ERROR(ret, fail, TAG, "esp_msc_ota_begin failed, err: %d", ret);

    do {
        ret = esp_msc_ota_perform(msc_ota_handle);
        if (ret != ESP_OK) {
            break;
            ESP_LOGE(TAG, "esp_msc_ota_perform: (%s)\n", esp_err_to_name(ret));
        }
    } while (!esp_msc_ota_is_complete_data_received(msc_ota_handle));

    if (esp_msc_ota_is_complete_data_received(msc_ota_handle)) {
        esp_msc_ota_end(msc_ota_handle);
        ESP_LOGI(TAG, "esp msc ota complete");
    } else {
        esp_msc_ota_abort(msc_ota_handle);
        ESP_LOGE(TAG, "esp msc ota failed");
    }
fail:
#endif
    esp_msc_host_uninstall(host_handle);
}

Terminal Output

Code: Select all

I (27) boot: ESP-IDF v5.3.1 2nd stage bootloader
I (27) boot: compile time Sep  7 2024 12:51:08
I (27) boot: Multicore bootloader
I (30) boot: chip revision: v0.1
I (34) boot.esp32s3: Boot SPI Speed : 80MHz
I (39) boot.esp32s3: SPI Mode       : DIO
I (43) boot.esp32s3: SPI Flash Size : 8MB
I (48) boot: Enabling RNG early entropy source...
I (53) boot: Partition Table:
I (57) boot: ## Label            Usage          Type ST Offset   Length
I (64) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (72) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (79) boot:  2 factory          factory app      00 00 00010000 00100000
I (87) boot: End of partition table
I (91) esp_image: segment 0: paddr=00010020 vaddr=3c040020 size=10a08h ( 68104) map
I (112) esp_image: segment 1: paddr=00020a30 vaddr=3fc93c00 size=02bf4h ( 11252) load
I (114) esp_image: segment 2: paddr=0002362c vaddr=40374000 size=0c9ech ( 51692) load
I (129) esp_image: segment 3: paddr=00030020 vaddr=42000020 size=359ech (219628) map
I (168) esp_image: segment 4: paddr=00065a14 vaddr=403809ec size=03168h ( 12648) load
I (178) boot: Loaded app from partition at offset 0x10000
I (178) boot: Disabling RNG early entropy source...
I (190) cpu_start: Multicore app
I (199) cpu_start: Pro cpu start user code
I (199) cpu_start: cpu freq: 160000000 Hz
I (199) app_init: Application information:
I (202) app_init: Project name:     z
I (206) app_init: App version:      1
I (211) app_init: Compile time:     Sep  7 2024 12:50:57
I (217) app_init: ELF file SHA256:  44bf17c65...
I (222) app_init: ESP-IDF:          v5.3.1
I (227) efuse_init: Min chip rev:     v0.0
I (232) efuse_init: Max chip rev:     v0.99
I (237) efuse_init: Chip rev:         v0.1
I (241) heap_init: Initializing. RAM available for dynamic allocation:
I (249) heap_init: At 3FC97140 len 000525D0 (329 KiB): RAM
I (255) heap_init: At 3FCE9710 len 00005724 (21 KiB): RAM
I (261) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (267) heap_init: At 600FE100 len 00001EE8 (7 KiB): RTCRAM
I (274) spi_flash: detected chip: gd
I (277) spi_flash: flash io: dio
I (281) sleep: Configure to isolate all GPIO pins in sleep state
I (288) sleep: Enable automatic switching of GPIO sleep configuration
I (296) main_task: Started on CPU0
I (326) main_task: Calling app_main()
I (356) esp_msc_host: Waiting for USB stick to be connected
I (356) esp_msc_host: MSC Host Install Done

I (356) usb_msc_ota: ESP_MSC_OTA_START
I (356) esp_msc_ota: Waiting for MSC device to connect...
I (956) esp_msc_host: MSC device connected
I (956) esp_msc_host: connection...
*** Device descriptor ***
bLength 18
bDescriptorType 1
bcdUSB 2.10
bDeviceClass 0x0
bDeviceSubClass 0x0
bDeviceProtocol 0x0
bMaxPacketSize0 64
idVendor 0x90c
idProduct 0x1000
bcdDevice 1.00
iManufacturer 1
iProduct 2
iSerialNumber 3
bNumConfigurations 1
*** Configuration descriptor ***
bLength 9
bDescriptorType 2
wTotalLength 32
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
bMaxPower 300mA
        *** Interface descriptor ***
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 0
        bAlternateSetting 0
        bNumEndpoints 2
        bInterfaceClass 0x8
        bInterfaceSubClass 0x6
        bInterfaceProtocol 0x50
        iInterface 0
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x1    EP 1 OUT
                bmAttributes 0x2        BULK
                wMaxPacketSize 64
                bInterval 0
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x82   EP 2 IN
                bmAttributes 0x2        BULK
                wMaxPacketSize 64
                bInterval 0
Device info:
         Capacity: 122376 MB
         Sector size: 512
         Sector count: 250626565
         PID: 0x1000
         VID: 0x 90C
         iProduct: Type-C
         iManufacturer: Samsung
         iSerialNumber: 0375723050002816
E (1866) esp_msc_host: ./main/esp_msc_host.c:121 (msc_host_task):Failed to register VFS
I (1866) esp_msc_host: Waiting for USB stick to be connected

paranormal-prog
Posts: 1
Joined: Thu Aug 24, 2023 9:19 am

Re: Anyone got esp_msc_ota example to work

Postby paranormal-prog » Mon Sep 09, 2024 1:43 pm

Which module are you using and are everything setup for OTA?
which file system format does your USB use?

With the error here:
[Codebox] err = msc_host_vfs_register(msc_device, msc_host->base_path, &msc_host->mount_config, &vfs_handle);
MSC_OTA_CHECK_GOTO(err == ESP_OK, "Failed to register VFS", host_uninstall);[/Codebox]

And the USB being detected, maybe the error is in the path, mount config, or handle?

mikemoy
Posts: 622
Joined: Fri Jan 12, 2018 9:10 pm

Re: Anyone got esp_msc_ota example to work

Postby mikemoy » Wed Sep 11, 2024 3:22 am

ESP32-S3 devkit.
format is FAT.

mikemoy
Posts: 622
Joined: Fri Jan 12, 2018 9:10 pm

Re: Anyone got esp_msc_ota example to work

Postby mikemoy » Sun Sep 15, 2024 5:44 am

My error, it was actually formatted as exFAT.
Formatting it as FAT fixed it.

Who is online

Users browsing this forum: No registered users and 167 guests