[feat] led blink 5hz when error in bootoader
This commit is contained in:
parent
9265d36a19
commit
b73a16f22f
@ -31,14 +31,12 @@ void file_to_flash(void)
|
|||||||
void system_init(void)
|
void system_init(void)
|
||||||
{
|
{
|
||||||
led_init(LED1 | LED2);
|
led_init(LED1 | LED2);
|
||||||
led_on(LED1 | LED2);
|
|
||||||
led_delay_ms(500);
|
|
||||||
led_off(LED1 | LED2);
|
led_off(LED1 | LED2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_blink(void)
|
void led_blink(void)
|
||||||
{
|
{
|
||||||
for (uint32_t i=0; i<2; i++) {
|
for (uint32_t i=0; i<1; i++) {
|
||||||
led_delay_ms(250);
|
led_delay_ms(250);
|
||||||
led_on(LED1 | LED2);
|
led_on(LED1 | LED2);
|
||||||
led_delay_ms(250);
|
led_delay_ms(250);
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#include "led.h"
|
||||||
#include "partition.h"
|
#include "partition.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "bitmap.h"
|
#include "bitmap.h"
|
||||||
@ -15,7 +16,7 @@ void file_write_flash_0(uint32_t flash, uint32_t len)
|
|||||||
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
|
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
|
||||||
for (i = 0; i < len / 4; i++) {
|
for (i = 0; i < len / 4; i++) {
|
||||||
if (FLASH_ProgramWord(flash + i * 4, 0) != FLASH_COMPLETE) {
|
if (FLASH_ProgramWord(flash + i * 4, 0) != FLASH_COMPLETE) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FLASH_Lock();
|
FLASH_Lock();
|
||||||
@ -23,7 +24,7 @@ void file_write_flash_0(uint32_t flash, uint32_t len)
|
|||||||
p_flash = (volatile uint32_t *)flash;
|
p_flash = (volatile uint32_t *)flash;
|
||||||
for (i = 0; i < len / 4; i++) {
|
for (i = 0; i < len / 4; i++) {
|
||||||
if (p_flash[i] != 0) {
|
if (p_flash[i] != 0) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,14 +40,14 @@ void file_bitmap_update(uint32_t mask)
|
|||||||
/* first open file */
|
/* first open file */
|
||||||
ret = f_open(&f, file_name[FILE_IDX_MAIN], FA_READ);
|
ret = f_open(&f, file_name[FILE_IDX_MAIN], FA_READ);
|
||||||
if (ret != FR_OK) {
|
if (ret != FR_OK) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
/* second program data to flash */
|
/* second program data to flash */
|
||||||
idx = 0;
|
idx = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
ret = f_read(&f, file_buffer, FILE_BUFF_SIZE, &bc);
|
ret = f_read(&f, file_buffer, FILE_BUFF_SIZE, &bc);
|
||||||
if (ret != FR_OK) {
|
if (ret != FR_OK) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
file_write_flash(ADDR_MAIN + idx * FILE_BUFF_SIZE, file_buffer, (uint32_t)bc);
|
file_write_flash(ADDR_MAIN + idx * FILE_BUFF_SIZE, file_buffer, (uint32_t)bc);
|
||||||
if ((uint32_t)bc != FILE_BUFF_SIZE) {
|
if ((uint32_t)bc != FILE_BUFF_SIZE) {
|
||||||
@ -60,14 +61,14 @@ void file_bitmap_update(uint32_t mask)
|
|||||||
/* first open file */
|
/* first open file */
|
||||||
ret = f_open(&f, file_name[FILE_IDX_GAS1], FA_READ);
|
ret = f_open(&f, file_name[FILE_IDX_GAS1], FA_READ);
|
||||||
if (ret != FR_OK) {
|
if (ret != FR_OK) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
/* second program data to flash */
|
/* second program data to flash */
|
||||||
idx = 0;
|
idx = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
ret = f_read(&f, file_buffer, FILE_BUFF_SIZE, &bc);
|
ret = f_read(&f, file_buffer, FILE_BUFF_SIZE, &bc);
|
||||||
if (ret != FR_OK) {
|
if (ret != FR_OK) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
file_write_flash(ADDR_GAS1 + idx * FILE_BUFF_SIZE, file_buffer, (uint32_t)bc);
|
file_write_flash(ADDR_GAS1 + idx * FILE_BUFF_SIZE, file_buffer, (uint32_t)bc);
|
||||||
if ((uint32_t)bc != FILE_BUFF_SIZE) {
|
if ((uint32_t)bc != FILE_BUFF_SIZE) {
|
||||||
@ -84,14 +85,14 @@ void file_bitmap_update(uint32_t mask)
|
|||||||
/* first open file */
|
/* first open file */
|
||||||
ret = f_open(&f, file_name[FILE_IDX_GAS2], FA_READ);
|
ret = f_open(&f, file_name[FILE_IDX_GAS2], FA_READ);
|
||||||
if (ret != FR_OK) {
|
if (ret != FR_OK) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
/* second program data to flash */
|
/* second program data to flash */
|
||||||
idx = 0;
|
idx = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
ret = f_read(&f, file_buffer, FILE_BUFF_SIZE, &bc);
|
ret = f_read(&f, file_buffer, FILE_BUFF_SIZE, &bc);
|
||||||
if (ret != FR_OK) {
|
if (ret != FR_OK) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
file_write_flash(ADDR_GAS2 + idx * FILE_BUFF_SIZE, file_buffer, (uint32_t)bc);
|
file_write_flash(ADDR_GAS2 + idx * FILE_BUFF_SIZE, file_buffer, (uint32_t)bc);
|
||||||
if ((uint32_t)bc != FILE_BUFF_SIZE) {
|
if ((uint32_t)bc != FILE_BUFF_SIZE) {
|
||||||
@ -108,14 +109,14 @@ void file_bitmap_update(uint32_t mask)
|
|||||||
/* first open file */
|
/* first open file */
|
||||||
ret = f_open(&f, file_name[FILE_IDX_GAS3], FA_READ);
|
ret = f_open(&f, file_name[FILE_IDX_GAS3], FA_READ);
|
||||||
if (ret != FR_OK) {
|
if (ret != FR_OK) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
/* second program data to flash */
|
/* second program data to flash */
|
||||||
idx = 0;
|
idx = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
ret = f_read(&f, file_buffer, FILE_BUFF_SIZE, &bc);
|
ret = f_read(&f, file_buffer, FILE_BUFF_SIZE, &bc);
|
||||||
if (ret != FR_OK) {
|
if (ret != FR_OK) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
file_write_flash(ADDR_GAS3 + idx * FILE_BUFF_SIZE, file_buffer, (uint32_t)bc);
|
file_write_flash(ADDR_GAS3 + idx * FILE_BUFF_SIZE, file_buffer, (uint32_t)bc);
|
||||||
if ((uint32_t)bc != FILE_BUFF_SIZE) {
|
if ((uint32_t)bc != FILE_BUFF_SIZE) {
|
||||||
@ -132,14 +133,14 @@ void file_bitmap_update(uint32_t mask)
|
|||||||
/* first open file */
|
/* first open file */
|
||||||
ret = f_open(&f, file_name[FILE_IDX_GAS4], FA_READ);
|
ret = f_open(&f, file_name[FILE_IDX_GAS4], FA_READ);
|
||||||
if (ret != FR_OK) {
|
if (ret != FR_OK) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
/* second program data to flash */
|
/* second program data to flash */
|
||||||
idx = 0;
|
idx = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
ret = f_read(&f, file_buffer, FILE_BUFF_SIZE, &bc);
|
ret = f_read(&f, file_buffer, FILE_BUFF_SIZE, &bc);
|
||||||
if (ret != FR_OK) {
|
if (ret != FR_OK) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
file_write_flash(ADDR_GAS4 + idx * FILE_BUFF_SIZE, file_buffer, (uint32_t)bc);
|
file_write_flash(ADDR_GAS4 + idx * FILE_BUFF_SIZE, file_buffer, (uint32_t)bc);
|
||||||
if ((uint32_t)bc != FILE_BUFF_SIZE) {
|
if ((uint32_t)bc != FILE_BUFF_SIZE) {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "stm32f4xx_flash.h"
|
#include "stm32f4xx_flash.h"
|
||||||
#include "partition.h"
|
#include "partition.h"
|
||||||
|
#include "led.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
@ -17,14 +18,14 @@ static void file_config_write(uint32_t addr, struct file_config_s *cfg)
|
|||||||
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
|
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
|
||||||
for (uint32_t i = 0; i < 4; i++) {
|
for (uint32_t i = 0; i < 4; i++) {
|
||||||
if (FLASH_ProgramWord(addr + i * 4, p[i]) != FLASH_COMPLETE) {
|
if (FLASH_ProgramWord(addr + i * 4, p[i]) != FLASH_COMPLETE) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FLASH_Lock();
|
FLASH_Lock();
|
||||||
p = (volatile uint32_t *)addr;
|
p = (volatile uint32_t *)addr;
|
||||||
if (p[0] != addr || (p[0] + p[1] + p[2]) != p[3]) {
|
if (p[0] != addr || (p[0] + p[1] + p[2]) != p[3]) {
|
||||||
/* program flash error */
|
/* program flash error */
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "sdio_sd.h"
|
#include "sdio_sd.h"
|
||||||
#include "partition.h"
|
#include "partition.h"
|
||||||
|
#include "led.h"
|
||||||
|
|
||||||
#define RETRY_MAX (5)
|
#define RETRY_MAX (5)
|
||||||
|
|
||||||
@ -189,14 +190,14 @@ void file_secctor_erase(uint16_t sector)
|
|||||||
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | \
|
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | \
|
||||||
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
|
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
|
||||||
if (FLASH_EraseSector(sector, VoltageRange_3) != FLASH_COMPLETE) {
|
if (FLASH_EraseSector(sector, VoltageRange_3) != FLASH_COMPLETE) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
FLASH_Lock();
|
FLASH_Lock();
|
||||||
for (uint32_t i = 0; i < size; i += 4) {
|
for (uint32_t i = 0; i < size; i += 4) {
|
||||||
if (*(volatile uint32_t *)(addr + i) == 0xFFFFFFFF) {
|
if (*(volatile uint32_t *)(addr + i) == 0xFFFFFFFF) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,7 +216,7 @@ void file_write_flash(uint32_t flash, uint8_t *buff, uint32_t len)
|
|||||||
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
|
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
|
||||||
for (i = 0; i < len / 4; i++) {
|
for (i = 0; i < len / 4; i++) {
|
||||||
if (FLASH_ProgramWord(flash + i * 4, p_buff[i]) != FLASH_COMPLETE) {
|
if (FLASH_ProgramWord(flash + i * 4, p_buff[i]) != FLASH_COMPLETE) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FLASH_Lock();
|
FLASH_Lock();
|
||||||
@ -223,7 +224,7 @@ void file_write_flash(uint32_t flash, uint8_t *buff, uint32_t len)
|
|||||||
p_flash = (volatile uint32_t *)flash;
|
p_flash = (volatile uint32_t *)flash;
|
||||||
for (i = 0; i < len / 4; i++) {
|
for (i = 0; i < len / 4; i++) {
|
||||||
if (p_flash[i] != p_buff[i]) {
|
if (p_flash[i] != p_buff[i]) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#include "partition.h"
|
#include "partition.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "firmware.h"
|
#include "firmware.h"
|
||||||
|
#include "led.h"
|
||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
|
|
||||||
void file_firmware_update(void)
|
void file_firmware_update(void)
|
||||||
@ -11,14 +12,14 @@ void file_firmware_update(void)
|
|||||||
|
|
||||||
ret = f_open(&f, file_name[FILE_IDX_FW], FA_READ);
|
ret = f_open(&f, file_name[FILE_IDX_FW], FA_READ);
|
||||||
if (ret != FR_OK) {
|
if (ret != FR_OK) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
idx = 0;
|
idx = 0;
|
||||||
byte_cnt = 0;
|
byte_cnt = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
ret = f_read(&f, file_buffer, FILE_BUFF_SIZE, &bc);
|
ret = f_read(&f, file_buffer, FILE_BUFF_SIZE, &bc);
|
||||||
if (ret != FR_OK) {
|
if (ret != FR_OK) {
|
||||||
while (1);
|
led_indicate_error();
|
||||||
}
|
}
|
||||||
/* check whether sector need to be erase */
|
/* check whether sector need to be erase */
|
||||||
if ((byte_cnt == 0) && (bc != 0)) {
|
if ((byte_cnt == 0) && (bc != 0)) {
|
||||||
|
|||||||
@ -64,6 +64,16 @@ void led_delay_ms(uint16_t ms)
|
|||||||
TIM_Cmd(TIM3, DISABLE);
|
TIM_Cmd(TIM3, DISABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void led_indicate_error(void)
|
||||||
|
{
|
||||||
|
while (1) {
|
||||||
|
led_delay_ms(100);
|
||||||
|
led_on(LED1 | LED2);
|
||||||
|
led_delay_ms(100);
|
||||||
|
led_off(LED1 | LED2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void led_deinit(void)
|
void led_deinit(void)
|
||||||
{
|
{
|
||||||
TIM_DeInit(TIM3);
|
TIM_DeInit(TIM3);
|
||||||
|
|||||||
@ -16,6 +16,7 @@ void led_off(uint16_t led);
|
|||||||
void led_on(uint16_t led);
|
void led_on(uint16_t led);
|
||||||
void led_toggle(uint16_t led);
|
void led_toggle(uint16_t led);
|
||||||
void led_delay_ms(uint16_t ms);
|
void led_delay_ms(uint16_t ms);
|
||||||
|
void led_indicate_error(void);
|
||||||
void led_deinit(void);
|
void led_deinit(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user