mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-14 20:10:18 +03:00
Initial (untested) implementation of config in flash 16kb (#14107)
This commit is contained in:
parent
73a06e9279
commit
bb5a38d116
4 changed files with 92 additions and 7 deletions
68
src/platform/PICO/config_flash.c
Normal file
68
src/platform/PICO/config_flash.c
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue