Use cyw43_delay_ms() in cyw43_spi_reset() instead of sleep_ms()#2431
Merged
kilograham merged 1 commit intoraspberrypi:developfrom May 8, 2025
Merged
Use cyw43_delay_ms() in cyw43_spi_reset() instead of sleep_ms()#2431kilograham merged 1 commit intoraspberrypi:developfrom
kilograham merged 1 commit intoraspberrypi:developfrom
Conversation
Since cyw43_spi_reset() may be executed from an async context, we should use cyw43_delay_ms() instead of sleep_ms(). This is particularly a problem when using the async_context_threadsafe_background backend, because sleep_ms() will assert in an ISR.
Contributor
Author
|
For additional context, this is the code that I'm running that crashes without this patch: #include "pico/cyw43_arch.h"
void StartBlinkingLed() {
static bool state = false;
static async_at_time_worker_t worker = {
.next = nullptr,
.do_work =
[](async_context_t* context, async_at_time_worker_t* worker) {
bool& state = *static_cast<bool*>(worker->user_data);
state = !state;
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, state);
async_context_add_at_time_worker_in_ms(context, worker, 1000);
},
.next_time = 0,
.user_data = &state,
};
cyw43_arch_init();
async_context_add_at_time_worker_in_ms(
cyw43_arch_async_context(), &worker, 50);
} |
peterharperuk
approved these changes
May 8, 2025
Contributor
peterharperuk
left a comment
There was a problem hiding this comment.
I think this should be ok. Ran some tests and everything worked.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since
cyw43_spi_reset()may be executed from an async context, we should usecyw43_delay_ms()instead ofsleep_ms(). This is particularly a problem when using theasync_context_threadsafe_backgroundbackend, becausesleep_ms()will assert in an ISR.