Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions firmware/bootloader/openblt_chibios/openblt_net.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "pch.h"

#include "wifi_socket.h"
#include "wifi_sd_firmware_updater.h"
#include "thread_controller.h"
#include "socket/include/socket.h"

Expand Down Expand Up @@ -40,6 +41,10 @@ void NetDeferredInit() {

didInit = true;

// In the bootloader the SD-card WiFi firmware update never runs, so unblock
// WifiHelperThread (which waits on this semaphore before it calls initWifi()).
signalWifiSdUpdateComplete();

initWifi();

wifiInitFinisher.startThread();
Expand Down
8 changes: 7 additions & 1 deletion firmware/console/binary_log/sd_file_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,13 @@ static void sdTriggerLogger() {
#endif /* EFI_TOOTH_LOGGER */
}

static THD_WORKING_AREA(sdCardLoggerStack, 3 * UTILITY_THREAD_STACK_SIZE); // MMC monitor thread
#if EFI_WIFI
// WiFi needs extra stack, as WiFi firmware update happens from here
static THD_WORKING_AREA(sdCardLoggerStack, 6 * UTILITY_THREAD_STACK_SIZE);
#else // not EFI_WIFI
static THD_WORKING_AREA(sdCardLoggerStack, 4 * UTILITY_THREAD_STACK_SIZE);
#endif

static THD_FUNCTION(sdCardLoggerThread, arg) {
(void)arg;
chRegSetThreadName("MMC Card Logger");
Expand Down
7 changes: 4 additions & 3 deletions firmware/ext/atwinc1500/spi_flash/source/spi_flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ sint8 spi_flash_erase(uint32 u32Offset, uint32 u32Sz)
uint32 t;
t = GetTickCount();
#endif
M2M_PRINT("\r\n>Start erasing...\r\n");
M2M_INFO(">Start erasing...");
for(i = u32Offset; i < (u32Sz +u32Offset); i += (16*FLASH_PAGE_SZ))
{
ret += spi_flash_write_enable();
Expand All @@ -696,14 +696,15 @@ sint8 spi_flash_erase(uint32 u32Offset, uint32 u32Sz)
ret += spi_flash_read_status_reg(&tmp);
do
{
nm_bsp_sleep(10);
if(ret != M2M_SUCCESS) goto ERR;
ret += spi_flash_read_status_reg(&tmp);
}while(tmp & 0x01);

}
M2M_PRINT("Done\r\n");
M2M_INFO("Done!");
#ifdef PROFILING
M2M_PRINT("#Erase time = %f sec\n", (GetTickCount()-t)/1000.0);
M2M_INFO("#Erase time = %f sec\n", (GetTickCount()-t)/1000.0);
#endif
ERR:
return ret;
Expand Down
5 changes: 5 additions & 0 deletions firmware/hw_layer/dma_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct DmaBufferContents {
FATFS fs;
FIL file;
SdLogBufferWriter logBuffer;
std::array<uint8_t, 512> wifiUpdateBuffer;
#endif

#if HAL_USE_USB_MSD
Expand Down Expand Up @@ -92,6 +93,10 @@ SdLogBufferWriter& logBuffer() {
}
#endif // EFI_FILE_LOGGING

std::array<uint8_t, 512>& wifiUpdateBuffer() {
return dmaBufferRegion.contents.wifiUpdateBuffer;
}

} // namespace dma_buffers

#endif // EFI_PROD_CODE
1 change: 1 addition & 0 deletions firmware/hw_layer/dma_buffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ uint8_t* sdCardBlockBuffer();
FATFS* fs();
FIL* logFileFd();
SdLogBufferWriter& logBuffer();
std::array<uint8_t, 512>& wifiUpdateBuffer();
#endif // EFI_FILE_LOGGING

} // namespace dma_buffers
Expand Down
2 changes: 2 additions & 0 deletions firmware/hw_layer/mmc_card.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "buffered_writer.h"

#include <array>

BaseBlockDevice* initializeMmcBlockDevice();
void stopMmcBlockDevice();

Expand Down
43 changes: 39 additions & 4 deletions firmware/hw_layer/mmc_card_mount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

#include "ff.h"
#include "mass_storage_init.h"
#include "usbconsole.h"

#if EFI_WIFI
#include "wifi_sd_firmware_updater.h"
#endif

static bool fs_ready = false;

Expand All @@ -19,6 +24,9 @@ void onUsbConnectedNotifyMmcI() {
#endif /* HAL_USE_USB_MSD */

bool mountSdFilesystem() {
Timer t;
t.reset();

auto cardBlockDevice = initializeMmcBlockDevice();

#if EFI_TUNER_STUDIO
Expand All @@ -28,18 +36,45 @@ bool mountSdFilesystem() {

// if no card, don't try to mount FS
if (!cardBlockDevice) {
#if EFI_WIFI
signalWifiSdUpdateComplete();
#endif
#if HAL_USE_USB_MSD
// No SD card - allow USB to enumerate so serial and INI drive still work
allowUsbEnumeration();
#endif
return false;
}

// Mount filesystem temporarily for WiFi update check
bool mounted = f_mount(dma_buffers::fs(), "/", 1) == FR_OK;

if (mounted) {
#if EFI_WIFI
// Check for WiFi firmware update/dump trigger files on SD card
tryUpdateWifiFirmwareFromSd();
tryDumpWifiFirmwareToSd();
#endif
// Unmount — we'll either hand the card to USB or re-mount for logging
f_mount(nullptr, "/", 0);
} else {
efiPrintf("SD card failed to mount filesystem");
}

#if EFI_WIFI
signalWifiSdUpdateComplete();
#endif

#if HAL_USE_USB_MSD
// Wait for the USB stack to wake up, or a 5 second timeout, whichever occurs first
// Allow USB to enumerate - the host will see the real SD card
allowUsbEnumeration();

// Wait for the USB enumeration, or a 5 second timeout, whichever occurs first
msg_t usbResult = usbConnectedSemaphore.wait(TIME_MS2I(5000));

bool hasUsb = usbResult == MSG_OK;

// If we have a device AND USB is connected, mount the card to USB, otherwise
// mount the null device and try to mount the filesystem ourselves
if (cardBlockDevice && hasUsb) {
if (hasUsb) {
// Mount the real card to USB
attachMsdSdCard(cardBlockDevice);

Expand Down
18 changes: 18 additions & 0 deletions firmware/hw_layer/ports/stm32/serial_over_usb/usbconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

static bool isUsbSerialInitialized = false;

#if HAL_USE_USB_MSD
// When MSD is enabled, defer USB bus connection until the SD card thread
// has finished any WiFi firmware updates and is ready to present media.
static chibios_rt::BinarySemaphore usbEnumerationAllowed(/* taken =*/true);
#endif

/**
* start USB serial using hard-coded communications pins (see comments inside the code)
*/
Expand Down Expand Up @@ -50,11 +56,23 @@ void usb_serial_start() {
chThdSleepMilliseconds(250);
#endif /* EFI_SKIP_USB_DISCONNECT */
usbStart(usbp, &usbcfg);

#if HAL_USE_USB_MSD
// Wait for the SD card thread to signal that it's ready
usbEnumerationAllowed.wait();
#endif

usbConnectBus(usbp);

isUsbSerialInitialized = true;
}

void allowUsbEnumeration() {
#if HAL_USE_USB_MSD
usbEnumerationAllowed.signal();
#endif
}

bool is_usb_serial_ready() {
#if EFI_USB_SERIAL_DIRECT
return isUsbSerialInitialized && EFI_USB_DRIVER->state == USB_ACTIVE;
Expand Down
14 changes: 5 additions & 9 deletions firmware/hw_layer/ports/stm32/serial_over_usb/usbconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@

#pragma once

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void usb_serial_start();
bool is_usb_serial_ready();

void usb_serial_start(void);
bool is_usb_serial_ready(void);

#ifdef __cplusplus
}
#endif /* __cplusplus */
#if HAL_USE_USB_MSD
void allowUsbEnumeration();
#endif
2 changes: 1 addition & 1 deletion firmware/net/net.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ALLCPPSRC += \
$(PROJECT_DIR)/net/wifi_socket.cpp \
# $(PROJECT_DIR)/net/wifi_firmware_updater.cpp \
$(PROJECT_DIR)/net/wifi_sd_firmware_updater.cpp

ALLINC += \
$(PROJECT_DIR)/net \
Loading
Loading