dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_bl_helper.c
Go to the documentation of this file.
1 
15 /*
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful, but
22  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24  * for more details.
25  *
26  * You should have received a copy of the GNU General Public License along
27  * with this program; if not, see <http://www.gnu.org/licenses/>
28  */
29 
30 /* Project Includes */
31 #include "pios.h"
32 #if defined(PIOS_INCLUDE_BL_HELPER)
33 #include <pios_board_info.h>
34 #include "stm32f10x_flash.h"
35 
36 uint8_t *PIOS_BL_HELPER_FLASH_If_Read(uint32_t SectorAddress)
37 {
38  return (uint8_t *) (SectorAddress);
39 }
40 
41 #if defined(PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT)
43 {
44  FLASH_Unlock();
45  return 1;
46 }
47 
49 {
50  const struct pios_board_info * bdinfo = &pios_board_info_blob;
51  uint32_t pageAdress = bdinfo->fw_base;
52  uint8_t fail = false;
53  while ((pageAdress < (bdinfo->fw_base + bdinfo->fw_size + bdinfo->desc_size))
54  && (fail == false)) {
55  for (int retry = 0; retry < MAX_DEL_RETRYS; ++retry) {
56  if (FLASH_ErasePage(pageAdress) == FLASH_COMPLETE) {
57  fail = false;
58  break;
59  } else {
60  fail = true;
61  }
62  }
63 
64 #ifdef STM32F10X_HD
65  pageAdress += 2048;
66 #elif defined (STM32F10X_MD)
67  pageAdress += 1024;
68 #endif
69  }
70 
71  return (fail == true) ? 0 : 1;
72 }
73 #endif
74 
76 {
77  const struct pios_board_info * bdinfo = &pios_board_info_blob;
78 
80  CRC_ResetDR();
81  CRC_CalcBlockCRC((uint32_t *) bdinfo->fw_base, (bdinfo->fw_size) >> 2);
82  return CRC_GetCRC();
83 }
84 
85 void PIOS_BL_HELPER_FLASH_Read_Description(uint8_t * array, uint8_t size)
86 {
87  const struct pios_board_info * bdinfo = &pios_board_info_blob;
88  uint8_t x = 0;
89  if (size > bdinfo->desc_size) size = bdinfo->desc_size;
90  for (uint32_t i = bdinfo->fw_base + bdinfo->fw_size; i < bdinfo->fw_base + bdinfo->fw_size + size; ++i) {
91  array[x] = *PIOS_BL_HELPER_FLASH_If_Read(i);
92  ++x;
93  }
94 }
95 
97 {
98  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);
99 }
100 #endif
uint8_t * PIOS_BL_HELPER_FLASH_If_Read(uint32_t SectorAddress)
Main PiOS header to include all the compiled in PiOS options.
uint32_t PIOS_BL_HELPER_CRC_Memory_Calc()
const struct pios_board_info pios_board_info_blob
uint32_t fw_base
void PIOS_BL_HELPER_FLASH_Read_Description(uint8_t *array, uint8_t size)
uint8_t i
Definition: msp_messages.h:97
#define MAX_DEL_RETRYS
Definition: pios_board.h:80
void PIOS_BL_HELPER_CRC_Ini()
uint8_t PIOS_BL_HELPER_FLASH_Ini()
uint8_t PIOS_BL_HELPER_FLASH_Start()