flash_if.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. ******************************************************************************
  3. * @file IAP/IAP_Main/Inc/flash_if.h
  4. * @author MCD Application Team
  5. * @brief This file provides all the headers of the flash_if functions.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
  10. * All rights reserved.</center></h2>
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted, provided that the following conditions are met:
  14. *
  15. * 1. Redistribution of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of other
  21. * contributors to this software may be used to endorse or promote products
  22. * derived from this software without specific written permission.
  23. * 4. This software, including modifications and/or derivative works of this
  24. * software, must execute solely and exclusively on microcontroller or
  25. * microprocessor devices manufactured by or for STMicroelectronics.
  26. * 5. Redistribution and use of this software other than as permitted under
  27. * this license is void and will automatically terminate your rights under
  28. * this license.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  31. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  33. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  34. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  35. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  36. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  37. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  38. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  39. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  40. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  41. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. *
  43. ******************************************************************************
  44. */
  45. /* Define to prevent recursive inclusion -------------------------------------*/
  46. #ifndef __FLASH_IF_H
  47. #define __FLASH_IF_H
  48. /* Includes ------------------------------------------------------------------*/
  49. #include "stm32f4xx_hal.h"
  50. #include "iwdg.h"
  51. /* Exported types ------------------------------------------------------------*/
  52. /* Exported constants --------------------------------------------------------*/
  53. /* Base address of the Flash sectors */
  54. #define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbyte */
  55. #define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbyte */
  56. #define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbyte */
  57. #define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbyte */
  58. #define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbyte */
  59. #define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbyte */
  60. #define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbyte */
  61. #define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbyte */
  62. #define ADDR_FLASH_SECTOR_8 ((uint32_t)0x08080000) /* Base @ of Sector 8, 128 Kbyte */
  63. #define ADDR_FLASH_SECTOR_9 ((uint32_t)0x080A0000) /* Base @ of Sector 9, 128 Kbyte */
  64. #define ADDR_FLASH_SECTOR_10 ((uint32_t)0x080C0000) /* Base @ of Sector 10, 128 Kbyte */
  65. #define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) /* Base @ of Sector 11, 128 Kbyte */
  66. /* Error code */
  67. enum
  68. {
  69. FLASHIF_OK = 0,
  70. FLASHIF_ERASEKO,
  71. FLASHIF_WRITINGCTRL_ERROR,
  72. FLASHIF_WRITING_ERROR
  73. };
  74. enum{
  75. FLASHIF_PROTECTION_NONE = 0,
  76. FLASHIF_PROTECTION_PCROPENABLED = 0x1,
  77. FLASHIF_PROTECTION_WRPENABLED = 0x2,
  78. FLASHIF_PROTECTION_RDPENABLED = 0x4,
  79. };
  80. /* End of the Flash address */
  81. #define USER_FLASH_END_ADDRESS 0x080FFFFF
  82. /* Define the user application size */
  83. #define USER_FLASH_SIZE (USER_FLASH_END_ADDRESS - APPLICATION_ADDRESS + 1)
  84. /* Define the address from where user application will be loaded.
  85. Note: the 1st sector 0x08000000-0x08003FFF is reserved for the IAP code */
  86. #define APPLICATION_ADDRESS ADDR_FLASH_SECTOR_6
  87. #define NEW_CODE_ADDRESS ADDR_FLASH_SECTOR_9
  88. #define UPGRADE_REQ_ADDRESS ADDR_FLASH_SECTOR_3
  89. #define FLASH_AP_LENGTH 0x60000
  90. /* Define bitmap representing user flash area that could be write protected (check restricted to pages 8-39). */
  91. #define FLASH_SECTOR_TO_BE_PROTECTED (OB_WRP_SECTOR_0 | OB_WRP_SECTOR_1 | OB_WRP_SECTOR_2 | OB_WRP_SECTOR_3 |\
  92. OB_WRP_SECTOR_4 | OB_WRP_SECTOR_5 | OB_WRP_SECTOR_6 | OB_WRP_SECTOR_7 |\
  93. OB_WRP_SECTOR_8 | OB_WRP_SECTOR_9 | OB_WRP_SECTOR_10 | OB_WRP_SECTOR_11 )
  94. /* Exported macro ------------------------------------------------------------*/
  95. /* Exported functions ------------------------------------------------------- */
  96. void FLASH_If_Init(void);
  97. uint32_t FLASH_If_Erase(uint32_t StartSector, uint32_t NumberOfSector);
  98. uint32_t FLASH_If_Write(uint32_t FlashAddress, uint32_t* Data, uint32_t DataLength);
  99. uint16_t FLASH_If_GetWriteProtectionStatus(void);
  100. HAL_StatusTypeDef FLASH_If_WriteProtectionConfig(uint32_t modifier);
  101. uint8_t PH_CalNewCodeChecksum(void);
  102. uint8_t PH_isMoveOK(void);
  103. void PH_ClearUpgradeReq(void);
  104. uint8_t PH_isUpgradeReq(void);
  105. void PH_MoveCode2Ap(void);
  106. #endif /* __FLASH_IF_H */
  107. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/