32ESPecial Version 1.00 (#9)
This release reworked the initialization code to provide more robust initialization, especially when no USB stick is present. It incorporates [Version 1.0 of SystemK](Software/SystemK#9). This is the first release for the [32ESPecial Blaster Kits](https://link.clubk.club/2025002). Co-authored-by: Joe Kearney <joe@clubk.club> Reviewed-on: #9
This commit is contained in:
parent
14ec8fe280
commit
e12ee17973
67 changed files with 1232 additions and 649 deletions
|
|
@ -22,6 +22,7 @@
|
|||
// From https://github.com/espressif/esp-idf/blob/master/examples/peripherals/usb/host/msc/main/msc_example_main.c
|
||||
|
||||
#include <SystemK.h>
|
||||
#include <System_Events.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
|
@ -55,6 +56,9 @@ static const char *TAG = "USB";
|
|||
static const char *OTA_FILE = "/usb/esp/OTA_URL.txt";
|
||||
const char *CONFIG_FILE = "/usb/esp/config.txt";
|
||||
|
||||
__NOINIT_ATTR uint_fast8_t Restarts;
|
||||
static bool Device_Connected_This_Power_Cycle = false;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
USB_STATE_UNINITIALIZED,
|
||||
|
|
@ -260,27 +264,25 @@ static void usb_host_task(void *args)
|
|||
if (usb_host_device_free_all() == ESP_OK)
|
||||
{
|
||||
KLOG_INFO(TAG, "USB_HOST_LIB_EVENT_FLAGS_NO_CLIENTS");
|
||||
// break;
|
||||
};
|
||||
}
|
||||
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_ALL_FREE)
|
||||
{
|
||||
KLOG_INFO(TAG, "USB_HOST_LIB_EVENT_FLAGS_ALL_FREE");
|
||||
// break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void app_usb_task(void *args)
|
||||
{
|
||||
SemaphoreHandle_t init_complete = args;
|
||||
|
||||
static USB_State_T Current_State = USB_STATE_UNINITIALIZED;
|
||||
static msc_host_device_handle_t msc_device = NULL;
|
||||
static msc_host_vfs_handle_t vfs_handle = NULL;
|
||||
static uint8_t device_address = 1;
|
||||
usb_message_t msg;
|
||||
|
||||
esp_reset_reason() == ESP_RST_POWERON ? Restarts = 0 : Restarts++;
|
||||
|
||||
while (true)
|
||||
{
|
||||
switch (Current_State)
|
||||
|
|
@ -308,14 +310,32 @@ static void app_usb_task(void *args)
|
|||
{
|
||||
device_address = msg.data.new_dev_address;
|
||||
Current_State = USB_STATE_DEVICE_CONNECTED;
|
||||
Device_Connected_This_Power_Cycle = true;
|
||||
Restarts = 0;
|
||||
KLOG_INFO(TAG, "Device connected.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
KLOG_ERROR(TAG, "No flash drive detected--rebooting.");
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
esp_restart();
|
||||
if (Device_Connected_This_Power_Cycle == false)
|
||||
{
|
||||
if (Restarts <= 3)
|
||||
{
|
||||
KLOG_ERROR(TAG, "No flash drive detected--rebooting.");
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
esp_restart();
|
||||
}
|
||||
else
|
||||
{
|
||||
static bool warning_sent = false;
|
||||
|
||||
if (warning_sent == false)
|
||||
{
|
||||
KLOG_WARN(TAG, "No flash drive detected after multiple attempts.");
|
||||
warning_sent = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -345,7 +365,7 @@ static void app_usb_task(void *args)
|
|||
else
|
||||
{
|
||||
Current_State = USB_STATE_VFS_REGISTERED;
|
||||
xSemaphoreGive(init_complete);
|
||||
xEventGroupSetBits(Get_System_Events(), SYS_USB_FS_PRESENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -360,6 +380,7 @@ static void app_usb_task(void *args)
|
|||
if (msg.id == USB_DEVICE_DISCONNECTED)
|
||||
{
|
||||
Current_State = USB_STATE_PROCESSING_DISCONNECTION;
|
||||
xEventGroupClearBits(Get_System_Events(), SYS_USB_FS_PRESENT);
|
||||
}
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
|
|
@ -389,7 +410,7 @@ static void app_usb_task(void *args)
|
|||
}
|
||||
}
|
||||
|
||||
void Initialize_USB(SemaphoreHandle_t init_complete)
|
||||
void Initialize_USB(void)
|
||||
{
|
||||
KLOG_INFO(TAG, "Initializing USB file system...");
|
||||
|
||||
|
|
@ -404,7 +425,7 @@ void Initialize_USB(SemaphoreHandle_t init_complete)
|
|||
app_usb_task, // Function that implements the task.
|
||||
"USB NVM", // Text name for the task.
|
||||
STACK_SIZE, // Stack size in bytes, not words.
|
||||
(void *)init_complete, // Parameter passed into the task.
|
||||
NULL, // Parameter passed into the task.
|
||||
tskIDLE_PRIORITY + 2, // Priority at which the task is created.
|
||||
xStack, // Array to use as the task's stack.
|
||||
&xTaskBuffer, // Variable to hold the task's data structure.
|
||||
|
|
@ -446,4 +467,4 @@ void Erase_OTA_File(void)
|
|||
{
|
||||
KLOG_ERROR(TAG, "Error erasing the OTA file: %s", strerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue