Skip to content

Commit

Permalink
Merge pull request #9545 from tannewt/fix_funhouse_wifi
Browse files Browse the repository at this point in the history
Fix FreeRTOS weirdness on Funhouse
  • Loading branch information
dhalbert authored Aug 21, 2024
2 parents 4d88d73 + 28f3d91 commit f4ca293
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ports/espressif/common-hal/busio/SPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {

// Wait for any other users of this to finish.
while (!common_hal_busio_spi_try_lock(self)) {
RUN_BACKGROUND_TASKS;
}

// Mark us as deinit early in case we are used in an interrupt.
Expand All @@ -139,7 +140,10 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
spi_bus_remove_device(spi_handle[self->host_id]);
spi_bus_free(self->host_id);

// Release the mutex before we delete it. Otherwise FreeRTOS gets unhappy.
xSemaphoreGive(self->mutex);
vSemaphoreDelete(self->mutex);
self->mutex = NULL;

common_hal_reset_pin(self->MOSI);
common_hal_reset_pin(self->MISO);
Expand All @@ -166,7 +170,7 @@ bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) {
}

bool common_hal_busio_spi_has_lock(busio_spi_obj_t *self) {
return xSemaphoreGetMutexHolder(self->mutex) == xTaskGetCurrentTaskHandle();
return self->mutex != NULL && xSemaphoreGetMutexHolder(self->mutex) == xTaskGetCurrentTaskHandle();
}

void common_hal_busio_spi_unlock(busio_spi_obj_t *self) {
Expand Down
2 changes: 2 additions & 0 deletions supervisor/shared/status_leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ void status_led_deinit() {

#elif defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
#if CIRCUITPY_BITBANG_APA102
shared_module_bitbangio_spi_unlock(&status_apa102);
shared_module_bitbangio_spi_deinit(&status_apa102);
#else
common_hal_busio_spi_unlock(&status_apa102);
common_hal_busio_spi_deinit(&status_apa102);
#endif

Expand Down

0 comments on commit f4ca293

Please sign in to comment.