diff --git a/src/platform/PICO/config_flash.c b/src/platform/PICO/config_flash.c new file mode 100644 index 0000000000..dfa6d48b4a --- /dev/null +++ b/src/platform/PICO/config_flash.c @@ -0,0 +1,68 @@ +/* + * This file is part of Betaflight. + * + * Betaflight is free software. You can redistribute this software + * and/or modify this software under the terms of the GNU General + * Public License as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later + * version. + * + * Betaflight is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this software. + * + * If not, see . + */ + +#include + +#include "platform.h" +#include "drivers/system.h" +#include "config/config_streamer.h" + +#include "hardware/flash.h" +#include "hardware/sync.h" + +#if defined(CONFIG_IN_FLASH) + +static uint32_t interrupts; + +void configUnlock(void) +{ + // NOOP +} + +void configLock(void) +{ + // NOOP +} + +void configFlashClearFlags(void) +{ + // NOOP +} + +configStreamerResult_e configWriteWord(uintptr_t address, config_streamer_buffer_type_t value) +{ + if (address == __config_start) { + // Erase the flash sector before writing + flash_range_erase(address, FLASH_PAGE_SIZE); + } + + STATIC_ASSERT(CONFIG_STREAMER_BUFFER_SIZE == sizeof(uint32_t) * 1, "CONFIG_STREAMER_BUFFER_SIZE does not match written size"); + + // TODO: refactor to stream the entire buffer to flash also possibly avoid disabling interrupts. + // Write data to flash + // TODO: synchronise second core... + uint32_t interrupts = save_and_disable_interrupts(); + flash_range_program(address, (uint8_t*)&value, sizeof(uint32_t)); + restore_interrupts(interrupts); + return CONFIG_RESULT_SUCCESS; +} + +#endif // CONFIG_IN_FLASH diff --git a/src/platform/PICO/platform_mcu.h b/src/platform/PICO/platform_mcu.h index 238ed6385f..67d09a7a78 100644 --- a/src/platform/PICO/platform_mcu.h +++ b/src/platform/PICO/platform_mcu.h @@ -92,3 +92,11 @@ typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; #define IOCFG_IN_FLOATING IO_CONFIG(GPIO_IN, 0, 0) #define SERIAL_UART_FIRST_INDEX 0 + +extern uint32_t systemUniqueId[3]; + +// PICOs have an 8 byte unique identifier. +#define U_ID_0 (systemUniqueId[0]) +#define U_ID_1 (systemUniqueId[1]) +#define U_ID_2 (systemUniqueId[2]) + diff --git a/src/platform/PICO/system.c b/src/platform/PICO/system.c index 9b5be53dfe..76cd3c6e29 100644 --- a/src/platform/PICO/system.c +++ b/src/platform/PICO/system.c @@ -19,10 +19,14 @@ * If not, see . */ -#include "platform.h" #include +#include + +#include "platform.h" + #include "hardware/timer.h" #include "hardware/clocks.h" +#include "pico/unique_id.h" int main(int argc, char * argv[]); @@ -85,9 +89,16 @@ void systemReset(void) //TODO: implement } +uint32_t systemUniqueId[3] = { 0 }; + void systemInit(void) { //TODO: implement + + // load the unique id into a local array + pico_unique_board_id_t id; + pico_get_unique_board_id(&id); + memcpy(&systemUniqueId, &id.id, MIN(sizeof(systemUniqueId), PICO_UNIQUE_BOARD_ID_SIZE_BYTES)); } // Return system uptime in milliseconds (rollover in 49 days) diff --git a/src/platform/PICO/target/RP2350B/target.h b/src/platform/PICO/target/RP2350B/target.h index 0730f454e7..1d06711a30 100644 --- a/src/platform/PICO/target/RP2350B/target.h +++ b/src/platform/PICO/target/RP2350B/target.h @@ -116,12 +116,10 @@ #undef USE_FLASH_PY25Q128HA #undef USE_FLASH_W25Q64FV -#define FLASH_PAGE_SIZE 0x1000 -#define CONFIG_IN_RAM - -#define U_ID_0 0 -#define U_ID_1 1 -#define U_ID_2 2 +#define FLASH_PAGE_SIZE 0x4000 +#define CONFIG_IN_FLASH +#define FLASH_CONFIG_STREAMER_BUFFER_SIZE 4 +#define FLASH_CONFIG_BUFFER_ALIGN_TYPE uint32_t /* to be moved to a config file once target if working */ #define LED0_PIN PA6