Merge pull request #9545 from tannewt/fix_funhouse_wifi

Fix FreeRTOS weirdness on Funhouse
This commit is contained in:
Dan Halbert 2024-08-21 16:35:45 -04:00 committed by GitHub
commit f4ca2939d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View file

@ -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.
@ -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);
@ -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) {

View file

@ -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