pico-sdk
pico-sdk copied to clipboard
multicore_lockout_start_blocking assertion failure v1.4.0 and v1.4.1
Similar with an old closed issue: #687
EDIT: Workaround found (check the bottom)
assertion "us_since_boot <= INT64_MAX" failed: file
Version of SKD:
- I tried Master with SDK 1.4.0
- And Develop with 1.4.1
The repo where I have the code is here, is a pretty complex one
- core 0 is handling wifi and tcp socket server
- core 1 is handling some service specific data, in the case where I tried the functions is for an adjustable desk
Repo: https://github.com/RaresAil/pico-w-template/tree/feat/flash-saving-data
Called from the main thread of core 1:
void save_flash_data() {
uint8_t* bytes = (uint8_t*) &flash_data;
int data_size = sizeof(flash_data);
printf("[Flash] Programming flash (Size: %d)\n", data_size);
printf("[Flash] Requesting core 0 to pause\n");
multicore_lockout_start_blocking(); // ERROR HERE
printf("[Flash] Locking core 1\n");
uint32_t interrupts = save_and_disable_interrupts();
flash_range_erase(FLASH_TARGET_OFFSET, FLASH_SECTOR_SIZE);
flash_range_program(FLASH_TARGET_OFFSET, bytes, FLASH_PAGE_SIZE);
restore_interrupts(interrupts);
printf("[Flash] Unlocking core 1\n");
multicore_lockout_end_blocking();
printf("[Flash] Releasing core 0\n");
printf("[Flash] Done.\n");
}
At the beginning of core 0 in main
multicore_launch_core1(core1_entry);
multicore_lockout_victim_init();
Workaround
Instead of using multicore_lockout_end_blocking and multicore_lockout_start_blocking i managed to get it working by using the timeout version of them:
// 10 years in microseconds
#define MULTICORE_LOCKOUT_TIMEOUT (uint64_t)10 * 365 * 24 * 60 * 60 * 1000 * 1000
const bool locked = multicore_lockout_start_timeout_us(MULTICORE_LOCKOUT_TIMEOUT);
if (locked) {
uint32_t interrupts = save_and_disable_interrupts();
flash_range_erase(FLASH_TARGET_OFFSET, FLASH_SECTOR_SIZE);
flash_range_program(FLASH_TARGET_OFFSET, bytes, FLASH_PAGE_SIZE)
restore_interrupts(interrupts);
bool unlocked = false;
do {
unlocked = multicore_lockout_end_timeout_us(MULTICORE_LOCKOUT_TIMEOUT);
} while(!unlocked);
}