mirror of
https://github.com/ArteryTek/AT32F415_Firmware_Library.git
synced 2026-05-21 01:12:20 +00:00
update version to v2.1.4
This commit is contained in:
@@ -9,8 +9,7 @@
|
||||
the slib example) describes how to generate an execute-only ip-code (using
|
||||
compiler options), place and protect it (protection using slib) in some preferred
|
||||
sectors in internal flash memory. the fir filter algorithm from cmsis library
|
||||
is chosen as an example of ip-code to be protected. enabling slib is managed
|
||||
by software in slib_enable() function.
|
||||
is chosen as an example of ip-code to be protected.
|
||||
|
||||
the ip-code function fir_lowpass_filter() is called in main.c file. note that
|
||||
symbol definition file have to be generated in project configuration described
|
||||
@@ -22,9 +21,6 @@
|
||||
|
||||
@note the ip-code and ip-data are placed in sector 2 to sector 5 which will
|
||||
be protected.
|
||||
|
||||
activating the slib on these sectors is completed by slib_enable() function
|
||||
descripes in main file.
|
||||
|
||||
@note the application needs to ensure that the systick time base is always
|
||||
set to 1 millisecond to have correct operation.
|
||||
@@ -76,12 +72,8 @@
|
||||
(a) power on the board then load the code, led3 should toggle fast if not
|
||||
press reset button.
|
||||
(b) press the user button key to execute the ip-code called in main.c file.
|
||||
(c) if macro "use_slib_function" is defined and slib is never enabled, go
|
||||
to step(e).
|
||||
(d) if the ip-code is successfully executed, the green led4 should toggle
|
||||
continuously. else the red led2 toggles continuously.
|
||||
(e) the slib_enable() function will set slib configuration once the ip-code
|
||||
is correctly executed. the green led4 will turn on some time and then
|
||||
a system rest is executed to activate slib. the code will run to step(b).
|
||||
|
||||
(c) if the ip-code is successfully executed, the green led4 should toggle
|
||||
continuously. else the red led2 toggles continuously.
|
||||
|
||||
for details, please refer to the application note document AN0065.
|
||||
|
||||
@@ -39,86 +39,11 @@ extern float32_t refOutput[];
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define USE_SLIB_FUNCTION /* define it when user want to activate slib in this project */
|
||||
|
||||
#if defined (USE_SLIB_FUNCTION)
|
||||
#define FLASH_START_ADDR 0x08000000
|
||||
#define TEST_SLIB_PSW 0x55665566
|
||||
#define SLIB_START_ADDR 0x08001000
|
||||
#define SLIB_DATA_ADDR 0x08002000
|
||||
#define SLIB_END_ADDR 0x08002800
|
||||
#define FLASH_SECTOR_SIZE 0x800
|
||||
#define SECTOR_NUM(dwAddr) ((dwAddr & (FLASH_START_ADDR - 1)) / FLASH_SECTOR_SIZE)
|
||||
#define SECTOR_WORD_CNT (FLASH_SECTOR_SIZE >> 2) /* words per sector */
|
||||
#endif
|
||||
#define SNR_THRESHOLD_F32 140.0f
|
||||
#define TEST_LENGTH_SAMPLES 320
|
||||
|
||||
#if defined (USE_SLIB_FUNCTION)
|
||||
uint32_t dw_start_sector, dw_data_start_sector, dw_end_sector;
|
||||
uint32_t temp_buf[512]; /* 2kb buffer */
|
||||
#endif
|
||||
|
||||
static float32_t testOutput[TEST_LENGTH_SAMPLES];
|
||||
|
||||
#if defined (USE_SLIB_FUNCTION)
|
||||
flash_status_type slib_enable(void);
|
||||
#endif
|
||||
void config_flash_interrupt(void);
|
||||
|
||||
/**
|
||||
* @brief config flash error interrupt.
|
||||
* @param none
|
||||
* @retval flash status
|
||||
*/
|
||||
void config_flash_interrupt(void)
|
||||
{
|
||||
flash_unlock();
|
||||
flash_interrupt_enable(FLASH_ERR_INT, TRUE);
|
||||
flash_lock();
|
||||
/* config nvic priority group */
|
||||
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
|
||||
|
||||
nvic_irq_enable(FLASH_IRQn, 0, 0);
|
||||
}
|
||||
|
||||
#if defined (USE_SLIB_FUNCTION)
|
||||
/**
|
||||
* @brief config slib enable and program slib area.
|
||||
* @param none
|
||||
* @retval flash status
|
||||
*/
|
||||
flash_status_type slib_enable(void)
|
||||
{
|
||||
uint32_t *ptr;
|
||||
uint32_t i, j;
|
||||
flash_status_type status = FLASH_OPERATE_DONE;
|
||||
ptr = (uint32_t *)SLIB_START_ADDR;
|
||||
dw_start_sector = SECTOR_NUM(SLIB_START_ADDR); /* slib start sector */
|
||||
dw_data_start_sector = SECTOR_NUM(SLIB_DATA_ADDR); /* slib data sector */
|
||||
dw_end_sector = SECTOR_NUM(SLIB_END_ADDR); /* slib end sector */
|
||||
flash_unlock();
|
||||
status = flash_slib_enable(TEST_SLIB_PSW, dw_start_sector, dw_data_start_sector, dw_end_sector);
|
||||
if(status != FLASH_OPERATE_DONE)
|
||||
return status;
|
||||
for(i = 0; i <= (dw_end_sector - dw_start_sector); i++)
|
||||
{
|
||||
memcpy(temp_buf, ptr, FLASH_SECTOR_SIZE);
|
||||
status = flash_sector_erase(SLIB_START_ADDR + i * FLASH_SECTOR_SIZE);
|
||||
if(status != FLASH_OPERATE_DONE)
|
||||
return status;
|
||||
for(j = 0; j < (FLASH_SECTOR_SIZE >> 2); j++)
|
||||
{
|
||||
status = flash_word_program(SLIB_START_ADDR + i * FLASH_SECTOR_SIZE + (j << 2), temp_buf[j]);
|
||||
if(status != FLASH_OPERATE_DONE)
|
||||
return status;
|
||||
}
|
||||
ptr += SECTOR_WORD_CNT;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief main function.
|
||||
* @param none
|
||||
@@ -136,9 +61,6 @@ int main(void)
|
||||
inputf32 = &testInput_f32_1kHz_15kHz[0];
|
||||
outputf32 = &testOutput[0];
|
||||
|
||||
/* configure flash to generate an interrupt when a write protect error occur */
|
||||
config_flash_interrupt();
|
||||
|
||||
/* wait for key button to be pushed, then turn off led3 */
|
||||
while(at32_button_press() == NO_BUTTON)
|
||||
{
|
||||
@@ -159,28 +81,6 @@ int main(void)
|
||||
else
|
||||
{
|
||||
status = ARM_MATH_SUCCESS;
|
||||
#if defined (USE_SLIB_FUNCTION)
|
||||
/* enable slib protection from sector 2 to sector 5 when fir filter ip-code is tested ok */
|
||||
if(flash_slib_state_get() == RESET)
|
||||
{
|
||||
/* if slib has not been enabled, set slib configuration */
|
||||
if(slib_enable() == FLASH_OPERATE_DONE)
|
||||
{
|
||||
/* if slib configuration is correctly set, tuen on green led4 */
|
||||
at32_led_on(LED4);
|
||||
delay_sec(3);
|
||||
|
||||
/* execute system reset to activate slib protection */
|
||||
nvic_system_reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* turn on red led2 if slib activation failed */
|
||||
at32_led_on(LED2);
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* infinite loop */
|
||||
|
||||
Reference in New Issue
Block a user