app_conf.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. #pragma once
  2. #include "hw_conf.h"
  3. #include "hw_if.h"
  4. #include <interface/patterns/ble_thread/hw.h>
  5. #include <ble/core/ble_bufsize.h>
  6. #define CFG_TX_POWER (0x19) /* +0dBm */
  7. /**
  8. * Define Advertising parameters
  9. */
  10. #define CFG_ADV_BD_ADDRESS (0x7257acd87a6c)
  11. #define CFG_FAST_CONN_ADV_INTERVAL_MIN (0x80) /**< 80ms */
  12. #define CFG_FAST_CONN_ADV_INTERVAL_MAX (0xa0) /**< 100ms */
  13. #define CFG_LP_CONN_ADV_INTERVAL_MIN (0x640) /**< 1s */
  14. #define CFG_LP_CONN_ADV_INTERVAL_MAX (0xfa0) /**< 2.5s */
  15. /**
  16. * Define IO Authentication
  17. */
  18. #define CFG_BONDING_MODE (1)
  19. #define CFG_FIXED_PIN (111111)
  20. #define CFG_USED_FIXED_PIN (1)
  21. #define CFG_ENCRYPTION_KEY_SIZE_MAX (16)
  22. #define CFG_ENCRYPTION_KEY_SIZE_MIN (8)
  23. /**
  24. * Define IO capabilities
  25. */
  26. #define CFG_IO_CAPABILITY_DISPLAY_ONLY (0x00)
  27. #define CFG_IO_CAPABILITY_DISPLAY_YES_NO (0x01)
  28. #define CFG_IO_CAPABILITY_KEYBOARD_ONLY (0x02)
  29. #define CFG_IO_CAPABILITY_NO_INPUT_NO_OUTPUT (0x03)
  30. #define CFG_IO_CAPABILITY_KEYBOARD_DISPLAY (0x04)
  31. #define CFG_IO_CAPABILITY CFG_IO_CAPABILITY_DISPLAY_YES_NO
  32. /**
  33. * Define MITM modes
  34. */
  35. #define CFG_MITM_PROTECTION_NOT_REQUIRED (0x00)
  36. #define CFG_MITM_PROTECTION_REQUIRED (0x01)
  37. #define CFG_MITM_PROTECTION CFG_MITM_PROTECTION_REQUIRED
  38. /**
  39. * Define Secure Connections Support
  40. */
  41. #define CFG_SECURE_NOT_SUPPORTED (0x00)
  42. #define CFG_SECURE_OPTIONAL (0x01)
  43. #define CFG_SECURE_MANDATORY (0x02)
  44. #define CFG_SC_SUPPORT CFG_SECURE_OPTIONAL
  45. /**
  46. * Define Keypress Notification Support
  47. */
  48. #define CFG_KEYPRESS_NOT_SUPPORTED (0x00)
  49. #define CFG_KEYPRESS_SUPPORTED (0x01)
  50. #define CFG_KEYPRESS_NOTIFICATION_SUPPORT CFG_KEYPRESS_NOT_SUPPORTED
  51. /**
  52. * Numeric Comparison Answers
  53. */
  54. #define YES (0x01)
  55. #define NO (0x00)
  56. /**
  57. * Device name configuration for Generic Access Service
  58. */
  59. #define CFG_GAP_DEVICE_NAME "TEMPLATE"
  60. #define CFG_GAP_DEVICE_NAME_LENGTH (8)
  61. /**
  62. * Define PHY
  63. */
  64. #define ALL_PHYS_PREFERENCE 0x00
  65. #define RX_2M_PREFERRED 0x02
  66. #define TX_2M_PREFERRED 0x02
  67. #define TX_1M 0x01
  68. #define TX_2M 0x02
  69. #define RX_1M 0x01
  70. #define RX_2M 0x02
  71. /**
  72. * Identity root key used to derive LTK and CSRK
  73. */
  74. #define CFG_BLE_IRK \
  75. { \
  76. 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, \
  77. 0xf0 \
  78. }
  79. /**
  80. * Encryption root key used to derive LTK and CSRK
  81. */
  82. #define CFG_BLE_ERK \
  83. { \
  84. 0xfe, 0xdc, 0xba, 0x09, 0x87, 0x65, 0x43, 0x21, 0xfe, 0xdc, 0xba, 0x09, 0x87, 0x65, 0x43, \
  85. 0x21 \
  86. }
  87. /* USER CODE BEGIN Generic_Parameters */
  88. /**
  89. * SMPS supply
  90. * SMPS not used when Set to 0
  91. * SMPS used when Set to 1
  92. */
  93. #define CFG_USE_SMPS 1
  94. /* USER CODE END Generic_Parameters */
  95. /**< specific parameters */
  96. /*****************************************************/
  97. /**
  98. * AD Element - Group B Feature
  99. */
  100. /* LSB - Second Byte */
  101. #define CFG_FEATURE_OTA_REBOOT (0x20)
  102. /******************************************************************************
  103. * BLE Stack
  104. ******************************************************************************/
  105. /**
  106. * Maximum number of simultaneous connections that the device will support.
  107. * Valid values are from 1 to 8
  108. */
  109. #define CFG_BLE_NUM_LINK 1
  110. /**
  111. * Maximum number of Services that can be stored in the GATT database.
  112. * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services
  113. */
  114. #define CFG_BLE_NUM_GATT_SERVICES 8
  115. /**
  116. * Maximum number of Attributes
  117. * (i.e. the number of characteristic + the number of characteristic values + the number of descriptors, excluding the services)
  118. * that can be stored in the GATT database.
  119. * Note that certain characteristics and relative descriptors are added automatically during device initialization
  120. * so this parameters should be 9 plus the number of user Attributes
  121. */
  122. #define CFG_BLE_NUM_GATT_ATTRIBUTES 68
  123. /**
  124. * Maximum supported ATT_MTU size
  125. */
  126. #define CFG_BLE_MAX_ATT_MTU (256 + 128 + 16 + 8 + 4 + 2)
  127. /**
  128. * Size of the storage area for Attribute values
  129. * This value depends on the number of attributes used by application. In particular the sum of the following quantities (in octets) should be made for each attribute:
  130. * - attribute value length
  131. * - 5, if UUID is 16 bit; 19, if UUID is 128 bit
  132. * - 2, if server configuration descriptor is used
  133. * - 2*DTM_NUM_LINK, if client configuration descriptor is used
  134. * - 2, if extended properties is used
  135. * The total amount of memory needed is the sum of the above quantities for each attribute.
  136. */
  137. #define CFG_BLE_ATT_VALUE_ARRAY_SIZE (1344)
  138. /**
  139. * Prepare Write List size in terms of number of packet
  140. */
  141. #define CFG_BLE_PREPARE_WRITE_LIST_SIZE BLE_PREP_WRITE_X_ATT(CFG_BLE_MAX_ATT_MTU)
  142. /**
  143. * Number of allocated memory blocks
  144. */
  145. #define CFG_BLE_MBLOCK_COUNT \
  146. (BLE_MBLOCKS_CALC(CFG_BLE_PREPARE_WRITE_LIST_SIZE, CFG_BLE_MAX_ATT_MTU, CFG_BLE_NUM_LINK))
  147. /**
  148. * Enable or disable the Extended Packet length feature. Valid values are 0 or 1.
  149. */
  150. #define CFG_BLE_DATA_LENGTH_EXTENSION 1
  151. /**
  152. * Sleep clock accuracy in Slave mode (ppm value)
  153. */
  154. #define CFG_BLE_SLAVE_SCA 500
  155. /**
  156. * Sleep clock accuracy in Master mode
  157. * 0 : 251 ppm to 500 ppm
  158. * 1 : 151 ppm to 250 ppm
  159. * 2 : 101 ppm to 150 ppm
  160. * 3 : 76 ppm to 100 ppm
  161. * 4 : 51 ppm to 75 ppm
  162. * 5 : 31 ppm to 50 ppm
  163. * 6 : 21 ppm to 30 ppm
  164. * 7 : 0 ppm to 20 ppm
  165. */
  166. #define CFG_BLE_MASTER_SCA 0
  167. /**
  168. * Source for the low speed clock for RF wake-up
  169. * 1 : external high speed crystal HSE/32/32
  170. * 0 : external low speed crystal ( no calibration )
  171. */
  172. #define CFG_BLE_LSE_SOURCE 0
  173. /**
  174. * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us)
  175. */
  176. #define CFG_BLE_HSE_STARTUP_TIME 0x148
  177. /**
  178. * Maximum duration of the connection event when the device is in Slave mode in units of 625/256 us (~2.44 us)
  179. */
  180. #define CFG_BLE_MAX_CONN_EVENT_LENGTH (0xFFFFFFFF)
  181. /**
  182. * Viterbi Mode
  183. * 1 : enabled
  184. * 0 : disabled
  185. */
  186. #define CFG_BLE_VITERBI_MODE 1
  187. /**
  188. * BLE stack Options flags to be configured with:
  189. * - SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY
  190. * - SHCI_C2_BLE_INIT_OPTIONS_LL_HOST
  191. * - SHCI_C2_BLE_INIT_OPTIONS_NO_SVC_CHANGE_DESC
  192. * - SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC
  193. * - SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RO
  194. * - SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW
  195. * - SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV
  196. * - SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV
  197. * - SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2
  198. * - SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2
  199. * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_1
  200. * - SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3
  201. * which are used to set following configuration bits:
  202. * (bit 0): 1: LL only
  203. * 0: LL + host
  204. * (bit 1): 1: no service change desc.
  205. * 0: with service change desc.
  206. * (bit 2): 1: device name Read-Only
  207. * 0: device name R/W
  208. * (bit 3): 1: extended advertizing supported [NOT SUPPORTED]
  209. * 0: extended advertizing not supported [NOT SUPPORTED]
  210. * (bit 4): 1: CS Algo #2 supported
  211. * 0: CS Algo #2 not supported
  212. * (bit 7): 1: LE Power Class 1
  213. * 0: LE Power Class 2-3
  214. * other bits: reserved (shall be set to 0)
  215. */
  216. #define CFG_BLE_OPTIONS \
  217. (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | \
  218. SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV | \
  219. SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3)
  220. /**
  221. * Queue length of BLE Event
  222. * This parameter defines the number of asynchronous events that can be stored in the HCI layer before
  223. * being reported to the application. When a command is sent to the BLE core coprocessor, the HCI layer
  224. * is waiting for the event with the Num_HCI_Command_Packets set to 1. The receive queue shall be large
  225. * enough to store all asynchronous events received in between.
  226. * When CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE is set to 27, this allow to store three 255 bytes long asynchronous events
  227. * between the HCI command and its event.
  228. * This parameter depends on the value given to CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE. When the queue size is to small,
  229. * the system may hang if the queue is full with asynchronous events and the HCI layer is still waiting
  230. * for a CC/CS event, In that case, the notification TL_BLE_HCI_ToNot() is called to indicate
  231. * to the application a HCI command did not receive its command event within 30s (Default HCI Timeout).
  232. */
  233. #define CFG_TLBLE_EVT_QUEUE_LENGTH 5
  234. /**
  235. * This parameter should be set to fit most events received by the HCI layer. It defines the buffer size of each element
  236. * allocated in the queue of received events and can be used to optimize the amount of RAM allocated by the Memory Manager.
  237. * It should not exceed 255 which is the maximum HCI packet payload size (a greater value is a lost of memory as it will
  238. * never be used)
  239. * With the current wireless firmware implementation, this parameter shall be kept to 255
  240. *
  241. */
  242. #define CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE \
  243. 255 /**< Set to 255 with the memory manager and the mailbox */
  244. #define TL_BLE_EVENT_FRAME_SIZE (TL_EVT_HDR_SIZE + CFG_TLBLE_MOST_EVENT_PAYLOAD_SIZE)
  245. /******************************************************************************
  246. * UART interfaces
  247. ******************************************************************************/
  248. /**
  249. * Select UART interfaces
  250. */
  251. #define CFG_DEBUG_TRACE_UART hw_uart1
  252. #define CFG_CONSOLE_MENU 0
  253. /******************************************************************************
  254. * Low Power
  255. ******************************************************************************/
  256. /**
  257. * When set to 1, the low power mode is enable
  258. * When set to 0, the device stays in RUN mode
  259. */
  260. #define CFG_LPM_SUPPORTED 1
  261. /******************************************************************************
  262. * Timer Server
  263. ******************************************************************************/
  264. /**
  265. * CFG_RTC_WUCKSEL_DIVIDER: This sets the RTCCLK divider to the wakeup timer.
  266. * The lower is the value, the better is the power consumption and the accuracy of the timerserver
  267. * The higher is the value, the finest is the granularity
  268. *
  269. * CFG_RTC_ASYNCH_PRESCALER: This sets the asynchronous prescaler of the RTC. It should as high as possible ( to ouput
  270. * clock as low as possible) but the output clock should be equal or higher frequency compare to the clock feeding
  271. * the wakeup timer. A lower clock speed would impact the accuracy of the timer server.
  272. *
  273. * CFG_RTC_SYNCH_PRESCALER: This sets the synchronous prescaler of the RTC.
  274. * When the 1Hz calendar clock is required, it shall be sets according to other settings
  275. * When the 1Hz calendar clock is not needed, CFG_RTC_SYNCH_PRESCALER should be set to 0x7FFF (MAX VALUE)
  276. *
  277. * CFG_RTCCLK_DIVIDER_CONF:
  278. * Shall be set to either 0,2,4,8,16
  279. * When set to either 2,4,8,16, the 1Hhz calendar is supported
  280. * When set to 0, the user sets its own configuration
  281. *
  282. * The following settings are computed with LSI as input to the RTC
  283. */
  284. #define CFG_RTCCLK_DIVIDER_CONF 0
  285. #if(CFG_RTCCLK_DIVIDER_CONF == 0)
  286. /**
  287. * Custom configuration
  288. * It does not support 1Hz calendar
  289. * It divides the RTC CLK by 16
  290. */
  291. #define CFG_RTCCLK_DIV (16)
  292. #define CFG_RTC_WUCKSEL_DIVIDER (0)
  293. #define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1)
  294. #define CFG_RTC_SYNCH_PRESCALER (0x7FFF)
  295. #else
  296. #if(CFG_RTCCLK_DIVIDER_CONF == 2)
  297. /**
  298. * It divides the RTC CLK by 2
  299. */
  300. #define CFG_RTC_WUCKSEL_DIVIDER (3)
  301. #endif
  302. #if(CFG_RTCCLK_DIVIDER_CONF == 4)
  303. /**
  304. * It divides the RTC CLK by 4
  305. */
  306. #define CFG_RTC_WUCKSEL_DIVIDER (2)
  307. #endif
  308. #if(CFG_RTCCLK_DIVIDER_CONF == 8)
  309. /**
  310. * It divides the RTC CLK by 8
  311. */
  312. #define CFG_RTC_WUCKSEL_DIVIDER (1)
  313. #endif
  314. #if(CFG_RTCCLK_DIVIDER_CONF == 16)
  315. /**
  316. * It divides the RTC CLK by 16
  317. */
  318. #define CFG_RTC_WUCKSEL_DIVIDER (0)
  319. #endif
  320. #define CFG_RTCCLK_DIV CFG_RTCCLK_DIVIDER_CONF
  321. #define CFG_RTC_ASYNCH_PRESCALER (CFG_RTCCLK_DIV - 1)
  322. #define CFG_RTC_SYNCH_PRESCALER (DIVR(LSE_VALUE, (CFG_RTC_ASYNCH_PRESCALER + 1)) - 1)
  323. #endif
  324. /** tick timer value in us */
  325. #define CFG_TS_TICK_VAL DIVR((CFG_RTCCLK_DIV * 1000000), LSE_VALUE)
  326. typedef enum {
  327. CFG_TIM_PROC_ID_ISR,
  328. /* USER CODE BEGIN CFG_TimProcID_t */
  329. /* USER CODE END CFG_TimProcID_t */
  330. } CFG_TimProcID_t;
  331. /******************************************************************************
  332. * Debug
  333. ******************************************************************************/
  334. /**
  335. * When set, this resets some hw resources to set the device in the same state than the power up
  336. * The FW resets only register that may prevent the FW to run properly
  337. *
  338. * This shall be set to 0 in a final product
  339. *
  340. */
  341. #define CFG_HW_RESET_BY_FW 0
  342. /**
  343. * keep debugger enabled while in any low power mode when set to 1
  344. * should be set to 0 in production
  345. */
  346. #define CFG_DEBUGGER_SUPPORTED 1
  347. /**
  348. * When set to 1, the traces are enabled in the BLE services
  349. */
  350. #define CFG_DEBUG_BLE_TRACE 0
  351. /**
  352. * Enable or Disable traces in application
  353. */
  354. #define CFG_DEBUG_APP_TRACE 0
  355. #if(CFG_DEBUG_APP_TRACE != 0)
  356. #define APP_DBG_MSG PRINT_MESG_DBG
  357. #else
  358. #define APP_DBG_MSG PRINT_NO_MESG
  359. #endif
  360. #if((CFG_DEBUG_BLE_TRACE != 0) || (CFG_DEBUG_APP_TRACE != 0))
  361. #define CFG_DEBUG_TRACE 1
  362. #endif
  363. #if(CFG_DEBUG_TRACE != 0)
  364. #undef CFG_LPM_SUPPORTED
  365. #undef CFG_DEBUGGER_SUPPORTED
  366. #define CFG_LPM_SUPPORTED 0
  367. #define CFG_DEBUGGER_SUPPORTED 1
  368. #endif
  369. /**
  370. * When CFG_DEBUG_TRACE_FULL is set to 1, the trace are output with the API name, the file name and the line number
  371. * When CFG_DEBUG_TRACE_LIGHT is set to 1, only the debug message is output
  372. *
  373. * When both are set to 0, no trace are output
  374. * When both are set to 1, CFG_DEBUG_TRACE_FULL is selected
  375. */
  376. #define CFG_DEBUG_TRACE_LIGHT 0
  377. #define CFG_DEBUG_TRACE_FULL 0
  378. #if((CFG_DEBUG_TRACE != 0) && (CFG_DEBUG_TRACE_LIGHT == 0) && (CFG_DEBUG_TRACE_FULL == 0))
  379. #undef CFG_DEBUG_TRACE_FULL
  380. #undef CFG_DEBUG_TRACE_LIGHT
  381. #define CFG_DEBUG_TRACE_FULL 0
  382. #define CFG_DEBUG_TRACE_LIGHT 1
  383. #endif
  384. #if(CFG_DEBUG_TRACE == 0)
  385. #undef CFG_DEBUG_TRACE_FULL
  386. #undef CFG_DEBUG_TRACE_LIGHT
  387. #define CFG_DEBUG_TRACE_FULL 0
  388. #define CFG_DEBUG_TRACE_LIGHT 0
  389. #endif
  390. /**
  391. * When not set, the traces is looping on sending the trace over UART
  392. */
  393. #define DBG_TRACE_USE_CIRCULAR_QUEUE 0
  394. /**
  395. * max buffer Size to queue data traces and max data trace allowed.
  396. * Only Used if DBG_TRACE_USE_CIRCULAR_QUEUE is defined
  397. */
  398. #define DBG_TRACE_MSG_QUEUE_SIZE 4096
  399. #define MAX_DBG_TRACE_MSG_SIZE 1024
  400. #define CFG_OTP_BASE_ADDRESS OTP_AREA_BASE
  401. #define CFG_OTP_END_ADRESS OTP_AREA_END_ADDR