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/>.
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)
32 void config_streamer_impl_unlock(void)
35 flash_flag_clear(FLASH_ODF_FLAG
|FLASH_PRGMERR_FLAG
|FLASH_EPPERR_FLAG
);
38 void config_streamer_impl_lock(void)
43 int config_streamer_impl_write_word(config_streamer_t
*c
, config_streamer_buffer_align_type_t
*buffer
)
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
) {
56 const flash_status_type status
= flash_word_program(c
->address
, *buffer
);
57 if (status
!= FLASH_OPERATE_DONE
) {
61 c
->address
+= CONFIG_STREAMER_BUFFER_SIZE
;