From 41ecc09c3fe8882c2d28f7e8f1180c732781e417 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sun, 28 Apr 2013 10:19:08 +0200 Subject: [PATCH] OP-917 Various review fixes: -Fixed casing for PIOS_BL_HELPER_FLASH_ERASE_BOOTLOADER -fixed wrong condition in f1 bl_helper -other cosmetic changes and use of stdbool in f1 pios_bl_helper -remove now unused macros +review OPReview-456 --- flight/pios/inc/pios_bl_helper.h | 2 +- flight/pios/stm32f10x/pios_bl_helper.c | 25 +++++++++---------- flight/pios/stm32f4xx/pios_bl_helper.c | 10 +++----- .../bootloader_updater/inc/pios_config.h | 1 - .../targets/common/bootloader_updater/main.c | 7 ++---- .../common/bootloader_updater/pios_board.c | 4 --- 6 files changed, 19 insertions(+), 30 deletions(-) diff --git a/flight/pios/inc/pios_bl_helper.h b/flight/pios/inc/pios_bl_helper.h index 7b527d95d..3a0c6bdb0 100644 --- a/flight/pios/inc/pios_bl_helper.h +++ b/flight/pios/inc/pios_bl_helper.h @@ -36,7 +36,7 @@ extern uint8_t PIOS_BL_HELPER_FLASH_Ini(); extern uint32_t PIOS_BL_HELPER_CRC_Memory_Calc(); extern void PIOS_BL_HELPER_FLASH_Read_Description(uint8_t * array, uint8_t size); extern uint8_t PIOS_BL_HELPER_FLASH_Start(); -extern uint8_t PIOS_BL_HELPER_FLASH_ERASE_BOOTLOADER(); +extern uint8_t PIOS_BL_HELPER_FLASH_Erase_Bootloader(); extern void PIOS_BL_HELPER_CRC_Ini(); #endif /* PIOS_BL_HELPER_H */ diff --git a/flight/pios/stm32f10x/pios_bl_helper.c b/flight/pios/stm32f10x/pios_bl_helper.c index 7fe351e17..0c2d7b7d9 100644 --- a/flight/pios/stm32f10x/pios_bl_helper.c +++ b/flight/pios/stm32f10x/pios_bl_helper.c @@ -28,13 +28,13 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "pios.h" +#include #ifdef PIOS_INCLUDE_BL_HELPER #include -#include "stm32f10x_flash.h" - +#include +#include uint8_t *PIOS_BL_HELPER_FLASH_If_Read(uint32_t SectorAddress) { @@ -62,7 +62,7 @@ uint8_t PIOS_BL_HELPER_FLASH_Start() return (success) ? 1 : 0; } -uint8_t PIOS_BL_HELPER_FLASH_ERASE_BOOTLOADER() { +uint8_t PIOS_BL_HELPER_FLASH_Erase_Bootloader() { /// Bootloader memory space erase uint32_t startAddress = BL_BANK_BASE; uint32_t endAddress = BL_BANK_BASE + BL_BANK_SIZE; @@ -73,23 +73,22 @@ uint8_t PIOS_BL_HELPER_FLASH_ERASE_BOOTLOADER() { } static bool erase_flash(uint32_t startAddress, uint32_t endAddress) { - uint32_t pageAdress = startAddress; - uint8_t fail = FALSE; - while ((pageAdress < endAddress) - || (fail == TRUE)) { + uint32_t pageAddress = startAddress; + uint8_t fail = false; + while ((pageAddress < endAddress) && (fail == false)) { for (int retry = 0; retry < MAX_DEL_RETRYS; ++retry) { - if (FLASH_ErasePage(pageAdress) == FLASH_COMPLETE) { - fail = FALSE; + if (FLASH_ErasePage(pageAddress) == FLASH_COMPLETE) { + fail = false; break; } else { - fail = TRUE; + fail = true; } } #ifdef STM32F10X_HD - pageAdress += 2048; + pageAddress += 2048; #elif defined (STM32F10X_MD) - pageAdress += 1024; + pageAddress += 1024; #endif } return !fail; diff --git a/flight/pios/stm32f4xx/pios_bl_helper.c b/flight/pios/stm32f4xx/pios_bl_helper.c index 3458120c6..562587819 100644 --- a/flight/pios/stm32f4xx/pios_bl_helper.c +++ b/flight/pios/stm32f4xx/pios_bl_helper.c @@ -28,15 +28,14 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "pios.h" +#include #ifdef PIOS_INCLUDE_BL_HELPER #include -#include "stm32f4xx_flash.h" +#include #include - uint8_t *PIOS_BL_HELPER_FLASH_If_Read(uint32_t SectorAddress) { return (uint8_t *) (SectorAddress); @@ -151,7 +150,7 @@ uint8_t PIOS_BL_HELPER_FLASH_Start() } -uint8_t PIOS_BL_HELPER_FLASH_ERASE_BOOTLOADER() { +uint8_t PIOS_BL_HELPER_FLASH_Erase_Bootloader() { /// Bootloader memory space erase uint32_t startAddress = BL_BANK_BASE; uint32_t endAddress = BL_BANK_BASE + BL_BANK_SIZE; @@ -165,8 +164,7 @@ static bool erase_flash(uint32_t startAddress, uint32_t endAddress) { uint32_t pageAddress = startAddress; bool fail = false; - while ((pageAddress < endAddress) - && (fail == false)) { + while ((pageAddress < endAddress) && (fail == false)) { uint8_t sector_number; uint32_t sector_start; uint32_t sector_size; diff --git a/flight/targets/common/bootloader_updater/inc/pios_config.h b/flight/targets/common/bootloader_updater/inc/pios_config.h index ce6c6fc2b..9fbd71501 100644 --- a/flight/targets/common/bootloader_updater/inc/pios_config.h +++ b/flight/targets/common/bootloader_updater/inc/pios_config.h @@ -34,7 +34,6 @@ #define PIOS_INCLUDE_DELAY #define PIOS_INCLUDE_SYS #define PIOS_INCLUDE_IRQ -//#define PIOS_INCLUDE_GPIO #define PIOS_INCLUDE_LED #define PIOS_INCLUDE_BL_HELPER #define PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT diff --git a/flight/targets/common/bootloader_updater/main.c b/flight/targets/common/bootloader_updater/main.c index 387d3a16c..4a55a7aed 100644 --- a/flight/targets/common/bootloader_updater/main.c +++ b/flight/targets/common/bootloader_updater/main.c @@ -37,9 +37,6 @@ extern void PIOS_Board_Init(void); extern void FLASH_Download(); void error(int, int); -#ifdef STM32F4XX -#define FLASH_ErasePage(x) FLASH_EraseSector((x) > 0x08000000 ? FLASH_Sector_1 : FLASH_Sector_0, VoltageRange_3) -#endif /* The ADDRESSES of the _binary_* symbols are the important * data. This is non-intuitive for _binary_size where you * might expect its value to hold the size but you'd be wrong. @@ -93,7 +90,7 @@ int main() bool fail; - fail = (PIOS_BL_HELPER_FLASH_ERASE_BOOTLOADER() != 1); + fail = (PIOS_BL_HELPER_FLASH_Erase_Bootloader() != 1); if (fail == true){ error(PIOS_LED_HEARTBEAT, 3); @@ -105,7 +102,7 @@ int main() PIOS_LED_Toggle(PIOS_LED_HEARTBEAT); for (uint8_t retry = 0; retry < MAX_WRI_RETRYS; ++retry) { if (result == false) { - result = (FLASH_ProgramWord(0x08000000 + (offset * 4), embedded_image_start[offset]) == FLASH_COMPLETE); + result = (FLASH_ProgramWord(BL_BANK_BASE + (offset * 4), embedded_image_start[offset]) == FLASH_COMPLETE); } } if (result == false) { diff --git a/flight/targets/common/bootloader_updater/pios_board.c b/flight/targets/common/bootloader_updater/pios_board.c index fe68d66aa..accc300f9 100644 --- a/flight/targets/common/bootloader_updater/pios_board.c +++ b/flight/targets/common/bootloader_updater/pios_board.c @@ -34,10 +34,6 @@ * NOTE: THIS IS THE ONLY PLACE THAT SHOULD EVER INCLUDE THIS FILE */ #include -#ifdef STM32F4XX -#define FLASH_ErasePage(x) FLASH_EraseSector(x,VoltageRange_3) -#endif - void PIOS_Board_Init(void) { const struct pios_board_info * bdinfo = &pios_board_info_blob;