@@ -52,6 +52,9 @@ PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t
52
52
uint16_t _write_index;
53
53
uint16_t _write_index_initial;
54
54
55
+ /* * Bluetooth Device Address */
56
+ static uint8_t bd_addr_udn[6 ];
57
+
55
58
HCISharedMemTransportClass::HCISharedMemTransportClass (BLEChip_t ble_chip) :
56
59
_ble_chip(ble_chip)
57
60
{
@@ -266,12 +269,20 @@ int HCISharedMemTransportClass::begin()
266
269
*/
267
270
268
271
269
- /* Now start BLE service on firmware side, using Vendor specific
270
- * command on the System Channel
271
- */
272
- stm32wb_start_ble ();
272
+ /* Now start BLE service on firmware side, using Vendor specific
273
+ * command on the System Channel
274
+ */
275
+ stm32wb_start_ble ();
273
276
274
277
/* "IPM Channel Open Completed" */
278
+
279
+ /* Once reset complete evet is received we need
280
+ * to send a few more commands:
281
+ * set bd addr */
282
+ bt_ipm_set_addr ();
283
+ /* and Tx power */
284
+ bt_ipm_set_power ();
285
+
275
286
return 1 ;
276
287
} else {
277
288
/* "Error opening IPM channel" */
@@ -488,11 +499,96 @@ size_t HCISharedMemTransportClass::write(const uint8_t* data, size_t length)
488
499
489
500
}
490
501
502
+ #if 1
503
+ /* This function fills in a BD address table */
504
+ bool get_bd_address (uint8_t *bd_addr)
505
+ {
506
+ uint8_t *otp_addr;
507
+ uint32_t udn;
508
+ uint32_t company_id;
509
+ uint32_t device_id;
510
+ bool bd_found;
511
+
512
+ udn = LL_FLASH_GetUDN ();
513
+
514
+ if (udn != 0xFFFFFFFF ) {
515
+ /* "Found Unique Device Number: %#06x", udn) */
516
+
517
+ company_id = LL_FLASH_GetSTCompanyID ();
518
+ device_id = LL_FLASH_GetDeviceID ();
519
+
520
+ bd_addr[0 ] = (uint8_t )(udn & 0x000000FF );
521
+ bd_addr[1 ] = (uint8_t )((udn & 0x0000FF00 ) >> 8 );
522
+ bd_addr[2 ] = (uint8_t )((udn & 0x00FF0000 ) >> 16 );
523
+ bd_addr[3 ] = (uint8_t )device_id;
524
+ bd_addr[4 ] = (uint8_t )(company_id & 0x000000FF );
525
+ bd_addr[5 ] = (uint8_t )((company_id & 0x0000FF00 ) >> 8 );
526
+
527
+ bd_found = true ;
528
+ } else {
529
+ bd_addr =NULL ;
530
+ bd_found = false ;
531
+ }
532
+
533
+ return bd_found;
534
+ }
535
+
536
+ static int bt_ipm_set_addr (void )
537
+ {
538
+ /* the specific table for set addr is 8 bytes:
539
+ * one byte for config_offset
540
+ * one byte for length
541
+ * 6 bytes for payload */
542
+ uint8_t data[4 +8 ];
543
+
544
+ if (get_bd_address (bd_addr_udn)) {
545
+ /* create ACI_HAL_WRITE_CONFIG_DATA */
546
+
547
+ data[0 ] = BT_BUF_CMD;
548
+ data[1 ] = uint8_t (ACI_WRITE_CONFIG_DATA_OPCODE & 0x000000FF ); /* OCF */
549
+ data[2 ] = uint8_t ((ACI_WRITE_CONFIG_DATA_OPCODE & 0x0000FF00 ) >> 8 ); /* OGF */
550
+ data[3 ] = 8 ; /* length of parameters */
551
+ /* fill the ACI_HAL_WRITE_CONFIG_DATA with the addr*/
552
+ data[4 ] = CONFIG_DATA_PUBADDR_OFFSET; /* the offset */
553
+ data[5 ] = 6 ; /* is the length of the bd_addr table */
554
+ memcpy (data + 6 , bd_addr_udn, 6 );
555
+ /* send the ACI_HAL_WRITE_CONFIG_DATA */
556
+ mbox_write (data[0 ], 11 , &data[1 ]);
557
+
558
+ return 1 ; /* success */
559
+ } else {
560
+ return 0 ; /* Error */
561
+ }
562
+ }
563
+
564
+ static int bt_ipm_set_power (void )
565
+ {
566
+ /* the specific table for power is 3 bytes:
567
+ * one byte for cmd
568
+ * two bytes for value */
569
+ uint8_t data[4 +3 ];
570
+
571
+ data[0 ] = BT_BUF_CMD; /* the type */
572
+ data[1 ] = (uint8_t )(ACI_HAL_SET_TX_POWER_LEVEL & 0x000000FF ); /* the OPCODE */
573
+ data[2 ] = (uint8_t )((ACI_HAL_SET_TX_POWER_LEVEL & 0x0000FF00 ) >> 8 );
574
+ data[3 ] = 3 ; /* the length */
575
+ /* fill the ACI_HAL_WRITE_CONFIG_DATA */
576
+ data[4 ] = 0x0F ; /* the command */
577
+ data[5 ] = 0x18 ;
578
+ data[6 ] = 0x01 ;
579
+
580
+ /* send the ACI_HAL_WRITE_CONFIG_DATA */
581
+ mbox_write (data[0 ], 3 , &data[1 ]);
582
+
583
+ return 1 ; /* success */
584
+ }
585
+
586
+ #else
491
587
int bt_ipm_ble_init(void)
492
588
{
493
589
uint16_t opcode;
494
590
static uint8_t randCnt;
495
- # if 0
591
+
496
592
/* if event is a command complete event */
497
593
if (*pMsg == HCI_CMD_CMPL_EVT) {
498
594
/* "Command Complete Event Command" */
@@ -707,9 +803,10 @@ size_t HCISharedMemTransportClass::write(const uint8_t* data, size_t length)
707
803
#endif /* DEBUG */
708
804
}
709
805
}
710
- # endif
711
- return 0 ;
806
+
807
+ return 1; /* success */
712
808
}
809
+ #endif
713
810
714
811
uint16_t mbox_write (uint8_t type, uint16_t len, const uint8_t *pData)
715
812
{
@@ -817,40 +914,3 @@ static void init_debug(void)
817
914
818
915
return ;
819
916
}
820
-
821
- /* This function fills in a BD address table */
822
- bool get_bd_address (uint8_t *bd_addr)
823
- {
824
- uint8_t *otp_addr;
825
- uint32_t udn;
826
- uint32_t company_id;
827
- uint32_t device_id;
828
- bool bd_found;
829
-
830
- udn = LL_FLASH_GetUDN ();
831
-
832
- if (udn != 0xFFFFFFFF ) {
833
- #if defined(DEBUG)
834
- tr_info (" Found Unique Device Number: %#06x" , udn);
835
- #endif /* DEBUG */
836
- company_id = LL_FLASH_GetSTCompanyID ();
837
- device_id = LL_FLASH_GetDeviceID ();
838
-
839
- bd_addr[0 ] = (uint8_t )(udn & 0x000000FF );
840
- bd_addr[1 ] = (uint8_t )((udn & 0x0000FF00 ) >> 8 );
841
- bd_addr[2 ] = (uint8_t )((udn & 0x00FF0000 ) >> 16 );
842
- bd_addr[3 ] = (uint8_t )device_id;
843
- bd_addr[4 ] = (uint8_t )(company_id & 0x000000FF );
844
- bd_addr[5 ] = (uint8_t )((company_id & 0x0000FF00 ) >> 8 );
845
-
846
- bd_found = true ;
847
- } else {
848
- #if defined(DEBUG)
849
- tr_info (" Cannot find Bluetooth Device ADDRESS to program - will leave hw default" );
850
- #endif /* DEBUG */
851
- bd_addr = NULL ;
852
- bd_found = false ;
853
- }
854
-
855
- return bd_found;
856
- }
0 commit comments