-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
141 changed files
with
14,207 additions
and
402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,60 @@ | ||
#include "eeprom.h" | ||
#include "targets.h" | ||
|
||
#include <string.h> | ||
#include <stdbool.h> | ||
|
||
//#pragma GCC optimize("O0") | ||
|
||
#include "at32f415_flash.h" | ||
|
||
// #define APP_START (uint32_t)0x08001000 | ||
// #define FLASH_STORAGE 0x08005000 // at the 31kb mark | ||
#define page_size 0x400 // 1 kb for f051 | ||
// uint32_t FLASH_FKEY1 =0x45670123; | ||
// uint32_t FLASH_FKEY2 =0xCDEF89AB; | ||
/* | ||
the F415 can be either 1k or 2k sector size. The 256k flash part has | ||
2k sector size. We only support ESCs with 128k flash or less, so 1k | ||
sector size, but it is useful to work with 2k sector size when using | ||
a F415 dev board like the AT-Start F415, so we detect here. | ||
*/ | ||
static inline uint32_t sector_size() | ||
{ | ||
const uint16_t *F_SIZE = (const uint16_t *)0x1FFFF7E0; | ||
if (*F_SIZE <= 128) { | ||
// 1k sectors for 128k flash or less | ||
return 1024; | ||
} | ||
// 256k flash is 2k sectors | ||
return 2048; | ||
} | ||
|
||
void save_flash_nolib(uint8_t* data, int length, uint32_t add) | ||
{ /// todo | ||
|
||
// fmc_wscnt_set(2); | ||
|
||
// fmc_prefetch_enable(); | ||
|
||
uint32_t data_to_FLASH[length / 4]; | ||
memset(data_to_FLASH, 0, length / 4); | ||
for (int i = 0; i < length / 4; i++) { | ||
data_to_FLASH[i] = data[i * 4 + 3] << 24 | data[i * 4 + 2] << 16 | data[i * 4 + 1] << 8 | data[i * 4]; // make 16 bit | ||
{ | ||
if ((add & 0x3) != 0 || (length & 0x3) != 0) { | ||
return; | ||
} | ||
volatile uint32_t data_length = length / 4; | ||
/* | ||
we need the data to be 32 bit aligned | ||
*/ | ||
const uint32_t word_length = length / 4; | ||
|
||
// unlock flash | ||
|
||
flash_unlock(); | ||
|
||
// erase page if address even divisable by 1024 | ||
if ((add % 1024) == 0) { | ||
flash_sector_erase(add); | ||
// erase page if address even divisable by sector size | ||
if ((add % sector_size()) == 0) { | ||
flash_sector_erase(add); | ||
} | ||
|
||
volatile uint32_t index = 0; | ||
while (index < data_length) { | ||
// fmc_word_program(add + (index*4),data_to_FLASH[index]); | ||
flash_word_program(add + (index * 4), data_to_FLASH[index]); | ||
// fmc_flag_clear(FMC_FLAG_END | | ||
// FMC_FLAG_WPERR | | ||
// FMC_FLAG_PGERR); | ||
flash_flag_clear(FLASH_PROGRAM_ERROR | FLASH_EPP_ERROR | FLASH_OPERATE_DONE); | ||
uint32_t index = 0; | ||
while (index < word_length) { | ||
uint32_t word; | ||
memcpy(&word, &data[index*4], sizeof(word)); | ||
flash_word_program(add + (index * 4), word); | ||
flash_flag_clear(FLASH_PROGRAM_ERROR | FLASH_EPP_ERROR | FLASH_OPERATE_DONE); | ||
index++; | ||
} | ||
flash_lock(); | ||
} | ||
|
||
void read_flash_bin(uint8_t* data, uint32_t add, int out_buff_len) | ||
{ | ||
// volatile uint32_t read_data; | ||
for (int i = 0; i < out_buff_len; i++) { | ||
data[i] = *(uint8_t*)(add + i); | ||
} | ||
} | ||
memcpy(data, (void*)add, out_buff_len); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.