Set blackbox file handler to NULL after closing file
[inav.git] / src / main / config / config_streamer_at32f43x.c
blobdce84dbd2752d19689f4112ed75df0e7fa19fddd
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <string.h>
19 #include "platform.h"
20 #include "drivers/system.h"
21 #include "config/config_streamer.h"
23 #if defined(AT32F43x) && !defined(CONFIG_IN_RAM) && !defined(CONFIG_IN_EXTERNAL_FLASH)
26 #if defined(AT32F437ZMT7) || defined(AT32F437VMT7) || defined(AT32F435RMT7)
27 #define FLASH_PAGE_SIZE ((uint32_t)0x1000)
28 #elif defined(AT32F437ZGT7) || defined(AT32F437VGT7) || defined(AT32F435RGT7)
29 #define FLASH_PAGE_SIZE ((uint32_t)0x800)
30 #endif
32 void config_streamer_impl_unlock(void)
34 flash_unlock();
35 flash_flag_clear(FLASH_ODF_FLAG|FLASH_PRGMERR_FLAG|FLASH_EPPERR_FLAG);
38 void config_streamer_impl_lock(void)
40 flash_lock();
43 int config_streamer_impl_write_word(config_streamer_t *c, config_streamer_buffer_align_type_t *buffer)
45 if (c->err != 0) {
46 return c->err;
48 // Erases sectors from the start address
49 if (c->address % FLASH_PAGE_SIZE == 0) {
50 const flash_status_type status =flash_sector_erase(c->address);
51 if (status != FLASH_OPERATE_DONE) {
52 return -1;
56 const flash_status_type status = flash_word_program(c->address, *buffer);
57 if (status != FLASH_OPERATE_DONE) {
58 return -2;
61 c->address += CONFIG_STREAMER_BUFFER_SIZE;
62 return 0;
65 #endif