Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FreeRTOS weirdness on Funhouse #9545

Merged
merged 2 commits into from
Aug 21, 2024
Merged
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
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