1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-13 11:29:58 +03:00

Initial (untested) implementation of config in flash 16kb (#14107)

This commit is contained in:
Jay Blackman 2025-01-03 22:40:12 +11:00 committed by GitHub
parent 73a06e9279
commit bb5a38d116
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 92 additions and 7 deletions

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#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

View file

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

View file

@ -19,10 +19,14 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "platform.h"
#include <stdint.h>
#include <string.h>
#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)

View file

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