Skip to content

Commit

Permalink
Add a semaphore to smg_uart_write so debug output doesn't get garbled
Browse files Browse the repository at this point in the history
Get debug output from wifi task
  • Loading branch information
mikee47 committed Nov 20, 2024
1 parent f2450ad commit e9654e4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Sming/Arch/Esp32/Components/driver/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,28 @@ smg_uart_t* get_standard_uart(smg_uart_t* uart)
return is_standard_uart(uart) ? uart : nullptr;
}

class Lock
{
public:
Lock()
{
if(!mutex) {
mutex = xSemaphoreCreateMutex();
}
xSemaphoreTake(mutex, portMAX_DELAY);
}

~Lock()
{
xSemaphoreGive(mutex);
}

private:
static SemaphoreHandle_t mutex;
};

SemaphoreHandle_t Lock::mutex;

#if UART_ID_SERIAL_USB_JTAG

/**
Expand Down Expand Up @@ -544,6 +566,8 @@ size_t smg_uart_write(smg_uart_t* uart, const void* buffer, size_t size)

auto buf = static_cast<const uint8_t*>(buffer);

Lock lock;

while(written < size) {
// If TX buffer not in use or it's empty then write directly to hardware FIFO
if(uart->tx_buffer == nullptr || uart->tx_buffer->isEmpty()) {
Expand Down

0 comments on commit e9654e4

Please sign in to comment.