| BlueNRG-1 HAL drivers APIs

- Main Page
- Classes
- Files

- File List
- File Members

OTA_btl.h
Go to the documentation of this file.
1
21 /* Define to prevent recursive inclusion -------------------------------------*/
22 #ifndef __BTL_H
23 #define __BTL_H
24
25 /* Includes ------------------------------------------------------------------*/
26 /* Exported types ------------------------------------------------------------*/
27 /* Exported constants --------------------------------------------------------*/
28
29 /* Exported macro ------------------------------------------------------------*/
30 #ifdef DEBUG
31 #include <stdio.h>
32 #define PRINTF(...) printf(__VA_ARGS__)
33 #else
34 #define PRINTF(...)
35 #endif
36
37 /* Exported define -----------------------------------------------------------*/
38
39 /* BlueNRG-1 Flash memory layout for OTA */
40
42 #define FLASH_PAGE_SIZE 2048
43 #ifndef RESET_MANAGER_FLASH_BASE_ADDRESS
44
45 #define RESET_MANAGER_FLASH_BASE_ADDRESS (0x10040000)
46 #endif
47
51 #define RESET_MANAGER_FLASH_BASE_OFFSET (0x800)
52
54 #define OTA_BASIC_APPLICATION_BASE_OFFSET (0x10000)
55
57 #define HIGHER_APPLICATION_BASE_OFFSET (0x13800)
58
60 #define OTA_LOWER_HIGHER_APPLICATION_AVAILABLE_SECTORS_NUMBERS 38 /* 38 * 2048 = 76K */
61
63 #define OTA_RESET_MANAGER_PAGE_NUMBER_START 0
64 #define OTA_RESET_MANAGER_PAGE_NUMBERS (RESET_MANAGER_FLASH_BASE_OFFSET/FLASH_PAGE_SIZE)
65
67 #define OTA_LOWER_APPLICATION_PAGE_NUMBER_START (OTA_RESET_MANAGER_PAGE_NUMBER_START + OTA_RESET_MANAGER_PAGE_NUMBERS) //1
68 #define OTA_LOWER_APPLICATION_PAGE_NUMBER_END (OTA_LOWER_HIGHER_APPLICATION_AVAILABLE_SECTORS_NUMBERS) //38
69 #define APP_LOWER_ADDRESS (RESET_MANAGER_FLASH_BASE_ADDRESS + RESET_MANAGER_FLASH_BASE_OFFSET)
70 #define APP_LOWER_ADDRESS_END APP_LOWER_ADDRESS + (OTA_LOWER_HIGHER_APPLICATION_AVAILABLE_SECTORS_NUMBERS*FLASH_PAGE_SIZE)
71
73 #define OTA_HIGHER_APPLICATION_PAGE_NUMBER_START (OTA_LOWER_APPLICATION_PAGE_NUMBER_END + 1) //39: 0x13800 Higher application starts at sector 39 and ends at sector 76
74 #define OTA_HIGHER_APPLICATION_PAGE_NUMBER_END (OTA_LOWER_HIGHER_APPLICATION_AVAILABLE_SECTORS_NUMBERS*2) //76
75 #define APP_HIGHER_ADDRESS (RESET_MANAGER_FLASH_BASE_ADDRESS + HIGHER_APPLICATION_BASE_OFFSET)
76 #define APP_HIGHER_ADDRESS_END APP_HIGHER_ADDRESS + (((OTA_HIGHER_APPLICATION_PAGE_NUMBER_END - OTA_HIGHER_APPLICATION_PAGE_NUMBER_START)+1)*FLASH_PAGE_SIZE)
77
79 #define APP_OTA_SERVICE_ADDRESS (RESET_MANAGER_FLASH_BASE_ADDRESS)
80 #define APP_WITH_OTA_SERVICE_PAGE_NUMBER_START (OTA_BASIC_APPLICATION_BASE_OFFSET)/FLASH_PAGE_SIZE //29
81 #define APP_WITH_OTA_SERVICE_PAGE_NUMBER_END (OTA_HIGHER_APPLICATION_PAGE_NUMBER_END + 1) //77
82
83
85 #define APP_WITH_OTA_SERVICE_ADDRESS (RESET_MANAGER_FLASH_BASE_ADDRESS + OTA_BASIC_APPLICATION_BASE_OFFSET)
86
89 #define OTA_NO_OPERATION (0x11)
90 #define OTA_APP_SWITCH_OP_CODE_NO_OPERATION (0xb0014211)
91 #define OTA_APP_SWITCH_OP_CODE_GO_TO_LOWER_APP (OTA_APP_SWITCH_OP_CODE_NO_OPERATION + (OTA_NO_OPERATION*2)) //0xb0014233
92 #define OTA_APP_SWITCH_OP_CODE_GO_TO_HIGHER_APP (OTA_APP_SWITCH_OP_CODE_NO_OPERATION + (OTA_NO_OPERATION*3)) //0xb0014244
93 #define OTA_APP_SWITCH_OP_CODE_GO_TO_OTA_SERVICE_MANAGER (OTA_APP_SWITCH_OP_CODE_NO_OPERATION + (OTA_NO_OPERATION*4))
94 #define OTA_APP_SWITCH_OP_CODE_GO_TO_NEW_APP (OTA_APP_SWITCH_OP_CODE_NO_OPERATION + (OTA_NO_OPERATION*5))
95
103 #if ST_OTA_HIGHER_APPLICATION /* linker option */
104 /* BLE Application with OTA Service, based at higher FLASH address */
105
106 #define ST_OTA_FIRMWARE_UPGRADE_SUPPORT 1
107 #define APPLICATION_BASE_ADDRESS APP_HIGHER_ADDRESS
108
110 #define OTA_FREE_SPACE_RANGE {0x10,0x04,0x08,0x00,0x10,0x05,0x37,0xff} //Flash start: 0x10040800; Flash end: 0x100537ff
111
112 #define OTA_OP_CODE OTA_APP_SWITCH_OP_CODE_GO_TO_LOWER_APP // Go to Lower App when OTA completes with success
113
118 #elif ST_OTA_LOWER_APPLICATION /* linker option */
119 /* BLE Application with OTA Service, based at lower FLASH address */
120
121 #define ST_OTA_FIRMWARE_UPGRADE_SUPPORT 1
122 #define APPLICATION_BASE_ADDRESS APP_LOWER_ADDRESS
123
125 #define OTA_FREE_SPACE_RANGE {0x10,0x05,0x38,0x00,0x10,0x06,0x67,0xFF} //Flash start: 0x10053800; Flash end: 0x100667ff
126
127 #define OTA_OP_CODE OTA_APP_SWITCH_OP_CODE_GO_TO_HIGHER_APP// Go to Higher App when OTA completes with success
128
133 #elif ST_OTA_SERVICE_MANAGER_APPLICATION
134 /* OTA Service manager, based at FLASH base address */
135 #define APPLICATION_BASE_ADDRESS APP_OTA_SERVICE_ADDRESS
136
138 #define OTA_FREE_SPACE_RANGE {0x10,0x05,0x00,0x00,0x10,0x06,0x6F,0xFF}; //Flash start: 0x10050000; Flash end: 0x10066FFF;
139
140 #define OTA_OP_CODE OTA_APP_SWITCH_OP_CODE_GO_TO_NEW_APP
141
146 #elif ST_USE_OTA_SERVICE_MANAGER_APPLICATION /* linker option */
147 /* BLE Application (with no OTA service) which uses the OTA Service Manager */
148 /* BLE application is based at new higher FLASH address */
149 #define APPLICATION_BASE_ADDRESS APP_WITH_OTA_SERVICE_ADDRESS
150
151 #define OTA_FREE_SPACE_RANGE {0,0,0,0,0,0} //Not used in this context TBR
152
153 #define OTA_OP_CODE OTA_APP_SWITCH_OP_CODE_GO_TO_OTA_SERVICE_MANAGER //Not used in this context TBR
154
155 #else
156 /* Nothing to do: no OTA Service is supported; No OTA Service Manager is used */
157 #endif
158
159 /* ************************************************************************************************ */
160
162 #define OTA_SERVICE_MANAGER_RAM_LOCATION (0x20000004)
163
164 #define OTA_SET_SERVICE_MANAGER_RAM_LOCATION (*(uint32_t *)(OTA_SERVICE_MANAGER_RAM_LOCATION))
165
167 #define OTA_TAG_VECTOR_TABLE_ENTRY_INDEX (4)
168
169 #define OTA_TAG_VECTOR_TABLE_ENTRY_OFFSET (OTA_TAG_VECTOR_TABLE_ENTRY_INDEX * 4)
170
176 #define OTA_IN_PROGRESS_TAG (0xFFFFFFFF)
177
181 #define OTA_INVALID_OLD_TAG (0x00000000)
182
186 #define OTA_VALID_TAG (0xAA5555AA)
187
190 #define OTA_SERVICE_MANAGER_TAG (0xAABBCCDD)
191
192 /* Exported Variables --------------------------------------------------------*/
194 extern uint8_t BTLServiceUUID4Scan[];
195
196 /* Exported Functions --------------------------------------------------------*/
197
209 void OTA_Write_Request_CB(uint16_t attr_handle,
210 uint8_t data_length,
211 uint8_t *att_data);
212
220 uint8_t OTA_Add_Btl_Service(void);
221
229 uint8_t OTA_Tick(void);
230
238 void OTA_Jump_To_New_Application(void);
239
247 void OTA_Jump_To_Service_Manager_Application(void);
248
249 #endif /* __BTL_H */
250
251 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
BTLServiceUUID4Scan
uint8_t BTLServiceUUID4Scan[]
OTA Service UUID.
OTA_Add_Btl_Service
uint8_t OTA_Add_Btl_Service(void)
Add the 'OTABootloader' service.
OTA_Tick
uint8_t OTA_Tick(void)
It returns the OTA upgrade fw status.
OTA_Jump_To_Service_Manager_Application
void OTA_Jump_To_Service_Manager_Application(void)
It jumps to the OTA Service Manager application.
OTA_Jump_To_New_Application
void OTA_Jump_To_New_Application(void)
It jumps to the new upgraded application.
OTA_Write_Request_CB
void OTA_Write_Request_CB(uint16_t attr_handle, uint8_t data_length, uint8_t *att_data)
This function handles the OTA bootloader updgrade. It is called on the aci_gatt_attribute_modified_ev...